Datasets:

Modalities:
Text
Formats:
parquet
Languages:
Slovak
ArXiv:
License:
File size: 2,453 Bytes
620c09a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Build script for mteb/SlovakSTS.

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

Source: slovak-nlp/sklep, config "sts" (columns include: sentence1, sentence2,
  similarity_score, plus sentence1_orig/sentence2_orig which MTEB does not use)
  https://huggingface.co/datasets/slovak-nlp/sklep
Transform: rename `similarity_score` -> `score` (cast to float), and select only
  `sentence1`/`sentence2`/`score` -- the schema MTEB's AbsTaskSTS 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 `SlovakSTS` 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 DatasetDict, load_dataset
from huggingface_hub import HfApi

SOURCE_REPO = "slovak-nlp/sklep"
SOURCE_CONFIG = "sts"
SOURCE_REVISION = "10549a8c63542e6a0db4fcf5fcdc29b3e1b8c4e9"
TARGET_REPO = "mteb/SlovakSTS"


def build(source_revision: str = SOURCE_REVISION) -> DatasetDict:
    raw = load_dataset(SOURCE_REPO, SOURCE_CONFIG, revision=source_revision)
    ds = raw.rename_columns({"similarity_score": "score"})
    ds = ds.map(lambda example: {"score": float(example["score"])})
    ds = ds.select_columns(["sentence1", "sentence2", "score"])
    return 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()