Roomcar commited on
Commit
60f3d2f
1 Parent(s): a86ccfe
Files changed (2) hide show
  1. README.md +63 -0
  2. SpaCE2022.py +206 -0
README.md CHANGED
@@ -10,6 +10,69 @@ tags:
10
  pretty_name: SpaCE2022
11
  size_categories:
12
  - 1K<n<10K
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  ---
14
 
15
  # Dataset Card for Dataset Name
 
10
  pretty_name: SpaCE2022
11
  size_categories:
12
  - 1K<n<10K
13
+ dataset_info:
14
+ - config_name: task1
15
+ features:
16
+ - name: qid
17
+ dtype: string
18
+ - name: context
19
+ dtype: string
20
+ - name: judge
21
+ dtype: int8
22
+ splits:
23
+ - name: train
24
+ num_bytes: 4018440
25
+ num_examples: 10993
26
+ - name: validation
27
+ num_bytes: 599209
28
+ num_examples: 1602
29
+ download_size: 4932714
30
+ dataset_size: 4617649
31
+ - config_name: task2
32
+ features:
33
+ - name: qid
34
+ dtype: string
35
+ - name: context
36
+ dtype: string
37
+ - name: reasons
38
+ sequence:
39
+ - name: fragments
40
+ sequence:
41
+ - name: role
42
+ dtype:
43
+ class_label:
44
+ names:
45
+ '0': S
46
+ '1': P
47
+ '2': E
48
+ '3': S1
49
+ '4': P1
50
+ '5': E1
51
+ '6': S2
52
+ '7': P2
53
+ '8': E2
54
+ '9': text1
55
+ '10': text2
56
+ - name: text
57
+ dtype: string
58
+ - name: idxes
59
+ sequence: int32
60
+ - name: type
61
+ dtype:
62
+ class_label:
63
+ names:
64
+ '0': A
65
+ '1': B
66
+ '2': C
67
+ splits:
68
+ - name: train
69
+ num_bytes: 2655240
70
+ num_examples: 4966
71
+ - name: validation
72
+ num_bytes: 370883
73
+ num_examples: 700
74
+ download_size: 3543914
75
+ dataset_size: 3026123
76
  ---
77
 
78
  # Dataset Card for Dataset Name
