Update README.md
Browse files
README.md
CHANGED
@@ -18,31 +18,64 @@ The Medical-Mixtral-7B-v1.5k is a fine-tuned Mixtral model for answering medical
|
|
18 |
|
19 |
### Model Sources [optional]
|
20 |
|
|
|
|
|
21 |
## How to Get Started with the Model
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
Use the code below to get started with the model.
|
24 |
|
25 |
```python
|
26 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
|
27 |
|
28 |
# Define the name of your fine-tuned model
|
29 |
finetuned_model = 'ruslanmv/Medical-Mixtral-7B-v1.5k'
|
30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
# Load tokenizer
|
32 |
tokenizer = AutoTokenizer.from_pretrained(finetuned_model, trust_remote_code=True)
|
33 |
|
34 |
-
#
|
35 |
-
model_pretrained
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
]
|
41 |
|
42 |
-
|
|
|
43 |
|
44 |
-
|
45 |
-
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
46 |
```
|
47 |
|
48 |
|
|
|
18 |
|
19 |
### Model Sources [optional]
|
20 |
|
21 |
+
|
22 |
+
|
23 |
## How to Get Started with the Model
|
24 |
|
25 |
+
Installation
|
26 |
+
|
27 |
+
```
|
28 |
+
pip install -qU transformers==4.36.2 datasets python-dotenv peft bitsandbytes accelerate
|
29 |
+
```
|
30 |
+
|
31 |
Use the code below to get started with the model.
|
32 |
|
33 |
```python
|
34 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline, logging, BitsAndBytesConfig
|
35 |
+
import os, torch
|
36 |
|
37 |
# Define the name of your fine-tuned model
|
38 |
finetuned_model = 'ruslanmv/Medical-Mixtral-7B-v1.5k'
|
39 |
|
40 |
+
# Load fine-tuned model
|
41 |
+
bnb_config = BitsAndBytesConfig(
|
42 |
+
load_in_4bit=True,
|
43 |
+
bnb_4bit_quant_type="nf4",
|
44 |
+
bnb_4bit_compute_dtype=torch.bfloat16,
|
45 |
+
bnb_4bit_use_double_quant=False,
|
46 |
+
)
|
47 |
+
model_pretrained = AutoModelForCausalLM.from_pretrained(
|
48 |
+
finetuned_model,
|
49 |
+
load_in_4bit=True,
|
50 |
+
quantization_config=bnb_config,
|
51 |
+
torch_dtype=torch.bfloat16,
|
52 |
+
device_map="auto",
|
53 |
+
trust_remote_code=True
|
54 |
+
)
|
55 |
+
|
56 |
# Load tokenizer
|
57 |
tokenizer = AutoTokenizer.from_pretrained(finetuned_model, trust_remote_code=True)
|
58 |
|
59 |
+
# Set pad_token_id to eos_token_id
|
60 |
+
model_pretrained.config.pad_token_id = tokenizer.eos_token_id
|
61 |
+
|
62 |
+
pipe = pipeline(task="text-generation", model=model_pretrained, tokenizer=tokenizer, max_length=100)
|
63 |
+
|
64 |
+
def build_prompt(question):
|
65 |
+
prompt=f"[INST]@Enlighten. {question} [/INST]"
|
66 |
+
return prompt
|
67 |
+
|
68 |
+
question = "What does abutment of the nerve root mean?"
|
69 |
+
prompt = build_prompt(question)
|
70 |
|
71 |
+
# Generate text based on the prompt
|
72 |
+
result = pipe(prompt)[0]
|
73 |
+
generated_text = result['generated_text']
|
|
|
74 |
|
75 |
+
# Remove the prompt from the generated text
|
76 |
+
generated_text = generated_text.replace(prompt, "", 1).strip()
|
77 |
|
78 |
+
print(generated_text)
|
|
|
79 |
```
|
80 |
|
81 |
|