'Emotion detection in text using EmoRoberta
I'm using Emoroberta for emotion detection and I want the output to be all emotions, each with its assigned score and not only the final emotion and its score. How can I do that? This is the code I'm using:
tokenizer = RobertaTokenizerFast.from_pretrained("arpanghoshal/EmoRoBERTa")
model = TFRobertaForSequenceClassification.from_pretrained("arpanghoshal/EmoRoBERTa")
emotion = pipeline('sentiment-analysis', model='arpanghoshal/EmoRoBERTa')
def get_emotion_label(text):
return(emotion(text)[0]['label'])
df['Text']= df['Text'].apply(remove_html).apply(remove_URL).apply(remove_stopwords)
df['Emotion']= df['Text'].apply(get_emotion_label)
Solution 1:[1]
So the solution is to add a parameter in the pipeline for it to become:
emotion = pipeline('sentiment-analysis', model='arpanghoshal/EmoRoBERTa' , return_all_scores= True)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Yosr Dhaoui |
