Skip to content

Latest commit

 

History

History
55 lines (44 loc) · 5.18 KB

20.Deploy cognitive services in containers.MD

File metadata and controls

55 lines (44 loc) · 5.18 KB

Deploy cognitive services in containers

  • To deploy and use a Cognitive Services container, the following three activities must occur:

    1. The container image for the specific Cognitive Services API you want to use is downloaded and deployed to a container host, such as a local Docker server, an Azure Container Instance (ACI), or Azure Kubernetes Service (AKS).
    2. Client applications submit data to the endpoint provided by the containerized service, and retrieve results just as they would from a Cognitive Services cloud resource in Azure.
    3. Periodically, usage metrics for the containerized service are sent to a Cognitive Services resource in Azure in order to calculate billing for the service.
  • Cognitive Services container images

  • Each container provides a subset of Cognitive Services functionality. For example, not all features of the Language service are in a single container. Language detection, translation, and sentiment analysis are each separate container images. However, the setup steps are similar for each container.

  • For the Language service, each of the three core features maps to a separate image:

    1. Key Phrase Extraction - image mcr.microsoft.com/azure-cognitive-services/keyphrase
    2. Language Detection mcr.microsoft.com/azure-cognitive-services/language
    3. Sentiment Analysis v3 (English) mcr.microsoft.com/azure-cognitive-services/sentiment:3.0-en
  • Cognitive Services container configuration When you deploy a Cognitive Services container image to a host, you must specify three settings.

    1. ApiKey - Key from your deployed Azure Cognitive Service; used for billing.
    2. Billing - Endpoint URI from your deployed Azure Cognitive Service; used for billing.
    3. Eula - Value of accept to state you accept the license for the container.
  • After your Cognitive Services container is deployed, applications consume the containerized Cognitive Services endpoint rather than the default Azure endpoint. The client application must be configured with the appropriate endpoint for your container, but does not need to provide a subscription key to be authenticated. You can implement your own authentication solution and apply network security restrictions as appropriate for your specific application scenario.

Exercise - Use a container

  1. git clone https://github.com/MicrosoftLearning/AI-102-AIEngineer.git

  2. Provision (Create) a Cognitive Services resource

  3. Deploy and run a Text Analytics container. Create a Container Instances resource

    1. (Basics) Image source: Other Registry | Image type: Public | Image: mcr.microsoft.com/azure-cognitive-services/textanalytics/language:latest | OS type: Linux | Size: 1 vcpu, 4 GB memory
    2. (Networking) Networking type: Public | DNS name label: Enter a unique name for the container endpoint | Ports: Change the TCP port from 80 to 5000
    3. (Advanced) Restart policy: On failure | Environment variables: Mark as secure Key Value | Yes ApiKey Either key for your cognitive services resource | Yes Billing The endpoint URI for your cognitive services resource | No Eula accept | Command override: [ ]
  4. Observe the following properties of your container instance resource on its Overview page:

    1. Status: This should be Running.
    2. IP Address: This is the public IP address you can use to access your container instances.
    3. FQDN: This is the fully-qualified domain name of the container instances resource, you can use this to access the container instances instead of the IP address.
  5. Note: In this exercise, you've deployed the cognitive services container image for text translation to an Azure Container Instances (ACI) resource. You can use a similar approach to deploy it to a Docker host on your own computer or network by running the following command: docker run --rm -it -p 5000:5000 --memory 4g --cpus 1 mcr.microsoft.com/azure-cognitive-services/textanalytics/language Eula=accept Billing= ApiKey=

  6. Use the container

    1. 04-containers/(edit & run, verify the reusul) rest-test.cmd -> curl -X POST "http://<your_ACI_IP_address_or_FQDN>:5000/text/analytics/v3.0/languages?" -H "Content-Type: application/json" --data-ascii "{'documents':[{'id':1,'text':'Hello world.'},{'id':2,'text':'Salut tout le monde.'}]}"

Quiz

  1. You plan to use a cognitive services container in a local Docker host. Which of the following statements is true?
  • Client applications must pass a subscription key to the Azure resource endpoint before using the container.

  • The container must be able to connect to the Azure resource endpoint to send usage data for billing.

  • All data passed from the client application to the container is forwarded to the Azure resource endpoint.

    1. Which of the following parameters must you specify when deploying a Cognitive Services container image?
  • EULA

  • ResourceGroup

  • SubscriptionName

    1. You plan to use the language detection functionality of the Language cognitive service in a container. Which container image should you deploy?
  • mcr.microsoft.com/azure-cognitive-services/textanalytics

  • mcr.microsoft.com/azure-cognitive-services

  • mcr.microsoft.com/azure-cognitive-services/textanalytics/language