Arth_madhav commited on
Commit ·
434d3f4
1
Parent(s): e582172
stat
Browse files- README.md +145 -0
- confusion_matrices.png +0 -0
- experiment_summary.json +22 -0
- metrics_summary.json +108 -0
- model.pt +3 -0
- per_class_metrics.png +0 -0
- test_accuracy_comparison.png +0 -0
- training_curves.png +0 -0
README.md
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Hindi Sentiment Analysis Model
|
| 2 |
+
|
| 3 |
+
This repository contains a Hindi sentiment analysis model that can classify text into three categories: negative (neg), neutral (neu), and positive (pos). The model has been trained and evaluated using various BERT-based architectures, with XLM-RoBERTa showing the best performance.
|
| 4 |
+
|
| 5 |
+
## Model Performance
|
| 6 |
+
|
| 7 |
+
### Test Accuracy Comparison
|
| 8 |
+

|
| 9 |
+
|
| 10 |
+
Our extensive evaluation shows:
|
| 11 |
+
- XLM-RoBERTa: 81.3%
|
| 12 |
+
- mBERT: 76.5%
|
| 13 |
+
- Custom-BERT-Attention: 74.9%
|
| 14 |
+
- IndicBERT: 69.9%
|
| 15 |
+
|
| 16 |
+
### Detailed Results
|
| 17 |
+
|
| 18 |
+
#### Confusion Matrices
|
| 19 |
+

|
| 20 |
+
|
| 21 |
+
The confusion matrices show the prediction performance for each model:
|
| 22 |
+
- XLM-RoBERTa shows the strongest performance with 82.1% accuracy on positive class
|
| 23 |
+
- mBERT demonstrates balanced performance across classes
|
| 24 |
+
- Custom-BERT-Attention maintains consistent performance
|
| 25 |
+
- IndicBERT shows room for improvement in negative class detection
|
| 26 |
+
|
| 27 |
+
#### Per-class Metrics
|
| 28 |
+

|
| 29 |
+
|
| 30 |
+
The detailed per-class metrics show:
|
| 31 |
+
1. Precision:
|
| 32 |
+
- Positive class: Best performance across all models (~0.80-0.85)
|
| 33 |
+
- Neutral class: Consistent performance (~0.75-0.80)
|
| 34 |
+
- Negative class: More varied performance (~0.40-0.70)
|
| 35 |
+
|
| 36 |
+
2. Recall:
|
| 37 |
+
- Positive class: High recall across models (~0.85-0.90)
|
| 38 |
+
- Neutral class: Moderate recall (~0.65-0.85)
|
| 39 |
+
- Negative class: Lower but improving recall (~0.25-0.60)
|
| 40 |
+
|
| 41 |
+
3. F1-Score:
|
| 42 |
+
- Positive class: Best overall performance (~0.80-0.85)
|
| 43 |
+
- Neutral class: Good balance (~0.70-0.80)
|
| 44 |
+
- Negative class: Area for potential improvement (~0.30-0.65)
|
| 45 |
+
|
| 46 |
+
### Training Progress
|
| 47 |
+

