Datasets:
shibing624
commited on
Commit
•
b0498c9
1
Parent(s):
96e1778
Create nli_zh.py
Browse files
nli_zh.py
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Natural Language Inference (NLI) Chinese Corpus.(nli_zh)"""
|
2 |
+
|
3 |
+
|
4 |
+
import csv
|
5 |
+
import os
|
6 |
+
|
7 |
+
import datasets
|
8 |
+
|
9 |
+
|
10 |
+
_DESCRIPTION = """\
|
11 |
+
常见中文语义匹配数据集,包含ATEC、BQ、LCQMC、PAWSX、STS-B共5个任务。
|
12 |
+
"""
|
13 |
+
|
14 |
+
|
15 |
+
class Nli_zh(datasets.GeneratorBasedBuilder):
|
16 |
+
"""The Natural Language Inference Chinese(NLI_zh) Corpus."""
|
17 |
+
|
18 |
+
BUILDER_CONFIGS = [
|
19 |
+
datasets.BuilderConfig(
|
20 |
+
name="ATEC",
|
21 |
+
version=datasets.Version("1.0.0", ""),
|
22 |
+
description="Plain text import of NLI_zh",
|
23 |
+
)
|
24 |
+
]
|
25 |
+
|
26 |
+
def _info(self):
|
27 |
+
return datasets.DatasetInfo(
|
28 |
+
description=_DESCRIPTION,
|
29 |
+
features=datasets.Features(
|
30 |
+
{
|
31 |
+
"sentence1": datasets.Value("string"),
|
32 |
+
"sentence2": datasets.Value("string"),
|
33 |
+
"label": datasets.Value("int32"),
|
34 |
+
}
|
35 |
+
),
|
36 |
+
supervised_keys=None,
|
37 |
+
homepage="https://github.com/shibing624/text2vec",
|
38 |
+
)
|
39 |
+
|
40 |
+
def _split_generators(self, dl_manager):
|
41 |
+
dl_dir = dl_manager.download_and_extract(_DATA_URL)
|
42 |
+
data_dir = os.path.join(dl_dir, "nli_zh")
|
43 |
+
return [
|
44 |
+
datasets.SplitGenerator(
|
45 |
+
name=datasets.Split.TEST, gen_kwargs={"filepath": os.path.join(data_dir, "snli_1.0_test.txt")}
|
46 |
+
),
|
47 |
+
datasets.SplitGenerator(
|
48 |
+
name=datasets.Split.VALIDATION, gen_kwargs={"filepath": os.path.join(data_dir, "snli_1.0_dev.txt")}
|
49 |
+
),
|
50 |
+
datasets.SplitGenerator(
|
51 |
+
name=datasets.Split.TRAIN, gen_kwargs={"filepath": os.path.join(data_dir, "snli_1.0_train.txt")}
|
52 |
+
),
|
53 |
+
]
|
54 |
+
|
55 |
+
def _generate_examples(self, filepath):
|
56 |
+
"""This function returns the examples in the raw (text) form."""
|
57 |
+
with open(filepath, encoding="utf-8") as f:
|
58 |
+
reader = csv.DictReader(f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
59 |
+
for idx, row in enumerate(reader):
|
60 |
+
label = -1 if row["gold_label"] == "-" else row["gold_label"]
|
61 |
+
yield idx, {
|
62 |
+
"premise": row["sentence1"],
|
63 |
+
"hypothesis": row["sentence2"],
|
64 |
+
"label": label,
|
65 |
+
}
|