Rocketknight1 HF Staff commited on
Commit
c9a5bd0
·
verified ·
1 Parent(s): b30991b

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +23 -14
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 MistralForCausalLM
51
- from transformers import AutoTokenizer
52
 
53
- tokenizer = AutoTokenizer.from_pretrained('mistralai/mathstral-7B-v0.1')
 
54
 
55
- prompt = "What are the roots of unity?"
56
- tokenized_prompts = tokenizer(prompt, return_tensors="pt")
57
 
58
- model = MistralForCausalLM.from_pretrained('mistralai/mathstral-7B-v0.1')
59
- generation = model.generate(**tokenized_prompts, max_new_tokens=512)
60
- print(tokenizer.decode(generation[0]))
61
- >>> """<s>What are the roots of unity?
 
 
 
 
 
62
 
63
- The roots of unity are the solutions to the equation $z^n = 1$, where $n$ is a positive integer.
64
- These roots are complex numbers and they form a regular $n$-gon in the complex plane.
 
65
 
66
- For example, the roots of unity for $n=1$ are just $1$,
67
- and for $n=2$ they are $1$ and $-1$. For $n=3$, they are $1$, $\\frac{-1+\\sqrt{3}i}{2}$, and $\\frac{-1-\\sqrt{3}i}{2}$.
68
 
69
- The roots of unity have many interesting properties and they are used in many areas of mathematics, including number theory, algebra, and geometry.</s>"""
 
 
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