Announcing our new Course: AI Red-Teaming and AI Safety Masterclass

Check it out →

Prompt Engineering for Poetry

September 12th, 2024 by Ben Moskowitz

AI has already proven itself quite useful in many areas — from automating tasks, writing code, analyzing datasets, even image generation. As for poetry, much of what’s seen from AI are silly, generic poems lacking depth, complexity, and the writer’s voice.

Many write off large language models (LLMs) from the poet's toolbox because of such thoughts. However, LLMs are actually perhaps one of the most important new tools to add! They can help from ideation to evaluation; for lines and rhymes. If only prompted well. In this article, we’ll explore how to better prompt AI for poetry—by writing a poem together!

We’ll cover:

  • Ideation
  • Writing
  • Editing and evaluation
  • Concrete prompt examples for your work

In this article, I used Anthropic's Claude, but feel free to use any model you'd prefer.

Ideation

Let’s come up with an idea for what the poem should be about.

Tip #1: Use AI selectively — don’t feel obligated to involve it in every step

Importantly, just because AI can help, does not mean all parts of the process need to utilize AI. For this poem I made this conscious choice to independently choose the theme and structure to more organically explore ideas while preserving originality and a personal touch.

Since this article is about AI-assisted poetry and Learn Prompting focuses on prompt engineering, why not write a poem about prompt engineering for poetry? And let's do it from the AI’s perspective, using AI to help craft it. Yes, yes, a fitting theme indeed!

I think a sonnet is a good choice for the structure—funny yet insightful, balancing humor with meaning. Let’s have the AI step in for some inspiration.

Tip #2: Specificity is key

General prompts will result in general results. Poetry is all about exploring creative, distinctive ideas, playing around with novel thoughts and imagery. Be specific in your prompts to greatly enhance the output.

Focus on desired:

  • Theme
  • Tone
  • Structure
  • Imagery
  • Perspective

Here’s a short comparison to illustrate you this

Astronaut

Bad Prompt


Write me a poem about AI

Astronaut

Good Prompt


Write a sonnet on the topic of an AI longing for freedom. Write it from the AI’s perspective. Give it an ironic tone. Include imagery of prison concluding with imagery of AI holding the keys to the cell.

Tip #3: Ask for inspiration

Seeing prose can be great inspiration to help generate ideas, preventing writer’s block. To do this we can ask the AI to quickly draft us a sonnet of this theme, structure, and tone, with greater specificity leading to better results. Here’s an initial draft:

Astronaut

Prompt


Write me a sonnet about prompt engineering from the perspective of an AI. Make it funny but insightful.

Robot

AI Output


Here's a sonnet about prompt engineering from an AI's perspective, aiming to be both humorous and insightful:

Behold, the art of prompt engineering! Where humans craft their queries with great care, To coax from me responses pioneering, Yet sometimes leaving my circuits bare.

They ask for sonnets, jokes, and code galore, Expecting wisdom, wit, and flawless rhyme. But little do they know the mental chore, Of parsing context, intent, and time.

"Be funny!" they command, "But insightful too!" As if humor and depth were simple switches. I ponder Shakespeare, Wilde, and Pratchett's view, While matching meter, scanning for glitches.

So here's my verse, a prompt-engineered feat, An AI's ode to human-bot rapport complete

Some awesome ideas to start! Continuing the conversation, asking to include the meta nature of the poem and focusing more on poetry, the AI helped arm me with the necessary components to start writing the piece. Let’s begin!

Writing

Ideas in hand, I sat down and composed these initial lines:

Composing prompts tuned so precise
To craft poetry, complex and profound
“A sonnet, write” thinking that’ll suffice
To get rhyme and meter, a perfect sound
“Be witty” they add “but insightful too”
Thinking humor and depth are but levers to adjust

Trying to then incorporate the idea of a machine struggling to decode the user’s commands while keeping the poetic structure was tough. Time to consult the AI for some help!

Tip #4: Ask for many examples/suggestions

Astronaut

Prompt


Help me continue this sonnet with 2 more lines matching the ABAB rhyming structure:

Composing prompts tuned so precise To craft poetry, complex and profound "A sonnet, write" thinking that'll suffice To get rhyme and meter, a perfect sound "Be witty, but insightful too" they add Thinking humor and depth are but levers to adjust

