Skip to main content

Fixed: return_all_scores=True Returns Only One Label in Transformers 5

· 7 min read
Jagdish Kumawat
Founder @ Dewiride

A model card's example passes return_all_scores=True to a Hugging Face text-classification pipeline and shows a score for every label. In Transformers 5 the same code printed only the top label, with no error and no warning, because the argument no longer exists. top_k=None is its replacement, and it returned all six labels.

What I Was Doing​

I was trying bhadresh-savani/distilbert-base-uncased-emotion, a model that classifies English text into six emotions, with the example in the "How to Use the model" section of its card on the Hugging Face Hub:

The How to Use the model section of the bhadresh-savani/distilbert-base-uncased-emotion card on the Hugging Face Hub: a text-classification pipeline created with return_all_scores=True, a prediction for a sentence about loving transformers, and an Output block with a list inside a list holding six labels and scores: sadness, joy at 0.9959, love, anger, fear and surprise.

I copied the example as it is, in a project with Transformers 5.26.0 on Python 3.14:

card_snippet.py
from transformers import pipeline
classifier = pipeline("text-classification",model='bhadresh-savani/distilbert-base-uncased-emotion', return_all_scores=True)
prediction = classifier("I love using transformers. The best part is wide range of support and its easy to use", )
print(prediction)
Terminal
uv run python card_snippet.py

What I Expected​

What the card's Output block shows: all six emotions, each with its score, joy at 0.9959 and the other five far below it.

What I Got​

Output
Loading weights: 100%|█████████████████████████████████████████| 104/104 [00:00<00:00, 11900.68it/s]
[{'label': 'joy', 'score': 0.9959298968315125}]

The terminal after uv run python card_snippet.py: the weights loading, then a list with one result, joy with a score of 0.9959298968315125.

One label instead of six. The top label and its score match the card, so the model works; the other five scores are missing, and nothing says why.

What I Checked​

Whether the argument still exists. Transformers' pull request huggingface/transformers#43195, "Remove more deprecated objects/args", merged in January 2026 for Transformers 5, removed return_all_scores. The text-classification pipeline's settings in 5.26.0 are function_to_apply and top_k; every other keyword argument goes to the tokenizer:

transformers/pipelines/text_classification.py (excerpt, 5.26.0)
def _sanitize_parameters(self, function_to_apply=None, top_k="", **tokenizer_kwargs):
# Using "" as default argument because we're going to use `top_k=None` in user code to declare
# "No top_k"
preprocess_params = tokenizer_kwargs

So return_all_scores=True is handed to the tokenizer, which doesn't use it, and the pipeline returns its default: the top label.

Whether it's known. An issue on Transformers, huggingface/transformers#43901, "TextClassificationPipeline docs still mention return_all_scores, but behavior differs", shows the same result: "users may expect return_all_scores=True to return all label scores, but it currently returns only the top label." It was closed by a fix to the documentation, #43903.

What replaces it. Before the argument was removed, using it printed a deprecation warning that named its replacement. The code that #43195 removed said:

transformers/pipelines/text_classification.py (removed by #43195)
"`return_all_scores` is now deprecated, if want a similar functionality use `top_k=None` instead of"
" `return_all_scores=True` or `top_k=1` instead of `return_all_scores=False`.",

The pipeline's documentation describes top_k as "How many results to return", and top_k=None means no limit: every label.

Why It Happens​

The card was written for an older Transformers, where return_all_scores=True returned every label. Transformers 5 removed the argument, but the pipeline accepts unknown keyword arguments and passes them to the tokenizer, so the old argument is silently ignored instead of raising an error.

The Fix​

Pass top_k=None when you call the pipeline. This version also pins the model to a commit, so it doesn't change under the code:

card_fixed.py
from transformers import pipeline

classifier = pipeline(
"text-classification",
model="bhadresh-savani/distilbert-base-uncased-emotion",
revision="98864ce5bb9cb58a41e882e62f1d8e55173b5ac6",
)
prediction = classifier(
"I love using transformers. The best part is wide range of support and its easy to use",
top_k=None,
)
print(prediction)

The fixed card_fixed.py in a macOS-style code window: a text-classification pipeline with the bhadresh-savani/distilbert-base-uncased-emotion model pinned to a commit, called on the card's sentence with top_k=None, and the prediction printed.

After the Fix​

Terminal
uv run python card_fixed.py
Output
Loading weights: 100%|██████████████████████████████████████████| 104/104 [00:00<00:00, 9092.39it/s]
[{'label': 'joy', 'score': 0.9959298968315125}, {'label': 'anger', 'score': 0.0018055237596854568}, {'label': 'love', 'score': 0.0009452462545596063}, {'label': 'sadness', 'score': 0.000679271062836051}, {'label': 'fear', 'score': 0.0004111042362637818}, {'label': 'surprise', 'score': 0.00022885717044118792}]

The terminal after the fix: the weights loading, then six results sorted by score: joy 0.9959, anger 0.0018, love 0.00095, sadness 0.00068, fear 0.00041 and surprise 0.00023.

All six labels, with the same scores as the card's output to six or more decimal places. Two things differ from the card: the list is sorted from the highest score down, and it's one flat list instead of a list inside a list. The commands work unchanged in PowerShell.

Common Mistakes​

MistakeWhat happensDo this instead
Reading the first result as the model's first labelWith top_k=None, results are sorted by score, so the first is the top labelLook labels up by their label, not their position
Passing top_k=None to pipeline(...) instead of the callOne text then returns a list inside a list, and code that loops over it failsPass it when you call the pipeline, as above

Troubleshooting​

SymptomLikely causeFix
TypeError: list indices must be integers or slices, not str after switching to top_k=Nonetop_k=None was given to pipeline(...), so a single text returns a nested listFixed: TypeError: list indices must be integers or slices, not str with a Hugging Face Pipeline's top_k
Only some of the labels come backtop_k set to a numbertop_k=None returns them all

FAQ​

Do the scores add up to 1?​

For this model, yes. The pipeline's documentation says that when a model has two labels or more, "the pipeline will run a softmax over the results", which shares 1 between the labels. Adding up the six scores for another sentence gave 1.000000001717126: 1, apart from the rounding of decimal numbers.

Is the card wrong?​

It was right for the Transformers version it was written with. The card's code is the model author's to update.

Conclusion​

return_all_scores=True printed one label in Transformers 5 because the argument was removed, and the pipeline passes unknown arguments to the tokenizer instead of rejecting them. Calling the pipeline with top_k=None returned all six emotions with the card's scores, sorted from highest to lowest.

Additional Resources​