Training the NMT
Understand the process of training neural machine translation models by preparing data, implementing custom training loops in TensorFlow, and tracking performance using the BLEU score, a key metric for evaluating translation quality in NLP.
Now that we have defined the NMT architecture and preprocessed the training data, it’s quite straightforward to train the model. Here, we’ll define and illustrate the exact process used for training:
The prepare_data() function
For the model training, we’re going to define a custom training loop because there’s a special metric we’d like to track. Unfortunately, this metric is not a readily available TensorFlow metric. But before that, there are several utility functions we need to define:
The prepare_data() function takes the source sentence and target sentence pairs and generates encoder and decoder inputs and decoder labels. Let’s look at the arguments:
de_lookup_layer: TheStringLookuplayer of the German language.train_xy: A tuple containing tokenized English sentences and tokenized German sentences in the training set, respectively.valid_xy: Similar totrain_xybut for validation data.test_xy: Similar totrain_xybut for test data.
For each training, validation, and test dataset, this function generates the following: ...