Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,148 @@
|
|
1 |
-
---
|
2 |
-
license: apache-2.0
|
3 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: apache-2.0
|
3 |
+
---
|
4 |
+
|
5 |
+
From:
|
6 |
+
https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.3
|
7 |
+
|
8 |
+
---
|
9 |
+
license: apache-2.0
|
10 |
+
---
|
11 |
+
|
12 |
+
# Model Card for Mistral-7B-Instruct-v0.3
|
13 |
+
|
14 |
+
The Mistral-7B-Instruct-v0.3 Large Language Model (LLM) is an instruct fine-tuned version of the Mistral-7B-v0.3.
|
15 |
+
|
16 |
+
Mistral-7B-v0.3 has the following changes compared to [Mistral-7B-v0.2](https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.2/edit/main/README.md)
|
17 |
+
- Extended vocabulary to 32768
|
18 |
+
- Supports v3 Tokenizer
|
19 |
+
- Supports function calling
|
20 |
+
|
21 |
+
## Installation
|
22 |
+
|
23 |
+
It is recommended to use `mistralai/Mistral-7B-Instruct-v0.3` with [mistral-inference](https://github.com/mistralai/mistral-inference). For HF transformers code snippets, please keep scrolling.
|
24 |
+
|
25 |
+
```
|
26 |
+
pip install mistral_inference
|
27 |
+
```
|
28 |
+
|
29 |
+
## Download
|
30 |
+
|
31 |
+
```py
|
32 |
+
from huggingface_hub import snapshot_download
|
33 |
+
from pathlib import Path
|
34 |
+
|
35 |
+
mistral_models_path = Path.home().joinpath('mistral_models', '7B-Instruct-v0.3')
|
36 |
+
mistral_models_path.mkdir(parents=True, exist_ok=True)
|
37 |
+
|
38 |
+
snapshot_download(repo_id="mistralai/Mistral-7B-Instruct-v0.3", allow_patterns=["params.json", "consolidated.safetensors", "tokenizer.model.v3"], local_dir=mistral_models_path)
|
39 |
+
```
|
40 |
+
|
41 |
+
### Chat
|
42 |
+
|
43 |
+
After installing `mistral_inference`, a `mistral-chat` CLI command should be available in your environment. You can chat with the model using
|
44 |
+
|
45 |
+
```
|
46 |
+
mistral-chat $HOME/mistral_models/7B-Instruct-v0.3 --instruct --max_tokens 256
|
47 |
+
```
|
48 |
+
|
49 |
+
### Instruct following
|
50 |
+
|
51 |
+
```py
|
52 |
+
from mistral_inference.model import Transformer
|
53 |
+
from mistral_inference.generate import generate
|
54 |
+
|
55 |
+
from mistral_common.tokens.tokenizers.mistral import MistralTokenizer
|
56 |
+
from mistral_common.protocol.instruct.messages import UserMessage
|
57 |
+
from mistral_common.protocol.instruct.request import ChatCompletionRequest
|
58 |
+
|
59 |
+
|
60 |
+
tokenizer = MistralTokenizer.from_file(f"{mistral_models_path}/tokenizer.model.v3")
|
61 |
+
model = Transformer.from_folder(mistral_models_path)
|
62 |
+
|
63 |
+
completion_request = ChatCompletionRequest(messages=[UserMessage(content="Explain Machine Learning to me in a nutshell.")])
|
64 |
+
|
65 |
+
tokens = tokenizer.encode_chat_completion(completion_request).tokens
|
66 |
+
|
67 |
+
out_tokens, _ = generate([tokens], model, max_tokens=64, temperature=0.0, eos_id=tokenizer.instruct_tokenizer.tokenizer.eos_id)
|
68 |
+
result = tokenizer.instruct_tokenizer.tokenizer.decode(out_tokens[0])
|
69 |
+
|
70 |
+
print(result)
|
71 |
+
```
|
72 |
+
|
73 |
+
### Function calling
|
74 |
+
|
75 |
+
```py
|
76 |
+
from mistral_common.protocol.instruct.tool_calls import Function, Tool
|
77 |
+
from mistral_inference.model import Transformer
|
78 |
+
from mistral_inference.generate import generate
|
79 |
+
|
80 |
+
from mistral_common.tokens.tokenizers.mistral import MistralTokenizer
|
81 |
+
from mistral_common.protocol.instruct.messages import UserMessage
|
82 |
+
from mistral_common.protocol.instruct.request import ChatCompletionRequest
|
83 |
+
|
84 |
+
|
85 |
+
tokenizer = MistralTokenizer.from_file(f"{mistral_models_path}/tokenizer.model.v3")
|
86 |
+
model = Transformer.from_folder(mistral_models_path)
|
87 |
+
|
88 |
+
completion_request = ChatCompletionRequest(
|
89 |
+
tools=[
|
90 |
+
Tool(
|
91 |
+
function=Function(
|
92 |
+
name="get_current_weather",
|
93 |
+
description="Get the current weather",
|
94 |
+
parameters={
|
95 |
+
"type": "object",
|
96 |
+
"properties": {
|
97 |
+
"location": {
|
98 |
+
"type": "string",
|
99 |
+
"description": "The city and state, e.g. San Francisco, CA",
|
100 |
+
},
|
101 |
+
"format": {
|
102 |
+
"type": "string",
|
103 |
+
"enum": ["celsius", "fahrenheit"],
|
104 |
+
"description": "The temperature unit to use. Infer this from the users location.",
|
105 |
+
},
|
106 |
+
},
|
107 |
+
"required": ["location", "format"],
|
108 |
+
},
|
109 |
+
)
|
110 |
+
)
|
111 |
+
],
|
112 |
+
messages=[
|
113 |
+
UserMessage(content="What's the weather like today in Paris?"),
|
114 |
+
],
|
115 |
+
)
|
116 |
+
|
117 |
+
tokens = tokenizer.encode_chat_completion(completion_request).tokens
|
118 |
+
|
119 |
+
out_tokens, _ = generate([tokens], model, max_tokens=64, temperature=0.0, eos_id=tokenizer.instruct_tokenizer.tokenizer.eos_id)
|
120 |
+
result = tokenizer.instruct_tokenizer.tokenizer.decode(out_tokens[0])
|
121 |
+
|
122 |
+
print(result)
|
123 |
+
```
|
124 |
+
|
125 |
+
## Generate with `transformers`
|
126 |
+
|
127 |
+
If you want to use Hugging Face `transformers` to generate text, you can do something like this.
|
128 |
+
|
129 |
+
```py
|
130 |
+
from transformers import pipeline
|
131 |
+
|
132 |
+
messages = [
|
133 |
+
{"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
|
134 |
+
{"role": "user", "content": "Who are you?"},
|
135 |
+
]
|
136 |
+
chatbot = pipeline("text-generation", model="mistralai/Mistral-7B-Instruct-v0.3")
|
137 |
+
chatbot(messages)
|
138 |
+
```
|
139 |
+
|
140 |
+
## Limitations
|
141 |
+
|
142 |
+
The Mistral 7B Instruct model is a quick demonstration that the base model can be easily fine-tuned to achieve compelling performance.
|
143 |
+
It does not have any moderation mechanisms. We're looking forward to engaging with the community on ways to
|
144 |
+
make the model finely respect guardrails, allowing for deployment in environments requiring moderated outputs.
|
145 |
+
|
146 |
+
## The Mistral AI Team
|
147 |
+
|
148 |
+
Albert Jiang, Alexandre Sablayrolles, Alexis Tacnet, Antoine Roux, Arthur Mensch, Audrey Herblin-Stoop, Baptiste Bout, Baudouin de Monicault, Blanche Savary, Bam4d, Caroline Feldman, Devendra Singh Chaplot, Diego de las Casas, Eleonore Arcelin, Emma Bou Hanna, Etienne Metzger, Gianna Lengyel, Guillaume Bour, Guillaume Lample, Harizo Rajaona, Jean-Malo Delignon, Jia Li, Justus Murke, Louis Martin, Louis Ternon, Lucile Saulnier, Lélio Renard Lavaud, Margaret Jennings, Marie Pellat, Marie Torelli, Marie-Anne Lachaux, Nicolas Schuhl, Patrick von Platen, Pierre Stock, Sandeep Subramanian, Sophia Yang, Szymon Antoniak, Teven Le Scao, Thibaut Lavril, Timothée Lacroix, Théophile Gervet, Thomas Wang, Valera Nemychnikova, William El Sayed, William Marshall
|