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
也可以使用pipeline:
from transformers import AutoTokenizer, AutoModel,pipeline
from huggingface_hub.hf_api import HfFolder
HfFolder.save_token('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')
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer,MT5ForConditionalGeneration
checkpoint = "bigscience/mt0-large"
classifier = pipeline(model=checkpoint,max_new_tokens=2000)
print(classifier("Translate to English: 泰卢固语具有丰富的音系,包括元音、辅音和复合音"))
print(classifier("一个传奇的开端,一个不灭的神话,这不仅仅是一部电影,而是作为一个走进新时代的标签,永远彪炳史册。你认为这句话的立场是赞扬、中立还是批评"))
print(classifier("写一首有关草莓的故事,不少于100字"))