Something went wrong. Try again.
bayes for days
Something went wrong. Try again.
sds ablate-features.py
1.4 kB · 38 lines
Python
123456789101112131415161718192021222324252627282930313233343536373839#!/usr/bin/env python3"""Every learnable feature except one, as --feature flags.
Resolves a corpus NAME through the store as well as a run directory path. Thefirst version took only a path, was handed a name, silently wrote nothing, andthe fit it fed ran with no --feature flags at all - which means "fiteverything", so the ablation was the same fit twice and reported a difference ofexactly zero."""import jsonimport pathlibimport subprocessimport sys
target, drop = sys.argv[1], sys.argv[2]candidates = [ pathlib.Path(target) / "manifest.json", pathlib.Path(target) / "data" / "manifest.json",]root = subprocess.run(["git", "rev-parse", "--git-common-dir"], capture_output=True, text=True).stdout.strip()if root: store = pathlib.Path(root).parent / "corpora" / target candidates += [store / "manifest.json", store / "data" / "manifest.json"]
for path in candidates: if path.is_file(): learnable = json.load(open(path)).get("learnable") or [] breakelse: sys.exit(f"no manifest for {target!r}; tried {[str(c) for c in candidates]}")
if drop not in learnable: sys.exit(f"{drop!r} is not learnable in this corpus; nothing to ablate")kept = [n for n in learnable if n != drop]if len(kept) < 2: sys.exit(f"only {len(kept)} feature(s) left after dropping {drop!r}")print(" ".join(f"--feature {n}" for n in kept))