1. Learn
  2. /
  3. Courses
  4. /
  5. Recurrent Neural Networks (RNNs) for Language Modeling with Keras

Connected

Exercise

Keras preprocessing

The second most important module of Keras is keras.preprocessing. You will see how to use the most important modules and functions to prepare raw data to the correct input shape. Keras provides functionalities that substitute the dictionary approach you learned before.

You will use the module keras.preprocessing.text.Tokenizer to create a dictionary of words using the method .fit_on_texts() and change the texts into numerical ids representing the index of each word on the dictionary using the method .texts_to_sequences().

Then, use the function .pad_sequences() from keras.preprocessing.sequence to make all the sequences have the same size (necessary for the model) by adding zeros on the small texts and cutting the big ones.

Instructions

100 XP
  • Import Tokenizer and pad_sequences from relevant modules.
  • Fit the tokenizer object on the sample data stored in texts.
  • Transform the texts into sequences of numerical indexes using the method .texts_to_sequences().
  • Fix the size of the texts by padding them.