Datasets:
Download scripts/build.py from Lilambd/empire-eval: direct link, hf CLI and curl.
- Browser
- Download file 3.48 kB
-
https://huggingface.co/datasets/Lilambd/empire-eval/resolve/main/scripts/build.py
- Command line
-
hf download hf://datasets/Lilambd/empire-eval/scripts/build.py
-
curl -L -o build.py https://huggingface.co/datasets/Lilambd/empire-eval/resolve/main/scripts/build.py
3.48 kB
| """Build Lilambd Empire Eval question sets. | |
| usage: python build.py --data-root ROOTS.json --out OUT_DIR [--only name,name] | |
| ROOTS.json maps dataset short name -> local folder holding that dataset's files | |
| (same relative paths as on the Hugging Face repo). | |
| """ | |
| import argparse, collections, importlib, json, os, sys, time | |
| sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) | |
| from evallib import Builder, Store, sha256, write_jsonl | |
| MODULES = { | |
| 'world-hazard': 'ds_hazard', | |
| 'world-earth': 'ds_earth', | |
| 'world-ground': 'ds_ground', | |
| 'world-prices': 'ds_prices', | |
| 'world-science': 'ds_science', | |
| 'world-marketplaces': 'ds_marketplaces', | |
| 'world-sound': 'ds_sound', | |
| 'world-signals': 'ds_signals', | |
| 'world-seeds': 'ds_rest:seeds', | |
| 'japan-dpc-hospitals': 'ds_rest:dpc', | |
| 'japan-prefecture-facts': 'ds_rest:prefecture', | |
| 'world-biodiversity-cells': 'ds_rest:biodiversity', | |
| 'machine-economy-daily': 'ds_rest:machine_economy', | |
| 'security-daily': 'ds_security', | |
| 'world-pulse-daily': 'ds_pulse', | |
| 'world-markets': 'ds_rest:markets', | |
| } | |
| def load_module(name): | |
| spec = MODULES.get(name) or ('ds_worlds' if name.startswith('worlds-') else None) | |
| mod, _, attr = spec.partition(':') | |
| m = importlib.import_module(mod) | |
| return getattr(m, attr) if attr else m | |
| def main(): | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument('--data-root', required=True) | |
| ap.add_argument('--out', required=True) | |
| ap.add_argument('--only', default='') | |
| a = ap.parse_args() | |
| roots = json.load(open(a.data_root)) | |
| only = [x for x in a.only.split(',') if x] | |
| os.makedirs(os.path.join(a.out, 'data'), exist_ok=True) | |
| manifest_path = os.path.join(a.out, 'manifest.json') | |
| manifest = json.load(open(manifest_path)) if os.path.exists(manifest_path) else {'datasets': {}} | |
| for name, root in roots.items(): | |
| if only and name not in only: | |
| continue | |
| if name not in MODULES and not name.startswith('worlds-'): | |
| print('skip (no module)', name) | |
| continue | |
| t0 = time.time() | |
| m = load_module(name) | |
| if hasattr(m, 'setup'): | |
| m.setup(root) | |
| store = Store(root, getattr(m, 'STR', {})) | |
| rp = os.path.join(root, '_revision.json') | |
| rev = json.load(open(rp)).get('revision') if os.path.exists(rp) else getattr(m, 'REVISION', None) | |
| B = Builder(m.DS, store, m.KEYS, rev) | |
| m.build(B) | |
| if hasattr(m, 'import_original'): | |
| m.import_original(B, root) | |
| files = {} | |
| for f in sorted(store.files()): | |
| p = os.path.join(root, f) | |
| files[f] = {'sha256': sha256(p), 'bytes': os.path.getsize(p), 'rows': int(len(store[f]))} | |
| for it in B.items: | |
| it['revision'] = rev | |
| write_jsonl(B.items, os.path.join(a.out, 'data', f'{name}.jsonl')) | |
| c = collections.Counter(it['task'] for it in B.items) | |
| manifest['datasets'][name] = {'hf_repo': m.DS, 'revision': rev, 'n_questions': len(B.items), 'tasks': dict(c), 'files': files, | |
| 'license': getattr(m, 'LICENSE', None)} | |
| print(f'{name}: {len(B.items)} q {dict(c)} in {time.time() - t0:.1f}s; skipped {sum(B.fail.values())} {dict(list(B.fail.items())[:6])}') | |
| json.dump(manifest, open(manifest_path, 'w'), indent=1, ensure_ascii=False) | |
| if __name__ == '__main__': | |
| main() | |