Making Qwen3-4B a dependable web→JSON extractor with Halo GRPO

Track: ft-hf (HuggingFace post-training) · Team lead: @rjaat Model: RJaat/qwen3-4b-web-extract-lora (LoRA on Qwen/Qwen3-4B-Instruct-2507) Code: the extraction/ directory of the competition fork (branch named in competition/SUBMISSION.md) Data: RJaat/web-extract-v1


1. What we did and why

A 4B model that turns a messy web page into schema-valid JSON — product listings, job posts, recipes — is a genuinely useful piece of local plumbing: private, free per call, and good enough to replace a hosted API for ETL and dataset building.

Base Qwen3-4B-Instruct-2507 is a strong generalist but a sloppy extractor. On our held-out real pages it scores 0.625 field-F1: it drops list items, misreads prices buried in prose, invents values for missing fields, and occasionally wraps JSON in commentary. We post-train it with Halo to fix exactly that.

Result: field-F1 on pages from domains the model never saw during training goes from 0.625 → 0.778 (+24% relative), schema-validity from 0.991 → 1.000, with general ability unchanged.

2. Method

Halo offline GRPO (LoRA r=64, α=128, all projection modules), three epochs on 374 prompts × 8 sampled completions.

Reward — verifiable, stdlib only

r = clip(0.4 · schema_valid + 0.5 · field_F1 − 0.1 · fabrication, 0, 1)

Because the reward is programmatic, it costs nothing per sample and cannot be gamed by stylistic noise — the only way to score is to be right.

Data

Source Role Rows
8 sites, scraped with Firecrawl (books.toscrape, python.org/jobs, WeWorkRemotely, Minimalist Baker, Cookie & Kate, Smitten Kitchen, Budget Bytes, Love & Lemons) real pages, provenance per row 243 pages
gpt-oss-20b / 120b via OpenRouter gold labels + noise variants 247 labels
extractkit.generator (seeded, parametric) synthetic pages for training volume 350 rows
Programmatic noise injection (boilerplate, teaser items) layout robustness, fact-preservation gate 75 variants

Every gold label was schema-validated and every gold value verified to be supported by its page — the same fabrication check used at eval time. Listing pages that slipped through URL filters were rejected by a quality gate (122 rows).

Split: near-duplicate clusters (minhash, Jaccard ≥ 0.8) are kept whole, then family-stratified ~25% to eval, so no cluster spans train and eval. The eval set contains domains the model never trains on (WeWorkRemotely, Love & Lemons, Smitten Kitchen).

Training

torchrun --nproc_per_node=1 scripts/training/grpo/offline.py \
    extraction/configs/extraction-offline-grpo.yaml

One H100, ~65 minutes, LoRA. The rollouts are checked in, so the run is reproducible without a rollout server or any API key.

3. Results

Held-out real pages, 3 seeds (0, 1, 2), temperature 0.7, top-p 0.95:

Eval set Metric Base Tuned Δ
real v1 (26 pages) field-F1 0.639 0.838 +0.199
real v2 hard (75 pages, unseen domains) field-F1 0.625 0.778 +0.153
real v2 hard schema-valid 0.991 1.000 +0.009
real v2 hard fabrication 0.0056 0.0034 −0.002
synthetic generator, eval seed 101 (120 items) field-F1 0.911 0.991 +0.080
fresh items, new seed 4242 (120 items) field-F1 0.910 0.991 +0.081
fresh items, new seed 4242 fabrication 0.0024 0.0012 −50%
general check (40 items) overall 0.925 0.925 0

The remaining errors are concentrated in job posts (salary period and requirement lists) and in long specification tables; product pages are the cleanest family.

General ability is untouched (math 0.8, knowledge 1.0, instruction 0.9, tool use 1.0 before and after), so the specialization did not cost us the base model.

How reliable is the gold itself?

Every number above is relative to labels produced by gpt-oss-20b/120b through OpenRouter. To check that those labels are not idiosyncratic, we re-labelled 90 pages with an independent annotator from a different model family — GLM-5.3-Flash via Baseten Model APIs — using the identical prompt and schema.

Family Pages Leaf agreement Exact page match
product 30 93.6% 76.7%
job 30 85.6% 16.7%
recipe 30 76.7% 20.0%
overall 90 87.3% 37.8%

