Case study
Model adaptation with LLMs, embeddings, and classifiers
Fine-tuning where prompting and retrieval run out, using SFT with LoRA, contrastive embeddings, and transformer classifiers taken from 78% to 89% accuracy.
- Role
- Machine Learning Engineer
- Context
- Acranton · projects
- When
- 2022 – 2025
- Core stack
- PyTorch, Hugging Face Transformers, PEFT / LoRA
- sentiment accuracy, up from 78%
- 89%
- inference latency
- −30%
- F1 on imbalanced classes
- +10%
Problem
Off-the-shelf models were close but not good enough. They didn’t follow domain-specific instructions reliably, retrieval missed domain phrasing, and classifiers plateaued on the classes that mattered most. Each needed adaptation, under a GPU budget.
Constraints
- Compute. Full fine-tuning of large models wasn’t affordable, so memory and training cost had to come down.
- Production readiness. Models had to be served fast, not just score well offline.
- Imbalanced labels. The minority classes were often the important ones.
Approach
LLMs: SFT with parameter-efficient adapters
I fine-tuned open-source LLMs for domain-specific instruction following using supervised fine-tuning (SFT) and PEFT. LoRA adapters kept the base model frozen, which reduced GPU memory and training cost while preserving model performance. The training pipelines covered dataset curation, prompt formatting, evaluation metrics, and inference optimization.
Embeddings: contrastive fine-tuning for retrieval
General-purpose embeddings blur domain distinctions, so I fine-tuned transformer embedding models on domain-specific text pairs with a contrastive objective (Sentence Transformers). This improved top-k retrieval relevance and downstream QA performance in RAG and semantic search.
Classifiers: accuracy and latency together
At Acranton I optimized and fine-tuned transformer NLP models, raising sentiment classification accuracy from 78% to 89% while cutting inference latency 30%. On imbalanced sentiment tasks, Hugging Face Transformers fine-tuning gave a 10% F1 improvement. Custom classification models raised data-pipeline accuracy 18% and cut processing time 25%.
Results
- sentiment classification accuracy, up from 78%
- 89%
- inference latency
- −30%
- F1 on imbalanced sentiment classes
- +10%
- pipeline accuracy / processing time (custom classifiers)
- +18% / −25%
Stack
- Training
- PyTorch
- Hugging Face Transformers
- PEFT
- LoRA
- Sentence Transformers
- Experimentation
- Weights & Biases
- Optuna
- MLflow
Related writing
- Multi-Label Classification Using Hugging Face Transformer: fine-tuning a transformer classifier end to end.
- Sentiment Classification and Word Embeddings: an LSTM sentiment model and what its embeddings learn.