Download dev/eval_local.py from da24b002athreyaganesh/enzymeretrieval: direct link, hf CLI and curl.
- Browser
- Download file 2.1 kB
-
https://huggingface.co/da24b002athreyaganesh/enzymeretrieval/resolve/main/dev/eval_local.py
- Command line
-
hf download hf://da24b002athreyaganesh/enzymeretrieval/dev/eval_local.py
-
curl -L -o eval_local.py https://huggingface.co/da24b002athreyaganesh/enzymeretrieval/resolve/main/dev/eval_local.py
2.1 kB
| """Score a local validation split exactly the way the leaderboard will. | |
| Two ways in: | |
| python dev/eval_local.py --val dev/splits/random_val.parquet | |
| runs the packaged weights directly | |
| python dev/eval_local.py --val dev/splits/random_val.parquet \ | |
| --predictions output/predictions.jsonl | |
| scores a file your container already produced, which also checks that | |
| the container path and the local path agree | |
| """ | |
| import argparse | |
| import sys | |
| from pathlib import Path | |
| import pandas as pd | |
| ROOT = Path(__file__).resolve().parents[1] | |
| sys.path.insert(0, str(ROOT)) | |
| from metric import build_truth, load_predictions, report, score # noqa: E402 | |
| def constant_baseline(truth, frame): | |
| """The starter's model: always answer the most frequent EC.""" | |
| most_common = frame.ec_number.astype(str).str.strip().value_counts().idxmax() | |
| return {key: [most_common] for key in truth} | |
| def main(): | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument('--val', default=str(ROOT / 'dev' / 'splits' / 'random_val.parquet')) | |
| parser.add_argument('--weights', default=str(ROOT / 'weights')) | |
| parser.add_argument('--predictions') | |
| parser.add_argument('--alpha', type=float, help='override the blend weight') | |
| args = parser.parse_args() | |
| val = pd.read_parquet(args.val) | |
| truth, first_id = build_truth(val) | |
| print(f'{len(val)} rows -> {len(truth)} unique inputs') | |
| report(score(truth, constant_baseline(truth, val)), 'frequency baseline') | |
| if args.predictions: | |
| id_to_key = {rid: key for key, rid in first_id.items()} | |
| predictions = load_predictions(args.predictions, id_to_key) | |
| report(score(truth, predictions), Path(args.predictions).name) | |
| return | |
| from ecmodel import ECModel | |
| model = ECModel(args.weights) | |
| if args.alpha is not None: | |
| model.alpha = model.alpha_far = args.alpha | |
| keys = list(truth) | |
| predictions = dict(zip(keys, model.predict(keys))) | |
| report(score(truth, predictions), f'model alpha={model.alpha}') | |
| if __name__ == '__main__': | |
| main() | |