From 632ca9d0390bffe8ae4c25b18da768a6df8819c4 Mon Sep 17 00:00:00 2001 From: Ronald Tse Date: Tue, 24 Nov 2026 15:46:30 +0800 Subject: [PATCH] bom: SPDX 3.0-style Model BOM generator + lineage registry + emitted BOMs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Formalizes the recorded model provenance (models.yaml artifact/license/ metrics/parity, corpora/*.yaml sha-pinned splits, card + TODO lineage) into a self-contained SPDX 3.0-style JSON per model: model = Package, training data = Dataset dependencies carrying the split sha256 pins, lineage = relationships. bom/lineage.yaml is the declarative model -> corpus registry plus gated-pending entries. Emitted for heb-vocalized-plane-3.0 (shipped) and urd-vocalized-2.0 (gated-pending: no artifact sha/urls pre-staged per owner law — the ship runbook is not altered; the BOM records the 16(e) FAIL verdict and lineage). --- bom/heb-vocalized-plane-3.0.spdx.json | 194 ++++++++++++ bom/heb-vocalized-plane-3.0.spdx.json.sha256 | 1 + bom/lineage.yaml | 77 +++++ bom/urd-vocalized-2.0.spdx.json | 139 +++++++++ bom/urd-vocalized-2.0.spdx.json.sha256 | 1 + scripts/generate_model_bom.py | 300 +++++++++++++++++++ 6 files changed, 712 insertions(+) create mode 100644 bom/heb-vocalized-plane-3.0.spdx.json create mode 100644 bom/heb-vocalized-plane-3.0.spdx.json.sha256 create mode 100644 bom/lineage.yaml create mode 100644 bom/urd-vocalized-2.0.spdx.json create mode 100644 bom/urd-vocalized-2.0.spdx.json.sha256 create mode 100644 scripts/generate_model_bom.py diff --git a/bom/heb-vocalized-plane-3.0.spdx.json b/bom/heb-vocalized-plane-3.0.spdx.json new file mode 100644 index 0000000..8d53aa3 --- /dev/null +++ b/bom/heb-vocalized-plane-3.0.spdx.json @@ -0,0 +1,194 @@ +{ + "spdxVersion": "SPDX-3.0", + "dataLicense": "CC0-1.0", + "SPDXID": "SPDXRef-DOCUMENT", + "documentNamespace": "https://github.com/interscript/interscript-models/model-bom/heb-vocalized-plane-3.0@2026-11-24T07:46:03Z", + "name": "model-bom-heb-vocalized-plane-3.0", + "comment": "SPDX 3.0-style Model BOM generated by interscript-models/scripts/generate_model_bom.py from models.yaml, corpora/*.yaml and bom/lineage.yaml. Model = Package; sha-pinned training corpora = Dataset dependencies; lineage = relationships.", + "creationInfo": { + "created": "2026-11-24T07:46:03Z", + "creators": [ + "Organization: Interscript (interscript.org)", + "Tool: interscript-models/scripts/generate_model_bom.py" + ] + }, + "x-interscript-status": "shipped", + "@graph": [ + { + "type": "Package", + "spdxId": "SPDXRef-Model-heb-vocalized-plane-3.0", + "name": "heb-vocalized-plane-3.0", + "versionInfo": "3.0", + "downloadLocation": "https://github.com/interscript/interscript-models/releases/download/heb-vocalized-plane-3.0/heb-vocalized-plane-3.0-int8-dynamic.zip", + "filesAnalyzed": false, + "licenseConcluded": "BSD-3-Clause", + "licenseDeclared": "BSD-3-Clause", + "copyrightText": "NOASSERTION", + "supplier": "Organization: Interscript (interscript.org)", + "primaryPackagePurpose": "OTHER", + "packageComment": "Machine-learning model weights (SPDX 3.0 AI profile domain).", + "externalRefs": [ + { + "referenceCategory": "PACKAGE-MANAGER", + "referenceType": "purl", + "referenceLocator": "pkg:interscript/model/heb-vocalized-plane-3.0" + } + ], + "x-interscript": { + "status": "shipped", + "registry": "models.yaml", + "task": "diacritization", + "scripts": [ + "Hebr", + "Hebr" + ], + "kind": "plane", + "precision": "int8", + "filename": "heb-vocalized-plane-3.0-int8-dynamic.zip", + "size": 416041780, + "parity": { + "samples": 600, + "der_delta": 0.0549, + "cer_delta": 0.3629 + }, + "sourceRefs": { + "card": "cards/heb-vocalized-plane-3.0.md" + }, + "lineage": [ + { + "step": "WO92 stage 1 (weak pretrain)", + "detail": "run-093-heb-weak-pretrain: 1,500,000 deduped knesset-v6 weak units (Dicta machine labels — weak supervision only) COMBINED with the full gold corpus (50,303 gold), 1 epoch (cards/heb-vocalized-plane-3.0.md)." + }, + { + "step": "WO92 stage 2 (gold SFT)", + "detail": "run-094-heb-gold-sft (train_hebrew_sft_hf.py, HF Jobs a100-large), resumed from run-093 best with the exact crown recipe; inventory inherited byte-identical (labels.sha edd595d96d09) (cards/heb-vocalized-plane-3.0.md)." + } + ], + "evaluations": [ + { + "name": "der_total_greedy", + "value": 6.6078, + "source": "interscript/interscript-models docs/RESULTS.md#wo92-stage-2-cleared--run-094-gold-sft-der-66078-vs-crown-818-157pp-the-curriculum-verdict-confirms-on-the-plane-lineage-2026-11-20" + }, + { + "name": "der_crown_baseline", + "value": 8.18, + "source": "interscript/interscript-models docs/RESULTS.md#run-022-heb-plane-base--818-der-at-the-artifact-level-gate-cleared-hebrew--430pp-2026-10-07" + } + ] + }, + "checksums": [ + { + "algorithm": "SHA256", + "checksumValue": "d6833fc79751ad39ee6a6a7d45632038997ec060955e46f77d39c1fdb848959a" + } + ] + }, + { + "type": "Dataset", + "spdxId": "SPDXRef-Corpus-hebrew-v4", + "name": "hebrew-v4", + "datasetComment": "Training corpus (SPDX 3.0 Dataset profile).", + "licenseConcluded": "NOASSERTION", + "x-interscript-corpus": { + "registry": "corpora/hebrew-v4.yaml", + "task": "diacritization", + "sources": [ + { + "kind": "hf-dataset", + "id": "Interscript/hebrew-v4", + "revision": "main", + "license": "LicenseRef-mixed-internal", + "license_review": { + "status": "owner-approved", + "date": "2026-11-21", + "note": "crown-lineage corpus — ship approved by the WO92 ship decision (heb-vocalized-plane-3.0, owner go 2026-11-21); assembled internally from public sources for the shipped plane family; upstream license audit tracked as backlog, card states the lineage" + } + } + ], + "splits": { + "train": { + "path": "train.jsonl", + "rows": 50433, + "sha256": "3b71166c842d9515412bb1ac2b76cdb874f336f2b02e9cbf648e1921ed696c48" + }, + "test": { + "path": "test.jsonl", + "rows": 1864, + "sha256": "77e9b5dc3a3b9e7d70924e670f7361455b714ec8212e046662ea04187b153ccc" + } + } + }, + "checksums": [ + { + "algorithm": "SHA256", + "checksumValue": "3b71166c842d9515412bb1ac2b76cdb874f336f2b02e9cbf648e1921ed696c48" + }, + { + "algorithm": "SHA256", + "checksumValue": "77e9b5dc3a3b9e7d70924e670f7361455b714ec8212e046662ea04187b153ccc" + } + ] + }, + { + "type": "Dataset", + "spdxId": "SPDXRef-Corpus-heb-knesset-weak", + "name": "heb-knesset-weak", + "datasetComment": "Training corpus (SPDX 3.0 Dataset profile).", + "licenseConcluded": "NOASSERTION", + "x-interscript-corpus": { + "registry": "corpora/heb-knesset-weak.yaml", + "task": "diacritization", + "sources": [ + { + "kind": "hf-dataset", + "id": "Phonikud/phonikud-data", + "revision": "main", + "license": "MIT", + "provenance": "https://huggingface.co/datasets/Phonikud/phonikud-data (knesset_nikud_v6.txt.7z; snapshot 2026-11-19)" + }, + { + "kind": "hf-dataset", + "id": "Interscript/he-knesset-v6-weak", + "revision": "main", + "license": "MIT", + "provenance": "built by interscript-train prep_heb_knesset_weak.py (job 6afe91e5e41aae15936d24b1, 2026-11-19)" + } + ], + "splits": { + "train": { + "path": "heb-knesset-weak-00000-of-00008.jsonl … heb-knesset-weak-00007-of-00008.jsonl (8 shards; pins in SHA256SUMS.txt)", + "rows": 2667695, + "sha256": "825015b13c128f6bd964935daa6d7113baa94930a68e99c86ffdc633f5bf66d6" + }, + "test": { + "path": "heb-knesset-weak-00007-of-00008.jsonl", + "rows": 333462, + "sha256": "10c2c7c595d24aae0bf5ea4fa7431861ef16656d4492fa00411d3229159ce144" + } + } + }, + "checksums": [ + { + "algorithm": "SHA256", + "checksumValue": "825015b13c128f6bd964935daa6d7113baa94930a68e99c86ffdc633f5bf66d6" + }, + { + "algorithm": "SHA256", + "checksumValue": "10c2c7c595d24aae0bf5ea4fa7431861ef16656d4492fa00411d3229159ce144" + } + ] + }, + { + "type": "Relationship", + "spdxId": "SPDXRef-Relationship-01", + "relationshipType": "dependsOn", + "from": "SPDXRef-Model-heb-vocalized-plane-3.0", + "to": [ + "SPDXRef-Corpus-hebrew-v4", + "SPDXRef-Corpus-heb-knesset-weak" + ], + "comment": "Training data (sha-pinned splits under each Dataset)." + } + ] +} diff --git a/bom/heb-vocalized-plane-3.0.spdx.json.sha256 b/bom/heb-vocalized-plane-3.0.spdx.json.sha256 new file mode 100644 index 0000000..597f047 --- /dev/null +++ b/bom/heb-vocalized-plane-3.0.spdx.json.sha256 @@ -0,0 +1 @@ +b478047c95b36bb0cba44fa0f76fbf8bd94acf972e51efa3a7f298e4d0545be3 heb-vocalized-plane-3.0.spdx.json diff --git a/bom/lineage.yaml b/bom/lineage.yaml new file mode 100644 index 0000000..ca0a658 --- /dev/null +++ b/bom/lineage.yaml @@ -0,0 +1,77 @@ +# Model-BOM lineage registry. +# +# models.yaml records artifact sha256/urls, license, metrics and parity, but +# leaves the model -> training-corpus linkage implicit (prose trained_from +# notes or card text). This registry makes that linkage declarative for the +# SPDX 3.0-style Model BOM (scripts/generate_model_bom.py): +# +# shipped models -> `corpora` list resolved against corpora/*.yaml +# (+ optional `lineage` training-chain notes) +# pending models -> full gated-pending entry (status, gate, lineage) +# +# Every value here is transcribed from the org's recorded evidence +# (models.yaml, corpora/*.yaml, cards/*.md, TODO.sota/*). Artifact +# sha256/urls are NEVER pre-staged for pending models (owner law, +# TODO.sota/92: the models.yaml ship entry is created at ship time with +# real artifact data). + +heb-vocalized-plane-3.0: + corpora: [hebrew-v4, heb-knesset-weak] + lineage: + - step: WO92 stage 1 (weak pretrain) + detail: >- + run-093-heb-weak-pretrain: 1,500,000 deduped knesset-v6 weak units + (Dicta machine labels — weak supervision only) COMBINED with the + full gold corpus (50,303 gold), 1 epoch + (cards/heb-vocalized-plane-3.0.md). + - step: WO92 stage 2 (gold SFT) + detail: >- + run-094-heb-gold-sft (train_hebrew_sft_hf.py, HF Jobs a100-large), + resumed from run-093 best with the exact crown recipe; inventory + inherited byte-identical (labels.sha edd595d96d09) + (cards/heb-vocalized-plane-3.0.md). + source_refs: + card: cards/heb-vocalized-plane-3.0.md + +urd-vocalized-2.0: + status: gated-pending + ship_name: urd-vocalized-2.0 + # canonical ship name per the WO87 renames (models.yaml: + # urd-diac-2.0 -> urd-vocalized-2.0, staged) + version: "2.0" + task: diacritization + scripts: [Arab, Arab] + planned_license: BSD-3-Clause + # org convention (code + weights); confirmed at ship time + corpora: [urd-dia] + descends_from: [urd-vocalized-base-1.0] + lineage: + - step: teacher lineage (public only) + detail: >- + urd-vocalized-base-1.0 (run-066): google/byt5-base + data-diacrit + only — STEP 0 trace corroborated by four independent records + (TODO.sota/92). + - step: clean-room distill candidates + detail: >- + run-095-urd-diac-distill (candidate sha8 2a29658c) and + run-096-urd-diac-distill (candidate + run-096-urd-diac-distill/step-41232/model, sha8 24f5a2d6); + 41,232/41,232 steps; CER 0.03641 vs quality gate 0.0377 (PASS), + below champion urd-vocalized-1.0 3.74 (TODO.sota/92). + gate: + name: Clause 16(e) calibrated membership-inference (CLE compliance) + verdict: FAIL + date: "2026-11-23" + detail: >- + calibrated_auc 0.6475 (tolerance ±0.05 around 0.5) and calibrated + success rate 0.6324 (tolerance 0.6) — both FAIL; reference + self-control exactly 0.5 (probe sound); extraction / verbatim / + wordnet all PASS. Shingle-overlap discriminator: data-diacrit vs CLE + overlap is ZERO. Records retained to 2028-11-23 (TODO.sota/92). + records: hf://buckets/rhtse/urdu-16e-gate/urdu-16e-run-096-vocalized-calibrated/ + ship_runbook_executed: false + artifact: + note: >- + Deliberately absent: sha256/urls are never pre-staged; the models.yaml + ship entry is created at ship time with real artifact data (owner law, + TODO.sota/92). diff --git a/bom/urd-vocalized-2.0.spdx.json b/bom/urd-vocalized-2.0.spdx.json new file mode 100644 index 0000000..ca0961f --- /dev/null +++ b/bom/urd-vocalized-2.0.spdx.json @@ -0,0 +1,139 @@ +{ + "spdxVersion": "SPDX-3.0", + "dataLicense": "CC0-1.0", + "SPDXID": "SPDXRef-DOCUMENT", + "documentNamespace": "https://github.com/interscript/interscript-models/model-bom/urd-vocalized-2.0@2026-11-24T07:46:03Z", + "name": "model-bom-urd-vocalized-2.0", + "comment": "SPDX 3.0-style Model BOM generated by interscript-models/scripts/generate_model_bom.py from models.yaml, corpora/*.yaml and bom/lineage.yaml. Model = Package; sha-pinned training corpora = Dataset dependencies; lineage = relationships.", + "creationInfo": { + "created": "2026-11-24T07:46:03Z", + "creators": [ + "Organization: Interscript (interscript.org)", + "Tool: interscript-models/scripts/generate_model_bom.py" + ] + }, + "x-interscript-status": "gated-pending", + "@graph": [ + { + "type": "Package", + "spdxId": "SPDXRef-Model-urd-vocalized-2.0", + "name": "urd-vocalized-2.0", + "versionInfo": "2.0", + "downloadLocation": "NOASSERTION", + "filesAnalyzed": false, + "licenseConcluded": "BSD-3-Clause", + "licenseDeclared": "BSD-3-Clause", + "copyrightText": "NOASSERTION", + "supplier": "Organization: Interscript (interscript.org)", + "primaryPackagePurpose": "OTHER", + "packageComment": "Machine-learning model weights (SPDX 3.0 AI profile domain).", + "externalRefs": [ + { + "referenceCategory": "PACKAGE-MANAGER", + "referenceType": "purl", + "referenceLocator": "pkg:interscript/model/urd-vocalized-2.0@2.0" + } + ], + "x-interscript": { + "status": "gated-pending", + "registry": "bom/lineage.yaml (pending)", + "task": "diacritization", + "scripts": [ + "Arab", + "Arab" + ], + "lineage": [ + { + "step": "teacher lineage (public only)", + "detail": "urd-vocalized-base-1.0 (run-066): google/byt5-base + data-diacrit only — STEP 0 trace corroborated by four independent records (TODO.sota/92)." + }, + { + "step": "clean-room distill candidates", + "detail": "run-095-urd-diac-distill (candidate sha8 2a29658c) and run-096-urd-diac-distill (candidate run-096-urd-diac-distill/step-41232/model, sha8 24f5a2d6); 41,232/41,232 steps; CER 0.03641 vs quality gate 0.0377 (PASS), below champion urd-vocalized-1.0 3.74 (TODO.sota/92)." + } + ] + } + }, + { + "type": "Dataset", + "spdxId": "SPDXRef-Corpus-urd-dia", + "name": "urd-dia", + "datasetComment": "Training corpus (SPDX 3.0 Dataset profile).", + "licenseConcluded": "NOASSERTION", + "x-interscript-corpus": { + "registry": "corpora/urd-dia.yaml", + "task": "diacritization", + "sources": [ + { + "kind": "bucket", + "id": "rhtse/jobs-artifacts/rababa-urdu-cc174b96", + "revision": "data-diacrit", + "license": "LicenseRef-unresolved", + "license_review": { + "status": "owner-approved", + "date": "2026-10-18", + "note": "ship with dependency note — weights depend on the original data license (owner decision" + }, + "mount": "/data-dia" + } + ], + "splits": { + "train": { + "path": "data-diacrit/train.jsonl", + "rows": 573130, + "sha256": "95736b0d19e57ada3ce435f28300b8a72a3fec6c761dfce34770ed9549331ee2" + }, + "test": { + "path": "data-diacrit/test.jsonl", + "rows": 11940, + "sha256": "6d822ae70a383e5547ee82e841a65e83fac81ae47ff320999b8e6b101b1790bb" + } + } + }, + "checksums": [ + { + "algorithm": "SHA256", + "checksumValue": "95736b0d19e57ada3ce435f28300b8a72a3fec6c761dfce34770ed9549331ee2" + }, + { + "algorithm": "SHA256", + "checksumValue": "6d822ae70a383e5547ee82e841a65e83fac81ae47ff320999b8e6b101b1790bb" + } + ] + }, + { + "type": "Relationship", + "spdxId": "SPDXRef-Relationship-01", + "relationshipType": "dependsOn", + "from": "SPDXRef-Model-urd-vocalized-2.0", + "to": [ + "SPDXRef-Corpus-urd-dia" + ], + "comment": "Training data (sha-pinned splits under each Dataset)." + }, + { + "type": "Relationship", + "spdxId": "SPDXRef-Relationship-02", + "relationshipType": "descendantOf", + "from": "SPDXRef-Model-urd-vocalized-2.0", + "to": [ + "SPDXRef-Model-urd-vocalized-base-1.0" + ], + "comment": "trained_from chain (models.yaml lineage)." + }, + { + "type": "Annotation", + "spdxId": "SPDXRef-Annotation-Gate-urd-vocalized-2.0", + "annotationType": "OTHER", + "subject": "SPDXRef-Model-urd-vocalized-2.0", + "comment": { + "gate": "Clause 16(e) calibrated membership-inference (CLE compliance)", + "verdict": "FAIL", + "date": "2026-11-23", + "detail": "calibrated_auc 0.6475 (tolerance ±0.05 around 0.5) and calibrated success rate 0.6324 (tolerance 0.6) — both FAIL; reference self-control exactly 0.5 (probe sound); extraction / verbatim / wordnet all PASS. Shingle-overlap discriminator: data-diacrit vs CLE overlap is ZERO. Records retained to 2028-11-23 (TODO.sota/92).", + "records": "hf://buckets/rhtse/urdu-16e-gate/urdu-16e-run-096-vocalized-calibrated/", + "shipRunbookExecuted": false + } + } + ] +} diff --git a/bom/urd-vocalized-2.0.spdx.json.sha256 b/bom/urd-vocalized-2.0.spdx.json.sha256 new file mode 100644 index 0000000..dcde3a2 --- /dev/null +++ b/bom/urd-vocalized-2.0.spdx.json.sha256 @@ -0,0 +1 @@ +682a170cb7892fbf0cc6ab607f35d110bf9f6ad317785bac4cad8640a5468942 urd-vocalized-2.0.spdx.json diff --git a/scripts/generate_model_bom.py b/scripts/generate_model_bom.py new file mode 100644 index 0000000..25baac0 --- /dev/null +++ b/scripts/generate_model_bom.py @@ -0,0 +1,300 @@ +"""Generate an SPDX 3.0-style Model BOM for a shipped or gated-pending model. + +Formalizes the org's recorded model provenance into a self-contained JSON +document (model = Package; training data = Dataset dependencies with their +sha256 pins; license + eval metric references carried on the model): + + models.yaml artifact sha256/size/urls/parts, license, metrics, + parity, trained_from (the shipped-model registry) + corpora/*.yaml sha-pinned training corpora (sources + splits) + bom/lineage.yaml declarative model -> corpora linkage, training-chain + notes, and gated-pending model entries + +The SPDX 3.0-style graph carries: + - ``Package`` the model (checksums, license, release asset refs, + task/precision/kind, parity, eval metric references) + - ``Dataset`` one per training corpus (sources, split sha256 pins) + - ``Relationship`` ``dependsOn`` (model -> training data) and + ``descendantOf`` (model -> teacher/base model) + - ``x-interscript`` extension blocks preserve the registry fields verbatim + +Usage:: + + python scripts/generate_model_bom.py --model heb-vocalized-plane-3.0 + python scripts/generate_model_bom.py --model urd-vocalized-2.0 + python scripts/generate_model_bom.py --all + +Output: bom/.spdx.json (+ .spdx.json.sha256 sidecar, the +house sidecar pattern). Gated-pending models carry no artifact sha256/urls +by owner law (never pre-staged); their document records the recorded gate +verdict and lineage instead. + +Exit code 0 on success, 2 on a bad model id, 3 on an inconsistent entry. +""" + +from __future__ import annotations + +import argparse +import hashlib +import json +import sys +from datetime import datetime, timezone +from pathlib import Path + +import yaml + +REPO = Path(__file__).resolve().parent.parent +MODELS_YAML = REPO / "models.yaml" +CORPORA_DIR = REPO / "corpora" +LINEAGE_YAML = REPO / "bom" / "lineage.yaml" +OUT_DIR = REPO / "bom" +NAMESPACE_BASE = "https://github.com/interscript/interscript-models/model-bom" + + +def load_yaml(path: Path): + with open(path, "r", encoding="utf-8") as fh: + return yaml.safe_load(fh) + + +def sha256_file(path: Path) -> str: + digest = hashlib.sha256() + with open(path, "rb") as fh: + for chunk in iter(lambda: fh.read(1024 * 1024), b""): + digest.update(chunk) + return digest.hexdigest() + + +def spdx_id(kind: str, name: str) -> str: + return f"SPDXRef-{kind}-{name}" + + +def build_model_package( + model_id: str, model: dict, lineage_entry: dict, status: str +) -> dict: + x = { + "status": status, + "registry": "models.yaml" if status == "shipped" else "bom/lineage.yaml (pending)", + "task": model.get("task"), + "scripts": model.get("scripts"), + } + for key in ("kind", "precision", "filename", "size"): + if model.get(key) is not None: + x[key] = model[key] + if model.get("parity"): + x["parity"] = model["parity"] + if lineage_entry.get("source_refs"): + x["sourceRefs"] = lineage_entry["source_refs"] + if lineage_entry.get("lineage"): + x["lineage"] = lineage_entry["lineage"] + if model.get("metrics"): + x["evaluations"] = [ + { + "name": m["name"], + "value": m["value"], + **({"protocol": m["protocol"]} if m.get("protocol") else {}), + "source": m.get("source"), + } + for m in model["metrics"] + ] + if model.get("parts"): + x["releaseAssetParts"] = model["parts"] + if model.get("trained_from"): + x["trainedFrom"] = model["trained_from"] + + package = { + "type": "Package", + "spdxId": spdx_id("Model", model_id), + "name": lineage_entry.get("ship_name", model_id), + "versionInfo": str(lineage_entry.get("version", model_id.rsplit("-", 1)[-1])), + "downloadLocation": model.get("url") or "NOASSERTION", + "filesAnalyzed": False, + "licenseConcluded": model.get("license") or lineage_entry.get("planned_license"), + "licenseDeclared": model.get("license") or lineage_entry.get("planned_license"), + "copyrightText": "NOASSERTION", + "supplier": "Organization: Interscript (interscript.org)", + "primaryPackagePurpose": "OTHER", + "packageComment": "Machine-learning model weights (SPDX 3.0 AI profile domain).", + "externalRefs": [ + { + "referenceCategory": "PACKAGE-MANAGER", + "referenceType": "purl", + "referenceLocator": f"pkg:interscript/model/{model_id}" + + (f"@{lineage_entry['version']}" if lineage_entry.get("version") else ""), + } + ], + "x-interscript": x, + } + if model.get("sha256"): + package["checksums"] = [{"algorithm": "SHA256", "checksumValue": model["sha256"]}] + if model.get("license_note"): + x["licenseNote"] = model["license_note"] + return package + + +def build_corpus_dataset(corpus_id: str, corpus: dict) -> dict: + dataset = { + "type": "Dataset", + "spdxId": spdx_id("Corpus", corpus_id), + "name": corpus.get("id", corpus_id), + "datasetComment": "Training corpus (SPDX 3.0 Dataset profile).", + "licenseConcluded": corpus.get("license", "NOASSERTION"), + "x-interscript-corpus": { + "registry": f"corpora/{corpus_id}.yaml", + "task": corpus.get("task"), + "sources": corpus.get("sources", []), + "splits": corpus.get("splits", {}), + }, + } + split_checksums = [ + {"algorithm": "SHA256", "checksumValue": split["sha256"]} + for split in (corpus.get("splits") or {}).values() + if split.get("sha256") + ] + if split_checksums: + dataset["checksums"] = split_checksums + return dataset + + +def build_document(model_id: str, graph: list, created: str, status: str) -> dict: + namespace = f"{NAMESPACE_BASE}/{model_id}@{created}" + return { + "spdxVersion": "SPDX-3.0", + "dataLicense": "CC0-1.0", + "SPDXID": "SPDXRef-DOCUMENT", + "documentNamespace": namespace, + "name": f"model-bom-{model_id}", + "comment": ( + "SPDX 3.0-style Model BOM generated by " + "interscript-models/scripts/generate_model_bom.py from models.yaml, " + "corpora/*.yaml and bom/lineage.yaml. Model = Package; sha-pinned " + "training corpora = Dataset dependencies; lineage = relationships." + ), + "creationInfo": { + "created": created, + "creators": [ + "Organization: Interscript (interscript.org)", + "Tool: interscript-models/scripts/generate_model_bom.py", + ], + }, + "x-interscript-status": status, + "@graph": graph, + } + + +def generate(model_id: str, models: dict, corpora: dict, lineage: dict, created: str) -> dict: + entry = lineage.get(model_id) + if entry is None: + raise KeyError(model_id) + + pending = entry.get("status") == "gated-pending" + model = entry if pending else models.get(model_id) + if model is None: + raise KeyError(model_id) + if pending: + # Owner law: never pre-stage artifact data for gated-pending models. + assert not model.get("sha256") and not model.get("url"), ( + f"{model_id}: gated-pending entries must not pre-stage artifact data" + ) + + graph: list = [] + graph.append(build_model_package(model_id, model, entry, entry.get("status", "shipped"))) + + corpus_ids = entry.get("corpora", []) + for cid in corpus_ids: + if cid not in corpora: + raise KeyError(f"corpora/{cid}.yaml") + graph.append(build_corpus_dataset(cid, corpora[cid])) + + rel_n = 0 + if corpus_ids: + rel_n += 1 + graph.append( + { + "type": "Relationship", + "spdxId": f"SPDXRef-Relationship-{rel_n:02d}", + "relationshipType": "dependsOn", + "from": spdx_id("Model", model_id), + "to": [spdx_id("Corpus", cid) for cid in corpus_ids], + "comment": "Training data (sha-pinned splits under each Dataset).", + } + ) + teachers = [lid for lid in entry.get("descends_from", []) if lid in models] + if teachers: + rel_n += 1 + graph.append( + { + "type": "Relationship", + "spdxId": f"SPDXRef-Relationship-{rel_n:02d}", + "relationshipType": "descendantOf", + "from": spdx_id("Model", model_id), + "to": [spdx_id("Model", t) for t in teachers], + "comment": "trained_from chain (models.yaml lineage).", + } + ) + if pending and entry.get("gate"): + graph.append( + { + "type": "Annotation", + "spdxId": f"SPDXRef-Annotation-Gate-{model_id}", + "annotationType": "OTHER", + "subject": spdx_id("Model", model_id), + "comment": { + "gate": entry["gate"].get("name"), + "verdict": entry["gate"].get("verdict"), + "date": entry["gate"].get("date"), + "detail": entry["gate"].get("detail"), + "records": entry["gate"].get("records"), + "shipRunbookExecuted": entry["gate"].get("ship_runbook_executed"), + }, + } + ) + return build_document(model_id, graph, created, entry.get("status", "shipped")) + + +def main(argv: list[str] | None = None) -> int: + parser = argparse.ArgumentParser(description=__doc__.splitlines()[0]) + parser.add_argument("--model", action="append", help="model id (repeatable)") + parser.add_argument("--all", action="store_true", help="generate for every lineage.yaml entry") + parser.add_argument( + "--out-dir", type=Path, default=OUT_DIR, help="output directory (default bom/)" + ) + args = parser.parse_args(argv) + + models = load_yaml(MODELS_YAML).get("models", {}) + corpora = { + p.stem: load_yaml(p) + for p in sorted(CORPORA_DIR.glob("*.yaml")) + } + lineage = load_yaml(LINEAGE_YAML) + + targets = sorted(lineage.keys()) if args.all else (args.model or []) + if not targets: + parser.error("no models requested: pass --model (repeatable) or --all") + + created = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ") + out_dir: Path = args.out_dir + out_dir.mkdir(parents=True, exist_ok=True) + + failures = 0 + for model_id in targets: + try: + doc = generate(model_id, models, corpora, lineage, created) + except KeyError as exc: + print(f"FAIL {model_id}: unknown id or missing source: {exc}", file=sys.stderr) + failures += 1 + continue + out_path = out_dir / f"{model_id}.spdx.json" + with open(out_path, "w", encoding="utf-8") as fh: + json.dump(doc, fh, indent=2, ensure_ascii=False) + fh.write("\n") + sidecar = out_path.parent / (out_path.name + ".sha256") + with open(sidecar, "w", encoding="utf-8") as fh: + fh.write(f"{sha256_file(out_path)} {out_path.name}\n") + status = doc["x-interscript-status"] + print(f"OK {model_id} [{status}] -> {out_path} (+ {sidecar.name})") + + return 3 if failures else 0 + + +if __name__ == "__main__": + sys.exit(main())