/** * @copyright Sister Software * @license AGPL-3.0 * @author Teffen Ellis, et al. * * Soft-prior emission biases derived from `QueryShape`. * * When the QueryShape sub-system has identified a known-format span (US ZIP, UK postcode, PO box, * etc.), this module produces an additive bias matrix that nudges the encoder's per-token * emissions toward the matching BIO label. The biases compose with the structural BIO mask in the * Viterbi decoder — confident encoder predictions still win, but uncertain ones get pulled toward * the format-implied label. * * Bitter-lesson-safe boundary: we don't override the encoder, just bias it. The encoder remains the * authority on context-dependent calls (the "Buffalo Wild Wings, Buffalo, NY" disambiguation); * the QueryShape prior helps on the easy cases (a 5-digit token is _probably_ a postcode). * * RETIRED 2026-07-17 — the LOCALITY bias (regionAbbreviations → boost B/I-locality on preceding * tokens). The M1 stack ablation (docs/articles/evals/2026-07-17-m1-stack-ablation.md) measured the * full prior at −2.3 micro / −7.8 locality on golden-us, and the three-arm sub-ablation attributed * 100% of the damage to the locality half: stripping it recovered locality exact-match 0.7822 → * 0.8546 (= the no-prior arm), while the known-format half was exactly neutral. The failure mode was * venue/org absorption on registry-style rows ("DANVILLE HEALTH CENTER, 26 Cedar Lane, Danville VT" * → locality "danville health center"): the backward walk from a detected region abbreviation * crossed comma gaps and dragged venue text into locality. The WOF bare-name over-emission it was * built to counter no longer reproduces — the model outgrew it (same lifecycle as the #956-era * near-postcode suppression, also measured negative in M1). The known-format boosts below remain. * * Uses structural typing for the QueryShape input so this module has zero dependencies on * `@mailwoman/query-shape` — consumers compute the shape with that package, pass it in here. */ export interface QueryShapeLike { knownFormats: ReadonlyArray; regionAbbreviations?: ReadonlyArray; } interface RegionAbbreviationHitLike { start: number; span: string; } export interface KnownFormatHitLike { format: string; span: { start: number; end: number; }; /** * 0..1; ambiguous patterns (e.g. 5-digit US/FR/DE overlap) score lower. */ confidence: number; } /** * Minimal subset of `TokenizedPiece` this module consumes. */ export interface TokenLike { start: number; end: number; } export interface BuildPriorsOpts { /** * Maximum bias magnitude (in log-odds units). Default 1.0 — adds up to ~e^1 ≈ 2.7× odds to the favored label. * Confidence-scaled, so a 0.6-confidence format hit gets +0.6 max bias. */ biasScale?: number; /** * Raw input text — enables the SCOPED locality bias (bare admin doubletons only; see `applyScopedLocalityBias`). * Without it the digit guard cannot run, so the locality bias never fires. */ inputText?: string; } /** * Build a `[seqLen][numLabels]` matrix of additive log-bias to be added to encoder emissions before Viterbi decoding. * * For each (token, format-hit) pair where the token's character span overlaps the hit's span, the matrix entry for the * format's mapped label receives `hit.confidence × biasScale`. Tokens that don't overlap any hit, or for which no label * mapping exists, get 0. * * Returns the all-zeros matrix if `shape.knownFormats` is empty — composes harmlessly. */ export declare function buildEmissionPriors(shape: QueryShapeLike, tokens: ReadonlyArray, labels: ReadonlyArray, opts?: BuildPriorsOpts): number[][]; /** * Element-wise add two matrices of equal shape. Returns a new matrix. */ export declare function addEmissionMatrix(emissions: number[][], priors: number[][]): number[][]; export {}; //# sourceMappingURL=query-shape-prior.d.ts.map