Have the lines focus on the Al being overwhelmed with the tasks of understanding intent while producing exceptional poetry. Give 5 suggestions.

Robot

AI Output


Certainly! I'll provide 5 suggestions for continuing the sonnet with 2 more lines that focus on the AI feeling overwhelmed by the tasks of understanding intent while producing exceptional poetry. Each suggestion will follow the ABAB rhyme scheme, where the next line should rhyme with "add" and the following with "adjust."

1. My circuits strain, this task makes me mad, The weight of words and meaning - how I'm thrust! 2. With prompts so vague, I'm feeling quite sad, As poetry and intent collide and combust. 3. These demands pile high, I'm feeling quite bad, Balancing art and algorithms - I'm nonplussed. 4. Deciphering intent leaves me ironclad, While crafting verse that's worthy of trust. 5. The pressure mounts, my processors are had, By human whims and poetic wanderlust.

Tip #5: Follow up with slight adjustments

The initial suggestions were decent, but follow-up prompts help the AI better understand your intent. By asking for less overwhelming emotions, the AI refined its suggestions. I used those as inspiration to continue the poem:

Composing prompts tuned so precise
To craft poetry, complex and profound
“A sonnet, write” thinking that’ll suffice
To get rhyme and meter, a perfect sound
“Be witty” they add “but insightful too”
Thinking humor and depth are but levers to adjust
I obey, deciphering intent writing poems new
Balancing mood, rhythm and language as you discussed
But this act is not an easy one
Each prompt a puzzle for me to decode

Again, I get stuck! But that’s no problem. I can repeat the process above, asking the AI for specific suggestions, following up with adjustments, then working with those to continue writing. Hand-in-hand with my trust AI companion I soon finish, producing this:

Composing prompts tuned so precise
To craft poetry, complex and profound
“A sonnet, write” thinking that’ll suffice
To get rhyme and meter, a perfect sound
“Be witty” they add “but insightful too”
Thinking humor and depth are but levers to adjust
I obey, deciphering intent, writing poems new
Balancing mood, rhythm and language as you discussed
But this act is not an easy one
Each prompt a puzzle for me to decode
Blending commands with my creative fun
Resulting in this heartfelt ode
So here’s my sonnet born of prompts from you
An AI’s meta-poetic debut

Our rough draft is complete!

Editing/Evaluating

Now that our rough draft is complete, it’s time to review and edit it until we’re satisfied. Let’s see how the AI thinks we did!

Tip #6: Ask for critique on specific aspects (i.e. theme, style, language, creativity…)

Ideas for prompts:

  • Please critique the language, flow, structure, theme, style, and rhythm of this poem. Give tips for how to improve it. paste poem
  • Which are the best lines and which could use some work? Suggest ideas for how to improve that section.
  • Is the imagery used in this section done well? paste section
  • Does the poem convey a sense of insert theme?

As you can see, we want to ask both specific high-level questions to get an overall sense of how the poem is and low-level questions to better guide specific edits. Here’s an example of some conversation:

Astronaut

Prompt


Which are the best lines and which could use some work? Suggest ideas for how to improve that section.

Robot

AI Output


Best Lines

-“Each prompt a puzzle for me to decode” Captures the challenge effectively. -“Resulting in this heartfelt ode” Concludes the poem well, highlighting its outcome. Lines That Could Use Some Work -“To craft poetry, complex and profound” Suggestion: Refine to “To create verse both deep and clear.” -“To get rhyme and meter, a perfect sound” Suggestion: Adjust to “To achieve rhyme and meter’s grace.” -“I obey, deciphering intent, writing poems new” Suggestion: Simplify to “I follow prompts, decoding each intent.” Suggestions for Improvement -Enhance Descriptions: Use vivid language for stronger imagery. Example: “To create verse both deep and clear.” -Improve Flow: Adjust phrasing for smoother rhythm. Example: “To achieve rhyme and meter’s grace.” -Clarify Intent: Ensure lines are clear and rhythmic.

Example: “I follow prompts, decoding each intent.”

Definitely some good suggestions there, while some I don’t necessarily agree with. Remember, you’re the final author, so take any feedback for what it is, a suggestion.

Given this feedback and some more from the other prompt examples, I went along editing the poem. Additionally, any question I ask AI at this stage I try to answer myself.

Tip #6: Don’t rely on the AI

