Datasets:
Download code/examples/load_data.py from microsoft/XL-DocBench: direct link, hf CLI and curl.
- Browser
- Download file 1.17 kB
-
https://huggingface.co/datasets/microsoft/XL-DocBench/resolve/main/code/examples/load_data.py
- Command line
-
hf download hf://datasets/microsoft/XL-DocBench/code/examples/load_data.py
-
curl -L -o load_data.py https://huggingface.co/datasets/microsoft/XL-DocBench/resolve/main/code/examples/load_data.py
1.17 kB
| #!/usr/bin/env python3 | |
| """Load XL-DocBench JSONL files with the Python standard library.""" | |
| from __future__ import annotations | |
| import argparse | |
| import json | |
| from pathlib import Path | |
| def parse_args() -> argparse.Namespace: | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument( | |
| "--release-root", | |
| type=Path, | |
| default=Path(__file__).resolve().parents[2], | |
| help="Release directory; defaults to the directory containing code/", | |
| ) | |
| return parser.parse_args() | |
| def read_jsonl(path: Path) -> list[dict]: | |
| with path.open("r", encoding="utf-8") as handle: | |
| return [json.loads(line) for line in handle if line.strip()] | |
| def main() -> None: | |
| root = parse_args().release_root.resolve() | |
| documents = read_jsonl(root / "data/documents.jsonl") | |
| single_doc = read_jsonl(root / "data/qa_single_doc.jsonl") | |
| cross_doc = read_jsonl(root / "data/qa_cross_doc.jsonl") | |
| print(f"documents: {len(documents):,}") | |
| print(f"single_doc: {len(single_doc):,}") | |
| print(f"cross_doc: {len(cross_doc):,}") | |
| print(f"first question: {single_doc[0]['question']}") | |
| if __name__ == "__main__": | |
| main() | |