NimaZahedinameghi
commited on
Commit
•
153fb28
1
Parent(s):
bb0f2d1
Update README.md
Browse files
README.md
CHANGED
@@ -121,8 +121,8 @@ This model is built by [Nima Zahedinameghi](https://www.linkedin.com/in/nima-zah
|
|
121 |
It achieves the following results on the evaluation set:
|
122 |
- Loss: 0.5867, after 3 epochs.
|
123 |
|
124 |
-
##
|
125 |
-
|
126 |
``` txt
|
127 |
transformers==4.36.2
|
128 |
datasets==2.15.0
|
@@ -135,6 +135,46 @@ sentencepiece==0.1.99
|
|
135 |
protobuf==4.23.4 --upgrade
|
136 |
```
|
137 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
138 |
## Model description
|
139 |
|
140 |
the model is fine tuned on a small dataset with 4bit precision.
|
|
|
121 |
It achieves the following results on the evaluation set:
|
122 |
- Loss: 0.5867, after 3 epochs.
|
123 |
|
124 |
+
## How to use the model
|
125 |
+
1. **Pip install the required dependencies**
|
126 |
``` txt
|
127 |
transformers==4.36.2
|
128 |
datasets==2.15.0
|
|
|
135 |
protobuf==4.23.4 --upgrade
|
136 |
```
|
137 |
|
138 |
+
|
139 |
+
2. **Load the Model and Tokenizer:**
|
140 |
+
```python
|
141 |
+
from peft import AutoPeftModelForCausalLM
|
142 |
+
from transformers import AutoTokenizer
|
143 |
+
|
144 |
+
model_id = 'NimaZahedinameghi/source_of_injury'
|
145 |
+
model = AutoPeftModelForCausalLM.from_pretrained(model_id).cuda()
|
146 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
147 |
+
tokenizer.pad_token = tokenizer.eos_token
|
148 |
+
```
|
149 |
+
|
150 |
+
3. **Define the Prompt Function:**
|
151 |
+
Create a function to structure your prompt correctly:
|
152 |
+
```python
|
153 |
+
def prompt(incident_description):
|
154 |
+
return f"""[INST] <<SYS>>
|
155 |
+
Workers Compensation Board of Manitoba manages claims by reviewing incident descriptions submitted by workers. Claim coders review the incident description and populate a database with reasoning towards determining the source of injury (InjurySource).
|
156 |
+
<</SYS>>
|
157 |
+
|
158 |
+
IncidentDescription: {incident_description}
|
159 |
+
[/INST]
|
160 |
+
"""
|
161 |
+
|
162 |
+
def prompt_tok(incident_description):
|
163 |
+
_p = prompt(incident_description)
|
164 |
+
input_ids = tokenizer(_p, return_tensors="pt", truncation=True).input_ids.cuda()
|
165 |
+
out_ids = model.generate(input_ids=input_ids, max_new_tokens=500, do_sample=False)
|
166 |
+
return tokenizer.batch_decode(out_ids.detach().cpu().numpy(), skip_special_tokens=True)[0][len(_p):]
|
167 |
+
```
|
168 |
+
|
169 |
+
4. **Make Predictions:**
|
170 |
+
Use the function to get predictions from your model:
|
171 |
+
```python
|
172 |
+
incident_description = "While working on a vehicle repair, I had to contort my body to access hard-to-reach areas. This position caused severe discomfort and pain in my neck and shoulders."
|
173 |
+
output = prompt_tok(incident_description)
|
174 |
+
print(output)
|
175 |
+
```
|
176 |
+
|
177 |
+
This function will take an incident description and return the reasoning and injury source as determined by your fine-tuned model. Ensure you follow the specific prompt format that matches your training setup.
|
178 |
## Model description
|
179 |
|
180 |
the model is fine tuned on a small dataset with 4bit precision.
|