Views
No views yet
1from transformers import pipeline
2
3pipe = pipeline(model="delarosajav95/tw-roberta-base-sentiment-FT-v2")
4
5inputs = ["The flat is very nice but it's too expensive and the location is very bad.",
6 "I loved the music, but the crowd was too rowdy to enjoy it properly.",
7 "They believe that I'm stupid and I like waiting for hours in line to buy a simple coffee."
8]
9
10result = pipe(inputs, return_all_scores=True)
11
12label_mapping = {"LABEL_0": "Negative", "LABEL_1": "Neutral", "LABEL_2": "Positive"}
13for i, predictions in enumerate(result):
14 print("==================================")
15 print(f"Text {i + 1}: {inputs[i]}")
16 for pred in predictions:
17 label = label_mapping.get(pred['label'], pred['label'])
18 score = pred['score']
19 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: 78.54%
4Neutral: 20.66%
5Positive: 0.80%
6==================================
7Text 2: I loved the music, but the crowd was too rowdy to enjoy it properly.
8Negative: 5.18%
9Neutral: 93.34%
10Positive: 1.48%
11==================================
12Text 3: They believe that I'm stupid and I like waiting for hours in line to buy a simple coffee.
13Negative: 82.37%
14Neutral: 16.85%
15Positive: 0.79%1from transformers import pipeline
2
3url = "delarosajav95/tw-roberta-base-sentiment-FT-v2"
4
5classifier = pipeline("sentiment-analysis", model=url)
6
7text = "text to classify"
8
9result = classifier(text, return_all_scores=True)
10
11label_mapping = {"LABEL_0": "Negative", "LABEL_1": "Neutral", "LABEL_2": "Positive"}
12for i, predictions in enumerate(result):
13 print("==================================")
14 print(f"Text {i + 1}: {text}")
15 for pred in predictions:
16 label = label_mapping.get(pred['label'], pred['label'])
17 score = pred['score']
18 print(f"{label}: {score:.2%}")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}