🚀 t5-small-spanish-nahuatl
本项目旨在解决纳瓦特尔语(Nahuatl)数据缺乏情况下的神经机器翻译难题。通过利用T5文本到文本的前缀训练策略,先让多语言模型学习西班牙语,再适配纳瓦特尔语,最终实现了短句子的成功翻译,并给出了Chrf和BLEU评估结果。
🚀 快速开始
本模型可实现西班牙语到纳瓦特尔语的翻译,以下是使用示例:
from transformers import AutoModelForSeq2SeqLM
from transformers import AutoTokenizer
model = AutoModelForSeq2SeqLM.from_pretrained('hackathon-pln-es/t5-small-spanish-nahuatl')
tokenizer = AutoTokenizer.from_pretrained('hackathon-pln-es/t5-small-spanish-nahuatl')
model.eval()
sentence = 'muchas flores son blancas'
input_ids = tokenizer('translate Spanish to Nahuatl: ' + sentence, return_tensors='pt').input_ids
outputs = model.generate(input_ids)
outputs = tokenizer.batch_decode(outputs, skip_special_tokens=True)[0]
✨ 主要特性
- 数据补偿策略:利用T5文本到文本前缀训练策略,先让多语言模型学习西班牙语,再适配纳瓦特尔语,以补偿数据的不足。
- 成功翻译短句子:训练得到的T5 Transformer能够成功翻译短句子。
- 评估指标报告:报告了Chrf和BLEU评估结果。
📦 安装指南
暂未提及安装相关内容,可参考使用示例中的代码进行模型的加载和使用。
💻 使用示例
基础用法
from transformers import AutoModelForSeq2SeqLM
from transformers import AutoTokenizer
model = AutoModelForSeq2SeqLM.from_pretrained('hackathon-pln-es/t5-small-spanish-nahuatl')
tokenizer = AutoTokenizer.from_pretrained('hackathon-pln-es/t5-small-spanish-nahuatl')
model.eval()
sentence = 'muchas flores son blancas'
input_ids = tokenizer('translate Spanish to Nahuatl: ' + sentence, return_tensors='pt').input_ids
outputs = model.generate(input_ids)
outputs = tokenizer.batch_decode(outputs, skip_special_tokens=True)[0]
📚 详细文档
模型描述
本模型是一个T5 Transformer(t5-small),在从网络收集的西班牙语和纳瓦特尔语句子上进行了微调。数据集使用了来自 py-elotl 的 'sep' 规范化方法进行规范化。
方法
数据集
由于Axolotl语料库存在对齐问题,我们选择了最佳样本(12,207个)。我们还使用了 bible-corpus(7,821个)。此外,我们还从网络收集了3,000个额外样本以增加数据量。
Axolotl最佳对齐书籍 |
Anales de Tlatelolco |
Diario |
Documentos nauas de la Ciudad de México del siglo XVI |
Historia de México narrada en náhuatl y español |
La tinta negra y roja (antología de poesía náhuatl) |
Memorial Breve (Libro las ocho relaciones) |
Método auto-didáctico náhuatl-español |
Nican Mopohua |
Quinta Relación (Libro las ocho relaciones) |
Recetario Nahua de Milpa Alta D.F |
Testimonios de la antigua palabra |
Trece Poetas del Mundo Azteca |
Una tortillita nomás - Se taxkaltsin saj |
Vida económica de Tenochtitlan |
模型与训练
我们使用多语言T5-small进行两个阶段的训练。该模型的优势在于它可以处理不同的词汇表和前缀。T5-small在不同的任务和语言(法语、罗马尼亚语、英语、德语)上进行了预训练。
- 训练阶段1(学习西班牙语):在训练阶段1,我们首先让模型学习西班牙语。目标是学习一种数据丰富的新语言(西班牙语),同时不丢失之前的知识。我们使用了英语 - 西班牙语的 Anki 数据集,该数据集包含118,964个文本对。模型训练至收敛,并添加前缀 "Translate Spanish to English: "。
- 训练阶段2(学习纳瓦特尔语):我们使用预训练的西班牙语 - 英语模型来学习西班牙语 - 纳瓦特尔语。由于纳瓦特尔语对的数量有限,我们还添加了20,000个来自英语 - 西班牙语Anki数据集的样本。这种双任务训练避免了过拟合,使模型更加健壮。
训练设置
我们在相同的数据集上对模型进行了660,000步的训练,使用的批量大小为16,学习率为2e-5。
评估结果
我们在相同的505个验证纳瓦特尔语句子上对模型进行了评估,以进行公平比较。最后,我们使用chrf和sacrebleu hugging face指标报告了结果:
英语 - 西班牙语预训练 |
验证损失 |
BLEU |
Chrf |
否 |
1.34 |
6.17 |
26.96 |
是 |
1.31 |
6.18 |
28.21 |
英语 - 西班牙语预训练提高了BLEU和Chrf指标,并导致更快的收敛。评估可在 eval.ipynb 笔记本中查看。
🔧 技术细节
本项目利用T5文本到文本前缀训练策略,先让多语言模型学习西班牙语,再适配纳瓦特尔语,以补偿数据的不足。在数据集处理上,选择最佳样本并使用规范化方法。在模型训练上,采用两阶段训练策略,并添加额外样本避免过拟合。
📄 许可证
本项目使用Apache-2.0许可证。
📖 参考文献
- Colin Raffel, Noam Shazeer, Adam Roberts, Katherine Lee, Sharan Narang, Michael Matena, Yanqi Zhou, Wei Li, and Peter J Liu. 2019. Exploring the limits of transfer learning with a unified Text-to-Text transformer.
- Ximena Gutierrez-Vasques, Gerardo Sierra, and Hernandez Isaac. 2016. Axolotl: a web accessible parallel corpus for Spanish-Nahuatl. In International Conference on Language Resources and Evaluation (LREC).
- https://github.com/christos-c/bible-corpus
- https://github.com/ElotlMX/py-elotl
👥 团队成员