|
| 48 |
+
|
| 49 |
+
The training graphs show:
|
| 50 |
+
- Consistent loss reduction across epochs
|
| 51 |
+
- Stable validation accuracy improvement
|
| 52 |
+
- No significant overfitting
|
| 53 |
+
- XLM-RoBERTa achieving the best validation accuracy
|
| 54 |
+
- Custom-BERT-Attention showing rapid initial learning
|
| 55 |
+
|
| 56 |
+
## Model Usage
|
| 57 |
+
|
| 58 |
+
```python
|
| 59 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
| 60 |
+
|
| 61 |
+
# Load the model and tokenizer
|
| 62 |
+
tokenizer = AutoTokenizer.from_pretrained("madhav112/hindi-sentiment-analysis")
|
| 63 |
+
model = AutoModelForSequenceClassification.from_pretrained("madhav112/hindi-sentiment-analysis")
|
| 64 |
+
|
| 65 |
+
# Example usage
|
| 66 |
+
text = "यह फिल्म बहुत अच्छी है"
|
| 67 |
+
inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True)
|
| 68 |
+
outputs = model(**inputs)
|
| 69 |
+
predictions = outputs.logits.argmax(-1)
|
| 70 |
+
```
|
| 71 |
+
|
| 72 |
+
## Model Architecture
|
| 73 |
+
|
| 74 |
+
The repository contains experiments with multiple BERT-based architectures:
|
| 75 |
+
1. XLM-RoBERTa (Best performing)
|
| 76 |
+
- Highest overall accuracy
|
| 77 |
+
- Best performance on positive sentiment
|
| 78 |
+
- Strong cross-lingual capabilities
|
| 79 |
+
|
| 80 |
+
2. mBERT
|
| 81 |
+
- Good balanced performance
|
| 82 |
+
- Strong on neutral class detection
|
| 83 |
+
- Consistent across all metrics
|
| 84 |
+
|
| 85 |
+
3. Custom-BERT-Attention
|
| 86 |
+
- Competitive performance
|
| 87 |
+
- Quick convergence during training
|
| 88 |
+
- Good precision on positive class
|
| 89 |
+
|
| 90 |
+
4. IndicBERT
|
| 91 |
+
- Baseline performance
|
| 92 |
+
- Room for improvement
|
| 93 |
+
- Better suited for specific Indian language tasks
|
| 94 |
+
|
| 95 |
+
## Dataset
|
| 96 |
+
|
| 97 |
+
The model was trained on a Hindi sentiment analysis dataset with three classes:
|
| 98 |
+
- Positive (pos)
|
| 99 |
+
- Neutral (neu)
|
| 100 |
+
- Negative (neg)
|
| 101 |
+
|
| 102 |
+
The confusion matrices show balanced class distribution and strong performance across categories.
|
| 103 |
+
|
| 104 |
+
## Training Details
|
| 105 |
+
|
| 106 |
+
The model was trained for 7 epochs with the following characteristics:
|
| 107 |
+
- Learning rate: Optimized for each architecture
|
| 108 |
+
- Batch size: Adjusted for optimal performance
|
| 109 |
+
- Validation split: Regular evaluation during training
|
| 110 |
+
- Early stopping: Monitored for best model selection
|
| 111 |
+
- Loss function: Cross-entropy loss
|
| 112 |
+
|
| 113 |
+
## Limitations
|
| 114 |
+
|
| 115 |
+
- Lower performance on negative sentiment detection compared to positive
|
| 116 |
+
- Neutral class classification shows moderate confusion with both positive and negative
|
| 117 |
+
- Performance may vary on domain-specific text
|
| 118 |
+
- Best suited for standard Hindi text; may have reduced performance on heavily colloquial or dialectal variations
|
| 119 |
+
|
| 120 |
+
## Citation
|
| 121 |
+
|
| 122 |
+
If you use this model in your research, please cite:
|
| 123 |
+
|
| 124 |
+
```bibtex
|
| 125 |
+
@misc{madhav2024hindisentiment,
|
| 126 |
+
author = {Madhav},
|
| 127 |
+
title = {Hindi Sentiment Analysis Model},
|
| 128 |
+
year = {2024},
|
| 129 |
+
publisher = {HuggingFace},
|
| 130 |
+
howpublished = {\url{https://huggingface.co/madhav112/hindi-sentiment-analysis}}
|
| 131 |
+
}
|
| 132 |
+
```
|
| 133 |
+
|
| 134 |
+
## Author
|
| 135 |
+
|
| 136 |
+
**Madhav**
|
| 137 |
+
- HuggingFace: [madhav](https://huggingface.co/madhav)
|
| 138 |
+
|
| 139 |
+
## License
|
| 140 |
+
|
| 141 |
+
This project is licensed under the MIT License - see the LICENSE file for details.
|
| 142 |
+
|
| 143 |
+
## Acknowledgments
|
| 144 |
+
|
| 145 |
+
Special thanks to the HuggingFace team and the open-source community for providing the tools and frameworks that made this model possible.
|
confusion_matrices.png
ADDED
|
experiment_summary.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"best_model": "XLM-RoBERTa",
|
| 3 |
+
"best_accuracy": 81.33333333333333,
|
| 4 |
+
"model_rankings": [
|
| 5 |
+
[
|
| 6 |
+
"XLM-RoBERTa",
|
| 7 |
+
81.33333333333333
|
| 8 |
+
],
|
| 9 |
+
[
|
| 10 |
+
"mBERT",
|
| 11 |
+
76.53333333333333
|
| 12 |
+
],
|
| 13 |
+
[
|
| 14 |
+
"Custom-BERT-Attention",
|
| 15 |
+
74.93333333333334
|
| 16 |
+
],
|
| 17 |
+
[
|
| 18 |
+
"IndicBERT",
|
| 19 |
+
69.86666666666666
|
| 20 |
+
]
|
| 21 |
+
]
|
| 22 |
+
}
|
metrics_summary.json
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"model_comparisons": {
|
| 3 |
+
"IndicBERT": {
|
| 4 |
+
"test_accuracy": 69.86666666666666,
|
| 5 |
+
"avg_precision": 0.6224180162184014,
|
| 6 |
+
"avg_recall": 0.5884580801343807,
|
| 7 |
+
"avg_f1": 0.593856658862321,
|
| 8 |
+
"per_class_metrics": {
|
| 9 |
+
"neg": {
|
| 10 |
+
"precision": 0.4,
|
| 11 |
+
"recall": 0.23076923076923078,
|
| 12 |
+
"f1-score": 0.29268292682926833,
|
| 13 |
+
"support": 52.0
|
| 14 |
+
},
|
| 15 |
+
"neu": {
|
| 16 |
+
"precision": 0.7709923664122137,
|
| 17 |
+
"recall": 0.6733333333333333,
|
| 18 |
+
"f1-score": 0.7188612099644129,
|
| 19 |
+
"support": 150.0
|
| 20 |
+
},
|
| 21 |
+
"pos": {
|
| 22 |
+
"precision": 0.6962616822429907,
|
| 23 |
+
"recall": 0.861271676300578,
|
| 24 |
+
"f1-score": 0.7700258397932817,
|
| 25 |
+
"support": 173.0
|
| 26 |
+
}
|
| 27 |
+
}
|
| 28 |
+
},
|
| 29 |
+
"mBERT": {
|
| 30 |
+
"test_accuracy": 76.53333333333333,
|
| 31 |
+
"avg_precision": 0.7711061102018549,
|
| 32 |
+
"avg_recall": 0.6763361493997332,
|
| 33 |
+
"avg_f1": 0.699825091252967,
|
| 34 |
+
"per_class_metrics": {
|
| 35 |
+
"neg": {
|
| 36 |
+
"precision": 0.7692307692307693,
|
| 37 |
+
"recall": 0.38461538461538464,
|
| 38 |
+
"f1-score": 0.5128205128205128,
|
| 39 |
+
"support": 52.0
|
| 40 |
+
},
|
| 41 |
+
"neu": {
|
| 42 |
+
"precision": 0.8085106382978723,
|
| 43 |
+
"recall": 0.76,
|
| 44 |
+
"f1-score": 0.7835051546391754,
|
| 45 |
+
"support": 150.0
|
| 46 |
+
},
|
| 47 |
+
"pos": {
|
| 48 |
+
"precision": 0.7355769230769231,
|
| 49 |
+
"recall": 0.884393063583815,
|
| 50 |
+
"f1-score": 0.8031496062992126,
|
| 51 |
+
"support": 173.0
|
| 52 |
+
}
|
| 53 |
+
}
|
| 54 |
+
},
|
| 55 |
+
"XLM-RoBERTa": {
|
| 56 |
+
"test_accuracy": 81.33333333333333,
|
| 57 |
+
"avg_precision": 0.8151709401709403,
|
| 58 |
+
"avg_recall": 0.7698423990909541,
|
| 59 |
+
"avg_f1": 0.7866802163819814,
|
| 60 |
+
"per_class_metrics": {
|
| 61 |
+
"neg": {
|
| 62 |
+
"precision": 0.8205128205128205,
|
| 63 |
+
"recall": 0.6153846153846154,
|
| 64 |
+
"f1-score": 0.7032967032967034,
|
| 65 |
+
"support": 52.0
|
| 66 |
+
},
|
| 67 |
+
"neu": {
|
| 68 |
+
"precision": 0.7797619047619048,
|
| 69 |
+
"recall": 0.8733333333333333,
|
| 70 |
+
"f1-score": 0.8238993710691823,
|
| 71 |
+
"support": 150.0
|
| 72 |
+
},
|
| 73 |
+
"pos": {
|
| 74 |
+
"precision": 0.8452380952380952,
|
| 75 |
+
"recall": 0.8208092485549133,
|
| 76 |
+
"f1-score": 0.8328445747800586,
|
| 77 |
+
"support": 173.0
|
| 78 |
+
}
|
| 79 |
+
}
|
| 80 |
+
},
|
| 81 |
+
"Custom-BERT-Attention": {
|
| 82 |
+
"test_accuracy": 74.93333333333334,
|
| 83 |
+
"avg_precision": 0.7866521381595728,
|
| 84 |
+
"avg_recall": 0.6839429870065707,
|
| 85 |
+
"avg_f1": 0.7130132766136565,
|
| 86 |
+
"per_class_metrics": {
|
| 87 |
+
"neg": {
|
| 88 |
+
"precision": 0.8620689655172413,
|
| 89 |
+
"recall": 0.4807692307692308,
|
| 90 |
+
"f1-score": 0.6172839506172839,
|
| 91 |
+
"support": 52.0
|
| 92 |
+
},
|
| 93 |
+
"neu": {
|
| 94 |
+
"precision": 0.7862595419847328,
|
| 95 |
+
"recall": 0.6866666666666666,
|
| 96 |
+
"f1-score": 0.7330960854092526,
|
| 97 |
+
"support": 150.0
|
| 98 |
+
},
|
| 99 |
+
"pos": {
|
| 100 |
+
"precision": 0.7116279069767442,
|
| 101 |
+
"recall": 0.884393063583815,
|
| 102 |
+
"f1-score": 0.7886597938144329,
|
| 103 |
+
"support": 173.0
|
| 104 |
+
}
|
| 105 |
+
}
|
| 106 |
+
}
|
| 107 |
+
}
|
| 108 |
+
}
|
model.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:98d8bfa806feff9ff73b70df4b0a5a474f6c63f799d389fdcbf9d7fb782d481e
|
| 3 |
+
size 1112250694
|
per_class_metrics.png
ADDED
|
test_accuracy_comparison.png
ADDED
|
training_curves.png
ADDED
|