How retajmelhem/imdb-sentiment-api works
This repository serves fine-tuned IMDB sentiment predictions through a FastAPI application. The main workflow is client request → API validation and safeguards → shared predictor → normalization/tokenization and batched model inference → typed prediction result. Separate branches cover notebook-based model research, artifact export/parity verification, and the optional Gradio interface. The application, inference modules, export tool, and parity checker are excerpted; the notebook and demo are included as documented capabilities, but their internal behavior is not sampled.
Main entry points: main.py FastAPI app · predictor.py Sentiment predictor · config.py Settings and metadata · verify_parity.py Inference parity check
Components 16
Model research
- Training and evaluation
notebooks/model_training.ipynb
Model artifacts
- Fine-tuned model and tokenizer
- Inference metadata
model_metadata.json - Checkpoint export
scripts/export_model.py - Inference parity check
scripts/verify_parity.py
Inference service
- Request and result schemas
src/sentiment/schemas.py - Body-size safeguard
app/middleware.py - Settings and metadata
src/sentiment/config.py - Logging setup
src/sentiment/logging_config.py - Inference errors
src/sentiment/exceptions.py - Sentiment predictor
src/sentiment/predictor.py - Normalize and encode
src/sentiment/preprocessing.py
Client interfaces
- FastAPI app
app/main.py - Optional Gradio UI
demo/app.py
Other components
- Client
- Local model or Hub
Connections 18
- Client → FastAPI app: sends request
README.md - FastAPI app → Body-size safeguard: applies safeguard
app/main.py - FastAPI app → Request and result schemas: validates and returns
app/main.py - FastAPI app → Settings and metadata: loads settings
app/main.py - FastAPI app → Logging setup: configures
app/main.py - FastAPI app → Sentiment predictor: creates and calls
app/main.py - FastAPI app → Inference errors: handles
app/main.py - Sentiment predictor → Settings and metadata: uses settings
src/sentiment/predictor.py - Sentiment predictor → Inference errors: raises
src/sentiment/predictor.py - Sentiment predictor → Normalize and encode: encodes texts
src/sentiment/predictor.py - Sentiment predictor → Request and result schemas: builds results
src/sentiment/predictor.py - Sentiment predictor → Local model or Hub: loads artifacts
README.md - Settings and metadata → Inference metadata: loads metadata
README.md - Training and evaluation → Checkpoint export: provides checkpoint
README.md - Checkpoint export → Fine-tuned model and tokenizer: writes artifacts
scripts/export_model.py - Inference parity check → Sentiment predictor: checks parity
scripts/verify_parity.py - Inference parity check → Fine-tuned model and tokenizer: verifies outputs
README.md - Optional Gradio UI → FastAPI app: uses service
README.md