Download scripts/merge_plus_shards.py from SocrAIte-Mosaic/patientphex-task1: direct link, hf CLI and curl.
- Browser
- Download file 843 Bytes
-
https://huggingface.co/SocrAIte-Mosaic/patientphex-task1/resolve/main/scripts/merge_plus_shards.py
- Command line
-
hf download hf://SocrAIte-Mosaic/patientphex-task1/scripts/merge_plus_shards.py
-
curl -L -o merge_plus_shards.py https://huggingface.co/SocrAIte-Mosaic/patientphex-task1/resolve/main/scripts/merge_plus_shards.py
843 Bytes
| import json | |
| import sys | |
| from pathlib import Path | |
| base = Path(sys.argv[1]) | |
| order_file = Path(sys.argv[2]) | |
| out = Path(sys.argv[3]) | |
| pos = {} | |
| for i, line in enumerate(order_file.read_text(encoding='utf-8').splitlines()): | |
| if line.strip(): | |
| pos[str(json.loads(line)['pmc_id'])] = i | |
| rows = [] | |
| for i in range(2): | |
| p = base / ('shard%d/predictions-longest_abbr.jsonl' % i) | |
| for line in p.read_text(encoding='utf-8').splitlines(): | |
| if line.strip(): | |
| rows.append(json.loads(line)) | |
| rows.sort(key=lambda r: pos.get(str(r['pmc_id']), 1 << 30)) | |
| out.parent.mkdir(parents=True, exist_ok=True) | |
| with out.open('w', encoding='utf-8', newline='\n') as f: | |
| for r in rows: | |
| f.write(json.dumps(r, ensure_ascii=False) + '\n') | |
| ents = sum(len(r.get('entities', [])) for r in rows) | |
| print('docs:', len(rows), 'entities:', ents) | |