Datasets:

Modalities:
Text
Formats:
parquet
Languages:
Slovak
ArXiv:
License:
SlovakSumURLClustering / build_dataset.py
andrejridzik's picture
Upload build_dataset.py
3410778 verified
Raw
History Blame Contribute Delete
2.54 kB
"""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()