In the previous blog we talked through a basic 'getting started' process on Azure Cognitive Services. Now we are going to take the service from Azure and run it somewhere else. There are a few reasons why you might want to do this:
These are all valid use cases and Azure enables you to download the docker image of the Text Analytics service and use it anywhere. This isn’t going to be a tutorial on Docker, but we will cover the basic steps of running Docker on Linux.
I’ve used another Cloud platform for this demonstration and spun up a VM. Installing Docker is pretty straight forward now and can be done with a single command:
We then run the classic Hello-World container from Docker to validate the installation:
So now we have a docker running we can pull down the latest Docker Text Analytics service from Microsoft:
Then we just need to run it:
The docker image requires just a few parameters which enable it to run, all of which are well documented. Also the docker image will need to be able to communicate with Azure to ensure all billing metrics are captured; if it can’t communicate with Azure then it will not process the Text Analytics API calls.
I’m doing this on a VM with a Public IP but this could equally be done on a private subnet with outbound communications enabled via a NAT gateway. The -p 5000:5000 is the port translation element of docker, meaning that to communicate with the actual API it will be on port 5000, but this could be changed to 80 or something else entirely.
Once started we can directly send API requests to the service. Interestingly, if you’re not familiar with tools like Postman, Azure ship the container with Swagger to help testing of the API calls. The below image is what you will see; if you can’t call the home page (http://<IP>:5000/swagger) then check the following:
Now we have the Azure Text Analytics service running outside of Azure - pretty neat! Let’s celebrate with a song. Maybe I’m showing my age but a classic tune for me is Red Hot Chilli Peppers Under The Bridge.
Text Analytics has this as having largely a negative sentiment:
Had my parents known about sentiment analysis, they would have worked out what made me such a moody teenager.
One issue with running the docker image is that now it’s gone from a ‘managed’ service hosted in Azure with SSL certificates to be running on a standalone VM without any SSL. However, this can be easily fixed with Cloud services-provided managed Load Balancers which can also handle SSL termination.
To generate a SSL self-signed certificate you can do the following in OpenSSL on a Linux VM.
When you upload this to a Load Balancer you browser will still say it’s an 'Invalid Certificate' as it doesn’t recognise the certificate authority that created the certificate (i.e. you). You can use OpenSSL to create a 'certificate authority certificate' and this will bypass some issues. If you then add that certificate to your browser's 'trusted certificate authority certificates'...it's a bit of a mouth full. But this is a blog about Azure Text Analytics, so now I have my docker container running and terminated with SSL I will celebrate with one more song.
How about 'Get Off My Cloud' (see what I did there) by the Rolling Stones; well it’s a song you probably know, and it seems in terms of sentiment it’s neither positive or negative.
In conclusion I think the element that I’m most interested to share is the portability of Cloud services outside their native Cloud platform. Azure has done an amazing job in helping customers utilise Cloud services even if there are significant blockers against said customers moving to a Cloud platform, or if they have already decided to use a different Cloud provider. The above is just one of a number of services which have this level of portability.
To read more about how DSP-Explorer are exploring AI technologies, check out our blog predicting the results of the Rugby World Cup: https://content.dsp.co.uk/rugby-world-cup-oracle-machine-learning. You can also get in touch with one of our specialists at enquiries@dsp.co.uk.