File size: 1,172 Bytes
72954bd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/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()