Upload sindhinltk/sentiment.py with huggingface_hub
Browse files- sindhinltk/sentiment.py +10 -0
sindhinltk/sentiment.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import pipeline
|
| 2 |
+
class SindhiSentiment:
|
| 3 |
+
def __init__(self):
|
| 4 |
+
# Neural Backbone: Multilingual Contextual Brain
|
| 5 |
+
self.classifier = pipeline('sentiment-analysis', model='tabularisai/multilingual-sentiment-analysis')
|
| 6 |
+
def analyze(self, text):
|
| 7 |
+
res = self.classifier(text)[0]
|
| 8 |
+
# Professional Label Mapping
|
| 9 |
+
m = {'LABEL_1': 'Positive', 'LABEL_0': 'Negative', 'LABEL_2': 'Neutral'}
|
| 10 |
+
return {'label': m.get(res['label'], res['label']), 'confidence': f"{round(res['score']*100, 2)}%"}
|