walid-iguider
commited on
Commit
•
9bf0270
1
Parent(s):
ed5db7d
Update README.md
Browse files
README.md
CHANGED
@@ -32,6 +32,49 @@ Here's a breakdown of the performance metrics:
|
|
32 |
|:----------------------------|:----------------------|:----------------|:---------------------|:--------|
|
33 |
| **Accuracy Normalized** | 0.5841 | 0.4414 | 0.5365 | 0.5250 |
|
34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
This model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
|
36 |
|
37 |
[<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
|
|
|
32 |
|:----------------------------|:----------------------|:----------------|:---------------------|:--------|
|
33 |
| **Accuracy Normalized** | 0.5841 | 0.4414 | 0.5365 | 0.5250 |
|
34 |
|
35 |
+
---
|
36 |
+
|
37 |
+
## How to Use
|
38 |
+
|
39 |
+
```python
|
40 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig
|
41 |
+
import torch
|
42 |
+
|
43 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
44 |
+
|
45 |
+
tokenizer = AutoTokenizer.from_pretrained("FairMind/Phi-3-mini-4k-instruct-bnb-4bit-Ita")
|
46 |
+
model = AutoModelForCausalLM.from_pretrained("FairMind/Phi-3-mini-4k-instruct-bnb-4bit-Ita")
|
47 |
+
model.to(device)
|
48 |
+
|
49 |
+
|
50 |
+
generation_config = GenerationConfig(
|
51 |
+
penalty_alpha=0.6, # The values balance the model confidence and the degeneration penalty in contrastive search decoding.
|
52 |
+
do_sample = True, # Whether or not to use sampling ; use greedy decoding otherwise.
|
53 |
+
top_k=5, # The number of highest probability vocabulary tokens to keep for top-k-filtering.
|
54 |
+
temperature=0.001, # The value used to modulate the next token probabilities.
|
55 |
+
repetition_penalty=1.7, # The parameter for repetition penalty. 1.0 means no penalty.
|
56 |
+
max_new_tokens = 64, # The maximum numbers of tokens to generate, ignoring the number of tokens in the prompt.
|
57 |
+
eos_token_id=tokenizer.eos_token_id, # The id of the *end-of-sequence* token.
|
58 |
+
pad_token_id=tokenizer.eos_token_id, # The id of the *padding* token.
|
59 |
+
)
|
60 |
+
|
61 |
+
|
62 |
+
def generate_answer(question):
|
63 |
+
messages = [
|
64 |
+
{"role": "user", "content": question},
|
65 |
+
]
|
66 |
+
model_inputs = tokenizer.apply_chat_template(messages, return_tensors="pt").to(device)
|
67 |
+
outputs = model.generate(model_inputs, generation_config=generation_config)
|
68 |
+
result = tokenizer.batch_decode(outputs, skip_special_tokens=True)[0]
|
69 |
+
return result
|
70 |
+
|
71 |
+
|
72 |
+
question = """Quale è la torre più famosa di Parigi?"""
|
73 |
+
answer = generate_answer(question)
|
74 |
+
print(answer)
|
75 |
+
```
|
76 |
+
---
|
77 |
+
|
78 |
This model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
|
79 |
|
80 |
[<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
|