Update README.md
Browse files
README.md
CHANGED
@@ -9,6 +9,76 @@ tags:
|
|
9 |
- medical
|
10 |
- doctor
|
11 |
- chat
|
|
|
|
|
12 |
---
|
13 |
|
14 |
-
# BioGPT (Large) fine-tuned on ChatDoctor
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
- medical
|
10 |
- doctor
|
11 |
- chat
|
12 |
+
- qa
|
13 |
+
- question-answering
|
14 |
---
|
15 |
|
16 |
+
# BioGPT (Large) fine-tuned on ChatDoctor for QA
|
17 |
+
|
18 |
+
Microsoft's BioGPT Large fine-tuned on ChatDoctor dataset for Question Answering.
|
19 |
+
|
20 |
+
|
21 |
+
## Intended Use
|
22 |
+
|
23 |
+
This is just a research model and does **NOT** have to be used out of this scope.
|
24 |
+
|
25 |
+
|
26 |
+
## Limitations
|
27 |
+
|
28 |
+
TBA
|
29 |
+
|
30 |
+
## Model
|
31 |
+
|
32 |
+
Pre-trained language models have attracted increasing attention in the biomedical domain, inspired by their great success in the general natural language domain. Among the two main branches of pre-trained language models in the general language domain, i.e. BERT (and its variants) and GPT (and its variants), the first one has been extensively studied in the biomedical domain, such as BioBERT and PubMedBERT. While they have achieved great success on a variety of discriminative downstream biomedical tasks, the lack of generation ability constrains their application scope. In this paper, we propose BioGPT, a domain-specific generative Transformer language model pre-trained on large-scale biomedical literature. We evaluate BioGPT on six biomedical natural language processing tasks and demonstrate that our model outperforms previous models on most tasks. Especially, we get 44.98%, 38.42% and 40.76% F1 score on BC5CDR, KD-DTI and DDI end-to-end relation extraction tasks, respectively, and 78.2% accuracy on PubMedQA, creating a new record. Our case study on text generation further demonstrates the advantage of BioGPT on biomedical literature to generate fluent descriptions for biomedical terms.
|
33 |
+
|
34 |
+
|
35 |
+
## Dataset
|
36 |
+
|
37 |
+
ChatDoctor-200K dataset is collected from this paper https://arxiv.org/pdf/2303.14070.pdf
|
38 |
+
|
39 |
+
|
40 |
+
## Usage
|
41 |
+
```py
|
42 |
+
import torch
|
43 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, GenerationConfig
|
44 |
+
|
45 |
+
|
46 |
+
model_id = "Narrativaai/BioGPT-Large-finetuned-chatdoctor"
|
47 |
+
|
48 |
+
tokenizer = AutoTokenizer.from_pretrained("microsoft/BioGPT-Large")
|
49 |
+
|
50 |
+
model = AutoModelForCausalLM.from_pretrained(model_id)
|
51 |
+
|
52 |
+
def generate(
|
53 |
+
prompt,
|
54 |
+
temperature=0.1,
|
55 |
+
top_p=0.75,
|
56 |
+
top_k=40,
|
57 |
+
num_beams=2,
|
58 |
+
**kwargs,
|
59 |
+
):
|
60 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
61 |
+
input_ids = inputs["input_ids"].to("cuda")
|
62 |
+
attention_mask = inputs["attention_mask"].to("cuda")
|
63 |
+
generation_config = GenerationConfig(
|
64 |
+
temperature=temperature,
|
65 |
+
top_p=top_p,
|
66 |
+
top_k=top_k,
|
67 |
+
num_beams=num_beams,
|
68 |
+
**kwargs,
|
69 |
+
)
|
70 |
+
with torch.no_grad():
|
71 |
+
generation_output = model.generate(
|
72 |
+
input_ids=input_ids,
|
73 |
+
attention_mask=attention_mask,
|
74 |
+
generation_config=generation_config,
|
75 |
+
return_dict_in_generate=True,
|
76 |
+
output_scores=True,
|
77 |
+
max_new_tokens=512,
|
78 |
+
eos_token_id=tokenizer.eos_token_id
|
79 |
+
|
80 |
+
)
|
81 |
+
s = generation_output.sequences[0]
|
82 |
+
output = tokenizer.decode(s, skip_special_tokens=True)
|
83 |
+
return output.split(" Response:")[1]
|
84 |
+
```
|