Update README.md
Browse files
README.md
CHANGED
@@ -99,45 +99,58 @@ model_name = "tabularisai/multilingual-sentiment-analysis"
|
|
99 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
100 |
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
101 |
|
102 |
-
def predict_sentiment(
|
103 |
-
inputs = tokenizer(
|
104 |
with torch.no_grad():
|
105 |
outputs = model(**inputs)
|
106 |
probabilities = torch.nn.functional.softmax(outputs.logits, dim=-1)
|
107 |
-
predicted_class = torch.argmax(probabilities, dim=-1).item()
|
108 |
sentiment_map = {0: "Very Negative", 1: "Negative", 2: "Neutral", 3: "Positive", 4: "Very Positive"}
|
109 |
-
return sentiment_map[
|
110 |
|
111 |
texts = [
|
112 |
# English
|
113 |
-
"I absolutely
|
114 |
-
|
115 |
# Chinese
|
116 |
-
"
|
117 |
-
|
118 |
# Spanish
|
119 |
-
"El
|
120 |
-
|
121 |
# Arabic
|
122 |
-
"
|
123 |
-
|
124 |
# Ukrainian
|
125 |
-
"
|
126 |
-
|
127 |
# Hindi
|
128 |
-
"यह
|
129 |
-
|
130 |
# Bengali
|
131 |
-
"
|
132 |
-
|
133 |
# Portuguese
|
134 |
-
"Este livro é fantástico! Eu aprendi muitas coisas novas e inspiradoras."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
]
|
136 |
|
137 |
-
for text in texts:
|
138 |
-
|
139 |
-
print(f"Text: {text}")
|
140 |
-
print(f"Sentiment: {sentiment}\n")
|
141 |
```
|
142 |
|
143 |
## Ethical Considerations
|
|
|
99 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
100 |
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
101 |
|
102 |
+
def predict_sentiment(texts):
|
103 |
+
inputs = tokenizer(texts, return_tensors="pt", truncation=True, padding=True, max_length=512)
|
104 |
with torch.no_grad():
|
105 |
outputs = model(**inputs)
|
106 |
probabilities = torch.nn.functional.softmax(outputs.logits, dim=-1)
|
|
|
107 |
sentiment_map = {0: "Very Negative", 1: "Negative", 2: "Neutral", 3: "Positive", 4: "Very Positive"}
|
108 |
+
return [sentiment_map[p] for p in torch.argmax(probabilities, dim=-1).tolist()]
|
109 |
|
110 |
texts = [
|
111 |
# English
|
112 |
+
"I absolutely love the new design of this app!", "The customer service was disappointing.", "The weather is fine, nothing special.",
|
|
|
113 |
# Chinese
|
114 |
+
"这家餐厅的菜味道非常棒!", "我对他的回答很失望。", "天气今天一般。",
|
|
|
115 |
# Spanish
|
116 |
+
"¡Me encanta cómo quedó la decoración!", "El servicio fue terrible y muy lento.", "El libro estuvo más o menos.",
|
|
|
117 |
# Arabic
|
118 |
+
"الخدمة في هذا الفندق رائعة جدًا!", "لم يعجبني الطعام في هذا المطعم.", "كانت الرحلة عادية。",
|
|
|
119 |
# Ukrainian
|
120 |
+
"Мені дуже сподобалася ця вистава!", "Обслуговування було жахливим.", "Книга була посередньою。",
|
|
|
121 |
# Hindi
|
122 |
+
"यह जगह सच में अद्भुत है!", "यह अनुभव बहुत खराब था।", "फिल्म ठीक-ठाक थी।",
|
|
|
123 |
# Bengali
|
124 |
+
"এখানকার পরিবেশ অসাধারণ!", "সেবার মান একেবারেই খারাপ।", "খাবারটা মোটামুটি ছিল।",
|
|
|
125 |
# Portuguese
|
126 |
+
"Este livro é fantástico! Eu aprendi muitas coisas novas e inspiradoras.",
|
127 |
+
"Não gostei do produto, veio quebrado.", "O filme foi ok, nada de especial.",
|
128 |
+
# Japanese
|
129 |
+
"このレストランの料理は本当に美味しいです!", "このホテルのサービスはがっかりしました。", "天気はまあまあです。",
|
130 |
+
# Russian
|
131 |
+
"Я в восторге от этого нового гаджета!", "Этот сервис оставил у меня только разочарование.", "Встреча была обычной, ничего особенного.",
|
132 |
+
# French
|
133 |
+
"J'adore ce restaurant, c'est excellent !", "L'attente était trop longue et frustrante.", "Le film était moyen, sans plus.",
|
134 |
+
# Turkish
|
135 |
+
"Bu otelin manzarasına bayıldım!", "Ürün tam bir hayal kırıklığıydı.", "Konser fena değildi, ortalamaydı.",
|
136 |
+
# Italian
|
137 |
+
"Adoro questo posto, è fantastico!", "Il servizio clienti è stato pessimo.", "La cena era nella media.",
|
138 |
+
# Polish
|
139 |
+
"Uwielbiam tę restaurację, jedzenie jest świetne!", "Obsługa klienta była rozczarowująca.", "Pogoda jest w porządku, nic szczególnego.",
|
140 |
+
# Tagalog
|
141 |
+
"Ang ganda ng lugar na ito, sobrang aliwalas!", "Hindi maganda ang serbisyo nila dito.", "Maayos lang ang palabas, walang espesyal.",
|
142 |
+
# Dutch
|
143 |
+
"Ik ben echt blij met mijn nieuwe aankoop!", "De klantenservice was echt slecht.", "De presentatie was gewoon oké, niet bijzonder.",
|
144 |
+
# Malay
|
145 |
+
"Saya suka makanan di sini, sangat sedap!", "Pengalaman ini sangat mengecewakan.", "Hari ini cuacanya biasa sahaja.",
|
146 |
+
# Korean
|
147 |
+
"이 가게의 케이크는 정말 맛있어요!", "서비스가 너무 별로였어요.", "날씨가 그저 그렇네요.",
|
148 |
+
# Swiss German
|
149 |
+
"Ich find dä Service i de Beiz mega guet!", "Däs Esä het mir nöd gfalle.", "D Wätter hüt isch so naja."
|
150 |
]
|
151 |
|
152 |
+
for text, sentiment in zip(texts, predict_sentiment(texts)):
|
153 |
+
print(f"Text: {text}\nSentiment: {sentiment}\n")
|
|
|
|
|
154 |
```
|
155 |
|
156 |
## Ethical Considerations
|