神经机器翻译模型,用于将英语(en)翻译为阿拉伯语(ar)。
该模型是 OPUS-MT project 的一部分,旨在使神经机器翻译模型在世界上许多语言中广泛可用和易于访问。所有模型最初使用 Marian NMT 的出色框架进行训练,该框架是用纯C++编写的高效NMT实现。使用 huggingface 的 transformers 库将模型转换为 pyTorch。训练数据取自 OPUS ,训练流程使用 OPUS-MT-train 的过程。
@inproceedings{tiedemann-thottingal-2020-opus, title = "{OPUS}-{MT} {--} Building open translation services for the World", author = {Tiedemann, J{\"o}rg and Thottingal, Santhosh}, booktitle = "Proceedings of the 22nd Annual Conference of the European Association for Machine Translation", month = nov, year = "2020", address = "Lisboa, Portugal", publisher = "European Association for Machine Translation", url = "https://aclanthology.org/2020.eamt-1.61", pages = "479--480", } @inproceedings{tiedemann-2020-tatoeba, title = "The Tatoeba Translation Challenge {--} Realistic Data Sets for Low Resource and Multilingual {MT}", author = {Tiedemann, J{\"o}rg}, booktitle = "Proceedings of the Fifth Conference on Machine Translation", month = nov, year = "2020", address = "Online", publisher = "Association for Computational Linguistics", url = "https://aclanthology.org/2020.wmt-1.139", pages = "1174--1182", }
这是一个具有多个目标语言的多语言翻译模型。需要使用形式为 >>id<<(id = 有效的目标语言ID)的句子初始语言标记,例如 >>afb<<。
一个简短的示例代码:
from transformers import MarianMTModel, MarianTokenizer src_text = [ ">>ara<< I can't help you because I'm busy.", ">>ara<< I have to write a letter. Do you have some paper?" ] model_name = "pytorch-models/opus-mt-tc-big-en-ar" tokenizer = MarianTokenizer.from_pretrained(model_name) model = MarianMTModel.from_pretrained(model_name) translated = model.generate(**tokenizer(src_text, return_tensors="pt", padding=True)) for t in translated: print( tokenizer.decode(t, skip_special_tokens=True) ) # expected output: # لا أستطيع مساعدتك لأنني مشغول. # يجب أن أكتب رسالة هل لديك بعض الأوراق؟
您还可以使用 transformers pipelines 运行 OPUS-MT 模型,例如:
from transformers import pipeline pipe = pipeline("translation", model="Helsinki-NLP/opus-mt-tc-big-en-ar") print(pipe(">>ara<< I can't help you because I'm busy.")) # expected output: لا أستطيع مساعدتك لأنني مشغول.
langpair | testset | chr-F | BLEU | #sent | #words |
---|---|---|---|---|---|
eng-ara | tatoeba-test-v2021-08-07 | 0.48813 | 19.8 | 10305 | 61356 |
eng-ara | flores101-devtest | 0.61154 | 29.4 | 1012 | 21357 |
eng-ara | tico19-test | 0.60075 | 30.0 | 2100 | 51339 |
该工作得到 European Language Grid 的支持,作为 pilot project 2866 , 由 FoTran project 支持,该计划由欧洲研究理事会(ERC)根据欧洲联合体的Horizon 2020研究和创新计划(授权号:771113)以及根据欧洲联合体的Horizon 2020研究和创新计划(授权号:780069)下的资助。我们还感谢 CSC -- IT Center for Science 提供的慷慨计算资源和IT基础设施,芬兰。