🚀 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)。