diff --git a/tutorials/Watson Language Translator.ipynb b/tutorials/Watson Language Translator.ipynb index a0ee94a..9b7d2df 100644 --- a/tutorials/Watson Language Translator.ipynb +++ b/tutorials/Watson Language Translator.ipynb @@ -19,7 +19,7 @@ "### About this notebook\n", "You will learn how to translate text into different languages in this exercise. \n", " \n", - "**Estimated Time needed**: 15 min" + "**Estimated Time needed**: 10-15 min" ] }, { @@ -38,50 +38,41 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "slideshow": { + "slide_type": "subslide" + } + }, "source": [ - "#### Video tutorial (4 min 32 sec)" + "### Step 1 of 3: Initiate the translator service using Python" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Click on the code cell below and press Shift+Enter to run the cell and load the video tutorial." + "Press Shift+Enter to execute these cells." ] }, { - "cell_type": "code", - "execution_count": null, + "cell_type": "markdown", "metadata": {}, - "outputs": [], "source": [ - "from IPython.display import HTML\n", - "\n", - "HTML(\"\"\"\n", - "
\n", - "Click here to create your API key for Watson Language Translator on IBM Cloud.\n", - "\"\"\")\n" + "First, install the current IBM Watson SDK packages for Python." ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": null, "metadata": { "slideshow": { - "slide_type": "subslide" + "slide_type": "fragment" } }, + "outputs": [], "source": [ - "### Step 1 of 3: Initiate the translator service using Python" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Press Shift+Enter to execute these cells." + "!pip install ibm_cloud_sdk_core \n", + "!pip install ibm-watson" ] }, { @@ -94,7 +85,7 @@ }, "outputs": [], "source": [ - "from watson_developer_cloud import LanguageTranslatorV3" + "from ibm_watson import LanguageTranslatorV3" ] }, { @@ -114,10 +105,16 @@ }, "outputs": [], "source": [ + "from ibm_cloud_sdk_core.authenticators import IAMAuthenticator\n", + "\n", + "authenticator = IAMAuthenticator('apikey12345')\n", + "\n", "language_translator = LanguageTranslatorV3(\n", - " version='2018-05-01',\n", - " iam_api_key='apikey12345' #replace with your API key. Keep the quotation marks!\n", - ")" + " version='2018-05-01'\n", + " authenticator=authenticator\n", + ")\n", + "\n", + "language_translator.set_service_url('https://gateway.watsonplatform.net/language-translator/api')" ] }, { @@ -141,7 +138,7 @@ }, "outputs": [], "source": [ - "text_to_translate = \"Polong is excellent at table tennis\"" + "text_to_translate = \"Who is excellent at table tennis?\"" ] }, { @@ -169,7 +166,7 @@ "\n", "translation = language_translator.translate(\n", " text = text_to_translate,\n", - " model_id = 'en-fr')\n", + " model_id = 'en-fr').get_result()\n", "\n", "print(json.dumps(translation, indent=2, ensure_ascii=False))" ] @@ -211,7 +208,7 @@ "translation = language_translator.translate(\n", " text = text_to_translate,\n", " model_id = 'en-ja' #English to Japanese\n", - ") \n", + ").get_result()\n", "\n", "print(json.dumps(translation, indent=2, ensure_ascii=False))\n" ] @@ -241,9 +238,10 @@ "import pandas as pd\n", "from pandas.io.json import json_normalize\n", "\n", - "models = language_translator.list_models()\n", + "models = language_translator.list_models().get_result()\n", "\n", "model_df = pd.io.json.json_normalize(models[\"models\"])[[\"model_id\", \"source\", \"target\"]]\n", + "\n", "model_df.sort_values(\"source\").reset_index(drop=True)" ] }, @@ -261,13 +259,13 @@ "metadata": {}, "outputs": [], "source": [ - "text_to_translate = \"Polong is excellent at table tennis\"\n", + "text_to_translate = \"Who is excellent at table tennis?\"\n", "\n", "chosen_model_id = 'en-es'\n", "\n", "translation = language_translator.translate(\n", " text = text_to_translate,\n", - " model_id = chosen_model_id)\n", + " model_id = chosen_model_id).get_result()\n", "\n", "print(json.dumps(translation, indent=2, ensure_ascii=False))" ] @@ -308,8 +306,7 @@ "outputs": [], "source": [ "identification = language_translator.identify(\n", - " text = text_to_identify\n", - ")\n", + " text = text_to_identify).get_result()\n", "\n", "print(json.dumps(identification, indent=2, \n", " ensure_ascii=False))\n" @@ -359,7 +356,7 @@ "translation = language_translator.translate(\n", " text = text_to_identify,\n", " model_id = result_lang.language[0]+\"-en\" \n", - ") \n", + ").get_result()\n", "\n", "print(json.dumps(translation, indent=2, ensure_ascii=False))\n" ] @@ -397,14 +394,7 @@ "- [API Documentation](https://www.ibm.com/watson/developercloud/language-translator/api/v3/python.html?cm_mmc=Email_External-_-Developer_Community-_-WW_WW-_-CognitiveClass-cclabs-jupyterlab-watsontranslator-tutorial-WA0201&cm_mmca1=000026UJ&cm_mmca2=10006555&cm_mmca3=M12345678&cvosrc=email.External.M12345678&cvo_campaign=000026UJ)" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### About the Author: \n", - "Hi! It's [Polong Lin](https://ca.linkedin.com/in/polonglin), the author of this notebook. I hope you found the Watson Language Translator service easy to learn!" - ] - }, + { "cell_type": "markdown", "metadata": {},