Update README.md
Browse files
README.md
CHANGED
|
@@ -4,69 +4,108 @@ language:
|
|
| 4 |
- bn
|
| 5 |
metrics:
|
| 6 |
- f1
|
|
|
|
|
|
|
| 7 |
base_model:
|
| 8 |
- csebuetnlp/banglabert_small
|
| 9 |
pipeline_tag: text-classification
|
| 10 |
library_name: transformers
|
| 11 |
tags:
|
| 12 |
-
- bangla
|
| 13 |
- sentiment-analysis
|
| 14 |
- sarcasm-detection
|
|
|
|
|
|
|
|
|
|
| 15 |
---
|
| 16 |
|
| 17 |
-
#
|
| 18 |
|
| 19 |
-
|
| 20 |
|
| 21 |
-
|
|
|
|
| 22 |
|
| 23 |
-
|
| 24 |
|
| 25 |
-
|
|
|
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
- **Multilabel Stratified K-Fold Cross-Validation**: Ensures reliable model evaluation.
|
| 31 |
-
- **Interactive Gradio Interface**: Provides real-time predictions and user interaction.
|
| 32 |
-
- **Open Source**: Publicly available [code and dataset](https://github.com/ahs95/sentiment-analysis-cwcbd23) for reproducibility and further research.
|
| 33 |
|
| 34 |
-
|
|
|
|
|
|
|
| 35 |
|
| 36 |
-
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
- **Labels**:
|
| 41 |
-
- **Sentiment**: Positive / Negative / Neutral
|
| 42 |
-
- **Sarcasm**: Sarcastic / Non-sarcastic
|
| 43 |
|
| 44 |
-
|
|
|
|
|
|
|
| 45 |
|
| 46 |
-
|
| 47 |
-
- **Custom Head**: Dual-output head for multi-task classification.
|
| 48 |
-
- **Loss Function**: Combined focal loss for both tasks.
|
| 49 |
-
- **Training Strategy**: Multilabel stratified k-fold cross-validation to enhance model performance and reliability.
|
| 50 |
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
-
|
| 54 |
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
```
|
| 59 |
|
| 60 |
-
|
| 61 |
-
```python
|
| 62 |
-
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
| 63 |
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
- bn
|
| 5 |
metrics:
|
| 6 |
- f1
|
| 7 |
+
- precision
|
| 8 |
+
- recall
|
| 9 |
base_model:
|
| 10 |
- csebuetnlp/banglabert_small
|
| 11 |
pipeline_tag: text-classification
|
| 12 |
library_name: transformers
|
| 13 |
tags:
|
| 14 |
+
- bangla
|
| 15 |
- sentiment-analysis
|
| 16 |
- sarcasm-detection
|
| 17 |
+
- low-resource
|
| 18 |
+
- sports-analytics
|
| 19 |
+
- social-media
|
| 20 |
---
|
| 21 |
|
| 22 |
+
# BanglaBERT Dual-Head Model for Sentiment and Sarcasm Detection
|
| 23 |
|
| 24 |
+
## Overview
|
| 25 |
|
| 26 |
+
This repository contains a **fine-tuned BanglaBERT model** for **dual-head multi-label classification** — detecting both **sentiment** (positive, neutral, negative) and **sarcasm** (sarcastic, non-sarcastic) in Bangla social media text.
|
| 27 |
+
The model is designed for **low-resource NLP** and is trained on a manually annotated dataset of **5,635 Bangla Facebook and YouTube comments** related to Bangladesh’s performance in the **2023 ICC Cricket World Cup**.
|
| 28 |
|
| 29 |
+
## Model Architecture
|
| 30 |
|
| 31 |
+
* **Base Model:** [csebuetnlp/banglabert_small](https://huggingface.co/csebuetnlp/banglabert_small)
|
| 32 |
+
* **Architecture:** Transformer-based dual-head classification
|
| 33 |
|
| 34 |
+
* Head 1 → Sentiment Classification (3 classes)
|
| 35 |
+
* Head 2 → Sarcasm Detection (2 classes)
|
| 36 |
+
* **Training Techniques:**
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
+
* Focal Loss with class weighting to handle **severe data imbalance**
|
| 39 |
+
* Multilabel stratified K-fold cross-validation
|
| 40 |
+
* Domain-specific data preprocessing for Bangla text
|
| 41 |
|
| 42 |
+
## Dataset
|
| 43 |
|
| 44 |
+
* **Size:** 5,635 manually annotated comments
|
| 45 |
+
* **Labels:**
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
+
* Sentiment: Positive, Neutral, Negative
|
| 48 |
+
* Sarcasm: Sarcastic, Non-Sarcastic
|
| 49 |
+
* **Source:** Publicly available Facebook & YouTube comments (2023 ICC Cricket World Cup)
|
| 50 |
|
| 51 |
+
## Performance
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
+
| Task | Weighted F1 | Class-wise F1 (Minority) | Class-wise F1 (Majority) |
|
| 54 |
+
| ----------------- | ----------- | ----------------------------- | ------------------------ |
|
| 55 |
+
| Sentiment | **0.89** | Neutral: 0.69, Positive: 0.73 | Negative: 0.96 |
|
| 56 |
+
| Sarcasm Detection | **0.84** | Sarcastic: 0.60 | Non-Sarcastic: 0.91 |
|
| 57 |
|
| 58 |
+
**Key Gains:**
|
| 59 |
|
| 60 |
+
* +0.20 F1 improvement for Neutral sentiment
|
| 61 |
+
* +0.18 F1 improvement for Sarcastic content
|
| 62 |
+
* Attributed to focal loss + inverse class weighting
|
|
|
|
| 63 |
|
| 64 |
+
## Example Usage
|
|
|
|
|
|
|
| 65 |
|
| 66 |
+
```python
|
| 67 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 68 |
+
import torch
|
| 69 |
|
| 70 |
+
# Load tokenizer and model
|
| 71 |
+
tokenizer = AutoTokenizer.from_pretrained("your-username/banglabert-sentiment-sarcasm")
|
| 72 |
+
model = AutoModelForSequenceClassification.from_pretrained("your-username/banglabert-sentiment-sarcasm")
|
| 73 |
+
|
| 74 |
+
# Example Bangla text
|
| 75 |
+
text = "শিক্ষা সফর 2023 বাংলাদেশ টু ইন্ডিয়া সফল হোক"
|
| 76 |
+
|
| 77 |
+
# Tokenize
|
| 78 |
+
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
|
| 79 |
+
|
| 80 |
+
# Predict
|
| 81 |
+
with torch.no_grad():
|
| 82 |
+
outputs = model(**inputs)
|
| 83 |
+
|
| 84 |
+
# Raw logits
|
| 85 |
+
print(outputs.logits)
|
| 86 |
+
```
|
| 87 |
+
|
| 88 |
+
## Intended Use
|
| 89 |
+
|
| 90 |
+
* **Sports analytics:** Track fan sentiment and sarcasm during live matches
|
| 91 |
+
* **Social media monitoring:** Identify sarcastic backlash and emotional trends
|
| 92 |
+
* **Brand reputation analysis:** Understand nuanced customer feedback in Bangla
|
| 93 |
+
|
| 94 |
+
## Limitations
|
| 95 |
+
|
| 96 |
+
* Domain-specific: Trained on cricket-related data; performance may drop in other contexts
|
| 97 |
+
* Context sensitivity: Some sarcasm requires cultural or multimodal cues (e.g., emojis)
|
| 98 |
+
* Not suitable for toxic speech moderation without additional fine-tuning
|
| 99 |
+
|
| 100 |
+
## Citation
|
| 101 |
+
|
| 102 |
+
If you use this model in your work, please cite:
|
| 103 |
+
|
| 104 |
+
@misc{hoque2025banglabertsentimentsarcasm,
|
| 105 |
+
author = {Arshadul Hoque, Nasrin Sultana, Risul Islam Rasel},
|
| 106 |
+
title = {Bangla Sentiment and Sarcasm Detection: Reactions to Bangladesh's 2023 World Cup},
|
| 107 |
+
note = {Manuscript under review},
|
| 108 |
+
year = {2025},
|
| 109 |
+
publisher = {Hugging Face},
|
| 110 |
+
url = {https://huggingface.co/ahs95/sentiment-sarcasm-detection-BanglaBERT}
|
| 111 |
+
}
|