模型简介
模型特点
模型能力
使用案例
🚀 多斯拉夫双向模型
多斯拉夫双向模型是一组支持双向翻译的编码器 - 解码器香草变换器模型,可助力多语言翻译任务,为跨语言交流提供高效解决方案。
🚀 快速开始
由于存在一个bug,必须显式使用MarianMTModel
。请记得根据你的使用场景调整源语言和目标语言。
from transformers import AutoTokenizer, MarianMTModel
source_lang = "pol"
target_lang = "ces"
first_lang, second_lang = sorted([source_lang, target_lang])
model_name = f"Allegro/BiDi-{first_lang}-{second_lang}"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = MarianMTModel.from_pretrained(model_name)
text = f">>{target_lang}<<" + " " + "Allegro to internetowa platforma e-commerce, na której swoje produkty sprzedają średnie i małe firmy, jak również duże marki."
batch_to_translate = [text]
translations = model.generate(**tokenizer.batch_encode_plus(batch_to_translate, return_tensors="pt"))
decoded_translation = tokenizer.batch_decode(translations, skip_special_tokens=True, clean_up_tokenization_spaces=True)[0]
print(decoded_translation)
生成的捷克语输出:
Allegro je online e-commerce platforma, na které své výrobky prodávají střední a malé firmy, stejně jako velké značky.
✨ 主要特性
- 双向翻译:每个模型都支持双向翻译,能够在两种语言之间自由转换。
- 多语言支持:支持捷克语、英语、波兰语、斯洛伐克语和斯洛文尼亚语等多种语言。
- 多模型选择:提供了10种双向模型,可满足不同语言对之间的翻译需求。
📦 安装指南
文档未提及安装步骤,可参考transformers
库的官方安装说明进行安装。
💻 使用示例
基础用法
from transformers import AutoTokenizer, MarianMTModel
source_lang = "pol"
target_lang = "ces"
first_lang, second_lang = sorted([source_lang, target_lang])
model_name = f"Allegro/BiDi-{first_lang}-{second_lang}"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = MarianMTModel.from_pretrained(model_name)
text = f">>{target_lang}<<" + " " + "Allegro to internetowa platforma e-commerce, na której swoje produkty sprzedają średnie i małe firmy, jak również duże marki."
batch_to_translate = [text]
translations = model.generate(**tokenizer.batch_encode_plus(batch_to_translate, return_tensors="pt"))
decoded_translation = tokenizer.batch_decode(translations, skip_special_tokens=True, clean_up_tokenization_spaces=True)[0]
print(decoded_translation)
高级用法
文档未提及高级用法示例,可根据实际需求对基础用法代码进行扩展和调整。
📚 详细文档
支持的语言
要使用双向(BiDi)模型,你必须为翻译指定目标语言。目标语言标记以嵌入格式>>xxx<<
的3字母ISO 639 - 3语言代码表示。所有接受的方向及其各自的标记如下所列。请注意,每个模型仅提供两个方向。每个方向都作为特殊标记添加到Sentence - Piece分词器中。
目标语言 | 第一个标记 |
---|---|
捷克语 | >>ces<< |
英语 | >>eng<< |
波兰语 | >>pol<< |
斯洛伐克语 | >>slk<< |
斯洛文尼亚语 | >>slv<< |
可用的双向模型
我们提供了10个双向(BiDi)模型,可实现20种语言之间的翻译。
双向模型 | 支持的语言 | HF仓库 |
---|---|---|
BiDi - ces - eng | 捷克语 ↔ 英语 | [allegro/BiDi - ces - eng](https://huggingface.co/allegro/bidi - ces - eng) |
BiDi - ces - pol | 捷克语 ↔ 波兰语 | [allegro/BiDi - ces - pol](https://huggingface.co/allegro/bidi - ces - pol) |
BiDi - ces - slk | 捷克语 ↔ 斯洛伐克语 | [allegro/BiDi - ces - slk](https://huggingface.co/allegro/bidi - ces - slk) |
BiDi - ces - slv | 捷克语 ↔ 斯洛文尼亚语 | [allegro/BiDi - ces - slv](https://huggingface.co/allegro/bidi - ces - slv) |
BiDi - eng - pol | 英语 ↔ 波兰语 | [allegro/BiDi - eng - pol](https://huggingface.co/allegro/bidi - eng - pol) |
BiDi - eng - slk | 英语 ↔ 斯洛伐克语 | [allegro/BiDi - eng - slk](https://huggingface.co/allegro/bidi - eng - slk) |
BiDi - eng - slv | 英语 ↔ 斯洛文尼亚语 | [allegro/BiDi - eng - slv](https://huggingface.co/allegro/bidi - eng - slv) |
BiDi - pol - slk | 波兰语 ↔ 斯洛伐克语 | [allegro/BiDi - pol - slk](https://huggingface.co/allegro/bidi - pol - slk) |
BiDi - pol - slv | 波兰语 ↔ 斯洛文尼亚语 | [allegro/BiDi - pol - slv](https://huggingface.co/allegro/bidi - pol - slv) |
BiDi - slk - slv | 斯洛伐克语 ↔ 斯洛文尼亚语 | [allegro/BiDi - slk - slv](https://huggingface.co/allegro/bidi - slk - slv) |
训练
SentencePiece分词器的词汇表大小总共为32k(每种语言16k)。分词器是在训练语料库的随机抽样部分上进行训练的。在训练过程中,我们使用了[MarianNMT](https://marian - nmt.github.io/)框架。使用的基础Marian配置为:[transfromer - big](https://github.com/marian - nmt/marian - dev/blob/master/src/common/aliases.cpp#L113)。所有训练参数如下表所示。
训练超参数:
超参数 | 值 |
---|---|
总参数大小 | 209M |
词汇表大小 | 32k |
基础参数 | [Marian transfromer - big](https://github.com/marian - nmt/marian - dev/blob/master/src/common/aliases.cpp#L113) |
编码层数 | 6 |
解码层数 | 6 |
模型维度 | 1024 |
前馈维度 | 4096 |
头数 | 16 |
丢弃率 | 0.1 |
批量大小 | 小批量适应显存 |
训练加速器 | 4x A100 40GB |
最大长度 | 100个标记 |
优化器 | Adam |
预热步数 | 8000 |
上下文 | 句子级机器翻译 |
支持的语言 | 见[可用的双向模型](#Bi - Di模型可用) |
精度 | float16 |
验证频率 | 3000步 |
停止指标 | ChrF |
停止标准 | 20次验证步骤 |
训练语料库
主要研究问题是:“添加额外的相关语言如何影响模型的质量?” 我们在斯拉夫语族中进行了探索。双向(BiDi)模型是我们在通过使用更高级别的多语言性扩展数据机制之前的基线。
数据集是通过MT - Data库下载的。过滤和去重后,总示例数会根据支持的语言而有所不同,如下表所示。
语言对 | 训练示例数 |
---|---|
捷克语 ↔ 波兰语 | 63M |
捷克语 ↔ 斯洛伐克语 | 30M |
捷克语 ↔ 斯洛文尼亚语 | 25M |
波兰语 ↔ 斯洛伐克语 | 26M |
波兰语 ↔ 斯洛文尼亚语 | 23M |
斯洛伐克语 ↔ 斯洛文尼亚语 | 18M |
捷克语 ↔ 英语 | 151M |
英语 ↔ 波兰语 | 150M |
英语 ↔ 斯洛伐克语 | 52M |
英语 ↔ 斯洛文尼亚语 | 40M |
使用的数据集(仅适用于特定方向):
- paracrawl
- opensubtitles
- multiparacrawl
- dgt
- elrc
- xlent
- wikititles
- wmt
- wikimatrix
- dcep
- ELRC
- tildemodel
- europarl
- eesc
- eubookshop
- emea
- jrc_acquis
- ema
- qed
- elitr_eca
- EU - dcep
- rapid
- ecb
- kde4
- news_commentary
- kde
- bible_uedin
- europat
- elra
- wikipedia
- wikimedia
- tatoeba
- globalvoices
- euconst
- ubuntu
- php
- ecdc
- eac
- eac_reference
- gnome
- EU - eac
- books
- EU - ecdc
- newsdev
- khresmoi_summary
- czechtourism
- khresmoi_summary_dev
- worldbank
评估
模型的评估是在Flores200数据集上进行的。下表比较了开源模型和我们集合中所有适用模型的性能。使用的指标是:Unbabel/wmt22 - comet - da。
方向 | CES → ENG | CES → POL | CES → SLK | CES → SLV | ENG → CES | ENG → POL | ENG → SLK | ENG → SLV | POL → CES | POL → ENG | POL → SLK | POL → SLV | SLK → CES | SLK → ENG | SLK → POL | SLK → SLV | SLV → CES | SLV → ENG | SLV → POL | SLV → SLK |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
M2M - 100 | 87.0 | 89.0 | 92.1 | 89.7 | 88.6 | 86.4 | 88.4 | 87.3 | 89.6 | 84.6 | 89.4 | 88.4 | 92.7 | 86.8 | 89.1 | 89.6 | 90.3 | 86.4 | 88.7 | 90.1 |
NLLB - 200 | 88.1 | 88.9 | 91.2 | 88.6 | 90.4 | 88.5 | 90.1 | 88.8 | 89.4 | 85.8 | 88.9 | 87.7 | 91.8 | 88.2 | 88.9 | 88.8 | 90.0 | 87.5 | 88.6 | 89.4 |
Seamless - M4T | 87.5 | 80.9 | 90.8 | 82.0 | 90.7 | 88.5 | 90.6 | 89.6 | 79.6 | 85.4 | 80.0 | 76.4 | 91.5 | 87.2 | 81.2 | 82.9 | 80.9 | 87.3 | 76.7 | 81.0 |
OPUS - MT Sla - Sla | 88.2 | 82.8 | - | 83.4 | 89.1 | 85.6 | - | 84.5 | 82.9 | 82.2 | - | 81.2 | - | - | - | - | 83.5 | 84.1 | 80.8 | - |
OPUS - MT SK - EN | - | - | - | - | - | - | 89.5 | - | - | - | - | - | - | 88.4 | - | - | - | - | - | - |
BiDi Models | 87.5 | 89.4 | 92.4 | 89.8 | 87.8 | 86.2 | 87.2 | 86.6 | 90.0 | 85.0 | 89.1 | 88.4 | 92.9 | 87.3 | 88.8 | 89.4 | 90.0 | 86.9 | 88.1 | 89.1 |
P4 - pol | - | 89.6 | 90.8 | 88.7 | - | - | - | - | 90.2 | - | 89.8 | 88.7 | 91.0 | - | 89.3 | 88.4 | 89.3 | - | 88.7 | 88.5 |
P5 - eng | 88.0 | 89.0 | 90.7 | 89.0 | 88.8 | 87.3 | 88.4 | 87.5 | 89.0 | 85.7 | 88.5 | 87.8 | 91.0 | 88.2 | 88.6 | 88.5 | 89.6 | 87.2 | 88.4 | 88.9 |
P5 - ces | 87.9 | 89.6 | 92.5 | 89.9 | 88.4 | 85.0 | 87.9 | 85.9 | 90.3 | 84.5 | 89.5 | 88.0 | 93.0 | 87.8 | 89.4 | 89.8 | 90.3 | 85.7 | 87.9 | 89.8 |
MultiSlav - 4slav | - | 89.7 | 92.5 | 90.0 | - | - | - | - | 90.2 | - | 89.6 | 88.7 | 92.9 | - | 89.4 | 90.1 | 90.6 | - | 88.9 | 90.2 |
MultiSlav - 5lang | 87.8 | 89.8 | 92.5 | 90.1 | 88.9 | 86.9 | 88.0 | 87.3 | 90.4 | 85.4 | 89.8 | 88.9 | 92.9 | 87.8 | 89.6 | 90.2 | 90.6 | 87.0 | 89.2 | 90.2 |
注:
- ◊ 由2个模型 Many2XXX 和 XXX2Many 组成的系统,见[P5 - ces2many](https://huggingface.co/allegro/p5 - ces2many)
- * 所有双向模型的综合结果;每个值对应适用的模型
局限性和偏差
我们没有评估训练数据集中包含的固有偏差。建议在目标领域中验证我们模型的偏差。这在从英语到斯拉夫语的翻译中可能尤其成问题,因为斯拉夫语需要明确指示性别,并且可能会根据训练数据中存在的偏差产生幻觉。
🔧 技术细节
文档中关于技术细节的描述分散在训练、训练语料库和评估等部分,主要涉及模型的训练框架、超参数设置、训练语料的选择和处理以及模型评估的数据集和指标等方面。
📄 许可证
该模型采用CC BY 4.0许可协议,允许商业使用。
引用
即将更新 🤗
联系信息
作者
- MLR @ Allegro:Artur Kot,Mikołaj Koszowski,[Wojciech Chojnowski](https://linkedin.com/in/wojciech - chojnowski - 744702348),[Mieszko Rutkowski](https://linkedin.com/in/mieszko - rutkowski)
- Laniqo.com:[Artur Nowakowski](https://linkedin.com/in/artur - nowakowski - mt),[Kamil Guttmann](https://linkedin.com/in/kamil - guttmann),[Mikołaj Pokrywka](https://linkedin.com/in/mikolaj - pokrywka)
如果您有任何问题或建议,请随时联系作者:
- 电子邮件:artur.kot@allegro.com 或 mikolaj.koszowski@allegro.com
- LinkedIn:Artur Kot 或 Mikołaj Koszowski