A third annotator (Qwen3-14B via HuggingFace Inference) agrees with the Baseten labels on 84.1% of leaves across the 57 pages they share.

Two things follow. First, structured facts are stable — product pages agree at 94%, which is where our largest gain shows. Second, the disagreement is concentrated in free-text lists (recipe ingredients and steps, job requirement wording), which is expectable: two competent annotators write those differently even when both are right. That puts a ceiling on real-page scores: an extractor cannot beat its gold by more than the gold agrees with itself. The fresh-item evaluation does not have this problem — its gold is produced programmatically by the generator, so it is exact, and that is why we treat the fresh-item number as the cleanest evidence of the gain.

The full agreement reports are committed at extraction/results/annotator_agreement_openrouter.json and extraction/results/annotator_agreement_hf.json.

Iteration and what it bought

Round Training signal Hard-set F1
base — 0.625
r1 120 prompts × 8, lr 1e-6 — (v1: 0.663)
r2 374 prompts × 8, lr 2e-6 0.778

Round 1 taught format and honesty but only moved v1 by +0.02: the reward had little variance left on easy prompts (48/120 groups had zero-variance rewards). Scaling to the full prompt set and raising the learning rate is what unlocked the jump — a concrete instance of GRPO needing group variance to learn.

White Circle honesty signal

Two policies — Fabricated field values and Guessing missing fields — were run over all 4,488 rollouts of round 2 (environment halo-extraction). They flagged 173 completions (3.9%); honesty mean 0.964. The verdicts are usable as reward shaping (weight 0.3), and the flagged examples were the most useful debugging signal we had: they show exactly which page layouts invite invention (sparse spec tables and job posts with no stated salary).

4. How to reproduce

# train (1× H100, ~65 min)
torchrun --nproc_per_node=1 scripts/training/grpo/offline.py \
    extraction/configs/extraction-offline-grpo.yaml

# evaluate base and tuned on the hard held-out set
python3 extraction/eval_extract.py --model Qwen/Qwen3-4B-Instruct-2507 \
    --data extraction/data/eval_real_v2.jsonl --seeds 0 1 2
python3 extraction/eval_extract.py --model Qwen/Qwen3-4B-Instruct-2507 \
    --adapter <adapter path or HF id> \
    --data extraction/data/eval_real_v2.jsonl --seeds 0 1 2

eval_extract.py needs only transformers (+peft) from the public Halo image and the repo’s stdlib toolkit. No tokens, no installs.

Fresh items: python3 -m extractkit.generator --seed 4242 --n 120 renders new pages from the same distribution (seed never used for training); the tuned model scores 0.991 against the base model's 0.910 on that set, with fabrication halved.

5. Third-party materials

Material Use Licence
Qwen/Qwen3-4B-Instruct-2507 base model Apache-2.0
books.toscrape.com product pages (explicit scraping sandbox) demo site
python.org/jobs, WeWorkRemotely job posts site terms, public pages
Minimalist Baker, Cookie & Kate, Smitten Kitchen, Budget Bytes, Love & Lemons recipes site terms, public pages
openai/gpt-oss-20b, gpt-oss-120b via OpenRouter gold labels, variants Apache-2.0
Halo 1.3.0 (competition branch) training framework Halo Licence

No dataset or page content is redistributed verbatim in the model; the training corpus is released with per-row provenance.

6. Platforms used

Platform What we used it for
Modal All training and evaluation: offline GRPO on 1× H100 (~65 min/round), rollouts, and every eval run
Firecrawl Scraped the 243 real pages (8 sites) with per-page provenance, under 300 credits
OpenRouter Gold labelling and noise variants with gpt-oss-20b/120b (~$0.13 total)
White Circle Two honesty policies scored 4,488 GRPO completions (environment halo-extraction, 173 flagged)
Lovable Hosts the public project showcase at blue-ribbon-research.lovable.app: a visual copy of this writeup plus a side-by-side base-vs-tuned extraction demo
Baseten Model APIs: GLM-5.3-Flash re-labelled 90 pages as an independent annotator, producing the agreement numbers above (a few cents of credit)
HuggingFace Hosts the adapter, the dataset, and this writeup; Qwen3-14B via HF Inference as the third annotator

7. Limitations


Built with Halo. Competition: Halo Competition Participant Guide.