farizrahman4u / seq2seq

Sequence to Sequence Learning with Keras
GNU General Public License v2.0
3.17k stars 845 forks source link

Feeds AttentionSeq2Seq model with sequences of different length #203

Open azinnai opened 7 years ago

azinnai commented 7 years ago

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!

0b01 commented 7 years ago
  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.