AI generated Poetry

Generating AI Poetry #

Overview: #

  • Selected poetry samples
  • High level explanation of workflow
  • Reflections on design choice of prompt engineering in an application
  • Complete workflow of prompts used and raw output
    • Using OpenAI completion’s endpoint using gpt-3.5-turbo

Samples of generated content #

Quaint times, so simple and pure,
The atom split, the bomb did lure,
Destroyed the peace, left nothing to endure.
Amid the old-brewed smell;
Words grow loud through nights and day
None come home to dwell.
Now its a timeless spiral toiled  
my long redeemed lost spirits linger healing in tumultous waters and ache... 
Reflective elements guide lightning imprint  
lifting me in their mercurially formed embrace.
Swooning through veil's lace, pricked by a grace divine,
Eyes bluer than blue do unfold earth,
Allegories and stained sheets trace a divine enshrine,
While annoyed looks crave malignant mirth.

High level explanation of workflow #

For this set of poetry, I am manually setting an initial input to create more interesting results, however I have been able to completely randomize all inputs in order to generate poetry and have gotten somewhat interesting results. In the examples below, I do give it a “creative input” from which it then creates multiple of what we can call “base poems”. Then gpt-3.5 iterates through the poems to perform additional tasks that will enhance the poems with each iteration. The examples below have 7 steps.

Example of completely automated poetry design #

Reflections on design choice of prompt engineering in an application #

The work on this prompt design, I fed openai it’s own help article and it assisted me to use the format I wanted. I like this format of having multiple steps because you can see what gpt-3.5 is doing with each step.

My thinking at this point is rather than trying to jam in too many specific linguistic devices and tools, is instead to think how can I get gpt to think like a person does, to have a critical eye and to revise content to achieve a certain goal, and then randomize the goals and give them characteristics or parameters. Then, users can setup goals or themes and use a simplistic 2 button interface to modify the value of the chosen parameter up and down on the fly.

The poetry may still have some elements that feel robotic or random or nonsensical, but I do think that these poems do show some promise and in my humble opinion are better than most of the same repetitive poetry you see posted online from chatgpt.

If you’re interested to see the details, read on for the workflow that created the poems above.

Prompts in python code #

abstract_concepts = ["sensuality", "grace", "mundanity", "transcendence", "mortality", "morality", "transience",]
linguistic_styles = ["metaphor", "simile", "Personification", "allegory", "idiom", "Anachronism" ]
creative_prompt = "your example creative prompt here" 

def openai_api_call(creative_prompt):

# var setup and print
    abstract_concept = random.choice(abstract_concepts)

# API call
    response = openai.ChatCompletion.create(
        model="gpt-3.5-turbo",
        messages=[
            #{"role": "user", "content": creative_prompt},
            {"role": "user", "content": "Step 1: Produce three different versions of a poem that about: " + creative_prompt + ". Each poem can be three or four lines long" + "Each version should have a different structure - rhyme, free verse, sonnet, haiku, etc. Explain the changes made for each iteration before printing the result for each step."},
            {"role": "user", "content": "Step 2: Iterate over each version, revising and modifying to reduce consistency and introduce variation in the language, while maintaining coherence. Alter the tone and mood of each version."},
            {"role": "user", "content": "Step 3: The chosen abstract concept is: " + abstract_concept + ". Next you evaluate the revisions and determine which most closely has a deep connection to then chosen concept, or could most elegantly be modified to fit the concept."},
            {"role": "user", "content": "Step 4: Create a new poem that is two to four lines long with the following parameters: Revise the selected poem to subtly weave in the chosen concept."},
            {"role": "user", "content": "Step 5: Create a new poem that is two to four lines long with the following parameters: Revise the selected poem to to enhance the connection to the abstract concept."},
            {"role": "user", "content": "Step 6: Create a new poem that is two to four lines long with the following parameters: Review this list of linguistic devices: "  + ', '.join(linguistic_styles) + ". Determine which linguistic device would most contribute to the poem. Revise the poem to incorporate the chosen linguistic device"},
            {"role": "user", "content": "Step 7: Create a new poem that is two to four lines long with the following parameters: Introduce variation to reduce overall consistency in tone, language use, and sentence structure."},
        ],
        max_tokens=1000,
        n=1,
        stop=None,
        temperature=1.2,
    )

