Real-time NLP · Full stack
A sentiment engine you can watch think.
Quantized DistilBERT for real-time sentiment inference, paired with an interactive 3D particle interface. Type a sentence and a cloud of particles expands, contracts and changes colour with the prediction. Built as the capstone for my Natural Language Processing course.
WebGL · move your cursor
0.00%
Accuracy
0.0000
ROC AUC
0.0M
Training tweets
<0 ms
GPU inference
// highlights
Whatmakesittick
FP32 → INT8 quantization
Dynamic INT8 quantization of the 66M-parameter DistilBERT gives a 2-3x speedup with minimal accuracy loss.
Particles that respond
Three.js particles turn green and expand for positive text, red and contract for negative, and yellow at maximum expansion for neutral.
Runs on any hardware
CUDA on NVIDIA GPUs, MPS on Apple Silicon and a CPU fallback, with training scripts tuned for each (FP16 mixed precision on CUDA, torch.compile on MPS).
Evaluated properly
320K held-out samples, with precision, recall, F1, ROC AUC, Cohen's Kappa (0.7697), log loss (0.2729), a confusion matrix and 300 DPI plots.
A real API
FastAPI backend with CORS, a health check and a /predict endpoint that returns the sentiment, confidence and inference time. Swagger docs come free.
Glassmorphism UI
A React 19 front end with live confidence scores and latency readouts beside the 3D visualisation.
// architecture
Howit'sbuilt
- 01React + Three.js3D particle UI
- 02FastAPIREST · /predict · /health
- 03Quantized DistilBERTINT8 · CUDA / MPS / CPU
step 01
Clean
Remove URLs and usernames, lowercase, tokenize to 35 tokens. 70/10/20 train/val/test split.
step 02
Train
DistilBERT (6 layers), 3 epochs, AdamW at 2e-5 with 10% warmup.
step 03
Quantize
Dynamic INT8 quantization after training for fast inference.
step 04
Serve
FastAPI loads the quantized model and exposes /predict and /health.
step 05
Visualise
React and Three.js animate the prediction in real time.
// under the hood
Thedetails
curl -X POST "http://127.0.0.1:8000/predict" \
-H "Content-Type: application/json" \
-d '{"text": "I absolutely love this product!"}'
{
"sentiment": "Positive",
"confidence": 0.9567,
"inference_time_ms": 24.32
}Inference benchmarks (33M effective parameters, INT8)
| Device | Latency | Throughput |
|---|---|---|
| RTX 3080 (CUDA) | 8 ms | 125 samples/s |
| M1 Max (MPS) | 45 ms | 22 samples/s |
| Intel i9 (CPU) | 150 ms | 6.7 samples/s |
// stack
Builtwith
- Python
- PyTorch
- DistilBERT
- FastAPI
- React 19
- Three.js
- Vite
- Tailwind