Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
TensorFlow Deep Learning Projects

You're reading from   TensorFlow Deep Learning Projects 10 real-world projects on computer vision, machine translation, chatbots, and reinforcement learning

Arrow left icon
Product type Paperback
Published in Mar 2018
Publisher Packt
ISBN-13 9781788398060
Length 320 pages
Edition 1st Edition
Languages
Concepts
Arrow right icon
Authors (5):
Arrow left icon
Alberto Boschetti Alberto Boschetti
Author Profile Icon Alberto Boschetti
Alberto Boschetti
Rajalingappaa Shanmugamani Rajalingappaa Shanmugamani
Author Profile Icon Rajalingappaa Shanmugamani
Rajalingappaa Shanmugamani
Luca Massaron Luca Massaron
Author Profile Icon Luca Massaron
Luca Massaron
Abhishek Thakur Abhishek Thakur
Author Profile Icon Abhishek Thakur
Abhishek Thakur
Alexey Grigorev Alexey Grigorev
Author Profile Icon Alexey Grigorev
Alexey Grigorev
+1 more Show less
Arrow right icon
View More author details
Toc

Table of Contents (12) Chapters Close

Preface 1. Recognizing traffic signs using Convnets FREE CHAPTER 2. Annotating Images with Object Detection API 3. Caption Generation for Images 4. Building GANs for Conditional Image Creation 5. Stock Price Prediction with LSTM 6. Create and Train Machine Translation Systems 7. Train and Set up a Chatbot, Able to Discuss Like a Human 8. Detecting Duplicate Quora Questions 9. Building a TensorFlow Recommender System 10. Video Games by Reinforcement Learning 11. Other Books You May Enjoy

Test and translate

The code for the translation is in the file test_translator.py.

We start with some imports and the location of the pre-trained model:

import pickle
import sys
import numpy as np
import tensorflow as tf
import data_utils
from train_translator import (get_seq2seq_model, path_l1_dict, path_l2_dict,
build_dataset)
model_dir = "/tmp/translate"

Now, let's create a function to decode the output sequence generated by the RNN. Mind that the sequence is multidimensional, and each dimension corresponds to the probability of that word, therefore we will pick the most likely one. With the help of the reverse dictionary, we can then figure out what was the actual word. Finally, we will trim the markings (padding, start, end of string) and print the output.

In this example, we will decode the first five sentences in the training set, starting from the raw corpora....

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime