使用模型bigscience/mt0-large实现中文到英文的翻译

cpu版本

from transformers import AutoTokenizer, AutoModel
from huggingface_hub.hf_api import HfFolder

HfFolder.save_token('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')
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer,MT5ForConditionalGeneration
checkpoint = "bigscience/mt0-large"
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
model = AutoModelForSeq2SeqLM.from_pretrained(checkpoint)
inputs = tokenizer.encode("Translate to English: 泰卢固语具有丰富的音系,包括元音、辅音和复合音", return_tensors="pt")
outputs = model.generate(inputs,max_new_tokens=200)
decoded = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(decoded)



输出:

Turkish has a wide variety of sounds, including sounds of the alphabet, sounds of the alphabet, and sounds of the combination of sounds

你可能感兴趣的:(huggingface,java,linux,前端)