2016-06-21 3 views
1

Predicting the next word using the LSTM ptb model tensorflow example에 설명 된 것과 동일한 방법을 적용하여 tensorflow LSTM을 사용하고 테스트 문서의 다음 단어를 예측했습니다. 그러나 LSTM은 실행할 때마다 항상 모든 시퀀스에 대해 동일한 단어를 예측합니다. 다음과 같은 방법으로 run_epoch을 변경 한 후tensorflow의 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 

그리고 :

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 모델이 정상적으로 작동합니다. –

관련 문제