Skip to content

DRJ-14/transformers-text-classification

Repository files navigation

Efficient Text Classification using Lightweight Transformer Models

Python NLP Transformers Machine Learning Jupyter

This project implements an efficient natural language processing (NLP) pipeline for supervised text classification using Transformer-based models. The focus is on practical text understanding, model efficiency, and reproducible ML experimentation, reflecting real-world applied machine learning systems.

The system demonstrates how pretrained Transformer models can be adapted and evaluated for multi-class text classification tasks using supervised learning.


Project Overview

Text classification is a fundamental NLP task used in applications such as notification filtering, content categorization, and user intent detection. This project explores Transformer-based text representations to learn semantic features from raw text and perform accurate classification.

The project emphasizes:

  • Efficient model selection
  • Clean preprocessing pipelines
  • Reproducible experimentation
  • Evaluation using standard machine learning metrics

Notebooks

  1. IMDB_text_classification.ipynb — Fine-tunes a Transformer model for IMDB sentiment classification and evaluates performance.
  2. tokenization_and_input_representation.ipynb — Shows subword tokenization, special tokens, padding/truncation, and attention masks.
  3. bert_model_size_and_memory_analysis.ipynb — Computes parameter counts and estimates model weight memory for Transformer checkpoints.
  4. bert_inference_memory_requirements.ipynb — Estimates inference-time memory needs (weights + activations/KV-cache) under FP32/FP16.
  5. NLP_tasks_with_Transformers.ipynb — Walkthrough of common NLP tasks supported by Transformer architectures and APIs.
  6. Transformers_Text_classification_with_BERT_bias.ipynb — Runs basic bias probing + error analysis patterns for text classification outputs.

Machine Learning Approach

The classification pipeline consists of the following steps:

  • Text ingestion and normalization
  • Tokenization using pretrained Transformer tokenizers
  • Feature representation using Transformer encoders
  • Supervised fine-tuning for text classification
  • Model evaluation using accuracy and F1-score

Lightweight Transformer variants are preferred to balance performance and inference efficiency, reflecting real-world deployment considerations.
This pipeline mirrors production-oriented NLP systems where trade-offs between accuracy, model size, and inference efficiency must be carefully evaluated.


Models and Techniques

  • Transformer-based language models (BERT / DistilBERT)
  • Tokenization and embedding generation
  • Supervised fine-tuning for sequence classification
  • Evaluation using standard classification metrics
  • Experimentation using notebook-based workflows

Technologies Used

  • Python
  • HuggingFace Transformers
  • TensorFlow and PyTorch (used across different experiments)
  • NumPy
  • scikit-learn
  • Jupyter Notebook
  • Git and GitHub

Dataset Description

The project operates on labeled text datasets suitable for supervised classification tasks. The datasets contain short to medium-length text samples with corresponding class labels.

Typical use cases include:

  • Message or notification categorization
  • Content or topic classification
  • Sentiment or intent classification

Datasets are split into training and evaluation sets to assess generalization performance.
Publicly available benchmark datasets are used to ensure reproducibility and objective evaluation.


Model Training and Evaluation

During training:

  • Pretrained Transformer models are fine-tuned on labeled text data
  • Performance is evaluated using accuracy and F1-score
  • Results are analyzed to understand trade-offs between model size and classification performance

This approach demonstrates practical experience with modern NLP pipelines, evaluation techniques, and efficiency-aware model design.


Key Highlights

  • Applied NLP project using Transformer-based models
  • Focus on efficiency and real-world usability
  • Clean, reproducible experimentation workflow
  • Strong alignment with applied machine learning and ML engineering roles

Future Enhancements

  • Model optimization through quantization or distillation
  • Inference benchmarking for latency and memory usage
  • Extension to multi-label classification tasks
  • Integration with downstream applications or services

Author

Developed as an independent applied machine learning project focused on NLP system design, Transformer-based models, and efficient text classification.

Releases

No releases published

Packages

 
 
 

Contributors