Repository navigation
Commit fab459b
classification: GLiNER2 zero-shot + fine-tune scripts (train-gliner2.py, classify-gliner2.py) (#118)
* classification: train-gliner2.py + classify-gliner2.py — zero-shot first, then fine-tune
train-gliner2.py fine-tunes GLiNER2 (default fastino/gliner2.5-multi-v1) on any Hub dataset
with a text column and one or more label columns. It scores the base model zero-shot, trains,
and scores again on the same held-out rows; the model card reports both next to the
majority-class floor. Single-label and multi-label are auto-detected, and repeating
--label-column trains several tasks into one model. It records the tasks in
classification_schema.json so classify-gliner2.py can label a dataset with no label flags.
classify-gliner2.py labels a dataset zero-shot from --labels, or with a fine-tuned model.
The gliner2 trainer catches CUDA OOM, skips the batch and continues. On t4-small a 56-label
run skipped 1,006 of 1,020 steps and still "completed". train-gliner2.py now aborts after 5
OOM steps, before pushing, and suggests a batch size.
Verified on Jobs (t4-small): blbooksgenre 0.793 -> 0.925, ag_news 0.718 -> 0.852,
go_emotions micro-F1 0.265 -> 0.464, TREC-QC two tasks 0.542/0.468 -> 0.954/0.876; plus a
synthetic edge-case set (bracketed labels, missing labels, empty multi-label lists) and
zero-shot classification on cpu-basic (1.4 rows/s).
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* classification: report the BL books GLiNER2 row as five seeds, not the best one
The first run (seed 42) scored 0.925; four more seeds scored 0.897-0.908. The row now gives
the mean and range, and the README says what the spread means for comparing runs.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* classification: document the 30-minute Jobs timeout for train-gliner2.py
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* classification: gliner2 scripts — launch header, precision by GPU, GPU findings
- [tool.hf-jobs] header on both scripts (t4-small, 1h timeout, HF_TOKEN); verified with
--dry-run and with real submissions that pass no --flavor/--secrets flags.
- --precision auto|fp32|bf16: bf16 on Ampere or newer (gliner2's own default for the 2.5
models), fp32 on T4, chosen by compute capability because is_bf16_supported() is true on T4.
- ACCELERATOR was a bare "gpu" on t4-small and a10g-small, so the card's reproduce command
now falls back to the GPU name to pick the flavor.
- README: a10g-small fits the 56-label TREC run at batch size 16 (509s vs 1,761s on T4 at
batch size 4); bf16 and fp32 run at the same speed on A10G; hardware moves a fixed-seed
score by 1-2 eval rows.
- Tried and left out after they failed on Jobs with gliner2 2.0.0: gradient checkpointing
(crashes with the 2.5 models) and LoRA (final checkpoint did not load for scoring).
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* classification: train-gliner2 restarts at a smaller batch size on OOM
Instead of stopping after 5 out-of-memory steps, train-gliner2.py now restarts itself
(os.execv) at a quarter of the batch size with 4x the gradient accumulation, down to batch
size 1. Retrying inside the process does not work: after a failed run the gliner2 trainer
leaves its state on the GPU, so each retry starts with less memory. The restarted process
parses the new flags, so the model card's reproduce command names the batch size that worked.
Verified on Jobs: TREC-QC (56 labels) and IMDB (2,000-character reviews) both fell back from
16 to 4 on t4-small and completed; IMDB also fell back on a10g-small; BL books did not fall
back and reproduced 0.9253.
README: fix a blank line that split the results table, add the IMDB long-text row, and
describe the fallback.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019P6N4MBQsM535ZdEq5qi1j
* classification: train-gliner2 reads local files, scores several eval splits, exports predictions
- --train-file / --eval-file NAME=PATH (repeatable) load JSON Lines, e.g. from a mounted bucket.
Local eval files are scored in full and in file order.
- --labels-file fixes the label set and its order for training, zero-shot and eval, and stops
the run if the data has a label outside it.
- --export-predictions DIR writes {base,finetuned}-<split>/predictions.jsonl with the
probability and raw logit of every label per row (batch_score + decode).
- --no-push keeps the model in --output-dir/final. Pushed repos are now private by default
(--public to opt out); a private run refuses an existing public repo.
- --label-augmentation {upstream,off}: off sets synthetic_label_prob and
remove_classification_label_prob to 0, so training sees the real, complete label set.
- run_manifest.json (args, sampling config, precision, device, package versions, results).
- Model card reports the base model's parameter count instead of a fixed ~300M, and one
results table per eval split. README documents the options and an explicit --timeout.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* classification: classify-gliner2 pushes a private dataset by default
--public opts out; --private is still accepted. A private run stops before classifying if the
output dataset already exists and is public. Docstring notes the explicit --timeout.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* classification: move the GLiNER2 section out of the classify-dataset.py H1
It sits after the SetFit section, in index-table order, so the
classify-dataset.py Quick Start follows its own intro again.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* classification: classify-gliner2 declares its output features
A map batch where every confidence is None (multi-label with no label
selected, or rows with no text) typed the new columns as null, and the
next batch failed with "Couldn't cast array of type string to null".
Reproduced with the real model; explicit features fix it.
Also: the fine-tuned docstring example uses biglam/blbooksgenre (the
blbooks-parquet example could not finish), --timeout 1h in the examples
and the reproduce command, shlex-quoted reproduce values, a clear error
for a missing or inaccessible model repo, load_from_cache_file=False,
datasets<6, and ruff SIM102.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* classification: train-gliner2 exits clearly on an empty split, quotes reproduce values
A split with no usable rows after dropping unlabelled ones now stops
with a message instead of failing later. The card's reproduce and
classify commands shell-quote their values, and the classify snippet
passes --timeout 1h. datasets<6.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* classification: GLiNER2 train cost, pin chain, same-rows note
Train cost column at the current hf jobs hardware rates, the
transformers<5 -> huggingface_hub<1 pin chain versus the local hf CLI,
and a note that the fine-tune -> classify example labels training rows.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* classification: GLiNER2 README reorganised; findings move to GLINER2-NOTES.md
- README section: pitch, quick start, how to pass labels and models, results table
with a 52-label Hub task-tag row, model-size choice, fixed label sets, worked
example, short good-to-know list.
- GLINER2-NOTES.md: tested commands from the branch, table notes, the 52-tag
example, speed and quantization findings, behaviour details, dead ends.
- Cross-links between uv-scripts/classification (GLiNER2) and uv-scripts/gliner (GLiNER NER).
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* classification: train-gliner2 review fixes (label merge, zero updates, optimizer OOM)
- Check the raw -> cleaned label mapping before deduplicating: for a plain string
column, 'a (b)' and 'a b' were silently merged into one class.
- Fix operator precedence when collecting raw single-label names (it added the
characters of each label).
- Use the trainer's total_steps: a short run where every batch ran out of memory
(fewer than MAX_OOM_STEPS) no longer pushes an untrained model.
- Catch torch.cuda.OutOfMemoryError from the optimizer step, which gliner2 2.0.0
does not handle, so it restarts at a smaller batch size like other OOMs.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* classification: README puts GLiNER2 first, then SetFit, then train-classifier
Section and index-table order only, plus one line framing SetFit as the option for
8-64 labelled examples per class. No section content changed; anchors unchanged.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* classification: shorter GLiNER2 README section; detail moves to GLINER2-NOTES.md
The fixed-label-set / bucket command, the worked example's setup notes and three
behaviour bullets move to the notes file. The README keeps a pointer to each.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>1 parent 548719b commit fab459b
6 files changed
Lines changed: 2049 additions & 41 deletions
File tree
- classification
- gliner
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | | - | |
| 80 | + | |
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
0 commit comments