Problem
A telecom operator needs to recognize the intent of each customer phrase (26 classes, imbalanced like real traffic) and route it to a script or an operator. Fine-tuned BERT gave the best quality, but it has to run in a microservice on CPU-only servers under heavy HTTP load. Full-size BERT or RoBERTa models weigh more than 700 MB. The team had to trade inference speed against quality on the test set.
Example from the article: a customer writes "I would like to change the tariff for the internet" (in Russian) and the service must return the intent fast, on a CPU.
Solution in brief
Fine-tune a small distilled BERT, export it to ONNX, optionally quantize it to INT8, and serve it through ONNX Runtime behind FastAPI. The author benchmarked four Russian BERT models on one CPU core against native PyTorch and picked rubert-tiny2 as the best speed and quality compromise.
Questions this case answers
- How to serve a fine-tuned transformer classifier on CPU-only servers under online load without leaving the accuracy budget
- How to measure which inference optimization (runtime change, quantization, smaller model) pays off for a given batch size and input length
- How to make a fine-tuned BERT intent classifier fast enough for online prediction on CPU-only servers?
- How to choose between a distilled and a full-size BERT model when CPU latency is a hard constraint?
Tools and methods
- ONNX and ONNX Runtime — export the model graph and run CPU inference without the training stack
- Dynamic INT8 quantization (onnxruntime.quantization) — shrink weights to cut latency further
- PyTorch and Hugging Face Transformers — fine-tuning and the baseline for timing
- FastAPI — REST wrapper around the stateless inference function
Google or a one-time email code. No password.
