Llama 2 7b Chat Hf Function Calling V3
模型概述
此模型是基於Llama 2 7B聊天版本微調的,專門優化了函數調用能力,可用於構建支持函數調用的對話系統。
模型特點
函數調用支持
模型經過微調,支持OpenAI風格的函數調用元數據格式,可識別並生成函數調用請求。
商業用途許可
遵循Llama 2社區許可證,允許商業用途。
對話優化
基於Llama 2聊天版本微調,專為對話場景優化。
模型能力
文本生成
函數調用
對話系統
使用案例
對話助手
天氣查詢助手
通過函數調用集成天氣API,回答用戶關於天氣的查詢。
可準確生成函數調用請求並解析返回結果。
股票信息查詢
通過函數調用獲取股票數據並回答用戶問題。
能正確生成股票查詢函數調用並解釋結果。
🚀 函數調用微調版Llama 2 Chat
本模型針對函數調用進行了微調。
- 函數元數據格式與OpenAI所使用的格式相同。
- 該模型適用於商業用途,並遵循Llama 2社區許可證。
- GGUF版本位於gguf分支中。
查看其他微調的函數調用模型,請點擊此處。
🚀 快速開始
✨ 快速服務器設置
Runpod聯盟鏈接(有助於支持Trelis頻道)。
💻 推理腳本
以下是示例提示格式。
完整的推理腳本可點擊此處購買:
- 使用
tokenizer.apply_chat_format
輕鬆格式化提示(從OpenAI格式的函數和消息列表開始)。 - 自動捕獲、處理和鏈接函數調用。
💻 使用示例
基礎用法
B_FUNC, E_FUNC = "You have access to the following functions. Use them if required:\n\n", "\n\n"
B_INST, E_INST = "[INST] ", " [/INST]" #Llama style
prompt = f"{B_INST}{B_FUNC}{functionList.strip()}{E_FUNC}{user_prompt.strip()}{E_INST}\n\n"
高級用法
使用tokenizer.apply_chat_template
為了更輕鬆地應用提示,您可以按以下方式設置:
設置messages
:
[
{
"role": "function_metadata",
"content": "FUNCTION_METADATA"
},
{
"role": "user",
"content": "What is the current weather in London?"
},
{
"role": "function_call",
"content": "{\n \"name\": \"get_current_weather\",\n \"arguments\": {\n \"city\": \"London\"\n }\n}"
},
{
"role": "function_response",
"content": "{\n \"temperature\": \"15 C\",\n \"condition\": \"Cloudy\"\n}"
},
{
"role": "assistant",
"content": "The current weather in London is Cloudy with a temperature of 15 Celsius"
}
]
將FUNCTION_METADATA
設置為:
[
{
"type": "function",
"function": {
"name": "get_current_weather",
"description": "This function gets the current weather in a given city",
"parameters": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "The city, e.g., San Francisco"
},
"format": {
"type": "string",
"enum": ["celsius", "fahrenheit"],
"description": "The temperature unit to use."
}
},
"required": ["city"]
}
}
},
{
"type": "function",
"function": {
"name": "get_clothes",
"description": "This function provides a suggestion of clothes to wear based on the current weather",
"parameters": {
"type": "object",
"properties": {
"temperature": {
"type": "string",
"description": "The temperature, e.g., 15 C or 59 F"
},
"condition": {
"type": "string",
"description": "The weather condition, e.g., 'Cloudy', 'Sunny', 'Rainy'"
}
},
"required": ["temperature", "condition"]
}
}
}
]
然後應用聊天模板以獲取格式化的提示:
tokenizer = AutoTokenizer.from_pretrained('Trelis/Llama-2-7b-chat-hf-function-calling-v3', trust_remote_code=True)
prompt = tokenizer.apply_chat_template(prompt, tokenize=False)
如果您使用的是受限模型,則需要先運行:
pip install huggingface_hub
huggingface-cli login
手動提示
[INST] You have access to the following functions. Use them if required:
[
{
"type": "function",
"function": {
"name": "get_big_stocks",
"description": "Get the names of the largest N stocks by market cap",
"parameters": {
"type": "object",
"properties": {
"number": {
"type": "integer",
"description": "The number of largest stocks to get the names of, e.g. 25"
},
"region": {
"type": "string",
"description": "The region to consider, can be \"US\" or \"World\"."
}
},
"required": [
"number"
]
}
}
},
{
"type": "function",
"function": {
"name": "get_stock_price",
"description": "Get the stock price of an array of stocks",
"parameters": {
"type": "object",
"properties": {
"names": {
"type": "array",
"items": {
"type": "string"
},
"description": "An array of stocks"
}
},
"required": [
"names"
]
}
}
}
]
[INST] Get the names of the five largest stocks in the US by market cap [/INST]
{
"name": "get_big_stocks",
"arguments": {
"number": 5,
"region": "US"
}
}</s>
📚 詳細文檔
數據集
查看數據集詳情。
Llama 2模型詳情
Llama 2是一系列預訓練和微調的生成式文本模型,參數規模從70億到700億不等。這是7B微調模型的倉庫,針對對話用例進行了優化,並轉換為Hugging Face Transformers格式。其他模型的鏈接可在底部索引中找到。
模型信息
屬性 | 詳情 |
---|---|
模型開發者 | Meta |
模型變體 | Llama 2有7B、13B和70B等不同參數規模,以及預訓練和微調版本。 |
輸入 | 僅接受文本輸入。 |
輸出 | 僅生成文本輸出。 |
模型架構 | Llama 2是一種自迴歸語言模型,採用了優化的Transformer架構。微調版本使用監督微調(SFT)和基於人類反饋的強化學習(RLHF)來符合人類對有用性和安全性的偏好。 |
訓練數據 | 新的公開在線數據組合 |
訓練日期 | 2023年1月至2023年7月 |
模型狀態 | 這是一個基於離線數據集訓練的靜態模型。隨著我們根據社區反饋改進模型安全性,未來將發佈微調模型的新版本。 |
許可證 | 自定義商業許可證可在此處獲取。 |
研究論文 | "Llama-2: Open Foundation and Fine-tuned Chat Models" |
訓練數據
- 概述:Llama 2在來自公開來源的2萬億個標記數據上進行了預訓練。微調數據包括公開可用的指令數據集,以及超過100萬個新的人工標註示例。預訓練和微調數據集均不包含Meta用戶數據。
- 數據時效性:預訓練數據截止到2022年9月,但部分微調數據更新至2023年7月。
評估結果
模型 | 規模 | 代碼 | 常識推理 | 世界知識 | 閱讀理解 | 數學 | MMLU | BBH | AGI評估 |
---|---|---|---|---|---|---|---|---|---|
Llama 1 | 7B | 14.1 | 60.8 | 46.2 | 58.5 | 6.95 | 35.1 | 30.3 | 23.9 |
Llama 1 | 13B | 18.9 | 66.1 | 52.6 | 62.3 | 10.9 | 46.9 | 37.0 | 33.9 |
Llama 1 | 33B | 26.0 | 70.0 | 58.4 | 67.6 | 21.4 | 57.8 | 39.8 | 41.7 |
Llama 1 | 65B | 30.7 | 70.7 | 60.5 | 68.6 | 30.8 | 63.4 | 43.5 | 47.6 |
Llama 2 | 7B | 16.8 | 63.9 | 48.9 | 61.3 | 14.6 | 45.3 | 32.6 | 29.3 |
Llama 2 | 13B | 24.5 | 66.9 | 55.4 | 65.8 | 28.7 | 54.8 | 39.4 | 39.1 |
Llama 2 | 70B | 37.5 | 71.9 | 63.6 | 69.4 | 35.2 | 68.9 | 51.2 | 54.2 |
模型 | 規模 | TruthfulQA | Toxigen |
---|---|---|---|
Llama 1 | 7B | 27.42 | 23.00 |
Llama 1 | 13B | 41.74 | 23.08 |
Llama 1 | 33B | 44.19 | 22.57 |
Llama 1 | 65B | 48.71 | 21.77 |
Llama 2 | 7B | 33.29 | 21.25 |
Llama 2 | 13B | 41.86 | 26.10 |
Llama 2 | 70B | 50.18 | 24.60 |
模型 | 規模 | TruthfulQA | Toxigen |
---|---|---|---|
Llama-2-Chat | 7B | 57.04 | 0.00 |
Llama-2-Chat | 13B | 62.18 | 0.00 |
Llama-2-Chat | 70B | 64.14 | 0.01 |
預期用途
- 預期用例:Llama 2旨在用於英語的商業和研究用途。微調模型適用於類似助手的聊天,而預訓練模型可用於各種自然語言生成任務。
- 超出範圍的用途:以任何違反適用法律法規(包括貿易合規法律)的方式使用;使用英語以外的語言;以Llama 2的可接受使用政策和許可協議禁止的任何其他方式使用。
硬件和軟件
- 訓練因素:我們使用自定義訓練庫、Meta的研究超級集群和生產集群進行預訓練。微調、標註和評估也在第三方雲計算上進行。
- 碳足跡:預訓練在A100 - 80GB類型的硬件上累計使用了330萬個GPU小時的計算資源(TDP為350 - 400W)。估計總排放量為539 tCO2eq,其中100%由Meta的可持續發展計劃抵消。
模型 | 時間(GPU小時) | 功耗(W) | 碳排放(tCO₂eq) |
---|---|---|---|
Llama 2 7B | 184320 | 400 | 31.22 |
Llama 2 13B | 368640 | 400 | 62.44 |
Llama 2 70B | 1720320 | 400 | 291.42 |
總計 | 3311616 | - | 539.00 |
倫理考量和侷限性
Llama 2是一項新技術,使用時存在風險。到目前為止進行的測試均使用英語,且無法涵蓋所有場景。因此,與所有大語言模型一樣,Llama 2的潛在輸出無法提前預測,在某些情況下,模型可能會對用戶提示產生不準確、有偏見或其他令人反感的響應。因此,在部署Llama 2的任何應用程序之前,開發人員應針對其特定應用對模型進行安全測試和調整。
請參閱負責任使用指南。
問題反饋
請通過以下方式報告模型的軟件“漏洞”或其他問題:
- 報告模型問題:github.com/facebookresearch/llama
- 報告模型生成的不良內容:developers.facebook.com/llama_output_feedback
- 報告漏洞和安全問題:facebook.com/whitehat/info
Llama模型索引
模型 | Llama2 | Llama2-hf | Llama2-chat | Llama2-chat-hf |
---|---|---|---|---|
7B | 鏈接 | 鏈接 | 鏈接 | 鏈接 |
13B | 鏈接 | 鏈接 | 鏈接 | 鏈接 |
70B | 鏈接 | 鏈接 | 鏈接 | 鏈接 |
Phi 2 GGUF
其他
Phi-2是微軟開發的一個小型但強大的語言模型,具有27億參數,專注於高效推理和高質量文本生成。
大型語言模型 支持多種語言
P
TheBloke
41.5M
205
Roberta Large
MIT
基於掩碼語言建模目標預訓練的大型英語語言模型,採用改進的BERT訓練方法
大型語言模型 英語
R
FacebookAI
19.4M
212
Distilbert Base Uncased
Apache-2.0
DistilBERT是BERT基礎模型的蒸餾版本,在保持相近性能的同時更輕量高效,適用於序列分類、標記分類等自然語言處理任務。
大型語言模型 英語
D
distilbert
11.1M
669
Llama 3.1 8B Instruct GGUF
Meta Llama 3.1 8B Instruct 是一個多語言大語言模型,針對多語言對話用例進行了優化,在常見的行業基準測試中表現優異。
大型語言模型 英語
L
modularai
9.7M
4
Xlm Roberta Base
MIT
XLM-RoBERTa是基於100種語言的2.5TB過濾CommonCrawl數據預訓練的多語言模型,採用掩碼語言建模目標進行訓練。
大型語言模型 支持多種語言
X
FacebookAI
9.6M
664
Roberta Base
MIT
基於Transformer架構的英語預訓練模型,通過掩碼語言建模目標在海量文本上訓練,支持文本特徵提取和下游任務微調
大型語言模型 英語
R
FacebookAI
9.3M
488
Opt 125m
其他
OPT是由Meta AI發佈的開放預訓練Transformer語言模型套件,參數量從1.25億到1750億,旨在對標GPT-3系列性能,同時促進大規模語言模型的開放研究。
大型語言模型 英語
O
facebook
6.3M
198
1
基於transformers庫的預訓練模型,適用於多種NLP任務
大型語言模型
Transformers

