The Inspiration

Do you like the whimsical newspaper blackout poems? We can borrow the same idea to write a program that composes haikus. The making of blackout poetry is a process of finding desired words within a paragraph of text. When other words are eliminated, the poem emerges from the contexts. It’s refreshing.

Blackout poem

I have spoken to Batman by Austin Kleon.

Haiku is an unrhymed poetic form consisting of only 17 syllables that usually writes in three lines, with syllable counts of 5-7-5. With Python and NLP (Natural Language Processing) tools at our hands, we can program a haiku machine that takes in an arbitrary paragraph of writing from one end and outputs a haiku on the other end.

Let’s dive in.

NLP Libraries

Debuting in 2001, NLTK (Natural Language Toolkit) remains a mighty force and the most famous NLP library today. Its drawbacks are being complicated and slow. In 2012, Tom De Smedt and Walter Daelemans developed a library called Pattern that features sentiment and graph analysis. The more popular TextBlob was developed based on Pattern and NLTK.

#machine-learning #poetry #nlp #python #programming

NLP With Python: Build a Haiku Machine in 50 Lines Of Code
2.10 GEEK