Issue with summarization and translation pipeline

  1. summarization as a task in pipeline object is not available.

  2. Similar issue for translation pipeline

    • could not post a screenshot because of media limitation (1) for new user
1 Like

This is because several pipelines were removed in the upgrade from Transformers v4 to v5.


Why pipeline("summarization") and translation pipelines fail

1) In Transformers v5.x, those pipeline tasks were removed

Transformers v5 removed the legacy text-to-text pipelines:

  • Text2TextGenerationPipeline
  • and the related SummarizationPipeline / TranslationPipeline

The migration guide states these were deprecated and are now removed, recommending modern chat models via TextGenerationPipeline instead. (GitHub)

2) pipeline() only accepts tasks that are registered

pipeline("…") doesn’t “infer” what you mean; it checks a registry (SUPPORTED_TASKS). In v5.2.0, the list of accepted tasks includes things like text-generation, question-answering, etc., but does not include summarization or translation. (GitHub)

So:

  • pipeline("summarization") → Unknown task / task not available
  • pipeline("translation…") → similarly fails (because the pipeline task is not registered)

3) It’s confusing because older docs/tutorials still show the old pattern

There’s an open issue noting that the summarization/translation docs still referenced pipeline() examples, which misleads users on v5. (GitHub)

4) Translation errors can be misleading

There’s also a reported bug where the error message suggests translation_XX_to_YY tasks are available, but they still fail because "translation" isn’t actually supported in v5’s pipeline registry. (GitHub)

5) This is not just you—downstream libraries broke too

For example, MLflow users reported breakage because TranslationPipeline / SummarizationPipeline classes no longer exist in v5. (GitHub)


Quick confirmation (recommended first)

Run this to confirm you’re on v5 and see what pipeline tasks exist:

import transformers
from transformers.pipelines import get_supported_tasks

print(transformers.__version__)
print(get_supported_tasks())

If the printed task list doesn’t include summarization / translation, you’re in the v5 behavior described above. (GitHub)


Solutions (choose one)

Option A — Keep the old pipeline API (pin to v4)

If you want pipeline("summarization") and pipeline("translation_xx_to_yy") to work as in older tutorials, install Transformers v4:

pip install -U "transformers<5"

Why this works: v4 pipeline docs explicitly describe summarization and translation_xx_to_yy pipeline tasks as supported. (Hugging Face)

Use this option if:

  • you’re following older notebooks/courses
  • you want the classic pipeline outputs ({"summary_text": ...}, {"translation_text": ...})

Option B — Stay on v5 and use seq2seq models via generate()

Even though the convenience pipelines are gone, seq2seq models still work (e.g., BART/T5/Marian/NLLB). You just call model.generate() yourself.

The official generation docs recommend max_new_tokens to control output length. (Hugging Face)

Summarization example (BART)

import torch
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM

model_id = "facebook/bart-large-cnn"
tok = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForSeq2SeqLM.from_pretrained(model_id)

device = "cuda" if torch.cuda.is_available() else "cpu"
model.to(device).eval()

text = "YOUR ARTICLE HERE"
inputs = tok(text, return_tensors="pt", truncation=True).to(device)

with torch.inference_mode():
    out = model.generate(
        **inputs,
        max_new_tokens=150,   # recommended way to control output length
        num_beams=4,
        no_repeat_ngram_size=3,
    )

summary = tok.decode(out[0], skip_special_tokens=True)
print(summary)

Translation example (Marian)

import torch
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM

model_id = "Helsinki-NLP/opus-mt-en-ja"
tok = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForSeq2SeqLM.from_pretrained(model_id)

device = "cuda" if torch.cuda.is_available() else "cpu"
model.to(device).eval()

text = "Hello, how are you?"
inputs = tok(text, return_tensors="pt", truncation=True).to(device)

with torch.inference_mode():
    out = model.generate(**inputs, max_new_tokens=128)

print(tok.decode(out[0], skip_special_tokens=True))

Important translation pitfall (multilingual models)

If you use models like NLLB or M2M100, you typically must force the target language token using forced_bos_token_id. (Hugging Face)


Option C — Follow the v5 recommendation: use pipeline("text-generation") with a chat model

Transformers v5’s migration guide explicitly recommends using TextGenerationPipeline with a modern chat model for summarization/translation via prompting. (GitHub)

Summarization via chat model

from transformers import pipeline

summarizer = pipeline("text-generation", model="Qwen/Qwen3-4B-Instruct-2507")
messages = [{"role": "user", "content": "Summarize the following text:\n\n[TEXT]"}]

out = summarizer(messages)
print(out[0]["generated_text"][-1]["content"])

Translation via chat model

Same idea; change the prompt:

from transformers import pipeline

translator = pipeline("text-generation", model="Qwen/Qwen3-4B-Instruct-2507")
messages = [{"role": "user", "content": "Translate this into Japanese:\n\nHello, how are you?"}]

out = translator(messages)
print(out[0]["generated_text"][-1]["content"])

Use this option if:

  • you want better “instruction-following” behavior without model-family-specific translation settings
  • you prefer staying inside the pipeline API (but using text-generation)

What I would pick (rule of thumb)

  • Want old tutorials to work unchanged → Option A (transformers<5)
  • Want deterministic seq2seq translation/summarization with classic models → Option B (generate())
  • Want highest convenience and often better quality via instruction prompts → Option C (pipeline("text-generation"))