1. Learn
  2. /
  3. Courses
  4. /
  5. Machine Translation with Keras

Exercise

Understanding one-hot vectors

Here you will learn to generate one-hot encoded vectors from words. One-hot encoding is a common transformation applied to words to represent them numerically.

You will be using the Keras to_categorical() function to create one-hot vectors. The to_categorical() function expects a sequence of integers as the input. Therefore, a word2index dictionary is provided which can be used to convert a word to an integer.

To successfully complete this exercise you will also have to use the built-in Python zip() function. The zip() function allows you to iterate multiple things at once. For example if you have two lists xx and yy of same length, by calling for x,y in zip(xx,yy) you can access each x and y elements of the lists iteratively.

Instructions 1/3

undefined XP
    1
    2
    3
  • Create a list of words I, like, cats and convert each word to an integer using word2index. Print the resulting integers.