Phygitalytics
← Fine-Tuning

Fine-Tuning · Article

Classical models learn strings, the fine-tuned LLM learns the task


title: "Classical models learn strings, the fine-tuned LLM learns the task: ML vs DL vs SFT on UPI payments" thumbnail: figures/slide_02.png authors:

  • user: phygitalytics

tags: [qwen3, trl, sft, lora, text-classification, scikit-learn, lightgbm, evaluation, fintech, upi]


ML vs deep learning vs supervised fine-tuning on one frozen UPI dataset, scored once on 600 payments from payees no model had ever seen

Every personal-finance app in India has to answer the same question thousands of times a day: what was this UPI payment for? The usual answer is a keyword list or a TF-IDF classifier, and the usual accuracy claim is "96%". We wanted to know what happens when the same models meet the kirana store that opened last week, so we ran ten of them through one experiment, from a majority-class baseline to Qwen3-1.7B fine-tuned with LoRA.

The rule was apples to apples. One frozen dataset, one input string, one evaluator, one test set scored once, and paired significance tests on the same rows. This post reports what happened, what we learned, and how we would put it into production.

TL;DR

  • Fine-tuning wins by 27 points on unseen payees. Qwen3-1.7B + LoRA scores 89.8% (95% CI 87.2–92.0). The best classical model, a TF-IDF + linear SVM, scores 62.7%. Exact McNemar p < 0.0001.
  • The win is generalisation, not accuracy. On payees built from familiar vocabulary, LightGBM (97.2%) and SFT (98.1%) are tied. On new vocabulary, SFT keeps 85.2% and the classical models fall to 34–45%.
  • Validation could not see it. Every classical model scored 94–96 macro-F1 on validation, the same as SFT. On test they lost 31–38 points; SFT lost 7.
  • Zero-shot prompting lost to a 90-word keyword list (51.0% vs 58.7%, p = 0.002). It sent 284 of 600 payments to "Transfers to People".
  • Deep learning from scratch memorised better and generalised worst. The character CNN was second-best on familiar words and worst of all trained models on new ones (33.9%).
  • SFT is not ready to ship. It passes 8 of 10 measured ship-gate checks. It misses format consistency (87.8% vs a 90% bar) and p95 latency (515 ms vs 400 ms).

Problem statement

A model reads one payment string and returns one of 12 budget categories:

Paid Rs 370 to Udupi Bhavan Velachery (udupibhavan.vel@oksbi) on 12 Aug 2026 13:05. Note: lunch
→ Dining & Food Delivery

The categories are Groceries, Dining & Food Delivery, Transport & Fuel, Utilities & Bills, Rent & Housing, Shopping, Entertainment & Subscriptions, Health & Pharmacy, Education, Travel, Transfers to People, and Investments & Insurance.

The payments you have already seen are easy. What makes the task hard is everything else:

  • generic names like "Sri Balaji Enterprises" that only the note can disambiguate;
  • rent paid to a person's name, which looks exactly like a friend transfer;
  • opaque QR handles such as q482019334@ybl;
  • empty or vague notes ("paid", "ok", or nothing);
  • new merchants whose names use words the model has never seen.

The experiment answers two questions. Does a fine-tuned small LLM beat classical ML and DL by enough to justify a GPU? And if it does, where does the gain come from: depth, prompting, or pretraining knowledge?

Sample dataset

The dataset is synthetic, so the difficulty sits exactly where we put it. It is generated once with seed 7, frozen, and fingerprinted (81c7de0b0e5ecafa). Every notebook checks the fingerprint before it scores anything.

SplitRowsWhat it is
train4,48465% of payees
val77410% of payees: new names built from training vocabulary
test60025% of payees, 50 per category; mostly new vocabulary
seen_test300held-back payments from training payees

Split by payee, not by row. With our split, 0% of test VPAs appear in training. A random row-level split of the same data puts 96.8% of test VPAs into training, which is how a vendor ends up quoting "96% accurate". 64% of test payments also draw on name words and notes held out of training entirely ("Homestay", "Physiotherapy").

seen_test exists to measure memorisation. The seen-vs-unseen gap is seen_test accuracy minus test accuracy, and we use it throughout.

Some real rows from test.csv. None of these payees appear in train or val:

