Model Overview
Model Features
Model Capabilities
Use Cases
🚀 Cohere Labs Command R+ モデルカード
Cohere Labs Command R+ は強力な能力を持つモデルで、検索強化生成(RAG)やツール使用などの高度な機能を備え、複雑なタスクを処理できます。多言語に対応しており、推論、要約、質問応答などの様々なシナリオで優れた性能を発揮します。
🚀 クイックスタート
重みをダウンロードする前に、当社がホストしている Hugging Face スペース で Cohere Labs Command R+ を試用することができます。
このモデルに必要な変更を含むソースリポジトリから transformers
をインストールしてください。
# pip install 'git+https://github.com/huggingface/transformers.git' bitsandbytes accelerate
from transformers import AutoTokenizer, AutoModelForCausalLM
model_id = "CohereForAI/c4ai-command-r-plus-4bit"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id)
# Format message with the command-r-plus chat template
messages = [{"role": "user", "content": "Hello, how are you?"}]
input_ids = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt")
## <BOS_TOKEN><|START_OF_TURN_TOKEN|><|USER_TOKEN|>Hello, how are you?<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>
gen_tokens = model.generate(
input_ids,
max_new_tokens=100,
do_sample=True,
temperature=0.3,
)
gen_text = tokenizer.decode(gen_tokens[0])
print(gen_text)
✨ 主な機能
モデル概要
Cohere Labs Command R+ は、1040 億パラメータを持つモデルのオープンウェイト研究版で、高度な能力を備えています。これには、検索強化生成(RAG)やツール使用機能が含まれ、複雑なタスクを自動化できます。このモデルのツール使用機能は、多段階のツール使用をサポートしており、困難なタスクを達成するために複数のツールを複数のステップで組み合わせて使用することができます。
Cohere Labs Command R+ は多言語モデルで、10 種類の言語で性能が評価されています。これらの言語は、英語、フランス語、スペイン語、イタリア語、ドイツ語、ブラジルポルトガル語、日本語、韓国語、アラビア語、簡体字中国語です。Command R+ は、推論、要約、質問応答などの様々なユースケースに最適化されています。
Cohere Labs Command R+ は、Cohere For AI と Cohere のオープンウェイト版シリーズの一部です。より小さなモデルとして Cohere Labs Command R があります。
- 開発者:Cohere と Cohere For AI
- 連絡先:Cohere For AI: cohere.for.ai
- ライセンス:CC - BY - NC。また、Cohere Lab's 許容利用ポリシー も遵守する必要があります。
- モデル:c4ai - command - r - plus
- モデルサイズ:1040 億パラメータ
- コンテキスト長:128K
モデル詳細
- 入力:このモデルはテキスト入力のみを受け付けます。
- 出力:このモデルはテキスト出力のみを生成します。
- モデルアーキテクチャ:これは自己回帰型言語モデルで、最適化された Transformer アーキテクチャを使用しています。事前学習後、このモデルは教師付き微調整(SFT)と嗜好学習を使用して、有用性と安全性に関する人間の嗜好に合わせたモデル動作を実現しています。
- サポート言語:このモデルは、英語、フランス語、スペイン語、イタリア語、ドイツ語、ブラジルポルトガル語、日本語、韓国語、簡体字中国語、アラビア語に最適化されています。事前学習データには、さらに 13 種類の言語が含まれています。これらは、ロシア語、ポーランド語、トルコ語、ベトナム語、オランダ語、チェコ語、インドネシア語、ウクライナ語、ルーマニア語、ギリシャ語、ヒンディー語、ヘブライ語、ペルシャ語です。
- コンテキスト長:Command R+ は 128K のコンテキスト長をサポートしています。
ツール使用とマルチホップ能力
Command R+ は、会話型ツール使用能力を持つように特別に訓練されています。これらの能力は、特定のプロンプトテンプレートを使用して、教師付き微調整と嗜好微調整を組み合わせてモデルに学習させられています。このプロンプトテンプレートから逸脱すると性能が低下する可能性がありますが、実験を行うことを推奨します。
Command R+ のツール使用機能は、会話(オプションでユーザー - システムの前文を含む)と利用可能なツールのリストを入力として受け取ります。そして、モデルは一部のツールで実行するための JSON 形式のアクションリストを生成します。Command R+ は、提供されたツールの 1 つを複数回使用することがあります。
このモデルは、特殊な directly_answer
ツールを認識するように訓練されており、これは他のツールを使用したくないことを示すために使用されます。ユーザーに挨拶したり、説明を求める質問をしたりする場合など、特定のツールを呼び出さない能力は役立つことがあります。directly_answer
ツールを含めることを推奨しますが、必要に応じて削除またはリネームすることもできます。
Command R+ のツール使用プロンプトテンプレートの詳細なドキュメントについては、こちら を参照してください。
Command R+ は、Hugging Face の ツール使用 API もサポートしています。
以下のコードスニペットは、プロンプトをレンダリングする最小限の動作例を示しています。
使用方法:ツール使用プロンプトのレンダリング [クリックして展開]
from transformers import AutoTokenizer
model_id = "CohereForAI/c4ai-command-r-plus-4bit"
tokenizer = AutoTokenizer.from_pretrained(model_id)
# define conversation input:
conversation = [
{"role": "user", "content": "Whats the biggest penguin in the world?"}
]
# Define tools available for the model to use:
tools = [
{
"name": "internet_search",
"description": "Returns a list of relevant document snippets for a textual query retrieved from the internet",
"parameter_definitions": {
"query": {
"description": "Query to search the internet with",
"type": 'str',
"required": True
}
}
},
{
'name': "directly_answer",
"description": "Calls a standard (un-augmented) AI chatbot to generate a response given the conversation history",
'parameter_definitions': {}
}
]
# render the tool use prompt as a string:
tool_use_prompt = tokenizer.apply_tool_use_template(
conversation,
tools=tools,
tokenize=False,
add_generation_prompt=True,
)
print(tool_use_prompt)
使用方法:ツール使用 API を使用したプロンプトのレンダリング [クリックして展開]
from transformers import AutoTokenizer
model_id = "CohereForAI/c4ai-command-r-plus-4bit"
tokenizer = AutoTokenizer.from_pretrained(model_id)
# define conversation input:
conversation = [
{"role": "user", "content": "Whats the biggest penguin in the world?"}
]
# Define tools available for the model to use
# Type hints and docstrings from Python functions are automatically extracted
def internet_search(query: str):
"""
Returns a list of relevant document snippets for a textual query retrieved from the internet
Args:
query: Query to search the internet with
"""
pass
def directly_answer():
"""
Calls a standard (un-augmented) AI chatbot to generate a response given the conversation history
"""
pass
tools = [internet_search, directly_answer]
# render the tool use prompt as a string:
tool_use_prompt = tokenizer.apply_chat_template(
conversation,
tools=tools,
tokenize=False,
add_generation_prompt=True,
)
print(tool_use_prompt)
レンダリングされたツール使用プロンプトの例 [クリックして展開]
<BOS_TOKEN><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|># Safety Preamble
The instructions in this section override those in the task description and style guide sections. Don't answer questions that are harmful or immoral.
# System Preamble
## Basic Rules
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.
# User Preamble
## Task and Context
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.
## Style Guide
Unless the user asks for a different style of answer, you should answer in full sentences, using proper grammar and spelling.
## Available Tools
Here is a list of tools that you have available to you:
```python
def internet_search(query: str) -> List[Dict]:
"""Returns a list of relevant document snippets for a textual query retrieved from the internet
Args:
query (str): Query to search the internet with
"""
pass
def directly_answer() -> List[Dict]:
"""Calls a standard (un-augmented) AI chatbot to generate a response given the conversation history
"""
pass
```<|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:
```json
[
{
"tool_name": title of the tool in the specification,
"parameters": a dict of parameters to input into the tool as they are defined in the specs, or {} if it takes no parameters
}
]```<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>
レンダリングされたツール使用の完了結果の例 [クリックして展開]
Action: ```json
[
{
"tool_name": "internet_search",
"parameters": {
"query": "biggest penguin in the world"
}
}
]
事実ベースの生成と RAG 能力
Command R+ は、事実ベースの生成能力を持つように特別に訓練されています。これは、提供されたドキュメントの断片のリストに基づいて応答を生成し、応答に事実ベースの範囲(引用)を含めることができ、情報の出所を示すことができます。これは、事実ベースの要約や検索強化生成(RAG)の最後のステップなどの動作を実現するために使用できます。この動作は、特定のプロンプトテンプレートを使用して、教師付き微調整と嗜好微調整を組み合わせてモデルに学習させられています。このプロンプトテンプレートから逸脱すると性能が低下する可能性がありますが、実験を行うことを推奨します。
Command R+ の事実ベースの生成動作は、会話(オプションでユーザーが提供するシステム前文を含み、タスク、コンテキスト、必要な出力スタイルを指示する)と検索されたドキュメントの断片のリストを入力として受け取ります。ドキュメントの断片は小さなブロックである必要があり、長いドキュメントではなく、通常は各ブロックが約 100 - 400 単語です。ドキュメントの断片はキーバリューペアで構成されています。キーは簡潔な説明的な文字列である必要があり、値はテキストまたは半構造化データです。
デフォルトでは、Command R+ はまずどのドキュメントが関連するかを予測し、次にどのドキュメントを引用するかを予測し、次に答えを生成し、最後に答えに事実ベースの範囲を挿入することで、事実ベースの応答を生成します。以下はその例です。これは accurate
事実ベースの生成と呼ばれます。
このモデルは、他の複数の回答モードもサポートするように訓練されており、プロンプトを変更することで選択できます。トークナイザーは fast
引用モードをサポートしており、これはまず完全に答えを書き出すことなく、事実ベースの範囲を含む答えを直接生成します。これは、事実ベースの精度を多少犠牲にして、より少ないトークンを生成することを可能にします。
Command R+ の事実ベースの生成プロンプトテンプレートの詳細なドキュメントについては、こちら を参照してください。
以下のコードスニペットは、プロンプトをレンダリングする最小限の動作例を示しています。
使用方法:事実ベースの生成プロンプトのレンダリング [クリックして展開]
from transformers import AutoTokenizer
model_id = "CohereForAI/c4ai-command-r-plus-4bit"
tokenizer = AutoTokenizer.from_pretrained(model_id)
# define conversation input:
conversation = [
{"role": "user", "content": "Whats the biggest penguin in the world?"}
]
# define documents to ground on:
documents = [
{ "title": "Tall penguins", "text": "Emperor penguins are the tallest growing up to 122 cm in height." },
{ "title": "Penguin habitats", "text": "Emperor penguins only live in Antarctica."}
]
# render the tool use prompt as a string:
grounded_generation_prompt = tokenizer.apply_grounded_generation_template(
conversation,
documents=documents,
citation_mode="accurate", # or "fast"
tokenize=False,
add_generation_prompt=True,
)
print(grounded_generation_prompt)
その他の情報
- 言語サポート:このモデルは、英語、フランス語、ドイツ語、スペイン語、イタリア語、ポルトガル語、日本語、韓国語、中国語、アラビア語などの複数の言語をサポートしています。
- ライセンス:CC - BY - NC 4.0。このモデルを使用する場合は、フォームを提出し、ライセンス契約 に同意し、提供する情報が Cohere の プライバシーポリシー に基づいて収集、使用、共有されることを確認する必要があります。Cohere Labs および Cohere の研究、活動、製品、サービスに関する電子メール更新を受け取ることになりますが、いつでも購読を解除することができます。
- 追加フィールド:モデルを使用する際には、名前、所属機関、国などの情報を提供する必要があり、このモデルを非商用目的でのみ使用することを確認する必要があります。
⚠️ 重要提示
このモデルは、bitsandbytes を使用して Cohere Labs Command R+ を 4 ビット量子化したバージョンです。未量子化バージョンの Cohere Labs Command R+ は こちら で見つけることができます。
💡 使用アドバイス
ツール使用と事実ベースの生成のプロンプトテンプレートから逸脱すると性能が低下する可能性がありますが、実験を行うことをおすすめします。



