如何使用huggingface T5模型测试翻译任务?
How to use huggingface T5 model to test translation task?
我看到 T5 模型存在两个配置 - T5Model 和 TFT5WithLMHeadModel。我想测试翻译任务(例如 en-de),因为它们在 google 的原始仓库中显示。有没有一种方法可以使用这个模型从拥抱面来测试翻译任务。我在文档方面没有看到任何与此相关的示例,并且想知道如何提供输入并获得结果。
感谢任何帮助
T5 是预训练模型,可以针对机器翻译等下游任务进行微调。因此,当我们要求它翻译时,预计会出现乱码——它还没有学会如何做。
您可以使用 T5ForConditionalGeneration 来翻译您的文本...
!pip install transformers
from transformers import T5Tokenizer, T5ForConditionalGeneration
tokenizer = T5Tokenizer.from_pretrained('t5-small')
model = T5ForConditionalGeneration.from_pretrained('t5-small', return_dict=True)
input = "My name is Azeem and I live in India"
# You can also use "translate English to French" and "translate English to Romanian"
input_ids = tokenizer("translate English to German: "+input, return_tensors="pt").input_ids # Batch size 1
outputs = model.generate(input_ids)
decoded = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(decoded)
截至今天,变形金刚不支持 T5WithLMHeadModel。
我看到 T5 模型存在两个配置 - T5Model 和 TFT5WithLMHeadModel。我想测试翻译任务(例如 en-de),因为它们在 google 的原始仓库中显示。有没有一种方法可以使用这个模型从拥抱面来测试翻译任务。我在文档方面没有看到任何与此相关的示例,并且想知道如何提供输入并获得结果。
感谢任何帮助
T5 是预训练模型,可以针对机器翻译等下游任务进行微调。因此,当我们要求它翻译时,预计会出现乱码——它还没有学会如何做。
您可以使用 T5ForConditionalGeneration 来翻译您的文本...
!pip install transformers
from transformers import T5Tokenizer, T5ForConditionalGeneration
tokenizer = T5Tokenizer.from_pretrained('t5-small')
model = T5ForConditionalGeneration.from_pretrained('t5-small', return_dict=True)
input = "My name is Azeem and I live in India"
# You can also use "translate English to French" and "translate English to Romanian"
input_ids = tokenizer("translate English to German: "+input, return_tensors="pt").input_ids # Batch size 1
outputs = model.generate(input_ids)
decoded = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(decoded)
截至今天,变形金刚不支持 T5WithLMHeadModel。