PayeeHandleRsNoteLabel
Jai Venkateswara Agenciesq414774121@paytm8,075(empty)Shopping
Holiday Hotel Stay Adyarholidayhotelstayad.hsr@okhdfcbank718bus ticketTravel
Urban Tiffin Centre T Nagarpaytmqr9159020@paytm1,460upiDining & Food Delivery
Talent Learning Adyartalentlearningadya@axl4,572(empty)Education
Sri Pooja Traderssripoojatraders@ibl233eggs breadGroceries
Stream Club Powaistreamclubpowai.56@okhdfcbank493(empty)Entertainment & Subscriptions

Algorithms

FamilyModelHardwareTrain time
BaselineMajority classCPU0
BaselineKeyword rules (90 hand-written keywords)CPU0
MLTF-IDF words + logistic regressionCPU1.4 s
MLTF-IDF chars + words + logistic regressionCPU7.9 s
MLTF-IDF chars + words + linear SVMCPU4.0 s
MLTF-IDF + LightGBM (early-stopped on val)CPU52 s
DLCharacter CNN from scratch (PyTorch, 0.25M params)CPU92 s
PromptingQwen3-1.7B zero-shot / few-shot (12 examples)NVIDIA L40
SFTQwen3-1.7B + LoRA (17.4M trainable, 1%)NVIDIA L411.2 min

SFT config (TRL `SFTTrainer`): LoRA r=16, alpha 32, dropout 0.05 on all linear layers; 2 epochs; lr 2e-4 cosine; batch 16; bf16; loss on the completion only; Qwen3 thinking disabled.

The contract that keeps it fair:

  • Every model reads the same canonical text string, with no extra amount or time features.
  • Hyperparameters, early stopping and checkpoint choice use validation only. Test is scored once.
  • One evaluate() function scores everything. An invalid LLM output counts as wrong.
  • Uncertainty comes from a 95% bootstrap CI on accuracy and paired exact McNemar tests on the same 600 rows.
  • Format consistency re-renders each payment as a bank SMS, JSON and key=value text, and checks that the answer stays the same.

Two DL models in the notebooks, fine-tuned DistilBERT and frozen bge-small embeddings with an MLP, did not run in this round. They are the most important missing rung, and the first next step.

Algorithm outcomes

The leaderboard

ModelVal F1Test acc95% CISeen accGapConsistencyp50 latency
Qwen3-1.7B SFT-LoRA97.089.887.2–92.098.38.587.8504 ms (L4)
TF-IDF char+word + SVM94.462.758.8–66.599.336.785.54.0 ms (CPU)
TF-IDF + LightGBM96.160.756.8–64.398.738.063.36.7 ms (CPU)
Keyword rules84.258.754.7–62.381.022.3100.00.01 ms (CPU)
TF-IDF char+word + LR93.858.754.8–62.799.741.084.04.0 ms (CPU)
Qwen3-1.7B few-shot62.158.254.0–62.066.78.558.0143 ms (L4)
Char-CNN (scratch)95.856.552.5–60.399.342.861.21.2 ms (CPU)
TF-IDF words + LR95.256.252.0–60.099.743.583.22.8 ms (CPU)
Qwen3-1.7B zero-shot57.751.047.2–55.059.08.071.8257 ms (L4)
Majority class1.38.36.2–10.58.30.0100.01.7 ms (CPU)

SFT is 27 points clear. The next eight models sit in a 51–63 band where most differences are not significant.

Read the gap column first. Every classical and DL model scores 98.7–99.7% on payees it trained on and 56–63% on new ones. All three LLM variants have a gap near 8, including zero-shot, which never saw a training row. So about 8 points is simply how much harder the unseen payees are, and SFT's memorisation gap is essentially zero.

The win is generalisation

Split the test set by whether the payee was built from familiar vocabulary (216 rows) or held-out vocabulary (384 rows):

ModelFamiliarNewDrop
TF-IDF + LightGBM97.240.1−57
Char-CNN96.833.9−63
TF-IDF + SVM94.444.8−50
Qwen3-1.7B zero-shot61.145.3−16
Qwen3-1.7B SFT-LoRA98.185.2−13

On familiar words, a 4 ms CPU model is as good as a 1.7B LLM. If your merchant universe is closed and stable, you do not need an LLM.

On new words, the classical models collapse, because they learned strings. The fine-tuned LLM already knows from pretraining that "Homestay" is travel, "Physiotherapy" is health and "Fibernet" is a bill. Fine-tuning taught it the taxonomy and the output format; pretraining supplied the world knowledge.

Validation said tie, test said 27 points

On validation alone, we would have called it a tie and shipped the 4 ms model. Validation payees are new names built from training vocabulary; test payees mostly use new vocabulary. That is not a trick. It is what production looks like six months after launch, when new merchants open and nobody has retrained. GroupKFold by payee told the same false story in an earlier run (about 95% for every ML model).

