File size: 2,485 Bytes
f45e98c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
62
63
64
65
66
67
68
69
70
71
72
"""Build an eval dataset from DEplain-web-doc (German plain-language doc pairs).

DEplain-web-doc (Stodden et al., ACL 2023) is openly loadable from HuggingFace with no
auth. Each row has an `original` (complex) and a `simplification` (Einfache/Leichte
Sprache) German document, plus CEFR levels and a `corpus` (subcorpus) tag we keep for
register filtering.

We map to the repo's eval-dataset schema ({title, original, human_translated}) and keep
`corpus`/`complex_level`/`simple_level` as extra metadata. This materializes the human original/simplified pairs only.

Run:
    python -m data_process.deplain_web
"""

from __future__ import annotations

import json
from pathlib import Path

HF_DATASET = "DEplain/DEplain-web-doc"
SPLITS = ("train", "validation", "test")


def create_deplain_web_json(splits: tuple[str, ...] = SPLITS) -> int:
    """Load DEplain-web-doc (all splits by default) and write the eval dataset.
    Returns the number of records written.
    """
    from datasets import load_dataset

    out_path = Path("data/deplain_web.json")
    data: list[dict] = []
    for split in splits:
        ds = load_dataset(HF_DATASET, split=split)
        for i, row in enumerate(ds):
            original = (row.get("original") or "").strip()
            simplified = (row.get("simplification") or "").strip()
            if not original or not simplified:
                continue
            corpus = row.get("corpus", "")
            data.append(
                {
                    "title": f"{corpus}:{split}:{i}",
                    "original": original,
                    "human_translated": simplified,
                    "corpus": corpus,
                    "complex_level": row.get("complex_level"),
                    "simple_level": row.get("simple_level"),
                    "split": split,
                }
            )

    if not data:
        print("No DEplain-web records assembled - check dataset access.")
        return 0

    out_path.parent.mkdir(parents=True, exist_ok=True)
    out_path.write_text(
        json.dumps(data, ensure_ascii=False, indent=2), encoding="utf-8"
    )
    by_corpus: dict[str, int] = {}
    for d in data:
        by_corpus[d["corpus"]] = by_corpus.get(d["corpus"], 0) + 1
    print(f"Wrote {len(data)} pairs to {out_path}")
    print(
        "By subcorpus: " + ", ".join(f"{k}={v}" for k, v in sorted(by_corpus.items()))
    )
    return len(data)


if __name__ == "__main__":
    create_deplain_web_json()