from transformers import logging
logging.set_verbosity_error() # mute noticesIn [1]:
In [2]:
import pandas as pd
from transformers import pipeline
data = pd.read_csv("../data/example_dataset.csv")
textlist = list(data["text"])In [3]:
zeroshot_classifier = pipeline("zero-shot-classification",
model="MoritzLaurer/deberta-v3-base-zeroshot-v2.0")
template = "This text expresses {}."
label = "fear"
results = zeroshot_classifier(textlist, candidate_labels=[label],
hypothesis_template=template)
result_df = pd.DataFrame({
"text": data["text"],
"fear_score": [r["scores"][0] for r in results],
})
print(result_df) text fear_score
0 I feel helpless and afraid like never before 0.999899
1 No commute; sunny day; my kids laughing; being... 0.000050
2 Feeling scared and lonely, can't wait for this... 0.997561
3 It's gonna get tougher but we will get through... 0.006027
4 I am terrified by what is happening. I’m scare... 0.999911
5 Stay inside, stay safe, and this madness will ... 0.991620
6 I am scared that I will get sick and die, and ... 0.999891
7 Feeling relaxed and happy but I understand tha... 0.048903
8 I am very scared and worried about contracting... 0.999924
9 I'm confident we will get through this crisis. 0.003629