Paired significance

A vs BA right, B wrongB right, A wrongDiffp
SFT vs LightGBM1827+29.2< 0.0001
SFT vs SVM17714+27.2< 0.0001
SFT vs few-shot20515+31.7< 0.0001
SFT vs Char-CNN21212+33.3< 0.0001
Few-shot vs zero-shot13794+7.20.006
LightGBM vs Char-CNN5833+4.20.012
LightGBM vs keyword rules8674+2.00.38
Zero-shot vs keyword rules85131−7.70.002

When SFT and LightGBM disagree, SFT is right 182 times and LightGBM 7. The last two rows are the uncomfortable ones. Tuned LightGBM cannot be distinguished from a keyword list that took ten minutes to write, and zero-shot prompting is significantly worse than it.

Hard slices, and why prompting failed

Slice (n)RulesSVMLightGBMChar-CNNZero-shotFew-shotSFT
Generic names (50)20302836263272
Empty note (220)45514544454986
Opaque QR handle (155)53556052526392
Payments ≥ Rs 5,000 (101)63767275435288

Prompting a small model did not produce a classifier:

  • Zero-shot predicted "Transfers to People" 284 times out of 600. Travel was predicted once (2% recall).
  • Few-shot raised accuracy 7 points but moved the collapse instead of removing it: Shopping was predicted 129 times and Investments 103, while Transfers recall fell from 96% to 16%. Invalid outputs rose to 2.3% and format consistency fell to 58%, the worst of any model.

In-context examples moved the bias. They did not teach the task.

What SFT still gets wrong

SFT made 61 errors out of 600, in four buckets:

  • Taxonomy ambiguity (12): bus operators and cab rentals are Travel in our labels and Transport to the model; DTH providers are Utilities to us and Entertainment to the model.
  • Rent vs investment (5): rent payments with the note "deposit".
  • Groceries vs shopping (12): every one has an empty note, usually with a generic name ("Jai Arun Centre") or "Store" in the name.
  • Shopping is the weakest category at 72% recall, because it is the catch-all bucket.

An ensemble would not help. 54 of SFT's 61 errors are also LightGBM errors, and an oracle picking the right answer from either model reaches only 91.0%. The next gains come from a clearer taxonomy and better labels, not a bigger model.

What it costs, and the ship gate

Best ML (SVM)SFT-LoRA
Accuracy on unseen payees62.7%89.8%
p50 latency, one payment4.0 ms on CPU504 ms on an L4
Throughput~8,000 / s~28 / s (batch 64)
Training4 s11.2 min

That is 27 points of accuracy for more than 100× the latency on more expensive hardware. SFT was even slower than zero-shot (504 vs 257 ms), because we served the LoRA adapter unmerged and generated the full multi-token label.

We applied the 11 ship-gate bars frozen in our companion UPI ship-gate lab. Applying them here is retrospective, so treat this as a read, not a verdict:

CheckBarSFT-LoRA
Accuracy, unseen payees≥ 80%89.8%✅
Macro-F1≥ 0.780.899✅
Worst-category recall≥ 50%72%✅
Groceries recall≥ 50%86%✅
Format consistency≥ 90%87.8%❌
Invalid outputs≤ 1%0.17%✅
p95 latency, batch of 1≤ 400 ms515 ms❌
Avg prompt tokens≤ 300not measuredn/a
Margin over best baseline≥ 5 pts+27.1✅
Seen vs unseen gap≤ 10 pts8.5✅
Accuracy on Rs 5,000+≥ 80%88.1%✅

8 of 10 measured checks pass: not ready to ship. The best model on the scoreboard still gets sent back, and that is the gate doing its job.

Learnings

  1. Test on tomorrow's data. Holding out payees is not enough; hold out vocabulary, or whatever novelty production will bring. Our validation set ranked a memoriser and a generaliser as equals.
  2. Report seen vs unseen, always. It is the cheapest memorisation detector there is. A model that scores 99% on seen payees and 60% on new ones is a lookup table.
  3. Build the dumb baseline first. 90 keywords tied tuned ML (p = 0.38) and beat zero-shot prompting.
  4. Prompting a small model is not a classifier. It collapses onto a default class, and examples just move the collapse.
  5. The gain came from pretraining, not depth. A deep model from scratch memorised better and generalised worst.
  6. Fine-tuning is cheap; serving is not. 11 minutes and 17M trainable parameters bought 27 points. Paying 500 ms per payment is the real decision.
  7. Read the errors before scaling up. Most of SFT's remaining errors are label ambiguity that LightGBM also gets wrong.
  8. Freeze the gate before you run. Without bars written down in advance, we would have rationalised both failures.
  9. Dependencies are part of the experiment. The first SFT run died on Colab's preinstalled torchao 0.10 against PEFT's requirement for ≥ 0.16. Pin versions and keep a fix-it cell.

