Skip to content

teamfortyone/sentiment-analysis-lambda

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Movie Review Sentiment Analysis with AWS Lambda

Pre-requisites

Built and tested on WSL2 Ubuntu 20.04

  • Python v3.8
  • Docker (Tested on WSL2)
  • AWS CLI (install instructions)
  • Model artifacts from the NLP repo (link here)

Deployment

  1. Create a python virtual envionment
<project-root>$ python -m venv .venv
<project-root>$ source .venv/bin/activate
(.venv) <project-root>$ pip install -r requirements-dev.txt
  1. Go to ./layers and build & extract the spaCy dependency layer.
(.venv) ../layers$ docker build -t spacy-layer .
(.venv) ../layers$ docker run -d -it --name spacy spacy-layer

(.venv) ../layers$ docker cp spacy:/spacy/spacy-layer.zip .

This will copy the spacy.zip file from the container to host.

  1. Ensure that the model_artifacts.zip from the NLP repo is placed in the project root.

  2. Run aws configure and add AWS Access, Secret Keys, and select your default region and response format (json). Learn how to create AWS Access & Secret Keys.

  3. From project root directory: sam deploy --guided

Request and Response format

After deployment, SAM will print the API endpoint URL. It accepts a query parameter q with the text as input.

Request:

GET /predict?q=<input-text-here>

Response (Success):

Sentiment: Positive/Negative

Score: Between 0 & 1

{
    "sentiment": "Positive",
    "score": 0.9999545812606812
}

Response (Failure):

{
    "error": "Please provide input text"
}

About

Serverless function for sentiment analysis with spaCy

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published