Sample ML.NET application that trains, evaluates and deploys a model using Azure DevOps. The model uses reviews from Yelp to train an binary classification model to analyze sentiment. The trained model is stored in an Azure Storage Blob container and used to make predictions over HTTP by an Azure Function.
- Domain: F# .NET Core Class Library containing schema of input and output data used by the model.
- TrainConsole: C# .NET Core Console Application. Trains a binary classification model to analyze sentiment.
- TestModel: C# XUnit Test Project. Used to evaluate the model.
- AzFnUploadService: C# Azure Functions HTTP Triggered serverless application that uploads the trained model to a validation / staging Azure Storage Blob container and the evaluated model to a production Azure Storage Blob container.
- AzFnSentimentAnalysisService: C# Azure Functions HTTP Triggered serverless application that uses the production model to make predictions.
- azure-pipelines.yml: Contains Azure DevOps Build/Test/Deploy job definitions.
The data used in this application comes from the Sentiment Labeled Sentences UCI repository.
Use the following steps to run the applications
- Navigate to
TrainConsole
project directory. - Use .NET CLI and provide the URI of the dataset used for training as an argument. The URI can be hosted anywhere. For this application, it was hosted in an Azure Storage Blob container and anonymous read access was provided for the blob containing the data.
dotnet run <DATASET-URI>
- Navigate to
TestModel
project directory. - Use the .NET CLI to run the following command:
dotnet test
- Make sure you have in Azure Blob Storage, containers called validation and production.
- Navigate to the
AzFnUploadService
project directory. - Create a
local.settings.json
file with the following content. Replace theAZURE-BLOB-STORAGE-CONNECTION-STRING
with the connection string of the blob account where you'll be saving your models to.
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"AzModelStorageConnectionString": "<AZURE-BLOB-STORAGE-CONNECTION-STRING>"
}
}
- Use the Azure Functions Core Tools in the terminal to start the application:
func host start
- In another terminal, navigate to the
TrainConsole
project directory. - Use
curl
in the terminal to upload the model. Make sure to replaceENDPOINT
withValidation
orProduction
depending which Azure Storage Blob Container you want to upload the model to.
curl --location --request POST http://localhost:7071/api/Upload<ENDPOINT> \
--form '=@model.zip'
You should receive the following response if the model was uploaded successfully:
Uploaded Successfully
- Navigate to the
AzFnSentimentAnalysisService
project directory. - Create a
local.settings.json
file with the following content. Replace thePRODUCTION-MODEL-URI
with the URI of the blob containing the production model. (Validation is also valid. This URI can point to any serialized version of the model)
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"MODEL_URI": "<PRODUCTION-MODEL-URI>"
}
}
- Use the Azure Functions Core Tools in the terminal to start the application:
func host start
- In another terminal, use
curl
to classify the sentiment of a comment.
curl --location --request POST 'http://localhost:7071/api/AnalyzeSentiment' \
--header 'Content-Type: application/json' \
--data-raw '{
"Comment": "The steak was bad!"
}'
The response should look as follows:
Negative