Generate and Revise: Reinforcement Learning in Neural Poetry

Andrea Zugarini, Luca Pasqualini, Stefano Melacci, Marco MagginiarXiv 2021

TL;DR

Most AI text generators produce output in a single pass, failing to capture the iterative drafting and editing process typical of human writers. This paper introduces a "generate-and-revise" framework for poetry that uses Reinforcement Learning—specifically Proximal Policy Optimization (PPO)—to progressively detect and replace words until a target rhyming scheme is met, all without explicit linguistic rules.

What Problem Does This Paper Address?

Standard Natural Language Generation (NLG) models operate in a single pass, generating text token-by-token from left to right. While effective for standard prose, this approach struggles with highly constrained creative writing like poetry, where strict structural requirements (such as meter and rhyme) often necessitate backtracking, editing, and revision.

Existing neural poem generators typically try to enforce these constraints through rigid rule-based post-processing or complex decoding tricks. This paper addresses a fundamental gap: how to design an AI agent that mimics the human creative process by generating an initial rough draft and then autonomously revising it to satisfy structural constraints.

Methods

The authors decouple the generation and revision process into three distinct neural modules:

  1. Conditional Poem Generator: A sequence-to-sequence model with attention (utilizing a bidirectional LSTM encoder and a GRU decoder) that takes an author's style and a target rhyme scheme to output an initial draft poem.
  2. Detector: An RL agent that evaluates the current draft and selects the index of a word that violates the target structure or context. Crucially, the detector is not given any prior linguistic knowledge about what a "rhyme" is or where it should occur.
  3. Prompter: A context-aware language model that analyzes the left and right context of the word selected by the detector to suggest a pool of top-$k$ replacement candidates.

The revision process is framed as a navigation or shortest-path problem. The RL agent receives a positive reward ($+1$) if the poem successfully matches the target rhyme scheme, and a penalty ($-1$) for every editing step taken. This setup incentivizes the agent to make the minimum necessary corrections to achieve the goal.

Figure 1: Overall Generate and Revise scheme on an example poem. The conditional poem generator (light blue module) produces a draft poem, which is iteratively revised by the detector (pale yellow) - Prompter (light orange) modules until satisfaction of a certain criteria. At each step the detector identifies the word to replace, heart highlighted in red, while the prompter is responsible for finding the substitute, eyes highlighted in green.

Datasets

The models were trained and evaluated on a dataset of English poetry:

  • Source: English language poems extracted from Project Gutenberg using the GutenTag tool.
  • Size: 757,891 quatrains, filtered to ensure clean structural formatting.
  • Vocabulary: Limited to the 50,000 most frequent words, utilizing character-aware representations to capture sub-word rhyming patterns.
  • Conditioning Factors: The dataset was labeled with the top 768 most frequent authors and the top 50 most common eight-verse rhyme schemes.

Key Insights and Ideas

  • Decoupling the Action Space: Jointly deciding which word to change and what to change it to results in a massive action space ($|V| \times m$, where $V$ is vocabulary size and $m$ is poem length). By splitting this into a Detector (RL-driven) and a Prompter (standard language model), the RL agent's action space is drastically reduced to just the length of the poem ($m$), making RL training feasible.
  • The Superiority of PPO over VPG: While Vanilla Policy Gradient (VPG) is commonly used in text-based RL applications, it proved highly unstable in this environment. Proximal Policy Optimization (PPO), with its clipped surrogate objective, successfully prevented catastrophic policy collapses and allowed the agent to steadily learn complex structural rules.
  • Emergent Structural Awareness: Without explicit instructions, the detector naturally learns to focus its editing actions on the final words of each verse, discovering on its own that these positions are the ones responsible for satisfying rhyming schemes.

Key Results

The authors evaluated their framework on both a controlled "poem reconstruction" task (fixing artificially corrupted text) and the full "generate-and-revise" pipeline.

  • Language Modeling Quality: Incorporating conditional features (author and rhyme scheme) improved the perplexity of the poem generator (dropping from 59.78 to 54.86) and the prompter (dropping from 14.78 to 13.40).
  • RL Optimization: PPO significantly outperformed VPG across all test environments. In an evaluation using 100 poems, VPG failed to converge (stagnating at a final reward of -19.264), whereas PPO steadily improved from an initial reward of -15.598 to -5.200.

