license: apache-2.0
language:
- vi
base_model:
- Qwen/Qwen2.5-7B-Instruct
pipeline_tag: text-generation
tags:
- retrieval-augmented-generation
- text-generation-inference
library_name: transformers
模型卡片:GRPO-VI-Qwen2-7B-RAG
模型描述:
GRPO-VI-Qwen2-7B-RAG是基于Qwen2.5-7B-Instruct模型(https://huggingface.co/Qwen/Qwen2.5-7B-Instruct)微调的大型语言模型,专为检索增强生成(RAG)任务设计。微调过程结合了监督微调与GRPO(组相对策略优化)方法。
该模型在越南语数据集上进行训练,旨在提升越南语理解和生成能力,同时增强需要整合外部文档信息的任务表现。
使用目的:
GRPO-VI-Qwen2-7B-RAG模型在保留对话能力(上下文长度达8192个标记)的同时针对RAG任务训练,因此可处理以下场景:
- RAG相关任务:多跳推理、负面过滤、信息整合及正负识别
- STEM任务(数学与编程相关)
- 通用问答
训练方法:
模型训练分为两个阶段:监督微调与GRPO优化。
-
监督微调数据:
包含1万RAG样本和3万对话样本,涵盖数学相关及通用领域问题,均遵循"先思考后回答"格式
-
GRPO数据:
包含1万RAG样本和3千数学与编程相关样本
-
奖励评分:
基于启发式规则评分,包括格式质量、推理部分长度、回答长度、越南语回答纯净度、字符串重复率,以及评估RAG和STEM任务语义质量的奖励模型
局限性:
模型可能存在以下限制:
- 不保证政治、社会等相关问题的准确性
- 可能表现出偏见或不恰当观点
基准测试
我们在团队自建的手工标注数据集EvalRAGData上评估了多个LLM的RAG任务表现。
评估由人工标注者采用10分制进行,详细结果如下:
模型 |
得分 |
GRPO-VI-Qwen2-7B-RAG |
9.24 |
Vi-Qwen2-7B-RAG |
9.03 |
Vi-Qwen2-3B-RAG |
8.65 |
Vi-Qwen2-1.5B-RAG |
8.45 |
Qwen2.5-7B-Instruct |
8.06 |
Llama3.1 |
7.55 |
Vistral 7B |
6.62 |
Vi RAG GEMMA 2B |
3.02 |
此外,我们在VMLU排行榜上的基准测试结果:
模型 |
理工科 |
社会科学 |
人文科学 |
其他 |
平均 |
GRPO_Qwen2_7B_RAG |
62.11 |
60.86 |
52.8 |
51.56 |
57.4 |
Vi-Qwen2-7B-RAG |
60.22 |
57.8 |
52.67 |
51.08 |
56.04 |
使用方法:
1. RAG应用
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
path = 'AITeamVN/GRPO-VI-Qwen2-7B-RAG'
model = AutoModelForCausalLM.from_pretrained(
path,
torch_dtype=torch.bfloat16,
device_map="auto",
use_cache=True
)
tokenizer = AutoTokenizer.from_pretrained(path)
system_prompt = """你是一位热情且诚实的越南语助手。请始终提供最有帮助的回答。
请按以下格式回答:
<think>
[你的思考分析过程]
</think>
[你的最终回答]
"""
template = '''请注意以下要求:
- 若上下文包含答案,回答必须准确完整
- 仅使用提供的上下文信息
- 若上下文无答案,只需拒绝回答不作额外推断
请基于上下文回答问题:
### 上下文 :
{context}
### 问题 :
{question}
### 回答 :'''
context = '''[此处为越南语上下文内容]'''
question = '哪些纺织企业公布了2024年营收增长超100%的经营计划?实现该目标的支撑因素有哪些?'
conversation = [{"role": "system", "content": system_prompt }]
conversation.append({"role": "user", "content": template.format(context = context, question = question)})
text = tokenizer.apply_chat_template(
conversation,
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=4096,
temperature = 0.1,
)
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]
print(response)
2. 数学问题
prompt = "解方程:2x^2 - 3x + 1 = 0"
conversation = [{"role": "system", "content": system_prompt }]
conversation.append({"role": "user", "content": prompt})
text = tokenizer.apply_chat_template(
conversation,
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=4096,
temperature = 0.1,
)
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
print(response)
3. 通用领域
prompt = "越南最高峰是哪座山?"
conversation = [{"role": "system", "content": system_prompt }]
conversation.append({"role": "user", "content": prompt})
text = tokenizer.apply_chat_template(
conversation,
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=4096,
temperature = 0.1,
)
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
print(response)
开发团队
成员:Nguyen Nho Trung, Nguyen Van Huy, Nguyễn Nhat Quang
联系方式
邮箱: nguyennhotrung3004@gmail.com
引用
@misc{ViRAG-Gen,
title={ViRAG-Gen-v2: 基于GRPO的越南语检索增强生成专用大模型},
author={Nguyen Nho Trung, Nguyen Van Huy, Nguyen Nhat Quang},
year={2025},
publisher={Huggingface},
}