Inference

We will load the model from the checkpoint file and test the translation on the set of sample data:

with tf.Session(graph=loaded_graph) as sess:
loader = tf.train.import_meta_graph(checkpoint + '.meta')
loader.restore(sess, checkpoint)
input_data = loaded_graph.get_tensor_by_name('input_data:0')
logits = loaded_graph.get_tensor_by_name('predictions:0')
fr_length = loaded_graph.get_tensor_by_name('fr_len:0')
en_length = loaded_graph.get_tensor_by_name('en_len:0')
dropout_prob = loaded_graph.get_tensor_by_name('dropout_probs:0')
result_logits = sess.run(logits, {input_data: [fr_text]*batch_size,
en_length: [len(fr_text)],
fr_length: [len(fr_text)]*batch_size,
dropout_prob: 1.0})[0]

pad = en_word2int[TOKEN_PAD]
print(' French Text')
print(' Word Ids: {}'.format([i for i in fr_text]))
print(' Input Words: {}'.format(" ".join( [fr_int2word[i] for i in fr_text ] )))
print(' English Text')
print(' Word Ids: {}'.format([i for i in result_logits if i != pad]))
print(' Response Words: {}'.format(" ".join( [en_int2word[i]for i in result_logits if i!=pad] )))
print(' Ground Truth: {}'.format(" ".join( [en_int2word[i] for i in en_filtered[random]] )))

We will load the input and output prediction tensors to run the graph on the test data. The following are some of the translations that are given as output by our model:

Unseen Test Data

French Text
Word Ids: [119, 67, 1003, 699, 11, 192, 13740]
Input Words: C'est environ 100 millions de ces planètes.
English Text
Word Ids: [119, 61, 1004, 2467, 21, 193, 17860]
Response Words: It's about 100 million of these planets.
Ground Truth: It's about 100 million such planets. <EOS>

French Text
Word Ids: [1255, 34, 21, 1263, 147, 1591, 609, 111, 1466, 3388, 21, 12253, 21, 22, 1673, 816]
Input Words: Qu'est-ce que les gens ont voulu donner au premier groupe, les 20% les plus pauvres ?
English Text
Word Ids: [320, 227, 227, 1511, 8, 636, 77, 14, 257, 2010, 14, 5433, 21, 14, 5433, 39610]
Response Words: What guys guys wanted to give at the first group, the poorest of the poorest <UNK>
Ground Truth: What did people want to give to the first group, the bottom 20 <UNK> <EOS>INFO:tensorflow:Restoring parameters from /tmp/models/best_so_far_model.ckpt

French Text
Word Ids: [31, 14982, 972, 33, 1043, 111, 2822, 131, 162, 4136, 11, 388, 94, 34, 7, 7499, 119, 413, 2973]
Input Words: La 2e étape est d'apprendre au chien à avoir envie de faire ce que vous voulez. C'est très simple.
English Text
Word Ids: [34, 1560, 989, 1, 793, 8, 96, 8, 391, 8, 391, 99, 132, 128, 2938, 39612]
Response Words: The second step is learning to have to do to do what you're familiar simple. <EOS>
Ground Truth: So the second stage in training is to teach the dog to want to do what we want him to do, and this is very easy. <EOS>

French Text
Word Ids: [722, 4957, 873, 974, 6186, 24, 718, 816, 19704, 125, 1001, 375, 977]
Input Words: J'ai répondu : « Bien, et pourquoi ? <UNK> un peu plus. »
English Text
Word Ids: [52, 153, 2773, 29, 744, 897, 1609, 136, 215, 3141, 1111, 1124, 39610]
Response Words: I said, "Well, and why what? let's a little bit more more. <UNK>
Ground Truth: And I said, "Well, why? Tell me a little bit about it." <EOS>

We can observe that some of the translations are very close to the first example phrase, though it's not seen by the network during training. We will also test some of the training data:

Training Data

French Text
Word Ids: [422, 53, 1668, 277, 29, 378, 19704, 131, 1937, 4373, 4374, 218, 369, 538, 204, 157, 396, 704, 1791, 817, 34, 129, 87, 2172, 704, 1791, 87, 2172, 704, 3681]
Input Words: Donc pour moi, c'est une chose <UNK> à faire, d'essayer d'atteindre l'autre côté avant qu'il ne soit trop tard, parce que quand il sera trop tard, il sera trop tard.
English Text
Word Ids: [420, 57, 1323, 83, 1, 136, 464, 39610, 8, 391, 678, 8, 566, 225, 223, 564, 564, 118, 563, 737, 4316, 178, 131, 118, 565, 737, 4317, 39612]
Response Words: So for me, this is a thing <UNK> to do try to start other side before before it doesn't too late, because when it will too late. <EOS>
Ground Truth: So to me, this is the courageous thing to do, to try to reach the other side before it's too late, because when it's going to be too late, it's going to be too late. <EOS>

French Text
Word Ids: [1029, 33, 94, 625, 19704, 11, 3404, 735, 11, 19704, 131, 12, 5973, 816]
Input Words: Quel est ce besoin <UNK> de l'argent, puis de <UNK> à la philanthropie ?
English Text
Word Ids: [2168, 83, 657, 21, 2853, 29, 319, 39610, 39610, 39612]
Response Words: What's this need of money, and then <UNK> <UNK> <EOS>
Ground Truth: Why the need for accumulating money, then doing <UNK> <EOS>

The quality of the translations are not that different from the test data. Note that, in spite of having used only 50% of the data for training, we can get decent translations. You may train on the whole data to get even better results on the translations.

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

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