InterviewsVector
Arc 3
Concept labFoundation90 min estimateOriginal publication

The Generalization Contract

Generalization is not a personality trait of a model; it is a bounded claim from one learning process and sample to a named deployment situation.

Authorship
InterviewsVector
Published / updated
2026-08-20 / 2026-08-20
Review status
Artifact tests passing · primary sources recorded

Original InterviewsVector material. Code examples are covered by repository tests and primary references are recorded. No named human reviewer is claimed.

The decision in one pass

A generalization claim is complete only when it names the prediction task, eligible population, decision point, feature cutoff, outcome horizon, loss, model revision, sampling frame, and acceptance evidence. Training loss answers how one fitted function behaved on reused examples. Evaluation risk estimates behavior on a declared sample. Neither number silently transfers to a new population, time, policy, or loss. Make those assumptions an immutable contract, bind the full evaluation rows to a content identity, require mature labels and protected-slice coverage, then issue PASS or HOLD against versioned risk limits.

Why this matters

Teams often say a model ‘generalizes’ after one favorable test score, while the product serves different entities, later time periods, revised labels, or a cost function the test never measured. The result can look like model drift even when the real break is an unstated evaluation assumption. A contract makes the claim falsifiable, reviewable, and reproducible before deployment authority is granted.

You will be able to

  • Distinguish training fit, evaluation risk, generalization gap, and deployment risk.
  • Specify a generalization claim through task, population, time, model, sampling, loss, and slice identities.
  • Recognize label censoring, repeated entities, selection effects, and distribution mismatch in evaluation evidence.
  • Build a content-addressed audit that rejects incomplete or out-of-scope evidence before computing risk.
  • Operate acceptance thresholds as owned policy while preserving uncertainty and rollback evidence.

Your Vector Loop for this lab

  1. 01

    Model

    Name the deployment population, decision, information set, outcome horizon, and loss.

  2. 02

    Derive

    Separate empirical risk from expected risk and enumerate every transfer assumption.

  3. 03

    Build

    Bind a model, sampling frame, mature evaluation rows, slices, and limits into an audit.

  4. 04

    Stress

    Reuse entities, censor negative labels, swap populations, alter predictions, and starve rare slices.

  5. 05

    Operate

    Version evaluation evidence, monitor assumption drift, and route failed limits to accountable owners.

  6. 06

    Defend

    State exactly what the evidence supports, what it does not support, and what would invalidate it.

Model the claim before reading the score

Begin at the moment a prediction will be consumed. Identify the eligible entity, the decision being supported, the latest information legally and operationally available, the event and horizon, and the consequence being measured. Only then select a dataset. Starting from a convenient table encourages the table's historical accidents to masquerade as the deployment population.

The score is an output of the contract, not a substitute for it.
Contract fieldQuestionFailure when omitted
task and decision pointwhat is predicted, and when is it used?features arrive after the real decision
populationwhich entities are eligible?a favorable cohort is treated as universal
horizon and label maturitywhen is an outcome final?immature negatives hide late events
losswhich errors count, and how?accuracy substitutes for operational harm
sampling framehow did an entity enter evaluation?selection bias is mistaken for model quality
model and data revisionwhich executable evidence is this?a score is attached to the wrong release

Derive the layers of risk

R_P(f) = E_(X,Y)~P[L(f(X), Y)]

Expected risk is defined relative to a joint distribution P and loss L. Naming only f leaves the quantity incomplete.

R̂_S(f) = (1/n) Σᵢ L(f(xᵢ), yᵢ)

Empirical risk averages loss over a concrete sample S. It is evidence about expected risk only through assumptions about how S was produced and how f was selected.

generalization gap = R_P(f) − R̂_S(f)

The theoretical gap references the target distribution, which is not directly observable. A held-out estimate is useful evidence, not literal access to R_P or a proof that P will remain stable.

