T5-EN-VI-BASE:面向英越翻译的文本到文本转换Transformer预训练模型
数据集
采用来自斯坦福NLP小组的IWSLT'15 英越平行语料。
所有实验数据均划分为训练集、开发集和测试集:
数据集 |
句对数 |
下载地址 |
训练集 |
133,317 |
通过GitHub获取或位于data/train-en-vi.tgz |
开发集 |
1,553 |
通过GitHub获取或位于data/dev-2012-en-vi.tgz |
测试集 |
1,268 |
通过GitHub获取或位于data/test-2013-en-vi.tgz |
实验结果
测试集上的表现结果:
模型 |
BLEU(束搜索) |
Luong & Manning (2015) |
23.30 |
带注意力机制的序列到序列模型 |
26.10 |
神经短语式机器翻译 Huang等 (2017) |
27.69 |
神经短语式机器翻译+语言模型 Huang等 (2017) |
28.07 |
t5-en-vi-small(预训练阶段,无训练数据) |
28.46(区分大小写)/ 29.23(不区分大小写) |
t5-en-vi-small(使用训练数据微调后) |
32.38(区分大小写)/ 33.19(不区分大小写) |
t5-en-vi-base(预训练阶段,无训练数据) |
29.66(区分大小写)/ 30.37(不区分大小写) |
使用示例
import torch
from transformers import T5ForConditionalGeneration, T5Tokenizer
import torch
if torch.cuda.is_available():
device = torch.device("cuda")
print('检测到%d块可用GPU.' % torch.cuda.device_count())
print('将使用GPU设备:', torch.cuda.get_device_name(0))
else:
print('未检测到GPU,将使用CPU运行.')
device = torch.device("cpu")
model = T5ForConditionalGeneration.from_pretrained("NlpHUST/t5-en-vi-small")
tokenizer = T5Tokenizer.from_pretrained("NlpHUST/t5-en-vi-small")
model.to(device)
src = "In school , we spent a lot of time studying the history of Kim Il-Sung , but we never learned much about the outside world , except that America , South Korea , Japan are the enemies ."
tokenized_text = tokenizer.encode(src, return_tensors="pt").to(device)
model.eval()
summary_ids = model.generate(
tokenized_text,
max_length=128,
num_beams=5,
repetition_penalty=2.5,
length_penalty=1.0,
early_stopping=True
)
output = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
print(output)
输出结果
Ở trường, chúng tôi dành nhiều thời gian để nghiên cứu về lịch sử Kim Il-Sung, nhưng chúng tôi chưa bao giờ học được nhiều về thế giới bên ngoài, ngoại trừ Mỹ, Hàn Quốc, Nhật Bản là kẻ thù.
联系方式
有关本项目的沟通请联系阮文雅(nha282@gmail.com)。