Views
No views yet
1from transformers import pipeline
2
3pipe = pipeline(model="delarosajav95/tw-roberta-base-sentiment-FT")
4inputs = ["The flat is very nice but it's too expensive and the location is very bad.",
5 "I loved the music, but the crowd was too rowdy to enjoy it properly.",
6 "They believe that I'm stupid and I like waiting for hours in line to buy a simple coffee."
7]
8result = pipe(inputs, return_all_scores=True)
9
10label_mapping = {"LABEL_0": "Negative", "LABEL_1": "Neutral", "LABEL_2": "Positive"}
11for i, predictions in enumerate(result):
12 print("==================================")
13 print(f"Text {i + 1}: {inputs[i]}")
14 for pred in predictions:
15 label = label_mapping.get(pred['label'], pred['label'])
16 score = pred['score']
17 print(f"{label}: {score:.2%}")1==================================
2Text 1: The flat is very nice but it's too expensive and the location is very bad.
3Negative: 0.09%
4Neutral: 99.88%
5Positive: 0.03%
6==================================
7Text 2: I loved the music, but the crowd was too rowdy to enjoy it properly.
8Negative: 0.04%
9Neutral: 99.92%
10Positive: 0.04%
11==================================
12Text 3: They believe that I'm stupid and I like waiting for hours in line to buy a simple coffee.
13Negative: 69.79%
14Neutral: 30.12%
15Positive: 0.09%1@inproceedings{barbieri-etal-2020-tweeteval,
2 title = "{T}weet{E}val: Unified Benchmark and Comparative Evaluation for Tweet Classification",
3 author = "Barbieri, Francesco and
4 Camacho-Collados, Jose and
5 Espinosa Anke, Luis and
6 Neves, Leonardo",
7 booktitle = "Findings of the Association for Computational Linguistics: EMNLP 2020",
8 month = nov,
9 year = "2020",
10 address = "Online",
11 publisher = "Association for Computational Linguistics",
12 url = "https://aclanthology.org/2020.findings-emnlp.148",
13 doi = "10.18653/v1/2020.findings-emnlp.148",
14 pages = "1644--1650"
15}