Fixed: "KeyError: The task question-answering has been removed from transformers"
pipeline("question-answering") stopped with KeyError: 'The task question-answering has been removed from transformers. Use the text-generation pipeline with a chat model instead.' Transformers 5 removed that pipeline on purpose. A small chat model in a text-generation pipeline answers the same question from the same text.
What I Was Doing
I was checking which of the classic text pipelines still work in Transformers 5.26.0, on Python 3.14. Question answering takes a question and a piece of text, the context, and finds the answer in the text:
from transformers import pipeline
qa = pipeline("question-answering")
context = "The Eiffel Tower was finished in 1889."
print(qa(question="When was the Eiffel Tower finished?", context=context))
uv run python qa.py
What I Expected
An answer taken from the context, with its score and position, as older Transformers versions return it:
{'score': ..., 'start': ..., 'end': ..., 'answer': '1889'}
What I Got
Traceback (most recent call last):
File "/Users/you/source/qa-removed/qa.py", line 3, in <module>
qa = pipeline("question-answering")
File "/Users/you/source/qa-removed/.venv/lib/python3.14/site-packages/transformers/pipelines/__init__.py", line 1071, in pipeline
task = _resolve_deprecated_task(task)
File "/Users/you/source/qa-removed/.venv/lib/python3.14/site-packages/transformers/pipelines/__init__.py", line 378, in _resolve_deprecated_task
raise KeyError(
...<2 lines>...
)
KeyError: 'The task question-answering has been removed from transformers. Use the `text-generation` pipeline with a chat model instead. See the migration guide for more details: https://github.com/huggingface/transformers/blob/main/MIGRATION_GUIDE_V5.md#pipelines'

The error came from the first line that uses Transformers, before any model was downloaded.
What I Checked
The message links to the Transformers v5 migration guide. Its section "Text pipelines that should just be LLMs" says:
question-answeringandText2TextGenerationPipeline, including its relatedSummarizationPipelineandTranslationPipeline, were deprecated and will now be removed.pipelineclasses are intended as a high-level beginner-friendly API, but for almost all text-to-text or question-answering tasks a modern chat model andTextGenerationPipelinewill provide much higher quality output.
In the source, transformers/pipelines/__init__.py keeps a list of removed tasks, REMOVED_TASKS, and raises this KeyError for any of them: question-answering, summarization, translation (including names such as translation_en_to_fr) and text2text-generation.
Why It Happens
The question-answering pipeline was removed in Transformers 5. Code and tutorials written for Transformers 4 still use it, and they fail the moment they create the pipeline.
The Fix
Use the text-generation pipeline with a chat model, and put the context and the question in the message, as the migration guide shows. The guide's example uses Qwen/Qwen3-4B-Instruct-2507, which has 4 billion parameters, about 8 GB to download; its comment adds that "Any other chat model will also work - if you're low on memory you can use a smaller one". This fix uses Qwen/Qwen2.5-0.5B-Instruct, a chat model with 0.5 billion parameters (988 MB) under the Apache-2.0 license:
from transformers import pipeline
generator = pipeline(
"text-generation",
model="Qwen/Qwen2.5-0.5B-Instruct",
revision="7ae557604adf67be50417f59c2c2f167def9a775",
)
context = "The Eiffel Tower was finished in 1889."
question = "When was the Eiffel Tower finished?"
prompt = f"Answer using only this context: {context}\nQuestion: {question}"
messages = [{"role": "user", "content": prompt}]
print(generator(messages)[0]["generated_text"][-1]["content"])

A chat model takes a conversation: a list of messages, each a dictionary with a role and its content. Here there's one message from the user. The pipeline returns the whole conversation with the model's reply added at the end, so [0]["generated_text"][-1]["content"] is the text of that reply.
After the Fix
uv run python qa.py
Warning: You are sending unauthenticated requests to the HF Hub. Please set a HF_TOKEN to enable higher rate limits and faster downloads.
config.json: 100%|█████████████████████████████████████████████████| 659/659 [00:00<00:00, 4.61MB/s]
model.safetensors: downloading bytes: ██████████████████████████████████████████| 854MB, 1.15MB/s
model.safetensors: reconstructing file: 100%|██████████████████████████| 988MB / 988MB, 59.0MB/s
Loading weights: 100%|██████████████████████████████████████████| 290/290 [00:00<00:00, 7007.70it/s]
generation_config.json: 100%|██████████████████████████████████████| 242/242 [00:00<00:00, 1.61MB/s]
tokenizer_config.json: 100%|███████████████████████████████████| 7.30k/7.30k [00:00<00:00, 12.6MB/s]
vocab.json: 100%|██████████████████████████████████████████████| 2.78M/2.78M [00:00<00:00, 9.73MB/s]
merges.txt: 100%|██████████████████████████████████████████████| 1.67M/1.67M [00:00<00:00, 65.8MB/s]
tokenizer.json: 100%|██████████████████████████████████████████| 7.03M/7.03M [00:00<00:00, 61.2MB/s]
The Eiffel Tower was finished in 1889.

The model downloaded once and answered from the context: "The Eiffel Tower was finished in 1889." The commands work unchanged in PowerShell.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
| Passing a plain string instead of messages | The model treats it as text to continue: the result was the whole prompt with " The Eiffel Tower was finished in 1889." added to its end | Pass a list of {"role": …, "content": …} messages |
| Printing the whole result | You get the whole conversation: [{'generated_text': [{'role': 'user', …}, {'role': 'assistant', 'content': 'The Eiffel Tower was finished in 1889.'}]}] | Read [0]["generated_text"][-1]["content"] |
| Leaving the context out of the prompt | The model answers from what it learned in training, which can be wrong or out of date | Put the text in the message and ask it to answer from it |
| Staying on Transformers 4 to keep the old pipeline | Your project is stuck on an old major version | Move the task to a chat model |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
KeyError: 'The task summarization has been removed from transformers. | The summarization pipeline was removed too | Fixed: KeyError: The task summarization has been removed from transformers |
The same KeyError for translation or text2text-generation | Also removed in Transformers 5 | A chat model with a prompt that asks for the translation |
| The answer is wordy or not in the text | Small chat models sometimes add their own words | Ask for a short answer in the prompt, or try a larger chat model |
FAQ
Does a chat model find the answer the same way?
No. The old pipeline picked a span out of the context and told you where it was. A chat model writes its answer, so it can rephrase it, and it has no start or end. When you need the exact words, ask for them in the prompt and check them against the text.
Is the chat model slower?
It's larger than the models the old pipeline used, and it writes its answer one token at a time, so each answer takes longer. For a few questions it doesn't matter; for thousands, measure it.
Conclusion
pipeline("question-answering") raised KeyError: 'The task question-answering has been removed from transformers.' because Transformers 5 removed that pipeline. A text-generation pipeline with Qwen/Qwen2.5-0.5B-Instruct, given the context and the question in one message, answered "The Eiffel Tower was finished in 1889."
Additional Resources
- Migration guide: Text pipelines that should just be LLMs — why the pipelines were removed, with an example.
- Chat basics — using chat models with Transformers.
- Qwen/Qwen2.5-0.5B-Instruct — the model's card.
