Skip to content

About

Bangla sentiment analysis (negative / neutral / positive) using multilingual BERT embeddings and an LSTM classifier in PyTorch.

Topics

Resources

Stars

0 stars

Watchers

2 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

Bangla Sentiment Analysis with BERT Embeddings + LSTM

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

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.

Pipeline

  1. Load and encode labels. Read the Excel file and map labels to negative → 0, positive → 1, neutral → 2.
  2. BERT embeddings. Pass each text through bert-base-multilingual-uncased and mean-pool the last hidden state into a 768-dimensional vector.
  3. Split. Stratified 70% train / 15% test / 15% validation (random_state=42).
  4. 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
  5. Evaluation. Confusion matrix, per-class F1 and micro/macro/weighted F1 on the held-out split.

Project structure

├── Dataset-Sentiment Analysis.xlsx   # Labelled Bangla dataset
├── Sentiment_analysis_LSTM.py        # Full pipeline (exported from Google Colab)
└── README.md

Getting started

Requirements

  • 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/normalizer

Run

git clone https://github.com/intesurahmed/Sentiment_Analysis.git
cd Sentiment_Analysis
python Sentiment_analysis_LSTM.py

The 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).

Output

  • 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

Limitations and future work

  • 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.

Author

Intesur Ahmed: GitHub

About

Bangla sentiment analysis (negative / neutral / positive) using multilingual BERT embeddings and an LSTM classifier in PyTorch.

Topics

Resources

Stars

0 stars

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages