This is the code for a Final Year Project : Stylistic Classical Chinese Poem Generation – The anatomy of an AI poet The report of this project could be found at NTU Library.
This project consists of three parts and is dedicated to build an AI poem generator that can generate stylistic classical Chinese poems based on user input keywords.
Firstly, this project will build a Chinese poetry generator using the sequence-to-sequence model. Then, the project will explore unsupervised and supervised machine learning algorithms to classify Chinese poems by style. Finally, this project will integrate the results of the first two parts and use stylized data to train the Chinese poetry generator.
The result is a successful model that generates Chinese poems based on the keywords entered by the user and the style chosen.
The methodology contains 3 parts in total, as shown in the following slides:

The poem generator is built based on the Working Memory model, refering to Xiaoyuan Yi's work at (https://github.com/THUNLP-AIPoet/WMPoetry)
Part 2 tried both supervised Machine Learning method and unsupervised Machine Learning method.
For Unsupervised ML Method, the code is included in clustering.ipynb
for supervised ML method, the code is included in /sv_ML/ml_ccpc.ipynb.
By running this notebook, a few csv file will be generated. these files have been uploaded to /sv_ML for reference, noted that the generated result might be different everytime runing the file.
The following picture shows an flow chart of classification using ML method.
The code is included in the retrain.py.
After Part 2 is done, all data generated will need to be combined with result from part 1.
All parameters should be modified accordingly.
Here is a flowchart of this part
Given the same keywords as Wind and Flower, and genre pattern as 1, generating 7-character quatrain.

