RobCzikkel
commited on
Commit
•
5ae6680
1
Parent(s):
1114470
Update README.md
Browse files
README.md
CHANGED
@@ -31,6 +31,52 @@ The prompt used is as follows:
|
|
31 |
"""
|
32 |
```
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
## Intended uses & limitations
|
35 |
|
36 |
This is a private project for fine-tuning a medical language model, it is not intended to be used as a source medical advice.
|
|
|
31 |
"""
|
32 |
```
|
33 |
|
34 |
+
## Inference
|
35 |
+
|
36 |
+
The fine-tuned model has a saved generation config, to use it:
|
37 |
+
```py
|
38 |
+
model_config = GenerationConfig.from_pretrained(
|
39 |
+
DoctorGPT
|
40 |
+
)
|
41 |
+
```
|
42 |
+
|
43 |
+
This config is a diverse beam search strategy:
|
44 |
+
```py
|
45 |
+
diversebeamConfig = GenerationConfig(
|
46 |
+
min_length=20,
|
47 |
+
max_length=256,
|
48 |
+
do_sample=False,
|
49 |
+
num_beams=4,
|
50 |
+
num_beam_groups=4,
|
51 |
+
diversity_penalty=1.0,
|
52 |
+
repetition_penalty=3.0,
|
53 |
+
eos_token_id=model.config.eos_token_id,
|
54 |
+
pad_token_id=model.config.pad_token_id,
|
55 |
+
bos_token_id=model.config.bos_token_id,
|
56 |
+
)
|
57 |
+
```
|
58 |
+
|
59 |
+
For best results, please use this as your generator function:
|
60 |
+
```py
|
61 |
+
def generate(query):
|
62 |
+
sys = "You are a Doctor. Below is a question from a patient. Write a response to the patient that answers their question\n\n"
|
63 |
+
patient = f"### Patient:\n{query}\n\n"
|
64 |
+
doctor = f"### Doctor:\n "
|
65 |
+
|
66 |
+
prompt = sys+patient+doctor
|
67 |
+
|
68 |
+
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
|
69 |
+
generated_ids = model.generate(
|
70 |
+
**inputs,
|
71 |
+
generation_config=generation_config,
|
72 |
+
)
|
73 |
+
outputs = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)
|
74 |
+
answer = '.'.join(answer.split('.')[:-1])
|
75 |
+
torch.cuda.empty_cache()
|
76 |
+
return answer + "."
|
77 |
+
```
|
78 |
+
|
79 |
+
|
80 |
## Intended uses & limitations
|
81 |
|
82 |
This is a private project for fine-tuning a medical language model, it is not intended to be used as a source medical advice.
|