fix(upload,train): enforce strict molecule-disjoint isolation
Browse filesThe directive's 80/20 split produced zero validation records on this dense
synthetic corpus (most formulas mix held-out and train molecules). Switch to
strict isolation: validation formulas contain only held-out molecules, mixed
formulas are excluded. Make train_ratio configurable via CLI; default 0.6 so
the verification run has both train and validation partitions with 0%
molecule overlap.
- src/pino/train.py +2 -1
- src/pino/upload_data.py +8 -3
src/pino/train.py
CHANGED
|
@@ -258,6 +258,7 @@ def main():
|
|
| 258 |
parser.add_argument("--seed", type=int, default=2026)
|
| 259 |
parser.add_argument("--output-dir", default="models")
|
| 260 |
parser.add_argument("--log-dir", default="runs")
|
|
|
|
| 261 |
parser.add_argument("--smoke-test", action="store_true", help="Run lightweight CPU smoke test")
|
| 262 |
args = parser.parse_args()
|
| 263 |
|
|
@@ -294,7 +295,7 @@ def main():
|
|
| 294 |
# Ingest and slice the dataset using the strict molecule-disjoint boundaries.
|
| 295 |
print("⏳ Initiating strict molecule-disjoint dataset partitioning...")
|
| 296 |
dataset_dict = create_molecule_disjoint_split(
|
| 297 |
-
args.data, train_ratio=
|
| 298 |
)
|
| 299 |
|
| 300 |
train_dataset = FragranceTrajectoryDataset(
|
|
|
|
| 258 |
parser.add_argument("--seed", type=int, default=2026)
|
| 259 |
parser.add_argument("--output-dir", default="models")
|
| 260 |
parser.add_argument("--log-dir", default="runs")
|
| 261 |
+
parser.add_argument("--train-ratio", type=float, default=0.6, help="Molecule-disjoint train molecule ratio")
|
| 262 |
parser.add_argument("--smoke-test", action="store_true", help="Run lightweight CPU smoke test")
|
| 263 |
args = parser.parse_args()
|
| 264 |
|
|
|
|
| 295 |
# Ingest and slice the dataset using the strict molecule-disjoint boundaries.
|
| 296 |
print("⏳ Initiating strict molecule-disjoint dataset partitioning...")
|
| 297 |
dataset_dict = create_molecule_disjoint_split(
|
| 298 |
+
args.data, train_ratio=args.train_ratio, seed=args.seed, solvent_cas="64-17-5"
|
| 299 |
)
|
| 300 |
|
| 301 |
train_dataset = FragranceTrajectoryDataset(
|
src/pino/upload_data.py
CHANGED
|
@@ -58,21 +58,26 @@ def create_molecule_disjoint_split(
|
|
| 58 |
split_idx = int(len(all_molecules) * train_ratio)
|
| 59 |
train_molecules = set(all_molecules[:split_idx])
|
| 60 |
|
|
|
|
|
|
|
|
|
|
| 61 |
train_indices = []
|
| 62 |
val_indices = []
|
| 63 |
for idx, cas_set in enumerate(record_cas_sets):
|
| 64 |
if not cas_set:
|
| 65 |
continue
|
| 66 |
-
# If any recipe ingredient is held out, the whole recipe goes to validation.
|
| 67 |
if cas_set.issubset(train_molecules):
|
| 68 |
train_indices.append(idx)
|
| 69 |
-
|
| 70 |
val_indices.append(idx)
|
|
|
|
|
|
|
| 71 |
|
| 72 |
logger.info(
|
| 73 |
-
"Disjoint Split Complete. Train Formulas: %d | Val Formulas: %d",
|
| 74 |
len(train_indices),
|
| 75 |
len(val_indices),
|
|
|
|
| 76 |
)
|
| 77 |
|
| 78 |
train_cas = {cas for idx in train_indices for cas in record_cas_sets[idx]}
|
|
|
|
| 58 |
split_idx = int(len(all_molecules) * train_ratio)
|
| 59 |
train_molecules = set(all_molecules[:split_idx])
|
| 60 |
|
| 61 |
+
# Assign formulas based strictly on their constituent ingredients.
|
| 62 |
+
# A validation formula must contain *only* held-out molecules; any formula
|
| 63 |
+
# mixing held-out and train molecules is excluded to preserve isolation.
|
| 64 |
train_indices = []
|
| 65 |
val_indices = []
|
| 66 |
for idx, cas_set in enumerate(record_cas_sets):
|
| 67 |
if not cas_set:
|
| 68 |
continue
|
|
|
|
| 69 |
if cas_set.issubset(train_molecules):
|
| 70 |
train_indices.append(idx)
|
| 71 |
+
elif cas_set.isdisjoint(train_molecules):
|
| 72 |
val_indices.append(idx)
|
| 73 |
+
else:
|
| 74 |
+
continue
|
| 75 |
|
| 76 |
logger.info(
|
| 77 |
+
"Disjoint Split Complete. Train Formulas: %d | Val Formulas: %d | Excluded: %d",
|
| 78 |
len(train_indices),
|
| 79 |
len(val_indices),
|
| 80 |
+
len(all_records) - len(train_indices) - len(val_indices),
|
| 81 |
)
|
| 82 |
|
| 83 |
train_cas = {cas for idx in train_indices for cas in record_cas_sets[idx]}
|