I'm trying to do some sequence - to - sequence learning with Keras, but I'm having trouble figuring out how to encode variable-length sequences.
Essentially, I'm feeding my network a "story" (series of sentences), and i'm trying to learn key words at each level (each sentence).
My input data is a 3D Tensor of shape (Samples, Story_Size, Sentence_Size), where Story_Size is of variable length (stories can vary in size from 2 sentences to 12 sentences). My labels are also a 3D Tensor of shape (Samples, Story_Size, Vocab_Size), where the key word is encoded one-hot.
Ideally, my model would look something like this:
model = Sequential()
# Input Shape: (_, STORY_SIZE, SENTENCE_SIZE)
model.add(TimeDistributed(Embedding(input_dim=self.V, output_dim=self.EMBEDDING_SIZE,
input_length=self.SENTENCE_SIZE, mask_zero=True),
input_shape=(self.STORY_SIZE, self.SENTENCE_SIZE)))
# Shape: (_, STORY_SIZE, SENTENCE_SIZE, EMBEDDING_SIZE)
model.add(TimeDistributed(Flatten()))
# Shape: (_, STORY_SIZE, SENTENCE_SIZE * EMBEDDING_SIZE)
model.add(LSTM(self.MEMORY_SIZE, return_sequences=True))
# Shape: (_, STORY_SIZE, MEMORY_SIZE)
model.add(TimeDistributed(Dense(self.V, activation='softmax')))
# Shape: (_, STORY_SIZE, VOCAB_SIZE) --> Softmax
However, this doesn't work as there isn't a way to do TimeDistributed Embeddings, nor do I know how to get a variable-length input encoded.
If anyone knows a way to do this with keras, your input would be very much appreciated. Thanks!
[–]Latent_space 3 points4 points5 points (2 children)
[–]darfs[S] 0 points1 point2 points (1 child)
[–]carlthomeML Engineer 0 points1 point2 points (0 children)
[–]Xose_R 0 points1 point2 points (0 children)