Automating Humor: A Novel Approach to Joke Generation Using Template Extraction and Infilling (2024)

Abstract: This paper presents a novel approach to humor generation in natural language processing by automating the creation of jokes through template extraction and infilling. Traditional methods have relied on predefined templates or neural network models, which either lack complexity or fail to produce genuinely humorous content. Our method introduces a technique to extract templates from existing jokes based on semantic salience and BERT’s attention weights. We then infill these templates using advanced techniques, through BERT and large language models (LLMs) like GPT-4, to generate new jokes. Our results indicate that the generated jokes are novel and human-like, with BERT showing promise in generating funny content and GPT-4 excelling in creating clever jokes. The study contributes to a deeper understanding of humor generation and the potential of AI in creative domains.

## introduction humor generation in nlp is the task of generating jokes through a computer system. it is particularly challenging, and can be seen as a short creativity task. critical to solving this task is understanding humor theory, which attempts to explain the structure and mechanism of jokes. ideas from @xcite and then @xcite , building up from various theories from antiquity, have talked about how humor is based on the incongruity mechanism -the punchline is funny because it deviates from the expectations after the setup. the task of humor generation is important because of how culturally significant humor is, and how ingrained it is in our society, and yet we don't have any clear mechanism to produce a joke. applying computational methods on this task can lead us closer to understanding humor, as well as to language itself, since humor can be seen as a short creative task that is currently not understood well. most attempts at humor generation in the past have used template-based methods. the primary limitation in template-based methods is that they are restricted in the template they are infilling, and for neural methods is that they don't generate humorous content. chaudhary et al @xcite attempted to bridge this gap by generating templates from existing jokes and then infilling them, thus aiming to combine the creativity of neural outputs with the structured humor of templatebased methods. for extraction, they used a score that took two heuristics into account: however, this approach is contingent upon the universal applicability of the assigned weights and the accuracy of the dataset used for frequency analysis. in our paper, we propose enhancements to this model, introducing more robust and scalable methods that aim to generalize beyond the limitations of manual weight assignments and dataset validity. these methods use contextual embeddings to understand the semantic role of a word.