Translating a sequence

Now we're ready to sample a few input sequences and translate them. In the example code, we're using the first 100 bilingual pairs to translate with. A better test might be to sample randomly across the space, but I think this simple loop illustrates the process:

for seq_index in range(100):
input_seq = data["encoder_input_data"][seq_index: seq_index + 1]
decoded_sentence = decode_sequence(input_seq, data, encoder_model,
decoder_model)
print('-')
print('Input sentence:', data['input_texts'][seq_index])
print('Correct Translation:', data['target_texts']
[seq_index].strip(" "))
print('Decoded sentence:', decoded_sentence)

In this code, we're using one observation of encoder_input_data as the input to decode_sequencedecode_sequence will pass back the sequence that the decoder believes is the correct translation. We also need to pass it the encoder and decoder models so it can do its job.The translation following is more interesting because the learned phrase isn't connected to

Once we have the decoder prediction, we can compare it to the input and the correct translation.

Of course, we aren't quite done because we haven't explored how the decode_sequence method works. That's next.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.128.198.59