60  The whole pipeline in one measured pass

This is the closing chapter of the keystone: the whole spine run as one measured pass from a fresh engine —

construct → propagate → learn → predict & quantify → MEASURE

— every stage carrying a measured verdict, each the claim the stage’s own chapter makes. So this chapter is also the book’s consistency check: run end to end, the spine must hold what its tiers showed one at a time.

import tempfile

import jammi
import numpy as np
from jammi_cookbook import datasets, keystone, scale, shift
from jammi_cookbook.claims import claim

SCALE = scale.current()
ALPHA = 0.10
db = jammi.connect(f"file://{tempfile.mkdtemp()}")
arxiv = datasets.arxiv(db, SCALE)
golden = keystone.subject_golden(db, arxiv)
print(f"scale: {SCALE}")
scale: small

60.1 Stage 1 — Construct: the graph carries signal the embeddings cannot

embeddings = keystone.embed(db, arxiv, SCALE)
cites = db.sql(
    f"SELECT a.subject = b.subject AS same FROM {arxiv.cites}.public.{arxiv.cites} e "
    f"JOIN {arxiv.papers}.public.{arxiv.papers} a ON e.src = a.paper_id "
    f"JOIN {arxiv.papers}.public.{arxiv.papers} b ON e.dst = b.paper_id"
).column("same").to_pylist()
cite_homophily = sum(cites) / len(cites)
chance = keystone.subject_chance(db, arxiv)
print(f"citation-graph subject homophily: {cite_homophily:.3f}   (chance {chance:.3f})")
claim("citations link papers of one subject far more often than chance — the precondition",
      cite_homophily > chance, f"{cite_homophily:.3f} against {chance:.3f}")
citation-graph subject homophily: 0.537   (chance 0.356)
✓ citations link papers of one subject far more often than chance — the precondition (0.537 against 0.356)
2026-10-03T07:41:55.150627Z  WARN jammi_kernels::admission: fused-kernel domain check failed; falling back to the eager composition op="attention_block_fused" predicate="head_dim_is_attention_block_fixed_head_dim"

60.2 Stages 2 and 3 — Propagate and Learn

APPNP over the citation graph (a low-pass filter), then a contrastive fine-tune supervised by the declared citations, measured side by side against the raw embeddings in one eval_compare.

propagated = keystone.propagate(db, arxiv, embeddings)
tuned = keystone.fine_tune_on_graph(
    db, arxiv, SCALE, edge_source=arxiv.cites, provenance="declared",
    epochs=keystone.FINE_TUNE_EPOCHS[SCALE],
)
compared = db.eval_compare(
    embedding_tables=[embeddings, propagated, tuned],
    source=arxiv.papers, golden_source=golden, k=10,
)
raw, prop, ft = (e["embedding_eval"]["aggregate"]["precision_at_k"] for e in compared["per_table"])
print(f"precision@10  raw {raw:.3f} → propagated {prop:.3f} → declared fine-tune {ft:.3f}")
precision@10  raw 0.403 → propagated 0.427 → declared fine-tune 0.405

60.3 Stage 4 — Predict & Quantify

The year predictor, its conformal interval, and the subject classifier’s conformal set, over the 2018 calibration era and the 2019-onward test era.

predictor = keystone.train_year_predictor(db, arxiv, SCALE, propagated)
year = {
    r["paper_id"]: r["year"]
    for r in db.sql(f"SELECT paper_id, year FROM {arxiv.papers}.public.{arxiv.papers}").to_pylist()
}
cal_ids, test_ids = arxiv.split["valid"], arxiv.split["test"]
cal_mean, _ = keystone.predict_years(db, arxiv, predictor, cal_ids)
test_mean, _ = keystone.predict_years(db, arxiv, predictor, test_ids)
intervals = db.conformalize_interval(
    cal_mean.tolist(), [float(year[k]) for k in cal_ids], test_mean.tolist(), alpha=ALPHA
)
reg_cov = float(np.mean([lo <= year[k] <= hi for k, (lo, hi) in zip(test_ids, intervals)]))
print(f"year interval coverage:       {reg_cov:.3f}   (nominal {1 - ALPHA:.2f})")

scores = keystone.subject_scores(db, arxiv, propagated)
sets = db.conformalize(
    scores.cal_scores.tolist(), scores.cal_labels.tolist(), scores.test_scores.tolist(),
    alpha=ALPHA, score="aps",
)
marg_cov = float(np.mean([y in s for y, s in zip(scores.test_labels, sets)]))
print(f"subject APS set coverage:     {marg_cov:.3f}   (nominal {1 - ALPHA:.2f})")
year interval coverage:       0.938   (nominal 0.90)
subject APS set coverage:     0.958   (nominal 0.90)
band = shift.binomial_band(ALPHA, len(sets))
claim("the subject sets hold nominal coverage, to within three binomial standard errors",
      abs(marg_cov - (1 - ALPHA)) < band, f"{marg_cov:.3f}, nominal {1 - ALPHA:.2f} ± {band:.3f}")
if SCALE is scale.Scale.FULL:
    claim("propagation and the declared fine-tune both lift precision@10", raw < min(prop, ft),
          f"raw {raw:.3f}, propagated {prop:.3f}, fine-tuned {ft:.3f}")
    claim("the year interval under-covers under the time split", reg_cov < 1 - ALPHA - 0.1,
          f"coverage {reg_cov:.3f}")
✓ the subject sets hold nominal coverage, to within three binomial standard errors (0.958, nominal 0.90 ± 0.092)

60.4 The loop, closed

Every stage above ran live and held its own chapter’s claims. At full scale the spine reads: citations link same-subject papers far above chance (the precondition); propagation lifts same-subject precision, and the declared-edge fine-tune lifts it by about as much, though propagation trains nothing. Under the time split the year interval under-covers — the finding the governed calibration cohort (tier 04) answers — while the subject set holds its coverage, the shift being orthogonal to its score. At small scale the same pass runs in seconds on a CPU, and every claim that holds at both scales holds there too.

db.close()