Author: fchollet
 Date created: 2021/05/26
 Last modified: 2021/05/26
 Description: Implementing a sequence-to-sequene Transformer and training it

English-to-Spanish translation with a sequence-to-sequence Transformer

submited by
Style Pass
2021-05-27 16:30:03

Author: fchollet Date created: 2021/05/26 Last modified: 2021/05/26 Description: Implementing a sequence-to-sequene Transformer and training it on a machine translation task.

In this example, we'll build a sequence-to-sequence Transformer model, which we'll train on an English-to-Spanish machine translation task.

The code featured here is adapted from the book Deep Learning with Python, Second Edition (chapter 11: Deep learning for text). The present example is fairly barebones, so for detailed explanations of how each building block works, as well as the theory behind Transformers, I recommend reading the book.

Each line contains an English sentence and its corresponding Spanish sentence. The English sentence is the source sequence and Spanish one is the target sequence. We prepend the token "[start]" and we append the token "[end]" to the Spanish sentence.

We'll use two instances of the TextVectorization layer to vectorize the text data (one for English and one for Spanish), that is to say, to turn the original strings into integer sequences where each integer represents the index of a word in a vocabulary.

Leave a Comment