Closed anty-zhang closed 6 years ago
同问。
对于问题1:
embedding = tf.get_variable("embedding", [VOCAB_SIZE, HIDDEN_SIZE])
的定义是在下面的variable_scope里:
initializer = tf.random_uniform_initializer(-0.05, 0.05)
# 定义训练用的神经网络模型
with tf.variable_scope("language_model", reuse=None, initializer=initializer):
train_model = PTBModel(True, TRAIN_BATCH_SIZE, TRAIN_NUM_STEP)
所以默认的initializer就是tf.random_uniform_initializer(-0.05, 0.05)
对于问题2: 使用eval模型主要的变化是batch_size和step都为1,那这样可以处理任意长度的测试数据。
Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale
.
Stale issues rot after an additional 30d of inactivity and eventually close.
Prevent issues from auto-closing with an /lifecycle frozen
comment.
If this issue is safe to close now please do so with /close
.
/lifecycle stale
Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten
.
Rotten issues close after an additional 30d of inactivity.
If this issue is safe to close now please do so with /close
.
/lifecycle rotten /remove-lifecycle stale
Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen
.
Mark the issue as fresh with /remove-lifecycle rotten
.
/close
embedding = tf.get_variable("embedding", [VOCAB_SIZE, HIDDEN_SIZE])
将原本batch_size * num_steps 个单词ID转换为单词向量
*我看这两行的代码,embedding只是定义了一个VOCAB_SIZEHIDDEN_SIZE大小的矩阵,并没有进行初始化,这个地方通过embedding_lookup就转换为了input的单词向量,这个实际上是怎么办到的呢?**
def main(_):
获取原始数据
还有这段代码,在测试数据上测试模型的效果test_perplexity = run_epoch(sess, eval_model, test_data, tf.no_op(), False) 为什么不用训练好的模型train_model,而使用验证数据集上的eval_model模型呢?
以上代码主要是参考您书上的第217-221页。 期望能够在空余时间帮忙解惑一下,非常感谢