Qwen2 7B Instruct
基於Qwen2-7B-Instruct進一步後訓練的模型,擅長處理複雜的多輪工具/函數調用任務。
下載量 62
發布時間 : 6/10/2024
模型概述
該模型是對Qwen/Qwen2-7B-Instruct進行後訓練的成果,能夠處理複雜的多輪工具/函數調用任務,支持中英文對話。
模型特點
函數調用能力
支持複雜的多輪工具/函數調用任務,能夠生成函數調用請求並處理返回結果。
多語言支持
支持英文和中文的文本生成任務。
高性能
在多個基準測試中表現優異,如MMLU、GPQA、GSM-8K等。
模型能力
文本生成
函數調用
工具調用
多輪對話
使用案例
數學計算
鏈式數學問題求解
通過函數調用逐步解決複雜的數學問題,如加法、減法、乘法和除法。
生成函數調用請求並逐步求解。
對話系統
多輪對話
支持複雜的多輪對話任務,能夠處理用戶的多輪提問和工具調用需求。
生成連貫且符合上下文的回覆。
🚀 Rubra-Qwen2-7B-Instruct
本模型是基於Qwen/Qwen2-7B-Instruct進行進一步後訓練得到的成果,能夠處理複雜的多輪工具/函數調用任務。
🚀 快速開始
本模型可結合Hugging Face的transformers
庫以及rubra庫 rubra-tools 使用。
✨ 主要特性
- 基於Qwen/Qwen2-7B-Instruct進一步後訓練。
- 能夠進行復雜的多輪工具/函數調用。
📦 安裝指南
安裝Python依賴
pip install rubra_tools torch==2.3.0 transformers accelerate
安裝Node.js和npm依賴
你還需要安裝Node.js和npm,然後安裝jsonrepair
包,用於修復模型偶爾產生的幻覺問題。
npm install jsonrepair
💻 使用示例
基礎用法
1. 加載模型
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
from rubra_tools import preprocess_input, postprocess_output
model_id = "rubra-ai/Qwen2-7B-Instruct"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype="auto",
device_map="auto",
)
2. 定義函數
這裡我們使用4個函數來處理一個簡單的數學鏈式問題:
functions = [
{
'type': 'function',
'function': {
'name': 'addition',
'description': "Adds two numbers together",
'parameters': {
'type': 'object',
'properties': {
'a': {
'description': 'First number to add',
'type': 'string'
},
'b': {
'description': 'Second number to add',
'type': 'string'
}
},
'required': []
}
}
},
{
'type': 'function',
'function': {
'name': 'subtraction',
'description': "Subtracts two numbers",
'parameters': {
'type': 'object',
'properties': {
'a': {
'description': 'First number to be subtracted from',
'type': 'string'
},
'b': {
'description': 'Number to subtract',
'type': 'string'
}
},
'required': []
}
}
},
{
'type': 'function',
'function': {
'name': 'multiplication',
'description': "Multiply two numbers together",
'parameters': {
'type': 'object',
'properties': {
'a': {
'description': 'First number to multiply',
'type': 'string'
},
'b': {
'description': 'Second number to multiply',
'type': 'string'
}
},
'required': []
}
}
},
{
'type': 'function',
'function': {
'name': 'division',
'description': "Divide two numbers",
'parameters': {
'type': 'object',
'properties': {
'a': {
'description': 'First number to use as the dividend',
'type': 'string'
},
'b': {
'description': 'Second number to use as the divisor',
'type': 'string'
}
},
'required': []
}
}
},
]
3. 開始對話
messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is the result of four plus six? Take the result and add 2? Then multiply by 5 and then divide by two"},
]
def run_model(messages, functions):
## Format messages in Rubra's format
formatted_msgs = preprocess_input(msgs=messages, tools=functions)
text = tokenizer.apply_chat_template(
formatted_msgs,
tokenize=False,
add_generation_prompt=True
)
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
generated_ids = model.generate(
model_inputs.input_ids,
max_new_tokens=512
)
generated_ids = [
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
]
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
return response
raw_output = run_model(messages, functions)
# Check if there's a function call
function_call = postprocess_output(raw_output)
if function_call:
print(function_call)
else:
print(raw_output)
你應該會看到如下輸出,這是AI助手發起的函數調用:
[{'id': 'fc65a533', 'function': {'name': 'addition', 'arguments': '{"a": "4", "b": "6"}'}, 'type': 'function'}]
4. 將執行的工具結果添加到消息歷史並繼續對話
if function_call:
# append the assistant tool call msg
messages.append({"role": "assistant", "tool_calls": function_call})
# append the result of the tool call in openai format, in this case, the value of add 6 to 4 is 10.
messages.append({'role': 'tool', 'tool_call_id': function_call[0]["id"], 'name': function_call[0]["function"]["name"], 'content': '10'})
raw_output1 = run_model(messages, functions)
# Check if there's a function call
function_call = postprocess_output(raw_output1)
if function_call:
print(function_call)
else:
print(raw_output)
大語言模型會發起另一個調用:
[{'id': '2ffc3de4', 'function': {'name': 'addition', 'arguments': '{"a": "10", "b": "2"}'}, 'type': 'function'}]
📚 詳細文檔
框架版本
- Transformers 4.41.2
- Pytorch 2.3.1+cu121
- Datasets 2.19.2
- Tokenizers 0.19.1
侷限性和偏差
儘管該模型在眾多任務上表現出色,但仍可能產生有偏差或錯誤的輸出。在敏感或高風險應用中使用該模型時,用戶應謹慎並進行批判性判斷。模型的輸出受其訓練數據的影響,而這些數據可能存在固有偏差。
倫理考量
用戶應確保該模型的部署符合倫理準則,並考慮生成文本可能產生的社會影響。強烈反對將該模型用於生成有害或誤導性內容。
致謝
我們感謝阿里雲提供了該模型。
聯繫信息
如有關於該模型的問題或建議,請聯繫 rubra團隊。
引用信息
如果使用此模型,請按以下格式引用:
@misc {rubra_ai_2024,
author = { Sanjay Nadhavajhala and Yingbei Tong },
title = { Rubra-Qwen2-7B-Instruct },
year = 2024,
url = { https://huggingface.co/rubra-ai/Qwen2-7B-Instruct },
doi = { 10.57967/hf/2683 },
publisher = { Hugging Face }
}
信息表格
屬性 | 詳情 |
---|---|
模型類型 | 文本生成 |
訓練數據 | 專有數據集,包含各種函數調用、聊天和指令數據 |
提示信息
⚠️ 重要提示
儘管該模型在眾多任務上表現出色,但仍可能產生有偏差或錯誤的輸出。在敏感或高風險應用中使用該模型時,用戶應謹慎並進行批判性判斷。
💡 使用建議
用戶應確保該模型的部署符合倫理準則,並考慮生成文本可能產生的社會影響。強烈反對將該模型用於生成有害或誤導性內容。
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