Monday, February 27, 2023

Poetry writing with GPT-3 and ChatGPT

One really impressive thing about the GPT writing technology is the ability to quickly generate decent quality poems, songs, and other types of stylized constructions.

The key to understanding how this works, is to think about what GPT is literally doing. It's taking a document of text, and just completing it like auto-complete, but with an insane level of sophistication about what language and thought are like. This turns it into a type of natural language constraint satisfaction engine, and our job is to write the constraints. Or if you prefer a less technical description, our job is to give GPT "homework requirements" to satisfy.

For this example, I am using the GPT-3 Playground interface, because it's a bit more natural to work with than ChatGPT, though you can use ChatGPT to do the same thing by either editing your initial prompt, or by creating a fully new prompt and pasting in some of the generated output into your new prompt.

Consider a prompt like this:

write a six-line rhyming poem about horses in the forest on a sunny day in march

Notice I gave it many constraints:

(1) write a (2) six-line (3) rhyming (4) poem about (5) horses in the (6) forest on a (7) sunny day in (8) march

Here is the first response I received.


The horses prance in the bright sun rays,

As March brings us happy days.

Their coats shine with a golden hue,

On this beautiful day so new.

The wind blows through their manes of gold, 

A perfect sight for us to behold.


This is pretty decent for a first cut, but lets say I like some of these lines better than the others.... I can prime the generator by keeping any lines I like, or writing my own lead-in lines, and it will still complete the request above. For example, let's say I decide putting the word "horses" in the first line is too simplistic. I want the poem to feel like it is leading us to horses, not just stating that outright. 

Here is my next prompt:

write a six-line rhyming poem about horses on a sunny day in march


The wind blows through their manes of gold, 

A perfect sight for us to behold.

GPT auto-completes the document, by adding the missing four lines of the poem. This happens because the GPT-3 machine model is simply being asked over and over again for a single word (ish) to be added to the end of the document. It doesn't know the difference between this scenerio above, and the first scenerio after it's written two sentences. 


The horses prance in a sunny day, 

In March, when all is merry and gay. 

Their long tails sway from side to side, 

As they gallop with such grace and pride.


In fact, you can truncate the prompt input anywhere, not just on a line boundary, and it will do the same thing, finishing the construction. For example, consider this prompt:


write a six-line rhyming poem about horses on a sunny day in march


The wind blows through their manes of gold, 

A perfect sight for us to behold. 

The horses prance in a sunny day, 

In March,


Submitting this lead-in a few times, I was able to get the following completion:


a gallop and a neigh. 

Their hooves will make a gentle sound, 

No matter where they go, grace is found.


I'm not going for perfection here, just trying to demonstrate the authoring technique I think of as "curating". By that I mean, we are writing a prompt, looking at the response and "curating" the parts we like best, dropping the rest, and then asking it to complete again. I use this strategy in tons of situations, such as idea generation, character generation etc. Given a story-context, I might ask it to "generate 5 characters with bios and full names", then delete four of them, renumber the remaining one as number-1, then let it regenerate the other four.

I want to demonstrate one last technique here, and that is to always improve the results by tinkering with the prompt, adding more constraints. For example, I mentioned wanting to make the poem seem abstract by being about horses, but not actually *mention* the word horses. In the last response I got, GPT3 is again being very direct and mentioning horses. Let's see if we can fix this with an additional constraint:


write a six-line rhyming poem about horses on a sunny day in march. do not mention the word horses.


The wind blows through their manes of gold, 

A perfect sight for us to behold.


The first response I received from this complied with my request:


Their grace is seen, their beauty shared, 

As they run with swiftness unpared. 

The sun's bright rays give them a sheen, 

Their beauty for us to be seen.


What you can do by adding constraints is pretty astounding. Consider constraints like:

  •   make the poem sad
  •   make the poem happy
  •   use simple words for a four year old
  •   use rare or complex words to sound sophisticated


Here is a transcript of the first response I received after using the above additional qualifications.. Of course I could combine this technique with priming and/or curation to better steer the output. 

write a six-line rhyming poem about horses on a sunny day in march.. do not mention the word horses. make the poem sad.


The day was so bright, the sun shone so warm,

A gentle breeze in the air like a charm.

But where were the steeds, the noble and strong?

In the meadows they should have been roaming along. 

No neighs or whinnies to be seen or heard,  

Just silence that spoke of absence absurd.


write a six-line rhyming poem about horses on a sunny day in march.. do not mention the word horses. make the poem happy.


On a sparkling March day,

A herd of stallions with bay

Gallop o'er fields and glades,

Mane flowing in the soft breeze made. 

The colts they frolic free,

Bounding with glee!


write a six-line rhyming poem about horses on a sunny day in march.. do not mention the word horses. use simple words for a four year old.


A mare in the meadow,

Dazzling and bright.

In March on a sunny day,

She's a dazzling sight.

Galloping with grace,

Mane flying high.


write a six-line rhyming poem about horses on a sunny day in march.. do not mention the word horses. use rare or complex words to sound sophisticated.


In the month of Marching morn,

When the sun doth rise unbowed,

O'er a distant meadow fair,

Stands a steed of coat so rare;

Fleet-footed leaps he o'er the ground, 

Hooves a-clatter to his sound.


Happy hunting, prompters!

No comments:

Post a Comment

Creative Curating and Refinement with GPT-3

In this post I'm going to explain two GPT strategies that I call " Curating ", and " Refinement ". For this blog pos...