Cognitive Services and Deep Learning - Microsoft Cloud Workshop

Microsoft Cloud Workshop Microsoft Cloud Workshop on Mar 01, 2019

In this hands-on lab, you will implement a solution which combines both pre-built artificial intelligence (AI) in the form of various Cognitive Services, with custom AI in the form of services built and deployed with Azure Machine Learning services. You will learn to create intelligent solutions atop unstructured text data by designing and implementing a text analytics pipeline. You will discover how to build a binary classifier using a simple neural network that can be used to classify the textual data, as well as how to deploy multiple kinds of predictive services using Azure Machine Learning and learn to integrate with the Computer Vision API and the Text Analytics API from Cognitive Services.
At the end of this hands-on lab, you will be better able to present solutions leveraging Azure Machine Learning service, Azure Databricks and Cognitive Services.

Before the Hands-on Lab

Microsoft Cloud Workshops

Cognitive services and deep learning
Before the hands-on lab setup guide
March 2019

Information in this document, including URL and other Internet Web site references, is subject to change without notice. Unless otherwise noted, the example companies, organizations, products, domain names, e-mail addresses, logos, people, places, and events depicted herein are fictitious, and no association with any real company, organization, product, domain name, e-mail address, logo, person, place or event is intended or should be inferred. Complying with all applicable copyright laws is the responsibility of the user. Without limiting the rights under copyright, no part of this document may be reproduced, stored in or introduced into a retrieval system, or transmitted in any form or by any means (electronic, mechanical, photocopying, recording, or otherwise), or for any purpose, without the express written permission of Microsoft Corporation.

Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual property rights covering subject matter in this document. Except as expressly provided in any written license agreement from Microsoft, the furnishing of this document does not give you any license to these patents, trademarks, copyrights, or other intellectual property.

The names of manufacturers, products, or URLs are provided for informational purposes only and Microsoft makes no representations and warranties, either expressed, implied, or statutory, regarding these manufacturers or the use of the products with any Microsoft technologies. The inclusion of a manufacturer or product does not imply endorsement of Microsoft of the manufacturer or product. Links may be provided to third party sites. Such sites are not under the control of Microsoft and Microsoft is not responsible for the contents of any linked site or any link contained in a linked site, or any changes or updates to such sites. Microsoft is not responsible for webcasting or any other form of transmission received from any linked site. Microsoft is providing these links to you only as a convenience, and the inclusion of any link does not imply endorsement of Microsoft of the site or the products contained therein.

© 2019 Microsoft Corporation. All rights reserved.

Requirements

  1. Microsoft Azure subscription must be pay-as-you-go or MSDN

    1. Trial subscriptions will not work. You will run into issues with Azure resource quota limits.

    2. Subscriptions with access limited to a single resource group will not work. You will need the ability to deploy multiple resource groups.

Before the hands-on lab

This lab does not have any additional setup that needs to be completed before the lab.

Hands-on Lab Guide

Microsoft Cloud Workshops

Cognitive services and deep learning
Hands-on lab step-by-step
March 2019

Information in this document, including URL and other Internet Web site references, is subject to change without notice. Unless otherwise noted, the example companies, organizations, products, domain names, e-mail addresses, logos, people, places, and events depicted herein are fictitious, and no association with any real company, organization, product, domain name, e-mail address, logo, person, place or event is intended or should be inferred. Complying with all applicable copyright laws is the responsibility of the user. Without limiting the rights under copyright, no part of this document may be reproduced, stored in or introduced into a retrieval system, or transmitted in any form or by any means (electronic, mechanical, photocopying, recording, or otherwise), or for any purpose, without the express written permission of Microsoft Corporation.

Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual property rights covering subject matter in this document. Except as expressly provided in any written license agreement from Microsoft, the furnishing of this document does not give you any license to these patents, trademarks, copyrights, or other intellectual property.

The names of manufacturers, products, or URLs are provided for informational purposes only, and Microsoft makes no representations and warranties, either expressed, implied, or statutory, regarding these manufacturers or the use of the products with any Microsoft technologies. The inclusion of a manufacturer or product does not imply endorsement of Microsoft of the manufacturer or product. Links may be provided to third-party sites. Such sites are not under the control of Microsoft and Microsoft is not responsible for the contents of any linked site or any link contained in a linked site, or any changes or updates to such sites. Microsoft is not responsible for webcasting or any other form of transmission received from any linked site. Microsoft is providing these links to you only as a convenience, and the inclusion of any link does not imply endorsement of Microsoft of the site or the products contained therein.

© 2019 Microsoft Corporation. All rights reserved.

