Datasets:
Tasks:
Text Retrieval
Modalities:
Text
Formats:
parquet
Sub-tasks:
document-retrieval
Languages:
Slovak
Size:
1K - 10K
ArXiv:
License:
| """Build script for mteb/SMESumRetrieval. | |
| This dataset is the MTEB-ready (retrieval) version of the SMESum dataset, used by | |
| the `SMESumRetrieval` task in https://github.com/embeddings-benchmark/mteb. | |
| Source: NaiveNeuron/SMESum (columns: title, introduction, document) | |
| https://huggingface.co/datasets/NaiveNeuron/SMESum | |
| Transform: reformulate summarization into retrieval -- take the first `n_sample` | |
| rows of the "test" split, use `introduction` as the query, `title`+`document` as | |
| the corpus document, and pair each query 1:1 with its source document as the | |
| qrel. Produces the three-config (corpus/queries/qrels) layout MTEB's | |
| AbsTaskRetrieval 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 `SMESumRetrieval` 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 = "NaiveNeuron/SMESum" | |
| SOURCE_REVISION = "c5a6521a4ddce3450fb04ba218623681a9189c6d" | |
| TARGET_REPO = "mteb/SMESumRetrieval" | |
| N_SAMPLE = 600 | |
| def build( | |
| source_revision: str = SOURCE_REVISION, n_sample: int = N_SAMPLE | |
| ) -> dict[str, DatasetDict]: | |
| corpus, queries, qrels = {}, {}, {} | |
| for split in ["test"]: | |
| split_ds = load_dataset( | |
| SOURCE_REPO, revision=source_revision, split=f"{split}[:{n_sample}]" | |
| ) | |
| ids = [f"d{e + 1}" for e in range(len(split_ds))] | |
| query_ids = [f"q{e + 1}" for e in range(len(split_ds))] | |
| queries[split] = Dataset.from_dict( | |
| {"id": query_ids, "text": split_ds["introduction"]} | |
| ) | |
| corpus[split] = Dataset.from_dict( | |
| {"id": ids, "title": split_ds["title"], "text": split_ds["document"]} | |
| ) | |
| qrels[split] = Dataset.from_dict( | |
| {"query-id": query_ids, "corpus-id": ids, "score": [1] * len(split_ds)} | |
| ) | |
| return { | |
| "corpus": DatasetDict(corpus), | |
| "queries": DatasetDict(queries), | |
| "qrels": DatasetDict(qrels), | |
| } | |
| def main() -> None: | |
| p = argparse.ArgumentParser(description=__doc__) | |
| p.add_argument("--source-revision", default=SOURCE_REVISION) | |
| p.add_argument("--n-sample", type=int, default=N_SAMPLE) | |
| 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() | |
| result = build(args.source_revision, args.n_sample) | |
| for config_name, dataset_dict in result.items(): | |
| for split, d in dataset_dict.items(): | |
| print(f" config={config_name} split={split} rows={len(d)} columns={d.column_names}") | |
| if args.dry_run: | |
| print(f"[dry-run] would push configs {list(result)} to {args.repo}") | |
| return | |
| for config_name, dataset_dict in result.items(): | |
| dataset_dict.push_to_hub( | |
| args.repo, | |
| config_name, | |
| commit_message=f"Rebuild {config_name} 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() | |