这是一个使用 seq2seq模型实现人工智呢对对联的工具,基于TensorFlow ,fork自王斌的Github项目,原作者的demo在这里这里.
- Tensorflow
- Python 3.6
- Dataset
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 <s>
and <\s>
as the first two line into the vocabs file. **
Open couplet.py
and config the file locations and hyperparams. Then run python couplet.py
to train the model. You can see the training loss and bleu score at Tensorbloard. You may need to re-config learning_rate
when 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 restore_model
to True
and use m.train(<epoches>, start=<start>)
, which start
is the steps you've already run.
Open server.py
and config the vocab_file
and model_dir
params. Then run python server.py
will start a web service that can play couplet.
Here are some examples generated by this model:
上联 | 下联 |
---|---|
殷勤怕负三春意 | 潇洒难书一字愁 |
如此清秋何吝酒 | 这般明月不须钱 |
天朗气清风和畅 | 云蒸霞蔚日光辉 |
梦里不知身是客 | 醉时已觉酒为朋 |
千秋月色君长看 | 一夜风声我自怜 |