How a Large Language Model Writes a Poem

Wednesday 2nd April, 2025 - Bruce Sterling

*Of interest to Versificatore fans.

https://transformer-circuits.pub/2025/attribution-graphs/biology.html#dives-poems

How does Claude 3.5 Haiku write a rhyming poem? Writing a poem requires satisfying two constraints at the same time: the lines need to rhyme, and they need to make sense. There are two ways one might imagine a model achieving this:

Pure improvisation – the model could write the beginning of each line without regard for the need to rhyme at the end. Then, at the last word of each line, it would choose a word that (1) makes sense given the line it has just written, and (2) fits the rhyme scheme.
Planning – alternatively, the model could pursue a more sophisticated strategy. At the beginning of each line, it could come up with the word it plans to use at the end, taking into account the rhyme scheme and the content of the previous lines. It could then use this “planned word” to inform how it writes the next line, so that the planned word will fit naturally at the end of it.
Language models are trained to predict the next word, one word at a time. Given this, one might think the model would rely on pure improvisation. However, we find compelling evidence for a planning mechanism.

Specifically, the model often activates features corresponding to candidate end-of-next-line words prior to writing the line, and makes use of these features to decide how to compose the line….