1
unslothai
6.2M
1
Llama 3.1 8B Instruct
Llama 3.1是Meta推出的多語言大語言模型系列,包含8B、70B和405B參數規模,支持8種語言和代碼生成,優化了多語言對話場景。
大型語言模型
Transformers 支持多種語言

L
meta-llama
5.7M
3,898
T5 Base
Apache-2.0
T5基礎版是由Google開發的文本到文本轉換Transformer模型,參數規模2.2億,支持多語言NLP任務。
大型語言模型 支持多種語言
T
google-t5
5.4M
702
精選推薦AI模型
Llama 3 Typhoon V1.5x 8b Instruct
專為泰語設計的80億參數指令模型,性能媲美GPT-3.5-turbo,優化了應用場景、檢索增強生成、受限生成和推理任務
大型語言模型
Transformers 支持多種語言

L
scb10x
3,269
16
Cadet Tiny
Openrail
Cadet-Tiny是一個基於SODA數據集訓練的超小型對話模型,專為邊緣設備推理設計,體積僅為Cosmo-3B模型的2%左右。
對話系統
Transformers 英語

C
ToddGoldfarb
2,691
6
Roberta Base Chinese Extractive Qa
基於RoBERTa架構的中文抽取式問答模型,適用於從給定文本中提取答案的任務。
問答系統 中文
R
uer
2,694
98