Datasets:

Modalities:
Text
Formats:
parquet
Languages:
Slovak
ArXiv:
License:
File size: 2,541 Bytes
3410778
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 script for mteb/SlovakSumURLClustering.

This dataset is the MTEB-ready (clustering) version of the SlovakSum dataset,
used by the `SlovakSumURLClustering` task in
https://github.com/embeddings-benchmark/mteb.

Source: kiviki/slovaksum-url-clustering (columns: title, sum, theme)
  https://huggingface.co/datasets/kiviki/slovaksum-url-clustering
Transform: combine `title` + `sum` into a single `sentences` field, and rename
  `theme` to `labels` -- the schema MTEB's AbsTaskClustering expects.

If the source dataset publishes a new revision, regenerate this dataset with:
    python build_dataset.py --source-revision <new-sha> --token $HF_TOKEN

then update the `SlovakSumURLClustering` task's `dataset.path`/`revision` in mteb
to the new revision this script prints on push.
"""

from __future__ import annotations

import argparse

from datasets import Dataset, DatasetDict, load_dataset
from huggingface_hub import HfApi

SOURCE_REPO = "kiviki/slovaksum-url-clustering"
SOURCE_REVISION = "6ac67c0a18a641c611c49224a82012cd749000e2"
TARGET_REPO = "mteb/SlovakSumURLClustering"


def build(source_revision: str = SOURCE_REVISION) -> DatasetDict:
    raw = load_dataset(SOURCE_REPO, revision=source_revision)
    ds = {}
    for split in raw:
        titles = raw[split]["title"]
        summaries = raw[split]["sum"]
        sentences = [f"{t} {s}".strip() for t, s in zip(titles, summaries)]
        labels = raw[split]["theme"]
        ds[split] = Dataset.from_dict({"sentences": sentences, "labels": labels})
    return DatasetDict(ds)


def main() -> None:
    p = argparse.ArgumentParser(description=__doc__)
    p.add_argument("--source-revision", default=SOURCE_REVISION)
    p.add_argument("--repo", default=TARGET_REPO)
    p.add_argument("--token", default=None, help="HF token (or use HF_TOKEN env / `huggingface-cli login`).")
    p.add_argument("--private", action="store_true")
    p.add_argument("--dry-run", action="store_true")
    args = p.parse_args()

    ds = build(args.source_revision)
    for split, d in ds.items():
        print(f"  split={split} rows={len(d)} columns={d.column_names}")

    if args.dry_run:
        print(f"[dry-run] would push to {args.repo}")
        return

    ds.push_to_hub(
        args.repo,
        commit_message="Rebuild from source revision",
        token=args.token,
        private=args.private,
    )
    revision = HfApi(token=args.token).dataset_info(args.repo).sha
    print(f"-> pushed to {args.repo}, revision={revision}")


if __name__ == "__main__":
    main()