Microsoft and the trademarks listed at https://www.microsoft.com/en-us/legal/intellectualproperty/Trademarks/Usage/General.aspx are trademarks of the Microsoft group of companies. All other trademarks are the property of their respective owners.

Cognitive services and deep learning hands-on lab step-by-step

Contents

Abstract and learning objectives

In this hands-on lab, you will implement a solution which combines both pre-built artificial intelligence (AI) in the form of various Cognitive Services, with custom AI in the form of services built and deployed with Azure Machine Learning service. You will learn to create intelligent solutions atop unstructured text data by designing and implementing a text analytics pipeline. You will discover how to build a binary classifier using a simple neural network that can be used to classify the textual data, as well as how to deploy multiple kinds of predictive services using Azure Machine Learning and learn to integrate with the Computer Vision API and the Text Analytics API from Cognitive Services.

At the end of this hands-on lab, you will be better able to implement solutions leveraging Azure Machine Learning service and Cognitive Services.

Overview

In this workshop, you will help Contoso Ltd. build a proof of concept that shows how they can build a solution that amplifies the claims processing capabilities of their agents.

Solution architecture

The high-level architecture of the solution is illustrated in the diagram. The lab is performed within the context of a notebook running within Azure Databricks. Various notebooks are built to test the integration with the Cognitive Services listed, to train custom ML services, and to integrate the results in a simple user interface that shows the result of processing the claim with all of the AI services involved.

The High-level architectural solution begins with a Claim, which us submitted for processing using a notebook in Azure Databricks. This notebook coordinates the calls to Computer Vision, Text Analytics, and Containerized Services, which includes a Classification Service and a Summary Service that both process claim text.

Requirements

  1. Microsoft Azure subscription must be pay-as-you-go or MSDN

    1. Trial subscriptions will not work. You will run into issues with Azure resource quota limits.

    2. Subscriptions with access limited to a single resource group will not work. You will need the ability to deploy multiple resource groups.

Exercise 1: Setup Azure Databricks Workspace

Duration: 20 minutes

In this exercise, you will setup your Azure Databricks account and Workspace.

Task 1: Provision Azure Databricks service

  1. Navigate to the Azure Portal.

  2. Select Create a resource.

    Screenshot of the Create a resource button.

  3. In the search box, enter Azure Databricks and then select the matching entry that appears with the same name.

    In the New blade, Azure Databricks is typed into the search box.

  4. On the Azure Databricks blade, select Create.

  5. On the Azure Databricks Service, enter the following and then select Create:

    1. Workspace Name: Enter claims-workspace.

    2. Subscription: Choose your Azure subscription.

    3. Resource group: Choose Create new and then specify the name mcwailab.

    4. Location: Choose a location near you.

    5. Pricing Tier: Select Premium.

In the Azure Databricks Service blase, provide a workspace name, subscription, resource group, location and pricing tier.

  1. When the deployment completes, navigate to your deployed Azure Databricks service and select Launch Workspace. If prompted, sign in using the same credentials you used to access the Azure Portal.

    The Launch Workspace button on the Overview blade of the Azure Databricks Service

Task 2: Upload the Databricks notebook archive

  1. Within the Workspace, using the command bar on the left, select Workspace, Users and select your username (the entry with house icon).

  2. In the blade that appears, select the downwards pointing chevron next to your name, and select Import.

  3. On the Import Notebooks dialog, select URL and paste in the following URL:

    https://github.com/Microsoft/MCW-Cognitive-services-and-deep-learning/blob/master/Hands-on%20lab/media/notebooks/AI-Lab.dbc?raw=true
    
  4. Select Import.

  5. A folder named after the archive should appear. Select that folder.

  6. The folder will contain one or more notebooks. These are the notebooks you will use in completing this lab.

Task 3: Provision a cluster

  1. Within the Workspace, from the menu on the left, select Clusters.

  2. Select + Create Cluster.

  3. On the New Cluster page, provide the following:

    1. Cluster Name: ailab

    2. Cluster Mode: Standard

    3. Databricks Runtime Version: 5.3 (includes Apache Spark 2.4.0, Scala 2.11)

    4. Python Version: 3

    5. Driver Type: Same as worker

    6. Worker Type: Standard_F4s

    7. Enable autoscaling: Unchecked

    h: Workers: 2

    The New Cluster page configured to create a new cluster with the desired settings.

  4. Select Create Cluster. This will take about 5 minutes to provision your cluster. The cluster will show a State of "Ready" when the cluster is available for use.

Exercise 2: Create and Deploy an Unsupervised Model

Duration: 60 minutes

