hit-computer / char-rnn-tf

Implement character-level language models for text generation based-on LSTM, in Python/TensorFlow
150 stars 49 forks source link

新手提问 #2

Open d5d opened 7 years ago

d5d commented 7 years ago

需要安装tensorflow?再运行这个程序?还是安装char-rnn?

hit-computer commented 7 years ago

需要安装TensorFlow,char-rnn-tf不需要安装直接运行里面的python文件即可(运行train.py文件训练模型,得到训练好的模型后可运行generate.py进行文本生成)。

d5d commented 7 years ago

求指教 :-0 ubuntu 已经安装tf. train有如下错误提示: root@27:~/char-rnn-tf# python train.py test.txt data has 9437 characters, 702 unique. W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE3 instructions, but these are available on your machine and could speed up CPU computations. W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations. W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations. W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations. Traceback (most recent call last): File "train.py", line 211, in tf.app.run() File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/app.py", line 44, in run _sys.exit(main(_sys.argv[:1] + flags_passthrough)) File "train.py", line 194, in main m = Model(is_training=True, config=config) File "train.py", line 77, in init lstm_cell = tf.nn.rnn_cell.BasicLSTMCell(size, forget_bias=0.0, state_is_tuple=False) AttributeError: 'module' object has no attribute 'rnn_cell'

hit-computer commented 7 years ago

这个错误是TensorFlow不同版本间API不一样导致的。我的这个代码是TensorFlow 0.12,你用的应该是1.0吧。你需要把tf.nn.rnn_cell都改成tf.contrib.rnn,还有101行tf.concat(1, outputs)改成tf.concat(outputs, 1)。也不明白为何TensorFlow要改API,导致旧版的程序需要修改才能运行。汗...

d5d commented 7 years ago

已经成功运行。谢谢!

hscspring commented 7 years ago

@hit-computer 不好意思,请问 Python 版本没有要求吗? Tks:)

hit-computer commented 7 years ago

我用的是python2,如果你使用的是python3,则按照python2和python3的不同之处修改即可,TensorFlow部分的代码应该不需要修改