seq2seq icon indicating copy to clipboard operation
seq2seq copied to clipboard

Feeds AttentionSeq2Seq model with sequences of different length

Open azinnai opened this issue 8 years ago • 1 comments

Hi, I'm trying to implement a many to one model using the AttentionSeq2Seq model. I want to classify each sentence in my corpus with a category.

Each sentence has a different number of tokens I will explain briefly my workflow. I have a vocabulary of size N to create a one hot. For each sentence of length K I have a numpy matrix of size KxN.

I have two doubts:

  1. Suppose I want to use the keras' method fit_generator(): How can I can concatenate such matrices to obtain a batch of size L?
  2. In the snippet below, which is the correct value for input_length?
input_dim = len(source_vocab.keys())
output_dim = len(target_vocab.keys())

input_length = input_length # this boy here
output_length = 1

model = seq2seq.AttentionSeq2Seq(input_dim=input_dim,
                                      hidden_dim=hidden_dim,
                                      input_length=input_length,
                                      output_length=output_length,
                                      output_dim=output_dim,
                                      depth=depth,
                                      bidirectional=bidirectional)

Thanks!

azinnai avatar Jul 18 '17 17:07 azinnai

  1. You will need to convert to one hot encoded vector then use an embedding layer.

  2. Variable length input can be solved by bucketing.

0b01 avatar Jul 18 '17 19:07 0b01