Code Monkey home page Code Monkey logo

deep-humor-generation-analysis-and-classification-of-humor-using-transformers's Introduction

Deep-Humor

Humor generation and classification is one the hardest problem in the area of computational Natural Language Understanding. Even humans fail at being funny and recognizing humor. In this project, we attempt to create a joke generator using a large pre-trained language model (GPT2). Further, we create jokes classifier by fine-tuning pre-trained (BERT) to classify the generated jokes and attempt to understand what distinguish joke sentence(s) from non joke sentence(s). Qualitative analysis reveals that the classifier model has specific internal attention patterns while classifying joke sentences which is absent when classifying normal sentences.

Model Architecture

Model Architecture

Attention analysis

For Non-joke sentence Non Joke Attention

For Joke sentences, there's a visible 'X' pattern which validates the setup-punchline structure.

Joke Attention

Detailed view of the Joke attention pattern -

detailed view

Software Requirements:

  1. Python: 3.7
  2. pytorch: 1.2.0
  3. Cuda 10.1.243

Some experiments were directly carried out in Google Colab

Pretrained models are from https://github.com/huggingface/transformers

GTP2/fine_tuning.py is mostly the huggingface's run_lm_finetuning.py except for the Dataset Class.

Run-GPT2-finetuning

python fine_tuning.py \
	--output_dir output \
	--model_type gpt2 \
	--model_name_or_path distilgpt2 \
	--do_train \
	--train_data_file short_jokes_even_shorter.csv \
	--per_gpu_train_batch_size 5 \
	--save_steps 1000 \
	--num_train_epochs 10

GPT2-get a sample output

python run_generation.py \
    --model_type=gpt2 \
    --model_name_or_path=output/ \
    --top_k 50 \
    --top_p 1.0 \
    --temperature 0.3 \
    --prompt "Why did jonh call the cops?"

An improved version is in the jupyter notebook along with the rest of the code for generation, analysis and classification.

BERT

Jupyter notebook is run on Google Collab, any extra package requried required is being included in the notebook itself.

deep-humor-generation-analysis-and-classification-of-humor-using-transformers's People

Contributors

adich23 avatar emiljoswin avatar gargraghav avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

viper-vm

deep-humor-generation-analysis-and-classification-of-humor-using-transformers's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.