File size: 897 Bytes
0109502
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from __future__ import annotations
from datasets import load_dataset

def stream_hf_dataset(name: str, split: str = "train"):
    """Stream records so the first test does not download the full dataset."""
    return load_dataset(name, split=split, streaming=True)

def normalize_source_row(row: dict, source_name: str, row_index: int,
                         instruction_field: str = "instruction",
                         input_field: str = "input",
                         output_field: str = "output") -> dict:
    return {
        "record_id": f"{source_name.replace('/', '__')}__{row_index:08d}",
        "source": {"dataset": source_name, "row": row_index},
        "instruction": str(row.get(instruction_field, "") or "").strip(),
        "input": str(row.get(input_field, "") or "").strip(),
        "output": str(row.get(output_field, "") or "").strip(),
        "raw_row": row,
    }