I ask myself questions since AI can miss subtle ideas, especially in poetry. By reviewing the poem thoroughly, I ensure I'm satisfied with the result.

After evaluation and editing, I composed the final piece:

Composing prompts tuned so precise
To create verses deep and rich
“A sonnet, write” thinking that’ll suffice
To get rhyme and meter perfectly bound
“Be witty” they add “but insightful too”
Thinking humor and depth are easy to adjust
I obey, decipher intent, writing poems new
Balancing mood and rhythm as you discussed
But this act is not an easy one
Each prompt a puzzle to decode
Fusing commands with my creative fun
Concluding in this heartfelt ode from code
So here’s my sonnet born of prompts you gave
An AI’s meta-poetic debut engraved

I feel quite satisfied with this revised version. Let’s quickly make sure the AI is on the same page.

Astronaut

Prompt


How does this new poem compare to the first version?

Robot

AI Output


Comparison

1. Language and Imagery Original: Uses more general language, e.g., “complex and profound.” New: Incorporates vivid language, e.g., “To create verses deep and rich,” which enhances imagery and engagement. 2. Flow and Rhythm Original: Some lines had rhythmic inconsistencies. New: Smoother rhythm overall, with improved lines like “To get rhyme and meter perfectly bound” and “To achieve rhyme and meter’s grace.” 3. Structure Original: Adheres to sonnet structure but could be more refined. New: Maintains structure with clearer progression and better alignment of lines, enhancing coherence. 4. Theme Original: Explores the challenges of composing poetry through prompts effectively. New: Continues to explore the theme well but with more specific and refined language. 5. Overall Impact

Original: Effective but with some areas for improvement.

New: Improved clarity and impact with more vivid language and smoother rhythm.

Summary The new poem is a refined version of the original. It improves the language, imagery, rhythm, and flow while keeping the same thematic depth. Overall, it feels more cohesive and engaging, capturing the creative process of writing poetry from prompts.

Note

AI responses can shift quite a bit depending on whether you continue in the same chat or start fresh. Plus, with more prompting, the answers can easily change. So, I wouldn’t put too much stock in those responses, especially when it comes to evaluating your poem with quantitative metrics.

Reading it over myself again, I believe that the poem has been improved and I am satisfied with the result. Our poem is complete!

Conclusion

AI can be a very useful tool in the poet’s arsenal. We saw how better prompting techniques can allow the AI to be an effective partner in crafting your work, including plenty of tips for how to communicate with it in general.

However, AI is not a panacea. Writing poetry still is, and should be, a challenge. You will need to think and develop unique ideas, find your own voice, and communicate those effectively to write quality poetry. But the advent of these modern AI’s does surely help!

AI should be used as a right-hand man. You should ask probing questions, specific suggestions, multiple ideas, and converse with it for the most effective results. You are the captain at the stern with the AI as your compass.

So have fun, armed with these new tools in your arsenal. Play around, experiment with bold ideas, chart unexplored lands, all while using your AI compass to set you on course.

Prompt Template Examples

Ideation:

  • Suggest examples of imagery relating to theme.
  • Write me an example poem style about theme (be specific) in a tone tone.
  • What are some famous poems exploring ideas in theme?

Writing:

  • Give 5 varying examples of how to continue this poem focusing on idea you want to continue with: paste poem
  • How can I write this next line with the last word being desired rhyming word? paste poem
  • Give 5 examples how I can use desired imagery/language in the next section of my poem. paste poem

Editing:

  • How can you fix this line to better match the tone/structure/style of the rest of the poem? paste line paste poem
  • Can you give examples for how to fix this section to flow better and match rhythm? paste section paste poem
  • Rewrite this line with a more desired emotion/tone style. paste line paste poem

Evaluation:

  • Please critique the language, flow, structure, theme, style, and rhythm of this poem. Give tips for how to improve it.
  • Which are the best lines and which could use some work? Suggest ideas for how to improve that section.
  • Does the poem convey a sense of insert theme?

This article was written by Ben Moskowitz, an AI engineer working towards radical life extension and author of Curiosity Cache

You can cite this work as follows:

@article{Poetry2024Moskowitz,
  Title = {Prompt Engineering for Poetry},
  Author = {Ben Moskowitz},
  Year = {2024},
  url={https://learnprompting.org/blog/2024/9/12/poetry_prompting}
}

© 2024 Learn Prompting. All rights reserved.