Skip to content

hamidmatiny/bert-inference

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FastAPI BERT Inference Docker Container

Overview

This project containerizes a FastAPI application with BERT (DistilBERT) model inference using Docker. The application provides sentiment analysis capabilities through REST API endpoints.

Project Structure

/
├── Dockerfile         - Docker configuration to build the container image
├── main.py           - FastAPI application with BERT sentiment classification
├── requirements.txt  - Python dependencies
└── README.md         - This file

Features

  • Hello World Endpoint: Simple GET endpoint at / that returns a greeting message
  • BERT Sentiment Classification: POST endpoint at /classify that analyzes text sentiment
  • Health Check: GET endpoint at /health for monitoring container status
  • Exposed Port: Port 8000 is exposed for API access
  • Pre-loaded Model: BERT model is downloaded during image build for faster container startup

Building the Image

docker build -t fastapi-bert:latest .

Running the Container

docker run -d -p 8000:8000 --name fastapi-bert-app fastapi-bert:latest

API Endpoints

1. Welcome Endpoint

curl http://localhost:8000/

Response:

{"message":"Hello World! FastAPI BERT Inference Server"}

2. Health Check

curl http://localhost:8000/health

Response:

{"status":"healthy"}

3. Sentiment Classification

curl -X POST http://localhost:8000/classify \
  -H "Content-Type: application/json" \
  -d '{"text":"This is an amazing product, I love it!"}'

Response:

{
  "text":"This is an amazing product, I love it!",
  "classification":"POSITIVE",
  "confidence":0.9998859167098999
}

Technologies

  • Framework: FastAPI
  • Server: Uvicorn
  • ML Model: DistilBERT (HuggingFace Transformers)
  • Base Image: Python 3.11 (slim)
  • Containerization: Docker

Model Information

  • Model Name: distilbert-base-uncased-finetuned-sst-2-english
  • Task: Sentiment Analysis (Binary Classification - POSITIVE/NEGATIVE)
  • Framework: PyTorch via HuggingFace Transformers

About

This project containerizes a FastAPI application with BERT (DistilBERT) model inference using Docker. The application provides sentiment analysis capabilities through REST API endpoints.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors