import { type LicensePolicy, type LicenseRefusalKind, type LicenseVerdictCache } from "@mailwoman/license/policy"; import type { PathBuilder } from "path-ts"; import { type UnitSplitter } from "#adapters/street/unit"; import { type AlignSettings } from "#build/checkpoint"; import { ComponentRule, type ComponentFindingCounts } from "#build/component-check"; import { createIneligibilityReader } from "#build/eligibility"; import { type RegionNames } from "#build/region/names"; import type { BuildProfile, BuildStage } from "#build/types"; import { type AdapterRunManifest } from "#runner"; import type { AdapterOptions, CanonicalRow, LabeledRow } from "#types"; import type { SplitRetention } from "#utils/retention"; import { type CountryHoldout, type SplitName } from "#utils/split"; export interface AlignPhaseOptions { /** * The adapter runs to align, in the order their rows enter the output files. */ adapterRuns: readonly AdapterRunManifest[]; corpusVersion: string; synthesize: boolean; profile: BuildProfile; licensePolicy: LicensePolicy; excludeLicenses: readonly RegExp[]; holdouts: Record; /** * Each capped source's `trainShare`, from {@linkcode trainSharesOf}. */ trainShares?: Readonly>; /** * The retention table applied to every aligned row, when one was registered * (HOLDOUT_AND_EVALUATION section 5.1). */ retention?: SplitRetention; /** * Each register source's ingest-eligibility reasons, or `null` under the exploratory profile. */ eligibility: ReadonlyMap | null; labeledPaths: Record; /** * Where each split's `source_id` values are written, one per line in the order their rows were aligned. * * The split phase sorts these rather than parsing every labeled row again for its id. */ sourceIDPaths?: Record | null; quarantinePath: PathBuilder; checkpointPath: PathBuilder; /** * Continue from the checkpoint at `checkpointPath` rather than writing the outputs from the start. */ resume: boolean; onProgress?: (stage: BuildStage, message: string) => void; } /** * The counts produced by the align phase. * * The build uses them in its manifest and frozen source record. */ export interface AlignPhaseResult { aligned: number; quarantined: number; counts: Record; licenseCounts: Map; refusedByKind: Map; /** * Rows the license policy refused, counted per `source`. * * A source here contributed zero rows to the corpus whatever its adapter reported writing. * That's the distinction between a source present in corpus provenance * and one present in model provenance. */ refusedBySource: Map; /** * Training draws each source's `trainShare` left out: a row it dropped, * or an augmentation it kept from running. * * A skipped augmentation would have written one row or none. * Validation and test rows are never left out. */ trainRowsLeftOutBySource: Map; excludedByLicense: number; admittedUnresolved: number; excludedByEligibility: number; rowsBySource: Map; ineligibleSources: Map; /** * Base rows failing each component rule, per `source` then rule (#2898). * * Every rule is counted, whether the build quarantines a row for it * (`ENFORCED_COMPONENT_RULES`) or only reports it. */ componentFindingsBySource: ComponentFindingCounts; /** * The component rules this phase couldn't check, because the data they read wasn't on the host. * * Their counts in {@linkcode AlignPhaseResult.componentFindingsBySource} are absent rather than zero. */ uncheckedComponentRules: Set; /** * The base rows that reached the component check with a region, per {@linkcode regionValueKey}. * * A build that reuses a source under other region data recounts `region:unknown` from these. * The serial build's checkpoint doesn't record them, because only a parallel * build's source records are reused. */ regionValues: Map; /** * The source-id lists this phase wrote, or `null` when it wrote none. * * A phase resumed from a checkpoint that records no list offsets writes none, * because the rows before the checkpoint have no ids on disk. */ sourceIDPaths: Record | null; /** * The license cache this phase uses. * * Its `refusedValues()` method returns every value it refused. */ licenses: LicenseVerdictCache; } /** * The mutable state of one align run. * The checkpoint restores and records this state. */ export interface AlignTally { aligned: number; quarantined: number; excludedByLicense: number; admittedUnresolved: number; excludedByEligibility: number; } /** * The settings an align checkpoint or completion record is written under. * * `train_shares` is present only when a source is capped, so a build without * one writes the settings it always has. */ export declare function alignSettings(opts: Pick): AlignSettings; /** * Whether a training row whose source keeps `share` of its training rows is kept. * * The draw reads `recordIDOf(sourceID)`, which keeps the id up to its last `#`. * A source whose ids hold no `#`, as NAD's don't, draws once per row: a variant synthesized * from a record draws apart from its base row, so a kept record contributes some of its forms. * * Under a share of 0.11, 57% of NAD's training records keep at least one row. */ export declare function keepsTrainRow(sourceID: string, share: number): boolean; /** * Each configured source's `trainShare`, for the align phase. */ export declare function trainSharesOf(adapterInputs: Readonly>): Record; /** * One labeled row as a line of a labeled JSONL file. */ export declare function labeledLine(row: LabeledRow): string; /** * The `source_id` a labeled row contributes to its split's id list, or `null` when it has none. * * The split phase once parsed every labeled row back for its `source_id`. * The same guard it applied keeps the list identical to what that parse produced. */ export declare function labeledSourceID(row: LabeledRow): string | null; /** * Where one aligned row's output goes. */ export interface RowAlignerSinks { /** * One labeled row for `split`. * * A sink that writes labeled JSONL calls {@linkcode labeledLine} and {@linkcode labeledSourceID}. * A parallel build's align range stages the row for its parquet part instead. */ labeled: (split: SplitName, row: LabeledRow) => void; /** * One quarantine JSONL line. */ quarantine: (line: string) => void; } export interface RowAlignerOptions { synthesize: boolean; holdouts: Record; /** * The retention table applied to every aligned row, when one was registered * (HOLDOUT_AND_EVALUATION section 5.1). */ retention?: SplitRetention; /** * Each capped source's `trainShare` (`AdapterOptions.trainShare`). */ trainShares?: Readonly>; licenses: LicenseVerdictCache; ineligibility: ReturnType; /** * The unit vocabulary the component check's `street:trailing-unit` rule reads, from `createUnitSplitter`. */ units: UnitSplitter; /** * The region forms the `region:unknown` rule reads, or `null` when the WOF database isn't on the host. * * A `null` records the rule in `result.uncheckedComponentRules`. */ regions: RegionNames | null; /** * The accumulators the aligner adds each row to. */ result: AlignPhaseResult; tally: AlignTally; sinks: RowAlignerSinks; } /** * The align phase's work on one canonical row: refusals, synthesis, alignment and the split route. * * Each row's output depends only on that row's data. * The aligner keeps caches and sums between rows. * * Every later row writes the same lines regardless of those values. * A source's rows can therefore be aligned in contiguous ranges and the range outputs joined in order. */ export declare function createRowAligner(opts: RowAlignerOptions): (row: CanonicalRow) => void; /** * An empty set of align accumulators. */ export declare function emptyAlignResult(licenses: LicenseVerdictCache, ineligibleSources: Map): AlignPhaseResult; /** * Align every adapter run's rows into the four output files, writing a checkpoint at each adapter boundary. */ export declare function runAlignPhase(opts: AlignPhaseOptions): Promise; //# sourceMappingURL=align.d.ts.map