Skip to content

feat(fine_tuning): compare few-shot with zero-shot and fine-tuning - #36

Merged
rparundekar merged 2 commits into
mainfrom
feat/few-shot-decision-model
Nov 14, 2026
Merged

rparundekar merged 2 commits into
mainfrom
feat/few-shot-decision-model

Conversation

@rparundekar

Copy link
Copy Markdown
Collaborator

What

Adds a few-shot step to fine_tuning/fine_tune_a_decision_model, between zero-shot and fine-tuning, and adds both GLiClass models to MODELS.md.

Accuracy on held-out test rows Banking77 (150) Parser checks (60)
Zero-shot, GLiClass edge v3.0 67.3% 30.0%
Zero-shot, GLiClass instruct edge v1.0 63.3% 20.0%
Few-shot, instruct edge with 6 examples 26.0% 15.0%
Fine-tuned, edge v3.0 on 102 rows 93.3% 86.7%
  • Few-shot uses gliclass-instruct-edge-v1.0. It's the same size as the edge model (131 MB), and its model card documents few-shot examples. gliclass-edge-v3.0 doesn't read examples: given them, it put every test row in one label at a score of 0.999.
  • One example per label. Examples share the 1,024-token window with the row, and on the parser set two per label already overflow it. check_fits() stops the run instead of letting the model silently cut the row short.
  • Few-shot scored below zero-shot on both datasets, with most rows put in one or two labels. Without the prompt it did worse. With two and three examples per label on Banking77 it scored 20% and then 17%, with three per label putting every message in the same label. SIE's adapter (gliclass 0.1.17, transformers 4) gives the same numbers, so this isn't a setup problem.

Test split

The test rows are held out from training. Banking77 training rows come from its train split and test rows from its test split; the parser set is generated per label and split 17/10. There's no overlap in either dataset. The test sets have 150 and 60 rows.

Tested

  • recipe.py run on an Apple M-series laptop; the fine-tuned numbers are unchanged.
  • serve.py run against v0.11.1-cpu-default in Docker: all 840 decisions (4 approaches × 210 rows) match the local run, every score within 0.0001.
  • selfcheck.py (new few-shot check), ruff, mypy --strict and check_tree.py pass.

🤖 Generated with Claude Code

Few-shot uses knowledgator/gliclass-instruct-edge-v1.0 (same size as
the edge model and trained to read examples; edge v3.0 given examples
puts every row in one label) with one training row per label, which is
what fits the 1,024-token window on the parser set. Few-shot scored
below zero-shot on both datasets (Banking77 26.0% vs 63.3%, parser
checks 15.0% vs 20.0%); fine-tuning stays at 93.3% and 86.7%. SIE's
adapter (gliclass 0.1.17) gives the same numbers; serve.py scores all
four approaches and matched recipe.py on 840 of 840 decisions.

Adds both GLiClass models to MODELS.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rparundekar
rparundekar requested a review from a team as a code owner November 14, 2026 22:26
- check_fits() measures each input as GLiClass builds it (labels,
  prompt, the row, then the examples); it undercounted by leaving out
  the prompt. Parser set: 693 tokens at one example per label, 1,111
  (refused) at two.
- Say what overflow actually does: GLiClass cuts the examples off the
  end, not the row.
- Pass rules.yaml's window to the pipeline as max_length, so editing it
  changes the model as well as the check.
- serve.py records the example count in results.json, as recipe.py does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rparundekar

Copy link
Copy Markdown
Collaborator Author

Self-review

Two passes, code and security, since the diff is 209 lines in 7 files. Nothing Critical, and the security pass found nothing. Fixes are in aa05d36.

Important (3, all fixed)

  • check_fits() undercounted. It left out the task prompt, which GLiClass puts in the input, so a row near the limit could pass the check and still overflow. Fixed: it now measures each input the way GLiClass builds it. The parser set is 693 tokens at one example per label, and 1,111 at two, which it refuses.
  • The overflow message described the wrong thing. GLiClass builds the input as labels, prompt, the row, then the examples, and cuts what doesn't fit from the end. So overflow drops the examples, not the row. Fixed: the docstring, the error message and the README now say so.
  • window in rules.yaml only fed the check. The model used gliclass's default of 1,024 whatever you set. Fixed: it's now passed to the pipeline as max_length.

Suggestions

  • Fixed: serve.py records the example count in results.json, as recipe.py does.
  • Skipped: serve.py doesn't run check_fits(), which needs the model loaded locally. It reads the same rules.yaml as recipe.py, which checks the same examples.
  • Skipped: the README's few-shot figures for two and three examples per label (20%, then 17%), and its claim that SIE's adapter gives the same numbers, come from runs I did by hand that aren't in the recipe. The new check confirms Banking77 fits even at three per label, so those runs weren't distorted by truncation.

The code pass checked every number in the README against both run outputs, and all of them match. No test row is used as a few-shot example, and nothing refers to the old --zero-shot-only flag. After the fixes: selfcheck, ruff and mypy --strict pass, and recipe.py re-ran with unchanged numbers (67.3 / 26.0 / 93.3 and 30.0 / 15.0 / 86.7).

@rparundekar
rparundekar merged commit 7396f8a into main Nov 14, 2026
50 checks passed
@rparundekar
rparundekar deleted the feat/few-shot-decision-model branch November 14, 2026 23:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant