File size: 1,611 Bytes
6dfa658
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Build a 150-question evaluation set from HuggingFace Turkish legal QA data.

Output format (JSONL):
{
  "question": "...",
  "gold_answer": "...",
  "source_id": "HF_test_123"
}
"""

from __future__ import annotations

import json
from pathlib import Path

from datasets import load_dataset


def norm(text: str) -> str:
    return " ".join(str(text).split()).strip()


def build_eval_set(output_path: Path, target_size: int = 150) -> int:
    ds = load_dataset("Renicames/turkish-law-chatbot")
    rows = []

    # Held-out split for evaluation (do not index these rows in ``corpus_index.jsonl``).
    split_name = "test"
    if split_name not in ds:
        raise RuntimeError("Expected split 'test' in Renicames/turkish-law-chatbot")

    split = ds[split_name]
    for idx, row in enumerate(split):
        q = norm(row.get("Soru", ""))
        a = norm(row.get("Cevap", ""))
        if not q or not a:
            continue
        rows.append(
            {
                "question": q,
                "gold_answer": a,
                "source_id": f"HF_{split_name}_{idx}",
            }
        )
        if len(rows) >= target_size:
            break

    output_path.parent.mkdir(parents=True, exist_ok=True)
    with output_path.open("w", encoding="utf-8") as f:
        for item in rows:
            f.write(json.dumps(item, ensure_ascii=False) + "\n")
    return len(rows)


if __name__ == "__main__":
    root = Path(__file__).resolve().parent.parent
    out = root / "data" / "eval_qa_150.jsonl"
    n = build_eval_set(out, target_size=150)
    print(f"[EvalSet] Wrote {n} items -> {out}")