Skip to content
All work

Case study

Sarcasm Detection Model

NLP classifier for detecting sarcasm and tone in short-form text.

Role
Sole author
Domain
Machine Learning & Data Science
Stack
Python · scikit-learn · pandas · TensorFlow
Result
85% held-out test accuracy
Still: short text samples classified as sarcastic or sincere with model confidence.

Overview

A bidirectional LSTM that classifies news headlines as sarcastic or sincere, built for a hackathon. Sarcasm is hard precisely because the words say one thing and mean another.

Why headlines

Most sarcasm datasets come from social media, labelled by hashtags — noisy labels, and many posts are replies that need their conversation to make sense. A dataset of satirical and genuine news headlines avoids both: each headline stands alone, and the label comes from where it was published.

Pipeline

  1. Clean

    Lowercase, expand contractions, strip punctuation, lemmatise.

  2. Encode

    Tokenise, pad to the longest headline, map to pretrained GloVe vectors, kept frozen.

  3. Model

    A bidirectional LSTM reads each headline both ways; global max pooling keeps the strongest signal.

  4. Classify

    Two dense layers with heavy dropout, then a single sigmoid output.

  5. Train

    Early stopping and learning-rate reduction on a validation split.

Evaluation

Split
80/20 train/test, with validation carved from training.
Baseline
Classes are near-balanced, so always guessing the majority scores roughly half.
Balance
Precision and recall land within a point of each other on both classes — the accuracy is not bought by favouring one.

My Role

Role

Sole author

Contribution

  • Built the dataset processing and feature pipeline
  • Trained and evaluated the classification models

Results

85%

held-out test accuracy

Limits

The label is which site published the headline, so the model can learn a publication's style as well as sarcasm itself — it has never been tested on headlines from anywhere else. Results come from a single random split, not cross-validation, and training accuracy runs a few points above validation, a mild overfit. On review I also found the 50-dimension embeddings were tiled four times to fill a 200-dimension layer, which adds size without adding information.

What I'd Improve

  • Use embeddings at their native size instead of tiling them. First fix, and a one-line change.
  • Test on headlines from other publications, to see whether it learned sarcasm or a house style.
  • Cross-validate, and compare against a fine-tuned transformer as the obvious stronger baseline.