from transformers import logging
logging.set_verbosity_error()  # mute notices
import pandas as pd
from transformers import pipeline

data = pd.read_csv("../data/example_dataset.csv")
textlist = list(data["text"])
emotion_classifier = pipeline("text-classification",
                               model="SamLowe/roberta-base-go_emotions",
                               top_k=None,
                               truncation=True)

result = emotion_classifier(textlist)
fear_scores = [next(item["score"] for item in scores if item["label"] == "fear")
               for scores in result]

result_df = pd.DataFrame({
    "text": data["text"],
    "fear_score": fear_scores,
})

print(result_df)
                                                text  fear_score
0       I feel helpless and afraid like never before    0.860037
1  No commute; sunny day; my kids laughing; being...    0.000854
2  Feeling scared and lonely, can't wait for this...    0.861225
3  It's gonna get tougher but we will get through...    0.008892
4  I am terrified by what is happening. I’m scare...    0.903767
5  Stay inside, stay safe, and this madness will ...    0.005280
6  I am scared that I will get sick and die, and ...    0.896429
7  Feeling relaxed and happy but I understand tha...    0.002808
8  I am very scared and worried about contracting...    0.804676
9     I'm confident we will get through this crisis.    0.007578