Views
No views yet
mistral-7b-instruct-v0.3-adjuvant-extractormistralai/Mistral-7B-Instruct-v0.3You are a biomedical information extraction assistant.1Extract infectious-disease adjuvants from the text and provide evidence snippets.
2Return ONLY valid JSON in this format:
3[{"adjuvant": "<string>", "evidence": "<string>"}, ...]
4Do not include any extra keys or explanation.1Title: <paper title>
2Abstract: <paper abstract>1[
2 {
3 "adjuvant": "<string>",
4 "evidence": "<string>"
5 }
6][]).adjuvant: normalized or near-normalized adjuvant nameevidence: supporting text snippet from the same input abstract1Title: Intranasal vaccination study using alum and MPLA adjuvants in a murine influenza model.
2Abstract: Mice immunized with antigen formulated with alum showed increased IgG titers. A separate group receiving MPLA-adjuvanted vaccine demonstrated stronger IFN-gamma responses and reduced viral load after challenge.1[
2 {
3 "adjuvant": "alum",
4 "evidence": "Mice immunized with antigen formulated with alum showed increased IgG titers."
5 },
6 {
7 "adjuvant": "MPLA",
8 "evidence": "A separate group receiving MPLA-adjuvanted vaccine demonstrated stronger IFN-gamma responses and reduced viral load after challenge."
9 }
10][] if no supported adjuvant is found).adjuvant and evidence.1import torch
2import json
3from transformers import AutoTokenizer, AutoModelForCausalLM
4
5repo_id = "RehanaHasin/mistral-7b-instruct-v0.3-adjuvant-extractor"
6
7SYS_PROMPT = "You are a biomedical information extraction assistant."
8PROMPT_INSTRUCTION = (
9 "Extract infectious-disease adjuvants from the text and provide evidence snippets.\n"
10 "Return ONLY valid JSON in this format:\n"
11 "[{\"adjuvant\": \"<string>\", \"evidence\": \"<string>\"}, ...]\n"
12 "Do not include any extra keys or explanation."
13)
14
15title = "Protective immune response against Streptococcus pyogenes in mice after intranasal vaccination with the fibronectin-binding protein SfbI."
16abstract = (
17 "Despite the significant impact on human health caused by Streptococcus pyogenes, "
18 "there is currently no vaccine available. Intranasal immunization of mice with either "
19 "SfbI alone or coupled to cholera toxin B subunit (CTB) triggered efficient SfbI-specific responses."
20)
21
22user_input = f"{PROMPT_INSTRUCTION}\n\nTitle: {title}\nAbstract: {abstract}"
23
24tokenizer = AutoTokenizer.from_pretrained(repo_id, use_fast=True)
25model = AutoModelForCausalLM.from_pretrained(
26 repo_id,
27 dtype=torch.float16,
28 device_map="auto",
29)
30model.eval()
31
32chat = tokenizer.apply_chat_template(
33 [
34 {"role": "system", "content": SYS_PROMPT},
35 {"role": "user", "content": user_input},
36 ],
37 tokenize=False,
38 add_generation_prompt=True,
39)
40
41inputs = tokenizer(chat, return_tensors="pt", truncation=True, max_length=1024)
42inputs = {k: v.to(model.get_input_embeddings().weight.device) for k, v in inputs.items()}
43
44with torch.no_grad():
45 outputs = model.generate(
46 **inputs,
47 max_new_tokens=200,
48 do_sample=False,
49 pad_token_id=tokenizer.eos_token_id,
50 )
51
52prediction = tokenizer.decode(
53 outputs[0][inputs["input_ids"].shape[1]:],
54 skip_special_tokens=True
55).strip()
56
57print(json.dumps(json.loads(prediction), indent=2, ensure_ascii=False))
58r): 82e-451from transformers import AutoTokenizer, AutoModelForCausalLM
2import torch
3
4repo_id = "RehanaHasin/mistral-7b-instruct-v0.3-adjuvant-extractor"
5
6tokenizer = AutoTokenizer.from_pretrained(repo_id)
7model = AutoModelForCausalLM.from_pretrained(
8 repo_id,
9 torch_dtype=torch.float16,
10 device_map="auto",
11)adjuvantevidence