This example deploys a Twitter sentiment classifier as a microservice accessible via an API POST
request. The classifier was built using PL/Python in Greenplum Database (GPDB).
Read this blog post for more information.
There are two implementatations of deploying the model using
- Jupyter Notebook (via the Jupyter Kernel Gateway)
- Flask
Both apps are deployed on Cloud Foundry. This example deploys a trained sentiment classifier, but this framework can be modified for additional text analytics and general data science tasks.
Both implementations use this sentiment classifier which was built in a massively parallel processing environment using GPDB. The classifier is based on the approach of Go et al using the Sentiment140 data
If you do not have an account on a Cloud Foundry installation you can register for a free trial at Pivotal Web Services (PWS).
Download the Cloud Foundry Command Line Interface from the CF management console
or the CF Github repo.
This provides the cf
command which you will use to interact with a CF installation.
Alternatively, you can install PCF Dev to install Cloud Foundry on a single work station.
cd jupyter_gateway_deployment
cf push
cd flask_deployment
cf push
The classifier accepts POST
requests of text and returns a polarity prediction from 0 to 1. Lower polarity indicates negative sentiment and higher polarity indicates positive sentiment.
$ curl -H "Content-Type: application/json" -X POST -d '{"data":["This app is awesome and in the CLOUD","Steph Curry is a basketball player","i am so mad and angry"]}' sentiment-compute-flask.cfapps.pez.pivotal.io/polarity_compute
# returned result
{
"polarity": [
0.7803128570201056,
0.49108974839197184,
0.14809403223487322
]
}
Examples of both apps are currently deployed and be accessed at:
sentiment-compute.cfapps.pez.pivotal.io/polarity_compute
sentiment-compute-flask.cfapps.pez.pivotal.io/polarity_compute
- Sentiment classifier
- Python Cloud Foundry examples
- Cloud Foundry Documentation
- Pivotal Blog: Model scoring as a service
Chris Rawles