Datasets:
Commit
·
c273d21
1
Parent(s):
4b0f388
Create sts-sohu2021.py
Browse files- sts-sohu2021.py +102 -0
sts-sohu2021.py
ADDED
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# -*- coding: utf-8 -*-
|
2 |
+
"""
|
3 |
+
@author:XuMing([email protected])
|
4 |
+
@description:
|
5 |
+
2021搜狐校园文本匹配算法大赛数据集
|
6 |
+
upload: https://github.com/shibing624
|
7 |
+
"""
|
8 |
+
|
9 |
+
|
10 |
+
import csv
|
11 |
+
import os
|
12 |
+
import json
|
13 |
+
import datasets
|
14 |
+
|
15 |
+
|
16 |
+
_CITATION = """https://github.com/shibing624/text2vec"""
|
17 |
+
|
18 |
+
_DESCRIPTION = """\
|
19 |
+
2021搜狐校园文本匹配算法大赛数据集
|
20 |
+
"""
|
21 |
+
|
22 |
+
_DATA_URL = "https://huggingface.co/datasets/shibing624/sts-sohu2021/resolve/main/"
|
23 |
+
|
24 |
+
|
25 |
+
class Sohu(datasets.GeneratorBasedBuilder):
|
26 |
+
"""The Chinese Natural Language Inference (sts-sohu) Corpus."""
|
27 |
+
|
28 |
+
BUILDER_CONFIGS = [
|
29 |
+
datasets.BuilderConfig(
|
30 |
+
name="dda",
|
31 |
+
version=datasets.Version("1.0.0", ""),
|
32 |
+
description="Plain text import of sts-sohu2021",
|
33 |
+
),
|
34 |
+
datasets.BuilderConfig(
|
35 |
+
name="ddb",
|
36 |
+
version=datasets.Version("1.0.0", ""),
|
37 |
+
description="Plain text import of sts-sohu2021",
|
38 |
+
),
|
39 |
+
datasets.BuilderConfig(
|
40 |
+
name="dca",
|
41 |
+
version=datasets.Version("1.0.0", ""),
|
42 |
+
description="Plain text import of sts-sohu2021",
|
43 |
+
),
|
44 |
+
datasets.BuilderConfig(
|
45 |
+
name="dcb",
|
46 |
+
version=datasets.Version("1.0.0", ""),
|
47 |
+
description="Plain text import of sts-sohu2021",
|
48 |
+
),
|
49 |
+
datasets.BuilderConfig(
|
50 |
+
name="cca",
|
51 |
+
version=datasets.Version("1.0.0", ""),
|
52 |
+
description="Plain text import of sts-sohu2021",
|
53 |
+
),
|
54 |
+
datasets.BuilderConfig(
|
55 |
+
name="ccb",
|
56 |
+
version=datasets.Version("1.0.0", ""),
|
57 |
+
description="Plain text import of sts-sohu2021",
|
58 |
+
),
|
59 |
+
|
60 |
+
]
|
61 |
+
|
62 |
+
def _info(self):
|
63 |
+
return datasets.DatasetInfo(
|
64 |
+
description=_DESCRIPTION,
|
65 |
+
features=datasets.Features(
|
66 |
+
{
|
67 |
+
"sentence1": datasets.Value("string"),
|
68 |
+
"sentence2": datasets.Value("string"),
|
69 |
+
"label": datasets.Value("int32"),
|
70 |
+
}
|
71 |
+
),
|
72 |
+
|
73 |
+
supervised_keys=None,
|
74 |
+
homepage="https://github.com/shibing624/text2vec",
|
75 |
+
citation=_CITATION,
|
76 |
+
)
|
77 |
+
|
78 |
+
def _split_generators(self, dl_manager):
|
79 |
+
dl_dir = dl_manager.download_and_extract(_DATA_URL)
|
80 |
+
dl_file = f"{dl_dir}/{self.config.name}.jsonl"
|
81 |
+
return [
|
82 |
+
|
83 |
+
datasets.SplitGenerator(
|
84 |
+
name=datasets.Split.TRAIN, gen_kwargs={"filepath": dl_file}
|
85 |
+
),
|
86 |
+
]
|
87 |
+
|
88 |
+
def _generate_examples(self, filepath):
|
89 |
+
"""This function returns the examples in the raw (text) form."""
|
90 |
+
id = 0
|
91 |
+
if isinstance(filepath, str):
|
92 |
+
filepath = [filepath]
|
93 |
+
for file in filepath:
|
94 |
+
with open(file, encoding="utf-8") as f:
|
95 |
+
for key, row in enumerate(f):
|
96 |
+
data = json.loads(row)
|
97 |
+
yield id, {
|
98 |
+
"sentence1": data["sentence1"],
|
99 |
+
"sentence2": data["sentence2"],
|
100 |
+
"label": int(data["label"])
|
101 |
+
}
|
102 |
+
id += 1
|