CodeMixCheck / scripts /load_dataset.py
Prajjit's picture
CodeMixCheck v2.2.1
03859b9 verified
Raw History Blame
2.57 kB
#!/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()