Fine-tuned distilbert-base-uncased on the GLUE SST-2 sentiment classification task using LoRA (Low-Rank Adaptation) for parameter-efficient training.
This model is the sentiment pre-screening layer in a production insurance claims triage pipeline: negative-sentiment claims above a confidence threshold are routed for HUMAN_REVIEW before an LLM routing agent is invoked, reducing LLM calls by ~35% on high-volume batches.
q_lin, v_lin (query + value attention projections)
Trainable parameters
592,130 / 67,578,884 (0.88%)
Training dataset
GLUE SST-2 (67,349 examples)
Training steps
300
Batch size
64
Learning rate
2e-4
Optimizer
AdamW (weight decay 0.01)
Precision
FP32
Architecture notes
LoRA injects trainable low-rank matrices into the attention projections:
Original: y = W₀x (W₀ frozen)
LoRA: y = W₀x + (alpha/r) · BAx
B ∈ R^{768×8}, A ∈ R^{8×768} (initialized: B=0, A~Normal)
Only the B and A matrices are trained, reducing memory footprint by ~99% compared to full fine-tuning. At inference, LoRA weights are merged into W₀ via model.merge_and_unload() — zero overhead at serving time.
Training infrastructure
The training pipeline was built and tested in both single-process and distributed configurations:
Single process: HuggingFace Trainer API with LoraConfig from PEFT
Distributed (DDP): PyTorch DistributedDataParallel with DistributedSampler, gloo backend for CPU / nccl for GPU clusters
Distributed (Accelerate): HuggingFace Accelerate with gather_for_metrics() for rank-aware evaluation
Cloud deployment: Containerised and deployed to AWS SageMaker and GCP Vertex AI inference endpoints for A/B cost benchmarking
Systematic analysis of high-confidence mispredictions (confidence > 0.80, wrong class):
Failure type
Example
True
Predicted
Why
Negation blindness
"The film is not terrible"
NEG
POS
Negation token attention weight is low relative to "terrible"
Sarcasm
"Oh great, another superhero movie"
NEG
POS
Sarcastic positive surface form; no pragmatic layer
Mixed valence, recency
"Beautiful cinematography, but the story is a mess"
NEG
NEG
Last clause dominates via positional attention bias
Short inputs
"Awful."
NEG
POS (conf=0.81)
Insufficient context for attention heads; single token
Domain shift
Legal/medical vocabulary with clear sentiment
—
—
OOD vocabulary degrades confidence uniformly
These failure modes are used as evaluation test cases in the dual-layer evaluation framework (Ragas + LangSmith) to catch alignment regressions before production deployment.
Usage
python
1from transformers import pipeline
23pipe = pipeline(4"text-classification",5 model="ahnafthaqeef/distilbert-sst2-lora",6 device=-1,7)89result = pipe("The movie was surprisingly moving and well-acted.")10# [{'label': 'POSITIVE', 'score': 0.923}]1112result = pipe("Barely watchable. The plot made no sense.")13# [{'label': 'NEGATIVE', 'score': 0.911}]
Loading the LoRA adapter separately (before merge):