seungahdev
commited on
Commit
•
68b65d5
1
Parent(s):
bcdc7dd
Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,433 @@
|
|
1 |
---
|
2 |
-
license:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
license: cc-by-nc-4.0
|
3 |
+
base_model: CohereForAI/c4ai-command-r-plus
|
4 |
+
inference: false
|
5 |
+
model_link: https://huggingface.co/CohereForAI/c4ai-command-r-plus
|
6 |
+
model_name: CohereForAI/c4ai-command-r-plus
|
7 |
+
pipeline_tag: text-generation
|
8 |
+
quantized_by: FriendliAI
|
9 |
+
tags:
|
10 |
+
- pretrained
|
11 |
+
library_name: transformers
|
12 |
+
language:
|
13 |
+
- en
|
14 |
+
- fr
|
15 |
+
- de
|
16 |
+
- es
|
17 |
+
- it
|
18 |
+
- pt
|
19 |
+
- ja
|
20 |
+
- ko
|
21 |
+
- zh
|
22 |
+
- ar
|
23 |
---
|
24 |
+
|
25 |
+
<!-- header start -->
|
26 |
+
<p align="center">
|
27 |
+
<img src="https://i.imgur.com/mNM6Cai.png" width="100%" alt="Friendli Logo">
|
28 |
+
</p>
|
29 |
+
<!-- header end -->
|
30 |
+
|
31 |
+
# C4AI Command R+ FP8
|
32 |
+
|
33 |
+
- Model creator: [CohereForAI](https://cohere.com/)
|
34 |
+
- Original model: [c4ai-command-r-plus](https://huggingface.co/CohereForAI/c4ai-command-r-plus)
|
35 |
+
|
36 |
+
## Description
|
37 |
+
|
38 |
+
This repo contains the c4ai-command-r-plus model quantized to FP8 by FriendliAI, significantly enhancing its inference efficiency while maintaining high accuracy.
|
39 |
+
Note that FP8 is only supported by NVIDIA Ada, Hopper, and Blackwell GPU architectures.
|
40 |
+
Check out [FriendliAI documentation](https://docs.friendli.ai/) for more details.
|
41 |
+
|
42 |
+
## Compatibility
|
43 |
+
|
44 |
+
This model is compatible with **[Friendli Container](https://friendli.ai/products/container/)**.
|
45 |
+
|
46 |
+
## Prerequisites
|
47 |
+
|
48 |
+
- Before you begin, make sure you have signed up for [Friendli Suite](https://suite.friendli.ai/). **You can use Friendli Containers free of charge for four weeks.**
|
49 |
+
- Prepare a Personal Access Token following [this guide](#preparing-personal-access-token).
|
50 |
+
- Prepare a Friendli Container Secret following [this guide](#preparing-container-secret).
|
51 |
+
- Install Hugging Face CLI with `pip install -U "huggingface_hub[cli]"`
|
52 |
+
|
53 |
+
### Preparing Personal Access Token
|
54 |
+
|
55 |
+
PAT (Personal Access Token) is the user credential for for logging into our container registry.
|
56 |
+
|
57 |
+
1. Sign in [Friendli Suite](https://suite.friendli.ai/).
|
58 |
+
2. Go to **[User Settings > Tokens](https://suite.friendli.ai/user-settings/tokens)** and click **'Create new token'**.
|
59 |
+
3. Save your created token value.
|
60 |
+
|
61 |
+
### Pulling Friendli Container Image
|
62 |
+
|
63 |
+
1. Log in to the Docker client using the personal access token created as outlined in [this guide](#preparing-personal-access-token).
|
64 |
+
|
65 |
+
```sh
|
66 |
+
export FRIENDLI_PAT="YOUR PAT"
|
67 |
+
docker login registry.friendli.ai -u $YOUR_EMAIL -p $FRIENDLI_PAT
|
68 |
+
```
|
69 |
+
|
70 |
+
2. Pull image
|
71 |
+
|
72 |
+
```sh
|
73 |
+
docker pull registry.friendli.ai/trial
|
74 |
+
```
|
75 |
+
|
76 |
+
## Running Friendli Container
|
77 |
+
|
78 |
+
Once you've prepared the image of Friendli Container, you can launch it to create a serving endpoint.
|
79 |
+
|
80 |
+
```sh
|
81 |
+
docker run \
|
82 |
+
--gpus '"device=0,1,2,3"' \
|
83 |
+
-p 8000:8000 \
|
84 |
+
-v ~/.cache/huggingface:/root/.cache/huggingface \
|
85 |
+
-e FRIENDLI_CONTAINER_SECRET="YOUR CONTAINER SECRET" \
|
86 |
+
registry.friendli.ai/trial \
|
87 |
+
--web-server-port 8000 \
|
88 |
+
--hf-model-name FriendliAI/c4ai-command-r-plus-fp8 \
|
89 |
+
--num-devices 4 # Use tensor parallelism degree 4
|
90 |
+
```
|
91 |
+
|
92 |
+
---
|
93 |
+
|
94 |
+
# Original model card: CohereForAI's C4AI Command R+
|
95 |
+
|
96 |
+
# C4AI Command R+
|
97 |
+
|
98 |
+
🚨 **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-plus-4bit)**.
|
99 |
+
|
100 |
+
|
101 |
+
## Model Summary
|
102 |
+
|
103 |
+
C4AI Command R+ is an open weights research release of a 104B billion parameter model with highly advanced capabilities, this includes Retrieval Augmented Generation (RAG) and tool use to automate sophisticated tasks. The tool use in this model generation enables multi-step tool use which allows the model to combine multiple tools over multiple steps to accomplish difficult tasks. C4AI Command R+ is a multilingual model evaluated in 10 languages for performance: English, French, Spanish, Italian, German, Brazilian Portuguese, Japanese, Korean, Arabic, and Simplified Chinese. Command R+ is optimized for a variety of use cases including reasoning, summarization, and question answering.
|
104 |
+
|
105 |
+
C4AI Command R+ is part of a family of open weight releases from Cohere For AI and Cohere. Our smaller companion model is [C4AI Command R](https://huggingface.co/CohereForAI/c4ai-command-r-v01)
|
106 |
+
|
107 |
+
Developed by: [Cohere](https://cohere.com/) and [Cohere For AI](https://cohere.for.ai)
|
108 |
+
|
109 |
+
- Point of Contact: Cohere For AI: [cohere.for.ai](https://cohere.for.ai/)
|
110 |
+
- 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)
|
111 |
+
- Model: c4ai-command-r-plus
|
112 |
+
- Model Size: 104 billion parameters
|
113 |
+
- Context length: 128K
|
114 |
+
|
115 |
+
**Try C4AI Command R+**
|
116 |
+
|
117 |
+
You can try out C4AI Command R+ before downloading the weights in our hosted [Hugging Face Space](https://huggingface.co/spaces/CohereForAI/c4ai-command-r-plus).
|
118 |
+
|
119 |
+
**Usage**
|
120 |
+
|
121 |
+
Please install `transformers` from the source repository that includes the necessary changes for this model.
|
122 |
+
```python
|
123 |
+
# pip install 'git+https://github.com/huggingface/transformers.git'
|
124 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
125 |
+
|
126 |
+
model_id = "CohereForAI/c4ai-command-r-plus"
|
127 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
128 |
+
model = AutoModelForCausalLM.from_pretrained(model_id)
|
129 |
+
|
130 |
+
# Format message with the command-r-plus chat template
|
131 |
+
messages = [{"role": "user", "content": "Hello, how are you?"}]
|
132 |
+
input_ids = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt")
|
133 |
+
## <BOS_TOKEN><|START_OF_TURN_TOKEN|><|USER_TOKEN|>Hello, how are you?<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>
|
134 |
+
|
135 |
+
gen_tokens = model.generate(
|
136 |
+
input_ids,
|
137 |
+
max_new_tokens=100,
|
138 |
+
do_sample=True,
|
139 |
+
temperature=0.3,
|
140 |
+
)
|
141 |
+
|
142 |
+
gen_text = tokenizer.decode(gen_tokens[0])
|
143 |
+
print(gen_text)
|
144 |
+
```
|
145 |
+
|
146 |
+
**Quantized model through bitsandbytes, 8-bit precision**
|
147 |
+
|
148 |
+
```python
|
149 |
+
# pip install 'git+https://github.com/huggingface/transformers.git' bitsandbytes accelerate
|
150 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
|
151 |
+
|
152 |
+
bnb_config = BitsAndBytesConfig(load_in_8bit=True)
|
153 |
+
|
154 |
+
model_id = "CohereForAI/c4ai-command-r-plus"
|
155 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
156 |
+
model = AutoModelForCausalLM.from_pretrained(model_id, quantization_config=bnb_config)
|
157 |
+
|
158 |
+
# Format message with the command-r-plus chat template
|
159 |
+
messages = [{"role": "user", "content": "Hello, how are you?"}]
|
160 |
+
input_ids = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt")
|
161 |
+
## <BOS_TOKEN><|START_OF_TURN_TOKEN|><|USER_TOKEN|>Hello, how are you?<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>
|
162 |
+
|
163 |
+
gen_tokens = model.generate(
|
164 |
+
input_ids,
|
165 |
+
max_new_tokens=100,
|
166 |
+
do_sample=True,
|
167 |
+
temperature=0.3,
|
168 |
+
)
|
169 |
+
|
170 |
+
gen_text = tokenizer.decode(gen_tokens[0])
|
171 |
+
print(gen_text)
|
172 |
+
```
|
173 |
+
|
174 |
+
**Quantized model through bitsandbytes, 4-bit precision**
|
175 |
+
|
176 |
+
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-plus-4bit).
|
177 |
+
|
178 |
+
## Model Details
|
179 |
+
|
180 |
+
**Input**: Models input text only.
|
181 |
+
|
182 |
+
**Output**: Models generate text only.
|
183 |
+
|
184 |
+
**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.
|
185 |
+
|
186 |
+
**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.
|
187 |
+
|
188 |
+
Pre-training data additionally included the following 13 languages: Russian, Polish, Turkish, Vietnamese, Dutch, Czech, Indonesian, Ukrainian, Romanian, Greek, Hindi, Hebrew, Persian.
|
189 |
+
|
190 |
+
**Context length**: Command R+ supports a context length of 128K.
|
191 |
+
|
192 |
+
## Evaluations
|
193 |
+
|
194 |
+
Command R+ has been submitted to the [Open LLM leaderboard](https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard). We include the results below, along with a direct comparison to the strongest state-of-art open weights models currently available on Hugging Face. We note that these results are only useful to compare when evaluations are implemented for all models in a [standardized way](https://github.com/EleutherAI/lm-evaluation-harness) using publically available code, and hence shouldn't be used for comparison outside of models submitted to the leaderboard or compared to self-reported numbers which can't be replicated in the same way.
|
195 |
+
|
196 |
+
| Model | Average | Arc (Challenge) | Hella Swag | MMLU | Truthful QA | Winogrande | GSM8k |
|
197 |
+
|:--------------------------------|----------:|------------------:|-------------:|-------:|--------------:|-------------:|--------:|
|
198 |
+
| **CohereForAI/c4ai-command-r-plus** | 74.6 | 70.99 | 88.6 | 75.7 | 56.3 | 85.4 | 70.7 |
|
199 |
+
| [DBRX Instruct](https://huggingface.co/databricks/dbrx-instruct) | 74.5 | 68.9 | 89 | 73.7 | 66.9 | 81.8 | 66.9 |
|
200 |
+
| [Mixtral 8x7B-Instruct](https://huggingface.co/mistralai/Mixtral-8x7B-Instruct-v0.1) | 72.7 | 70.1 | 87.6 | 71.4 | 65 | 81.1 | 61.1 |
|
201 |
+
| [Mixtral 8x7B Chat](https://huggingface.co/mistralai/Mixtral-8x7B-Instruct-v0.1) | 72.6 | 70.2 | 87.6 | 71.2 | 64.6 | 81.4 | 60.7 |
|
202 |
+
| [CohereForAI/c4ai-command-r-v01](https://huggingface.co/CohereForAI/c4ai-command-r-v01) | 68.5 | 65.5 | 87 | 68.2 | 52.3 | 81.5 | 56.6 |
|
203 |
+
| [Llama 2 70B](https://huggingface.co/meta-llama/Llama-2-70b-hf) | 67.9 | 67.3 | 87.3 | 69.8 | 44.9 | 83.7 | 54.1 |
|
204 |
+
| [Yi-34B-Chat](https://huggingface.co/01-ai/Yi-34B-Chat) | 65.3 | 65.4 | 84.2 | 74.9 | 55.4 | 80.1 | 31.9 |
|
205 |
+
| [Gemma-7B](https://huggingface.co/google/gemma-7b) | 63.8 | 61.1 | 82.2 | 64.6 | 44.8 | 79 | 50.9 |
|
206 |
+
| [LLama 2 70B Chat](https://huggingface.co/meta-llama/Llama-2-70b-chat-hf) | 62.4 | 64.6 | 85.9 | 63.9 | 52.8 | 80.5 | 26.7 |
|
207 |
+
| [Mistral-7B-v0.1](https://huggingface.co/mistralai/Mistral-7B-v0.1) | 61 | 60 | 83.3 | 64.2 | 42.2 | 78.4 | 37.8 |
|
208 |
+
|
209 |
+
We include these metrics here because they are frequently requested, but note that these metrics do not capture RAG, multilingual, tooling performance or the evaluation of open ended generations which we believe Command R+ to be state-of-art at. For evaluations of RAG, multilingual and tooling read more [here](https://txt.cohere.com/command-r-plus-microsoft-azure/). For evaluation of open ended generation, Command R+ is currently being evaluated on the [chatbot arena](https://chat.lmsys.org/).
|
210 |
+
|
211 |
+
### Tool use & multihop capabilities:
|
212 |
+
|
213 |
+
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.
|
214 |
+
|
215 |
+
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.
|
216 |
+
|
217 |
+
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.
|
218 |
+
We recommend including the `directly_answer` tool, but it can be removed or renamed if required.
|
219 |
+
|
220 |
+
Comprehensive documentation for working with command R+'s tool use prompt template can be found [here](https://docs.cohere.com/docs/prompting-command-r).
|
221 |
+
|
222 |
+
The code snippet below shows a minimal working example on how to render a prompt.
|
223 |
+
|
224 |
+
<details>
|
225 |
+
<summary><b>Usage: Rendering Tool Use Prompts [CLICK TO EXPAND]</b> </summary>
|
226 |
+
|
227 |
+
```python
|
228 |
+
from transformers import AutoTokenizer
|
229 |
+
|
230 |
+
model_id = "CohereForAI/c4ai-command-r-plus"
|
231 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
232 |
+
|
233 |
+
# define conversation input:
|
234 |
+
conversation = [
|
235 |
+
{"role": "user", "content": "Whats the biggest penguin in the world?"}
|
236 |
+
]
|
237 |
+
# Define tools available for the model to use:
|
238 |
+
tools = [
|
239 |
+
{
|
240 |
+
"name": "internet_search",
|
241 |
+
"description": "Returns a list of relevant document snippets for a textual query retrieved from the internet",
|
242 |
+
"parameter_definitions": {
|
243 |
+
"query": {
|
244 |
+
"description": "Query to search the internet with",
|
245 |
+
"type": 'str',
|
246 |
+
"required": True
|
247 |
+
}
|
248 |
+
}
|
249 |
+
},
|
250 |
+
{
|
251 |
+
'name': "directly_answer",
|
252 |
+
"description": "Calls a standard (un-augmented) AI chatbot to generate a response given the conversation history",
|
253 |
+
'parameter_definitions': {}
|
254 |
+
}
|
255 |
+
]
|
256 |
+
|
257 |
+
# render the tool use prompt as a string:
|
258 |
+
tool_use_prompt = tokenizer.apply_tool_use_template(
|
259 |
+
conversation,
|
260 |
+
tools=tools,
|
261 |
+
tokenize=False,
|
262 |
+
add_generation_prompt=True,
|
263 |
+
)
|
264 |
+
print(tool_use_prompt)
|
265 |
+
```
|
266 |
+
|
267 |
+
</details>
|
268 |
+
|
269 |
+
<details>
|
270 |
+
<summary><b>Example Rendered Tool Use Prompt [CLICK TO EXPAND]</b></summary>
|
271 |
+
|
272 |
+
````
|
273 |
+
<BOS_TOKEN><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|># Safety Preamble
|
274 |
+
The instructions in this section override those in the task description and style guide sections. Don't answer questions that are harmful or immoral.
|
275 |
+
|
276 |
+
# System Preamble
|
277 |
+
## Basic Rules
|
278 |
+
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.
|
279 |
+
|
280 |
+
# User Preamble
|
281 |
+
## Task and Context
|
282 |
+
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.
|
283 |
+
|
284 |
+
## Style Guide
|
285 |
+
Unless the user asks for a different style of answer, you should answer in full sentences, using proper grammar and spelling.
|
286 |
+
|
287 |
+
## Available Tools
|
288 |
+
Here is a list of tools that you have available to you:
|
289 |
+
|
290 |
+
```python
|
291 |
+
def internet_search(query: str) -> List[Dict]:
|
292 |
+
"""Returns a list of relevant document snippets for a textual query retrieved from the internet
|
293 |
+
|
294 |
+
Args:
|
295 |
+
query (str): Query to search the internet with
|
296 |
+
"""
|
297 |
+
pass
|
298 |
+
```
|
299 |
+
|
300 |
+
```python
|
301 |
+
def directly_answer() -> List[Dict]:
|
302 |
+
"""Calls a standard (un-augmented) AI chatbot to generate a response given the conversation history
|
303 |
+
"""
|
304 |
+
pass
|
305 |
+
```<|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:
|
306 |
+
```json
|
307 |
+
[
|
308 |
+
{
|
309 |
+
"tool_name": title of the tool in the specification,
|
310 |
+
"parameters": a dict of parameters to input into the tool as they are defined in the specs, or {} if it takes no parameters
|
311 |
+
}
|
312 |
+
]```<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>
|
313 |
+
|
314 |
+
````
|
315 |
+
|
316 |
+
</details>
|
317 |
+
|
318 |
+
<details>
|
319 |
+
<summary><b>Example Rendered Tool Use Completion [CLICK TO EXPAND]</b></summary>
|
320 |
+
|
321 |
+
````
|
322 |
+
Action: ```json
|
323 |
+
[
|
324 |
+
{
|
325 |
+
"tool_name": "internet_search",
|
326 |
+
"parameters": {
|
327 |
+
"query": "biggest penguin in the world"
|
328 |
+
}
|
329 |
+
}
|
330 |
+
]
|
331 |
+
```
|
332 |
+
````
|
333 |
+
</details>
|
334 |
+
|
335 |
+
### Grounded Generation and RAG Capabilities:
|
336 |
+
|
337 |
+
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. 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. Deviating from this prompt template may reduce performance, but we encourage experimentation.
|
338 |
+
|
339 |
+
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. 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.
|
340 |
+
|
341 |
+
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. Finally, it will then insert grounding spans into the answer. See below for an example. This is referred to as `accurate` grounded generation.
|
342 |
+
|
343 |
+
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.
|
344 |
+
|
345 |
+
Comprehensive documentation for working with Command R+'s grounded generation prompt template can be found [here](https://docs.cohere.com/docs/prompting-command-r).
|
346 |
+
|
347 |
+
The code snippet below shows a minimal working example on how to render a prompt.
|
348 |
+
|
349 |
+
<details>
|
350 |
+
<summary> <b>Usage: Rendering Grounded Generation prompts [CLICK TO EXPAND]</b> </summary>
|
351 |
+
|
352 |
+
````python
|
353 |
+
from transformers import AutoTokenizer
|
354 |
+
|
355 |
+
model_id = "CohereForAI/c4ai-command-r-plus"
|
356 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
357 |
+
|
358 |
+
# define conversation input:
|
359 |
+
conversation = [
|
360 |
+
{"role": "user", "content": "Whats the biggest penguin in the world?"}
|
361 |
+
]
|
362 |
+
# define documents to ground on:
|
363 |
+
documents = [
|
364 |
+
{ "title": "Tall penguins", "text": "Emperor penguins are the tallest growing up to 122 cm in height." },
|
365 |
+
{ "title": "Penguin habitats", "text": "Emperor penguins only live in Antarctica."}
|
366 |
+
]
|
367 |
+
|
368 |
+
# render the tool use prompt as a string:
|
369 |
+
grounded_generation_prompt = tokenizer.apply_grounded_generation_template(
|
370 |
+
conversation,
|
371 |
+
documents=documents,
|
372 |
+
citation_mode="accurate", # or "fast"
|
373 |
+
tokenize=False,
|
374 |
+
add_generation_prompt=True,
|
375 |
+
)
|
376 |
+
print(grounded_generation_prompt)
|
377 |
+
````
|
378 |
+
</details>
|
379 |
+
|
380 |
+
<details>
|
381 |
+
<summary><b>Example Rendered Grounded Generation Prompt [CLICK TO EXPAND]</b></summary>
|
382 |
+
|
383 |
+
````<BOS_TOKEN><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|># Safety Preamble
|
384 |
+
The instructions in this section override those in the task description and style guide sections. Don't answer questions that are harmful or immoral.
|
385 |
+
|
386 |
+
# System Preamble
|
387 |
+
## Basic Rules
|
388 |
+
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.
|
389 |
+
|
390 |
+
# User Preamble
|
391 |
+
## Task and Context
|
392 |
+
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.
|
393 |
+
|
394 |
+
## Style Guide
|
395 |
+
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>
|
396 |
+
Document: 0
|
397 |
+
title: Tall penguins
|
398 |
+
text: Emperor penguins are the tallest growing up to 122 cm in height.
|
399 |
+
|
400 |
+
Document: 1
|
401 |
+
title: Penguin habitats
|
402 |
+
text: Emperor penguins only live in Antarctica.
|
403 |
+
</results><|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>Carefully perform the following instructions, in order, starting each with a new line.
|
404 |
+
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'.
|
405 |
+
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'.
|
406 |
+
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.
|
407 |
+
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|>
|
408 |
+
````
|
409 |
+
|
410 |
+
</details>
|
411 |
+
|
412 |
+
<details>
|
413 |
+
<summary><b>Example Rendered Grounded Generation Completion [CLICK TO EXPAND]</b></summary>
|
414 |
+
|
415 |
+
````
|
416 |
+
Relevant Documents: 0,1
|
417 |
+
Cited Documents: 0,1
|
418 |
+
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.
|
419 |
+
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>
|
420 |
+
````
|
421 |
+
</details>
|
422 |
+
|
423 |
+
### Code Capabilities:
|
424 |
+
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.
|
425 |
+
|
426 |
+
### Model Card Contact
|
427 |
+
For errors or additional questions about details in this model card, contact [info@for.ai](mailto:info@for.ai).
|
428 |
+
|
429 |
+
### Terms of Use:
|
430 |
+
We hope that the release of this model will make community-based research efforts more accessible, by releasing the weights of a highly performant 104 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).
|
431 |
+
|
432 |
+
### Try Chat:
|
433 |
+
You can try Command R+ chat in the playground [here](https://dashboard.cohere.com/playground/chat). You can also use it in our dedicated Hugging Face Space [here](https://huggingface.co/spaces/CohereForAI/c4ai-command-r-plus).
|