Code Monkey home page Code Monkey logo

mojitalk's Introduction

MojiTalk

Xianda Zhou, and William Yang Wang. 2018. Mojitalk: Generating emotional responses at scale. In Proceedings of the 56th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), pages 1128–1137. Association for Computational Linguistics.

Paper: https://arxiv.org/abs/1711.04090

Our lab: http://nlp.cs.ucsb.edu/index.html

Emojis

The file emoji-test.txt (http://unicode.org/Public/emoji/5.0/emoji-test.txt) provides data for loading and testing emojis. The 64 emojis that we used in our work are marked with '64' in our modified emoji-test.txt file.

Unicode and the Unicode Logo are registered trademarks of Unicode, Inc. in the U.S. and other countries.

For terms of use, see http://www.unicode.org/terms_of_use.html

Dependencies

  • Python 3.5.2
  • TensorFlow 1.2.1

Usage

  1. Preparation:

    Set up an environment according to the dependencies.

    Dataset: https://drive.google.com/file/d/1l0fAfxvoNZRviAMVLecPZvFZ0Qexr7yU/view?usp=sharing

    Unzip mojitalk_data.zip to the current path, creating mojitalk_data directory where our dataset is stored. Read the readme.txt in it for the format of the dataset.

  2. Base model:

    1. Set the is_seq2seq variable in the cvae_run.py to True

    2. Train, test and generate: python3 cvae_run.py

      This will save several breakpoints, a log file and generation output in mojitalk_data/seq2seq/<timestamp>/

  3. CVAE model:

    1. Set the is_seq2seq variable in the cvae_run.py to False

    2. Set path of pretrain model: Modify line 67 of cvae_run.py to load a previously trained base model. e.g.: saver.restore(sess, "seq2seq/07-17_05-49-50/breakpoints/at_step_18000.ckpt")

    3. Train, test and generate: python3 cvae_run.py

      This will save several breakpoints, a log file and generation output in mojitalk_data/cvae/<timestamp>/.

      Note that the choice of base model breakpoint as the pretrain setting would influence the result of CVAE training. A overfitted base model may cause the CVAE to diverge.

  4. Reinforced CVAE model:

    1. Train the emoji classifier: CUDA_VISIBLE_DEVICES=0 python3 classifier.py

      The trained model will be saved in mojitalk_data/classifier/<timestamp>/breakpoints as a tensorflow breakpoint.

    2. Set path of pretrain model: Modify line 63/74 of rl_run.py to load a previously trained CVAE model and the classifier.

    3. Train, test and generate: python3 rl_run.py

      This will save several breakpoints, a log file and generation output in mojitalk_data/cvae/<timestamp>/.

mojitalk's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

mojitalk's Issues

Twitter Conversations dataset

Need code of collecting large corpus of twitter conversations. I want to collect datasets of different language then will apply it in code to check accuracy..

Why not choose the breakpoint with lowest test perplexity?

2019-07-23 09-28-47屏幕截图

Recently, I've been reproducing the paper's result using the oringinal data and this code.
The picture is a visulization from tensorboard, with record of testing perplexity from every 500 step. And from this picture, I noticed that the last step (ppl:37.76) doesn't have the lowest test perplexity (ppl:25.11). However, the value of the last step consists with paper's result(ppl:36.9) .
So, why not choose the breakpoint with lowest test perplexity? Or, what is the criterion of the convergence of the model?

failed to replicate the result of top1, top5 acc for CVAE model

Hi,

I am trying to replicate your chatbot model. I did exactly the same thing as you mentioned in the README. I got more or less similar kl/reconstruction loss for training CVAE. But for emoji classification, top1 and top5 acc for CVAE model is only 30.4% and 54.3%, which is much worse than the results you reported in the paper. Can you give some suggestions about this?

Thanks
Peng

Question regarding testing perplexity

Hi,
I read your Mojitalk paper, awesome work!

Currently, I am trying to implement your idea in Pytorch. To have a better understanding of your model, I run the code by following the README.

But when I run the CVAE model, I found that the test ppl keep going down when kl loss is increasing. And when I check the cvae.py, I found that the test perplexity seems compute from the posterior latent variable ( the ppl in line 375 is compute by self.recon_loss in line 350 which is computed from self.logits in line 189) (correct me if I am wrong).

Can you give me some hint if I misunderstanding the code and how can I check the correct testing perplexity?

Any help will be appreciated

epoch:1 step:50 107.772 8.862 103.999 07-04 06:52:00
epoch:1 step:100 66.716 6.783 80.515 07-04 06:52:15
epoch:1 step:150 59.133 12.280 78.834 07-04 06:52:29
epoch:1 step:200 57.889 25.170 78.986 07-04 06:52:44
epoch:1 step:250 55.883 43.336 76.627 07-04 06:52:58
epoch:1 step:300 54.112 53.837 74.991 07-04 06:53:12
epoch:1 step:350 53.740 62.803 74.956 07-04 06:53:27
epoch:1 step:400 53.413 67.724 74.822 07-04 06:53:41
epoch:1 step:450 51.944 73.110 73.094 07-04 06:53:55
epoch:1 step:500 50.910 76.195 72.120 07-04 06:54:10
ori: i wanna go to hogwarts 07-04 06:55:16
rep: i want you to dm me 07-04 06:55:16
out: i 'm not invited i 'm not sure if you want me 07-04 06:55:16
epoch:1 step:500 TEST: recon/kl/bow-loss/ppl: 53.567 77.448 72.427 96.638 BLEU: 1.4 12.4 2.1 0.7 0.5
epoch:1 step:550 50.457 79.110 71.642 07-04 06:55:31
epoch:1 step:600 50.210 82.170 71.375 07-04 06:55:45
epoch:1 step:650 50.255 83.785 71.806 07-04 06:56:00
epoch:1 step:700 50.370 85.665 72.159 07-04 06:56:14
epoch:1 step:750 49.413 87.583 71.147 07-04 06:56:29
epoch:1 step:800 47.874 89.143 69.159 07-04 06:56:43
epoch:1 step:850 49.001 90.527 70.603 07-04 06:56:58
epoch:1 step:900 48.153 92.090 69.637 07-04 06:57:12
epoch:1 step:950 47.983 92.865 69.860 07-04 06:57:27
epoch:1 step:1000 47.925 94.706 69.635 07-04 06:57:41
ori: so just let she get lost way in fat ? ! and saying nothing ain 't gonna let her assume he is ok with her size ? 07-04 06:58:45
rep: tell her what you wanna say then 07-04 06:58:45
out: is the only one who said she 's a 😂 07-04 06:58:45
epoch:1 step:1000 TEST: recon/kl/bow-loss/ppl: 49.397 95.820 69.092 67.706 BLEU: 1.4 12.5 1.9 0.6 0.4
epoch:1 step:1050 47.384 95.038 68.745 07-04 06:59:00
epoch:1 step:1100 46.979 96.737 68.473 07-04 06:59:14
epoch:1 step:1150 46.943 97.259 68.621 07-04 06:59:28
epoch:1 step:1200 46.183 98.846 67.678 07-04 06:59:43
epoch:1 step:1250 46.427 99.554 68.186 07-04 06:59:58
epoch:1 step:1300 46.802 100.394 68.827 07-04 07:00:13
epoch:1 step:1350 46.464 100.820 68.449 07-04 07:00:27
epoch:1 step:1400 45.051 101.957 66.653 07-04 07:00:42
epoch:1 step:1450 45.727 102.452 67.607 07-04 07:00:56
epoch:1 step:1500 45.663 103.391 67.704 07-04 07:01:11
ori: not on my dime ! 07-04 07:02:14
rep: oh sorry , i didn 't realized you paid marshawn 07-04 07:02:14
out: now i 'm guessing it 's * 07-04 07:02:14
epoch:1 step:1500 TEST: recon/kl/bow-loss/ppl: 46.453 103.390 66.948 52.665 BLEU: 1.4 12.9 1.8 0.6 0.5
epoch:1 step:1550 45.080 103.456 66.981 07-04 07:02:29
epoch:1 step:1600 45.106 104.186 67.228 07-04 07:02:43
epoch:1 step:1650 44.463 104.330 66.302 07-04 07:02:58
epoch:1 step:1700 44.272 104.390 66.137 07-04 07:03:13
epoch:1 step:1750 44.144 105.010 66.103 07-04 07:03:27
epoch:1 step:1800 44.079 105.536 66.387 07-04 07:03:42
epoch:1 step:1850 44.267 105.570 66.333 07-04 07:03:57
epoch:1 step:1900 43.953 105.579 66.048 07-04 07:04:11
epoch:1 step:1950 44.030 106.264 66.265 07-04 07:04:25
epoch:1 step:2000 43.110 106.592 65.141 07-04 07:04:40
ori: ok good luck with that wish i felt that optimistic two wins next week will help me with that though 07-04 07:05:43
rep: when we beat reading tuesday evening you and % of the other negative minded will turn 07-04 07:05:43
out: that 's the only thing i know ! i 'll get it done 07-04 07:05:43
epoch:1 step:2000 TEST: recon/kl/bow-loss/ppl: 44.820 106.662 65.731 45.814 BLEU: 1.4 12.9 1.8 0.7 0.5
epoch:1 step:2050 43.850 106.989 66.077 07-04 07:05:58
epoch:1 step:2100 43.939 106.820 66.364 07-04 07:06:12
epoch:1 step:2150 42.929 107.280 64.857 07-04 07:06:27
epoch:1 step:2200 43.720 107.659 66.076 07-04 07:06:42
epoch:1 step:2250 42.856 107.565 65.242 07-04 07:06:56
epoch:1 step:2300 42.994 108.041 65.561 07-04 07:07:11
epoch:1 step:2350 42.776 108.275 65.423 07-04 07:07:26
epoch:1 step:2400 42.062 108.446 64.283 07-04 07:07:40
epoch:1 step:2450 43.076 108.430 65.497 07-04 07:07:55
epoch:1 step:2500 41.953 109.105 64.415 07-04 07:08:09
ori: thank you . very sweet . 07-04 07:09:14
rep: no problem at all 😇 is this your today 07-04 07:09:14
out: you know i 'm very thankful to hear you 07-04 07:09:14
epoch:1 step:2500 TEST: recon/kl/bow-loss/ppl: 43.247 109.860 64.690 40.059 BLEU: 1.4 12.3 1.6 0.6 0.4
epoch:1 step:2550 42.303 109.411 64.942 07-04 07:09:28
epoch:1 step:2600 42.119 109.258 64.836 07-04 07:09:43
epoch:1 step:2650 41.875 109.742 64.433 07-04 07:09:58
epoch:1 step:2700 41.382 109.555 63.651 07-04 07:10:12
epoch:1 step:2750 41.650 109.979 64.128 07-04 07:10:26
epoch:1 step:2800 41.436 109.846 63.863 07-04 07:10:41
epoch:1 step:2850 42.173 110.037 65.052 07-04 07:10:56
epoch:1 step:2900 41.014 110.504 63.471 07-04 07:11:11
epoch:1 step:2950 41.921 110.418 64.545 07-04 07:11:25
epoch:1 step:3000 40.486 110.566 63.036 07-04 07:11:40
ori: exactly ! but heyy if they do it to me then i do the same ! no need to waste my time if they won't ! 07-04 07:12:44
rep: i still try to give them love . i never want to be anything but genuine and real , even if it 's painful 07-04 07:12:44
out: lol i will just pay for them and . 07-04 07:12:44
epoch:1 step:3000 TEST: recon/kl/bow-loss/ppl: 41.839 111.107 63.764 35.526 BLEU: 1.4 12.9 1.6 0.6 0.4
epoch:1 step:3050 41.919 110.596 64.953 07-04 07:12:59
epoch:1 step:3100 41.268 110.967 63.885 07-04 07:13:14
epoch:1 step:3150 40.857 110.668 63.537 07-04 07:13:28
epoch:1 step:3200 41.346 110.425 64.017 07-04 07:13:43
epoch:1 step:3250 41.325 110.689 64.208 07-04 07:13:57
epoch:1 step:3300 41.175 110.971 64.111 07-04 07:14:12
epoch:1 step:3350 40.460 111.110 63.247 07-04 07:14:27
epoch:1 step:3400 40.388 110.900 63.333 07-04 07:14:42
epoch:1 step:3450 40.708 110.972 63.361 07-04 07:14:56
epoch:1 step:3500 41.294 111.122 64.673 07-04 07:15:11
ori: fact : i mostly wear shirts at work , even in winter 07-04 07:16:14
rep: i do the same 07-04 07:16:14
out: i just ordered but that 's ok 07-04 07:16:14
epoch:1 step:3500 TEST: recon/kl/bow-loss/ppl: 40.906 111.368 62.898 32.807 BLEU: 1.3 12.9 1.5 0.6 0.5
epoch:1 step:3550 39.530 111.451 62.172 07-04 07:16:28
epoch:1 step:3600 39.722 111.568 62.649 07-04 07:16:43
epoch:1 step:3650 40.440 111.326 63.306 07-04 07:16:58
epoch:1 step:3700 39.940 111.654 62.639 07-04 07:17:12
epoch:1 step:3750 40.446 111.495 63.478 07-04 07:17:27
epoch:1 step:3800 39.550 111.542 62.342 07-04 07:17:42
epoch:1 step:3850 39.261 111.786 62.139 07-04 07:17:56
epoch:1 step:3900 39.018 111.993 61.844 07-04 07:18:11
epoch:1 step:3950 39.622 112.127 62.840 07-04 07:18:26
epoch:1 step:4000 39.254 112.019 62.254 07-04 07:18:40
ori: i 'm going to my first pure class tomorrow , y'all pray for me 07-04 07:19:45
rep: update : that was the most intense workout session i 've ever done and i hated it during , but once i finished i felt accomplished af 07-04 07:19:45
out: you got to experience with that shit ! 07-04 07:19:45
epoch:1 step:4000 TEST: recon/kl/bow-loss/ppl: 39.753 112.672 62.152 29.733 BLEU: 1.4 12.8 1.7 0.6 0.4
epoch:1 step:4050 39.150 112.282 62.253 07-04 07:20:00
epoch:1 step:4100 39.070 112.243 62.233 07-04 07:20:14
epoch:1 step:4150 39.453 112.296 62.575 07-04 07:20:29
epoch:1 step:4200 39.535 112.161 62.902 07-04 07:20:44
epoch:1 step:4250 38.959 112.104 62.073 07-04 07:20:58
epoch:1 step:4300 39.917 112.226 63.286 07-04 07:21:13
epoch:1 step:4350 38.800 112.241 62.194 07-04 07:21:27
epoch:1 step:4400 38.333 112.360 61.498 07-04 07:21:42
epoch:1 step:4450 38.271 112.235 61.310 07-04 07:21:56
epoch:1 step:4500 38.895 112.136 62.119 07-04 07:22:11
ori: yupp its all about the race that is why jennifer picked the twins 07-04 07:23:15
rep: that or her picked the twins she does like the young backup dancers ! 07-04 07:23:15
out: i think of a great game , just shows in that case 07-04 07:23:15
epoch:1 step:4500 TEST: recon/kl/bow-loss/ppl: 38.916 112.277 61.664 27.683 BLEU: 1.3 12.7 1.5 0.6 0.5
epoch:1 step:4550 38.592 111.983 61.859 07-04 07:23:29
epoch:2 step:4600 36.704 112.468 60.710 07-04 07:23:52
epoch:2 step:4650 36.916 112.579 60.974 07-04 07:24:06
epoch:2 step:4700 36.802 113.059 60.884 07-04 07:24:21
epoch:2 step:4750 36.441 113.294 60.424 07-04 07:24:35
epoch:2 step:4800 36.765 113.232 60.900 07-04 07:24:50
epoch:2 step:4850 35.857 113.385 59.553 07-04 07:25:04
epoch:2 step:4900 36.527 113.063 60.646 07-04 07:25:19
epoch:2 step:4950 36.291 113.276 60.248 07-04 07:25:34
epoch:2 step:5000 36.539 113.242 60.408 07-04 07:25:48
ori: i wish i had more time to write domestic fluff porn ! it 's my absolute favorite kind . 😍 you should write some ! ;) 07-04 07:26:54
rep: i cannot . i write like a semi , illiterate with an for words like " first " and " never " . 07-04 07:26:54
out: yeah , i do like a new artist too . i 'm so excited to hear 07-04 07:26:54
epoch:2 step:5000 TEST: recon/kl/bow-loss/ppl: 38.448 113.298 61.266 26.599 BLEU: 1.4 12.7 1.6 0.6 0.4
epoch:2 step:5050 36.711 113.128 60.733 07-04 07:27:09
epoch:2 step:5100 36.484 113.213 60.498 07-04 07:27:23
epoch:2 step:5150 36.682 113.061 60.800 07-04 07:27:38
epoch:2 step:5200 36.266 112.851 60.212 07-04 07:27:53
epoch:2 step:5250 36.285 112.921 60.291 07-04 07:28:07
epoch:2 step:5300 36.537 112.519 60.672 07-04 07:28:22
epoch:2 step:5350 36.253 112.649 60.193 07-04 07:28:36
epoch:2 step:5400 35.857 112.646 59.776 07-04 07:28:51
epoch:2 step:5450 35.621 112.336 59.680 07-04 07:29:06
epoch:2 step:5500 36.168 112.244 60.084 07-04 07:29:20
ori: any people out there know if u can have another t have editing rights to your ? 07-04 07:30:24
rep: 👋 hi not currently but we are exploring different ways to achieve this . 07-04 07:30:24
out: hey , there are no one in the internet section , i 'm sorry to hear this 07-04 07:30:24
epoch:2 step:5500 TEST: recon/kl/bow-loss/ppl: 38.012 111.894 60.805 25.628 BLEU: 1.4 12.7 1.6 0.6 0.4
epoch:2 step:5550 36.571 112.210 60.714 07-04 07:30:39
epoch:2 step:5600 35.773 112.046 59.761 07-04 07:30:54
epoch:2 step:5650 36.230 111.600 60.156 07-04 07:31:08
epoch:2 step:5700 36.226 111.281 60.418 07-04 07:31:23
epoch:2 step:5750 35.539 111.378 59.414 07-04 07:31:37
epoch:2 step:5800 35.504 111.290 59.500 07-04 07:31:52
epoch:2 step:5850 36.859 111.043 61.241 07-04 07:32:06
epoch:2 step:5900 36.067 110.778 60.159 07-04 07:32:21
epoch:2 step:5950 36.104 111.007 60.192 07-04 07:32:35
epoch:2 step:6000 35.800 110.598 59.615 07-04 07:32:49
ori: i might become a k pop artist ? wht y'all think ? 07-04 07:33:54
rep: i 'm with it 07-04 07:33:54
out: also i 'm guessing they just released a song from gfriend 07-04 07:33:54
epoch:2 step:6000 TEST: recon/kl/bow-loss/ppl: 37.665 110.306 60.407 24.881 BLEU: 1.3 12.2 1.5 0.6 0.4
epoch:2 step:6050 35.593 110.399 59.619 07-04 07:34:08
epoch:2 step:6100 35.679 110.319 59.662 07-04 07:34:23
epoch:2 step:6150 35.576 110.070 59.473 07-04 07:34:38
epoch:2 step:6200 36.087 109.900 60.367 07-04 07:34:53
epoch:2 step:6250 35.760 109.692 59.817 07-04 07:35:07
epoch:2 step:6300 35.423 109.264 59.380 07-04 07:35:21
epoch:2 step:6350 35.938 109.127 60.170 07-04 07:35:36
epoch:2 step:6400 35.393 108.895 59.363 07-04 07:35:50
epoch:2 step:6450 36.056 108.591 60.318 07-04 07:36:05
epoch:2 step:6500 35.851 108.453 60.069 07-04 07:36:20
ori: thank you for the music tonight 07-04 07:37:25
rep: thank you for listening ! 07-04 07:37:25
out: just hope you 're having a blast . 07-04 07:37:25
epoch:2 step:6500 TEST: recon/kl/bow-loss/ppl: 36.763 108.455 60.046 23.037 BLEU: 1.4 12.8 1.6 0.6 0.4
epoch:2 step:6550 35.797 108.210 59.947 07-04 07:37:40
epoch:2 step:6600 35.257 107.995 59.272 07-04 07:37:54
epoch:2 step:6650 35.752 107.263 59.844 07-04 07:38:09
epoch:2 step:6700 35.424 107.175 59.611 07-04 07:38:24
epoch:2 step:6750 35.283 106.981 59.463 07-04 07:38:38
epoch:2 step:6800 35.262 106.830 59.244 07-04 07:38:53
epoch:2 step:6850 34.963 106.306 58.964 07-04 07:39:07
epoch:2 step:6900 35.507 106.425 59.536 07-04 07:39:22
epoch:2 step:6950 35.729 105.890 60.120 07-04 07:39:36
epoch:2 step:7000 35.804 105.615 60.084 07-04 07:39:51
ori: while it 's the perfect time to start planning christmas content to share for work , is it too early to start playing christmas music ? 07-04 07:40:57
rep: come out free drinks at 07-04 07:40:57
out: well it 's not . you should start this 07-04 07:40:57
epoch:2 step:7000 TEST: recon/kl/bow-loss/ppl: 36.270 105.460 59.703 22.087 BLEU: 1.4 12.7 1.5 0.5 0.4
epoch:2 step:7050 35.773 105.297 59.961 07-04 07:41:11
epoch:2 step:7100 34.809 104.952 58.745 07-04 07:41:26
epoch:2 step:7150 35.463 104.681 59.574 07-04 07:41:41
epoch:2 step:7200 35.451 104.403 59.574 07-04 07:41:56
epoch:2 step:7250 35.288 103.870 59.315 07-04 07:42:10
epoch:2 step:7300 35.968 103.508 60.253 07-04 07:42:25
epoch:2 step:7350 34.236 103.152 58.314 07-04 07:42:40
epoch:2 step:7400 34.889 102.766 59.110 07-04 07:42:54
epoch:2 step:7450 35.236 102.554 59.218 07-04 07:43:09
epoch:2 step:7500 35.318 102.063 59.370 07-04 07:43:23
ori: a cute ass bby shower is worth it smh 😪 07-04 07:44:30
rep: i also hate kids 07-04 07:44:30
out: that i don 't want to but i 'm tired of it .. 07-04 07:44:30
epoch:2 step:7500 TEST: recon/kl/bow-loss/ppl: 35.970 101.822 59.455 21.529 BLEU: 1.4 12.3 1.5 0.5 0.4
epoch:2 step:7550 34.370 101.599 58.356 07-04 07:44:45
epoch:2 step:7600 34.815 101.148 58.897 07-04 07:44:59
epoch:2 step:7650 35.968 100.801 60.237 07-04 07:45:14
epoch:2 step:7700 35.680 100.376 60.099 07-04 07:45:28
epoch:2 step:7750 35.149 99.986 59.348 07-04 07:45:43
epoch:2 step:7800 34.469 99.423 58.625 07-04 07:45:58
epoch:2 step:7850 35.575 99.104 59.844 07-04 07:46:12
epoch:2 step:7900 35.420 98.633 59.578 07-04 07:46:27
epoch:2 step:7950 34.702 98.104 58.983 07-04 07:46:41
epoch:2 step:8000 35.052 97.742 58.951 07-04 07:46:56
ori: i need it now 07-04 07:48:02
rep: i 'm about to get some 07-04 07:48:02
out: i 'll be taking the chances to you . 07-04 07:48:02
epoch:2 step:8000 TEST: recon/kl/bow-loss/ppl: 35.439 97.269 59.078 20.575 BLEU: 1.4 12.7 1.6 0.6 0.4

Is there a PyTorch version of this code?

I'm trying to implement this paper in pytorch,but I don't know how to convert this part ` with tf.variable_scope("decoder_train") as decoder_scope:
if decoder_layer == 2:
train_decoder_init_state = (
tf.concat([self.z_sample, ori_encoder_state[0], emoji_vec], axis=1),
tf.concat([self.z_sample, ori_encoder_state[1], emoji_vec], axis=1)
)
dim = latent_dim + num_unit + emoji_dim
cell = tf.nn.rnn_cell.MultiRNNCell(
[create_rnn_cell(dim, 2, cell_type, num_gpu, self.dropout),
create_rnn_cell(dim, 3, cell_type, num_gpu, self.dropout)])
else:
train_decoder_init_state = tf.concat([self.z_sample, ori_encoder_state_flat, emoji_vec], axis=1)
dim = latent_dim + 2 * num_unit + emoji_dim
cell = create_rnn_cell(dim, 2, cell_type, num_gpu, self.dropout)

        with tf.variable_scope("attention"):
            memory = tf.concat([ori_encoder_output[0], ori_encoder_output[1]], axis=2)
            memory = tf.transpose(memory, [1, 0, 2])

            attention_mechanism = seq2seq.LuongAttention(
                dim, memory, memory_sequence_length=self.ori_len, scale=True)
            # attention_mechanism = seq2seq.BahdanauAttention(
            #     num_unit, memory, memory_sequence_length=self.ori_len)

        decoder_cell = seq2seq.AttentionWrapper(
            cell,
            attention_mechanism,
            attention_layer_size=dim) # TODO: add_name; what atten layer size means
        # decoder_cell = cell

        helper = seq2seq.TrainingHelper(
            rep_input_emb, self.rep_len + 1, time_major=True)

        projection_layer = layers_core.Dense(
            vocab_size, use_bias=False, name="output_projection")
        decoder = seq2seq.BasicDecoder(
            decoder_cell, helper,
            decoder_cell.zero_state(batch_size, tf.float32).clone(cell_state=train_decoder_init_state),
            output_layer=projection_layer)
        train_outputs, _, _ = seq2seq.dynamic_decode(
            decoder,
            output_time_major=True,
            swap_memory=True,
            scope=decoder_scope
        )
        self.logits = train_outputs.rnn_output

    with tf.variable_scope("decoder_infer") as decoder_scope:
        # normal_sample = tf.random_normal(shape=(batch_size, latent_dim))

        if decoder_layer == 2:
            infer_decoder_init_state = (
                tf.concat([self.q_z_sample, ori_encoder_state[0], emoji_vec], axis=1),
                tf.concat([self.q_z_sample, ori_encoder_state[1], emoji_vec], axis=1)
            )
        else:
            infer_decoder_init_state = tf.concat([self.q_z_sample, ori_encoder_state_flat, emoji_vec], axis=1)

        start_tokens = tf.fill([batch_size], start_i)
        end_token = end_i

        if beam_width > 0:
            infer_decoder_init_state = seq2seq.tile_batch(
                infer_decoder_init_state, multiplier=beam_width)
            decoder = seq2seq.BeamSearchDecoder(
                cell=decoder_cell,
                embedding=embedding.coder,
                start_tokens=start_tokens,
                end_token=end_token,
                initial_state=decoder_cell.zero_state(
                    batch_size * beam_width, tf.float32).clone(cell_state=infer_decoder_init_state),
                beam_width=beam_width,
                output_layer=projection_layer,
                length_penalty_weight=0.0)
        else:
            helper = seq2seq.GreedyEmbeddingHelper(
                embedding.coder, start_tokens, end_token)
            decoder = seq2seq.BasicDecoder(
                decoder_cell,
                helper,
                decoder_cell.zero_state(batch_size, tf.float32).clone(cell_state=infer_decoder_init_state),
                output_layer=projection_layer  # applied per timestep
            )

        # Dynamic decoding
        infer_outputs, _, infer_lengths = seq2seq.dynamic_decode(
            decoder,
            maximum_iterations=maximum_iterations,
            output_time_major=True,
            swap_memory=True,
            scope=decoder_scope
        )
        if beam_width > 0:
            self.result = infer_outputs.predicted_ids
        else:
            self.result = infer_outputs.sample_id
            self.result_lengths = infer_lengths



    with tf.variable_scope("loss"):
        max_time = tf.shape(self.rep_output)[0]
        with tf.variable_scope("reconstruction"):
            # TODO: use inference decoder's logits to compute recon_loss
            cross_entropy = tf.nn.sparse_softmax_cross_entropy_with_logits(  # ce = [len, batch_size]
                labels=self.rep_output, logits=self.logits)
            # rep: [len, batch_size]; logits: [len, batch_size, vocab_size]
            target_mask = tf.sequence_mask(
                self.rep_len + 1, max_time, dtype=self.logits.dtype)
            # time_major
            target_mask_t = tf.transpose(target_mask)  # max_len batch_size
            self.recon_losses = tf.reduce_sum(cross_entropy * target_mask_t, axis=0)
            self.recon_loss = tf.reduce_sum(cross_entropy * target_mask_t) / batch_size

        with tf.variable_scope("latent"):
            # without prior network
            # self.kl_loss = 0.5 * tf.reduce_sum(tf.exp(self.log_var) + self.mu ** 2 - 1. - self.log_var, 0)
            self.kl_losses = 0.5 * tf.reduce_sum(
                tf.exp(self.log_var - self.p_log_var) +
                (self.mu - self.p_mu) ** 2 / tf.exp(self.p_log_var) - 1. - self.log_var + self.p_log_var,
                axis=1)
            self.kl_loss = tf.reduce_mean(self.kl_losses)

        with tf.variable_scope("bow"):
            # self.bow_loss = self.kl_weight * 0
            mlp_b = layers_core.Dense(
                vocab_size, use_bias=False, name="MLP_b")
            # is it a mistake that we only model on latent variable?
            latent_logits = mlp_b(tf.concat(
                [self.z_sample, ori_encoder_state_flat, emoji_vec], axis=1))  # [batch_size, vocab_size]
            latent_logits = tf.expand_dims(latent_logits, 0)  # [1, batch_size, vocab_size]
            latent_logits = tf.tile(latent_logits, [max_time, 1, 1])  # [max_time, batch_size, vocab_size]

            cross_entropy = tf.nn.sparse_softmax_cross_entropy_with_logits(  # ce = [len, batch_size]
                labels=self.rep_output, logits=latent_logits)
            self.bow_losses = tf.reduce_sum(cross_entropy * target_mask_t, axis=0)
            self.bow_loss = tf.reduce_sum(cross_entropy * target_mask_t) / batch_size

`

Failed to find any matching files for reinforced_cvae/01-09_11-12-05/breakpoints/best_test_bleu.ckpt

Hi ! Thanks for your code!

When i run Reinforced CVAE model , i modified line 63/74 of rl_run.py as
"cvae/01-08_07-16-13/breakpoints/at_step_20500.ckpt" and "classifier/01-07_13-08-49/breakpoints/best_test_loss.ckpt" .But it didn't save the best_test_bleu.ckpt
and i got the error information:

INFO:tensorflow:Restoring parameters from reinforced_cvae/01-09_11-12-05/breakpoints/best_test_bleu.ckpt
2019-01-10 08:37:14.839739: W tensorflow/core/framework/op_kernel.cc:1158] Not found: Unsuccessful TensorSliceReader constructor: Failed to find any matching files for reinforced_cvae/01-09_11-12-05/breakpoints/best_test_bleu.ckpt
2019-01-10 08:37:14.839756: W tensorflow/core/framework/op_kernel.cc:1158] Not found: Unsuccessful TensorSliceReader constructor: Failed to find any matching files for reinforced_cvae/01-09_11-12-05/breakpoints/best_test_bleu.ckpt

