我试图使用tensorflowLSTM model来进行下一个单词的预测。
如本related question(没有可接受的答案)中所述,示例包含伪代码以提取下一个单词的概率: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)
我对如何解释概率向量感到困惑。我修改了ptb_word_lm.py中PTBModel函数的__init__以存储概率和登录:class PTBModel(object):
"""The PTB model."""
def __init__(self, is_training, config):
# Gener