GAOXinyu
commited on
Commit
·
06747a2
1
Parent(s):
3826020
INIT: add afqmc dataset
Browse files- AFQMC.py +117 -0
- afqmc_public/dev.json +0 -0
- afqmc_public/test.json +0 -0
- afqmc_public/train.json +0 -0
- dataset_info.json +0 -0
AFQMC.py
ADDED
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
|
3 |
+
#
|
4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5 |
+
# you may not use this file except in compliance with the License.
|
6 |
+
# You may obtain a copy of the License at
|
7 |
+
#
|
8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9 |
+
#
|
10 |
+
# Unless required by applicable law or agreed to in writing, software
|
11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 |
+
# See the License for the specific language governing permissions and
|
14 |
+
# limitations under the License.
|
15 |
+
"""AFQMC"""
|
16 |
+
|
17 |
+
|
18 |
+
import os
|
19 |
+
import json
|
20 |
+
import datasets
|
21 |
+
|
22 |
+
|
23 |
+
_CITATION = """\
|
24 |
+
"""
|
25 |
+
|
26 |
+
_DESCRIPTION = """\
|
27 |
+
Download from https://www.cluebenchmarks.com/introduce.html
|
28 |
+
"""
|
29 |
+
|
30 |
+
_LICENSE = "apache-license-2.0"
|
31 |
+
_HOMEPAGE = "https://github.com/IDEA-CCNL/Fengshenbang-LM"
|
32 |
+
|
33 |
+
|
34 |
+
class AFQMCConfig(datasets.BuilderConfig):
|
35 |
+
"""BuilderConfig for AFQMCConfig"""
|
36 |
+
|
37 |
+
def __init__(self, **kwargs):
|
38 |
+
super().__init__(**kwargs)
|
39 |
+
"""
|
40 |
+
Args:
|
41 |
+
**kwargs: keyword arguments forwarded to super.
|
42 |
+
"""
|
43 |
+
|
44 |
+
|
45 |
+
class AFQMCConfig(datasets.GeneratorBasedBuilder):
|
46 |
+
|
47 |
+
VERSION = datasets.Version("1.0.0")
|
48 |
+
|
49 |
+
BUILDER_CONFIG_CLASS = AFQMCConfig
|
50 |
+
BUILDER_CONFIGS = [
|
51 |
+
AFQMCConfig(description=_DESCRIPTION)
|
52 |
+
]
|
53 |
+
|
54 |
+
def _info(self):
|
55 |
+
return datasets.DatasetInfo(
|
56 |
+
description=_DESCRIPTION,
|
57 |
+
features=datasets.Features({
|
58 |
+
"sentence1": datasets.Value("string"),
|
59 |
+
"sentence2": datasets.Value("string"),
|
60 |
+
"label": datasets.ClassLabel(num_classes=2, names=['not similar', 'similar']),
|
61 |
+
}),
|
62 |
+
homepage=_HOMEPAGE,
|
63 |
+
citation=_CITATION,
|
64 |
+
license=_LICENSE
|
65 |
+
)
|
66 |
+
|
67 |
+
def _split_generators(self, dl_manager):
|
68 |
+
|
69 |
+
files = {
|
70 |
+
"test": os.path.join("afqmc_public", f"test.json"),
|
71 |
+
"validation": os.path.join("afqmc_public", f"dev.json"),
|
72 |
+
"train": os.path.join("afqmc_public", f"train.json"),
|
73 |
+
}
|
74 |
+
data_dir = dl_manager.download_and_extract(files)
|
75 |
+
|
76 |
+
output = []
|
77 |
+
test = datasets.SplitGenerator(
|
78 |
+
name=datasets.Split.TEST,
|
79 |
+
gen_kwargs={
|
80 |
+
"filepath": data_dir["test"]
|
81 |
+
}
|
82 |
+
)
|
83 |
+
output.append(test)
|
84 |
+
|
85 |
+
# if os.path.exists(data_dir["validation"]):
|
86 |
+
valid = datasets.SplitGenerator(
|
87 |
+
name=datasets.Split.VALIDATION,
|
88 |
+
gen_kwargs={
|
89 |
+
"filepath": data_dir["validation"]
|
90 |
+
}
|
91 |
+
)
|
92 |
+
output.append(valid)
|
93 |
+
|
94 |
+
train = datasets.SplitGenerator(
|
95 |
+
name=datasets.Split.TRAIN,
|
96 |
+
gen_kwargs={
|
97 |
+
"filepath": data_dir["train"]
|
98 |
+
}
|
99 |
+
)
|
100 |
+
output.append(train)
|
101 |
+
|
102 |
+
return output
|
103 |
+
|
104 |
+
def _generate_examples(self, filepath):
|
105 |
+
"""Yields examples."""
|
106 |
+
with open(filepath, encoding="utf-8") as f:
|
107 |
+
lines = f.readlines()
|
108 |
+
for id_, line in enumerate(lines):
|
109 |
+
data = json.loads(line)
|
110 |
+
texta = data['sentence1']
|
111 |
+
textb = data['sentence2']
|
112 |
+
label = 'not similar' if data['label'] == '0' else 'similar'
|
113 |
+
yield id_, {
|
114 |
+
'sentence1': data['sentence1'],
|
115 |
+
'sentence2': data['sentence2'],
|
116 |
+
'label': label,
|
117 |
+
}
|
afqmc_public/dev.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
afqmc_public/test.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
afqmc_public/train.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
dataset_info.json
ADDED
File without changes
|