Summarization model doesn't work

I try to run this below code (provided in Hugging Face’s LLMs course, lesson: Transformers, what can they do?)

from transformers import pipeline
summarize = pipeline("summarization")
summarize(
    """
    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.
"""
)

Return Error as:

I’ve tried running this both on Google Colab and in PyCharm, but I’m seeing the same error in both environments.

Has anyone encountered this issue before or knows what might be causing it?

1 Like

Maybe Transformers v4 → v5 compatibility issue: Pipeline tutorial, summarization doesn't work

1 Like

I know long winded but Chatgpt and Chat Qwen Ai suggest tryin Google Colab.

So what is this and why does it have errors?

The image shows a KeyError message from a programming environment (likely Python).

What is it?

  1. KeyError: An exception raised when a key (or task) is not found in a dictionary or mapping.
  2. Task summarization: The code attempted to run a task named “task summarization”, which is not recognized.

Why does it have errors?

  1. Unknown task: “task summarization” is not in the list of available tasks.
  2. Available tasks: The error message lists supported tasks, such as ‘any-to-any’, ‘audio-classification’, ‘text-generation’, etc.
  3. Misspelling or unsupported task: The code might contain a typo or request a task not implemented in the system.

How to fix it?

  1. Choose a supported task: Replace “task summarization” with an available task, like ‘text-summarization’ (if it exists in the actual list) or ‘text-generation’.
  2. Check task names: Verify the exact names of available tasks and ensure the requested task matches one of them.
  3. Implement the task: If “task summarization” is needed, add it to the list of supported tasks or implement the functionality.

Do you want to:

  1. Pick a specific task from the list to replace “task summarization”?
  2. Understand how to implement a custom task?
  3. Learn more about handling KeyErrors in programming?

Not sure how to proceed? Does this help identify the problem to be specific in Fix? I am listing what was included with the error coding below:

I try to run this below code (provided in Hugging Face’s LLMs course, lesson: Transformers, what can they do?)

from transformers import pipeline summarize = pipeline(“summarization”) summarize( “”" 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. “”" )

The issue is with the task name “summarization”. The correct task name is actually “text-summarization” or “summarization” might not be available, try using “text2text-generation” or “summarization” isn’t in the list, you can try “text-generation” with specific model.

Try this code:
from transformers import pipeline
summarize = pipeline(“summarization”)

or try this

summarize = pipeline(“text-summarization”)

or

summarize = pipeline(“text2text-generation”, model=“facebook/bart-large-cnn”)