Full output examples #


abstract_concept: morality
creative_prompt: I don't care anymore that you're beautiful and that I'm scared. In between leaves and bytes and blood I'm searching for light In new ways I'm ready to believe 
------------------------------
------------------------------
Number of tokens: 553
------------------------------
Step 2: 

Version 1: 
"I don't care anymore 
that you're beautiful and that I'm scared. 
In between leaves and bytes and blood 
I'm searching for light 

Revised Version 1: 
I no longer marvel 
at your beauty or my fear. 
Amidst leaves, bits and drops of life 
I seek some glimmer approaching peace. 

Version 2: 
Amid beauty still, 
moved past my habit of trembling, 
where leaves and dots of gore collect 
I chase in quest of light. 

Revised Version 2: 
The tremors I felt around beauty. 
I left far back, impressed no more. 
Now, amidst trembling leaves and swords, 
Looking for my moral path 
again connecting the dots of my tattered being 
I chase to find a way to shine. 

Version 3: 
I'm not shaken no more 
by all the wonder and the fright as before. 
Where light struggles to regain grip in my hacked soul,  
I walk looking around and everything’s more sure. 

Revised Version 3:
Faced with magnificence and fearsome sparks
I steady on without staring overly long.
On quicksand-fingers, I trace fingertips
Trying to catch any moral strand I could of the shifting land. 

Step 3:

Revised Version 1 resonates more with the concept of morality. The search for light and peace interwoven between reality's disparate pieces places one seeking equanimity a betwixt situation before internal coherence attained - which reflects the strive to balance moral imperatives and life's infinite knotty irascibility in a way as perceived optimum.

Step 4:

I've once felt but mortared now: 
there sacking before beauty blueprints unmentored 
Tracing stretched lituminous veneers of peaceful gripes 
Until anchored around dot-oldest glitters, denied liberties liberated by shedding tears

Step 5:

Though seemstar struck and shadow visited 
I faulted not then nor now on paradise lost
Interlinking veins of astray with glitter akin -
Creating set safe rule’s customs, so time saw fit.

Step 6:

In darkened innards shards   beleaguered wings died,
my solitary nature made me glisten amidst dark sea gathered fragments on gold wings of lightning.
There unveiled stinging shooting star wings
 As audacious mimic reached to tear sunnis subtle

Step 7:

Now its a timeless spiral toiled  
my long redeemed lost spirits linger healing in tumultous waters and ache... 
Reflective elements guide lightning imprint  
lifting me in their mercurially formed embrace.
abstract_concept: sensuality
creative_prompt: its looking a little grey outside and busy on the roads be careful
------------------------------
------------------------------
Number of tokens: 398
------------------------------
Step 1: 

Rhyme version:
Grey skies overhead, 
Busy roads, paths we tread, 
Stay aware and be foresaid. 

Free verse version:
Clouds are shadowing the day, 
Traffic rush and sirens so loud,
Mindful steps guide the way.

Haiku version:
Grey clouds turn sky grim,
Rucks of speedy car rushed in,
Stay safe-pass the fray dim.

Step 2:

Rhyme version (revision):
Grey skies enter deep; 
Festival lanes found, roads steep; 
Whispers - fragrant seep.

Free verse version (revision): 
Dark clouds saturate all, 
Hustle glow intensifies further, 
Hesitant breath held opposed to allied thrall.

Haiku version (revision):
As heavy sky churns,
Trend of hurry-much concerns,
Be still soft touch sojourns.

Step 3:

After evaluating the revisions it seems that the Haiku version (revision) has a good connection with the chosen concept of "sensuality" because it involves sensual senses by indicating the idea of becoming more aware and be still for enjoying the song in texture.

Step 4:

Haiku version (abstract concept in act):
Galaxies seep damp 
Night settled quarks restless moan 
Still dance till it sleeps 


Step 5:

Haiku version (emphasis input):
Subtle body hues, 
Fences and private reserves- 
Easily crossed if truth 



Step 6:

Haiku version (Linguistic device-inserted):
Outside flutter green,
Every leafy race true sheen,
Navys of desires clean dreams. 

