ImranzamanML
commited on
Commit
•
00268e0
1
Parent(s):
d5ae0db
Update README.md
Browse files
README.md
CHANGED
@@ -11,12 +11,57 @@ tags:
|
|
11 |
- trl
|
12 |
---
|
13 |
|
14 |
-
|
|
|
|
|
|
|
15 |
|
16 |
-
|
17 |
-
- **License:** apache-2.0
|
18 |
-
- **Finetuned from model :** unsloth/Llama-3.2-1B-bnb-4bit
|
19 |
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
-
[<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
|
|
|
11 |
- trl
|
12 |
---
|
13 |
|
14 |
+
<div class="alert alert-block alert-danger">
|
15 |
+
<h2><center><strong>Mental Health Chatbot using 1B finetuned Llama 3.2 Model</strong></center></h2>
|
16 |
+
|
17 |
+
</div>
|
18 |
|
19 |
+
## Inference
|
|
|
|
|
20 |
|
21 |
+
```python
|
22 |
+
from unsloth import FastLanguageModel
|
23 |
+
model, tokenizer = FastLanguageModel.from_pretrained(
|
24 |
+
model_name = "ImranzamanML/1B_finetuned_llama3.2",
|
25 |
+
max_seq_length = 5020,
|
26 |
+
dtype = None,
|
27 |
+
load_in_4bit = True)
|
28 |
+
```
|
29 |
+
|
30 |
+
|
31 |
+
## Using this text to feed into model for getting the response
|
32 |
+
|
33 |
+
text="I'm going through some things with my feelings and myself. I barely sleep and I do nothing but think about how I'm worthless and how I shouldn't be here. I've never tried or contemplated suicide. I've always wanted to fix my issues, but I never get around to it. How can I change my feeling of being worthless to everyone?"
|
34 |
+
|
35 |
+
<div style="background-color: #f2f2f2; border-left: 5px solid #4CAF50; padding: 15px; margin: 20px 0;">
|
36 |
+
<strong>Note:</strong> Lets use the fine-tuned model for inference in order to generate responses based on mental health-related prompts !
|
37 |
+
</div>
|
38 |
+
|
39 |
+
<h3 style="color: #388e3c; font-family: Arial, sans-serif;">Here is some keys to note:</h3>
|
40 |
+
|
41 |
+
<ol style="margin-left: 20px;">
|
42 |
+
<p>The <code>model = FastLanguageModel.for_inference(model)</code> configures the model specifically for inference, optimizing its performance for generating responses.</p>
|
43 |
+
</li>
|
44 |
+
<p>The input text is tokenized using the <code>tokenizer</code>, it convert the text into a format that model can process. We are using <code>data_prompt</code> to format the input text, while the response placeholder is left empty to get response from model. The <code>return_tensors = "pt"</code> parameter specifies that the output should be in PyTorch tensors, which are then moved to the GPU using <code>.to("cuda")</code> for faster processing.</p>
|
45 |
+
</li>
|
46 |
+
<p>The <code>model.generate</code> method generating response based on the tokenized inputs. The parameters <code>max_new_tokens = 5020</code> and <code>use_cache = True</code> ensure that the model can produce long and coherent responses efficiently by utilizing cached computation from previous layers.</p>
|
47 |
+
</li>
|
48 |
+
</ol>
|
49 |
+
|
50 |
+
```python
|
51 |
+
model = FastLanguageModel.for_inference(model)
|
52 |
+
inputs = tokenizer(
|
53 |
+
[
|
54 |
+
data_prompt.format(
|
55 |
+
#instructions
|
56 |
+
text,
|
57 |
+
#answer
|
58 |
+
"",
|
59 |
+
)
|
60 |
+
], return_tensors = "pt").to("cuda")
|
61 |
+
|
62 |
+
outputs = model.generate(**inputs, max_new_tokens = 5020, use_cache = True)
|
63 |
+
answer=tokenizer.batch_decode(outputs)
|
64 |
+
answer = answer[0].split("### Response:")[-1]
|
65 |
+
print("Answer of the question is:", answer)
|
66 |
+
```
|
67 |
|
|