working with text data downloading the imdb data as raw text firsthead to nowlet' collect the individual training reviews into list of stringsone string per review you'll also collect the review labels (positive/negativeinto labels list listing processing he labels of he raw imdb dat import os imdb_dir '/users/fchollet/downloads/aclimdbtrain_dir os path join(imdb_dir'train'labels [texts [for label_type in ['neg''pos']dir_name os path join(train_dirlabel_typefor fname in os listdir(dir_name)if fname[- :=txt' open(os path join(dir_namefname)texts append( read() close(if label_type ='neg'labels append( elselabels append( tokenizing the data let' vectorize the text and prepare training and validation splitusing the concepts introduced earlier in this section because pretrained word embeddings are meant to be particularly useful on problems where little training data is available (otherwisetask-specific embeddings are likely to outperform them)we'll add the following twistrestricting the training data to the first samples so you'll learn to classify movie reviews after looking at just examples listing tokenizing he ext of he raw imdb dat from keras preprocessing text import tokenizer from keras preprocessing sequence import pad_sequences import numpy as np maxlen cuts off reviews after words training_samples trains on samples validation_samples validates on , samples max_words tokenizer tokenizer(num_words=max_wordstokenizer fit_on_texts(textssequences tokenizer texts_to_sequences(textslicensed to considers only the top , words in the dataset