The qualitative impact of these revisions can be seen in the successful adjustments made to match target rhyme schemes:

Two examples of generated poems with generate and revise approach given a target rhyme scheme, before and after the revision iterative steps.

Limitations and Future Work

  • Lack of Human Evaluation: The authors relied entirely on automated reward metrics (verifying if a rhyming scheme was mathematically satisfied). They did not conduct human studies to evaluate the semantic coherence or aesthetic quality of the revised poems.
  • Potential for Semantic Drift: While the prompter ensures local context compatibility, optimizing purely for a structural rhyme reward can cause the poem's overarching meaning to drift during long revision cycles.
  • Broader Applications: The framework is fundamentally general. The authors suggest that with appropriate reward shaping, this generate-and-revise approach could be applied to other text-editing tasks such as style transfer, text simplification, or paraphrasing.

Summary updated

Abstract

Writers, poets, singers usually do not create their compositions in just one breath. Text is revisited, adjusted, modified, rephrased, even multiple times, in order to better convey meanings, emotions and feelings that the author wants to express. Amongst the noble written arts, Poetry is probably the one that needs to be elaborated the most, since the composition has to formally respect predefined meter and rhyming schemes. In this paper, we propose a framework to generate poems that are repeatedly revisited and corrected, as humans do, in order to improve their overall quality. We frame the problem of revising poems in the context of Reinforcement Learning and, in particular, using Proximal Policy Optimization. Our model generates poems from scratch and it learns to progressively adjust the generated text in order to match a target criterion. We evaluate this approach in the case of matching a rhyming scheme, without having any information on which words are responsible of creating rhymes and on how to coherently alter the poem words. The proposed framework is general and, with an appropriate reward shaping, it can be applied to other text generation problems.

Empirical ResultsBrowse all benchmarks →

BenchmarkMethodMetricScoreProtocol / Evidence
Poem generator, Test setConditional GeneratorPerplexity54.86Poetry Generation · split: test · conditioning=author-and-rhyme-scheme · rhyme-schemes=50 most frequent eight-verse schemes
Source quote
L223: Conditional Generator │ 51.40 │ 54.86
Poem generator, Test setVanilla GeneratorPerplexity59.78Poetry Generation · split: test · conditioning=none · rhyme-schemes=50 most frequent eight-verse schemes
Source quote
L222: Vanilla Generator │ 52.98 │ 59.78
Prompter module, Test setConditional PrompterPerplexity13.40Language Modeling · split: test · input=single quatrains · conditioning=poem-related features
Source quote
L235: Conditional Prompter │ 12.90 │ 13.40
Prompter module, Test setVanilla PrompterPerplexity14.78Language Modeling · split: test · input=single quatrains · conditioning=none
Source quote
L234: Vanilla Prompter │ 14.09 │ 14.78
Generate-and-revise poem task, 10 poemsPPOAverage R reward-1.186+13.44 vs baselinePoetry Generation · poems=10 · algorithm=PPO · episode-limit=30 steps · training-steps-per-volley=10000
Source quote
L308: PPO │ -10.239 │ -1.186
Reported baseline / comparator measurements (1)
BenchmarkMethodMetricScoreProtocol / Evidence
Generate-and-revise poem task, 10 poemsVPG baselineAverage R reward-14.630Poetry Generation · poems=10 · algorithm=VPG · episode-limit=30 steps · training-steps-per-volley=10000
Source quote
L307: VPG │ \multirow{2}{*}{10} │ -18.752 │ -14.630
BibTeX
@misc{zugarini2021generate,
  author = {Andrea Zugarini and Luca Pasqualini and Stefano Melacci and Marco Maggini},
  title = {{Generate and Revise: Reinforcement Learning in Neural Poetry}},
  year = {2021},
  eprint = {2102.04114},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2102.04114},
}

Loading related content...

Figure