Abstract
Researchers at Duke University have developed "The Mechanical Bard," a system that generates Shakespearean sonnets by combining the creative power of GPT-2 with a rigorous, interpretable framework of human-curated linguistic templates. By explicitly enforcing constraints on meter, rhyme, and part-of-speech (POS) structure, the model produces poetry that outperforms existing baselines in grammatical correctness and poetic quality. This approach demonstrates that for highly structured creative tasks, explicit rule enforcement is superior to implicit learning in large language models.
Introduction
While Large Language Models (LLMs) like GPT-4 are remarkably good at generating fluent text, they often struggle with the "hard constraints" of formal poetry. A Shakespearean sonnet is a mathematical puzzle requiring exactly 14 lines, a strict ABAB CDCD EFEF GG rhyme scheme, and a consistent iambic pentameter (ten syllables of alternating unstressed and stressed beats).
Most modern approaches attempt to teach models these rules implicitly through massive datasets. However, this often leads to "hallucinated" rhymes or broken meters. The authors of "The Mechanical Bard" argue that for highly structured forms, we should not rely on the model to guess the rules; instead, we should enforce them explicitly through a transparent, interpretable generation process.
Methodology
The authors utilize a constrained decoding approach using a fine-tuned GPT-2 backbone. The pipeline is divided into three primary phases: pre-processing, a main generation loop, and final processing.
Key Components of the Pipeline:
- POS Templating: The system uses 120 handcrafted grammar templates derived from Shakespeare’s own work (e.g.,
THE NN OF NN ON A JJ NN). - Hard Constraint Enforcement: Utilizing the CMU Pronouncing Dictionary, the system ensures every word fits the required iambic pentameter pattern (0 1 0 1 0 1 0 1 0 1).
- Constrained Beam Search: During generation, the model filters out any word that violates the POS template, meter, or rhyme scheme.
- Thematic Integration: WordNet and FastText embeddings are used to select "thematic words" related to a user prompt, which are then strategically placed to anchor the rhyme scheme.
- Poetic Scoring: A custom function rewards "soft" poetic devices like alliteration while penalizing repetitive vocabulary.
Evaluation and Results
The model was fine-tuned on a corpus of 15,000 poems and a specialized set of Shakespearean sonnets. It was evaluated against human-written sonnets and two baselines: PoeTryMe and Benhardt et al. (2018). Evaluation involved both expert annotators from academic English departments and crowd workers via Amazon MTurk.
As shown in the comparative trials, "The Mechanical Bard" was a clear winner:
- Grammatical Superiority: In many tests, the model’s grammatical structure was rated so highly that it was nearly indistinguishable from human-written poetry to non-expert workers.
- Expert Consensus: Experts rated the model significantly higher than both baselines in Grammar, Emotion, and Poeticness (p < 0.05).
- Thematic Adherence: While the model excelled at structure, it occasionally struggled with "Theme" compared to baselines that simply repeated prompt words more frequently. However, the authors note their approach produces more lyrical, less repetitive content.
Discussion and Future Work
The most significant takeaway is that for structured creative writing, explicitly enforcing rules via templates is more effective than hoping a large model learns them implicitly. This makes the model "interpretable," as every word choice can be traced back to an underlying grammar template.
Despite these successes, the authors acknowledge limitations in narrative cohesion across all 14 lines. Expert readers can still distinguish these poems from human-authored ones, noting that humans often use intentional "meter-breaking" for emphasis—a nuance the model’s rigid constraints do not yet allow. Future work may involve applying these constrained decoding techniques to larger models like Llama 3 to combine massive world knowledge with rigid poetic templates.
Summary updated