🚀 Qwen2-7B-Instruct-Better-Translation
Qwen2-7B-Instruct-Better-Translation是基于Qwen2-7B-Instruct微调的语言模型,专门针对提升英文到中文的翻译效果进行了优化。该模型使用直接偏好优化(DPO)方法,在自定义数据集上进行微调,优先选择流畅、地道的翻译(选中)而非逐字逐句的直译(拒绝)。
🚀 快速开始
Qwen2-7B-Instruct-Better-Translation旨在提供高质量的英文到中文翻译,尤其注重产出自然、地道的译文,而非逐字逐句的直译。微调过程使用了一个偏好数据集,其中选中的翻译是地道的,而被拒绝的翻译则更偏向直译。该模型非常适合需要对复杂或有细微差别的英文文本进行准确、流畅翻译的用户。
✨ 主要特性
- 基于Qwen2-7B-Instruct进行微调,专注于英文到中文的翻译优化。
- 使用直接偏好优化(DPO)方法,优先选择地道的翻译。
- 上下文长度达131,072个标记,能处理长文本翻译。
📦 安装指南
要使用此模型,请确保已安装 transformers>=4.37.0
以避免任何兼容性问题。
💻 使用示例
基础用法
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 = "Translate the following sentence to Chinese: 'Artificial intelligence is transforming industries worldwide.'"
messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"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)
📚 详细文档
模型信息
属性 |
详情 |
开发者 |
sevenone |
许可证 |
Qwen2 License |
基础模型 |
Qwen2-7B-Instruct |
模型大小 |
7B |
上下文长度 |
131,072个标记(继承自Qwen2-7B-Instruct) |
训练详情
该模型使用直接偏好优化(DPO)进行微调,这是一种根据用户提供的偏好,优化模型使其更倾向于某些输出的方法。训练数据集包含英文源句子,对应的翻译被标记为“选中”(地道)或“拒绝”(直译)。
- 训练框架:Hugging Face Transformers
- 优化器:AdamW
- 训练方法:Lora与直接偏好优化结合
- 训练数据:用于英文到中文翻译的自定义偏好数据集
- 偏好类型:优先选择地道的翻译(选中)而非直译(拒绝)
引用信息
如果 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}
}
如需更多详细信息,请参考我们的 GitHub。