Download dev/explore.py from da24b002athreyaganesh/enzymeretrieval: direct link, hf CLI and curl.
- Browser
- Download file 2.67 kB
-
https://huggingface.co/da24b002athreyaganesh/enzymeretrieval/resolve/main/dev/explore.py
- Command line
-
hf download hf://da24b002athreyaganesh/enzymeretrieval/dev/explore.py
-
curl -L -o explore.py https://huggingface.co/da24b002athreyaganesh/enzymeretrieval/resolve/main/dev/explore.py
2.67 kB
| """Inspect the public data before training anything. | |
| Run: python dev/explore.py (expects ../data next to model/) | |
| python dev/explore.py /path/to/data | |
| """ | |
| import sys | |
| from collections import Counter | |
| from pathlib import Path | |
| import pandas as pd | |
| ROOT = Path(__file__).resolve().parents[1] | |
| DATA = Path(sys.argv[1]) if len(sys.argv) > 1 else ROOT.parent / 'data' | |
| def describe(path): | |
| frame = pd.read_parquet(path) | |
| print(f'=== {path.name} rows={len(frame)} columns={list(frame.columns)}') | |
| with pd.option_context('display.width', 200, 'display.max_colwidth', 90): | |
| print(frame.head(3).to_string()) | |
| print() | |
| return frame | |
| def main(): | |
| frames = {path.name: describe(path) for path in sorted(DATA.glob('*.parquet'))} | |
| if not frames: | |
| raise SystemExit(f'No parquet files under {DATA}') | |
| train = next((f for n, f in frames.items() if 'ec_number' in f.columns), None) | |
| if train is None: | |
| raise SystemExit('No frame carries an ec_number column; check the data directory.') | |
| print('=== label statistics') | |
| ecs = train.ec_number.astype(str).str.strip() | |
| print(f'pairs {len(train)}') | |
| print(f'distinct ECs {ecs.nunique()}') | |
| print(f'distinct reactions {train.rxn_smiles.nunique()}') | |
| malformed = ecs[ecs.str.count(r'\.') != 3] | |
| print(f'ECs not 4-part {len(malformed)} {sorted(set(malformed))[:5]}') | |
| per_rxn = train.groupby('rxn_smiles').ec_number.nunique() | |
| print(f'reactions with >1 EC {(per_rxn > 1).sum()} (max {per_rxn.max()})') | |
| print(f'mean ECs per reaction {per_rxn.mean():.3f}') | |
| counts = Counter(ecs) | |
| print(f'most common EC {counts.most_common(1)[0]}') | |
| singletons = sum(1 for v in counts.values() if v == 1) | |
| print(f'ECs seen exactly once {singletons}') | |
| print(f'EC1 spread {dict(Counter(e.split(".")[0] for e in ecs).most_common())}') | |
| print() | |
| print('=== leakage check against validation inputs') | |
| val = next((f for n, f in frames.items() if 'val' in n and 'ec_number' not in f.columns), None) | |
| if val is None: | |
| print('no validation input frame found') | |
| return | |
| train_rxn = set(train.rxn_smiles) | |
| hits = val.rxn_smiles.isin(train_rxn).sum() | |
| print(f'val rows {len(val)}') | |
| print(f'unique val reactions {val.rxn_smiles.nunique()}') | |
| print(f'val reactions seen in train {hits} ({hits / len(val):.1%})') | |
| print() | |
| print('A high overlap means a lookup table scores well and the split is easy.') | |
| print('A low overlap means you must generalise; weight your local split the same way.') | |
| if __name__ == '__main__': | |
| main() | |