Update README.md
Browse files
README.md
CHANGED
|
@@ -47,26 +47,35 @@ You can then start chatting with the model, *e.g.* prompt it with something like
|
|
| 47 |
To use this model within the `transformers` library, install the latest release with `pip install --upgrade transformers` and run, for instance:
|
| 48 |
|
| 49 |
```py
|
| 50 |
-
from transformers import
|
| 51 |
-
|
| 52 |
|
| 53 |
-
|
|
|
|
| 54 |
|
| 55 |
-
prompt = "What are the roots of unity?"
|
| 56 |
-
|
| 57 |
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
-
|
| 64 |
-
|
|
|
|
| 65 |
|
| 66 |
-
|
| 67 |
-
|
| 68 |
|
| 69 |
-
|
|
|
|
|
|
|
| 70 |
```
|
| 71 |
|
| 72 |
## Evaluation
|
|
|
|
| 47 |
To use this model within the `transformers` library, install the latest release with `pip install --upgrade transformers` and run, for instance:
|
| 48 |
|
| 49 |
```py
|
| 50 |
+
from transformers import pipeline
|
| 51 |
+
import torch
|
| 52 |
|
| 53 |
+
checkpoint = "mistralai/mathstral-7B-v0.1"
|
| 54 |
+
pipe = pipeline("text-generation", checkpoint, device_map="auto", torch_dtype=torch.bfloat16)
|
| 55 |
|
| 56 |
+
prompt = [{"role": "user", "content": "What are the roots of unity?"}]
|
| 57 |
+
out = pipe(prompt, max_new_tokens = 512)
|
| 58 |
|
| 59 |
+
print(out[0]['generated_text'][-1])
|
| 60 |
+
>>> "{'role': 'assistant', 'content': ' The roots of unity are the complex numbers that satisfy the equation $z^n = 1$, where $n$ is a positive integer. These roots are evenly spaced around the unit circle in the complex plane, and they have a variety of interesting properties and applications in mathematics and physics.'}"
|
| 61 |
+
```
|
| 62 |
+
|
| 63 |
+
You can also manually tokenize the input and generate text from the model, rather than using the higher-level pipeline:
|
| 64 |
+
|
| 65 |
+
```py
|
| 66 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 67 |
+
import torch
|
| 68 |
|
| 69 |
+
checkpoint = "mistralai/mathstral-7B-v0.1"
|
| 70 |
+
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
|
| 71 |
+
model = AutoModelForCausalLM.from_pretrained(checkpoint, device_map="auto", torch_dtype=torch.bfloat16)
|
| 72 |
|
| 73 |
+
prompt = [{"role": "user", "content": "What are the roots of unity?"}]
|
| 74 |
+
tokenized_prompt = tokenizer.apply_chat_template(prompt, add_generation_prompt=True, return_dict=True, return_tensors="pt").to(model.device)
|
| 75 |
|
| 76 |
+
out = model.generate(**tokenized_prompt, max_new_tokens=512)
|
| 77 |
+
tokenizer.decode(out[0])
|
| 78 |
+
>>> '<s>[INST] What are the roots of unity?[/INST] The roots of unity are the complex numbers that satisfy the equation $z^n = 1$, where $n$ is a positive integer. These roots are evenly spaced around the unit circle in the complex plane, and they have a variety of interesting properties and applications in mathematics and physics.</s>'
|
| 79 |
```
|
| 80 |
|
| 81 |
## Evaluation
|