Skip to content

feat(disfluency): the tree cutter and the cut filter run after the rules - #396

Merged
znat merged 4 commits into
mainfrom
feat/tree-cutter
Nov 4, 2026
Merged

znat merged 4 commits into
mainfrom
feat/tree-cutter

Conversation

@znat

@znat znat commented Nov 4, 2026

Copy link
Copy Markdown
Owner

With parse: vectors, disfluency.py now runs the tree cutter after its rules. The parse's reparandum arcs propose cuts, the cut filter V scores each one, and a cut with P(real) >= 0.75 is applied when no rule already cut one of its words. With parse: true, the default in config.example.yaml, nothing changes. The live gate shows 0 differences for parse: true.

On real dev, through the transform as the app runs it, the tree cutter takes fixed corrections from 122 to 146 and false-cut words from 12 to 16, with the filler rule off. That is the R+T number the training code measured. Real dev half 2 has been scored several times, so turning it on by default needs fresh dictations.

One addition to the measured R+T, for the owner to accept or not: a tree cut that is the first copy of a doubled letter the rules keep as a spelling is not applied. Without it, the keep case "it takes A A batteries" was cut (V 0.95). "I I" is exempt, because "I" is a word. On the public dev sets this changes no output. Vetoing on every KEPT guard instead cost 6 fixes on AMI dev and was rejected.

Out of scope: the too-big cuts that arc merging in groups makes (ported as it is; the next PR), retraining V on cleaned-text candidates, and parse: vectors by default.

Review first:

  • tree_cut and guarded in disfluency.py. tree_cut is the wiring. guarded keeps a doubled letter the rules keep as a spelling ("it takes A A batteries").
  • cut_spans, factored out of resolve, so the filler rule and the tree cutter delete text with the same code.
  • The ported section (subtree to cut_filter). It is kept close to the training code so the two diff by eye.
One step after the rules, standard library only; V's weights are a 74 KB JSON file beside the script
  • One step, R+T. The parse is of the step's input. The rules run first, then the filler rule. Then the tree cutter runs on that same parse. placed() maps the rules' output back onto the parse words. A proposal is applied only when all its words survived the rules, so the filler rule's cuts count as rules' cuts. There is no second parse.
  • Opt-in. The tree cutter runs when every parse word carries vector, which only parse: vectors sends. There is no new config key.
  • Pure Python, standard library. These are ported from training/syntax-parser: groups, derive_tags, gap_cues, of_clip, text_cue, text_features, the vector pooling (word_vectors, of_cand) and V. The vectors are decoded with struct (<384e).
  • V's weights. They are in built-in/transforms/disfluency/cut-filter.json (74 KB): w, b, mu and sd as exact doubles, plus the sha256 of clf-parser.pt. P(real) = sigmoid(((x - mu) / sd) . w + b). THRESHOLD = 0.75. The app copies every file of a built-in transform folder, so the file ships beside the script.
  • One pipeline. There is no language branch. The tree cutter runs on any parse.
  • Vars. disfluency.applied gains tree cut. disfluency.tree_cuts counts the cuts applied and disfluency.tree_dropped the cuts V dropped. Both appear only when the tree cutter ran.
  • Fail open. On any error, a missing weights file, or a parse of another text, the rules' output stands and disfluency.declined says tree cut: <reason>.
Parity with the training code: same candidates and decisions; every difference comes from the parse

The envelopes come from a release build of main's Swift, which this PR does not change (--parse --batch --vectors, tags rounded to 4 places as the envelope does). The reference is rules_reparse's [email protected]: the stored fp32 PyTorch parse, its candidates and its V scores. The filler rule is off for this comparison, as it was in rules_reparse. Its cuts are reported apart.

Set Rows Rules' cuts equal Candidates ref / port / same Max |dP| Flips at 0.75 R+T cut sets equal R+T fixed/partly/missed/damaged/false, ref → port
CV dev 153 153 112 / 112 / 111 0.0037 0 153 70/12/53/1/12 → same
Written dictation dev 150 150 60 / 60 / 60 0.0012 0 150 30/3/38/4/6 → same
Adversarial dev 96 96 61 / 62 / 61 0.0016 0 96 28/2/34/2/3 → same
AMI dev 2,445 2,445 1,827 / 1,825 / 1,816 0.0069 1 2,438 1190/193/706/28/56 → 1191/192/707/27/56

