Rhyme with AI

Henk Griffioen/
Rens Dimmendaal/
07 February, 2020
Demonstration of Rhyme with AI

Machines may take over the world within the year;
But creating rhymes instills in us the most fear!
Luckily, pre-trained neural networks are easy to apply.
With great pride we introduce our new assistant: Rhyme with AI.

NLP's ImageNet moment may have arrived in 2018, but the ecosystem around NLP models really has matured in 2019. Many of these models (BERT, GPT-2, Transformer-XL, DistilBERT, etc.) are easy to use for your use cases. Our service uses BERT to help us with our rhymes.

Language modeling helps state-of-the-art models understand languages before solving tasks like sentiment analysis or translation. Masking, where the model tries to predict a word that is hidden from a sentence, is one of BERT's innovations. We can use it to help us rhyme by rephrasing rhyming as a task to predict missing words.

From the The Illustrated BERT, ELMo, and co.
Predicting masked tokens is one of BERT's language modelling techniques.

Our problem involves multiple masks: we know the first sentence and the last word of the second sentence. For instance:

Machines will take over the world soon

Inspired by BERT has a Mouth, and It Must Speak, we first let BERT fill in the [MASK]'s and then randomly sample new tokens. Some example rhymes from our model:

Machines will take over the world soon

This already looks pretty good, but we need a solution that people can use!

Luckily, creating an end-to-end machine learning solution is fairly simple. The Datamuse API gives back rhyme words, BERT is available via huggingface and creating an app is no sweat with streamlit. Put it all together in a Docker container and a hosted solution is one command away with Google App Engine.

A few days well spent for us will hopefully save you a lot of pain. Check out or code on GitHub!

Would you like to get more hands-on experience with deep learning and NLP? Check out one of our courses:

Subscribe to our newsletter

Stay up to date on the latest insights and best-practices by registering for the GoDataDriven newsletter.

Free Video Course – Python Foundation

The goal of this free online self-paced training is to introduce enough Python to move on to more complicated topics in data science without getting surprised.