Repository navigation
Port iteration 14 model to Rust classifier - #10
Merged
Merged
Conversation
…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
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
shebang_present(#41), fixjson_lines_ratiopre-normalization, fixinline_markup_countmissing italic pattern, addCCpp/ObjCsub-types — comparison tool PASS (max MAE 0.003)model_config.jsonto 41 featuresclassify fileoutput, grouped by category — maps to Vespatensor<float>(subtype{})for ranking--min-scorethreshold: Filtersub_type_scoresanddetectionsto drop noise (31 entries → 2-5 with--min-score 0.01)TextCategory::Skip: 3 categories only (Prose, Code, Structured) — empty→prose/0.0, too-short→prose/0.5Classifier(min_score=0.01),extract_features()returns all 41 features, embedded model by defaultJavaScript→javascript,TypeScript→typescript,ObjC→objc;parse_sub_typehandlesc_cpp,objc,sgmlTest plan
make check(fmt, clippy, tests) — all passcargo test --features onnx-model— all pass (166 tests)classify validateon clear.jsonl: 97.7% accuracy (within 0.5pp of Python)--min-score 0.01filters 31 sub-type entries to 2-5classify --min-score 0.01 file <input> -o <output>produces clean Vespa-ready JSONLCloses textclf-1dd1.04w26k, textclf-1dd1.09kem4, textclf-1dd1.09j1g3, textclf-1dd1.078n9u