Every difference, and its cause:

  • Candidate sets. There are 2 + 1 + 20 one-sided candidates (CV, adversarial, AMI). Each is on a row where the app's fp16 Core ML tree differs from the stored fp32 PyTorch tree.
  • Score gap. The fp32 reference also explains the 1e-3 score gaps. The same envelope fed to the training functions (torch pooling, CutFilter) gives the same candidates on all 2,844 rows, a max |dP| of 2.3e-7, and 0 flips.
  • One AMI flip. It is 0.7503 vs 0.7490 on the same tree: fp16 against fp32 values at the threshold.
  • Seven AMI R+T rows. Six leave the same words. Only the copy of a repeated word that the scorer's map picks differs. One comes from a different tree.
  • Filler rule. With the filler rule on, it cuts these words: CV dev 46 (16 rows), dictation dev 2 (1), adversarial dev 6 (3), AMI dev 342 (179).
Real dev, confirm only: 146 / 16, as the training code measured

500 dictations, 254 corrections. Each envelope is piped into disfluency.py with PARROTFLOW_PROTOCOL=json, as the app runs it. Counts only. No text was printed, and nothing was chosen on this set.

Arm Fixed Partly Missed Damaged False-cut words Tree cuts / dropped
Rules, filler rule off 122 12 119 1 12
R+T, filler rule off 146 21 85 2 16 36 / 108
parse: true (rules + filler rule) 121 21 107 5 85
parse: vectors (rules + filler rule + tree cutter) 141 30 77 6 89 34 / 108
Cases: keep 44/44; the tree cutter changes no case that main passes

score.py now records every case with --vectors, and scores each one with its parse, as parse: vectors hands it over. The 10 French cases carry lang: fr, which --eval already reads. They are now parsed and scored in French. parses.json grows from 25 to 107 entries and to 1.29 MB, about 1 KB per word.

Main This branch
Total 101/104 103/107
Collapse 57/60 59/63
Keep 44/44 44/44
Known misses 3 4
  • The tree cutter proposes 27 cuts on the cases. V drops 23. The guard holds the "A A" case. On the 104 cases main has, the output is the same with and without vectors.
  • New cases (invented):
    • "I wa I I want to see the map." gives "I want to see the map.", with two tree cuts.
    • "We need the red one, no, the blue one." gives "We need the blue one."
  • --eval disfluency runs the config's own parse:. On a parse: vectors config it gives 103/107, the 4 known misses. On parse: true it gives 101/107: the 3 tree cases need vectors.
  • New known miss. In "I want to see it. I wa I I want to see it.", the parse draws arcs from the first sentence to the second, and groups merges the fragment's arc with them. That group scores 0.54 and is dropped. The "I I" group scores 0.98 and is kept, so a stray "Wa" is left.
Live gate and cost: `parse: true` changes nothing; `parse: vectors` changes 3 of 165 bench outputs and 4 of 573 French ones, all by a tree cut, for 3 to 6 ms

Release binary. Pipeline vocabulary then disfluency, in cp -c copies of the scratch homes. The PR changes no Swift, so one binary serves every arm, and only disfluency.py differs. Outputs are compared by hash; no text was kept.

Job Dictations Branch parse: true vs main: outputs differ parse: vectors vs main: outputs differ Rows with a proposal Tree cuts applied / V dropped Bench decisions changed
static, 0.85 165 0 3 13 3 / 11 0
chrono, 0.85 165 0 3 13 3 / 11 0
static, 0.60 165 0 3 13 3 / 11 0
chrono, 0.60 165 0 3 13 3 / 11 0
French 573, part 0 287 0 2 35 3 / 41
French 573, part 1 286 0 2 27 2 / 29
  • Every output that differs has a tree cut. None differs for another reason.
  • With parse: true, the branch's applied and declined equal main's on every row, and no tree var is published.
  • disfluency.declined is empty on every parse: vectors row, so the weights file was found every time.
  • French: the tree cutter runs there as it does in English. It proposes a cut on 62 of 573 dictations. 5 cuts are applied and V drops 70.

Cost. 3 to 6 ms of Python at 20 to 120 words. The stage time difference is inside the run-to-run noise. Release binary, --pipeline --vars --warm, one process per run, 5 interleaved runs. The text is invented and holds one self-correction, so the tree cutter applies one cut at every length. The disfluency.ms var includes the parse.

Words parse: true, median ms (runs) parse: vectors, median ms (runs) Tree cutter + V alone in Python Envelope with vectors
20 134 (109 to 141) 120 (116 to 132) 1.3 ms 28 KB
60 109 (106 to 178) 121 (118 to 159) 2.6 ms 79 KB
120 136 (124 to 144) 143 (122 to 168) 4.7 ms 157 KB

Importing the module and reading cut-filter.json adds 1.4 ms per process. The Python numbers are medians of 20 warm calls of tree_cut.

🤖 Generated with Claude Code

https://claude.ai/code/session_01WfxPEjc1EEGqG2rHoJcLJ2

