File size: 2,566 Bytes
03859b9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""Loading examples for CodeMixCheck with the Hugging Face `datasets` library.

    python scripts/load_dataset.py                       # load from this local folder
    python scripts/load_dataset.py --repo <user>/CodeMixCheck   # load from the Hub (after upload)

For a private or gated Hub repo, log in first (`huggingface-cli login`) and accept
the access conditions on the dataset page.
"""
from __future__ import annotations

import argparse
from collections import Counter
from pathlib import Path

from datasets import load_dataset

LOCAL = str(Path(__file__).resolve().parents[1])


def main():
    ap = argparse.ArgumentParser()
    ap.add_argument("--repo", default=LOCAL, help="Hub repo id or local path (default: this folder)")
    repo = ap.parse_args().repo

    # 1. Load each configuration (all splits)
    fv = load_dataset(repo, "fact_verification")
    sent = load_dataset(repo, "sentiment")
    abuse = load_dataset(repo, "abuse_detection")
    for name, ds in [("fact_verification", fv), ("sentiment", sent), ("abuse_detection", abuse)]:
        print(name, {k: v.num_rows for k, v in ds.items()})

    # 2. Load an individual split
    train = load_dataset(repo, "fact_verification", split="train")
    print("fact_verification/train:", train.num_rows, "rows")

    # 3. Access records
    rec = train[0]
    print({k: rec[k] for k in ("id", "text", "label", "label_3way", "evidence_explanation", "provenance_class")})

    # 4. Inspect labels
    print("train labels:", Counter(train["label"]))
    print("label origins:", Counter(train["label_origin"]))

    # 5. Synthetic test vs curated test (never merge them when reporting results)
    test_syn = load_dataset(repo, "fact_verification", split="test_synthetic")
    print("test_synthetic:", test_syn.num_rows)
    if "test_curated" in fv:
        cur = fv["test_curated"]
        for subset in sorted(set(cur["eval_subset"])):
            part = cur.filter(lambda r, s=subset: r["eval_subset"] == s)
            print("test_curated /", subset, part.num_rows, Counter(part["label"]))
    else:
        print("test_curated is not available in this copy.")

    # 6. Optional: drop rows flagged for cross-split overlap to get a stricter evaluation
    strict = test_syn.filter(lambda r: not ({"D01", "D02"} & set(r["audit_flags"])))
    print("test_synthetic without cross-split near-duplicate / same-claim rows:", strict.num_rows)

    # 7. Reproduce the statistics in README.md
    #    python scripts/dataset_statistics.py


if __name__ == "__main__":
    main()