In this exercise, you will create and deploy a web service that uses a pre-trained model to summarize long paragraphs of text.

Task 1: Install libraries

The notebook you will run depends on certain Python libraries like nltk and gensim that will need to be installed in your cluster. The following steps walk you through adding these dependencies.

  1. Within the Workspace, select the Workspace item in the menu and navigate to the folder where you uploaded the Databricks Archive (which should be [your-name/AI-lab]), and select the notebook called init. This will open the notebook so you can read and execute the code it contains.

  2. Read the instructions at the top of the notebook, and execute the cell. Remember you can use SHIFT + ENTER to execute the currently selected cell, and if you do not have a cluster attached, you will be prompted to attach to the cluster you recently deployed. This will create a file named init.bash that installs required libraries on the cluster.

  3. From the left-hand menu in your Workspace, select Clusters.

    The Clusters menu option.

  4. In the list of clusters, select your cluster.

    The list of Interactive Clusters.

  5. Select Edit to configure the cluster.

    The Edit button is highlighted.

  6. Expand Advanced Options at the bottom, then select Init Scripts. Enter the following into the Init Script Path, then select Add: dbfs:/databricks/scripts/init.bash

    The Init Scripts tab is selected and the path has been pasted into the Init Script Path.

  7. Select Confirm and Restart after adding the Init Script Path.

    The Confirm and Restart button is displayed.

Task 2: Read through and execute the Summarization notebook

  1. Within the Workspace, select the Workspace item in the menu and navigate to the folder where you uploaded the Databricks Archive (which should be [your-name/AI-lab]), and select the notebook called 01 Summarize. This will open the notebook so you can read and execute the code it contains.

  2. Read the instructions at the top of the notebook, and execute the cells as instructed. Remember you can use SHIFT + ENTER to execute the currently selected cell, and if you do not have a cluster attached, you will be prompted to attach to the cluster you recently deployed.

Task 3: Provision the Azure Machine Learning Workspace and Create the Summarization service

  1. From the left-hand menu in your Workspace, select Clusters.

    The Clusters menu option.

  2. In the list of clusters, select your cluster.

    The list of Interactive Clusters.

  3. Select the Libraries tab and then select Install New.

    The Libraries tab showing the Install New button.

    Note: There are interface updates being deployed, if you do not see the Install New button, instead go to the Azure Databricks menu option in your Workspace (the very top option on the left) and select Import Library. Then select a source of Upload Python Egg or PyPi and then provide the Package name specified in the following steps in the PyPi Name text box. Then in the Status on running clusters list, check the checkbox Attach that is listed to the left of your cluster's name to install the library on your cluster. When successful the Status should read Attached.

  4. In the Library Source, select PyPi and in the Package text box type azureml-sdk[databricks] and select Create.

    The Install Library dialog showing PyPi as the source and azureml-sdk[databricks] as the package.

  5. An entry for azureml-sdk[databricks] will appear in the list with a status of installing followed by installed. All the other required libraries are installed through the cluster init script you added.

    Installed libraries on the cluster.

  6. Within the Workspace, select the Workspace item in the menu and navigate to the folder where you uploaded the Databricks Archive (which should be [your-name/AI-lab]), and select the notebook called 02 Deploy Summarizer Web Service. This will open the notebook so you can read and execute the code it contains.

  7. Read the instructions at the top of the notebook, and execute the cells as instructed. Remember you can use SHIFT + ENTER to execute the currently selected cell, and if you do not have a cluster attached, you will be prompted to attach to the cluster you recently deployed.

    Pay attention to the top of the notebook where you are asked to ensure the Azure Machine Learning Python SDK (azureml-sdk[databricks]) is installed. You completed this in steps 3 and 4 above.

Exercise 3: Create and Deploy a TensorFlow Model

Duration: 60 minutes

In this exercise, you will use TensorFlow to construct and train a simple deep neural network classification model that will classify claim text as belonging to a home insurance claim or an automobile claim. You will then deploy this trained model as a web service.

Task 1: Create a simple TensorFlow based model

  1. Within the Workspace, select the Workspace item in the menu and navigate to the folder where you uploaded the Databricks Archive (which should be [your-name/AI-lab]), and select the notebook called 03 Claim Classification. This will open the notebook so you can read and execute the code it contains.

  2. Read the instructions at the top of the notebook, and execute the cells as instructed. Remember you can use SHIFT + ENTER to execute the currently selected cell, and if you do not have a cluster attached, you will be prompted to attach to the cluster you recently deployed.

    Pay attention to the top of the notebook where you are asked to ensure the tensorflow and tflearn libraries are installed. If you are running this lab in a hosted environment, they will already be installed. Otherwise, follow the posted instructions to install the libraries, ensuring they are installed and attached to your cluster before you run the cells in the notebook.

