tensorflow - 本文档中的softmax_w和softmax_b是什么?

标签 tensorflow language-model softmax

我是 TensorFlow 新手,需要训练语言模型,但在阅读 document 时遇到了一些困难如下图所示。

lstm = rnn_cell.BasicLSTMCell(lstm_size)
# Initial state of the LSTM memory.
state = tf.zeros([batch_size, lstm.state_size])

loss = 0.0
for current_batch_of_words in words_in_dataset:
    # The value of state is updated after processing each batch of words.
    output, state = lstm(current_batch_of_words, state)

    # The LSTM output can be used to make next word predictions
    logits = tf.matmul(output, softmax_w) + softmax_b
    probabilities = tf.nn.softmax(logits)
    loss += loss_function(probabilities, target_words)

我不明白为什么需要这条线,

logits = tf.matmul(output, softmax_w) + softmax_b

因为我了解到,一旦计算出输出并且知道 target_words,我们就可以直接计算出损失。看来伪代码增加了一个额外的层。另外,前面没有提到的softmax_w和softmax_b是什么。我想我提出这样一个简单的问题可能错过了一些重要的事情。

请为我指出正确的方向,我们非常感谢任何建议。多谢。

最佳答案

所有代码所做的就是在计算 softmax 之前添加额外的线性变换。 softmax_w 应该是一个包含权重矩阵的 tf.Variablesoftmax_b 应该是一个包含偏差向量的 tf.Variable

查看本教程中的 softmax 示例以了解更多详细信息: https://www.tensorflow.org/versions/r0.10/tutorials/mnist/beginners/index.html#softmax-regressions

关于tensorflow - 本文档中的softmax_w和softmax_b是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39039793/

相关文章:

python - 带暗淡的 PyTorch softmax

tensorflow - 反向传播的内存要求——为什么不使用均值激活?

python - Tensorflow 使用恢复的训练模型报告错误

java - 语言建模工具包

machine-learning - Keras 中 lm_1b 的字符-词嵌入

python - 150x150 图像上的基本 softmax 模型实现

python - 在 Tensorflow 中设置交集

python - Tensorflow 神经网络预测始终相同

python - 如何使用 KenLM 计算困惑度?

python - 即使学习率很小,当类别数量增加时,“模型因损失= NaN而发散”。 [ tensorflow ]