🚀 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。