Pros and cons

ApproachProsCons
Keyword ruleszero training, 0.01 ms, 100% format-consistent, explainable; tied tuned ML47% on new vocabulary; manual upkeep; silently defaults everything else to one bucket
Classical MLtrains in seconds, ~4 ms on CPU, 94–97% on familiar merchants, cheap nightly retrainmemorises strings: 37–44 pt gap, 34–45% on new words; validation hides it; LightGBM 63% consistency
DL from scratch1.2 ms, 0.25M params, learns sub-word patterns automaticallyno world knowledge: worst on new words (33.9%); 61% consistency; lost to LightGBM
LLM promptingno labelled data; strong where world knowledge is obvious (Health 86–94%)lost to rules; collapses onto a default class; few-shot 2.3% invalid and 58% consistency; needs a GPU
LLM SFT-LoRA89.8% on unseen payees, +27 pts, 85% on new words, ~0 memorisation gap, best on every hard slice~100× the latency on a GPU; misses the consistency bar; still confuses ambiguous categories

Production approach

No single approach wins every column, so we would not ship a single model. The design below is proposed, not yet measured end to end. It rests on two results from this run: classical models score 98.7–99.7% on payees they have seen, and SFT is the only model that holds up on new ones. So route on payee familiarity, not on model confidence.

  1. Normalise: SMS, JSON or key=value input becomes one canonical string.
  2. Merchant cache: a VPA or payee that has been seen and confirmed returns its category in about 0 ms.
  3. Fast model: the SVM handles known payees at 4 ms on CPU.
  4. SFT-LoRA: only new payees go to the LLM, served with a merged adapter and single-pass scoring of the 12 labels.
  5. Review and learn: low-margin or known-ambiguous pairs go to the user to confirm, and every confirmation becomes a cache entry, so the expensive path shrinks over time.

GPU load then scales with novelty, not traffic. Guardrails cover the known ambiguities (labelling rules for DTH, bus operators and "deposit"), ask for confirmation before budget alerts on payments of Rs 5,000 or more, and fall back to the fast model if the LLM times out.

The single most useful live metric is the share of traffic from new payees, because that is where classical models fail and where the LLM tier carries load. Alongside it we would track:

  • the seen-vs-unseen gap on labelled samples;
  • format consistency across SMS, app and bank feeds;
  • correction rate by category;
  • p95 latency and timeouts;
  • invalid outputs.

Pilot gates:

  • all 11 ship-gate checks pass on a fresh held-out set, frozen before the run;
  • ≥ 85% on a labelled sample of real payments;
  • consistency ≥ 90%;
  • p95 ≤ 400 ms on the target serving stack;
  • no regression against the fast model on known payees.

Next steps

Ordered by how much each could change the recommendation:

  1. Add the encoder rung. Fine-tuned DistilBERT and frozen bge-small + MLP have some pretraining knowledge at a fraction of the LLM's cost. If one reaches ≥ 80% on unseen payees at ≤ 20 ms, the LLM tier may not be needed at all.
  2. Fix serving. Merge the LoRA adapter, score the 12 labels in one forward pass, serve with vLLM, and re-measure against the 400 ms bar.
  3. Mixed-format training. Train on SMS, JSON and key=value renderings to push consistency past 90%.
  4. Clean the taxonomy. Write labelling rules for bus operators, DTH and "deposit", then re-score.
  5. GRPO on top of SFT. Use a verifiable reward on fresh payees. Success means a paired gain over SFT with p < 0.05.
  6. Seeds and real data. Run 3 seeds per model and evaluate on a labelled sample of real UPI text.

Limitations. The data is synthetic, and we designed its difficulty, including the held-out vocabulary. The direction of these results should transfer to real UPI data; the exact numbers will not. Each model ran once with one seed, so the CIs cover test-set sampling, not training variance. ML and Char-CNN ran on CPU and the LLM on an L4, so accuracy comparisons are exact but latency comparisons are indicative.


Built with Qwen3-1.7B, TRL, PEFT, transformers, scikit-learn and LightGBM.

Need a small model trained for your task?

Tell us the job. We will tell you if fine-tuning is the right answer.