Skip to main content

T5

T5 is an encoder–decoder Transformer that casts every NLP problem as text-to-text generation with a task prefix (translate English to German:, summarize:, …).

Adapted for this playbook from the 🤗 Transformers documentation by Hugging Face. Official page: https://huggingface.co/docs/transformers/model_doc/t5. Images © Hugging Face (documentation-images) unless noted. This is not a substitute for the upstream docs — verify against the current version.

Covers Hugging Face pages: model_doc/t5

Quick usage​

from transformers import AutoModelForSeq2SeqLM, AutoTokenizer

tok = AutoTokenizer.from_pretrained("google-t5/t5-base")
model = AutoModelForSeq2SeqLM.from_pretrained("google-t5/t5-base", device_map="auto")
inputs = tok("translate English to French: The weather is nice today.", return_tensors="pt").to(model.device)
out = model.generate(**inputs, max_new_tokens=64)
print(tok.decode(out[0], skip_special_tokens=True))

Collection: google/t5-release.

Quantization​

Large T5 variants can use Transformers quantization backends (for example torchao int4) — see Quantization.

Official API​

T5 model doc.

Discussion

Comments​

Share feedback or questions about this page. No account required.

Loading comments…