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

Connected

Exercise

Reversing sentences

Here you will learn how to reverse sentences for the encoder model. As discussed, reversing source sentences helps to form a strong initial connection between the encoder and the decoder, which boosts the performance of the model. However, always remember that the benefit is dependent on the two languages you are translating between. As long as they have the same subject, verb ,and object order, it will benefit the model.

In this exercise you will modify the sents2seqs() function to be able to reverse sentences if needed. The user can specify a boolean keyword argument reverse which does text reversing.

Instructions

100 XP
  • Write the sents2seqs() function signature by adding a new keyword argument reverse which defaults to False.
  • Reverse the returned sequence IDs on the time dimension (using ::-1 syntax), so that the first word ID becomes the last.
  • Call sents2seqs() and reverse the given sentences and keep all the other default parameters values unchanged.