Task 2: Deploy the TensorFlow model

  1. Within the Workspace, select the Workspace item in the menu and navigate to the folder where you uploaded the Databricks Archive (which should be [your-name/AI-lab]), and select the notebook called 04 Deploy Classifier Web Service. This will open the notebook so you can read and execute the code it contains.

  2. Read the instructions at the top of the notebook, and execute the cells as instructed. Remember you can use SHIFT + ENTER to execute the currently selected cell, and if you do not have a cluster attached, you will be prompted to attach to the cluster you recently deployed.

Exercise 4: Completing the solution

Duration: 45 minutes

In this exercise, you will perform the final integration with the Computer Vision API and the Text Analytics API along with the Azure Machine Learning service you previously deployed, to deliver the completed proof of concept solution.

Task 1: Deploy the Computer Vision API

  1. Navigate to the Azure Portal in your browser.

  2. Select Create a resource.

  3. Select AI + Machine Learning and then Computer Vision.
    In the New blade, the AI + Machine Learning option is selected.

  4. On the Create blade, provide the following:

    1. Name: Provide a unique name for this instance.

    2. Subscription: Select your Azure subscription.

    3. Location: Select a location nearest your other deployed services.

    4. Pricing tier: Select S1.

    5. Resource group: Select the existing mcwailab resource group.

    The Create blade fields display the previously defined settings.

  5. Select Create.

  6. When the notification appears that the deployment succeeded, select Go to resource.

    A Deployment succeeded notification displays.

  7. Select Keys and then copy the value of Key 1 into notepad or something similar as you will need this value later in the lab.

    In the Cognitive Services blade, under Resource Management, Keys is selected.

  8. Select Overview and copy the value of Endpoint from the Essentials panel. Store this value in notepad or something similar as you will need this value later in the lab.

    In the Cognitive Services blade, the Endpoint URL is selected.

Task 2: Deploy the Text Analytics API

  1. Navigate to the Azure Portal in your browser.

  2. Select Create a resource.

  3. Select AI + Machine Learning and then Text Analytics.

    In the New blade, both AI + Cognitive Services and Text Analytics API are selected.

  4. On the Create blade, provide the following:

    1. Name: Provide a unique name for this instance.

    2. Subscription: Select your Azure subscription.

    3. Location: Select a location nearest your other deployed services.

    4. Pricing tier: Select S0.

    5. Resource group: Select the existing mcw-ai-lab resource group.

    The Create blade fields are set to the previously defined settings.

  5. Select Create.

  6. When the notification appears that the deployment succeeded, select Go to resource.

    A Deployment succeeded notification displays.

  7. Select Keys, and then copy the value of Key 1 into notepad or something similar as you will need this value later in the lab.

    In the Cognitive Services blade, under Resource Management, Keys is selected.

  8. Select Overview and copy the value of Endpoint from the Essentials panel. Store this value in notepad or something similar as you will need this value later in the lab.

    In the Cognitive Services blade, the Endpoint URL is selected.

Task 3: Completing the solution

  1. Return to your Azure Databricks Workspace. Select the Workspace item in the menu and navigate to the folder where you uploaded the Databricks Archive (which should be [your-name/AI-lab]), and select the notebook called 05 Cognitive Services. Follow the steps within the notebook to complete the lab and view the result of combining Cognitive Services with your Azure Machine Learning Services.

After the hands-on lab

Duration: 5 minutes

To avoid unexpected charges, it is recommended that you clean up all of your lab resources when you complete the lab.

Task 1: Clean up lab resources

  1. Navigate to the Azure Portal and locate the mcwailab Resource Group you created for this lab.

  2. Select Delete resource group from the command bar.

    Screenshot of the Delete resource group button.

  3. In the confirmation dialog that appears, enter the name of the resource group and select Delete.

  4. Wait for the confirmation that the Resource Group has been successfully deleted. If you don't wait, and the delete fails for some reason, you may be left with resources running that were not expected. You can monitor using the Notifications dialog, which is accessible from the Alarm icon.

    The Notifications dialog box has a message stating that the resource group is being deleted.

  5. When the Notification indicates success, the cleanup is complete.

    The Notifications dialog box has a message stating that the resource group has been deleted.

You should follow all steps provided after attending the Hands-on lab.

Attribution

This content was originally posted here:
https://github.com/Microsoft/MCW-Cognitive-Services-and-Deep-Learning

License

This content is licensed with the MIT License license.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE