|
"""Natural Language Inference (NLI) Chinese Corpus.(nli_zh)""" |
|
|
|
|
|
import csv |
|
import os |
|
|
|
import datasets |
|
|
|
|
|
_DESCRIPTION = """\ |
|
常见中文语义匹配数据集,包含ATEC、BQ、LCQMC、PAWSX、STS-B共5个任务。 |
|
""" |
|
|
|
|
|
class Nli_zh(datasets.GeneratorBasedBuilder): |
|
"""The Natural Language Inference Chinese(NLI_zh) Corpus.""" |
|
|
|
BUILDER_CONFIGS = [ |
|
datasets.BuilderConfig( |
|
name="ATEC", |
|
version=datasets.Version("1.0.0", ""), |
|
description="Plain text import of NLI_zh", |
|
) |
|
] |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=datasets.Features( |
|
{ |
|
"sentence1": datasets.Value("string"), |
|
"sentence2": datasets.Value("string"), |
|
"label": datasets.Value("int32"), |
|
} |
|
), |
|
supervised_keys=None, |
|
homepage="https://github.com/shibing624/text2vec", |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
dl_dir = dl_manager.download_and_extract(_DATA_URL) |
|
data_dir = os.path.join(dl_dir, "nli_zh") |
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, gen_kwargs={"filepath": os.path.join(data_dir, "snli_1.0_test.txt")} |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.VALIDATION, gen_kwargs={"filepath": os.path.join(data_dir, "snli_1.0_dev.txt")} |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, gen_kwargs={"filepath": os.path.join(data_dir, "snli_1.0_train.txt")} |
|
), |
|
] |
|
|
|
def _generate_examples(self, filepath): |
|
"""This function returns the examples in the raw (text) form.""" |
|
with open(filepath, encoding="utf-8") as f: |
|
reader = csv.DictReader(f, delimiter="\t", quoting=csv.QUOTE_NONE) |
|
for idx, row in enumerate(reader): |
|
label = -1 if row["gold_label"] == "-" else row["gold_label"] |
|
yield idx, { |
|
"premise": row["sentence1"], |
|
"hypothesis": row["sentence2"], |
|
"label": label, |
|
} |