Column
Author: yonggege, author of Python Chinese community column
GitHub Address: https://github.com/wzyonggege
0. char-rnn
There are already many introductions about RNN, LSTM, and GRU. The char-rnn is a multi-layer RNN network. This time, we will use the Tensorflow version of sherjilozair/char-rnn-tensorflow to input a large number of ancient poems and let the machine learn to create by itself.
1. Usage
Environment
Python 3.6
Tensorflow 1.2.0
Usage
Help
Command line display:
<span>Training sample data</span>
Generate ancient poetry
The training above may take some time, but you can reduce the amount of data for training (ignore if using GPU).
After training is complete:
Ancient poetry can be generated:
(You can choose how many high-frequency Chinese characters to select. If the model generates characters not in the selected dictionary, use ‘*’ as a substitute)
South dawn string gate connects red terrace,
Evening comes with orchid railing and wine plate bent.
Old friends, no age, the river water flows long,
Two tears let the body’s tassel be full of tears.
(Let’s not care about the content for now~~)
Generate acrostic poetry
Next year the collar is favored,
The moon rises, painting the bed curtain.
There’s another regret for the lord of Pingzhou,
Branches bend, picking the plum and mulberry.
Surprised by the waist, every year the three heroes,
The magpie comes out, crossing the clock with jade flute frequently.
Let’s do another one
Brightly falling east and west,
The moon washes the brocade and silk.
The month is fresh and light,
Branches compete with birds.
Surprised by the original feather festival,
The magpie tower blows the mulberry shirt.
2. Finally
Code code: github.com/wzyonggege/RNN_poetry_generator (Welcome to Star)

Long press to scan and follow the Python Chinese community,
Get more technical content!
Python Chinese Community
The spiritual home of Python Chinese developers
For cooperation and submission, please contact WeChat:
pythonpost
This article is an original work by the author, and reproduction is prohibited without the author’s authorization.
The community plans to establish city clubs in Beijing, Shanghai, Shenzhen, Guangzhou, Hong Kong, Hangzhou, Chengdu, Nanjing, Wuhan, Xi’an ten cities to facilitate deeper communication among local Python developers, and also to facilitate future online and offline events. Welcome everyone to join! Please directly add staff WeChat: pythonpost and indicate the city to apply.