Multiple Categories (labels)

Hi @joeddav and @bhadresh-savani I am using your text-classification models, but I am encountering a problem, nothing I try allows me to retrieve all the values: always just the first value is returned, would you be able to advise me, thanks so much.

1 Like

Hi @snowdere,
I am really glad you use this model, you can use it like either of the below ways

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)

or

from transformers import pipeline
classifier = pipeline("sentiment-analysis",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)

return_all_scores=True should be in the pipeline() argument.
Output:

[[
{'label': 'sadness', 'score': 0.0006792712374590337}, 
{'label': 'joy', 'score': 0.9959300756454468}, 
{'label': 'love', 'score': 0.0009452480007894337}, 
{'label': 'anger', 'score': 0.0018055217806249857}, 
{'label': 'fear', 'score': 0.00041110432357527316}, 
{'label': 'surprise', 'score': 0.0002288572577526793}
]]

Thanks

Thanks for the answer that is great, so can this also be used for multiclassification (if it is both for example joy and love?) i.e. 60% joy, and 70% love and 20% anger etc…if not, do you know what model I can use for this?

Hi @snowdere,
Currently, text-classification pipeline only has multiclass classification. It uses softmax if more than two labels. You can try zero-shot pipeline, it supports multilabel things that you required. This model I trained for multiclass classification as the emotion dataset is multiclass kind of dataset(i.e. having labels like [1 0 0 0 0 0] with six class).

return_all_scores has been Deprecated. Instead pass top_k=None if you want all scores.