Downloads · 30 days
16
6% of all-time downloads
bhattaraisuman/nepali-sentiment-mbert
nepali-sentiment-mbert is a machine learning model from bhattaraisuman. Use it for the machine learning task on the model card, and read the license before you ship it in a product. The card lists the license as apache-2.0.
This model is fine-tuned bert-base-multilingual-cased for sentiment analysis on Nepali text. It classifies sentences into Negative (0), Neutral (1), or Positive (2) sentiments.
Downloads · 30 days
16
6% of all-time downloads
All-time downloads
250
Public
Parameters
178M
711 MB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors711 MB · 99%
From the Hugging Face model README
This model is fine-tuned bert-base-multilingual-cased for sentiment analysis on Nepali text. It classifies sentences into Negative (0), Neutral (1), or Positive (2) sentiments.
from transformers import pipeline
classifier = pipeline(
"text-classification",
model="bhattaraisuman/nepali-sentiment-mbert"
)
results = classifier("यो धेरै राम्रो छ!")
print(results)
# [{'label': 'LABEL_2', 'score': 0.95}]
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
# Load model and tokenizer
tokenizer = AutoTokenizer.from_pretrained("bhattaraisuman/nepali-sentiment-mbert")
model = AutoModelForSequenceClassification.from_pretrained("bhattaraisuman/nepali-sentiment-mbert")
# Input text
text = "तपाईंको परियोजना राम्रो छ"
# Tokenize the text
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True, max_length=256)
# Get predictions
with torch.no_grad():
outputs = model(**inputs)
predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
# Get results
predicted_class = predictions.argmax().item()
confidence = predictions.max().item()
# Map to sentiment labels
sentiments = ['Negative', 'Neutral', 'Positive']
print(f"Text: {text}")
print(f"Sentiment: {sentiments[predicted_class]}")
print(f"Confidence: {confidence:.2%}")
# Optional: See probabilities for all classes
print("\nAll probabilities:")
for i, prob in enumerate(predictions[0]):
print(f" {sentiments[i]}: {prob:.2%}")