Matthew Ford commited on
Commit ·
224d843
1
Parent(s): 8377646
feat: evaluators support pom_alltags arm (objective_dim-aware, prospective N/A for 575-dim)
Browse files- evaluate_frozen_benchmarks: load_model takes objective_dim; 575-dim arm runs
triplet ranking (width-agnostic learned perceptual space) and marks the
prospective family-profile projection not-applicable (it is defined over the
138-dim Pyrfume vocab, so a 575-dim tag arm is not comparable there). Verified
on smoke checkpoint: triplets 0.30 (6/20).
- eval_v6: --structural-source gains pom_alltags; threads objective_dim through
heads + make_validation_dataset.
Former-commit-id: 0cc448d0da43d7ed034bf9bde2217c5b441b26c8
Former-commit-id: d7c80afd29fa8e3bbfc6f5e0e0319efef88d97d2
- scripts/eval_v6.py +7 -4
- scripts/evaluate_frozen_benchmarks.py +17 -7
scripts/eval_v6.py
CHANGED
|
@@ -38,7 +38,7 @@ def parse_args() -> argparse.Namespace:
|
|
| 38 |
parser.add_argument("--batch-size", type=int, default=8)
|
| 39 |
parser.add_argument("--seed", type=int, default=42)
|
| 40 |
parser.add_argument("--train-ratio", type=float, default=DEFAULT_TRAIN_RATIO, help="Molecule-disjoint train molecule ratio used to rebuild the 15% holdout validation set.")
|
| 41 |
-
parser.add_argument("--structural-source", choices=["morgan", "openpom_256"], default="morgan", help="Structural embedding block matching the checkpoint's training arm.")
|
| 42 |
parser.add_argument("--output", default="metrics_v6_current.json", help="Metrics JSON output path.")
|
| 43 |
parser.add_argument(
|
| 44 |
"--hf-repo",
|
|
@@ -81,7 +81,7 @@ def sha256_file(path: str | Path) -> str:
|
|
| 81 |
return digest.hexdigest()
|
| 82 |
|
| 83 |
|
| 84 |
-
def make_validation_dataset(records: list[dict[str, Any]], *, train_ratio: float, seed: int, structural_source: str = "morgan") -> FragranceTrajectoryDataset:
|
| 85 |
split = create_molecule_disjoint_split_from_records(records, train_ratio=train_ratio, seed=seed)
|
| 86 |
genre_map = {genre: idx for idx, genre in enumerate(DEFAULT_GENRES)}
|
| 87 |
return FragranceTrajectoryDataset(
|
|
@@ -89,6 +89,7 @@ def make_validation_dataset(records: list[dict[str, Any]], *, train_ratio: float
|
|
| 89 |
use_embedding_fallback=True,
|
| 90 |
structural_source=structural_source,
|
| 91 |
genre_map=genre_map,
|
|
|
|
| 92 |
)
|
| 93 |
|
| 94 |
|
|
@@ -145,12 +146,14 @@ def evaluate(args: argparse.Namespace) -> dict[str, Any]:
|
|
| 145 |
model.load_state_dict(model_state)
|
| 146 |
model.eval()
|
| 147 |
|
| 148 |
-
|
|
|
|
| 149 |
heads_missing, heads_unexpected = heads.load_state_dict(ckpt["heads_state_dict"], strict=False)
|
| 150 |
heads.eval()
|
| 151 |
|
| 152 |
records = read_records(args.data)
|
| 153 |
-
|
|
|
|
| 154 |
val_loader = DataLoader(
|
| 155 |
val_dataset,
|
| 156 |
batch_size=args.batch_size,
|
|
|
|
| 38 |
parser.add_argument("--batch-size", type=int, default=8)
|
| 39 |
parser.add_argument("--seed", type=int, default=42)
|
| 40 |
parser.add_argument("--train-ratio", type=float, default=DEFAULT_TRAIN_RATIO, help="Molecule-disjoint train molecule ratio used to rebuild the 15% holdout validation set.")
|
| 41 |
+
parser.add_argument("--structural-source", choices=["morgan", "openpom_256", "pom_alltags"], default="morgan", help="Structural embedding block matching the checkpoint's training arm.")
|
| 42 |
parser.add_argument("--output", default="metrics_v6_current.json", help="Metrics JSON output path.")
|
| 43 |
parser.add_argument(
|
| 44 |
"--hf-repo",
|
|
|
|
| 81 |
return digest.hexdigest()
|
| 82 |
|
| 83 |
|
| 84 |
+
def make_validation_dataset(records: list[dict[str, Any]], *, train_ratio: float, seed: int, structural_source: str = "morgan", objective_dim: int = 138) -> FragranceTrajectoryDataset:
|
| 85 |
split = create_molecule_disjoint_split_from_records(records, train_ratio=train_ratio, seed=seed)
|
| 86 |
genre_map = {genre: idx for idx, genre in enumerate(DEFAULT_GENRES)}
|
| 87 |
return FragranceTrajectoryDataset(
|
|
|
|
| 89 |
use_embedding_fallback=True,
|
| 90 |
structural_source=structural_source,
|
| 91 |
genre_map=genre_map,
|
| 92 |
+
objective_dim=objective_dim,
|
| 93 |
)
|
| 94 |
|
| 95 |
|
|
|
|
| 146 |
model.load_state_dict(model_state)
|
| 147 |
model.eval()
|
| 148 |
|
| 149 |
+
objective_dim = 575 if args.structural_source == "pom_alltags" else 138
|
| 150 |
+
heads = PIMTHeads(hidden_dim=dims["hidden_dim"], objective_dim=objective_dim)
|
| 151 |
heads_missing, heads_unexpected = heads.load_state_dict(ckpt["heads_state_dict"], strict=False)
|
| 152 |
heads.eval()
|
| 153 |
|
| 154 |
records = read_records(args.data)
|
| 155 |
+
engine_source = "openpom_256" if args.structural_source == "pom_alltags" else args.structural_source
|
| 156 |
+
val_dataset = make_validation_dataset(records, train_ratio=args.train_ratio, seed=args.seed, structural_source=engine_source, objective_dim=objective_dim)
|
| 157 |
val_loader = DataLoader(
|
| 158 |
val_dataset,
|
| 159 |
batch_size=args.batch_size,
|
scripts/evaluate_frozen_benchmarks.py
CHANGED
|
@@ -46,13 +46,13 @@ def infer_model_dims(state_dict: dict[str, torch.Tensor]) -> dict[str, int]:
|
|
| 46 |
"hidden_dim": int(hidden_dim), "num_heads": num_heads, "num_layers": int(num_layers)}
|
| 47 |
|
| 48 |
|
| 49 |
-
def load_model(ckpt_path: Path):
|
| 50 |
ckpt = torch.load(ckpt_path, map_location="cpu", weights_only=False)
|
| 51 |
dims = infer_model_dims(ckpt["model_state_dict"])
|
| 52 |
model = PhysicsInformedMixtureTransformer(**dims)
|
| 53 |
model.load_state_dict(ckpt["model_state_dict"])
|
| 54 |
model.eval()
|
| 55 |
-
heads = PIMTHeads(hidden_dim=dims["hidden_dim"], objective_dim=
|
| 56 |
heads.load_state_dict(ckpt["heads_state_dict"], strict=False)
|
| 57 |
heads.eval()
|
| 58 |
return model, heads, dims
|
|
@@ -153,23 +153,30 @@ def eval_prospective(model, heads, engine) -> dict[str, Any]:
|
|
| 153 |
def main() -> int:
|
| 154 |
ap = argparse.ArgumentParser()
|
| 155 |
ap.add_argument("--checkpoint", required=True)
|
| 156 |
-
ap.add_argument("--structural-source", choices=["morgan", "openpom_256"], required=True)
|
| 157 |
ap.add_argument("--arm-label", default=None)
|
| 158 |
ap.add_argument("--output", required=True)
|
| 159 |
args = ap.parse_args()
|
| 160 |
|
| 161 |
ckpt = Path(args.checkpoint)
|
| 162 |
-
|
| 163 |
-
|
|
|
|
|
|
|
| 164 |
|
| 165 |
result = {
|
| 166 |
"arm": args.arm_label or args.structural_source,
|
| 167 |
"structural_source": args.structural_source,
|
|
|
|
| 168 |
"checkpoint": {"path": str(ckpt), "sha256": sha256_file(ckpt)},
|
| 169 |
"model_dims": dims,
|
| 170 |
"input_embedding_dim": engine.embedding_dim,
|
| 171 |
"substitution_triplets": eval_triplets(model, heads, engine),
|
| 172 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
"label_access": "evaluation_only; results reported for all outcomes incl. negative",
|
| 174 |
}
|
| 175 |
out = Path(args.output)
|
|
@@ -179,7 +186,10 @@ def main() -> int:
|
|
| 179 |
["arm", "input_embedding_dim"]}, indent=2))
|
| 180 |
print("triplets:", result["substitution_triplets"]["accuracy"],
|
| 181 |
f"({result['substitution_triplets']['n_correct']}/{result['substitution_triplets']['n_triplets']})")
|
| 182 |
-
|
|
|
|
|
|
|
|
|
|
| 183 |
return 0
|
| 184 |
|
| 185 |
|
|
|
|
| 46 |
"hidden_dim": int(hidden_dim), "num_heads": num_heads, "num_layers": int(num_layers)}
|
| 47 |
|
| 48 |
|
| 49 |
+
def load_model(ckpt_path: Path, objective_dim: int = 138):
|
| 50 |
ckpt = torch.load(ckpt_path, map_location="cpu", weights_only=False)
|
| 51 |
dims = infer_model_dims(ckpt["model_state_dict"])
|
| 52 |
model = PhysicsInformedMixtureTransformer(**dims)
|
| 53 |
model.load_state_dict(ckpt["model_state_dict"])
|
| 54 |
model.eval()
|
| 55 |
+
heads = PIMTHeads(hidden_dim=dims["hidden_dim"], objective_dim=objective_dim)
|
| 56 |
heads.load_state_dict(ckpt["heads_state_dict"], strict=False)
|
| 57 |
heads.eval()
|
| 58 |
return model, heads, dims
|
|
|
|
| 153 |
def main() -> int:
|
| 154 |
ap = argparse.ArgumentParser()
|
| 155 |
ap.add_argument("--checkpoint", required=True)
|
| 156 |
+
ap.add_argument("--structural-source", choices=["morgan", "openpom_256", "pom_alltags"], required=True)
|
| 157 |
ap.add_argument("--arm-label", default=None)
|
| 158 |
ap.add_argument("--output", required=True)
|
| 159 |
args = ap.parse_args()
|
| 160 |
|
| 161 |
ckpt = Path(args.checkpoint)
|
| 162 |
+
objective_dim = 575 if args.structural_source == "pom_alltags" else 138
|
| 163 |
+
engine_source = "openpom_256" if args.structural_source == "pom_alltags" else args.structural_source
|
| 164 |
+
model, heads, dims = load_model(ckpt, objective_dim=objective_dim)
|
| 165 |
+
engine = OlfactoryEmbeddingEngine(structural_source=engine_source)
|
| 166 |
|
| 167 |
result = {
|
| 168 |
"arm": args.arm_label or args.structural_source,
|
| 169 |
"structural_source": args.structural_source,
|
| 170 |
+
"objective_dim": objective_dim,
|
| 171 |
"checkpoint": {"path": str(ckpt), "sha256": sha256_file(ckpt)},
|
| 172 |
"model_dims": dims,
|
| 173 |
"input_embedding_dim": engine.embedding_dim,
|
| 174 |
"substitution_triplets": eval_triplets(model, heads, engine),
|
| 175 |
+
# Prospective family-profile projection is defined over the 138-dim
|
| 176 |
+
# Pyrfume vocabulary; not comparable for the 575-dim all-tags arm.
|
| 177 |
+
"prospective_formulas": (eval_prospective(model, heads, engine)
|
| 178 |
+
if objective_dim == 138
|
| 179 |
+
else {"not_applicable": "575-dim tag target; family projection is 138-vocab specific"}),
|
| 180 |
"label_access": "evaluation_only; results reported for all outcomes incl. negative",
|
| 181 |
}
|
| 182 |
out = Path(args.output)
|
|
|
|
| 186 |
["arm", "input_embedding_dim"]}, indent=2))
|
| 187 |
print("triplets:", result["substitution_triplets"]["accuracy"],
|
| 188 |
f"({result['substitution_triplets']['n_correct']}/{result['substitution_triplets']['n_triplets']})")
|
| 189 |
+
if objective_dim == 138:
|
| 190 |
+
print("prospective mean cosine:", result["prospective_formulas"]["mean_family_profile_cosine"])
|
| 191 |
+
else:
|
| 192 |
+
print("prospective: not applicable (575-dim tag target)")
|
| 193 |
return 0
|
| 194 |
|
| 195 |
|