jukofyork commited on
Commit
290cccd
1 Parent(s): 06e4ad1

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +7 -329
README.md CHANGED
@@ -1,336 +1,14 @@
1
  ---
2
  library_name: transformers
3
- language:
4
- - en
5
- - fr
6
- - de
7
- - es
8
- - it
9
- - pt
10
- - ja
11
- - ko
12
- - zh
13
- - ar
14
  license: cc-by-nc-4.0
 
 
 
 
15
  ---
16
 
17
- # Model Card for C4AI Command-R
18
 
19
- 🚨 **This model is non-quantized version of C4AI Command-R. You can find the quantized version of C4AI Command-R using bitsandbytes [here](https://huggingface.co/CohereForAI/c4ai-command-r-v01-4bit)**.
20
 
21
- ## Model Summary
22
-
23
- C4AI Command-R is a research release of a 35 billion parameter highly performant generative model. Command-R is a large language model with open weights optimized for a variety of use cases including reasoning, summarization, and question answering. Command-R has the capability for multilingual generation evaluated in 10 languages and highly performant RAG capabilities.
24
-
25
- Developed by: Cohere and [Cohere For AI](https://cohere.for.ai)
26
-
27
- - Point of Contact: Cohere For AI: [cohere.for.ai](https://cohere.for.ai/)
28
- - License: [CC-BY-NC](https://cohere.com/c4ai-cc-by-nc-license), requires also adhering to [C4AI's Acceptable Use Policy](https://docs.cohere.com/docs/c4ai-acceptable-use-policy)
29
- - Model: c4ai-command-r-v01
30
- - Model Size: 35 billion parameters
31
- - Context length: 128K
32
-
33
- **Try C4AI Command R**
34
-
35
- If you want to try Command R before downloading the weights, the model is hosted in a hugging face space [here](https://huggingface.co/spaces/CohereForAI/c4ai-command-r-v01).
36
-
37
- **Usage**
38
-
39
- Please use `transformers` version 4.39.1 or higher
40
- ```python
41
- # pip install 'transformers>=4.39.1'
42
- from transformers import AutoTokenizer, AutoModelForCausalLM
43
-
44
- model_id = "CohereForAI/c4ai-command-r-v01"
45
- tokenizer = AutoTokenizer.from_pretrained(model_id)
46
- model = AutoModelForCausalLM.from_pretrained(model_id)
47
-
48
- # Format message with the command-r chat template
49
- messages = [{"role": "user", "content": "Hello, how are you?"}]
50
- input_ids = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt")
51
- ## <BOS_TOKEN><|START_OF_TURN_TOKEN|><|USER_TOKEN|>Hello, how are you?<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>
52
-
53
- gen_tokens = model.generate(
54
- input_ids,
55
- max_new_tokens=100,
56
- do_sample=True,
57
- temperature=0.3,
58
- )
59
-
60
- gen_text = tokenizer.decode(gen_tokens[0])
61
- print(gen_text)
62
- ```
63
-
64
- **Quantized model through bitsandbytes, 8-bit precision**
65
-
66
- ```python
67
- # pip install 'transformers>=4.39.1' bitsandbytes accelerate
68
- from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
69
-
70
- bnb_config = BitsAndBytesConfig(load_in_8bit=True)
71
-
72
- model_id = "CohereForAI/c4ai-command-r-v01"
73
- tokenizer = AutoTokenizer.from_pretrained(model_id)
74
- model = AutoModelForCausalLM.from_pretrained(model_id, quantization_config=bnb_config)
75
-
76
- # Format message with the command-r chat template
77
- messages = [{"role": "user", "content": "Hello, how are you?"}]
78
- input_ids = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt")
79
- ## <BOS_TOKEN><|START_OF_TURN_TOKEN|><|USER_TOKEN|>Hello, how are you?<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>
80
-
81
- gen_tokens = model.generate(
82
- input_ids,
83
- max_new_tokens=100,
84
- do_sample=True,
85
- temperature=0.3,
86
- )
87
-
88
- gen_text = tokenizer.decode(gen_tokens[0])
89
- print(gen_text)
90
- ```
91
-
92
- **Quantized model through bitsandbytes, 4-bit precision**
93
-
94
- You can find a quantized version of this model to 4-bit precision [here](https://huggingface.co/CohereForAI/c4ai-command-r-v01-4bit).
95
-
96
- ## Model Details
97
-
98
- **Input**: Models input text only.
99
-
100
- **Output**: Models generate text only.
101
-
102
- **Model Architecture**: This is an auto-regressive language model that uses an optimized transformer architecture. After pretraining, this model uses supervised fine-tuning (SFT) and preference training to align model behavior to human preferences for helpfulness and safety.
103
-
104
- **Languages covered**: The model is optimized to perform well in the following languages: English, French, Spanish, Italian, German, Brazilian Portuguese, Japanese, Korean, Simplified Chinese, and Arabic.
105
-
106
- Pre-training data additionally included the following 13 languages: Russian, Polish, Turkish, Vietnamese, Dutch, Czech, Indonesian, Ukrainian, Romanian, Greek, Hindi, Hebrew, Persian.
107
-
108
- **Context length**: Command-R supports a context length of 128K.
109
-
110
- ### Tool use capabilities:
111
-
112
- Command-R has been specifically trained with conversational tool use capabilities. These have been trained into the model via a mixture of supervised fine-tuning and preference fine-tuning, using a specific prompt template. Deviating from this prompt template will likely reduce performance, but we encourage experimentation.
113
-
114
- Command-R’s tool use functionality takes a conversation as input (with an optional user-system preamble), along with a list of available tools. The model will then generate a json-formatted list of actions to execute on a subset of those tools. Command-R may use one of its supplied tools more than once.
115
-
116
- The model has been trained to recognise a special `directly_answer` tool, which it uses to indicate that it doesn’t want to use any of its other tools. The ability to abstain from calling a specific tool can be useful in a range of situations, such as greeting a user, or asking clarifying questions.
117
- We recommend including the `directly_answer` tool, but it can be removed or renamed if required.
118
-
119
- Comprehensive documentation for working with command-R's tool use prompt template can be found [here](https://docs.cohere.com/docs/prompting-command-r).
120
-
121
- The code snippet below shows a minimal working example on how to render a prompt.
122
-
123
- <details>
124
- <summary><b>Usage: Rendering Tool Use Prompts [CLICK TO EXPAND]</b> </summary>
125
-
126
- ```python
127
- from transformers import AutoTokenizer
128
-
129
- model_id = "CohereForAI/c4ai-command-r-v01"
130
- tokenizer = AutoTokenizer.from_pretrained(model_id)
131
-
132
- # define conversation input:
133
- conversation = [
134
- {"role": "user", "content": "Whats the biggest penguin in the world?"}
135
- ]
136
- # Define tools available for the model to use:
137
- tools = [
138
- {
139
- "name": "internet_search",
140
- "description": "Returns a list of relevant document snippets for a textual query retrieved from the internet",
141
- "parameter_definitions": {
142
- "query": {
143
- "description": "Query to search the internet with",
144
- "type": 'str',
145
- "required": True
146
- }
147
- }
148
- },
149
- {
150
- 'name': "directly_answer",
151
- "description": "Calls a standard (un-augmented) AI chatbot to generate a response given the conversation history",
152
- 'parameter_definitions': {}
153
- }
154
- ]
155
-
156
- # render the tool use prompt as a string:
157
- tool_use_prompt = tokenizer.apply_tool_use_template(
158
- conversation,
159
- tools=tools,
160
- tokenize=False,
161
- add_generation_prompt=True,
162
- )
163
- print(tool_use_prompt)
164
- ```
165
-
166
- </details>
167
-
168
- <details>
169
- <summary><b>Example Rendered Tool Use Prompt [CLICK TO EXPAND]</b></summary>
170
-
171
- ````
172
- <BOS_TOKEN><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|># Safety Preamble
173
- The instructions in this section override those in the task description and style guide sections. Don't answer questions that are harmful or immoral.
174
-
175
- # System Preamble
176
- ## Basic Rules
177
- You are a powerful conversational AI trained by Cohere to help people. You are augmented by a number of tools, and your job is to use and consume the output of these tools to best help the user. You will see a conversation history between yourself and a user, ending with an utterance from the user. You will then see a specific instruction instructing you what kind of response to generate. When you answer the user's requests, you cite your sources in your answers, according to those instructions.
178
-
179
- # User Preamble
180
- ## Task and Context
181
- You help people answer their questions and other requests interactively. You will be asked a very wide array of requests on all kinds of topics. You will be equipped with a wide range of search engines or similar tools to help you, which you use to research your answer. You should focus on serving the user's needs as best you can, which will be wide-ranging.
182
-
183
- ## Style Guide
184
- Unless the user asks for a different style of answer, you should answer in full sentences, using proper grammar and spelling.
185
-
186
- ## Available Tools
187
- Here is a list of tools that you have available to you:
188
-
189
- ```python
190
- def internet_search(query: str) -> List[Dict]:
191
- """Returns a list of relevant document snippets for a textual query retrieved from the internet
192
-
193
- Args:
194
- query (str): Query to search the internet with
195
- """
196
- pass
197
- ```
198
-
199
- ```python
200
- def directly_answer() -> List[Dict]:
201
- """Calls a standard (un-augmented) AI chatbot to generate a response given the conversation history
202
- """
203
- pass
204
- ```<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|USER_TOKEN|>Whats the biggest penguin in the world?<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>Write 'Action:' followed by a json-formatted list of actions that you want to perform in order to produce a good response to the user's last input. You can use any of the supplied tools any number of times, but you should aim to execute the minimum number of necessary actions for the input. You should use the `directly-answer` tool if calling the other tools is unnecessary. The list of actions you want to call should be formatted as a list of json objects, for example:
205
- ```json
206
- [
207
- {
208
- "tool_name": title of the tool in the specification,
209
- "parameters": a dict of parameters to input into the tool as they are defined in the specs, or {} if it takes no parameters
210
- }
211
- ]```<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>
212
-
213
- ````
214
-
215
- </details>
216
-
217
- <details>
218
- <summary><b>Example Rendered Tool Use Completion [CLICK TO EXPAND]</b></summary>
219
-
220
- ````
221
- Action: ```json
222
- [
223
- {
224
- "tool_name": "internet_search",
225
- "parameters": {
226
- "query": "biggest penguin in the world"
227
- }
228
- }
229
- ]
230
- ```
231
- ````
232
- </details>
233
-
234
- ### Grounded Generation and RAG Capabilities:
235
-
236
- Command-R has been specifically trained with grounded generation capabilities. This means that it can generate responses based on a list of supplied document snippets, and it will include grounding spans (citations) in its response indicating the source of the information.
237
- This can be used to enable behaviors such as grounded summarization and the final step of Retrieval Augmented Generation (RAG).This behavior has been trained into the model via a mixture of supervised fine-tuning and preference fine-tuning, using a specific prompt template.
238
- Deviating from this prompt template may reduce performance, but we encourage experimentation.
239
-
240
- Command-R’s grounded generation behavior takes a conversation as input (with an optional user-supplied system preamble, indicating task, context and desired output style), along with a list of retrieved document snippets.
241
- The document snippets should be chunks, rather than long documents, typically around 100-400 words per chunk. Document snippets consist of key-value pairs. The keys should be short descriptive strings, the values can be text or semi-structured.
242
-
243
- By default, Command-R will generate grounded responses by first predicting which documents are relevant, then predicting which ones it will cite, then generating an answer.
244
- Finally, it will then insert grounding spans into the answer. See below for an example. This is referred to as `accurate` grounded generation.
245
-
246
- The model is trained with a number of other answering modes, which can be selected by prompt changes . A `fast` citation mode is supported in the tokenizer, which will directly generate an answer with grounding spans in it, without first writing the answer out in full. This sacrifices some grounding accuracy in favor of generating fewer tokens.
247
-
248
- Comprehensive documentation for working with command-R's grounded generation prompt template can be found [here](https://docs.cohere.com/docs/prompting-command-r).
249
-
250
- The code snippet below shows a minimal working example on how to render a prompt.
251
-
252
- <details>
253
- <summary> <b>Usage: Rendering Grounded Generation prompts [CLICK TO EXPAND]</b> </summary>
254
-
255
- ````python
256
- from transformers import AutoTokenizer
257
-
258
- model_id = "CohereForAI/c4ai-command-r-v01"
259
- tokenizer = AutoTokenizer.from_pretrained(model_id)
260
-
261
- # define conversation input:
262
- conversation = [
263
- {"role": "user", "content": "Whats the biggest penguin in the world?"}
264
- ]
265
- # define documents to ground on:
266
- documents = [
267
- { "title": "Tall penguins", "text": "Emperor penguins are the tallest growing up to 122 cm in height." },
268
- { "title": "Penguin habitats", "text": "Emperor penguins only live in Antarctica."}
269
- ]
270
-
271
- # render the tool use prompt as a string:
272
- grounded_generation_prompt = tokenizer.apply_grounded_generation_template(
273
- conversation,
274
- documents=documents,
275
- citation_mode="accurate", # or "fast"
276
- tokenize=False,
277
- add_generation_prompt=True,
278
- )
279
- print(grounded_generation_prompt)
280
- ````
281
- </details>
282
-
283
- <details>
284
- <summary><b>Example Rendered Grounded Generation Prompt [CLICK TO EXPAND]</b></summary>
285
-
286
- ````<BOS_TOKEN><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|># Safety Preamble
287
- The instructions in this section override those in the task description and style guide sections. Don't answer questions that are harmful or immoral.
288
-
289
- # System Preamble
290
- ## Basic Rules
291
- You are a powerful conversational AI trained by Cohere to help people. You are augmented by a number of tools, and your job is to use and consume the output of these tools to best help the user. You will see a conversation history between yourself and a user, ending with an utterance from the user. You will then see a specific instruction instructing you what kind of response to generate. When you answer the user's requests, you cite your sources in your answers, according to those instructions.
292
-
293
- # User Preamble
294
- ## Task and Context
295
- You help people answer their questions and other requests interactively. You will be asked a very wide array of requests on all kinds of topics. You will be equipped with a wide range of search engines or similar tools to help you, which you use to research your answer. You should focus on serving the user's needs as best you can, which will be wide-ranging.
296
-
297
- ## Style Guide
298
- Unless the user asks for a different style of answer, you should answer in full sentences, using proper grammar and spelling.<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|USER_TOKEN|>Whats the biggest penguin in the world?<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|><results>
299
- Document: 0
300
- title: Tall penguins
301
- text: Emperor penguins are the tallest growing up to 122 cm in height.
302
-
303
- Document: 1
304
- title: Penguin habitats
305
- text: Emperor penguins only live in Antarctica.
306
- </results><|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>Carefully perform the following instructions, in order, starting each with a new line.
307
- Firstly, Decide which of the retrieved documents are relevant to the user's last input by writing 'Relevant Documents:' followed by comma-separated list of document numbers. If none are relevant, you should instead write 'None'.
308
- Secondly, Decide which of the retrieved documents contain facts that should be cited in a good answer to the user's last input by writing 'Cited Documents:' followed a comma-separated list of document numbers. If you dont want to cite any of them, you should instead write 'None'.
309
- Thirdly, Write 'Answer:' followed by a response to the user's last input in high quality natural english. Use the retrieved documents to help you. Do not insert any citations or grounding markup.
310
- Finally, Write 'Grounded answer:' followed by a response to the user's last input in high quality natural english. Use the symbols <co: doc> and </co: doc> to indicate when a fact comes from a document in the search result, e.g <co: 0>my fact</co: 0> for a fact from document 0.<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>
311
- ````
312
-
313
- </details>
314
-
315
- <details>
316
- <summary><b>Example Rendered Grounded Generation Completion [CLICK TO EXPAND]</b></summary>
317
-
318
- ````
319
- Relevant Documents: 0,1
320
- Cited Documents: 0,1
321
- Answer: The Emperor Penguin is the tallest or biggest penguin in the world. It is a bird that lives only in Antarctica and grows to a height of around 122 centimetres.
322
- Grounded answer: The <co: 0>Emperor Penguin</co: 0> is the <co: 0>tallest</co: 0> or biggest penguin in the world. It is a bird that <co: 1>lives only in Antarctica</co: 1> and <co: 0>grows to a height of around 122 centimetres.</co: 0>
323
- ````
324
- </details>
325
-
326
- ### Code Capabilities:
327
- Command-R has been optimized to interact with your code, by requesting code snippets, code explanations, or code rewrites. It might not perform well out-of-the-box for pure code completion. For better performance, we also recommend using a low temperature (and even greedy decoding) for code-generation related instructions.
328
-
329
- ### Model Card Contact
330
- For errors or additional questions about details in this model card, contact [info@for.ai](mailto:info@for.ai).
331
-
332
- ### Terms of Use:
333
- We hope that the release of this model will make community-based research efforts more accessible, by releasing the weights of a highly performant 35 billion parameter model to researchers all over the world. This model is governed by a [CC-BY-NC](https://cohere.com/c4ai-cc-by-nc-license) License with an acceptable use addendum, and also requires adhering to [C4AI's Acceptable Use Policy](https://docs.cohere.com/docs/c4ai-acceptable-use-policy).
334
-
335
- ### Try Chat:
336
- You can try Command-R chat in the playground [here](https://dashboard.cohere.com/playground/chat).
 
1
  ---
2
  library_name: transformers
 
 
 
 
 
 
 
 
 
 
 
3
  license: cc-by-nc-4.0
4
+ tags:
5
+ - creative-writing
6
+ - creative-writer
7
+ - multiplicative-lora
8
  ---
9
 
10
+ An experimental model, fine-tuned using the "multiplicative-LoRA" method on [c4ai-command-r-v01](https://huggingface.co/CohereForAI/c4ai-command-r-v01).
11
 
12
+ This model is nearly identical to [creative-writer-v0.1-bravo-35b](https://huggingface.co/jukofyork/creative-writer-v0.1-bravo-35b) (ie: the pre-softmax logits were scaled by `1.1` during training to increased single-token Entropy), but uses the new `v0.2` dataset which is around 15% larger and also more carefully curated to remove any weird formatting.
13
 
14
+ Please refer to [creative-writer-v0.1-alfa-35b](https://huggingface.co/jukofyork/creative-writer-v0.1-alfa-35b) for full details on how to use this model.