Gemma 2 9b It Russian Function Calling GGUF
該模型是基於google/gemma-2-9b-it針對函數調用任務進行微調的版本,訓練數據完全由人工標註,使用了俄語版本的DiTy/function-calling數據集。
Downloads 509
Release Time : 4/25/2025
Model Overview
該模型是一個針對函數調用任務優化的俄語語言模型,能夠理解和生成函數調用請求,並處理函數響應。
Model Features
函數調用優化
專門針對函數調用任務進行微調,能夠生成準確的函數調用請求和處理響應。
俄語支持
支持俄語,適用於俄語環境下的函數調用任務。
高效推理
基於Gemma-2-9b-it架構,推理速度快,適合即時應用。
Model Capabilities
函數調用生成
俄語文本生成
函數響應處理
Use Cases
智能助手
天氣查詢
用戶詢問天氣時,模型生成函數調用請求並返回天氣信息。
提供準確的天氣信息
日出日落時間查詢
用戶詢問日出日落時間時,模型生成函數調用請求並返回時間信息。
提供準確的日出日落時間
🚀 DiTy/gemma-2-9b-it-russian-function-calling-GGUF
本模型是 google/gemma-2-9b-it 的微調版本,用於在非合成數據上執行 函數調用 任務。這些數據僅由人工進行了完整註釋,來自俄語版的 DiTy/function-calling 數據集。
除了 safetensors 格式外,該模型還提供 GGUF 格式(在這種情況下,您只需下載單個文件(如何推理 GGUF 模型)):
文件名 | 量化類型 | 文件大小 | 描述 |
---|---|---|---|
gemma-2-9B-it-russian-function-calling-F16.gguf | F16 | 18.5GB | 採用 float16 的基礎模型 |
📚 模型卡片章節
🚀 快速開始
📦 安裝指南
首先,您需要安裝 transformers
庫:
pip install -U transformers
💻 使用示例
基礎用法
如何為 函數調用 準備您的函數(工具)
您需要用 Python 代碼 編寫模型使用的函數(工具),並務必添加 Python 文檔字符串,如下例所示:
def get_weather(city: str):
"""
該函數用於返回指定城市的天氣情況。
參數:
city: 需要查詢天氣的城市。
"""
import random
return "sunny" if random.random() > 0.5 else "rainy"
def get_sunrise_sunset_times(city: str):
"""
該函數用於返回指定城市當前日期的日出和日落時間(無需用戶提供日期),格式為列表:[日出時間, 日落時間]。
參數:
city: 可以查詢日出和日落時間的城市。
"""
return ["6:00", "18:00"]
直接使用聊天模板進行生成
接下來,您需要加載模型和分詞器:
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
model = AutoModelForCausalLM.from_pretrained(
"DiTy/gemma-2-9b-it-russian-function-calling-GGUF",
device_map="auto",
torch_dtype=torch.bfloat16, # 如果您的環境不支持 bfloat16,可以使用 float16 或 float32。
cache_dir=PATH_TO_MODEL_DIR, # 可選
)
tokenizer = AutoTokenizer.from_pretrained(
"DiTy/gemma-2-9b-it-russian-function-calling-GGUF",
cache_dir=PATH_TO_MODEL_DIR, # 可選
)
要獲得生成結果,只需使用 apply_chat_template
。為了考慮我們編寫的函數(工具),我們需要通過 tools
屬性將它們作為列表傳遞,並使用 add_prompt_generation=True
:
history_messages = [
{"role": "system", "content": "你是一個有用的助手,可以使用以下函數。如有需要,請使用它們 - "},
{"role": "user", "content": "你好,你能告訴我克拉斯諾達爾的日出時間嗎?"}
]
inputs = tokenizer.apply_chat_template(
history_messages,
tokenize=False,
add_generation_prompt=True, # 添加生成提示
tools=[get_weather, get_sunrise_sunset_times], # 我們的函數(工具)
)
print(inputs)
此時,我們的 inputs
將如下所示:
<bos><start_of_turn>user
你是一個有用的助手,可以使用以下函數。如有需要,請使用它們 - {
"name": "get_weather",
"description": "該函數用於返回指定城市的天氣情況。",
"parameters": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "需要查詢天氣的城市。"
}
},
"required": [
"city"
]
}
},
{
"name": "get_sunrise_sunset_times",
"description": "該函數用於返回指定城市當前日期的日出和日落時間(無需用戶提供日期),格式為列表:[日出時間, 日落時間]。",
"parameters": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "可以查詢日出和日落時間的城市。"
}
},
"required": [
"city"
]
}
}
你好,你能告訴我克拉斯諾達爾的日出時間嗎?<end_of_turn>
<start_of_turn>model
現在,我們可以生成模型的響應。請注意,在使用 apply_chat_template
之後,在分詞時不需要 添加特殊標記。因此,我們使用 add_special_tokens=False
:
terminator_ids = [
tokenizer.eos_token_id,
tokenizer.convert_tokens_to_ids("<end_of_turn>"),
]
prompt_ids = tokenizer.encode(inputs, add_special_tokens=False, return_tensors='pt').to(model.device)
generated_ids = model.generate(
prompt_ids,
max_new_tokens=512,
eos_token_id=terminator_ids,
bos_token_id=tokenizer.bos_token_id,
)
generated_response = tokenizer.decode(generated_ids[0][prompt_ids.shape[-1]:], skip_special_tokens=False) # `skip_special_tokens=False` 用於調試
print(generated_response)
我們得到的生成結果是一個函數調用:
函數調用: {"name": "get_sunrise_sunset_times", "arguments": {"city": "克拉斯諾達爾"}}<end_of_turn>
很好,現在我們可以使用我們的 可調用函數 獲取並處理結果,然後向模型提供 函數 的響應:
history_messages = [
{"role": "system", "content": "你是一個有用的助手,可以使用以下函數。如有需要,請使用它們 - "},
{"role": "user", "content": "你好,你能告訴我克拉斯諾達爾的日出時間嗎?"},
{"role": "function-call", "content": '{"name": "get_sunrise_sunset_times", "arguments": {"city": "Los Angeles"}}'},
{"role": "function-response", "content": '{"times_list": ["6:00", "18:00"]}'}, # 假設我們的函數返回的響應
]
inputs = tokenizer.apply_chat_template(
history_messages,
tokenize=False,
add_generation_prompt=True, # 添加生成提示
tools=[get_weather, get_sunrise_sunset_times], # 我們的函數(工具)
)
print(inputs)
讓我們確保 inputs
是正確的:
<bos><start_of_turn>user
你是一個有用的助手,可以使用以下函數。如有需要,請使用它們 - {
"name": "get_weather",
"description": "該函數用於返回指定城市的天氣情況。",
"parameters": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "需要查詢天氣的城市。"
}
},
"required": [
"city"
]
}
},
{
"name": "get_sunrise_sunset_times",
"description": "該函數用於返回指定城市當前日期的日出和日落時間(無需用戶提供日期),格式為列表:[日出時間, 日落時間]。",
"parameters": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "可以查詢日出和日落時間的城市。"
}
},
"required": [
"city"
]
}
}
你好,你能告訴我克拉斯諾達爾的日出時間嗎?<end_of_turn>
<start_of_turn>model
函數調用: {"name": "get_sunrise_sunset_times", "arguments": {"city": "克拉斯諾達爾"}}<end_of_turn>
<start_of_turn>user
函數響應: {"times_list": ["6:00", "18:00"]}<end_of_turn>
<start_of_turn>model
同樣,我們生成模型的響應:
prompt_ids = tokenizer.encode(inputs, add_special_tokens=False, return_tensors='pt').to(model.device)
generated_ids = model.generate(
prompt_ids,
max_new_tokens=512,
eos_token_id=terminator_ids,
bos_token_id=tokenizer.bos_token_id,
)
generated_response = tokenizer.decode(generated_ids[0][prompt_ids.shape[-1]:], skip_special_tokens=False) # `skip_special_tokens=False` 用於調試
print(generated_response)
結果,我們得到了模型的響應:
克拉斯諾達爾的日出時間是早上 6:00,日落時間是晚上 18:00。<end_of_turn>
高級用法
使用 transformers
的 pipeline
進行生成
使用 pipeline 進行生成
from transformers import pipeline
generation_pipeline = pipeline(
"text-generation",
model="DiTy/gemma-2-9b-it-russian-function-calling-GGUF",
model_kwargs={
"torch_dtype": torch.bfloat16, # 如果您的環境不支持 bfloat16,可以使用 float16 或 float32。
"cache_dir": PATH_TO_MODEL_DIR, # 可選
},
device_map="auto",
)
history_messages = [
{"role": "system", "content": "你是一個有用的助手,可以使用以下函數。如有需要,請使用它們 - "},
{"role": "user", "content": "你好,你能告訴我克拉斯諾達爾的日出時間嗎?"},
{"role": "function-call", "content": '{"name": "get_sunrise_sunset_times", "arguments": {"city": "克拉斯諾達爾"}}'},
{"role": "function-response", "content": '{"times_list": ["6:00", "18:00"]}'}
]
inputs = generation_pipeline.tokenizer.apply_chat_template(
history_messages,
tokenize=False,
add_generation_prompt=True,
tools=[get_weather, get_sunrise_sunset_times],
)
terminator_ids = [
generation_pipeline.tokenizer.eos_token_id,
generation_pipeline.tokenizer.convert_tokens_to_ids("<end_of_turn>")
]
outputs = generation_pipeline(
inputs,
max_new_tokens=512,
eos_token_id=terminator_ids,
)
print(outputs[0]["generated_text"][len(inputs):])
📚 詳細文檔
提示結構和預期內容
為了使模型正常工作,建議使用 apply_chat_template
。您需要以特定格式傳遞消息歷史記錄:
history_messages = [
{"role": "...", "content": "..."},
...
]
可用的角色如下:
system
- 這是一個可選角色,其內容始終位於最前面,並在列出模型可用的函數(工具)之前。您可以始終使用訓練期間使用的標準模板:"你是一個有用的助手,可以使用以下函數。如有需要,請使用它們 - "user
- 用戶的請求通過此角色傳遞。function-call
- 函數調用的主體通過此角色傳遞。儘管模型經過訓練以生成 "函數調用: {...}<end_of_turn>" 形式的函數調用,但您仍然只需在 "content" 字段中傳遞主體 "{...}",因為使用apply_chat_template
時,指令中的後綴會自動添加。function-response
- 在這個角色中,我們需要以字典 '{"name_returnable_value": value}' 的形式在 "content" 字段中傳遞函數的響應。model
- 與此角色相關的內容被視為模型生成的文本。
函數調用的聊天曆史結構
[
{"role": "system", "content": "你是一個有用的助手,可以使用以下函數。如有需要,請使用它們 - "},
{"role": "user", "content": "你好,你能告訴我克拉斯諾達爾的日出時間嗎?"},
{"role": "function-call", "content": '{"name": "get_sunrise_sunset_times", "arguments": {"city": "克拉斯諾達爾"}}'},
{"role": "function-response", "content": '{"times_list": ["6:00", "18:00"]}'}
]
這看起來像:
<bos><start_of_turn>user
你是一個有用的助手,可以使用以下函數。如有需要,請使用它們 - {
"name": "get_weather",
"description": "該函數用於返回指定城市的天氣情況。",
"parameters": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "需要查詢天氣的城市。"
}
},
"required": [
"city"
]
}
},
{
"name": "get_sunrise_sunset_times",
"description": "該函數用於返回指定城市當前日期的日出和日落時間(無需用戶提供日期),格式為列表:[日出時間, 日落時間]。",
"parameters": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "可以查詢日出和日落時間的城市。"
}
},
"required": [
"city"
]
}
}
你好,你能告訴我克拉斯諾達爾的日出時間嗎?<end_of_turn>
<start_of_turn>model
函數調用: {"name": "get_sunrise_sunset_times", "arguments": {"city": "克拉斯諾達爾"}}<end_of_turn>
<start_of_turn>user
函數響應: {"times_list": ["6:00", "18:00"]}<end_of_turn>
普通用戶 - 模型模板的聊天曆史結構
[
{"role": "system", "content": "你是一個友好的助手"},
{"role": "user", "content": "給我講講莫斯科"}
]
這看起來像:
<bos><start_of_turn>user
你是一個友好的助手
給我講講莫斯科<end_of_turn>
🔧 技術細節
模型評估
在訓練過程中,驗證損失接近以下值:
模型 | 生成語言 | 近似驗證損失 |
---|---|---|
DiTy/gemma-2-27b-it-function-calling-GGUF | EN | 0.47 |
DiTy/gemma-2-9b-it-russian-function-calling-GGUF | RU | 0.57 |
DiTy/gemma-2-9b-it-function-calling-GGUF | EN | 0.5 |
DiTy/gemma-2-2b-it-function-calling | EN | 0.66 |
📄 許可證
本模型採用 apache-2.0
許可證。
📖 引用
@article{gemma_2024,
title={Gemma},
url={https://www.kaggle.com/m/3301},
DOI={10.34740/KAGGLE/M/3301},
publisher={Kaggle},
author={Gemma Team},
year={2024}
}
Phi 2 GGUF
Other
Phi-2是微軟開發的一個小型但強大的語言模型,具有27億參數,專注於高效推理和高質量文本生成。
大型語言模型 Supports Multiple Languages
P
TheBloke
41.5M
205
Roberta Large
MIT
基於掩碼語言建模目標預訓練的大型英語語言模型,採用改進的BERT訓練方法
大型語言模型 English
R
FacebookAI
19.4M
212
Distilbert Base Uncased
Apache-2.0
DistilBERT是BERT基礎模型的蒸餾版本,在保持相近性能的同時更輕量高效,適用於序列分類、標記分類等自然語言處理任務。
大型語言模型 English
D
distilbert
11.1M
669
Llama 3.1 8B Instruct GGUF
Meta Llama 3.1 8B Instruct 是一個多語言大語言模型,針對多語言對話用例進行了優化,在常見的行業基準測試中表現優異。
大型語言模型 English
L
modularai
9.7M
4
Xlm Roberta Base
MIT
XLM-RoBERTa是基於100種語言的2.5TB過濾CommonCrawl數據預訓練的多語言模型,採用掩碼語言建模目標進行訓練。
大型語言模型 Supports Multiple Languages
X
FacebookAI
9.6M
664
Roberta Base
MIT
基於Transformer架構的英語預訓練模型,通過掩碼語言建模目標在海量文本上訓練,支持文本特徵提取和下游任務微調
大型語言模型 English
R
FacebookAI
9.3M
488
Opt 125m
Other
OPT是由Meta AI發佈的開放預訓練Transformer語言模型套件,參數量從1.25億到1750億,旨在對標GPT-3系列性能,同時促進大規模語言模型的開放研究。
大型語言模型 English
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 Supports Multiple Languages

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

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

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