0

I'm trying to build a basic encoder-decoder model. I build the model for training graph and it works perfect. The helper of the decoder is tf.contrib.seq2seq.TrainingHelper . But when I switch to helper to tf.contrib.seq2seq.GreedyEmbeddingHelper it throws a shape error.

Here it is my working helper.

helper = tf.contrib.seq2seq.TrainingHelper(
decoder_emb_inp, decoder_lengths, time_major=True)

And here it is the what I want to do.

start_tokens = tf.fill([batch_size], vezins_dict[start_token_str])
    end_token = vezins_dict[end_token_str]

helper = tf.contrib.seq2seq.GreedyEmbeddingHelper(decoder_emb_inp, 
    start_tokens, end_token)

I am using the same decoder and dynamic_decoding. It works with TrainingHelper, but it didn't work with GreedyEmbeddingHelper.

# decoder   
decoder = tf.contrib.seq2seq.BasicDecoder(
    decoder_cell, helper, encoder_state, 
    output_layer=projection_layer)

# Dynamic decoding
outputs, _, _ = tf.contrib.seq2seq.dynamic_decode(decoder)
logits = outputs.rnn_output

And here it is the error.

ValueError: linear is expecting 2D arguments: 
  [TensorShape([Dimension(20), Dimension(20), Dimension(10)]), 
  TensorShape([Dimension(20), Dimension(128)])]
mcemilg
  • 976
  • 1
  • 11
  • 18

1 Answers1

0

The problem was on GreedyEmbeddingHelpers input. When using Greedy Helper, no needs for decoder input.

This is wrong embedding input for Greedy Helper

embedding_decoder = tf.get_variable(
        "embedding_decoder", [out_alphabet_size, embedding_size])
decoder_emb_inp = tf.nn.embedding_lookup(
        embedding_decoder, decoder_inputs)

It needs to be like this for Greedy

decoder_emb_inp = tf.get_variable(
        "embedding_decoder", [out_alphabet_size, embedding_size])
mcemilg
  • 976
  • 1
  • 11
  • 18