ematvey / tensorflow-seq2seq-tutorials

Dynamic seq2seq in TensorFlow, step by step
MIT License
996 stars 374 forks source link

there is no input argument when loop_fn method is called. #25

Closed hsh2438 closed 7 years ago

hsh2438 commented 7 years ago

I am studying Advanced dynamic seq2seq with TensorFlow. When i executed source code, it works well. But i have a question among the below source code.

In [21]:

def loop_fn(time, previous_output, previous_state, previous_loop_state):
    if previous_state is None:    # time == 0
        assert previous_output is None and previous_state is None
        return loop_fn_initial()
    else:
        return loop_fn_transition(time, previous_output, previous_state, previous_loop_state)

decoder_outputs_ta, decoder_final_state, _ = tf.nn.raw_rnn(decoder_cell, loop_fn)
decoder_outputs = decoder_outputs_ta.stack()

decoder_outputs_ta, decoder_finalstate, = tf.nn.raw_rnn(decoder_cell, loop_fn)

Above bolded line call loop_fn method, but there's no input argument. Then, i wonder how loop_fn method works well.

ematvey commented 7 years ago

Check out loop_fn_transition above, it feeds PAD token at the 1 decoding step, then feeds previously generated tokens.