Skip to content

RFC: single-pass period-classifier abbreviation engine - #75

Merged
yisding merged 1 commit into
mainfrom
claude/v2-abbreviation-engine-rfc
Jun 18, 2026
Merged

yisding merged 1 commit into
mainfrom
claude/v2-abbreviation-engine-rfc

Conversation

@yisding

@yisding yisding commented Jun 14, 2026

Copy link
Copy Markdown
Owner

What

A design RFC (analysis/ABBREVIATION_ENGINE_V2_RFC.md) — no code changes — capturing the architectural analysis that came out of the latency investigation (which landed +21.7% separately, in #73).

The core argument

The abbreviation engine inherits pySBD's model — segmentation as a sequence of global re.sub rewrites, decisions carried in-band as sentinels (). But deciding whether a period is a sentence boundary is an inherently local, per-period classification. Modeling it as repeated global rewrites turns that into:

  • O(distinct-abbreviations × text-length) work (~19% of normal prose, ~28% / ≈1,800 re.sub/call on dense legal text);
  • order-dependence (each rewrite sees the previous one's ) — bug-prone, and the main obstacle to optimizing the current code;
  • six divergent re-implementations of the same decision across languages.

A single-pass period classifier would be O(text), order-independent, and collapse the six per-language rewrites into one classifier + small policy hooks.

The honest catch

The current quirks (down to German's unescaped lookbehind and the order-dependent tie-breaks) are now the product spec — the historically-tuned golden output. So this isn't "refactor the engine," it's "re-derive every golden behavior in a new paradigm" — a multi-week, high-risk project.

What the RFC contains

  • Essential-vs-accidental complexity breakdown (what the linguistics need vs. what the architecture imposed).
  • The proposed classifier design + per-language AbbrPolicy hooks.
  • A full preservation spec distilled from surveying every lang/ module: the suffix-decision patterns, the steering flags, and the genuinely hard parts (context-reading callbacks, the replace_multi_period interaction, the &ᓷ&&ᓷ& placeholder injection, unescaped-am languages, whole-pipeline overrides).
  • A phased, English-first implementation plan.
  • Guardrails: differential oracle, Golden-Rule anchor, all-26-language diff (the leg that caught the U+0130 İ bug), fuzz, CodSpeed, feature-flag parallel paths.
  • Acceptance criteria and an honest risk/reward recommendation: default — leave it (already +21.7%, competitive); v2 only as a deliberate major-version effort, started with a throwaway English-only prototype.

Filed as a draft for discussion, not for merge-as-work.

https://claude.ai/code/session_01RBqMKEGgvcZEAXLTPP5FiV


Generated by Claude Code

Captures the architectural analysis from the latency investigation: the
abbreviation engine inherits pySBD's global-re.sub-rewrite model, which
makes the per-period boundary decision O(distinct-abbreviations x
text-length), order-dependent, and re-implemented six ways across
languages. Argues that the linguistically-essential task is a local
per-period classification that a single-pass design would make O(text),
order-independent, and far simpler.

Includes: essential-vs-accidental complexity analysis, the proposed
classifier design and per-language policy hooks, the full preservation
spec distilled from surveying every lang/ override (suffix-decision
patterns, flags, and the genuinely hard parts), a phased English-first
implementation plan, the guardrails (differential oracle, Golden-Rule
anchor, all-26-language diff, fuzz, CodSpeed), acceptance criteria, and
an honest risk/reward recommendation (default: leave it; v2 only as a
deliberate major-version effort). No code changes.
@codspeed

codspeed Bot commented Jun 14, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 22 untouched benchmarks


Comparing claude/v2-abbreviation-engine-rfc (bc073f0) with main (04066c6)

Open in CodSpeed

@yisding
yisding merged commit bc073f0 into main Jun 18, 2026
9 checks passed
@yisding
yisding deleted the claude/v2-abbreviation-engine-rfc branch June 18, 2026 03:35
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.

2 participants