jayparks / tf-seq2seq

Sequence to sequence learning using TensorFlow.
392 stars 109 forks source link

can this code work? #1

Closed lkluo closed 7 years ago

lkluo commented 7 years ago

I found this seq2seq project is quite helpful, which is based on the latest tensorflow 1.2. May I know whether your source code really works, as I found in your notebook that there is error arisen.

screen shot 2017-06-03 at 19 49 31
jayparks commented 7 years ago

Yes, this is a working code running on >= tf.1.2.rc1 However, BeamSearchDecoder API does not seem to produce correct output as of now. For beam_width=1 (greedy decoding), It works well. If you see any issues while using this, please open an issue or email me!

lkluo commented 7 years ago

Thanks for your replay. What do you think that make BeamSearchDecoder not work? Can it be the API itself, or something related to the other part, e.g., connection with decoder? As there are source code released in google's seq2seq project for beam search, would you try that in your project in future? I am really interested in seq2seq, however, I am a beginner which could contribute less on this. I am learning it.

jayparks commented 7 years ago

The error came from API itself, but i resolved the error by using cutting edge updated code from tensorflow. It now fully supports beamsearch decoding. google's seq2seq api would be added in the future

lkluo commented 7 years ago

Thanks for your effort. I am trying to implement bidirectional RNN, while error keeps occurring. I notice you also tried to add this function, but it did not show in the code. Below is my code:

        if self.bidirectional:
            fw_cell = self.encoder_cell
            bw_cell = self.encoder_cell
            ((encoder_fw_outputs, encoder_bw_outputs),
             (encoder_fw_state, encoder_bw_state)) = (tf.nn.bidirectional_dynamic_rnn(
                cell_fw=fw_cell,
                cell_bw=bw_cell,
                inputs=self.encoder_inputs_embedded,
                sequence_length=self.encoder_inputs_length,
                dtype=self.dtype,
                time_major=True
            ))

            self.encoder_outputs = tf.concat(
                (encoder_fw_outputs, encoder_bw_outputs), 2,
                name="bidirectional_output_concat")

            # @TODO: need to check correctness
            if not isinstance(encoder_fw_state, LSTMStateTuple) and \
                    isinstance(encoder_fw_state, tuple):  # for MultiRNNCell:
                encoder_fw_state = encoder_fw_state[-1]
                encoder_bw_state = encoder_bw_state[-1]

            if isinstance(encoder_fw_state, LSTMStateTuple):  # for LSTM cell
                state_c = tf.concat(
                    (encoder_fw_state.c, encoder_bw_state.c), 1, name="bidirectional_concat_c")
                state_h = tf.concat(
                    (encoder_fw_state.h, encoder_bw_state.h), 1, name="bidirectional_concat_h")
                self.encoder_last_state = LSTMStateTuple(c=state_c, h=state_h)
            else:
                self.encoder_last_state = tf.concat(
                    (encoder_fw_state, encoder_bw_state), 1,
                    name="bidirectional_state_concat")

the error said "TypeError: 'Tensor' object is not iterable." at "initial_state = [state for state in encoder_last_state]". do you have any idea?

BTW, I think line 418 in file seq2seq_model shall be zip(clip_gradients, trainable_params) ....

angryBird2014 commented 7 years ago

when I run train.py,but a problem cam to me that "iter() returned non-iterator of type 'BiTextIterator'". I found that the problem is from line 139

jayparks commented 7 years ago

Hello, you must type your own arguments for training data.