Pipeline tutorial, summarization doesn't work
Hugging Face Forums [Unofficial]
March 31, 2026
This worked in Colab in my own notebook.
# Fixed code from this tutorial:
# https://huggingface.co/learn/llm-course/chapter1/3
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
model_id = "google-t5/t5-small" # or your finetuned summarization checkpoint
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForSeq2SeqLM.from_pretrained(model_id)
text = """
America has changed dramatically during recent years. Not only has the number of
graduates in traditional engineering disciplines such as mechanical, civil,
electrical, chemical, and aeronautical engineering declined, but in most of
the premier American universities engineering curricula now concentrate on
and encourage largely the study of engineering science. As a result, there
are declining offerings in engineering subjects dealing with infrastructure,
the environment, and related issues, and greater concentration on high
technology subjects, largely supporting increasingly complex scientific
developments. While the latter is important, it should not be at the expense
of more traditional engineering.
Rapidly developing economies such as China and India, as well as other
industrial countries in Europe and Asia, continue to encourage and advance
the teaching of engineering. Both China and India, respectively, graduate
six and eight times as many traditional engineers as does the United States.
Other industrial countries at minimum maintain their output, while America
suffers an increasingly serious decline in the number of engineering graduates
and a lack of well-educated engineers.
"""
inputs = tokenizer(
"summarize: " + text,
return_tensors="pt",
truncation=True
).input_ids
outputs = model.generate(inputs, max_new_tokens=100, do_sample=False)
summary = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(summary)
The program did have some warnings and did not wrap the output text “summary” but that’s fine.
Discussion in the ATmosphere