working with text data sequences ( integer tensorinto embedded sequences ( float tensor)flatten the tensor to dand train single dense layer on top for classification listing loading he imdb dat for use wit an embedding layer from keras datasets import imdb from keras import preprocessing max_features maxlen number of words to consider as features cuts off the text after this number of words (among the max_features most common words(x_trainy_train)(x_testy_testimdb load_datanum_words=max_featuresloads the data as lists of integers x_train preprocessing sequence pad_sequences(x_trainmaxlen=maxlen x_test preprocessing sequence pad_sequences(x_testmaxlen=maxlenturns the lists of integers into integer tensor of shape (samplesmaxlenlisting using an embedding layer and classifier on he imdb data specifies the maximum input length to the embedding layer so you can later flatten the embedded inputs after the embedding layerthe activations have shape (samplesmaxlen from keras models import sequential from keras layers import flattendense flattens the tensor of embeddings into tensor of shape (samplesmaxlen model sequential(model add(embedding( input_length=maxlen)model add(flatten()adds the classifier on top model add(dense( activation='sigmoid')model compile(optimizer='rmsprop'loss='binary_crossentropy'metrics=['acc']model summary(history model fit(x_trainy_trainepochs= batch_size= validation_split= you get to validation accuracy of ~ %which is pretty good considering that you're only looking at the first words in every review but note that merely flattening the embedded sequences and training single dense layer on top leads to model that treats each word in the input sequence separatelywithout considering inter-word relationships and sentence structure (for examplethis model would likely treat both "this movie is bomband "this movie is the bombas being negative reviewsit' much better to add recurrent layers or convolutional layers on top of the embedded sequences to learn features that take into account each sequence as whole that' what we'll focus on in the next few sections licensed to