top of page

ABOUT

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. 

DEMO

PICK A POEM

UPLOAD A .TXT FILE

Button Disabled:
Only runs from terminal

POEM PRESETS

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. 

havingacokewithyou3.png
"Having A Coke With You"
"Poetry"
"A Prayer for my daughter"
"If--"
"The Darkling Thrush"
"Poem about My Rights"
"The Starry Night"
"Abandoned Farmhouse"
"Being"
havingacokewithyou1.png

Random Poems Trials

poetry.png
poemaboutrights2.png
poemaboutrights3.png
havingacokewithyou2.png
poetry2.png
poemaboutrights1.png
poetry3.png
aprayerformydaughter1.png
aprayerformydaughter3.png
aprayerformydaughter2.png
if1.png
if2.png
if3.png
thedarklingthrush1.png
thedarklingthrush2.png
thedarklingthrush3.png
starrynight3.png
starrynight1.png
starrynight2.png
abandonedfarmhouse1.png
abandonedfarmhouse3.png
abandonedfarmhouse2.png
being2.png
being1.png
being3.png

CODE

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
                                                                                                              I look
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

Screen Shot 2022-04-25 at 9.00.41 PM.png

get_top_words()
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

Screen Shot 2022-04-25 at 9.01.43 PM.png

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

Screen Shot 2022-04-25 at 9.01.11 PM.png

Language Database 

determine_mask():

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)]

​

22.PNG

Mask Shapes

,ask shapes.PNG

Step 5: Create final word cloud with the mask, color range, nouns

Screen Shot 2022-04-25 at 9.01.43 PM.png

wordCloud():

Finally, we create the word cloud. Each time the code is run, a new word cloud will be generated for the text. 

bottom of page