Three-class sentiment classification (negative / neutral / positive) of Bangla (Bengali) customer conversation text about financial services. Sentence embeddings come from multilingual BERT and are classified by a 2-layer LSTM in PyTorch.
Dataset-Sentiment Analysis.xlsx has 99 labelled Bangla text samples. Company and bank names are anonymised as company_x, bank_y and so on.
| Column | Description |
|---|---|
conversation_text |
Bangla text of the customer conversation or post |
sentiment |
negative, neutral or positive |
Class distribution: neutral 45, negative 42, positive 12. The classes are imbalanced, with few positive samples.
- Load and encode labels. Read the Excel file and map labels to
negative → 0,positive → 1,neutral → 2. - BERT embeddings. Pass each text through
bert-base-multilingual-uncasedand mean-pool the last hidden state into a 768-dimensional vector. - Split. Stratified 70% train / 15% test / 15% validation (
random_state=42). - LSTM classifier.
- Input: 768-dim embedding (treated as a sequence of length 1)
- 2 LSTM layers, hidden size 128, dropout 0.2
- Fully connected layer → LogSoftmax over 3 classes
- Adam optimizer (lr = 0.001), cross-entropy loss, 50 epochs
- Evaluation. Confusion matrix, per-class F1 and micro/macro/weighted F1 on the held-out split.
├── Dataset-Sentiment Analysis.xlsx # Labelled Bangla dataset
├── Sentiment_analysis_LSTM.py # Full pipeline (exported from Google Colab)
└── README.md
- Python 3.8+
- PyTorch
- Hugging Face Transformers
- pandas, numpy, scikit-learn, matplotlib, openpyxl, nltk
normalizer(Bangla text normalizer from BUET CSE NLP)
pip install torch transformers pandas numpy scikit-learn matplotlib openpyxl nltk
pip install git+https://github.com/csebuetnlp/normalizergit clone https://github.com/intesurahmed/Sentiment_Analysis.git
cd Sentiment_Analysis
python Sentiment_analysis_LSTM.pyThe script was exported from a Google Colab notebook. Running it cell by cell in Jupyter or Colab is the easiest way to see the plots (class distribution and confusion matrix).
- Bar chart of the sentiment class distribution
- Training and validation loss for each epoch
- Confusion matrix on the held-out split
- Per-class F1 scores, plus micro, macro and weighted average F1
- The dataset is very small (99 samples), and the positive class is underrepresented. Results should be treated as a proof of concept.
- Each text is reduced to one pooled vector, so the LSTM sees a sequence of length 1. Feeding token-level BERT outputs to the LSTM, or fine-tuning a Bangla-specific model such as BanglaBERT, would likely work better.
- Possible next steps: class weighting or oversampling, mini-batch training, early stopping, and a larger dataset.
Intesur Ahmed: GitHub