A comprehensive machine learning pipeline designed to classify the sentiment of Twitter data using both traditional statistical methods and deep learning architectures.
- Project Timeline: September 2025
Twitter data is inherently noisy due to:
- Informal language
- Slang and abbreviations
- High noise-to-signal ratio
This project implements a full Natural Language Processing (NLP) pipeline—from raw data cleaning to advanced sequence modeling—to classify tweets into sentiment categories.
To handle noisy Twitter data, the following steps were applied:
-
Noise Removal
- Removed URLs, HTML tags, mentions (
@user), and special characters using Regex
- Removed URLs, HTML tags, mentions (
-
Stopword Removal
- Eliminated common words (e.g., the, is)
-
Tokenization & Lemmatization
- Converted text into tokens
- Reduced words to their base/root forms
Two approaches were used to represent text numerically:
-
TF-IDF (Term Frequency–Inverse Document Frequency)
- Captures importance of words across the dataset
-
Word Embeddings
- Dense vector representations capturing semantic meaning and context
- Baseline linear classifier
- Performs well with TF-IDF features
- Fast and interpretable
- A type of Recurrent Neural Network (RNN)
- Captures sequential dependencies in text
- Handles context and long-range relationships
Models were evaluated on balanced datasets using:
| Metric | Description |
|---|---|
| Precision | Measures correctness of positive predictions |
| Recall | Measures ability to find all positive samples |
| F1-Score | Harmonic mean of precision and recall |
- LSTM outperformed traditional methods in capturing nuanced sentiment
- Logistic Regression provided a strong and efficient baseline
- Python 3.10+
- TensorFlow / Keras
- Scikit-learn
- NLTK or SpaCy
git clone https://github.com/yourusername/twitter-sentiment-analysis.gitpip install -r requirements.txtpython src/models.py-
Preprocessing is critical (~80% of performance gains)
- Effective noise removal significantly improved model performance
-
Context Matters
- Word embeddings + LSTM outperform TF-IDF for:
- Sarcasm detection
- Multi-word sentiment patterns
- Word embeddings + LSTM outperform TF-IDF for:
This project demonstrates:
- End-to-end NLP pipeline design
- Handling noisy real-world text data
- Feature engineering for text classification
- Comparison of classical ML vs deep learning approaches
- Importance of contextual understanding in sentiment analysis