znat and others added 4 commits November 4, 2026 17:25
With `parse: vectors`, disfluency.py reads the parse's reparandum arcs as
proposed cuts and scores each with the cut filter V. A cut V gives 0.75 or
more is applied when no rule already cut one of its words and it is not a
doubled letter the rules keep as a spelling. With `parse: true` nothing
changes.

The training code is ported in pure Python: groups, of_clip, the text
features, the vector pooling and V. V's weights are cut-filter.json beside
the script. score.py records every case with vectors.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WfxPEjc1EEGqG2rHoJcLJ2
Signed-off-by: Nathan Zylbersztejn <[email protected]>
Eight cases are French. score.py read every case as English, so their
recorded parse split elisions with the English table. `lang: fr` on each, as
`--eval` reads it, and score.py records and scores each case in its language.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WfxPEjc1EEGqG2rHoJcLJ2
Signed-off-by: Nathan Zylbersztejn <[email protected]>
@greptile-apps

greptile-apps Bot commented Nov 4, 2026

Copy link
Copy Markdown

Automatic reviews are disabled for this repository.

@znat

znat commented Nov 4, 2026

Copy link
Copy Markdown
Owner Author

Local CodeRabbit review (coderabbit review --agent --committed, run twice against the merge base). Four findings.

  1. docs/pipelines.md: the disfluency examples still say parse: true. Not changed. parse: true is the shipped default, and this PR keeps it. The sentence after the example says that parse: vectors also runs the tree cutter.
  2. parses.json: French cases were parsed as English. Fixed in 3420ad5. The 8 French cases carry lang: fr, which --eval already reads. score.py now records and scores each case in its language.
  3. cases.yaml: the tree cases need parse: vectors, but the shipped config says parse: true. Kept, and documented. The section comment says they need vectors. --eval disfluency on a parse: vectors config gives 103/107, the 4 known misses. On parse: true it gives 101/107, because the 3 tree cases fail. score.py in CI scores them with the recorded vectors.
  4. parses.json: two more French cases were labelled English. Fixed in 4bd92f3. lang: fr is on both, and they are re-recorded. 10 French cases now.

@coderabbitai

coderabbitai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Explain Change →

Walkthrough

The disfluency transform now applies filler processing and can score parse-based tree-cut proposals when word vectors are available. It applies proposals scoring at least 0.75, records tree-cut counts, and reports them in JSON output. The scorer records vector parses for cases and passes each case’s language and parse to the transform. Validation cases and documentation cover the new behavior.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

  • znat/parrotflow#395: Updates disfluency.py to use the parse supplied in the envelope, which is also consumed by this change.
  • znat/parrotflow#394: Adds the parse: vectors request and per-word vectors used to score tree-cut proposals here.
  • znat/parrotflow#393: Adds parser data to transform envelopes, including dependency and tag fields used for tree-cut proposals here.
Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: adding the tree cutter and cut filter after the disfluency rules.
Description check Passed The description is detailed, relevant, and covers the setting, behavior, safeguards, measurements, parity results, case results, performance, and out-of-scope work. It does not explicitly include the …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description is detailed, relevant, and covers the setting, behavior, safeguards, measurements, parity results, case results, performance, and out-of-scope work. It does not explicitly include the template checklist confirmations for make test, scoring, or signed-off commits, but the description is otherwise mostly complete.

Full details: Docstring Coverage

Explanation

Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 27 functions across 2 files. (6 skipped: 6 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Review coverage is incomplete: 1 file could not be fully reviewed. Findings from completed review steps are included; see review info for details.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share
Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e5fc9acd-5caa-4ac6-946b-fa296b4b1d61
Commits

Reviewing files that changed from the base of the PR and between 3df615a and 4bd92f3.

Files selected for processing: 9
  • README.md
  • built-in/config.example.yaml
  • built-in/transforms/disfluency/cases.yaml
  • built-in/transforms/disfluency/cut-filter.json
  • built-in/transforms/disfluency/disfluency.py
  • built-in/transforms/disfluency/parses.json
  • built-in/transforms/disfluency/score.py
  • docs/authoring.md
  • docs/pipelines.md
Files not fully reviewed because their changes were unavailable: 1
  • built-in/transforms/disfluency/parses.json

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@znat

znat commented Nov 4, 2026

Copy link
Copy Markdown
Owner Author

CodeRabbit's docstring coverage warning (66.67% against 80%). I will not add docstrings here. The functions without one are the ported training functions (subtree, is_filler, of_cand, text_features and others). They keep the training code's form, so a reviewer can diff the two by eye. The repo's CLAUDE.md asks for the strict minimum of comments. CodeRabbit made no inline findings on 4bd92f3.

@znat
znat merged commit d2a8d9a into main Nov 4, 2026
4 checks passed
@znat
znat deleted the feat/tree-cutter branch November 4, 2026 18:54
@znat znat mentioned this pull request Nov 9, 2026
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