Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

Sarcasm Detection NLP Project

This project demonstrates a complete Natural Language Processing (NLP) pipeline for detecting sarcasm in text headlines. It compares traditional machine learning approaches using different text vectorization techniques: TF-IDF with unigrams vs. N-grams (bigrams and trigrams) with CountVectorizer.

Project Structure

  • sarcasm_detection.ipynb: The main Jupyter Notebook containing the code, analysis, and visualizations.
  • sarcasm.json: A JSON dataset containing headlines and their sarcasm labels (0 for non-sarcastic, 1 for sarcastic).

Installation

To run this notebook, you need Python installed along with the following libraries:

pip install pandas numpy scikit-learn matplotlib seaborn

All required libraries are part of the standard data science stack - no additional dependencies needed!

Usage

  1. Clone this repository.
  2. Ensure sarcasm.json is in the same directory as the notebook (or update the path in the notebook).
  3. Open sarcasm_detection.ipynb in Jupyter Notebook, JupyterLab, or VS Code.
  4. Run all cells to execute the pipeline.

Features

  • Data Exploration: Distribution of classes, class balance analysis.
  • Preprocessing: Text cleaning, lowercasing, punctuation removal.
  • Vectorization:
    • TF-IDF (Term Frequency - Inverse Document Frequency) with unigrams
    • CountVectorizer with N-grams (unigrams, bigrams, and trigrams)
  • Modeling:
    • Logistic Regression
    • Support Vector Machine (SVM)
    • Random Forest
  • Evaluation: Accuracy score, Confusion Matrix, Classification Report.

Key Insights

  • N-grams capture word sequences and phrase patterns (e.g., "yeah right", "oh great")
  • Simple methods can be very effective for sarcasm detection
  • No need for complex deep learning models for good baseline performance

Future Improvements

  • Add character n-grams to capture spelling patterns and informal language
  • Implement feature engineering (sentiment scores, punctuation patterns, capitalization)
  • Use pre-trained embeddings (GloVe, FastText) for semantic understanding
  • Try ensemble methods combining multiple models
  • Experiment with deep learning approaches (LSTM, Transformers) for comparison

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages