Author avatar

Matthew Soucoup

Creating an Azure Cognitive Services Account

Matthew Soucoup

  • Jun 14, 2019
  • 6 Min read
  • 22 Views
  • Jun 14, 2019
  • 6 Min read
  • 22 Views
Cloud
Azure Cognitive Services

Introduction

Microsoft Azure Cognitive Services allow you to integrate machine learning into your applications. The best part is you do not have to write any algorithms to do so!

Cognitive Services enable your app to identify objects within a photo or detect the sentiment behind a text snippet. You do this by using an SDK or calling a REST service. Those, in turn, will invoke the appropriate Cognitive Service in the Azure Cloud.

First, though, you need to create a Cognitive Services account in Azure. There are two different types of Cognitive Services accounts: single-service and multi-service subscriptions. A single-service subscription focuses on a single product, like Text Analytics. A multi-service subscription lets you access the full array of Cognitive Services through one account.

This guide will show you how to create a Cognitive Services multi-service subscription account using ARM templates.

Creating an Azure Resource Manager (ARM) Template

The Azure Resource Manager manages the deployments of resources for the Azure cloud. Whether you create resources through the Azure Portal user interface, the command line, or use REST APIs, they all use the Azure Resource Manager behind the scenes.

Azure Resource Manager (ARM) templates are JSON formatted and declaratively list out the resources to create in a single file. You can create one or many resources in an ARM template.

Having all the resources for your application defined in a single file allows you to reliably deploy them to any environment every single time.

The Azure Command Line Interface (CLI) can execute ARM templates. Using the Azure CLI you specify any parameters needed to run the template, such as the name of the resource.

Below is an ARM template that creates a multi-service Cognitive Services account subscription.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
{  
    "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",  
    "contentVersion": "1.0.0.0",  
    "parameters": {  
        "name": {  
            "type": "String"  
        },  
        "location": {  
            "type": "String"  
        },  
        "sku": {  
            "type": "String"  
        }  
    },  
    "resources": [{  
        "type": "Microsoft.CognitiveServices/accounts",  
        "apiVersion": "2016-02-01-preview",  
        "name": "[parameters('name')]",  
        "location": "[parameters('location')]",  
        "sku": {  
            "name": "[parameters('sku')]"  
        },  
        "kind": "CognitiveServices",  
        "properties": {  
            "apiProperties": {  
                "statisticsEnabled": false  
            }  
        }  
    }]  
}
json

This file specifies three parameters. They are: name of the resource, location or Azure region it will be deployed to, and the sku or pricing level.

Save this file with the name azuredeploy.json.

You will use this file when deploying the ARM Template in the next section.

Deploying via Azure Cloud Shell

To deploy the ARM Template and create the Microsoft Cognitive Services account, you will use the Cloud Shell.

The Cloud Shell is a browser-based shell located within the Azure portal. It will always have the latest Azure tools, such as the Azure CLI, applied to it.

To deploy the ARM template you created in the section above, open up the Azure portal and log in.

Then click on the button that looks like a command prompt.

cloud shell button

Once the cloud shell starts, select Bash from the dropdown.

select bash button

You will need to upload the file created in the previous step. Click the upload button, as shown below, and upload the file.

upload button

Next, you will execute a command to create a resource group; a resource group is like a folder that organizes Azure services.

Type the following in:

az group create -g MyCognitiveServicesAccount -l westus

The name which follows the -g parameter can be any name of your choosing. The value which follows the -l parameter must be an Azure region.

Next you'll run the template with this command:

az group deployment create -g MyCognitiveServicesAccount --template-file azuredeploy.json --parameters name=pluralsightcog location=westus2 sku=S0

This command took several parameters. The first, after the -g switch indicated which resource group. The second, --template-file, indicated the ARM template file's name. And the last one, --parameters is a space-delimited list of all the parameters defined in the ARM template, along with their values. Here, the name of the Cognitive Services account is pluralsightcog and it is deployed in the westus2 region, with the pricing or sku of S0.

After running this command, Azure will provision and create a new Multi-Service Cognitive Services account subscription.

Conclusion

In this guide, you learned how to create a Microsoft Cognitive Services Multi-Subscription account by using an ARM template.

The ARM template provides several advantages for creating resources over other means. The most important is that you can declaratively specify one or many resources in a single template file for reliable deployments across environments.

The JSON formatted ARM template is deployed using the Azure CLI. Azure Cloud Shell will always have the latest and greatest version of the CLI, so it makes sense to use that when possible.

2