Play couplet with seq2seq model. 用深度学习对对联。
This is a project use seq2seq model to play couplets (对对联)。 This project is written with Tensorflow. You can try the demo at https://ai.binwang.me/couplet.
You will need some data to run this program, the dataset can be downloaded from this project.
** Note: If you are using your own dataset, you need to add
and as the first two line into the vocabs file. **
couplet.pyand config the file locations and hyperparams. Then run
python couplet.pyto train the model. You can see the training loss and bleu score at Tensorbloard. You may need to re-config
learning_ratewhen you find the loss stops descresing. Here is an example of the loss graph:
If you stoped the training and want to continue to train it. You can set
m.train(, start=), which
startis the steps you've already run.
I've trained the model on a Nivida GTX-1080 GPU for about 4 days.
server.pyand config the
model_dirparams. Then run
python server.pywill start a web service that can play couplet.
Or build the Docker image with Dockerfile and run it with Docker. Remember to mount the correct model file paths into the Docker container.
Here are some examples generated by this model:
| 上联 | 下联 | |-----------------------------|--------------------| | 殷勤怕负三春意 | 潇洒难书一字愁 | | 如此清秋何吝酒 | 这般明月不须钱 | | 天朗气清风和畅 | 云蒸霞蔚日光辉 | | 梦里不知身是客 | 醉时已觉酒为朋 | | 千秋月色君长看 | 一夜风声我自怜 |