File size: 1,897 Bytes
736d46c | 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 | """Load the SCM-SQL dataset and print a few pairs from each level.
Two loading paths shown:
1. Native YAML — zero extra dependencies beyond PyYAML.
2. Hugging Face `datasets` — canonical for ML training / eval scripts.
Run:
python examples/load_dataset.py
"""
from __future__ import annotations
from collections import Counter
from pathlib import Path
def load_from_yaml() -> list[dict]:
"""Load directly from the shipped YAML file (no HF dependency)."""
import yaml
here = Path(__file__).resolve().parent.parent
data = yaml.safe_load((here / "data" / "pilot_500.yaml").read_text(encoding="utf-8"))
return data["pairs"]
def load_from_huggingface() -> list[dict]:
"""Load from the Hugging Face hub. Requires `pip install datasets`."""
from datasets import load_dataset # type: ignore
ds = load_dataset("AniruddhaAI/scm-sql", split="test")
return list(ds)
def summarise(pairs: list[dict]) -> None:
by_level = Counter(p["level"] for p in pairs)
print(f"Loaded {len(pairs)} pairs")
print(f"By level: {dict(sorted(by_level.items()))}")
n_multi = sum(1 for p in pairs if p.get("turns"))
print(f"Multi-turn dialogues: {n_multi}")
print("\nFirst pair at each level:")
seen: set[int] = set()
for p in pairs:
lvl = p["level"]
if lvl in seen:
continue
seen.add(lvl)
print(f"\n--- L{lvl} · {p['id']} · domains={p['domains']} ---")
if "turns" in p:
for i, t in enumerate(p["turns"], 1):
print(f" Turn {i} NL : {t['nl']}")
print(f" SQL: {t['gold_sql'].strip()[:120]}...")
else:
print(f" NL : {p['nl']}")
print(f" SQL: {p['gold_sql'].strip()[:120]}...")
if len(seen) == 6:
break
if __name__ == "__main__":
pairs = load_from_yaml()
summarise(pairs)
|