Download export_jsonl.py from ko120/MLE-World: direct link, hf CLI and curl.
- Browser
- Download file 1.78 kB
-
https://huggingface.co/datasets/ko120/MLE-World/resolve/main/export_jsonl.py
- Command line
-
hf download hf://datasets/ko120/MLE-World/export_jsonl.py
-
curl -L -o export_jsonl.py https://huggingface.co/datasets/ko120/MLE-World/resolve/main/export_jsonl.py
1.78 kB
| #!/usr/bin/env python3 | |
| """Restore LlamaFactory JSONL files from this downloaded dataset repository.""" | |
| import argparse | |
| import hashlib | |
| import json | |
| import shutil | |
| from pathlib import Path | |
| import pyarrow.parquet as pq | |
| def main(): | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument('--output-dir', type=Path, required=True) | |
| args = parser.parse_args() | |
| root = Path(__file__).resolve().parent | |
| provenance = json.loads((root / 'provenance.json').read_text()) | |
| args.output_dir.mkdir(parents=True, exist_ok=True) | |
| for split, filename in [('train', 'train.jsonl'), ('validation', 'holdout.sharegpt.jsonl')]: | |
| info = provenance['splits'][split] | |
| destination = args.output_dir / filename | |
| if destination.exists(): | |
| raise FileExistsError(destination) | |
| digest, count = hashlib.sha256(), 0 | |
| with destination.open('x', encoding='utf-8') as stream: | |
| for shard in info['shards']: | |
| for batch in pq.ParquetFile(root / shard['path']).iter_batches(batch_size=1000): | |
| for row in batch.to_pylist(): | |
| line = json.dumps(row, ensure_ascii=False, sort_keys=True, separators=(',', ':')) + '\n' | |
| stream.write(line) | |
| digest.update(line.encode()) | |
| count += 1 | |
| assert count == info['rows'] | |
| assert digest.hexdigest() == info['canonical_rows_sha256'] | |
| print(f'{filename}: {count} verified rows') | |
| shutil.copy2(root / 'llamafactory/dataset_info.json', args.output_dir / 'dataset_info.json') | |
| for name in ('exception_tokens.json', 'exception_tokens.yaml'): | |
| shutil.copy2(root / name, args.output_dir / name) | |
| if __name__ == '__main__': | |
| main() | |