szymonrucinski
commited on
Commit
•
26cc4d0
1
Parent(s):
9b8ca87
Update README.md
Browse files
README.md
CHANGED
@@ -36,6 +36,34 @@ text = "<s>[INST] Czy warto się uczyć? [/INST]"
|
|
36 |
|
37 |
From my experience the temperature value of 0.7 is the best baseline value.
|
38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
## Use a pipeline as a high-level helper
|
41 |
```
|
|
|
36 |
|
37 |
From my experience the temperature value of 0.7 is the best baseline value.
|
38 |
|
39 |
+
## Optimal text generation
|
40 |
+
```
|
41 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
42 |
+
import torch
|
43 |
+
torch_device = "cuda" if torch.cuda.is_available() else "cpu"
|
44 |
+
|
45 |
+
chat_tokenizer = AutoTokenizer.from_pretrained("mistralai/Mistral-7B-Instruct-v0.1")
|
46 |
+
messages = [
|
47 |
+
{"role": "user", "content": "Czy warto nauczyć się jeździć na nartach w wieku 25 lat?"},
|
48 |
+
]
|
49 |
+
chat_tokenized = tokenizer.apply_chat_template(messages, tokenize=False)
|
50 |
+
|
51 |
+
model = AutoModelForCausalLM.from_pretrained("szymonrucinski/krakowiak-v2-7b")
|
52 |
+
tokenizer = AutoTokenizer.from_pretrained("szymonrucinski/krakowiak-v2-7b",add_eos_token=True)
|
53 |
+
tokenizer.pad_token = tokenizer.eos_token
|
54 |
+
|
55 |
+
beam_outputs = model.generate(
|
56 |
+
**model_inputs,
|
57 |
+
max_new_tokens=1024,
|
58 |
+
num_beams=5,
|
59 |
+
no_repeat_ngram_size=2,
|
60 |
+
num_return_sequences=1,
|
61 |
+
early_stopping=True
|
62 |
+
)
|
63 |
+
model_inputs = tokenizer(chat_tokenized, return_tensors='pt').to(torch_device)
|
64 |
+
print(tokenizer.decode(beam_outputs[0], skip_special_tokens=True))
|
65 |
+
|
66 |
+
```
|
67 |
|
68 |
## Use a pipeline as a high-level helper
|
69 |
```
|