10 Azure ML Code Examples Every Cloud AI Developer Should Know
Tags: azure, machinelearning, datascience, ai
Published: 2020-04-17 06:29:48

---
title: 10 Azure ML Code Examples Every Cloud AI Developer Should Know
published: true
date: 2020-04-16 16:20:02 UTC
tags: azure,machinelearning,datascience,ai
canonical_url: https://medium.com/microsoftazure/10-azure-ml-code-examples-every-cloud-ai-developer-should-know-a2899bf2f8bd
---

![](https://cdn-images-1.medium.com/max/1024/1*w1HiCSXwBpbiuoG-685qDg.png)

TLDR; The [Azure ML Python SDK](https://docs.microsoft.com/en-us/python/api/overview/azure/ml/?WT.mc.id=aiapril-medium-abornst) enables Data scientists, AI engineers,and MLOps developers to be productive in the cloud. This post highlights 10 examples every cloud AI developer should know, to be successful with Azure ML.

If you are new to Azure you can get a free subscription using the link below.

[Create your Azure free account today | Microsoft Azure](https://azure.microsoft.com/en-us/free/?WT.mc.id=aiapril-medium-abornst)

### #10 Build Scikit-Learn models at scale with Azure Machine Learning

![](https://cdn-images-1.medium.com/max/492/0*tkhkmGRvvvCDS0U6.png)

The scripts in this example are used to classify iris flower images to build a machine learning model based on scikit-learn’s [iris dataset](https://archive.ics.uci.edu/ml/datasets/iris) the code can easily be adapted to any scikit-learn estimator.

Code:

[Train scikit-learn machine learning models - Azure Machine Learning](https://docs.microsoft.com/en-us/azure/machine-learning/how-to-train-scikit-learn?WT.mc.id=aiapril-medium-abornst)

### #9 Build a TensorFlow Deep Learning Model at Scale with Azure Machine Learning

![](https://cdn-images-1.medium.com/max/1024/0*Ow99GpZR3hDV-yh8.png)

This example shows you how to run your [TensorFlow](https://www.tensorflow.org/overview) training scripts at scale using Azure Machine Learning’s [TensorFlow estimator](https://docs.microsoft.com/en-us/python/api/azureml-train-core/azureml.train.dnn.tensorflow?WT.mc.id=aiapril-medium-abornst) class. This example trains and registers a TensorFlow model to classify handwritten digits using a deep neural network (DNN) and MNIST but can be scaled to other more complex models.

Code:

[Train and deploy a TensorFlow model - Azure Machine Learning](https://docs.microsoft.com/en-us/azure/machine-learning/how-to-train-tensorflow?WT.mc.id=aiapril-medium-abornst)

### #8 Train PyTorch Deep Learning Models at Scale with Azure Machine Learning

![](https://cdn-images-1.medium.com/max/686/0*tB9ubpH2NU_-67jF.jpg)

PyTorch the example scripts in this article are used to classify chicken and turkey images to build a deep learning neural network based on PyTorch’s transfer learning [tutorial](https://pytorch.org/tutorials/beginner/transfer_learning_tutorial.html) and can be adapted to more complex projects.

Code:

[Train deep learning PyTorch models - Azure Machine Learning](https://docs.microsoft.com/en-us/azure/machine-learning/how-to-train-pytorch?WT.mc.id=aiapril-medium-abornst)

### #7 How to Deploy a Model to an Azure Kubernetes Service Cluster

![](https://cdn-images-1.medium.com/max/872/1*v9tLe9L3jy5lIEHTx4eA-w.png)

This example demonstrates how to deploy a production model on [Azure Kubernetes Service (AKS)](https://docs.microsoft.com/en-us/azure/aks/?WT.mc.id=aiapril-medium-abornst). [AKS](https://docs.microsoft.com/en-us/azure/aks/?WT.mc.id=aiapril-medium-abornst)is good for high-scale production deployments. Use [AKS](https://docs.microsoft.com/en-us/azure/aks/?WT.mc.id=aiapril-medium-abornst) if you need one or more of the following capabilities:

- **Fast response time**.
- **Autoscaling** of the deployed service.
- **Hardware acceleration** options such as GPU and field-programmable gate arrays (FPGA).

Code:

[How to deploy models to Azure Kubernetes Service - Azure Machine Learning](https://docs.microsoft.com/en-us/azure/machine-learning/how-to-deploy-azure-kubernetes-service?WT.mc.id=aiapril-medium-abornst)

### #6 Detect Model Data Drift with AML and Azure Kubernetes Service (AKS)

![](https://cdn-images-1.medium.com/max/1024/0*FMfkIkKTZD59CX3m.png)

Data in the wild is dynamic, this example walks through how to monitor changes in you data distribution and model performance over it’s production lifespan so that you can be alerted and update it more readily. ‘

Code:

[Detect data drift on AKS deployments - Azure Machine Learning](https://docs.microsoft.com/en-us/azure/machine-learning/how-to-monitor-data-drift?WT.mc.id=aiapril-medium-abornst)

### #5 Fine Tune and BERT QA System With Distributed Training

![](https://cdn-images-1.medium.com/max/801/0*qSdXbs2CPbI4n-89.jpg)<figcaption>Img Source <a href="https://pixabay.com/photos/bert-and-ernie-sesamstrasse-382270/">https://pixabay.com/photos/bert-and-ernie-sesamstrasse-382270/</a></figcaption>

This code example walks through using [BERT model](https://arxiv.org/abs/1810.04805) for question and answering in an end to end pipeline on the AzureML platform. From how to fine tune it from scratch using the distributed training with Horovod and how to optimize model performance with [Azure ML Hyper Drive](https://docs.microsoft.com/en-us/azure/machine-learning/how-to-tune-hyperparameters?WT.mc.id=aiapril-medium-abornst).

Code:

[microsoft/nlp-recipes](https://github.com/microsoft/nlp-recipes/blob/master/examples/question_answering/pretrained-BERT-SQuAD-deep-dive-aml.ipynb)

### #4 Distributed Training For Extractive Text Summarization

![](https://cdn-images-1.medium.com/max/1000/0*FwWady708zH18hyu.jpg)

This example shows how to use Azure Machine Learning to run distributed training using Distributed Data Parallel in Pytorch for [extractive summarization](https://en.wikipedia.org/wiki/Automatic_summarization#Extraction-based_summarization).

Code:

[microsoft/nlp-recipes](https://github.com/microsoft/nlp-recipes/blob/master/examples/text_summarization/extractive_summarization_cnndm_aml_distributed.ipynb)

### #3 Video Anomaly Detection Pipeline With Azure ML

![](https://cdn-images-1.medium.com/max/1024/1*rRxOQZLi9hAfSBNNVRc4jw.png)

The automation of detecting anomalous events in videos is a challenging problem that currently attracts a lot of attention by researchers, but also has broad applications across industry verticals. This code example provides an an end to end template for creating Video Anomaly Detection service with Azure ML and [AML Pipelines](https://docs.microsoft.com/en-us/azure/machine-learning/concept-ml-pipelines?WT.mc.id=aiapril-medium-abornst).

Code:

[microsoft/MLOps\_VideoAnomalyDetection](https://github.com/Microsoft/MLOps_VideoAnomalyDetection)

### #2 Interpretability for Local and Remote machine learning models

![](https://cdn-images-1.medium.com/max/1024/0*h45-UK_ZMDjqsR79.png)

At its best, AI advances society through critical high-impact applications such as Heathcare, Security and Self Driving Cars. However at its worst AI can amplify existing societal biases with unintended consequences, such as ethnic, gender or racial discrimination. Model [interpretability](https://docs.microsoft.com/en-us/azure/machine-learning/how-to-machine-learning-interpretability?WT.mc_id=10bestpractices-medium-abornst) is a critical component of the Machine Learning Engineering process. This code example shows how to use the [interpretability package](https://docs.microsoft.com/en-us/azure/machine-learning/how-to-machine-learning-interpretability-aml?WT.mc.id=aiapril-medium-abornst) of the Azure Machine Learning Python SDK to better understand why your model made its predictions.

[Model interpretability for local and remote runs - Azure Machine Learning](https://docs.microsoft.com/en-us/azure/machine-learning/how-to-machine-learning-interpretability-aml?WT.mc.id=aiapril-medium-abornst)

For more information about Shapley Values one of the key [interpretability measures](https://docs.microsoft.com/en-us/azure/machine-learning/how-to-machine-learning-interpretability-aml?WT.mc.id=aiapril-medium-abornst) check out my previous post on the topic.

[How Coalitions Can Help Detect Bias In AI](https://dev.to/azure/how-coalitions-can-help-detect-bias-in-ai-3af7)

### **#1 Aspect Based Sentiment Analysis with Intel NLP Architect**

![](https://cdn-images-1.medium.com/max/1024/0*7Ox0LZT7_vvEpdMz.png)

This End To End Notebook demonstrates how to train a custom estimator in Azure ML using the Intel NLP Architect Open Source Aspect Based Sentiment model. This model enables more granular insight into sentiment analysis as well contains best practices for configuring custom estimators from remote GitHub branches and custom environmental variable settings.

[microsoft/ignite-learning-paths-training-aiml](https://github.com/microsoft/ignite-learning-paths-training-aiml/blob/master/aiml40/absa.ipynb)

See also:

[Installing Azure ML Estimator Dependencies from Remote GitHub Branches](https://dev.to/azure/installing-azure-ml-estimator-dependencies-from-remote-github-branches-5g9m)

### Next Steps

Now that you have all the code you need to get started for your own production Azure ML project check out my previous posts on 9 Advanced Tips for Production Machine Learning and how Setting up AML Notebook VM.

- [Getting Started With AzureML Notebook VMs](https://dev.to/azure/getting-started-with-azureml-notebook-vms-26l0)
- [9 Advanced Tips for Production Machine Learning](https://dev.to/azure/9-advanced-tips-for-production-machine-learning-4ccg)

### About the Author

[**Aaron (Ari) Bornstein**](https://www.linkedin.com/in/aaron-ari-bornstein-22aa7a77/) is an avid AI enthusiast with a passion for history, engaging with new technologies and computational medicine. As an Open Source Engineer at Microsoft’s Cloud Developer Advocacy team, he collaborates with Israeli Hi-Tech Community, to solve real world problems with game changing technologies that are then documented, open sourced, and shared with the rest of the world.

* * *