Download python_lora_dataset_builder/pipeline/dataset_writer.py from api-relay/sadASDasd: direct link, hf CLI and curl.
- Browser
- Download file 1.39 kB
-
https://huggingface.co/datasets/api-relay/sadASDasd/resolve/main/python_lora_dataset_builder/pipeline/dataset_writer.py
- Command line
-
hf download hf://datasets/api-relay/sadASDasd/python_lora_dataset_builder/pipeline/dataset_writer.py
-
curl -L -o dataset_writer.py https://huggingface.co/datasets/api-relay/sadASDasd/resolve/main/python_lora_dataset_builder/pipeline/dataset_writer.py
1.39 kB
| from __future__ import annotations | |
| import json | |
| from pathlib import Path | |
| from .utils import append_jsonl | |
| _DECISION_DIRS = { | |
| "include": "accepted", | |
| "manual_review": "manual_review", | |
| "reject": "rejected", | |
| "skip": "skipped", | |
| "retry": "retry", | |
| } | |
| class DatasetWriter: | |
| def __init__(self, output_dir: Path): | |
| self.output_dir = output_dir | |
| def write(self, decision: str, record: dict, tier: str | None = None, | |
| tier_library: str | None = None) -> Path: | |
| """Write a record under data/<tier>/[<library>/]<decision>/records.jsonl. | |
| `tier` defaults to record["tier"] if not passed explicitly, then to | |
| "unclassified" for records that never made it far enough to be | |
| classified (e.g. empty source rows). | |
| """ | |
| tier = tier or record.get("tier") or "unclassified" | |
| parts = [tier] | |
| if tier_library: | |
| parts.append(tier_library) | |
| parts.append(_DECISION_DIRS[decision]) | |
| path = self.output_dir.joinpath(*parts) / "records.jsonl" | |
| append_jsonl(path, record) | |
| return path | |
| def write_raw_nim(self, record_id: str, raw: dict) -> Path: | |
| path = self.output_dir / "nim_raw" / f"{record_id}.json" | |
| path.parent.mkdir(parents=True, exist_ok=True) | |
| path.write_text(json.dumps(raw, ensure_ascii=False, indent=2), encoding="utf-8") | |
| return path | |