We created a python-based word cloud generator that takes in any poem, parses it, determines a specific shape and color (including a range of hues) based on the most frequent topics discussed in the poem, and outputs a corresponding word cloud. The model can be rerun to create different clouds for the poem.
PICK A POEM
Only runs from terminal
Click a button to see its word cloud! Click it again to generate a different word cloud (max 3). Keep clicking to close.
Close cloud before clicking a different button.
Random Poems Trials
HOW IT WORKS
Step 1: User inputs poem as .txt file
Example: "Having a coke with you" by Frank O'hara
"is even more fun than going to San Sebastian, Irún, Hendaye, Biarritz, Bayonne
or being sick to my stomach on the Travesera de Gracia in Barcelona
partly because in your orange shirt you look like a better happier St. Sebastian
partly because of my love for you, partly because of your love for yoghurt
partly because of the fluorescent orange tulips around the birches
partly because of the secrecy our smiles take on before people and statuary
it is hard to believe when I’m with you that there can be anything as still
as solemn as unpleasantly definitive as statuary when right in front of it
in the warm New York 4 o’clock light we are drifting back and forth
between each other like a tree breathing through its spectacles
and the portrait show seems to have no faces in it at all, just paint
you suddenly wonder why in the world anyone ever did them
at you and I would rather look at you than all the portraits in the world
except possibly for the Polish Rider occasionally and anyway it’s in the Frick
which thank heavens you haven’t gone to yet so we can go together for the first time
and the fact that you move so beautifully more or less takes care of Futurism
just as at home I never think of the Nude Descending a Staircase or
at a rehearsal a single drawing of Leonardo or Michelangelo that used to wow me
and what good does all the research of the Impressionists do them
when they never got the right person to stand near the tree when the sun sank
or for that matter Marino Marini when he didn’t pick the rider as carefully
as the horse
it seems they were all cheated of some marvelous experience
which is not going to go wasted on me which is why I’m telling you about it"
Step 2: Parsing through the text and creating a list of nouns
We decided to only pull nouns from texts as they are more interesting to observe than other parts of speech such as prepositions. This function filters out all the words in the given text so that there are only nouns in the word cloud.
Step 3: Determining the most important/ prevalent top 3 words in the noun list
Example (continued from above)
List of nouns in decreasing font size order (the larger font= more important):
['love', 'tree', 'portrait', 'world', 'stomach', 'orange', 'shirt', 'yoghurt', 'tulips', 'birches', 'secrecy', 'smiles', 'people', 'front', 'o', 'clock', 'light', 'spectacles', 'show', 'faces', 'heavens', 'time', 'fact', 'care', 'Futurism', 'home', 'Staircase', 'rehearsal', 'drawing', 'good', 'research', 'person', 'sun', 'matter', 'rider', 'horse', 'experience']
Top 3 words to use for the word cloud shape and color
['love', 'tree', 'portrait']
Step 4: Determining word cloud shape and color based on top 3 words
We added masks to each word cloud so that the words can form a shape on the canvas. This function takes the filtered words from the text and determines the mask of best-fit for the text. For example, a love poem will likely have a heart-shaped mask.
If no mask shape or color is identified, the code will randomly choose a default shape and the color black.
Example (continued from above)
"Love" is first matched to the heart_list list, so the word cloud is paired with a heart mask shape and the color red (with a range of hsl values to create different hues)
top_words= ['love', 'tree', 'portrait']
heart_list = ["lover", "love", "heart", "romance", "kiss", "family", "families", "hugs", "hug", "relationship", "friend"]
red = ["hsl(0,100%%, %d%%)", (20, 80)]
Step 5: Create final word cloud with the mask, color range, nouns
Finally, we create the word cloud. Each time the code is run, a new word cloud will be generated for the text.