Technical case study
Tweet Sentiment Classification
A Kaggle notebook explores tweet labels and implements a TensorFlow classifier that combines one-dimensional convolutions with a bidirectional LSTM.
Overview
This notebook takes labeled tweets through exploratory analysis, text preprocessing, and the implementation of a sequence model for positive, negative, and neutral sentiment.
Problem
Short texts often contain few clues about sentiment. Word order and context can change the meaning of words that appear in more than one class.
Objective
Implement a three-class classifier and define an evaluation workflow for how it handles labeled tweets.
My approach
I visualized the label distribution, explored a bag-of-words representation, then used padded token sequences to preserve word order for the neural classifier.
Technology stack
- Python
- TensorFlow
- Keras
- scikit-learn
- Pandas
- Plotly
Architecture
-
Labeled tweets
Load text and sentiment labels, drop missing rows, and inspect class frequencies.
-
Sequence preparation
Convert text to token IDs and use fixed-length sequences of 50 tokens.
-
Local features
Pass learned embeddings through a one-dimensional convolution and pooling layer.
-
Sequence context
Use a bidirectional LSTM to read the features in both directions.
-
Sentiment
Predict a distribution over positive, negative, and neutral labels with a softmax output.
-
Evaluation
Compare training and validation curves and define accuracy, precision, recall, and F1 reporting for the test split.
Key engineering decisions
- Use convolution for short text patterns and a bidirectional recurrent layer for sequence context.
- Include a neutral label so the model can represent posts without a clear positive or negative sentiment.
Implementation details
- Explore class counts and word frequencies before preparing model inputs.
- Serialize the tokenizer so it can be reused with the same vocabulary.
- Use separate training, validation, and test splits for the sequence model.
Results and limitations
The public notebook export contains the evaluation code. It does not contain saved metric outputs. The tokenizer is fitted before splitting the data, so a stricter evaluation would fit the vocabulary on training text only.
Lessons learned
Text preprocessing belongs inside the train-test boundary. Inspect class-level errors when evaluating a classifier with a neutral category.