| """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 |
| 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) |
|
|