Datasets:

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