review-response: upload src/pino/train.py
Browse files- src/pino/train.py +30 -0
src/pino/train.py
CHANGED
|
@@ -310,6 +310,15 @@ def main():
|
|
| 310 |
logger.info("Configuration: %s", cfg)
|
| 311 |
|
| 312 |
# Ingest and split the dataset with strict active-molecule isolation.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 313 |
print("⏳ Splicing empirical bootstrap data streams...")
|
| 314 |
with open(args.data, "r") as f:
|
| 315 |
all_records = [json.loads(line) for line in f]
|
|
@@ -331,6 +340,27 @@ def main():
|
|
| 331 |
print(f"🔒 Molecule isolation check: {len(overlap)} active CAS shared between splits.")
|
| 332 |
print(f"🚫 Excluded mixed-boundary records: {len(split['excluded_indices'])}")
|
| 333 |
assert len(overlap) == 0, f"Molecule leakage detected: {sorted(overlap)}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 334 |
if not train_records or not val_records:
|
| 335 |
raise RuntimeError(
|
| 336 |
"Molecule-disjoint split produced an empty train or validation set. "
|
|
|
|
| 310 |
logger.info("Configuration: %s", cfg)
|
| 311 |
|
| 312 |
# Ingest and split the dataset with strict active-molecule isolation.
|
| 313 |
+
# NOTE (leakage review): a connected-components split over the formula-molecule
|
| 314 |
+
# co-occurrence graph was evaluated and REJECTED for this corpus. The graph is
|
| 315 |
+
# dominated by a single giant component (5,592/5,707 records; shared carriers +
|
| 316 |
+
# genre ingredient pools link nearly all molecules), so a strict component split
|
| 317 |
+
# is mathematically impossible, and the hub-excluded variant yields a validation
|
| 318 |
+
# set of only singleton/duplicate formulas (degenerate, unrepresentative).
|
| 319 |
+
# Molecule-disjoint splitting is therefore the correct instrument here: it gives
|
| 320 |
+
# a representative held-out set with a strict zero-active-molecule guarantee.
|
| 321 |
+
# See scripts/split_leakage_analysis.py for the full evidence + assertion.
|
| 322 |
print("⏳ Splicing empirical bootstrap data streams...")
|
| 323 |
with open(args.data, "r") as f:
|
| 324 |
all_records = [json.loads(line) for line in f]
|
|
|
|
| 340 |
print(f"🔒 Molecule isolation check: {len(overlap)} active CAS shared between splits.")
|
| 341 |
print(f"🚫 Excluded mixed-boundary records: {len(split['excluded_indices'])}")
|
| 342 |
assert len(overlap) == 0, f"Molecule leakage detected: {sorted(overlap)}"
|
| 343 |
+
# Persist the zero-intersection assertion for the paper's reproducibility ledger.
|
| 344 |
+
try:
|
| 345 |
+
leakage_report = {
|
| 346 |
+
"split_strategy": "molecule_disjoint",
|
| 347 |
+
"seed": args.seed,
|
| 348 |
+
"train_ratio": args.train_ratio,
|
| 349 |
+
"n_train_records": len(train_records),
|
| 350 |
+
"n_validation_records": len(val_records),
|
| 351 |
+
"n_excluded_records": len(split["excluded_indices"]),
|
| 352 |
+
"n_train_molecules": len(train_cas),
|
| 353 |
+
"n_validation_molecules": len(val_cas),
|
| 354 |
+
"shared_molecule_count": len(overlap),
|
| 355 |
+
"zero_intersection_assertion": "PASSED" if not overlap else "FAILED",
|
| 356 |
+
}
|
| 357 |
+
Path(args.output_dir).mkdir(parents=True, exist_ok=True)
|
| 358 |
+
report_name = f"split_leakage_report_seed{args.seed}.json"
|
| 359 |
+
with open(Path(args.output_dir) / report_name, "w") as rf:
|
| 360 |
+
json.dump(leakage_report, rf, indent=2)
|
| 361 |
+
print(f"📝 Split leakage report: {report_name} (zero-intersection: {leakage_report['zero_intersection_assertion']})")
|
| 362 |
+
except Exception as e: # noqa: BLE001
|
| 363 |
+
logger.warning("Could not write split leakage report: %s", e)
|
| 364 |
if not train_records or not val_records:
|
| 365 |
raise RuntimeError(
|
| 366 |
"Molecule-disjoint split produced an empty train or validation set. "
|