A small train-to-test gap can coexist with high risk when both scores are poor. A low test risk can still fail deployment if the sampling frame excludes hard entities or the production loss weights errors differently. Conversely, a modest aggregate regression may conceal a severe protected-slice failure. Keep absolute risk, transfer assumptions, slice evidence, and uncertainty separate.

Build decision-complete evaluation evidence

The reference artifact supports one explicit binary Brier-risk convention. Its frozen contract fixes the task, population, decision point, 30-day horizon, label definition, model, dataset, sampling frame, required slices, thresholds, and owners. Every row carries stable record and entity identities, its feature cutoff, event time when positive, full-horizon label-as-of time, prediction, outcome, and slice membership. The full evidence object receives a SHA-256 content identity, so two evaluations cannot share a run label while silently changing predictions or rows.

generalization_contract.py
1def format_example() -> str:
2 audit = audit_generalization(ILLUSTRATIVE_CONTRACT, ILLUSTRATIVE_EVIDENCE)
3 return "\n".join(
4 (
5 "example=illustrative_only",
6 f"contract_version={ILLUSTRATIVE_CONTRACT.contract_version}",
7 f"evaluation={audit.evaluation_id}",
8 f"evidence_id={audit.evidence_id}",
9 f"records={audit.record_count}",
10 f"empirical_risk={audit.empirical_risk:.3f}",
11 f"worst_slice={audit.worst_slice_id}:{audit.worst_slice_risk:.3f}",
12 f"decision={audit.decision}",
13 )
14 )

Expected output

example=illustrative_only
contract_version=generalization-contract-v1
evaluation=renewal-evaluation-run-0042
evidence_id=evaluation-evidence-v1@sha256:30095ac28b8a270520044ad288c168de952df89cd2b21a0ef824fa01b551cd38
records=4
empirical_risk=0.075
worst_slice=low-volume:0.125
decision=PASS

Verify: Run python3 -m unittest discover courses/ai-engineering/reference-impl/generalization_contract.

  1. 01Freeze the claimContent-address every assumption that changes what a score means, including slice requirements and acceptance limits.
  2. 02Validate before aggregatingReject wrong populations, repeated entities, future features, immature labels, invalid numbers, undeclared slices, and stale provenance before allocating reports.
  3. 03Preserve the evidence identityReturn the full content digest beside the friendly evaluation name so an operator can reproduce the exact decision input.

Stress every bridge from sample to deployment

StressWhat stays constantWhat the result diagnoses
later time windowmodel, task, losstemporal or policy shift
new entities or groupstime and taskmemorization and dependency
alternate sampling framepopulation definitionselection sensitivity
slice-specific riskaggregate evidenceheterogeneous failure
label adjudication replaypredictionsmeasurement instability
changed cost-weighted losspredictions and outcomesdecision sensitivity
  1. 01Censor a negative rowSet its label-as-of time before the full outcome horizon. A correct audit refuses to count absence of an event as a final zero.
  2. 02Reuse one entityDuplicate a customer under a fresh record ID. The sample size increases, but independent evidence does not; reject the row under this contract.
  3. 03Keep a run name, alter one predictionThe human label may remain unchanged, but the content identity must change and bind the new decision.
  4. 04Hide a rare sliceRefuse an aggregate score when a contractually required slice lacks enough mature examples.

Operate the claim as a release boundary

  • Store the contract ID, evidence ID, model digest, dataset snapshot, feature view, label policy, and code revision with every gate decision.
  • Report sample counts, time coverage, missingness, and risk intervals by required slice; a point estimate without support can invite false precision.
  • Separate model acceptance thresholds from alert thresholds. One governs release authority; the other governs investigation after release.
  • Re-evaluate when acquisition, eligibility, product policy, label adjudication, feature availability, or model selection changes—not only when weights change.
  • Keep rollback tied to the model-plus-policy bundle whose evidence passed, rather than to a floating model name.
