🚀 T5-EN-VI-BASE:用于英越翻译的文本到文本转移Transformer预训练模型
本项目是一个用于英越翻译的预训练模型,借助文本到文本转移Transformer技术,能有效提升英越翻译的质量和效率。
🚀 快速开始
你可以参考下面的代码示例,快速开始使用本模型进行英越翻译。
📦 安装指南
文档未提及安装步骤,故跳过此章节。
💻 使用示例
基础用法
import torch
from transformers import T5ForConditionalGeneration, T5Tokenizer
import torch
if torch.cuda.is_available():
device = torch.device("cuda")
print('There are %d GPU(s) available.' % torch.cuda.device_count())
print('We will use the GPU:', torch.cuda.get_device_name(0))
else:
print('No GPU available, using the CPU instead.')
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ù.
📚 详细文档
数据集
本项目使用了来自斯坦福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 et. al. (2017) |
27.69 |
基于神经短语的机器翻译 + 语言模型 Huang et. al. (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(不区分大小写) |
联系信息
如果你有与本项目相关的个人交流需求,请联系Nha Nguyen Van(nha282@gmail.com)。