SpaCE2022.py ADDED
@@ -0,0 +1,206 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import datasets
3
+ import json
4
+ from typing import List
5
+ from typing import Union
6
+
7
+ _LICENSE = """
8
+ ## 第二届中文空间语义理解评测 SpaCE2022 数据集使用许可
9
+
10
+ 由 北京大学计算语言学研究所 授权给(使用者)
11
+
12
+ #### 一
13
+
14
+ 1. 任何使用本数据集的主体都需要知晓、理解并同意本许可的全部内容。
15
+ 2. 传播本数据集的主体必须同时提供本许可并要求传播受众知晓、理解并同意本许可的全部内容。
16
+ 3. 使用本数据集即代表知晓、理解并同意本许可的全部内容。
17
+
18
+ #### 二
19
+
20
+ 1. 本数据集的版权归北京大学计算语言学研究所(下简称“版权所有者”)所有。
21
+ 2. 本数据集将分阶段在 第二届中文空间语义理解评测 SpaCE2022 活动中发布。
22
+ 3. 版权所有者对本数据集内容有权进行任何修改,修改后,如无特殊说明,使用者仍需遵守本许可的条款。
23
+ 4. 版权所有者对本数据集的名称、网站等相关信息、材料等有权进行任何修改,修改后,如无特殊说明,使用者仍需遵守本许可的条款。
24
+
25
+ #### 三
26
+
27
+ 1. 本数据集仅供以下用途使用:
28
+ (1) 参赛选手在比赛中使用。参看《[第二届中文空间语义理解评测 SpaCE2022 参赛协议](https://github.com/2030NLP/SpaCE2022/blob/main/Agreement.md)》。
29
+ (2) 高校、科研机构在科学研究中使用。
30
+ 2. 本数据集禁止用于任何商业目的,不提供任何形式的商业授权。除了在参与第二届中文空间语义理解评测 SpaCE2022 的过程中为参赛而使用本数据集,公司或其他商业机构禁止使用本数据集。
31
+ 3. 使用本数据进行科学研究,发表论文或其他材料时应注明来源信息,如:“本研究使用了北京大学组织的第二届中文空间语义理解评测提供的 SpaCE2022 数据集”,并在参考文献中引用版权所有者的评测报告论文(**请关注举办方后续的论文发表情况**)。
32
+
33
+ #### 四
34
+
35
+ 1. 本许可证的最终解释权归属于版权所有者。
36
+
37
+ 北京大学计算语言学研究所
38
+ 2022年5月23日
39
+ """
40
+
41
+ _DESCRIPTION = """SpaCE2022"""
42
+ _CITATION = """ """
43
+
44
+ _DESCRIPTION_TASK1 = """SpaCE2022 Task1"""
45
+ _DESCRIPTION_TASK2 = """SpaCE2022 Task2"""
46
+ _DESCRIPTION_TASK3 = """SpaCE2022 Task3"""
47
+
48
+
49
+
50
+ _DESCRIPTION_DICT = {
51
+ 'task1': _DESCRIPTION_TASK1,
52
+ 'task2': _DESCRIPTION_TASK2,
53
+ 'task3': _DESCRIPTION_TASK3,
54
+ }
55
+
56
+ # _URLS_ROOT = "https://huggingface.co/datasets/2030NLP/SpaCE2022/raw/main/"
57
+ _URLS_ROOT = "./"
58
+ _URLS_DICT = {
59
+ 'task1': {
60
+ 'train': _URLS_ROOT + "data/task1/task1_train.jsonl",
61
+ 'dev': _URLS_ROOT + "data/task1/task1_dev.jsonl",
62
+ },
63
+ 'task2': {
64
+ 'train': _URLS_ROOT + "data/task2/task2_train.jsonl",
65
+ 'dev': _URLS_ROOT + "data/task2/task2_dev.jsonl",
66
+ },
67
+ 'task3': {
68
+ 'train': _URLS_ROOT + "data/task3/task3_train.jsonl",
69
+ 'dev': _URLS_ROOT + "data/task3/task3_dev.jsonl",
70
+ },
71
+ }
72
+
73
+ XXXX = datasets.Sequence([{
74
+ 'text': datasets.Sequence(datasets.Value('string')),
75
+ 'idxes': datasets.Sequence(datasets.Value('int32')),
76
+ }])
77
+
78
+ _FEATURES_DICT = {
79
+ 'task1': {
80
+ "qid": datasets.Value(dtype="string"),
81
+ "context": datasets.Value(dtype="string"),
82
+ "judge": datasets.Value(dtype="int8"),
83
+ },
84
+ 'task2': {
85
+ "qid": datasets.Value(dtype="string"),
86
+ "context": datasets.Value(dtype="string"),
87
+ "reasons": datasets.Sequence(
88
+ feature={
89
+ "fragments": datasets.Sequence(
90
+ feature={
91
+ "role": datasets.ClassLabel(num_classes=11, names=['S', 'P', 'E', 'S1', 'P1', 'E1', 'S2', 'P2', 'E2', 'text1', 'text2']),
92
+ "text": datasets.Value(dtype="string"),
93
+ "idxes": datasets.Sequence(datasets.Value("int32")),
94
+ },
95
+ ),
96
+ "type": datasets.ClassLabel(num_classes=3, names=['A', 'B', 'C']),
97
+ },
98
+ ),
99
+ },
100
+ 'task3': {
101
+ "qid": datasets.Value(dtype="string"),
102
+ "context": datasets.Value(dtype="string"),
103
+ "corefs": datasets.Sequence(datasets.Sequence(feature={
104
+ "text": datasets.Value("string"),
105
+ "idxes": datasets.Sequence(datasets.Value("int32")),
106
+ })),
107
+ "non_corefs": datasets.Sequence(datasets.Sequence(feature={
108
+ "text": datasets.Value("string"),
109
+ "idxes": datasets.Sequence(datasets.Value("int32")),
110
+ })),
111
+ # "outputs": datasets.Sequence(datasets.Sequence(feature={
112
+ # "text": datasets.Value("string"),
113
+ # "idxes": datasets.Sequence(datasets.Value("int32")),
114
+ # })),
115
+ "outputs": datasets.Sequence(datasets.Sequence(feature={})),
116
+ },
117
+ }
118
+
119
+ _split_name_map = {
120
+ 'train': datasets.Split.TRAIN,
121
+ 'dev': datasets.Split.VALIDATION,
122
+ 'test': datasets.Split.TEST,
123
+ }
124
+
125
+
126
+
127
+
128
+ class SpaCE2022Config(datasets.BuilderConfig):
129
+ """BuilderConfig for SpaCE2022."""
130
+
131
+ def __init__(self, splits, **kwargs):
132
+ # Version history:
133
+ # 1.4.0: final version used in SpaCE2022 Eval.
134
+ super().__init__(version=datasets.Version("1.4.0"), **kwargs)
135
+ self.splits = splits
136
+
137
+
138
+ class SpaCE2022(datasets.GeneratorBasedBuilder):
139
+ """The SpaCE2022 benchmark."""
140
+
141
+ BUILDER_CONFIGS = [
142
+ SpaCE2022Config(
143
+ name="task1",
144
+ splits=['train', 'dev'],
145
+ ),
146
+ SpaCE2022Config(
147
+ name="task2",
148
+ splits=['train', 'dev'],
149
+ ),
150
+ # SpaCE2022Config(
151
+ # name="task3",
152
+ # splits=['train', 'dev'],
153
+ # ),
154
+ ]
155
+
156
+ def _info(self):
157
+ return datasets.DatasetInfo(
158
+ description=_DESCRIPTION_DICT[self.config.name],
159
+ features=datasets.Features(_FEATURES_DICT[self.config.name]),
160
+ homepage="https://2030nlp.github.io/SpaCE2022/",
161
+ citation=_CITATION,
162
+ license=_LICENSE,
163
+ )
164
+
165
+ def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
166
+
167
+ # 在 hugging face 中如何为 dataset 创建 _split_generators 函数?
168
+
169
+ split_things = []
170
+ for split_name in self.config.splits:
171
+ # print('')
172
+ split_data_path = _URLS_DICT[self.config.name][split_name]
173
+ # print(split_data_path)
174
+ filepath = dl_manager.download(split_data_path)
175
+ # print(filepath)
176
+ # print('')
177
+ split_thing = datasets.SplitGenerator(
178
+ name=_split_name_map[split_name],
179
+ gen_kwargs={
180
+ "task": self.config.name,
181
+ "filepath": filepath,
182
+ "split": split_name,
183
+ }
184
+ )
185
+ split_things.append(split_thing)
186
+ return split_things
187
+
188
+ def _generate_examples(self, task, filepath, split):
189
+ try:
190
+ with open(filepath, encoding="utf-8") as ff:
191
+ keys = _FEATURES_DICT[task].keys()
192
+ for idx, line in enumerate(ff):
193
+ example = json.loads(line.strip())
194
+ example = {kk: example[kk] for kk in keys if kk in example}
195
+ print('')
196
+ print(example)
197
+ print('')
198
+ qid = example.get("qid")
199
+ # print(qid)
200
+ jj = (split == qid.split("-")[1])
201
+ # print(jj)
202
+ if jj:
203
+ yield qid, example
204
+ except Exception as error:
205
+ print(error)
206
+