数学建模社区-数学中国

标题: 深度学习实现对对联 [打印本页]

作者: 2744557306    时间: 2024-4-19 15:59
标题: 深度学习实现对对联
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.
Pre-requirementsDataset
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. **
UsageTrain
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.
I've trained the model on a Nvidia GTX-1080 GPU for about 4 days.
Run the trained model
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.
Or build the Docker image with Dockerfile and run it with Docker. Remember to mount the correct model file paths into the Docker container.
Examples
Here are some examples generated by this model:
[td]
  • 上联
    ) r! W8 G, R0 k# l
  • 下联
    6 Q! k6 [9 g4 H/ O- [
  • 殷勤怕负三春意+ i, e3 D4 ^; R
  • 潇洒难书一字愁/ @" X( D1 T' d% u& J) t
  • 如此清秋何吝酒
    8 \. i8 q: ?, E9 J6 S4 i% r
  • 这般明月不须钱
    : n- N+ c+ @8 G. n) D' t' |
  • 天朗气清风和畅' y8 h8 l) o) p7 {% `$ {
  • 云蒸霞蔚日光辉
    7 ]; E6 v1 o, e2 A. I
  • 梦里不知身是客# f% q1 ^. o- {: n: }& E& X
  • 醉时已觉酒为朋
    % |: ^' H2 d2 F; f1 f5 L# g; k3 z
  • 千秋月色君长看
    - y+ F$ U2 E7 X7 [  b5 a! x
  • 一夜风声我自怜
    5 ~3 u5 P1 N) P/ ~/ q
0 x% ~" Q1 X( a. v
  \4 @" P+ y/ R* U1 l
! k/ |; |& \% p( i% j1 ]. V

seq2seq-couplet-master.zip

24.48 KB, 下载次数: 0, 下载积分: 体力 -2 点

售价: 2 点体力  [记录]  [购买]






欢迎光临 数学建模社区-数学中国 (http://www.madio.net/) Powered by Discuz! X2.5