Datasets:

Modalities:
Text
Formats:
parquet
Languages:
Slovak
ArXiv:
License:
andrejridzik commited on
Commit
3410778
·
verified ·
1 Parent(s): 78be19a

Upload build_dataset.py

Browse files
Files changed (1) hide show
  1. build_dataset.py +71 -0
build_dataset.py ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Build script for mteb/SlovakSumURLClustering.
2
+
3
+ This dataset is the MTEB-ready (clustering) version of the SlovakSum dataset,
4
+ used by the `SlovakSumURLClustering` task in
5
+ https://github.com/embeddings-benchmark/mteb.
6
+
7
+ Source: kiviki/slovaksum-url-clustering (columns: title, sum, theme)
8
+ https://huggingface.co/datasets/kiviki/slovaksum-url-clustering
9
+ Transform: combine `title` + `sum` into a single `sentences` field, and rename
10
+ `theme` to `labels` -- the schema MTEB's AbsTaskClustering 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 `SlovakSumURLClustering` task's `dataset.path`/`revision` in mteb
16
+ to the new revision this script prints on push.
17
+ """
18
+
19
+ from __future__ import annotations
20
+
21
+ import argparse
22
+
23
+ from datasets import Dataset, DatasetDict, load_dataset
24
+ from huggingface_hub import HfApi
25
+
26
+ SOURCE_REPO = "kiviki/slovaksum-url-clustering"
27
+ SOURCE_REVISION = "6ac67c0a18a641c611c49224a82012cd749000e2"
28
+ TARGET_REPO = "mteb/SlovakSumURLClustering"
29
+
30
+
31
+ def build(source_revision: str = SOURCE_REVISION) -> DatasetDict:
32
+ raw = load_dataset(SOURCE_REPO, revision=source_revision)
33
+ ds = {}
34
+ for split in raw:
35
+ titles = raw[split]["title"]
36
+ summaries = raw[split]["sum"]
37
+ sentences = [f"{t} {s}".strip() for t, s in zip(titles, summaries)]
38
+ labels = raw[split]["theme"]
39
+ ds[split] = Dataset.from_dict({"sentences": sentences, "labels": labels})
40
+ return DatasetDict(ds)
41
+
42
+
43
+ def main() -> None:
44
+ p = argparse.ArgumentParser(description=__doc__)
45
+ p.add_argument("--source-revision", default=SOURCE_REVISION)
46
+ p.add_argument("--repo", default=TARGET_REPO)
47
+ p.add_argument("--token", default=None, help="HF token (or use HF_TOKEN env / `huggingface-cli login`).")
48
+ p.add_argument("--private", action="store_true")
49
+ p.add_argument("--dry-run", action="store_true")
50
+ args = p.parse_args()
51
+
52
+ ds = build(args.source_revision)
53
+ for split, d in ds.items():
54
+ print(f" split={split} rows={len(d)} columns={d.column_names}")
55
+
56
+ if args.dry_run:
57
+ print(f"[dry-run] would push to {args.repo}")
58
+ return
59
+
60
+ ds.push_to_hub(
61
+ args.repo,
62
+ commit_message="Rebuild from source revision",
63
+ token=args.token,
64
+ private=args.private,
65
+ )
66
+ revision = HfApi(token=args.token).dataset_info(args.repo).sha
67
+ print(f"-> pushed to {args.repo}, revision={revision}")
68
+
69
+
70
+ if __name__ == "__main__":
71
+ main()