Skip to content

Port iteration 14 model to Rust classifier - #10

Merged
bfirestone merged 6 commits into
mainfrom
port-iter14-to-rust
Apr 8, 2026
Merged

bfirestone merged 6 commits into
mainfrom
port-iter14-to-rust

Conversation

@bfirestone

@bfirestone bfirestone commented Apr 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Featurizer alignment: Add shebang_present (#41), fix json_lines_ratio pre-normalization, fix inline_markup_count missing italic pattern, add CCpp/ObjC sub-types — comparison tool PASS (max MAE 0.003)
  • Model artifacts: Re-export ONNX as single file (no external data), update model_config.json to 41 features
  • Model-first classification: ONNX model handles all non-trivial samples when loaded, Tier 1 as fallback only — Rust eval 97.7% vs Python 97.6%
  • Sub-type probability distribution: Surface full softmax over 31 sub-types in classify file output, grouped by category — maps to Vespa tensor<float>(subtype{}) for ranking
  • --min-score threshold: Filter sub_type_scores and detections to drop noise (31 entries → 2-5 with --min-score 0.01)
  • Remove TextCategory::Skip: 3 categories only (Prose, Code, Structured) — empty→prose/0.0, too-short→prose/0.5
  • Python bindings: Classifier(min_score=0.01), extract_features() returns all 41 features, embedded model by default
  • Serde fixes: JavaScript→javascript, TypeScript→typescript, ObjC→objc; parse_sub_type handles c_cpp, objc, sgml

Test plan

  • make check (fmt, clippy, tests) — all pass
  • cargo test --features onnx-model — all pass (166 tests)
  • Featurizer comparison: PASS (max MAE 0.003, threshold 0.01)
  • classify validate on clear.jsonl: 97.7% accuracy (within 0.5pp of Python)
  • --min-score 0.01 filters 31 sub-type entries to 2-5
  • Manual: classify --min-score 0.01 file <input> -o <output> produces clean Vespa-ready JSONL

Closes textclf-1dd1.04w26k, textclf-1dd1.09kem4, textclf-1dd1.09j1g3, textclf-1dd1.078n9u

…ures)

