license: apache-2.0
language:
- en
pipeline_tag: text-generation
tags:
- chat
base_model: Qwen/Qwen2-7B
模型概述
Qwen2-7B-Instruct-Better-Translation是基于Qwen2-7B-Instruct微调的语言模型,专门针对英译中翻译任务进行优化。该模型采用直接偏好优化(DPO)方法,使用自定义数据集进行微调,优先选择流畅地道的翻译(优选)而非字面直译(弃用)。
开发者:sevenone
- 许可证:Qwen2许可证
- 基础模型:Qwen2-7B-Instruct
- 模型规模:70亿参数
- 上下文长度:131,072 tokens(继承自Qwen2-7B-Instruct)
更多详情请参阅我们的GitHub。
1. 模型介绍
Qwen2-7B-Instruct-Better-Translation专为提供高质量的英译中翻译而设计,特别注重产出自然地道的中文表达,而非逐字直译。微调过程中使用了偏好数据集,其中优选译文为地道表达,弃用译文为字面翻译。本模型特别适合需要精准流畅翻译复杂或具有微妙含义英文文本的用户。
2. 训练细节
模型采用直接偏好优化(DPO)方法进行微调,该方法基于用户提供的偏好数据优化模型输出倾向。训练数据集包含英文原句,对应译文标注为"优选"(地道表达)或"弃用"(字面翻译)。
- 训练框架:Hugging Face Transformers
- 优化器:AdamW
- 训练方法:基于LoRA的直接偏好优化
- 训练数据:英译中偏好定制数据集
- 偏好类型:优先选择地道表达(优选)而非字面翻译(弃用)
3. 环境要求
使用本模型需确保安装transformers>=4.37.0
以避免兼容性问题。
4. 使用示例
可通过以下代码片段加载模型进行英译中翻译:
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
model_id = "sevenone/Qwen2-7B-Instruct-Better-Translation"
device = "cuda"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype="auto",
device_map="auto"
)
prompt = "将下列句子翻译成中文:'Artificial intelligence is transforming industries worldwide.'"
messages = [
{"role": "system", "content": "你是一个得力的助手。"},
{"role": "user", "content": prompt}
]
text = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True
)
model_inputs = tokenizer([text], return_tensors="pt").to(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]
print(response)
5. 引用规范
若sevenone/qwen2-7b-instruct-better-translation对您的研究有所帮助,请引用为:
@misc{sevenone_2024,
author = {sevenone},
title = {Qwen2-7B-Instruct-Better-Translation},
year = 2024,
url = {https://huggingface.co/sevenone/Qwen2-7B-Instruct-Better-Translation},
publisher = {Hugging Face}
}