This model is a fine-tuned version of
csebuetnlp/banglabert on the
SentiGOLD dataset for 5-class sentiment analysis in Bengali. It classifies text into:
1from transformers import pipeline
2from normalizer import normalize
3
4# Load model
5classifier = pipeline(
6 "text-classification",
7 model="ahs95/banglabert-sentiment-analysis",
8 tokenizer="ahs95/banglabert-sentiment-analysis"
9)
10
11# Prepare text
12text = "আপনার পণ্যটি অসাধারণ! আমি খুবই সন্তুষ্ট।"
13normalized_text = normalize(text) # Important for BanglaBERT
14
15# Classify
16result = classifier(normalized_text)
17print(f"Sentiment: {result[0]['label']} (Confidence: {result[0]['score']:.2f})")
1
2from transformers import AutoTokenizer, AutoModelForSequenceClassification
3import torch
4from normalizer import normalize
5
6# Load model and tokenizer
7model_name = "ahs95/banglabert-sentiment-analysis"
8tokenizer = AutoTokenizer.from_pretrained(model_name)
9model = AutoModelForSequenceClassification.from_pretrained(model_name)
10
11# Prepare inputs
12texts = [
13 "সেবা খুব খারাপ ছিল। আমি কখনো ফিরে আসব না।",
14 "পণ্যটির গুণগত মান মোটামুটি ভাল"
15]
16normalized_texts = [normalize(t) for t in texts]
17
18# Tokenize and predict
19inputs = tokenizer(normalized_texts, padding=True, truncation=True, return_tensors="pt")
20with torch.no_grad():
21 outputs = model(**inputs)
22 probabilities = torch.nn.functional.softmax(outputs.logits, dim=-1)
23
24# Get predictions
25sentiment_labels = ["Very Negative", "Negative", "Neutral", "Positive", "Very Positive"]
26predictions = [sentiment_labels[p] for p in probabilities.argmax(dim=1)]
27
28for text, pred in zip(texts, predictions):
29 print(f"Text: {text}\nPredicted Sentiment: {pred}\n")
-
Bias: While SentiGOLD reduces bias through synthetic data, real-world validation is recommended
-
Use Cases: Suitable for:
- Product feedback analysis
- Social media monitoring
- Market research
- Avoid: Critical decision systems without human oversight
1@misc{banglabert-sentiment,
2 author = {Arshadul Hoque},
3 title = {Fine-tuned BanglaBERT for Bengali Sentiment Analysis},
4 year = {2025},
5 publisher = {Hugging Face},
6 howpublished = {\url{https://huggingface.co/ahs95/banglabert-sentiment-analysis}}
7}
For questions and support:
ahsbd95@gmail.com