We fix the Tx size to the max length of our sentences, then we pad up to that length with zeros. We only care about the last output from the second layer of LSTM cells, so we have Ty = 1 here (it is a classification problem). Keras does not automatically pad, but we do it in sentences_to_indices(X, word_to_index, max_len). How? We initialize X_indices as a numpy matrix of zeros and the correct shape. Now we have the problem that some of our sentences are padded, we can use a padding mask to skip computations for padded entries. In the lab, we don’t skip padded entries, but use them in our model. If you want to skip padded entries, you could pass mask_zero=True to the embedding layer. You might have better performance if you do. Please try it out and compare.