2016-06-21 3 views
1

Predicting the next word using the LSTM ptb model tensorflow exampleで説明したのと同じメソッドを適用してテンソルフローLSTMを使用し、テストドキュメントの次の単語を予測します。しかし、LSTMは、実行するたびに常にすべてのシーケンスに対して同じ単語を予測します。テンソルフロー内のLSTM ptbモデルは常に同じ単語を返します

は具体的には、私はこれらの行を追加:

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 

をし、次のようにrun_epochを変更:私はテストデータセット内の次の単語を予測したい

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) 

。このプログラムを実行すると、常に同じインデックス(ほとんどの場合< eos>のインデックス)が返されます。どんな助けもありがとうございます。

答えて

0

SoftMaxの温度が低すぎるのでしょうか?

+0

どうすればウォームアップできますか? – Sauber

+0

SoftMaxで何か変更しましたか? 私が理解しているところでは、LSTMのptbモデルはそのままで動作するはずです。 –

関連する問題