Download train.py from Raghav06123/Firstsubda3410: direct link, hf CLI and curl.
- Browser
- Download file 1.37 kB
-
https://huggingface.co/Raghav06123/Firstsubda3410/resolve/main/train.py
- Command line
-
hf download hf://Raghav06123/Firstsubda3410/train.py
-
curl -L -o train.py https://huggingface.co/Raghav06123/Firstsubda3410/resolve/main/train.py
1.37 kB
| """Build the reference database: one row per unique training sequence with its ECs (most frequent first).""" | |
| import argparse | |
| import json | |
| from pathlib import Path | |
| import pandas as pd | |
| def build(train_path, output_path): | |
| root = Path(__file__).parent | |
| vocab = set(json.loads((root / 'ec_vocabulary.json').read_text())) | |
| frame = pd.read_parquet(train_path)[['sequence', 'ec_number']].dropna() | |
| bad = sorted(set(frame.ec_number) - vocab) | |
| if bad: | |
| raise ValueError(f'{len(bad)} training ECs not in vocabulary, e.g. {bad[:5]}') | |
| counts = frame.ec_number.value_counts() | |
| frame = frame.drop_duplicates() | |
| frame['n'] = frame.ec_number.map(counts) | |
| frame = frame.sort_values(['sequence', 'n', 'ec_number'], ascending=[True, False, True]) | |
| db = frame.groupby('sequence', sort=False).ec_number.agg(list).reset_index(name='ecs') | |
| Path(output_path).parent.mkdir(parents=True, exist_ok=True) | |
| db.to_parquet(output_path, index=False, compression='zstd') | |
| print(f'Wrote {len(db)} sequences, {frame.ec_number.nunique()} ECs to {output_path}') | |
| if __name__ == '__main__': | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument('--train', required=True) | |
| parser.add_argument('--output', default=str(Path(__file__).parent / 'weights/db.parquet')) | |
| args = parser.parse_args() | |
| build(args.train, args.output) | |