Hugging FaceDominiciTutorial
My Journey to a serverless transformers pipeline on Google Cloud
Summary
The post documents Maxence Dominici’s effort to deploy a Transformers sentiment-analysis pipeline on Google Cloud for classifying customer reviews from Discord. After considering AI Platform Prediction and App Engine, he chose Cloud Run with a Docker image because custom checkpoint handling, dependencies, and resource requirements made the other options unsuitable. The implementation uses a PyTorch DistilBERT model fine-tuned on SST-2, Flask, Gunicorn, and a GET request protected by an optional API key; the shown handler retrieves a review but passes the hard-coded text “that was great” to the classifier. Cloud Run is configured with 4 GB of memory, one worker, and one thread to limit memory pressure and billing. Requests take under five seconds including model loading, while cold starts may add about ten seconds, and the author reports that the pretrained model’s accuracy was already impressive.
Context
The goal was to create a microservice that detects whether customer reviews left in Discord are positive or negative, enabling different follow-up actions for dissatisfied customers. Expected usage was low—up to 2,000 requests per month—so the author did not impose performance or scalability constraints.
Approach / What changed
The implementation packages a PyTorch DistilBERT sentiment model, its configuration and vocabulary, Flask application code, and pinned dependencies in a Docker image. The image runs on Cloud Run with Gunicorn, one worker, one thread, and 4 GB of memory. The service accepts review and API-key query parameters and uses the Transformers sentiment-analysis pipeline; deployment uses Google Cloud Build and Cloud Run commands.
Takeaways
Cloud Run was selected after AI Platform Prediction encountered beta-service issues and App Engine had TensorFlow installation problems and limited PyTorch concurrency.
The container uses PyTorch DistilBERT fine-tuned on SST-2, with 4 GB of memory and a single worker and thread to accommodate model memory usage and limit billing exposure.
Measured request handling took less than five seconds including pipeline loading and prediction, while cold starts could add roughly ten seconds; loading the model at startup was identified as a possible improvement.
Source and freshness
- Source
- huggingface.co
- Published
- Added to Yomu
- Last updated
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.