Skip to content

About

GitHub repository documenting a deep learning text classification pipeline with BiLSTM, including preprocessing code, training script and example predictions.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

Β 

History

6 Commits

Folders and files

Repository files navigation

🧠 Deep NLP: BiLSTM Text Classification on Custom Dataset

Python TensorFlow Keras Kaggle License

An end-to-end deep NLP pipeline for text classification using Bidirectional LSTM.

Covers text cleaning, tokenization, sequence modeling, evaluation, and custom inference.

Open in Kaggle


πŸ“Œ Table of Contents


🧠 Overview

This project builds a complete deep learning NLP pipeline to classify text responses from a custom dataset. Unlike traditional ML approaches, this project leverages a Bidirectional LSTM (BiLSTM) to capture contextual information from both directions of a text sequence β€” leading to richer and more accurate representations.

Key highlights:

  • Full text preprocessing pipeline (cleaning, tokenization, padding)
  • BiLSTM model trained with TensorFlow/Keras
  • Evaluation with accuracy, precision, recall, F1-score & confusion matrix
  • Predict labels on brand-new custom text inputs
  • Full experiment available as a Kaggle Notebook

πŸ›  Tech Stack

Category Tools
Language Python 3.8+
Deep Learning TensorFlow, Keras (BiLSTM, Embedding, Dense, Dropout)
Data Handling pandas, numpy
ML Utilities scikit-learn (split, metrics)
Visualization matplotlib, seaborn
Environment Kaggle Notebook, Jupyter, VS Code

πŸ“‚ Dataset

Field Description
File Sheet_1.csv
response_text Raw input text response
class Target label β€” flagged or not_flagged
Split 80% Train / 20% Validation (stratified)

Unused columns like Unnamed: ... are automatically dropped during preprocessing.


πŸ—‚ Project Structure

deep-nlp-text-classification-bilstm/
β”‚
β”œβ”€β”€ πŸ““ deep_nlp_bilstm.ipynb       # Main notebook: preprocessing, training & evaluation
β”œβ”€β”€ πŸ“Š Sheet_1.csv                  # Custom dataset (text responses + labels)
β”œβ”€β”€ πŸ€– bilstm_model.h5              # Saved trained BiLSTM model
β”œβ”€β”€ πŸ”€ tokenizer.pkl                # Saved Keras tokenizer
β”œβ”€β”€ πŸš€ predict.py                   # Script for inference on new text
β”œβ”€β”€ πŸ“‹ requirements.txt             # Python dependencies
└── πŸ“„ README.md                    # Project documentation

βš™οΈ NLP Pipeline

Raw Text (response_text)
        β”‚
        β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚      Text Preprocessing      β”‚
β”‚  β€’ Lowercase                 β”‚
β”‚  β€’ Remove URLs & @mentions   β”‚
β”‚  β€’ Remove special characters β”‚
β”‚  β€’ Strip extra whitespace    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
        β”‚
        β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Tokenization & Padding     β”‚
β”‚  β€’ Vocab size: 20,000 words  β”‚
β”‚  β€’ Convert text β†’ sequences  β”‚
β”‚  β€’ Pad to fixed max length   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
        β”‚
        β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚     BiLSTM Neural Network    β”‚
β”‚  β€’ Embedding Layer           β”‚
β”‚  β€’ Bidirectional LSTM        β”‚
β”‚  β€’ Dense + Dropout           β”‚
β”‚  β€’ Sigmoid / Softmax output  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
        β”‚
        β–Ό
   Prediction + Confidence
   (flagged / not_flagged)

πŸ— Model Architecture

_________________________________________________________________
Layer (type)             Output Shape          Param #
=================================================================
Embedding                (None, max_len, 128)  2,560,000
Bidirectional LSTM       (None, 256)           263,168
Dropout (0.5)            (None, 256)           0
Dense (64, ReLU)         (None, 64)            16,448
Dropout (0.3)            (None, 64)            0
Dense (1, Sigmoid)       (None, 1)             65
=================================================================
Hyperparameter Value
Vocabulary Size 20,000
Embedding Dim 128
LSTM Units 128 (Γ— 2 bidirectional)
Optimizer Adam
Loss Binary Crossentropy
Epochs ~10
Batch Size 32

πŸš€ Getting Started

1. Clone the Repository

git clone https://github.com/Musawir456/Deep-NLP-Text-Classifier-BiLSTM-.git
cd Deep-NLP-Text-Classifier-BiLSTM-

2. (Optional) Create a Virtual Environment

python -m venv venv
# Windows
venv\Scripts\activate
# macOS/Linux
source venv/bin/activate

3. Install Dependencies

pip install -r requirements.txt

4. Run the Notebook

jupyter notebook deep_nlp_bilstm.ipynb

5. Or Open Directly on Kaggle

Open in Kaggle


πŸ“ˆ Model Performance

Metric Score
Accuracy ~XX%
Precision ~XX%
Recall ~XX%
F1-Score ~XX%

πŸ“ Update this table with your actual results after training.


πŸ’‘ Custom Inference

Run predictions on any new text:

import pickle
import numpy as np
from tensorflow.keras.models import load_model
from tensorflow.keras.preprocessing.sequence import pad_sequences

# Load model and tokenizer
model = load_model("bilstm_model.h5")
with open("tokenizer.pkl", "rb") as f:
    tokenizer = pickle.load(f)

MAX_LEN = 100  # same as training

def predict(text):
    seq = tokenizer.texts_to_sequences([text])
    padded = pad_sequences(seq, maxlen=MAX_LEN, padding='post')
    prob = model.predict(padded)[0][0]
    label = "🚩 flagged" if prob >= 0.5 else "βœ… not_flagged"
    print(f"Prediction : {label}")
    print(f"Confidence : {prob:.4f}")

predict("Your custom text goes here...")

πŸ‘¨β€πŸ’» Author

Abdul Musawir AI/ML Engineer & Data Scientist πŸ“ Lahore, Pakistan

LinkedIn GitHub Kaggle


⭐ If you found this project helpful, please give it a star! ⭐

Made with ❀️ by Abdul Musawir

About

GitHub repository documenting a deep learning text classification pipeline with BiLSTM, including preprocessing code, training script and example predictions.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages