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
Cognitive Computing with IBM Watson

You're reading from   Cognitive Computing with IBM Watson Build smart applications using artificial intelligence as a service

Arrow left icon
Product type Paperback
Published in Apr 2019
Publisher Packt
ISBN-13 9781788478298
Length 256 pages
Edition 1st Edition
Arrow right icon
Authors (2):
Arrow left icon
Tanmay Bakshi Tanmay Bakshi
Author Profile Icon Tanmay Bakshi
Tanmay Bakshi
Robert High Robert High
Author Profile Icon Robert High
Robert High
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface 1. Background, Transition, and the Future of Computing FREE CHAPTER 2. Can Machines Converse Like Humans? 3. Computer Vision 4. This Is How Computers Speak 5. Expecting Empathy from Dumb Computers 6. Language - How Watson Deals with NL 7. Structuring Unstructured Content Through Watson 8. Putting It All Together with Watson 9. Future - Cognitive Computing and You 10. Another Book You May Enjoy

Translating between languages with Language Translator

To start, provision a new Language Translator service instance. Once that's done, head over to your favorite text editor, open up a new Python file, and let's get coding:

  1. Import the service:
from ibm_watson import LanguageTranslatorV3
  1. Initialize the API:
language_translator = LanguageTranslatorV3(version=“2018-05-01”, 
iam_apikey=“rvE894AVGJQ_t_ZNuUoQrclWWQwvpFB0_78jr9pvtjIl”)

Of course, you will have to use your own API Key.

  1. We just need to translate and get our result! But let's make it a bit prettier, and create a command-line interface for it:
print("Enter a sentence in English:")
eng_sent = raw_input()
translation = language_translator.translate(
text=eng_sent, model_id="en-fr").get_result() \
["translations”][0][“translation...
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