We will use the model in『SiEBERT - English-Language Sentiment Classification』 to classify the sentiment of English sentences. I would like to classify the sentiment of each English sentence by positive and negative.
Hartmann, Jochen and Heitmann, Mark and Siebert, Christian and Schamp, Christina,
“More than a feeling: Accuracy and Application of Sentiment Analysis”, International Journal of Research in Marketing(2022)
Here we use the siebert/sentiment-roberta-large-english model on huggingface, if you want to use transformers on Google Colab you need to install transformers beforehand.
Visualize the results using positive and negative labels and their scores.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
fort,sinzip(ts_list,scores):score=np.round(float(s["score"]),4)# sentiment scorefont_weight="bold"ifscore>0.995else"normal"# thickness of the text# color display for each sentimentifs["label"]=="NEGATIVE":r=255-10*int(1000-score*1000)display(HTML(f"[score={score}] <span style='color:rgb({r},100,100);font-weight:{font_weight};'>{t}</span>"))elifs["label"]=="POSITIVE":g=255-10*int(1000-score*1000)display(HTML(f"[score={score}] <span style='color:rgb(100,{g},100);font-weight:{font_weight};'>{t}</span>"))