Traceback (most recent call last):
File "/data/linshuai/anaconda3/envs/tf12py35/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 1139, in _do_call
return fn(*args)
File "/data/linshuai/anaconda3/envs/tf12py35/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 1121, in _run_fn
status, run_metadata)
File "/data/linshuai/anaconda3/envs/tf12py35/lib/python3.5/contextlib.py", line 66, in exit
next(self.gen)
File "/data/linshuai/anaconda3/envs/tf12py35/lib/python3.5/site-packages/tensorflow/python/framework/errors_impl.py", line 466, in raise_exception_on_not_ok_status
pywrap_tensorflow.TF_GetCode(status))
tensorflow.python.framework.errors_impl.NotFoundError: Unsuccessful TensorSliceReader constructor: Failed to find any matching files for reinforced_cvae/01-09_11-12-05/breakpoints/best_test_bleu.ckpt
[[Node: save/RestoreV2_9 = RestoreV2[dtypes=[DT_FLOAT], _device="/job:localhost/replica:0/task:0/cpu:0"](_arg_save/Const_0_0, save/RestoreV2_9/tensor_names, save/RestoreV2_9/shape_and_slices)]]
[[Node: save/RestoreV2_9/_115 = _Recvclient_terminated=false, recv_device="/job:localhost/replica:0/task:0/gpu:0", send_device="/job:localhost/replica:0/task:0/cpu:0", send_device_incarnation=1, tensor_name="edge_176_save/RestoreV2_9", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/gpu:0"]]

The log.txt saved the result until epoch:6 step:27560 ,yet the checkpoint/ is empty .
what's the reason of the problem?Could you please tell me ?Thanks a lot!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.