|
|
import json |
|
|
|
|
|
import datasets |
|
|
|
|
|
|
|
|
class JMTEBlite(datasets.GeneratorBasedBuilder): |
|
|
|
|
|
BUILDER_CONFIGS = [ |
|
|
datasets.BuilderConfig( |
|
|
name=name, |
|
|
description=f"JMTEB-lite dataset configuration for {name}", |
|
|
) |
|
|
for name in [ |
|
|
"livedoor_news", |
|
|
"mewsc16_ja", |
|
|
"sib200_japanese_clustering", |
|
|
"amazon_review_classification", |
|
|
"amazon_counterfactual_classification", |
|
|
"massive_intent_classification", |
|
|
"massive_scenario_classification", |
|
|
"japanese_sentiment_classification", |
|
|
"sib200_japanese_classification", |
|
|
"wrime_classification", |
|
|
"jsts", |
|
|
"jsick", |
|
|
"jaqket-query", |
|
|
"jaqket-corpus", |
|
|
"mrtydi-query", |
|
|
"mrtydi-corpus", |
|
|
"jagovfaqs_22k-query", |
|
|
"jagovfaqs_22k-corpus", |
|
|
"nlp_journal_title_abs-query", |
|
|
"nlp_journal_title_abs-corpus", |
|
|
"nlp_journal_title_intro-query", |
|
|
"nlp_journal_title_intro-corpus", |
|
|
"nlp_journal_abs_intro-query", |
|
|
"nlp_journal_abs_intro-corpus", |
|
|
"nlp_journal_abs_article-query", |
|
|
"nlp_journal_abs_article-corpus", |
|
|
"jacwir-retrieval-query", |
|
|
"jacwir-retrieval-corpus", |
|
|
"miracl-retrieval-query", |
|
|
"miracl-retrieval-corpus", |
|
|
"mldr-retrieval-query", |
|
|
"mldr-retrieval-corpus", |
|
|
"mintaka-retrieval-query", |
|
|
"mintaka-retrieval-corpus", |
|
|
"esci-query", |
|
|
"esci-corpus", |
|
|
"jqara-query", |
|
|
"jqara-corpus", |
|
|
"jacwir-reranking-query", |
|
|
"jacwir-reranking-corpus", |
|
|
"miracl-reranking-query", |
|
|
"miracl-reranking-corpus", |
|
|
"mldr-reranking-query", |
|
|
"mldr-reranking-corpus", |
|
|
] |
|
|
] |
|
|
|
|
|
def _info(self): |
|
|
builder = datasets.load_dataset_builder( |
|
|
"sbintuitions/JMTEB", |
|
|
self.config.name, |
|
|
trust_remote_code=True, |
|
|
) |
|
|
return datasets.DatasetInfo( |
|
|
description=f"{self.config.name} in JMTEB-lite:" + builder.info.description, |
|
|
citation=builder.info.citation, |
|
|
homepage=builder.info.homepage, |
|
|
license=builder.info.license, |
|
|
features=builder.info.features, |
|
|
) |
|
|
|
|
|
def _split_generators(self, dl_manager): |
|
|
if self.config.name in [ |
|
|
"jacwir-retrieval-corpus", |
|
|
"jaqket-corpus", |
|
|
"miracl-retrieval-corpus", |
|
|
"mrtydi-corpus", |
|
|
]: |
|
|
filename = self.config.name.replace("corpus", "lite-corpus") |
|
|
data_file = dl_manager.download(f"Retrieval-lite-data/{filename}.jsonl") |
|
|
return [ |
|
|
datasets.SplitGenerator( |
|
|
name="corpus", gen_kwargs={"filepath": data_file, "split": "corpus"} |
|
|
) |
|
|
] |
|
|
|
|
|
if self.config.name in ["jacwir-reranking-corpus", "jqara-corpus"]: |
|
|
filename = self.config.name.replace("corpus", "lite-corpus") |
|
|
data_file = dl_manager.download(f"Reranking-lite-data/{filename}.jsonl") |
|
|
return [ |
|
|
datasets.SplitGenerator( |
|
|
name="corpus", gen_kwargs={"filepath": data_file, "split": "corpus"} |
|
|
) |
|
|
] |
|
|
|
|
|
if self.config.name in ["jacwir-reranking-query", "jqara-query"]: |
|
|
filename = self.config.name.replace("query", "lite-query-{split}.jsonl") |
|
|
return [ |
|
|
datasets.SplitGenerator( |
|
|
name=split, |
|
|
gen_kwargs={ |
|
|
"filepath": dl_manager.download( |
|
|
f"Reranking-lite-data/{filename.format(split=split)}" |
|
|
), |
|
|
"split": split, |
|
|
}, |
|
|
) |
|
|
for split in ["validation", "test"] |
|
|
] |
|
|
|
|
|
original = datasets.load_dataset( |
|
|
"sbintuitions/JMTEB", self.config.name, trust_remote_code=True |
|
|
) |
|
|
return [ |
|
|
datasets.SplitGenerator(name=split, gen_kwargs={"split": split}) |
|
|
for split in original.keys() |
|
|
] |
|
|
|
|
|
def _generate_examples(self, split, filepath=None): |
|
|
if filepath: |
|
|
with open(filepath, "r", encoding="utf-8") as f: |
|
|
for i, line in enumerate(f): |
|
|
example = json.loads(line.strip()) |
|
|
yield i, example |
|
|
else: |
|
|
original_split = datasets.load_dataset( |
|
|
"sbintuitions/JMTEB", |
|
|
self.config.name, |
|
|
split=split, |
|
|
trust_remote_code=True, |
|
|
) |
|
|
for i, example in enumerate(original_split): |
|
|
yield i, example |
|
|
|