Rom89823974978's picture
Drafting some parts
8521f60
raw
history blame contribute delete
551 Bytes
"""I/O utilities (e.g., dataset loading, model caching)."""
from pathlib import Path
from typing import List, Dict, Any, Iterable
import json
def read_jsonl(path: Path) -> List[Dict[str, Any]]:
"""Read a JSON Lines file into a list of dicts."""
with path.open() as f:
return [json.loads(line) for line in f]
def write_jsonl(path: Path, rows: Iterable[Dict[str, Any]]) -> None:
"""Write a list/iterable of dicts as JSON Lines."""
with path.open("w") as f:
for row in rows:
f.write(json.dumps(row) + "\n")