File size: 3,218 Bytes
3847bc1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env python3
"""Join this release with your own CiteVQA download to get runnable records.

This dataset ships identifiers, our verification metadata, and our normalised
ground-truth boxes. It deliberately does not redistribute the benchmark's
question text, answers, or PDFs. Download those from the original CiteVQA
release, then run this script to produce the record format the pipeline reads.

    python rehydrate.py \
        --release verified_eval_set.jsonl \
        --citevqa /path/to/CiteVQA/data/validation/CiteVQA.json \
        --pdf-dir /path/to/CiteVQA/data/pdf \
        --out citevqa_singledoc_pub.jsonl

The output is exactly what `src/build_citevqa_pub.py` in the code repository
produces, so every downstream script runs unchanged:

    https://github.com/Ryenhails/quote-and-retrieve
"""
import argparse
import json
import os
import sys


def main():
    ap = argparse.ArgumentParser()
    ap.add_argument("--release", default="verified_eval_set.jsonl")
    ap.add_argument("--citevqa", required=True,
                    help="path to the CiteVQA validation JSON from the original release")
    ap.add_argument("--pdf-dir", required=True,
                    help="directory holding the source PDFs")
    ap.add_argument("--out", default="citevqa_singledoc_pub.jsonl")
    args = ap.parse_args()

    release = [json.loads(line) for line in open(args.release)]
    print(f"release records: {len(release)}")

    raw = json.load(open(args.citevqa))
    if isinstance(raw, dict):
        raw = raw.get("data") or next(v for v in raw.values() if isinstance(v, list))
    by_index = {}
    for item in raw:
        idx = item.get("index") or item.get("id") or item.get("question_id")
        if idx is not None:
            by_index[str(idx)] = item
    print(f"benchmark records loaded: {len(by_index)}")

    out, missing_q, missing_pdf = [], 0, 0
    for r in release:
        src = by_index.get(r["index"])
        if src is None:
            missing_q += 1
            continue
        pdf = os.path.join(args.pdf_dir, r["pdf_stem"] + ".pdf")
        if not os.path.exists(pdf):
            missing_pdf += 1
            continue
        out.append({
            "index": r["index"],
            "question": src.get("question") or src.get("Question"),
            "standard_answer": src.get("answer") or src.get("standard_answer"),
            "language": r["language"],
            "qtype": r["qtype"],
            "n_pdf_pages": r["n_pdf_pages"],
            "alignment": r["alignment"],
            "pdf_path": pdf,
            "gt_pages": r["gt_pages"],
            "gt_necessary": r["gt_necessary"],
            "gt_all": r["gt_all"],
        })

    with open(args.out, "w") as f:
        for d in out:
            f.write(json.dumps(d, ensure_ascii=False) + "\n")

    print(f"wrote {len(out)} records -> {args.out}")
    if missing_q:
        print(f"  {missing_q} identifiers not found in the benchmark file")
    if missing_pdf:
        print(f"  {missing_pdf} source PDFs not found in {args.pdf_dir}")
    if len(out) != len(release):
        print("  note: the paper's numbers assume all 719 records are present")
        sys.exit(1)


if __name__ == "__main__":
    main()