NELSONZHAO / zhihu

This repo contains the source code in my personal column (https://zhuanlan.zhihu.com/zhaoyeyu), implemented using Python 3.6. Including Natural Language Processing and Computer Vision projects, such as text generation, machine translation, deep convolution GAN and other actual combat code.
https://zhuanlan.zhihu.com/zhaoyeyu
3.5k stars 2.14k forks source link

训练+预测输入正常,单独预测输出就乱七八糟,请问这是什么原因? #9

Open callwhl opened 6 years ago

callwhl commented 6 years ago

单独使用 checkpoint = tf.train.latest_checkpoint('checkpoints') samp = sample(checkpoint, 2000, lstm_size, prime="The") print(samp) 输出的就乱七八糟

92xianshen commented 6 years ago

遇到了同样的问题~

92xianshen commented 6 years ago

还再纠结这个问题么?

92xianshen commented 6 years ago

@callwhl 问题解决了么?

spiderHJS commented 6 years ago

因为词汇表在训练的时候和预测时候使用的不是同一个,因为vocab是通过set建立的,set中的元素顺序不一样,所以在预测时候生成类似于乱码的文本。解决方法是,在训练的时候将得到的词汇表存储下来,在预测的时候使用训练时候的词汇表。

am9x commented 5 years ago

在训练的时候将得到的词汇表存储下来,在预测的时候使用训练时候的词汇表。

注意:存的时候如果直接pkl.dump那个vocab set,继续会有同样问题 应该pkl.dump(list(vocab))

RangHeng commented 5 years ago

请问怎么把训练和测试代码分开。我用的pycharm,不是ipython,.