Datasets:

Modalities:
Text
Formats:
parquet
Languages:
Slovak
ArXiv:
License:
andrejridzik commited on
Commit
620c09a
·
verified ·
1 Parent(s): 7cf0d9a

Upload build_dataset.py

Browse files
Files changed (1) hide show
  1. build_dataset.py +68 -0
build_dataset.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Build script for mteb/SlovakSTS.
2
+
3
+ This dataset is the MTEB-ready (STS) version of the sklep STS benchmark, used by
4
+ the `SlovakSTS` task in https://github.com/embeddings-benchmark/mteb.
5
+
6
+ Source: slovak-nlp/sklep, config "sts" (columns include: sentence1, sentence2,
7
+ similarity_score, plus sentence1_orig/sentence2_orig which MTEB does not use)
8
+ https://huggingface.co/datasets/slovak-nlp/sklep
9
+ Transform: rename `similarity_score` -> `score` (cast to float), and select only
10
+ `sentence1`/`sentence2`/`score` -- the schema MTEB's AbsTaskSTS expects.
11
+
12
+ If the source dataset publishes a new revision, regenerate this dataset with:
13
+ python build_dataset.py --source-revision <new-sha> --token $HF_TOKEN
14
+
15
+ then update the `SlovakSTS` task's `dataset.path`/`revision` in mteb to the new
16
+ revision this script prints on push.
17
+ """
18
+
19
+ from __future__ import annotations
20
+
21
+ import argparse
22
+
23
+ from datasets import DatasetDict, load_dataset
24
+ from huggingface_hub import HfApi
25
+
26
+ SOURCE_REPO = "slovak-nlp/sklep"
27
+ SOURCE_CONFIG = "sts"
28
+ SOURCE_REVISION = "10549a8c63542e6a0db4fcf5fcdc29b3e1b8c4e9"
29
+ TARGET_REPO = "mteb/SlovakSTS"
30
+
31
+
32
+ def build(source_revision: str = SOURCE_REVISION) -> DatasetDict:
33
+ raw = load_dataset(SOURCE_REPO, SOURCE_CONFIG, revision=source_revision)
34
+ ds = raw.rename_columns({"similarity_score": "score"})
35
+ ds = ds.map(lambda example: {"score": float(example["score"])})
36
+ ds = ds.select_columns(["sentence1", "sentence2", "score"])
37
+ return ds
38
+
39
+
40
+ def main() -> None:
41
+ p = argparse.ArgumentParser(description=__doc__)
42
+ p.add_argument("--source-revision", default=SOURCE_REVISION)
43
+ p.add_argument("--repo", default=TARGET_REPO)
44
+ p.add_argument("--token", default=None, help="HF token (or use HF_TOKEN env / `huggingface-cli login`).")
45
+ p.add_argument("--private", action="store_true")
46
+ p.add_argument("--dry-run", action="store_true")
47
+ args = p.parse_args()
48
+
49
+ ds = build(args.source_revision)
50
+ for split, d in ds.items():
51
+ print(f" split={split} rows={len(d)} columns={d.column_names}")
52
+
53
+ if args.dry_run:
54
+ print(f"[dry-run] would push to {args.repo}")
55
+ return
56
+
57
+ ds.push_to_hub(
58
+ args.repo,
59
+ commit_message="Rebuild from source revision",
60
+ token=args.token,
61
+ private=args.private,
62
+ )
63
+ revision = HfApi(token=args.token).dataset_info(args.repo).sha
64
+ print(f"-> pushed to {args.repo}, revision={revision}")
65
+
66
+
67
+ if __name__ == "__main__":
68
+ main()