from jammi_cookbook import scale
SCALE = scale.current()
print(f"this run: scale = {SCALE}")this run: scale = small
The book runs on two public graphs, each used where it is strongest.
route graph (airport↔︎airport) and a contains hierarchy (continent→country→airport). Numeric and categorical features, thin text. It carries the tiers 01–02 on-ramp.Every chapter runs its capability live. What it runs over is a scale:
small — the committed fixtures and the tiny fixture encoders, on the CPU: seconds per chapter. This is what the book’s CI renders, and what a CPU Colab runtime runs.full — the published datasets and real encoders (for text, gte-modernbert-base, a ModernBERT trained for embeddings), on a GPU: the book’s findings at the size they are about.The chapter code is the same at both; only the data and the encoders differ. Choose with the environment variable JAMMI_COOKBOOK_SCALE (small when unset) before the chapter starts:
from jammi_cookbook import scale
SCALE = scale.current()
print(f"this run: scale = {SCALE}")this run: scale = small
Air Routes is small enough to run whole, so both scales read the same graph (committed with the cookbook). ogbn-arxiv at full is a connected ball of the citation graph — 4,000 papers collected breadth-first from the most-cited paper, downloaded and checksum-verified on first use; a ball keeps the citation density and the subject homophily later chapters depend on. At small it is that ball’s 400 best-connected papers (committed with the cookbook): one dataset at two sizes, the smaller keeping the larger’s character.
import tempfile
import jammi
from jammi_cookbook import datasets, keystone
from jammi_cookbook.claims import claim
db = jammi.connect(f"file://{tempfile.mkdtemp()}")
air = datasets.air_routes(db)
arxiv = datasets.arxiv(db, SCALE)A file source is queried in SQL as <source>.public.<table>, where the table is the file’s name without its extension. The book names each file after its source, so every source here reads as <source>.public.<source>.
def count(source: str) -> int:
return db.sql(f"SELECT COUNT(*) AS n FROM {source}.public.{source}").to_pylist()[0]["n"]
print(f"airports: {count(air.airports)}")
print(f"route edges: {count(air.routes)}")
print(f"contains edges: {count(air.contains)}")
# An airport's continent comes from the continent→airport hierarchy.
atl = db.sql(
f"SELECT code, city, country, continent FROM {air.airports}.public.{air.airports} "
"WHERE code = 'ATL'"
).to_pylist()[0]
print("ATL:", atl)airports: 3504
route edges: 50637
contains edges: 7008
ATL: {'code': 'ATL', 'city': 'Atlanta', 'country': 'US', 'continent': 'NA'}
claim("every airport sits under one continent and one country edge",
count(air.contains) == 2 * count(air.airports),
f"{count(air.contains)} edges for {count(air.airports)} airports")
claim("so the hierarchy gives every airport its continent", atl["continent"] == "NA",
f"ATL in {atl['continent']}")✓ every airport sits under one continent and one country edge (7008 edges for 3504 airports)
✓ so the hierarchy gives every airport its continent (ATL in NA)
The time split is the dataset’s own: papers up to 2017 train, 2018 validates, 2019 onward is the test era — a split by publication year.
print(f"papers: {count(arxiv.papers)}")
print(f"citation edges: {count(arxiv.cites)}")
print("time split: ", {name: len(ids) for name, ids in arxiv.split.items()})
top = db.sql(
f"SELECT subject, COUNT(*) AS c FROM {arxiv.papers}.public.{arxiv.papers} "
"GROUP BY subject ORDER BY c DESC LIMIT 3"
).to_pylist()
print("top subjects: ", [(r["subject"], r["c"]) for r in top])papers: 400
citation edges: 1577
time split: {'train': 182, 'valid': 122, 'test': 96}
top subjects: [('arxiv cs cv', 201), ('arxiv cs lg', 113), ('arxiv cs cl', 61)]
The citation graph is homophilous on the subject label: a paper cites papers of its own subject more often than the subject mix alone would give — the chance level is the probability that two papers drawn at random share a subject, \(\sum_s p_s^2\). That correlation, together with the time split, is what later breaks conformal exchangeability (the prediction chapter).
def subject_chance(db, arxiv: Arxiv) -> float:
"""The chance that two papers drawn at random share a subject, ``Σ p_s²``
over the subject mix — the level a graph's subject homophily is read
against."""
mix = db.sql(
f"SELECT COUNT(*) AS n FROM {arxiv.papers}.public.{arxiv.papers} GROUP BY subject"
).column("n").to_pylist()
return sum((n / sum(mix)) ** 2 for n in mix)edges = db.sql(
f"SELECT a.subject AS sa, b.subject AS sb "
f"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"
).to_pylist()
homophily = sum(r["sa"] == r["sb"] for r in edges) / len(edges)
chance = keystone.subject_chance(db, arxiv)
print(f"citation-edge subject homophily: {homophily:.3f} (chance for this subject mix: {chance:.3f})")citation-edge subject homophily: 0.537 (chance for this subject mix: 0.356)
claim("the time split partitions the papers: every paper falls in exactly one era",
sum(len(ids) for ids in arxiv.split.values()) == count(arxiv.papers))
claim("citations connect papers of one subject far more often than chance",
homophily > chance, f"{homophily:.3f} against {chance:.3f}")✓ the time split partitions the papers: every paper falls in exactly one era
✓ citations connect papers of one subject far more often than chance (0.537 against 0.356)
An embedded engine holds its catalog until close() returns, so a chapter closes its session before anything removes the directory the catalog lives in.
db.close()