Abstract
Poetry generation is an interesting research topic in the field of text generation. As one of the most valuable literary and cultural heritages of China, Chinese classical poetry is very familiar and loved by Chinese people from generation to generation. It has many particular characteristics in its language structure, ranging from form, sound to meaning, thus is regarded as an ideal testing task for text generation. In this paper, we propose a GPT-2 based uniformed framework for generating major types of Chinese classical poems. We define a unified format for formulating all types of training samples by integrating detailed form information, then present a simple form-stressed weighting method in GPT-2 to strengthen the control to the form of the generated poems, with special emphasis on those forms with longer body length. Preliminary experimental results show this enhanced model can generate Chinese classical poems of major types with high quality in both form and content, validating the effectiveness of the proposed strategy. The model has been incorporated into Jiuge, the most influential Chinese classical poetry generation system developed by Tsinghua University.
Introduction
Chinese classical poetry is defined by a rigorous trinity of form, sound, and meaning. While modern AI has become adept at generating SHI (which typically has a fixed number of lines and characters, like the four-line Jueju), it has historically struggled with CI.
CI is significantly more complex than SHI; it consists of over 1,000 distinct "forms" (Cipai), each with its own specific requirements for line length and stanza breaks. Previous models often "lost the thread" during generation, missing characters or failing to end stanzas correctly, especially in longer poems. The challenge lies in teaching a language model to respect strict, variable structural constraints while maintaining semantic beauty and thematic coherence.
Methodology
Researchers from Tsinghua University moved away from traditional Encoder-Decoder architectures in favor of a unified GPT-2 framework. Their approach consists of two primary innovations designed to treat structure as a first-class citizen.
Unified Pre-processing Format
Instead of treating different poem types as separate tasks, the researchers formulated all training samples into a single string format: [CLS]form[#]title[*]body[EOS]. As shown in the training pipeline, specific labels are used to demarcate the form name (#), title (*), and stanzas (&). This allows a single model to learn the relationship between a specific Cipai (form) and its required structure.
Form-Stressed Weighting
Standard language models treat every token's loss equally. However, for constrained forms like poetry, structural markers (like commas or stanza breaks) are the most critical tokens to get right. The authors modified the cross-entropy loss function to assign higher weights to these markers:
- Weight 1: Standard Chinese characters.
- Weight 2: Line and stanza separators.
- Weight 3: The End-of-File (
[EOF]) token.
This "form-stressed weighting" forces the model to prioritize learning when to end a line or a poem, significantly reducing structural "drift" in longer compositions.
Datasets and Evaluation
The study utilized the CCPC1.0 (Chinese Classical Poetry Corpus), containing 834,902 poems. While the dataset is dominated by SHI (92.87%), the researchers focused on the top 121 most frequent Cipai to handle the "long tail" of CI forms. For detailed testing, they selected 6 specific Cipai with body lengths ranging from 33 to 114 characters to test the model's limits.
Key Results
The "Enhanced Model" (with stressed weighting) showed dramatic improvements over a standard GPT-2 baseline, particularly as poem length increased:
- Complex Long Forms: For the Qinyuanchun form (114 characters), structural correctness leaped from 12.0% to 55.0%.
- Medium Forms: For Manjianghong (93 characters), correctness rose from 42.1% to 83.3%.
- Standard Forms: For shorter CI and fixed SHI, the model achieved nearly 100% structural accuracy.
Beyond formal correctness, the model demonstrated an ability to maintain Duizhang (parallelism in parts of speech and sense between lines), a hallmark of high-quality classical poetry.
Conclusion
By integrating form-stressed weighting into a unified GPT-2 framework, this research demonstrates that large language models can be steered to respect complex structural constraints without sacrificing semantic quality. While long-form poetry remains a challenge—with nearly half of the longest poems still containing errors—the progress is substantial. This model has been successfully integrated into Jiuge, one of the world's most influential Chinese poetry generation systems, providing a robust tool for cultural preservation and creative exploration.
Summary updated