summarize( “”"
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.
“”")
If you still face issues, ensure you have the necessary model installed, you can install it via:
pip install transformers

Let me know if this works or if you need further assistance! :blush:

That’s weird I put this in Google, then it did that did you mean think?oh well, I had a hard time copy so did a screen shot of Google response!

I try to run this below code (provided in Hugging Face’s LLMs course, lesson: Transformers, what can they do? The issue is with the task name “summarization”. The correct task name is actually “text-summarization” or “summarization” might not be available, try using “text2text-generation” or “summarization” isn’t in the list, you can try “text-generation” with specific model.

Does this help from Google Search Engine?

from transformers import pipeline
summarizer = pipeline(“summarization”, model=“sshleifer/distilbart-cnn-12-6”)

from transformers import pipeline

Example using a T5 model suitable for text-to-text tasks

summarizer = pipeline(“text2text-generation”, model=“t5-small”)

:blush: Yes, you’re on the right track!

The issue was likely due to the missing model specification. By specifying a model, you’re telling the pipeline which specific model to use for the task.

Your updated code
from transformers import pipeline
summarizer = pipeline(“summarization”, model=“sshleifer/distilbart-cnn-12-6”)

or

summarizer = pipeline(“text2text-generation”, model=“t5-small”)
What’s happening

  1. Model specification: You’re specifying a pre-trained model (sshleifer/distilbart-cnn-12-6 or t5-small) that’s suitable for the summarization task.
  2. Task alignment: The summarization task is aligned with the sshleifer/distilbart-cnn-12-6 model, while text2text-generation is aligned with the t5-small model.

Try this
from transformers import pipeline
summarizer = pipeline(“summarization”, model=“sshleifer/distilbart-cnn-12-6”)
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.
“”"
print(summarizer(text))
Does this work for you?

So Chatgpt any ideas?

You’re very close — and no, this has nothing to do with your printer or computer being “off” :slightly_smiling_face:. This is purely a coding / library issue.

:red_circle: What the error actually means

The key part of your screenshot:
KeyError: “Unknown task summarization…”
This means:
:backhand_index_pointing_right: The version of the Hugging Face Transformers library installed on your system does NOT recognize “summarization” as a valid task.
And we can see that clearly because the error lists allowed tasks — and “summarization” is missing.

:brain: Why this is happening

Most likely causes:

  1. :cross_mark: Your Transformers version is outdated

Older versions didn’t include “summarization” as a built-in pipeline task.

  1. :cross_mark: Wrong environment / partial install

Sometimes:

You installed Transformers in one environment

But you’re running code in another

  1. :cross_mark: Google result confusion

Google mixed suggestions — some are correct, some are not.
“text-summarization” is NOT a valid pipeline task name, so that suggestion is misleading.

:white_check_mark: The correct fix (do this first)

:wrench: Upgrade Transformers

Run this in your terminal:
pip install --upgrade transformers

:wrench: Then use THIS code (correct version)

from transformers import pipeline summarizer = pipeline(“summarization”) text = “”“America has changed dramatically during recent years…”“” print(summarizer(text))

:white_check_mark: If it STILL fails (backup solution)

Force a model explicitly (this usually works even on older setups):
from transformers import pipeline summarizer = pipeline( “summarization”, model=“sshleifer/distilbart-cnn-12-6” ) print(summarizer(“Your long text here”))

:warning: Important clarification

These are valid vs invalid task names:
Task NameStatus"summarization":white_check_mark: Correct"text-generation":white_check_mark: Correct"text2text-generation":white_check_mark: Correct"text-summarization":cross_mark: Not valid

:puzzle_piece: Why your error list looks weird

Your error shows tasks like:
‘any-to-any’, ‘image-classification’, ‘text-generation’
That suggests:
:backhand_index_pointing_right: You might be using a restricted or custom build of Transformers
:backhand_index_pointing_right: OR a very old version

:rocket: Quick checklist

Do these in order:

Upgrade:
pip install --upgrade transformers

Restart your Python environment (VERY important)

Run:
from transformers import pipeline pipeline(“summarization”)

:speech_balloon: Bottom line

:cross_mark: Not hardware related

:cross_mark: Not your fault

:white_check_mark: Just a version mismatch / missing task

If you want, I can:

Check your exact version

Help you fix your environment step-by-step

Or get it working in Google Colab in 2 minutes :+1:

KeyError: “Unknown task summarization…”

pip install --upgrade transformers

from transformers import pipeline

summarizer = pipeline(“summarization”)

text = “”“America has changed dramatically during recent years…”“”

print(summarizer(text))

from transformers import pipeline

summarizer = pipeline(
“summarization”,
model=“sshleifer/distilbart-cnn-12-6”
)

print(summarizer(“Your long text here”))

Task NameStatus"summarization":white_check_mark: Correct"text-generation":white_check_mark: Correct"text2text-generation":white_check_mark: Correct"text-summarization":cross_mark: Not valid

‘any-to-any’, ‘image-classification’, ‘text-generation’

pip install --upgrade transformers

from transformers import pipeline
pipeline(“summarization”)

How could Google Colab get it working if can do it!

Great question — this actually gets to why Colab feels “magically easier” :slightly_smiling_face:

:rocket: Why Google Colab works (when your PC doesn’t)

Colab runs your code in a pre-configured cloud environment that already has:

:white_check_mark: 1. Up-to-date libraries

It usually comes with a recent version of:

Transformers

PyTorch

So “summarization” is already supported.

:white_check_mark: 2. Clean environment

Your local machine might have:

old versions

conflicting installs

broken dependencies

Colab = fresh environment every time

:white_check_mark: 3. Built-in GPU (optional)

Not required here, but helpful for bigger models.

:test_tube: How to make it work in Colab (step-by-step)

  1. Go to Colab

:backhand_index_pointing_right: https://colab.research.google.com

  1. Paste this code in a cell:

!pip install transformers from transformers import pipeline summarizer = pipeline(“summarization”) text = “”“America has changed dramatically during recent years…”“” print(summarizer(text))

  1. Run the cell :play_button:

First run will:

download the model (~1GB sometimes)

take a minute or two

After that, it works instantly.

:fire: Why this fixes YOUR exact error

Your error:
KeyError: Unknown task summarization
Colab fixes it because:

It installs the correct version automatically

No old config interfering

No missing task definitions

:vs_button: Local vs Colab (simple truth)

Your PCColab​:cross_mark: Might be outdated​:white_check_mark: Always updated​:cross_mark: Can break easily​:white_check_mark: Clean every run​:cross_mark: Setup required​:white_check_mark: Works instantly

:light_bulb: Real takeaway

Colab is basically:

“A ready-to-use AI lab in the cloud”

So instead of debugging your environment for hours, you can:

test code instantly

confirm it works

THEN fix your local setup later

:+1: What I’d suggest

Try it in Colab first

Confirm it works

Then we fix your local environment properly (I can help)

If you want, I can:

Walk you through fixing your PC setup step-by-step

Or show you how to run this permanently without errors locally

!pip install transformers

from transformers import pipeline

summarizer = pipeline(“summarization”)

text = “”“America has changed dramatically during recent years…”“”

print(summarizer(text))

KeyError: Unknown task summarization

Your PCColab​:cross_mark: Might be outdated​:white_check_mark: Always updated​:cross_mark: Can break easily​:white_check_mark: Clean every run​:cross_mark: Setup required​:white_check_mark: Works instantly

So what do you think Chat Qwen Ai?

Looking at your error, I can see what’s happening! The other AI gave you good advice, but let me clarify the key points:

The Real Problem

Your Transformers library doesn’t have “summarization” in its list of valid tasks. Looking at the error, the available tasks include things like 'text-generation', 'text-classification', but no “summarization” - which is very unusual.

Why This Happens

This typically means:

  1. Outdated Transformers version (most likely)
  2. Incomplete/corrupted installation
  3. Wrong Python environment

The Quickest Fixes

Option 1: Upgrade Transformers (Try First)

pip install --upgrade transformers

Then restart your Python environment completely and try:

from transformers import pipeline
summarizer = pipeline("summarization")

Option 2: Use Google Colab (Fastest Working Solution)

Since you asked about this - yes, Colab would work immediately because it has fresh, updated libraries. Just:

  1. Go to https://colab.research.google.com
  2. Paste your code
  3. Run it - it will work!

Option 3: Explicit Model (Workaround)

from transformers import pipeline
summarizer = pipeline("text2text-generation", model="t5-small")

My recommendation: Try Colab first to confirm your code works, then fix your local setup. Want help with either approach?

pip install --upgrade transformers

from transformers import pipeline
summarizer = pipeline(“summarization”)

from transformers import pipeline
summarizer = pipeline(“text2text-generation”, model=“t5-small”)

1 Like

Yeah. That works with Transformers v4. However, I think it will throw an error with v5. The second half maybe works as-is. (Colab used to run on v4 until recently, but v5 is now the default.)

Since this is simply a Transformers version mismatch, if you run !pip install -U "transformers<5" beforehand and restart the Colab runtime, then the first half of the code should work as well, too.

Yeah. That works with Transformers v4. However, I think it will throw an error with v5. The second half maybe works as-is. (Colab used to run on v4 until recently, but v5 is now the default.)
Since this is simply a Transformers version mismatch, if you run !pip install -U “transformers<5” beforehand and restart the Colab runtime, then the first half of the code should work as well, too.

So what do you think Chatgpt?

You actually did a really solid job digging into this — the confusion here is coming from mixed advice + a breaking change in Transformers v5. Let me straighten it out cleanly.

:magnifying_glass_tilted_left: What’s REALLY going wrong

Your error:
KeyError: “Unknown task summarization…”
But here’s the important detail:
:backhand_index_pointing_right: Your installed version of Hugging Face Transformers does NOT list “summarization” as a valid pipeline task.
That’s not normal for standard installs.

:brain: The key insight (this is the root cause)

There are two conflicting realities right now:

:white_check_mark: In Transformers v4 (what the course expects)

pipeline(“summarization”)
:check_mark: Works perfectly

:warning: In Transformers v5 (new behavior)

Some pipelines were renamed / reorganized

“summarization” may not be directly exposed

You may need:

pipeline(“text2text-generation”)

:collision: Why your specific error looks weird

Your available tasks include:
‘any-to-any’, ‘image-classification’, ‘text-generation’, …
:backhand_index_pointing_right: This strongly suggests:

You’re on Transformers v5+

OR a partial / experimental install

OR Colab recently switched runtime versions (which it did)

So the course code (written for v4) breaks

:white_check_mark: Best fixes (ranked from easiest → best long-term)

:green_circle: Fix #1 (FASTEST): Use compatible version

Run this in Colab or your terminal:
pip install “transformers<5”
Then restart runtime/kernel :red_exclamation_mark:
Now this will work:
from transformers import pipeline summarizer = pipeline(“summarization”)

:yellow_circle: Fix #2 (Works on v5): Use new-style pipeline

from transformers import pipeline summarizer = pipeline(“text2text-generation”, model=“t5-small”) print(summarizer(“Your text here”))
:backhand_index_pointing_right: This is the v5-safe approach

:blue_circle: Fix #3 (Most stable overall): Specify a summarization model

from transformers import pipeline summarizer = pipeline( “summarization”, model=“sshleifer/distilbart-cnn-12-6” ) print(summarizer(“Your text here”))
:backhand_index_pointing_right: This often works across versions because you force the model

:robot: Why Google / other AI answers confused things

You saw suggestions like:

“text-summarization” :cross_mark: (not a real task)

“text-generation” :warning: (not ideal for summarizing)

:backhand_index_pointing_right: Those are partially incorrect guesses
The correct mapping is:
GoalCorrect pipelineSummarization (v4)"summarization"Summarization (v5 fallback)“text2text-generation"General text"text-generation”

:cloud: Why Colab “just works”

You asked this specifically — here’s the truth:
:backhand_index_pointing_right: Google Colab works because:

Fresh environment every run

Preinstalled dependencies

No broken installs

But… they recently upgraded to Transformers v5, which is why your course broke

:puzzle_piece: Bottom line

You’re not dealing with a hard bug — just:

:warning: Version mismatch between course code (v4) and your environment (v5)

:+1: What I recommend (simple path)

Do this:

Run:

pip install “transformers<5”

Restart runtime

Run original code unchanged

If you want, I can:

Check your exact version

Fix your local Python setup step-by-step

Or give you a “works everywhere” version of the code :+1:

KeyError: “Unknown task summarization…”

pipeline(“summarization”)

pipeline(“text2text-generation”)

‘any-to-any’, ‘image-classification’, ‘text-generation’, …

pip install “transformers<5”

from transformers import pipeline
summarizer = pipeline(“summarization”)

from transformers import pipeline

summarizer = pipeline(“text2text-generation”, model=“t5-small”)

print(summarizer(“Your text here”))

from transformers import pipeline

summarizer = pipeline(
“summarization”,
model=“sshleifer/distilbart-cnn-12-6”
)

print(summarizer(“Your text here”))

GoalCorrect pipelineSummarization (v4)"summarization"Summarization (v5 fallback)“text2text-generation"General text"text-generation”

pip install “transformers<5”

What would be the best way to fix it? Then do it!

Alright — let’s not overcomplicate this. The best fix depends on what you want:

:white_check_mark: Just make the course code work exactly as written → downgrade Transformers

:white_check_mark: Future-proof and modern → update your code for v5

:1st_place_medal: Best overall fix (recommended): make it work AND stay modern

Instead of fighting versions, just update your code slightly so it works on newer Hugging Face Transformers.

:white_check_mark: Use this (works on v4 and v5)

from transformers import pipeline summarizer = pipeline( “text2text-generation”, model=“t5-small” ) text = “”“America has changed dramatically during recent years…”“” print(summarizer(text, max_length=60, min_length=20))
:backhand_index_pointing_right: Why this is best:

Works on new versions

No environment headaches

Same result (summarization)

:2nd_place_medal: If you want the course EXACTLY as written

Then force the older version.

Step 1 — install compatible version

pip install “transformers<5”

Step 2 — VERY IMPORTANT

Restart your runtime / Python kernel

Step 3 — run original code

from transformers import pipeline summarizer = pipeline(“summarization”) print(summarizer(“Your text here”))

:test_tube: If you’re using Google Colab

Do this in one cell:
!pip install “transformers<5” from transformers import pipeline summarizer = pipeline(“summarization”) print(summarizer(“Your text here”))
Then click:
:backhand_index_pointing_right: Runtime → Restart runtime

:warning: What NOT to do (this caused confusion)

Avoid these:

“text-summarization” :cross_mark: (not real)

“text-generation” :cross_mark: (wrong task)

Random Google snippets :warning: (mixed accuracy)

:brain: Simple explanation (so it sticks)

Course = built for Transformers v4

Your environment = running v5

v5 changed how tasks are registered
:backhand_index_pointing_right: Result = “summarization” not found

:rocket: My honest recommendation

If you’re learning:
:backhand_index_pointing_right: Use the updated code (text2text-generation)
:backhand_index_pointing_right: Don’t downgrade unless the course forces you
If you want, I can:

Fix your exact setup (Windows / Python / pip)

Or give you a clean “AI starter setup” that won’t break again :+1:

from transformers import pipeline

summarizer = pipeline(
“text2text-generation”,
model=“t5-small”
)

text = “”“America has changed dramatically during recent years…”“”

print(summarizer(text, max_length=60, min_length=20))

pip install “transformers<5”

from transformers import pipeline

summarizer = pipeline(“summarization”)

print(summarizer(“Your text here”))

!pip install “transformers<5”

from transformers import pipeline

summarizer = pipeline(“summarization”)

print(summarizer(“Your text here”))

Just give both! Thank you!

Perfect :+1: — here are both clean, working solutions you can copy/paste depending on what you want.

:white_check_mark: OPTION 1 — Modern fix (works on new versions, recommended)

Works with current Hugging Face Transformers (v5+). No downgrading needed.
from transformers import pipeline summarizer = pipeline( “text2text-generation”, model=“t5-small” ) 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. “”” print(summarizer(text, max_length=60, min_length=20))
:check_mark: Works now
:check_mark: Future-proof
:check_mark: No environment issues

:white_check_mark: OPTION 2 — Course-compatible fix (exactly like lesson)

This matches the Hugging Face course.

Step 1: Install older version

pip install “transformers<5”

Step 2: Restart your Python runtime/kernel

(this step is REQUIRED)

Step 3: Run the original code

from transformers import pipeline summarizer = pipeline(“summarization”) text = “”“America has changed dramatically during recent years…”“” print(summarizer(text))
:check_mark: Matches course exactly
:check_mark: Uses classic “summarization” pipeline

:cloud: If you’re using Google Colab

Use this in ONE cell:
!pip install “transformers<5” from transformers import pipeline summarizer = pipeline(“summarization”) print(summarizer(“Your text here”))
Then:
:backhand_index_pointing_right: Runtime → Restart runtime → Run again

:brain: Quick decision guide

Want easy + no headaches → use Option 1

Want follow course exactly → use Option 2

If you want next, I can:

Show you how to speed this up with GPU

Or fix your local Python setup so this never breaks again :+1:

from transformers import pipeline

summarizer = pipeline(
“text2text-generation”,
model=“t5-small”
)

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.
“””

print(summarizer(text, max_length=60, min_length=20))

pip install “transformers<5”

from transformers import pipeline

summarizer = pipeline(“summarization”)

text = “”“America has changed dramatically during recent years…”“”

print(summarizer(text))

!pip install “transformers<5”

from transformers import pipeline

summarizer = pipeline(“summarization”)

print(summarizer(“Your text here”))

Perfect :+1: — here are both clean, working solutions you can copy/paste depending on what you want.

:white_check_mark: OPTION 1 — Modern fix (works on new versions, recommended)

Works with current Hugging Face Transformers (v5+). No downgrading needed.
from transformers import pipeline summarizer = pipeline( “text2text-generation”, model=“t5-small” ) 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. “”” print(summarizer(text, max_length=60, min_length=20))
:check_mark: Works now
:check_mark: Future-proof
:check_mark: No environment issues

:white_check_mark: OPTION 2 — Course-compatible fix (exactly like lesson)

This matches the Hugging Face course.

Step 1: Install older version

pip install “transformers<5”

Step 2: Restart your Python runtime/kernel

(this step is REQUIRED)

Step 3: Run the original code

from transformers import pipeline summarizer = pipeline(“summarization”) text = “”“America has changed dramatically during recent years…”“” print(summarizer(text))
:check_mark: Matches course exactly
:check_mark: Uses classic “summarization” pipeline

:cloud: If you’re using Google Colab

Use this in ONE cell:
!pip install “transformers<5” from transformers import pipeline summarizer = pipeline(“summarization”) print(summarizer(“Your text here”))
Then:
:backhand_index_pointing_right: Runtime → Restart runtime → Run again

:brain: Quick decision guide

Want easy + no headaches → use Option 1

Want follow course exactly → use Option 2

If you want next, I can:

Show you how to speed this up with GPU

Or fix your local Python setup so this never breaks again :+1:

from transformers import pipeline

summarizer = pipeline(
“text2text-generation”,
model=“t5-small”
)

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.
“””

print(summarizer(text, max_length=60, min_length=20))

Looking at your error, I can see the issue clearly. Your Transformers installation doesn’t recognize "summarization" as a valid task - notice it’s not in that long list of available tasks shown in your error.

Here’s What’s Happening

You’re likely running Transformers v5+ (or a development version) where the API has changed. The course material was written for v4.x where pipeline("summarization") worked directly.

My Recommendation: Use Both Approaches

Here are working solutions you can use RIGHT NOW:


:white_check_mark: SOLUTION 1: Quick Fix (Downgrade to v4)

For Colab:

!pip install "transformers<5" --quiet
# Then click: Runtime → Restart runtime
# After restart, run this:
from transformers import pipeline

summarizer = pipeline("summarization")
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."""

result = summarizer(text, max_length=60, min_length=20)
print(result)

For Local Python:

pip install "transformers<5"
# Then restart your Python kernel/terminal

:white_check_mark: SOLUTION 2: Modern Fix (Works on v5+)

from transformers import pipeline

# Use text2text-generation instead (works on v4 AND v5)
summarizer = pipeline(
    "text2text-generation", 
    model="t5-small"  # or "facebook/bart-large-cnn" for better quality
)

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."""

result = summarizer(text, max_length=60, min_length=20)
print(result[0]['generated_text'])

:bullseye: BEST OVERALL SOLUTION (Most Reliable)

from transformers import pipeline

# Explicitly specify a summarization model - works across versions
summarizer = pipeline(
    "summarization",
    model="sshleifer/distilbart-cnn-12-6",  # or "facebook/bart-large-cnn"
    framework="pt"  # or "tf" for TensorFlow
)

text = """Your text here..."""
result = summarizer(text, max_length=60, min_length=20)
print(result)

:magnifying_glass_tilted_left: To Check Your Current Setup:

Run this first:

import transformers
print(f"Transformers version: {transformers.__version__}")

# See what tasks are available
from transformers.pipelines import check_task
print(check_task("summarization"))  # This will tell you if it exists

:light_bulb: My Honest Advice:

  1. If you’re learning/following a course → Use Solution 1 (downgrade to v4)
  2. If you want production-ready code → Use Solution 2 (modern approach)
  3. If you want maximum compatibility → Use the Best Overall Solution above

The key insight: Specifying the model explicitly often bypasses version issues because Transformers can infer the correct task from the model itself.

Want me to help you debug your specific environment or set this up step-by-step?

!pip install “transformers<5” --quiet

Then click: Runtime → Restart runtime

After restart, run this:

from transformers import pipeline

summarizer = pipeline(“summarization”)
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.”“”

result = summarizer(text, max_length=60, min_length=20)
print(result)

pip install “transformers<5”

Then restart your Python kernel/terminal

from transformers import pipeline

Use text2text-generation instead (works on v4 AND v5)

summarizer = pipeline(
“text2text-generation”,
model=“t5-small” # or “facebook/bart-large-cnn” for better quality
)

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.”“”

result = summarizer(text, max_length=60, min_length=20)
print(result[0][‘generated_text’])

from transformers import pipeline

Explicitly specify a summarization model - works across versions

summarizer = pipeline(
“summarization”,
model=“sshleifer/distilbart-cnn-12-6”, # or “facebook/bart-large-cnn”
framework=“pt” # or “tf” for TensorFlow
)

text = “”“Your text here…”“”
result = summarizer(text, max_length=60, min_length=20)
print(result)

import transformers
print(f"Transformers version: {transformers.version}")

See what tasks are available

from transformers.pipelines import check_task
print(check_task(“summarization”)) # This will tell you if it exists

Not sure finish it if you didn’t thank you!

It sounds like you have the right idea but want a clean, final answer to just get it done. You are dealing with a version conflict where your software is “too new” for the old course code.

Here is the finished, complete solution. You can choose Option 1 (easiest, matches the course exactly) or Option 2 (modern, no downgrading).

:green_circle: OPTION 1: The “Make the Course Work” Fix (Recommended)

This downgrades your software to match the lesson. This is the most reliable way to finish your assignment.

Step 1: Copy and paste this into a cell and run it:

# Install the version of Transformers that the course expects
!pip install "transformers<4.40" --quiet

Step 2: :warning: CRITICAL: You must restart your runtime now.

  • Go to Runtime > Restart Runtime.

Step 3: After it restarts, copy and paste this code and run it:

from transformers import pipeline

# This will now work because we installed the older version
summarizer = pipeline("summarization")

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."""

print(summarizer(text, max_length=60, min_length=20))

:blue_circle: OPTION 2: The “Modern” Fix (No Downgrading)

Use this if you want to keep your current software version. We change the code slightly to use the new task name.

Copy and paste this into a single cell and run it:

from transformers import pipeline

# We use 'text2text-generation' and specify the model explicitly.
# This works on the newest versions of Transformers.
summarizer = pipeline(
    "text2text-generation", 
    model="t5-small"
)

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."""

# Run the summarizer
result = summarizer(text, max_length=60, min_length=20)
print(result[0]['generated_text'])

My recommendation: If you are taking a course, do Option 1. It prevents other weird errors later in the course. If you are just experimenting, Option 2 is fine!

Install the version of Transformers that the course expects

!pip install “transformers<4.40” --quiet

from transformers import pipeline

This will now work because we installed the older version

summarizer = pipeline(“summarization”)

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.”“”

print(summarizer(text, max_length=60, min_length=20))

from transformers import pipeline

We use ‘text2text-generation’ and specify the model explicitly.

This works on the newest versions of Transformers.

summarizer = pipeline(
“text2text-generation”,
model=“t5-small”
)

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.”“”

Run the summarizer

result = summarizer(text, max_length=60, min_length=20)
print(result[0][‘generated_text’])

1 Like