Created
September 12, 2023 01:03
-
-
Save vhxs/75a1a4919dab32a8622dd40dda383394 to your computer and use it in GitHub Desktop.
T5 translation example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM | |
tokenizer = AutoTokenizer.from_pretrained("t5-base") | |
model = AutoModelForSeq2SeqLM.from_pretrained("t5-base") | |
example_input = "This sentence is false" | |
input_ids = tokenizer("translate English to German: "+example_input, return_tensors="pt").input_ids | |
outputs = model.generate(input_ids) | |
decoded = tokenizer.decode(outputs[0], skip_special_tokens=True) | |
print(decoded) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment