🚀 翻譯模型
本模型是一款專為法語 - 沃洛夫語以及沃洛夫語 - 法語翻譯而優化的模型。它基於 nllb - 200 - distilled - 600M 進行微調,使用了 bilalfaye/english - wolof - french - translation 和 bilalfaye/english - wolof - french - translation - bis 數據集進行訓練,這些數據集經過了大量預處理,以提高翻譯質量。
支持語言
該模型支持以下雙向翻譯:
- 沃洛夫語到法語
- 法語到沃洛夫語
- 英語到沃洛夫語
- 沃洛夫語到英語
- 法語到英語
- 英語到法語
測試應用鏈接:https://huggingface.co/spaces/bilalfaye/WoFrEn - Translator
🚀 快速開始
✨ 主要特性
- 基於 nllb - 200 - distilled - 600M 微調,適用於多種語言對的翻譯。
- 支持雙向翻譯,涵蓋沃洛夫語、法語和英語。
- 經過數據集預處理,提升翻譯質量。
📦 安裝指南
安裝所需庫:
!pip install transformers
💻 使用示例
基礎用法
手動推理:
from transformers import NllbTokenizer, AutoModelForSeq2SeqLM
import torch
device = "cuda" if torch.cuda.is_available() else "cpu"
model_load_name = 'bilalfaye/nllb-200-distilled-600M-wo-fr-en'
model = AutoModelForSeq2SeqLM.from_pretrained(model_load_name).to(device)
tokenizer = NllbTokenizer.from_pretrained(model_load_name)
def translate(
text, src_lang='wol_Latn', tgt_lang='french_Latn',
a=32, b=3, max_input_length=1024, num_beams=4, **kwargs
):
"""Turn a text or a list of texts into a list of translations"""
tokenizer.src_lang = src_lang
tokenizer.tgt_lang = tgt_lang
inputs = tokenizer(
text, return_tensors='pt', padding=True, truncation=True,
max_length=max_input_length
)
model.eval()
result = model.generate(
**inputs.to(model.device),
forced_bos_token_id=tokenizer.convert_tokens_to_ids(tgt_lang),
max_new_tokens=int(a + b * inputs.input_ids.shape[1]),
num_beams=num_beams, **kwargs
)
return tokenizer.batch_decode(result, skip_special_tokens=True)
print(translate("Ndax mën nga ko waxaat su la neexee?", src_lang="wol_Latn", tgt_lang="french_Latn")[0])
print(translate("Ndax mën nga ko waxaat su la neexee?", src_lang="wol_Latn", tgt_lang="eng_Latn")[0])
print(translate("Bonjour, où allez-vous?", src_lang="fra_Latn", tgt_lang="wol_Latn")[0])
print(translate("Bonjour, où allez-vous?", src_lang="fra_Latn", tgt_lang="eng_Latn")[0])
print(translate("Hello, how are you?", src_lang="eng_Latn", tgt_lang="wol_Latn")[0])
print(translate("Hello, how are you?", src_lang="eng_Latn", tgt_lang="fr_Latn")[0])
高級用法
使用管道進行推理:
from transformers import pipeline
model_name = 'bilalfaye/nllb-200-distilled-600M-wo-fr-en'
device = "cuda" if torch.cuda.is_available() else "cpu"
translator = pipeline("translation", model=model_name, device=device)
print(translator("Ndax mën nga ko waxaat su la neexee?", src_lang="wol_Latn", tgt_lang="fra_Latn")[0]['translation_text'])
print(translator("Bonjour, où allez-vous?", src_lang="fra_Latn", tgt_lang="wol_Latn")[0]['translation_text'])
📚 詳細文檔
信息表格
屬性 |
詳情 |
模型類型 |
基於 nllb - 200 - distilled - 600M 微調的翻譯模型 |
訓練數據 |
bilalfaye/english - wolof - french - translation 和 bilalfaye/english - wolof - french - translation - bis 數據集 |
支持語言 |
沃洛夫語(wo)、法語(fr)、英語(en) |
評估指標 |
BLEU、CHRF |
基礎模型 |
facebook/nllb - 200 - distilled - 600M |
任務類型 |
翻譯 |
包版本
本模型在開發和測試過程中使用了以下包版本:
- transformers:4.41.2
- torch:2.4.0+cu121
- datasets:3.2.0
- sentencepiece:0.2.0
- sacrebleu:2.5.1
🔧 作者信息
作者:Bila Faye
如有任何問題或改進建議,歡迎隨時聯繫!
📄 許可證
本項目採用 MIT 許可證。