Configuration for the docker container of some emotion recognition and sentiment analysis models from HuggingFace. The emotion recognition model is a fine-tuned version of a pre-trained model to simplify the number of emotions detected to be relevant to my use-case (analyzing messages to a chatbot).
Make sure you have the following installed:
- Python 3.10
- Pip (Python package installer)
-
Clone the repository:
git clone https://github.com/benedictchuajj/emotion-docker.git
-
Change into the project directory:
cd emotion-docker
-
Download the zipped folder containing the emotion and sentiment models from Teams, and unzip it in this directory
-
Build the docker image:
docker build -t emotion .
Note: If you are rebuilding the images several times, make sure to delete the older images as each image is around 8GB
-
Run the image in a container:
docker run -p 9000:8080 emotion
This runs the docker image locally as a container on local port 9000, where 8080 is the container port.
-
Open a separate terminal and invoke the main function of the container:
curl --request POST \ --url http://localhost:9000/2015-03-31/functions/function/invocations \ --header 'Content-Type: application/json' \ --data '{"sentence": "nice to meet you, my name is bob :)"}'
You should receive an output similar to the following
{"statusCode": 200, "sentiment_score": 0.7384703792631626, "emotion": "joy", "top5_emotions": [ {"name": "joy", "value": 0.5143717527389526}, {"name": "others", "value": 0.169914111495018}, {"name": "anger", "value": 0.1594364047050476}, {"name": "sadness", "value": 0.15627767145633698} ]}
Follow the instructions in AWS docs to upload the docker image in Amazon ECR which can then be created into a Lambda function.