Download code/builder/v1_seen.py from wchai/prophet-v2: direct link, hf CLI and curl.
- Browser
- Download file 1.18 kB
-
https://huggingface.co/datasets/wchai/prophet-v2/resolve/main/code/builder/v1_seen.py
- Command line
-
hf download hf://datasets/wchai/prophet-v2/code/builder/v1_seen.py
-
curl -L -o v1_seen.py https://huggingface.co/datasets/wchai/prophet-v2/resolve/main/code/builder/v1_seen.py
1.18 kB
| """Read the released v1 shards (data/tasks/*.tar.zst) as a stream and record, per v1 task, the submission indices | |
| that submissions.json marks 'seen'. Out: out_v49/work/v1_seen.json (task_id -> [indices]).""" | |
| import glob, json, os, sys, tarfile | |
| from multiprocessing import Pool | |
| import zstandard | |
| V = '<ROOT>/' | |
| OUT = V + 'build_v2/out_v49/work/v1_seen.json' | |
| def one(path): | |
| out = {} | |
| with open(path, 'rb') as f: | |
| r = zstandard.ZstdDecompressor().stream_reader(f) | |
| with tarfile.open(fileobj=r, mode='r|') as t: | |
| for m in t: | |
| if m.isfile() and m.name.endswith('/environment/context/submissions.json'): | |
| subs = json.loads(t.extractfile(m).read()) | |
| out[m.name.split('/')[0]] = [s['index'] for s in subs if s.get('result') == 'seen'] | |
| return out | |
| if __name__ == '__main__': | |
| os.makedirs(os.path.dirname(OUT), exist_ok=True) | |
| allr = {} | |
| with Pool(int(sys.argv[1]) if len(sys.argv) > 1 else 4) as p: | |
| for d in p.imap_unordered(one, sorted(glob.glob(V + 'data/tasks/*.tar.zst'))): | |
| allr.update(d) | |
| json.dump(allr, open(OUT, 'w')) | |
| print('v1 tasks read', len(allr)) | |