Skip to content

fix(fine_tuning): fix gliclass's few-shot segment tags and rerun - #37

Merged
rparundekar merged 3 commits into
mainfrom
fix/gliclass-few-shot-segments
Nov 15, 2026
Merged

rparundekar merged 3 commits into
mainfrom
fix/gliclass-few-shot-segments

Conversation

@rparundekar

Copy link
Copy Markdown
Collaborator

What

gliclass 0.1.22's _create_segment_ids (gliclass/model.py) finds the first few-shot example token with argmin instead of argmax. That returns position 0, so whenever a request includes examples, every token (labels and the row too) is tagged as an example. Only models with use_segment_embeddings read these tags. The instruct edge model, which few-shot uses, does; gliclass-edge-v3.0 doesn't, so zero-shot and fine-tuning are unaffected.

  • recipe.py replaces that one function with segment_ids(), which tags the input as labels (0), the row (1) and examples (2), as gliclass intends.
  • selfcheck.py checks the tags on hand-written token ids.
  • The README has the re-run numbers and says through SIE what's affected.

Results, re-run on the same rows

Banking77 Parser checks
Zero-shot (edge) 67.3% 30.0%
Zero-shot (instruct) 63.3% 20.0%
Few-shot (instruct), before → after the fix 26.0% → 57.3% 15.0% → 16.7%
Fine-tuned (edge) 93.3% 86.7%

Few-shot still scores below zero-shot, and on Banking77 it depends heavily on the order of the examples. Ten seeded shuffles of the same six examples score anywhere from 20.0% to 69.3%. Without the prompt it scores 36.7%. Two examples per label score 55.3%, and three per label 28.7%.

Through SIE: the 630 zero-shot and fine-tuned decisions still match the local run within 0.0001. Few-shot doesn't, because SIE's GLiClass adapter copies gliclass's segment tags as they are, bug included. This is worth fixing upstream in SIE.

Tested

I re-ran every number above myself on this branch: recipe.py, and the order, prompt and example-count probes. selfcheck.py (with the new segment-tag check), ruff, mypy --strict and check_tree.py pass.

🤖 Generated with Claude Code

rparundekar and others added 2 commits November 14, 2026 15:55
gliclass 0.1.22 finds the first example token with argmin instead of
argmax in _create_segment_ids, so with examples in the request every
token, labels and row included, is tagged as an example. The instruct
model few-shot uses reads those tags. recipe.py now replaces that one
function; selfcheck.py checks the tags.

Rerun on the same rows: few-shot goes from 26.0% to 57.3% on Banking77
and from 15.0% to 16.7% on the parser set, still below zero-shot (67.3%,
30.0%). Zero-shot and fine-tuned are unchanged. Through SIE, the 630
zero-shot and fine-tuned decisions still match within 0.0001; few-shot
doesn't, because SIE's adapter copies gliclass's tags as they are.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The README's "shuffled 39.3%" came from an unrecorded shuffle. Ten seeded
shuffles (random.Random(0..9)) of the six Banking77 examples score 20.0%
to 69.3% (seed 1 is the 39.3%); say that, and that the best order edges
past zero-shot.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rparundekar
rparundekar requested a review from a team as a code owner November 15, 2026 00:13
… fix

- Say the best few-shot order edges past the edge model's zero-shot.
- Drop a stock phrase.
- Link SIE's segment_ids(), which uses the same argmin, so the claim
  that SIE copies the bug is checkable.

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 77 lines in 3 files. No Critical or Important findings, and the security pass found nothing.

Checked:

  • segment_ids() returns what gliclass's _create_segment_ids would with argmax in place of argmin, in every case: no examples, examples, padding, no text marker, and a mixed batch. It returns int64 on the input's device, which the embedding layer accepts.
  • The patch runs where it should. The instruct model builds a GLiClassUniEncoder with use_segment_embeddings: true, and nothing overrides the method. The edge model never calls it, so zero-shot and fine-tuning are unaffected.
  • The selfcheck's expected tags are right.
  • Every README number matches the run outputs.

Suggestions (3, all fixed in 5fe91de):

  • "The best order edged past zero-shot" now says the edge model's zero-shot (67.3%). Few-shot runs on the instruct model, whose zero-shot is 63.3%.
  • Dropped "Your mileage may vary"; the sentence already says the result is for these models on this decision.
  • Linked SIE's GLiClass segment_ids(), which uses the same argmin, so the claim that SIE copies the bug is checkable.

One change before the review: the README said a shuffled example order scored 39.3%, from a shuffle that wasn't recorded. Ten seeded shuffles (random.Random(0..9)) score 20.0% to 69.3%, and seed 1 is the 39.3%. The README now gives the range (f7853ce).

@rparundekar
rparundekar merged commit e34bff0 into main Nov 15, 2026
50 checks passed
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