Neil Ang


A stunning likeness of Neil Ang
Hello world

Pun generation algorithm

Posted on

As a father, it is my unspoken duty to make bad "dad" jokes. Arguably no jokes are more eye-roll-worthy than the common pun. One weekend I conducted a quick experiment to see how difficult it would be to create an algorithm to generate puns on the fly… Puns as a Service.

After a bit of research I discovered it is difficult to generate a good pun without the context in which it is being used. However, the bar is extremely low to make a bad pun based off word sounds.

By combining three algorithms (patgen, double metaphone and white similarity) I cobbled together a basic syllable sound substitution solution, and seeded it with well known english idioms. What I like about this approach is that the puns are dynamically generated instead of maintaining a list of known puns.

It is still a work in progress, but you can give it a go here: Paronomasia - Pun generator.

Although this approach basically "works" as intended. There are a few issues which could be improved upon to produce better results, but I'll leave that for another day.