模型概述
模型特點
模型能力
使用案例
🚀 C4AI Command R 08 - 2024 模型卡片
Cohere Labs Command R 08 - 2024 是一款擁有 320 億參數的高性能生成模型的研究版本。它是一個開放權重的大語言模型,針對推理、總結和問答等多種用例進行了優化。該模型具備多語言生成能力,在 23 種語言上進行訓練,並在 10 種語言上進行評估,同時還擁有出色的檢索增強生成(RAG)能力。
🚀 快速開始
如果你想在下載權重之前試用 Command R,可以在 這裡 的 Hugging Face 空間中使用該模型。
請使用 transformers
4.39.1 或更高版本:
# pip install 'transformers>=4.39.1'
from transformers import AutoTokenizer, AutoModelForCausalLM
model_id = "CohereLabs/c4ai-command-r-08-2024"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id)
# Format message with the command-r-08-2024 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)
✨ 主要特性
- 多語言支持:支持 23 種語言的訓練和 10 種語言的評估,包括英語、法語、西班牙語、意大利語、德語、葡萄牙語、日語、韓語、阿拉伯語和簡體中文等。
- 長上下文處理:支持 128K 的上下文長度。
- 高性能 RAG 能力:能夠基於提供的文檔片段生成響應,並在響應中包含引用信息。
- 工具使用能力:支持單步工具使用(“函數調用”)和多步工具使用(“代理”),可以與外部工具如 API、數據庫或搜索引擎進行交互。
- 代碼交互能力:經過優化,可與代碼進行交互,如請求代碼片段、代碼解釋或代碼重寫。
📦 安裝指南
請使用 transformers
4.39.1 或更高版本:
pip install 'transformers>=4.39.1'
💻 使用示例
基礎用法
# pip install 'transformers>=4.39.1'
from transformers import AutoTokenizer, AutoModelForCausalLM
model_id = "CohereLabs/c4ai-command-r-08-2024"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id)
# Format message with the command-r-08-2024 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)
高級用法 - 接地生成
from transformers import AutoTokenizer
model_id = "CohereLabs/c4ai-command-r-08-2024"
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)
高級用法 - 單步工具使用
from transformers import AutoTokenizer
model_id = "CohereLabs/c4ai-command-r-08-2024"
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)
📚 詳細文檔
模型詳情
- 輸入:僅接受文本輸入。
- 輸出:僅生成文本輸出。
- 模型架構:這是一個自迴歸語言模型,使用了優化的 Transformer 架構。在預訓練之後,該模型使用監督微調(SFT)和偏好訓練來使模型行為符合人類對有用性和安全性的偏好。使用分組查詢注意力(GQA)來提高推理速度。
- 支持的語言:在 23 種語言(英語、法語、西班牙語、意大利語、德語、葡萄牙語、日語、韓語、阿拉伯語、簡體中文、俄語、波蘭語、土耳其語、越南語、荷蘭語、捷克語、印尼語、烏克蘭語、羅馬尼亞語、希臘語、印地語、希伯來語和波斯語)上進行訓練,並在 10 種語言(英語、法語、西班牙語、意大利語、德語、葡萄牙語、日語、韓語、阿拉伯語、簡體中文)上進行評估。
- 上下文長度:支持 128K 的上下文長度。
接地生成和 RAG 能力
Command R 08 - 2024 經過專門訓練,具備接地生成能力。這意味著它可以根據提供的文檔片段列表生成響應,並在響應中包含引用信息,以表明信息的來源。這可用於實現接地總結和檢索增強生成(RAG)的最後一步。這種行為通過監督微調與偏好微調的結合進行訓練,使用特定的提示模板。偏離此提示模板可能會降低性能,因此建議使用下面描述的提示模板。
有關使用 Command R 08 - 2024 的接地生成提示模板的詳細文檔,請參閱 這裡、這裡 和 這裡。
單步工具使用能力(“函數調用”)
單步工具使用(或“函數調用”)允許 Command R 08 - 2024 與外部工具(如 API、數據庫或搜索引擎)進行交互。單步工具使用由兩個模型推理步驟組成:
- 工具選擇:模型決定調用哪些工具以及使用什麼參數。然後由開發人員執行這些工具調用並獲取工具結果。
- 響應生成:模型根據工具結果生成最終響應。
有關單步工具使用的更多信息,請參閱 文檔。
多步工具使用能力(“代理”)
多步工具使用適用於構建能夠使用多個工具規劃和執行一系列操作的代理。與單步工具使用不同,模型可以執行多個推理週期,通過“行動 → 觀察 → 反思”的循環迭代,直到確定最終響應。有關多步工具使用的更多詳細信息,請參閱 多步工具使用文檔。
代碼能力
Command R 08 - 2024 經過優化,可與代碼進行交互,如請求代碼片段、代碼解釋或代碼重寫。對於純代碼補全,它可能無法直接達到良好的性能。為了獲得更好的性能,建議在與代碼生成相關的指令中使用較低的溫度(甚至貪婪解碼)。
🔧 技術細節
- 模型類型:自迴歸語言模型,使用優化的 Transformer 架構。
- 訓練數據:在 23 種語言的數據上進行訓練。
- 微調方法:使用監督微調(SFT)和偏好訓練來使模型行為符合人類對有用性和安全性的偏好。
- 注意力機制:使用分組查詢注意力(GQA)來提高推理速度。
屬性 | 詳情 |
---|---|
模型類型 | 自迴歸語言模型,使用優化的 Transformer 架構 |
訓練數據 | 在 23 種語言的數據上進行訓練 |
微調方法 | 監督微調(SFT)和偏好訓練 |
注意力機制 | 分組查詢注意力(GQA) |
📄 許可證
本模型受 CC - BY - NC 許可證約束,同時需要遵守 Cohere Lab 的可接受使用政策。
模型卡片聯繫方式
如果對本模型卡片中的細節有錯誤反饋或額外問題,請聯繫 labs@cohere.com。
使用條款
我們希望通過向全球研究人員發佈這個擁有 320 億參數的高性能模型的權重,使基於社區的研究工作更加容易開展。該模型受 CC - BY - NC 許可證約束,並附有可接受使用附錄,同時還需要遵守 Cohere Lab 的可接受使用政策。
試用聊天
你可以在 這裡 的 playground 中試用 Command - R 聊天。
引用
如需引用此模型,請使用以下 BibTeX 格式:
@misc {cohere_for_ai_2024,
author = { {Cohere Labs} },
title = { c4ai-command-r-08-2024 },
year = 2024,
url = { https://huggingface.co/CohereLabs/c4ai-command-r-08-2024 },
doi = { 10.57967/hf/3134 },
publisher = { Hugging Face }
}