** Metaphor was adopted by blending all the elements fondly/nostalgically in one corner with navy themes**

Step 7:

Haiku version (modified for variation):
Amid the old-brewed smell;
Words grow loud through nights and day
None come home to dwell.
abstract_concept: grace
creative_prompt: a glimpse through the veil and you pierce me in blue eyes, in stained sheets, in annoyed looks, in moments of ecstasy and in panic
------------------------------
------------------------------
Number of tokens: 503
------------------------------
Step 1 - Three Versions of Poem:

Version 1 (Free verse):
Through the veil I see your blue eyes,
Piercing me with panic and sighs,
In those stained sheets we share ecstasies,
While annoyed looks ignore pleasantries.

Version 2 (Sonnet):
In blue eyes glimpsed through veil's shred,
My heart feels pierced, though lace thoughts loom;
Stained sheets, intense in ecstasy fed,
Yet panicked twirls into oblivion zoom.

Version 3 (Haiku):
Pierced and gasping breath
Bluest eyes behind veil's green breath
Stained sheets, grace in depth.

Step 2 - Revised Poems:

Version 1 (Free verse):
Pierced by blue eyes through veil's lace,
In stained sheets we find grace and disgrace,
Pleasantries gone; annoyed looks we face,
Ecstatic moments, panic's lonely embrace.

Version 2 (Sonnet):
Through veil's threads and shredded curtain lace,
A glimpse of piercing blue your eyes affirms;
Stained sheets that bear the mark of grace,
Still panic tints moments and malice confirms.

Version 3 (Haiku):
Veil's breath conceals blue eyes of piercing grace,
Stained sheets breathing pain with imagined haste,
An impasse solves if intrusion we erase.

Step 3 - Selection:

From the three revised versions, version 1 best depicts the concept of grace.

Step 4 - Incorporating concept:

Pierced by veil-laced blue,
Grace and disgrace coexist anew,
Annoyed looks and ecstatic moments cue
My inner beauty, pricked and true.

Step 5 - Enhanced connection:

Pierced by veil-lace's grace through your blue eyes,
Disgrace - a fallacy on stained sheets lies.
Annihilating the annoyed looks' black skies,
Ecstasy and panic move aside one's guise.

Step 6 - Linguistic device, expanding language use and tone:

Personification:
Veil-lace's grace does prick my heart,
As wary blue eye-gates depart,
Stained sheets embody my thwarted art,
While annoyed looks fast dispart.

Step 7 - Introducing variation:

Swooning through veil's lace, pricked by a grace divine,
Eyes bluer than blue do unfold earth,
Allegories and stained sheets trace a divine enshrine,
While annoyed looks crave malignant mirth.
running pif_poetry_generator with prompt: uranium_235
persona: poets
abstract_concept: quaintness
creative_prompt: uranium_235
------------------------------
Prompt tokens: 286
Completion tokens: 297
Total tokens: 583
------------------------------
Step 1: 

Free Verse:
Uranium-235, so coveted and rare,
A fissile isotope with power to spare,
A blessing and a curse, we must beware.

Rhyme:
Uranium-235, oh so fine,
A nuclear fuel that can shine,
Split the atoms, energy all mine.

Haiku:
Uranium-235
Power hidden in the core
Potential danger

Step 2:
The poem that most closely connects with the abstract concept of quaintness is the haiku. The juxtaposition of the dangerous potential of uranium-235 with the traditional and peaceful form of a haiku creates a sense of quaintness.

Revised Haiku:
Uranium-235
In the core, power hidden
Quaint destruction waits.

Step 3:
Revised Haiku with concept woven in:
Quaint atoms, refined
Fissile beauty, power within
Nuclear danger waits.

Step 4:
Revised Haiku with my personal style:
Uranium-235
Power in the heart of stone
Nuclear force unknown.

Step 5:
Revised Haiku with allegory incorporation:
A seed, small and still,
Uranium-235, a power to kill,
Nuclear winter chills.

Step 6:
Final Poem, concept applied further:
Quaint times, so simple and pure,
The atom split, the bomb did lure,
Destroyed the peace, left nothing to endure.