©2018 by macnabbs. Proudly created with Wix.com

  • Alibek Jakupov

Azure Machine Learning Web Services: Send array data

One great advantage of Azure Machine Learning studio is the ability to easily deploy your trained model as a web service.

Set Up

For instance we have created a sentiment analysis experiment by following this tutorial.

After publishing your prediction model as a web service you have a RESTful API that takes a text as an input and sends you back the sentiment score.

Here is the sample request

{ "Inputs": { "input1": { "ColumnNames": [ "UserRequest" ], "Values": [ [ "value" ], [ "value" ] ] } }, "GlobalParameters": {} }

Moreover there is also a code snippet in 3 programming languages provided by Azure ML team to create a client application. If we have a closer look we may notice that there is a possibility to send several lines simultaneously

data = { "Inputs": { "input1": { "ColumnNames": ["UserRequest"], "Values": [ [ "value" ], [ "value" ], ] }, }, "GlobalParameters": { } }

That is actually great as it allows us to tremendously speed our application.

I have recently tested my application sending the data line by line and in chunks and the difference was dramatic, which is not surprising as you do not have re-open a url connection each time you need to predict your data thus economizing several seconds per request that may turn out to be really crucial during the execution.

However, it took me a lot of time to form my http request properly as there are only few documentations on the web so I decided to share my code.

Hope you will find this useful. Enjoy.

1. First you need to create an array of a data to be predicted (an array of short texts if take atext classification sample as a reference)

2. Now construct a dictionary that represents your web input

3. Now convert your input into a json object.

4. Now you can send the array to the AML Studio web service and get the response

And here is the full code.