模型概述
模型特點
模型能力
使用案例
🚀 RigoChat-7b-v2
RigoChat-7b-v2是基於Qwen-2.5的模型,專為準確響應西班牙語查詢而設計,在西班牙語任務上有出色表現。
🚀 快速開始
RigoChat-7b-v2是基於Qwen/Qwen2.5-7B-Instruct的模型,經過Direct Preference Optimization (DPO)微調,以提升在西班牙語任務中的性能。該模型僅允許非商業使用。若需商業使用,請聯繫我們或通過AWS Marketplace提供的服務使用。你可以在此鏈接找到使用該基礎設施的教程。
加載模型和分詞器
from transformers import (
AutoModelForCausalLM,
AutoTokenizer,
)
import torch
model_name = "IIC/RigoChat-7b-v2"
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype=torch.bfloat16,
device_map="cuda",
trust_remote_code=True,
)
tokenizer = AutoTokenizer.from_pretrained(
model_name,
trust_remote_code=True,
)
示例生成
messages = [
{"role": "user", "content": "¿Cómo puedo transformar un diccionario de listas en una lista de diccionarios, y viceversa, en Python sin utilizar bucles for?"}
]
text = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True,
)
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
generated_ids = model.generate(
**model_inputs,
max_new_tokens=1024,
)
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]
為獲得更好的體驗,建議使用以下生成參數。
工具使用
def obtener_temperatura_actual(location: str) -> float:
"""
Obtener la temperatura actual de una localización.
Args:
location: La localización, con el siguiente formato: "Ciudad, País."
Returns:
El tiempo en dicha localización, en grados Celsius.
"""
return 22.
messages = [
{"role": "user", "content": "¿Cuál es el tiempo en Madrid ahora mismo?"}
]
text = tokenizer.apply_chat_template(
messages,
tokenize=False,
tools=[obtener_temperatura_actual],
add_generation_prompt=True
)
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
generated_ids = model.generate(
**model_inputs,
max_new_tokens=1024
)
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]
更多信息請查看HuggingFace的工具使用文檔。
如果模型生成了工具調用,應按以下方式將其添加到聊天中:
import re
import json
tools = {
"obtener_temperatura_actual" : obtener_temperatura_actual,
}
tool_call = re.search(
r"<tool_call>\s*(\{.*?\})\s*</tool_call>",
response,
)
tool_call = json.loads(tool_call.group(1))
# Add tool metadata to messages
messages.append(
{
"role": "assistant",
"tool_calls": [{"type": "function", "function": tool_call}],
},
)
# Add tool result to messages
messages.append(
{
"role": "tool",
"name": tool_call["name"],
"content": tools[tool_call["name"]](**tool_call["arguments"]),
},
)
上述代碼僅適用於模型生成函數調用的情況,如果同時調用多個函數,也可使用相同的邏輯。之後,可以像往常一樣繼續生成消息:
text = tokenizer.apply_chat_template(
messages,
tokenize=False,
tools=[obtener_temperatura_actual],
add_generation_prompt=True
)
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
generated_ids = model.generate(
**model_inputs,
max_new_tokens=1024
)
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]
✨ 主要特性
- 西班牙語任務性能提升:在西班牙語的通用任務上表現更優,尤其在使用西班牙語數據庫的RAG(檢索增強生成)系統中,能減少幻覺並確保安全響應。
- 硬件適應性強:可在不同硬件要求下使用,特別是計算能力有限的硬件。有關如何在低配置硬件上使用RigoChat-7b-v2的更多信息,請參閱IIC/RigoChat-7b-v2-GGUF。
📦 安裝指南
文檔未提及具體安裝步驟,故跳過此章節。
📚 詳細文檔
模型詳情
模型描述
RigoChat-7b-v2是RigoChat系列大語言模型(LLM)的第二個版本,旨在通過西班牙語指令解決典型的NLP任務,如工具使用、摘要生成、數學計算、代碼編寫、抽象問答等。該模型基於Qwen/Qwen2.5-7B-Instruct,未針對特定用例進行設計,可應用於廣泛的任務。
- 開發者:Instituto de Ingeniería del Conocimiento (IIC)
- 模型類型:生成式微調Transformer
- 語言:西班牙語 (BCP-47 es)
- 許可證:RIGOCHAT NON-COMMERCIAL
- 架構:採用Qwen的架構,未作修改
- 微調基礎模型:Qwen/Qwen2.5-7B-Instruct
模型來源
- 論文:https://arxiv.org/abs/2503.08188
用途
直接使用
可以通過AWS Marketplace的模型包將RigoChat-v2用於商業目的。你可以查看此筆記本中的說明。
不適用場景
由於技術和倫理限制,該語言模型在以下情況下不應使用:
- 非法活動:不得用於生成與非法活動相關的內容,如創建惡意軟件、欺詐、煽動犯罪或任何非法材料。
- 有害或危險內容:不得用於生成仇恨言論、暴力、騷擾或任何促進歧視、暴力或虐待的內容。
偏差、風險和侷限性
儘管該模型經過訓練以理解和生成西班牙語文本,但用戶應注意以下風險、偏差和侷限性:
- 偏差:模型可能反映訓練數據中存在的偏差,這些偏差可能與性別、種族、社會階層、性取向等有關,並可能生成延續刻板印象或歧視的響應。
- 準確性和可靠性:雖然模型在許多上下文中生成連貫且有用的文本,但並不總是100%準確或可靠,特別是在需要高度確定性的技術、科學或法律事務中。
- 知識有限或過時:模型未使用超過其訓練截止日期的信息進行訓練,因此可能無法反映近期事件、研究或進展。
建議
建議將此模型用作通用聊天機器人,或在為特定任務設計的應用程序中使用,如SQL查詢、RAG系統,或作為促進工具使用的自主代理。
訓練詳情
訓練數據
訓練數據結合了IIC設計的公共和私有數據集,包含21975個西班牙語對話,採用chatml
格式,結構與Anthropic/hh-rlhf數據集相同。每個對話有chosen
和rejected
兩個變體,僅助手的最後一個回答不同,chosen
變體中的最後一個回答被認為比rejected
變體中的更好。生成數據集使用了多種技術,相關研究將在後續發佈。
訓練過程
使用Transformer Reinforcement Learning (TRL)庫,具體應用了他們發佈的腳本作為使用DPO對生成的數據集進行訓練的示例。
訓練超參數
詳情
LORA_CONFIG = {
"r": 64,
"lora_alpha": 16,
"lora_dropout": 0.1,
"bias": "none",
"task_type": "CAUSAL_LM",
"target_modules": [
"q_proj",
"k_proj",
"v_proj",
"o_proj",
"up_proj",
"gate_proj",
"down_proj",
],
"use_rslora": True,
}
DPO_CONFIG = {
"num_train_epochs": 2,
"logging_steps": 25,
"eval_steps": 500,
"save_steps": 100,
"save_total_limit": 5,
"per_device_train_batch_size": 1,
"per_device_eval_batch_size": 1,
"gradient_accumulation_steps": 16,
"learning_rate": 5e-6,
"max_length": 8192, # max length in the history chat + latest assistant response.
"max_prompt_length": 6656, # max length in the history chat: user-assistant-...-assistant-user.
"gradient_checkpointing": True,
"weight_decay": 0.001,
"optim": "rmsprop",
"evaluation_strategy": "steps",
"lr_scheduler_type": "cosine",
"bf16": True,
}
速度、大小、時間
以下是顯示最新訓練日誌結果的一些有用參數:
latest_logs = {'loss': 0.3716, 'grad_norm': 4.989994049072266, 'learning_rate': 1.0380020311950844e-10, 'rewards/chosen': 0.534086287021637, 'rewards/rejected': -0.6236276030540466, 'rewards/accuracies': 0.8899999856948853, 'rewards/margins': 1.1577140092849731, 'logps/rejected': -218.88198852539062, 'logps/chosen': -250.0700225830078, 'logits/rejected': -1.6214849948883057, 'logits/chosen': -1.9585875272750854, 'epoch': 1.99}
final_training_results = {'train_runtime': 30825.7138, 'train_samples_per_second': 1.432, 'train_steps_per_second': 0.089, 'train_loss': 0.483570138469306, 'epoch': 2.0}
從使用時間可以看出,在八個半小時內,使用很少的硬件就成功改進了一個最先進的模型,使其在適應西班牙語的任務中表現出色。
評估
測試數據、因素和指標
測試數據
為評估大語言模型(LLM)的性能,開發並使用了幾個針對特定評估需求的高質量語料庫:
- IIC/AQuAS:由兩位計算語言學家手動策劃的語料庫,用於評估語言模型在西班牙語抽象問答任務中的表現,包括金融、保險、醫療、法律和音樂等領域的示例。
- IIC/RagQuAS:同樣由上述語言學家開發的語料庫,用於評估完整的RAG系統和語言模型在西班牙語抽象問答任務中的表現,涵蓋愛好、語言學、寵物、健康、天文學、客戶服務、汽車、日常生活、文檔、能源、滑雪、欺詐、美食、語言、遊戲、美甲、音樂、滑冰、急救、食譜、回收、投訴、保險、網球、交通、旅遊、獸醫、旅行和瑜伽等廣泛領域。
- CAM:專為所有CAM任務設計,該語料庫包含來自馬德里社區網站上消費者相關主題的常見問題(FAQ),問題分為三個退化級別(E1、E2和E3),旨在衡量LLM理解和有效響應因拼寫錯誤、不同程度的口語化等問題導致的表述不佳查詢的能力,此任務也屬於抽象問答類別。
- Shops:一個以各種服裝公司政策為中心的多輪對話語料庫,涉及多輪抽象問答。
- Insurance:另一個多輪對話語料庫,專注於各種保險公司的政策,也涉及多輪抽象問答。
每個語料庫包含以下列:問題、答案和包含模型可從中得出答案的相關信息的上下文。在多輪任務中,還提供聊天曆史記錄。
LLM的評分過程涉及測量原始答案與模型生成答案之間的相似度。除AQuAS和RagQuAS公開可用外,所有語料庫均為私有,可作為其他語料庫結構和內容的示例。
因素
這些評估非常具體,未涵蓋模型可能面臨的所有一般場景,因為所有評估都集中在解決非常特定領域的RAG任務上。
指標
評估基於使用Llama-3.1-8B-Instruct對答案進行評分。
結果
模型 | 平均得分 | AQuAS | RagQuAS | CAM | CAM_E1 | CAM_E2 | CAM_E3 | Shops | Insurance |
---|---|---|---|---|---|---|---|---|---|
RigoChat-7b-v2 | 79.55 | 82.52 | 79.10 | 78.91 | 79.17 | 76.73 | 78.23 | 80.79 | 81.04 |
GPT-4o | 78.26 | 85.23 | 77.91 | 78.00 | 74.91 | 73.45 | 77.09 | 78.60 | 80.89 |
stablelm-2-12b-chat | 77.74 | 78.88 | 78.21 | 77.82 | 78.73 | 77.27 | 74.73 | 77.03 | 79.26 |
Mistral-Small-Instruct-2409 | 77.29 | 80.56 | 78.81 | 77.82 | 75.82 | 73.27 | 73.45 | 78.25 | 80.36 |
Qwen2.5-7B-Instruct | 77.17 | 80.93 | 77.41 | 77.82 | 75.09 | 75.45 | 72.91 | 78.08 | 79.67 |
Meta-Llama-3.1-8B-Instruct | 76.55 | 81.87 | 80.50 | 72.91 | 73.45 | 75.45 | 71.64 | 77.73 | 78.88 |
GPT-4o-mini | 76.48 | 82.80 | 75.82 | 76.36 | 74.36 | 72.36 | 71.82 | 78.25 | 80.08 |
Phi-3.5-mini-instruct | 76.38 | 81.68 | 81.09 | 75.82 | 74.73 | 71.45 | 70.36 | 77.43 | 78.45 |
gemma-2-9b-it | 75.80 | 82.80 | 78.11 | 72.91 | 73.45 | 71.09 | 71.27 | 77.08 | 79.72 |
Ministral-8B-Instruct-2410 | 75.19 | 79.63 | 77.31 | 76.00 | 73.45 | 72.36 | 70.18 | 76.44 | 76.14 |
GPT-3.5-turbo-0125 | 74.78 | 80.93 | 73.53 | 76.73 | 72.55 | 72.18 | 69.09 | 75.63 | 77.64 |
Llama-2-7b-chat-hf | 71.18 | 67.10 | 77.31 | 71.45 | 70.36 | 70.73 | 68.55 | 72.07 | 71.90 |
granite-3.0-8b-instruct | 71.08 | 73.08 | 72.44 | 72.36 | 71.82 | 69.09 | 66.18 | 69.97 | 73.73 |
RigoChat-7b-v1 | 62.13 | 72.34 | 67.46 | 61.27 | 59.45 | 57.45 | 57.64 | 62.10 | 59.34 |
salamandra-7b-instruct | 61.96 | 63.74 | 60.70 | 64.91 | 63.27 | 62.36 | 60.55 | 59.94 | 60.23 |
總結
RigoChat-7b-v2在間接設計的任務中,相較於Qwen-2.5顯著提高了性能。此外,在這些任務中,它優於大多數最先進的模型,證明了使用少量資源可以使LLM適應特定用例。
🔧 技術細節
環境影響
可使用機器學習影響計算器估算碳排放,該計算器在Lacoste等人 (2019) 中提出。
- 硬件類型:A100 PCIe 80GB
- 使用時長:8.5小時
- 雲服務提供商:私有基礎設施
- 計算區域:西班牙
- 碳排放:0.92
硬件
NVIDIA A100 GPU,帶有Tensor Core和80GB內存。
軟件
Ubuntu 22.04.5 LTS
,並需要以下依賴:
python=3.11
flash_attn>=2.5.8
datasets
numpy
trl
peft
huggingface_hub
📄 許可證
該模型採用RIGOCHAT NON-COMMERCIAL許可證,許可證詳情請見此處。
📚 引用
@misc {instituto_de_ingeniería_del_conocimiento_2025,
author = { {Instituto de Ingeniería del Conocimiento} },
title = { RigoChat-7b-v2 },
year = 2025,
url = { https://huggingface.co/IIC/RigoChat-7b-v2 },
doi = { 10.57967/hf/4158 },
publisher = { Hugging Face }
}
@misc{gómez2025rigochat2adaptedlanguage,
title={RigoChat 2: an adapted language model to Spanish using a bounded dataset and reduced hardware},
author={Gonzalo Santamaría Gómez and Guillem García Subies and Pablo Gutiérrez Ruiz and Mario González Valero and Natàlia Fuertes and Helena Montoro Zamorano and Carmen Muñoz Sanz and Leire Rosado Plaza and Nuria Aldama García and David Betancur Sánchez and Kateryna Sushkova and Marta Guerrero Nieto and Álvaro Barbero Jiménez},
year={2025},
eprint={2503.08188},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2503.08188},
}
⚠️ 免責聲明
請注意,模型可能包含基於訓練數據的偏差或其他不良扭曲。當第三方基於此模型實施系統或提供服務,或自行使用該模型時,他們有責任減輕相關風險並確保遵守適用的法規,包括人工智能使用的法規。IIC作為模型的所有者和創建者,不對第三方使用導致的任何結果承擔責任。
📞 模型卡片聯繫信息
contacto.iic@iic.uam.es
©️ 版權聲明
- 作者:Instituto de Ingeniería del Conocimiento (IIC)
- 聯繫方式:如需更多信息,請發送電子郵件至contacto.iic@iic.uam.es
- 版權:Copyright(c) 2024 ADIC



