Spaces:
Running
Running
czjun
Update README and implement training and evaluation scripts for Chinese summarization model
8d28a45 Download data_utils.py from Czjun/Transformer: direct link, hf CLI and curl.
- Browser
- Download file 928 Bytes
-
https://huggingface.co/spaces/Czjun/Transformer/resolve/main/data_utils.py
- Command line
-
hf download hf://spaces/Czjun/Transformer/data_utils.py
-
curl -L -o data_utils.py https://huggingface.co/spaces/Czjun/Transformer/resolve/main/data_utils.py
928 Bytes
| from __future__ import annotations | |
| import json | |
| from dataclasses import dataclass | |
| from pathlib import Path | |
| from typing import Iterable, List | |
| class SummarizationExample: | |
| article: str | |
| summary: str | |
| def load_jsonl(path: str | Path) -> List[SummarizationExample]: | |
| path = Path(path) | |
| items: List[SummarizationExample] = [] | |
| with path.open("r", encoding="utf-8") as f: | |
| for line in f: | |
| line = line.strip() | |
| if not line: | |
| continue | |
| obj = json.loads(line) | |
| article = obj.get("article") or obj.get("text") or "" | |
| summary = obj.get("summary") or obj.get("label") or "" | |
| if article and summary: | |
| items.append(SummarizationExample(article=article, summary=summary)) | |
| return items | |
| def iter_pairs(examples: Iterable[SummarizationExample]): | |
| for ex in examples: | |
| yield ex.article, ex.summary | |