The Cloud Academy team shows how to build a sentiment analysis machine learning model by using a pubic dataset and how to deploy it to production with AWS Lambda and API Gateway.
OS libraries can be installed as follows (Linux):
$ sudo yum install -y atlas-devel atlas-sse3-devel blas-devel gcc gcc-c++ lapack-devel python27-devel
Python requirements can be installed with pip.
$ pip install -r requirements.txt
You can train and persist the model into file by executing:
$ python main.py
You can run the model via CLI as follows:
$ python predict.py "This function is awesome"
> positive
Simply execute the following deployment script:
$ ./deploy.sh
It will automatically create a new deployment package containing every Python dependency and the OS libraries required by scikit-learn and numpy, together with the "lambda" folder.
Here you can find the whole stack ready to be uploaded (reference).
Once the deployment package is ready, you can create a new AWS Lambda function and bind it to a new Amazon API Gateway endpoint.
-
Cloud Academy & AWS: how we use Amazon Web Services for machine learning and data collection (webinar)
-
Using Scikit-Learn In AWS Lambda (article by Ryan Brown)
-
Sentiment Analysis dataset (by cs.stanford.edu)
-
Amazon Serverless Architecture (Cloud Academy blog)
-
Google Cloud Functions VS AWS Lambda (Cloud Academy blog)