Complete text reversing model

You will now implement the decoder part of the text reversing model, which will convert the context vector from the encoder to reversed words.

You will be defining two functions onehot2words() and decoder(). The onehot2words() function takes in a list of ids and a dictionary index2word and converts an array of one-hot vectors to a list of words. The decoder() function takes in the context vector (i.e., list of word ids) and converts it to the reversed list of words.

For this exercise, the index2word dictionary, the context vector context, the encoder() function and the words2onehot() functions will be provided.

This exercise is part of the course

Machine Translation with Keras

View Course

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Define the onehot2words function that returns words for a set of onehot vectors
def ____(onehot, index2word):
  ids = np.____(____, ____=____)
  res = [____[____] for id in ids]
  return res