Skip to content

laavanjan/sarcasm_headline_classifier_bert_pytorch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

Sarcasm Detection in News Headlines using BERT and PyTorch

This project implements a sarcasm detection model for news headlines using a BERT-based architecture with PyTorch. The dataset is sourced from Kaggle and the workflow is organized in a Jupyter notebook.

Table of Contents

Overview

This notebook demonstrates how to classify news headlines as sarcastic or not using a fine-tuned BERT model. The workflow includes data loading, preprocessing, model definition, training, evaluation, and visualization of results.

Dataset

Model Architecture

  • Base Model: BERT (google-bert/bert-base-uncased from HuggingFace Transformers)
  • Custom Layers:
    • Dropout
    • Linear layers (768→384→1)
    • Sigmoid activation for binary classification
  • Frozen BERT: Only the custom layers are trained; BERT parameters are frozen.

Training Details

  • Loss Function: Binary Cross Entropy Loss (BCELoss)
  • Optimizer: Adam
  • Batch Size: 32
  • Epochs: 10
  • Learning Rate: 1e-4
  • Data Split: 70% train, 15% validation, 15% test

Results & Visualization

  • Training and validation loss/accuracy are tracked and plotted over epochs.
  • Final test accuracy is reported.

How to Run

  1. Clone the repository and open the notebook in Jupyter or VS Code.
  2. Ensure you have Python 3.7+ and install the required packages:
    pip install torch transformers opendatasets scikit-learn matplotlib pandas numpy
  3. Run all cells in the notebook. The dataset will be downloaded automatically.

Requirements

  • Python 3.7+
  • torch
  • transformers
  • opendatasets
  • scikit-learn
  • matplotlib
  • pandas
  • numpy

References


Feel free to use or modify this project for your own sarcasm detection or NLP experiments!

About

This project implements a sarcasm detection model for news headlines using a BERT-based architecture with PyTorch.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors