• Son Luu

Song Lyrics to Generated Poetic Form with Python

Updated: Oct 2, 2019

Class: Reading and Writing Electronic Text

Instructor: Allison Parrish

"Mama, I'm Coming Home" is my final project for Reading and Writing Electronic Text. Finally, after 2 weeks of struggling with concept and technical execution for over 2 weeks, I think I might finally be okay with the result so far. Please check it out.



Below are the concepts that I explored and tested coding:

  1. Hurricane names: corpuses of hurricane names before and after the natural disasters happened (i.e. how the name "Sandy" used before and after hurricane Sandy hit in 2012)

  2. Changes in "Self-" references [over the last 20 years]: references that have prefix "Self-" (i.e. self-confidence, self-care, self-destructing, self-image, etc. ) appearing in the NY Times over last 20 years that correspond to the founding of major social media platforms such as Facebook, Instagram.

  3. Chatbot conversation: chatbot conversations and the role of contexts, using Microsoft Social Media Conversation Corpuses from Twitter.

  4. Text Messages from My Mom: text messages my mom sent to check in with me twice a day, every day during the time I live far away from home, combined with the lyrics of "Mama, I'm Coming Home" by Ozzy Osbourne.

🌵Concept 4 and technical approach:

  • My mom sends me text messages that are often short sentences and phrases to check in: "Are you home?" "Are you at school?" "Are you up early today?" etc. The source text reflects a feeling of longing for updates and to know whether things are going fine and I am doing okay. Reading these texts all at once I can feel a mom's missing and longing for her child to come home and reunite.

  • Then, I decided to use the lyrics of "Mama, I'm Coming Home" as the son's response to his mother. The idea is to combine the two, then break them all apart on the character or word level and finally put them back together and see what will happen.


1️⃣ Text generation:

  • Break source text onto the character level

  • Use Markovify - a Markov Chain generation to combine the 2 sources. The reasons for using these among other text generative tools from this class:

  • (1) The source text (mom's text messages) is too original in terms of emotions that I didn't want to alter her own words. Because of that, Markov is appropriate because it doesn't evaluate the words based on context, but primarily just structure.

  • (2) At first, just using Markov Chain alone created quite a bit of repetition of phrases and sentences because the source text pool (2 weeks of text messages) was too small. So, by combining with another source text (the song lyrics) and using Markovify to combine them is appropriate to provide a larger amount of text to work with but also give the generated poem a richer context because now it brings in an interesting distant conversation between mom and son.

Played with the parameters:

  • level: word or character, the character ended up generated a version that I liked more. The word level didn't provide a more creative way

  • source text: I had to take out the signs : , ' ; Otherwise Markovify wouldn't read the text

  • order: I chose 7 because anything below 7 would create too drastically creative forms of sentences and grammatical structures.

  • weights: I decided to give mom_texts 0.7, and the song lyrics 0.3 to emphasize the larger amount of messages mom would send to her son, and the son is is not very responsive.

  • length_limit: I wanted to set a higher limit to have a wider range of possibilities.

2️⃣ Picked a favorite version

I was excited about how different versions which went through various runs through the codes, have generated text and structures in combination of the sources, that convey different contexts, and evoke different feelings. Here are 2 versions:

3️⃣ Create Rhyming

Use Pronouncing for reorganizing the text to create rhyming couplets for Version 1:

4️⃣ Final Product:

With very little editing (adding appropriate punctuations and taking out grammatically incorrect details), the below versions of the poem are nice to share:

🔆 Ver 1:

Mama, I'm Coming Home

a.k.a. "Mama I Turned Your Text Messages into a Poem"

Did you get my text?

Did you get my text?

Did you see my call?

Did you see my call?

You took me in and you drove me out

Lost and found and turned around

I'm coming home

I'm coming home

Here I come but I ain't sunshine

I've seen your face a thousand times

Lost and found and times

Lost and found and turned around

It hurts so bad, it's been so long

You took me in and you drove me out

I've seen your face a thousand times

Lost and found and times

Did you see me call?

You took me in and you drove me out.

🔆 Ver 2:

Mama, I'm Coming Home

a.k.a. "Mama, I Will Respond to Your Text Messages More Often"

Just me and dad.

We are taking a short walk.


We just had dinner.

Are you home?

I've seen your eyes.

It's hurt so bad, it's been so long.

You still at school today...?

You have changed and turned around.

Up yet?

Lost and found and times

I know.

Today dad left early.

You have school.

You should slow down a bit

Don't put too much pressure on yourself.

Take care of yourself

Have a good day

I'm coming home.

I don't care about sunshine.

Are you home yet?