Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python tensorflow中的LSTM ptb模型始终返回相同的单词_Python_Tensorflow_Lstm - Fatal编程技术网

Python tensorflow中的LSTM ptb模型始终返回相同的单词

Python tensorflow中的LSTM ptb模型始终返回相同的单词,python,tensorflow,lstm,Python,Tensorflow,Lstm,我使用了中描述的相同方法来使用tensorflow LSTM并预测测试文档中的下一个单词。然而,每次我运行LSTM时,它总是为每个序列预测相同的单词 更具体地说,我添加了以下几行: class PTBModel(object): """The PTB model.""" def __init__(self, is_training, config): # General definition of LSTM (unrolled) # identical to ten

我使用了中描述的相同方法来使用tensorflow LSTM并预测测试文档中的下一个单词。然而,每次我运行LSTM时,它总是为每个序列预测相同的单词

更具体地说,我添加了以下几行:

  class PTBModel(object):
  """The PTB model."""

  def __init__(self, is_training, config):
    # General definition of LSTM (unrolled)
    # identical to tensorflow example ...     
    # omitted for brevity ...
    outputs = []
    state = self._initial_state
    with tf.variable_scope("RNN"):
        for time_step in range(num_steps):
            if time_step > 0: tf.get_variable_scope().reuse_variables()
            (cell_output, state) = cell(inputs[:, time_step, :], state)
            outputs.append(cell_output)

    output = tf.reshape(tf.concat(1, outputs), [-1, size])
    softmax_w = tf.get_variable("softmax_w", [size, vocab_size])
    softmax_b = tf.get_variable("softmax_b", [vocab_size])
    logits = tf.matmul(output, softmax_w) + softmax_b

    #Storing the probabilities and logits
    self.probabilities = probabilities =  tf.nn.softmax(logits)
    self.logits = logits
然后按以下方式更改运行时间:

def run_epoch(session, m, data, eval_op, verbose=True, is_training = True):
  """Runs the model on the given data."""
  # first part of function unchanged from example

  for step, (x, y) in enumerate(reader.ptb_iterator(data, m.batch_size,
                                                    m.num_steps)):
    # evaluate proobability and logit tensors too:
    cost, state, probs, logits, _ = session.run([m.cost, m.final_state, m.probabilities, m.logits, eval_op],
                                 {m.input_data: x,
                                  m.targets: y,
                                  m.initial_state: state})
    costs += cost
    iters += m.num_steps

    if not is_training:
        chosen_word = np.argmax(probs, 1)
        print(chosen_word[-1])


  return np.exp(costs / iters)

我想预测测试数据集中的下一个单词。当我运行这个程序时,它总是返回相同的索引(大部分时间是的索引)。非常感谢您的帮助。

可能是SoftMax的温度太低了?

可能是SoftMax的温度太低了?

我如何预热它?您是否更改了SoftMax中的任何内容?据我所知,LSTM ptb型号应该是开箱即用的。我如何预热它?你在SoftMax中做了任何更改吗?据我所知,LSTM ptb模型应该是开箱即用的。