Observed changeContract responseOwner
population eligibility changesnew population ID and evaluationproduct and data
label window or adjudication changesnew target definitiondomain and measurement
model or preprocessing changesnew model revision and evidencemodel
slice risk exceeds limitHOLD and investigate evidencemodel plus slice owner
sampling frame loses coveragestop claiming transferdata and evaluation

Operate at three altitudes

Production lens

  • Propagate contract and evidence identities into model registry entries, deployment approvals, dashboards, and incident traces.
  • Reject immature negative labels and future feature timestamps before any aggregate metric is computed.
  • Gate both overall and required-slice risk, and expose counts and time coverage beside each estimate.
  • Reopen the contract whenever population, measurement, sampling, loss, decision policy, or model revision changes.

Staff lens

  • Make generalization claims organization-readable so product, data, model, and policy owners can challenge different assumptions.
  • Fund stable sampling frames and independent evaluation identities; without them, repeated score production is not accumulating evidence.
  • Define who may change acceptance limits and require the rationale to be versioned with the release decision.

Interview defense

A model has 3% training error and 3.2% test error. Does it generalize well enough to launch?

The small gap alone is insufficient. I would ask whether the loss reflects the decision, whether the test entities and time range represent the deployment population, whether feature timestamps precede the decision, whether labels matured over the full horizon, whether model selection reused this holdout, and whether required slices have adequate support. I would bind the exact model and evaluation rows to identities, compare overall and slice risk with owned limits, quantify uncertainty, and launch only within the scope that evidence supports.

Expect the interviewer to press on

  • Can a model have a small generalization gap and still be unusable?
  • Why is a newly collected test set valuable?
  • What changes require a new generalization contract?
  • How would you handle a thin but safety-critical slice?

Misconceptions to remove

A low train-test gap proves low deployment risk.

Both risks can be high, and the test distribution can differ from deployment. The gap is one diagnostic inside a scoped claim.

A larger random holdout automatically provides stronger evidence.

More rows reduce some sampling error but do not fix repeated entities, wrong populations, future information, censored labels, or adaptive reuse.

Generalization belongs to the model architecture.

It depends on the learned parameters, data-generating process, selection procedure, loss, and target use; architecture alone is not the claim.

Check your model

1. Why is an outcome=0 row at day 12 invalid for a 30-day event target?

The event still has 18 days to occur. Unless the label-as-of time reaches the full horizon, the zero is censored rather than a mature negative.

2. What does content-addressing evaluation rows add beyond a friendly run ID?

It makes predictions, labels, identities, timestamps, and slices part of the evidence identity, so reused names cannot conceal a changed decision input.

3. Why should absolute risk and generalization gap be reported separately?

A small gap can accompany poor performance, while acceptable absolute risk can coexist with a visible but operationally tolerable gap. They answer different questions.

Prove the mechanism

Extend the artifact with a bootstrap interval computed from a bounded, contract-owned resampling plan. Preserve the resampling seed and method in the contract, and make a release decision only when the interval—not just the point estimate—meets the limit.

Add a production constraint

Add a second sampling frame and produce a transport sensitivity report that clearly separates observed reweighting evidence from untestable assumptions about unobserved populations.

Artifact: Generalization contract audit

courses/ai-engineering/reference-impl/generalization_contract/generalization_contract.py

Download reference implementation

Primary references and next links

References

  1. 1. Stability and Generalization

    Bousquet and Elisseeff. Primary JMLR paper formalizing empirical error, expected risk, and stability-based generalization analysis.

  2. 2. Do ImageNet Classifiers Generalize to ImageNet?

    Recht et al.. Primary ICML study using newly collected test sets to examine transfer under a carefully matched data-collection process.

  3. 3. Deep Double Descent: Where Bigger Models and More Data Hurt

    Nakkiran et al.. Primary paper demonstrating non-monotonic interactions among fit, capacity, sample size, and test behavior.

Continue through the graph

Glossary: expected risk · empirical risk · generalization gap · sampling frame · label maturity · censoring · content identity · protected slice