Skip to content

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Creating an Azure Cognitive Services Account

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

Aug 19, 2019 • 6 Minute Read

Introduction

Microsoft Azure Cognitive Services allows you to integrate machine learning into your applications. The best part is that 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. This is done 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.

      {  
    "$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  
            }  
        }  
    }]  
}
    

This file specifies three parameters:

  • name of the resource
  • location or the Azure region it will be deployed to
  • 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.

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

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

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 advantage 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.

Matthew Soucoup

Matthew S.

Matthew is a Microsoft and Xamarin MVP from Madison, WI. He founded his company, Code Mill Technologies, and the Madison Mobile .NET Developers Group. Matt loves mobile development. At Code Mill, he creates elegant cross-platform mobile apps. For fun, Matt shares his passion for mobile and cloud development by blogging, writing articles, and presenting at conferences such as Xamarin Evolve, CodeMash, and That Conference. When not behind a computer screen, Matt gardens hot peppers, rides bikes, and loves Wisconsin craft beers and cheese.

More about this author