- Add shebang_present feature (#41): 1.0 if text starts with #!
- Fix json_lines_ratio to compute on pre-normalization text
- Fix inline_markup_count: add missing *italic* pattern, rewrite as
  single-pass byte scanner matching Python regex semantics
- Add CCpp and ObjC variants to ContentSubType enum
- Update feature_vector_to_array to 41 features
- Update CSV output (classify features) to emit all 41 features
- Update label-corpus JSON to include all 41 features

Comparison tool: PASS — max MAE 0.003 across 500 samples (threshold 0.01)

Closes textclf-1dd1.09kem4 (featurizer alignment)
Closes textclf-1dd1.09j1g3 (c_cpp/objc enum)
Re-exported training/output/model.onnx as single file (no external data)
and copied model_config.json with 41 feature definitions.

All ONNX tests pass with --features onnx-model.
When the embedded ONNX model is available, all non-trivial samples
go directly to the model instead of through Tier 1 rules first.
Tier 1 serves as fallback when no model is loaded.

This closes the accuracy gap: Rust eval 97.4% vs Python 97.6%
(within 0.5pp tolerance). The old tiered approach (Tier 1 at 0.95
threshold) caused 75 confident-but-wrong Tier 1 decisions that the
model would have gotten right.

Also adds Classifier::with_embedded_model() constructor and uses it
in the CLI binary.
…on scores

- Add sub_type_scores field to Classification: full softmax distribution
  over all 31 sub-types grouped by category (no threshold filtering)
- Serialize Classification via serde in classify file output, so both
  detections and sub_type_scores appear automatically when model runs
- Fix serde labels: JavaScript→javascript, TypeScript→typescript, ObjC→objc
- Fix parse_sub_type: add c_cpp, objc, separate sgml from xml
- Update Python bindings: surface sub_type_scores, fix extract_features
  to return all 41 features, use embedded model by default
- Accuracy: 97.7% (up from 97.4% due to parse_sub_type fixes)

For Vespa: sub_type_scores maps to tensor<float>(subtype{}) for ranking.
The model has no concept of "skip" (category_map is {prose, code,
structured}). Skip was a ghost from the pre-model era.

- Remove TextCategory::Skip variant from enum
- Empty text → prose, confidence 0.0
- Too-short text → prose, confidence 0.5
- Tier 1 ambiguous fallback → prose, confidence 0.4
- Tier 2 no-model fallback → prose, confidence 0.3
- ContentSubType::Unknown now maps to Prose (not Skip)
- Update all tests to match new behavior

Closes textclf-1dd1.078n9u
…ections

Classifier::min_score(threshold) filters sub_type_scores and detections
to only include entries >= threshold. Drops empty category groups.

- Rust: Classifier::with_embedded_model().min_score(0.01)
- CLI: classify --min-score 0.01 file input.jsonl -o output.jsonl
- Python: Classifier(min_score=0.01)

Default is None (no filtering, all 31 sub-type scores included).
With --min-score 0.01, typical output drops from 31 to 2-5 entries.
@bfirestone
bfirestone merged commit b4e4533 into main Apr 8, 2026
1 check passed
@bfirestone
bfirestone deleted the port-iter14-to-rust branch April 8, 2026 02:42
bfirestone added a commit that referenced this pull request Apr 8, 2026
* feat(rust): align featurizer to iteration 14 Python pipeline (41 features)

- Add shebang_present feature (#41): 1.0 if text starts with #!
- Fix json_lines_ratio to compute on pre-normalization text
- Fix inline_markup_count: add missing *italic* pattern, rewrite as
  single-pass byte scanner matching Python regex semantics
- Add CCpp and ObjC variants to ContentSubType enum
- Update feature_vector_to_array to 41 features
- Update CSV output (classify features) to emit all 41 features
- Update label-corpus JSON to include all 41 features

Comparison tool: PASS — max MAE 0.003 across 500 samples (threshold 0.01)

Closes textclf-1dd1.09kem4 (featurizer alignment)
Closes textclf-1dd1.09j1g3 (c_cpp/objc enum)

* feat(model): update ONNX model to iteration 14 (seed=789, 41 features)

Re-exported training/output/model.onnx as single file (no external data)
and copied model_config.json with 41 feature definitions.

All ONNX tests pass with --features onnx-model.

* feat(classify): model-first classification when ONNX model is loaded

When the embedded ONNX model is available, all non-trivial samples
go directly to the model instead of through Tier 1 rules first.
Tier 1 serves as fallback when no model is loaded.

This closes the accuracy gap: Rust eval 97.4% vs Python 97.6%
(within 0.5pp tolerance). The old tiered approach (Tier 1 at 0.95
threshold) caused 75 confident-but-wrong Tier 1 decisions that the
model would have gotten right.

Also adds Classifier::with_embedded_model() constructor and uses it
in the CLI binary.

* feat(classify): surface sub-type probability distribution and detection scores

- Add sub_type_scores field to Classification: full softmax distribution
  over all 31 sub-types grouped by category (no threshold filtering)
- Serialize Classification via serde in classify file output, so both
  detections and sub_type_scores appear automatically when model runs
- Fix serde labels: JavaScript→javascript, TypeScript→typescript, ObjC→objc
- Fix parse_sub_type: add c_cpp, objc, separate sgml from xml
- Update Python bindings: surface sub_type_scores, fix extract_features
  to return all 41 features, use embedded model by default
- Accuracy: 97.7% (up from 97.4% due to parse_sub_type fixes)

For Vespa: sub_type_scores maps to tensor<float>(subtype{}) for ranking.

* chore: remove TextCategory::Skip — 3 categories only

The model has no concept of "skip" (category_map is {prose, code,
structured}). Skip was a ghost from the pre-model era.

- Remove TextCategory::Skip variant from enum
- Empty text → prose, confidence 0.0
- Too-short text → prose, confidence 0.5
- Tier 1 ambiguous fallback → prose, confidence 0.4
- Tier 2 no-model fallback → prose, confidence 0.3
- ContentSubType::Unknown now maps to Prose (not Skip)
- Update all tests to match new behavior

Closes textclf-1dd1.078n9u

* feat(classify): add --min-score threshold for sub-type scores and detections

Classifier::min_score(threshold) filters sub_type_scores and detections
to only include entries >= threshold. Drops empty category groups.

- Rust: Classifier::with_embedded_model().min_score(0.01)
- CLI: classify --min-score 0.01 file input.jsonl -o output.jsonl
- Python: Classifier(min_score=0.01)

Default is None (no filtering, all 31 sub-type scores included).
With --min-score 0.01, typical output drops from 31 to 2-5 entries.
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