OfekGlick commited on
Commit
e97d234
1 Parent(s): 91d9c44

Upload DiscoEval.py

Browse files
Files changed (1) hide show
  1. DiscoEval.py +183 -2
DiscoEval.py CHANGED
@@ -19,6 +19,187 @@ import DiscoEvalConstants
19
  import pickle
20
  import logging
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  _CITATION = """\
23
  @InProceedings{mchen-discoeval-19,
24
  title = {Evaluation Benchmarks and Learning Criteria for Discourse-Aware Sentence Representations},
@@ -138,7 +319,7 @@ class DiscoEvalSentence(datasets.GeneratorBasedBuilder):
138
  for i in range(DiscoEvalConstants.RST_TEXT_COLUMNS)
139
  }
140
  features_dict[DiscoEvalConstants.LABEL_NAME] = datasets.ClassLabel(
141
- names=DiscoEvalConstants.RST_LABELS
142
  )
143
  features = datasets.Features(features_dict)
144
 
@@ -259,7 +440,7 @@ class DiscoEvalSentence(datasets.GeneratorBasedBuilder):
259
  data = pickle.load(open(filepath, "rb"))
260
  for key, line in enumerate(data):
261
  example = {DiscoEvalConstants.TEXT_COLUMN_NAME[i]: sent for i, sent in enumerate(line[1:])}
262
- example[DiscoEvalConstants.LABEL_NAME] = line[0]
263
  yield key, example
264
 
265
  else:
 
19
  import pickle
20
  import logging
21
 
22
+ # General Constants:
23
+ LABEL_NAME = 'label'
24
+ numbers = {
25
+ 1: "first",
26
+ 2: "second",
27
+ 3: "third",
28
+ 4: "fourth",
29
+ 5: "fifth",
30
+ 6: "sixth",
31
+ 7: "seventh",
32
+ 8: "eighth",
33
+ 9: "ninth"
34
+
35
+ }
36
+ TEXT_COLUMN_NAME = [f"{numbers[i]}_sentence" for i in range(1, 10)]
37
+
38
+ # SSPabs Constants:
39
+ SSPABS = 'SSPabs'
40
+ SSPABS_TRAIN_NAME = 'train.txt'
41
+ SSPABS_VALID_NAME = 'valid.txt'
42
+ SSPABS_TEST_NAME = 'test.txt'
43
+ SSPABS_DATA_DIR = 'data/SSP/abs'
44
+ SSPABS_LABELS = {
45
+ "0": "Does not belong to abstract",
46
+ "1": "Belongs to abstract",
47
+ }
48
+ SSPABS_TEXT_COLUMNS = 1
49
+
50
+ # PDTB Constants:
51
+ PDTB_I = 'PDTB-I'
52
+ PDTB_E = 'PDTB-E'
53
+ PDTB_TRAIN_NAME = 'train.txt'
54
+ PDTB_VALID_NAME = 'valid.txt'
55
+ PDTB_TEST_NAME = 'test.txt'
56
+ PDTB_DATA_DIR = 'data/PDTB'
57
+ PDTB_DIRS = {PDTB_E: 'Explicit', PDTB_I: 'Implicit'}
58
+ PDTB_E_LABELS = [
59
+ 'Comparison.Concession',
60
+ 'Comparison.Contrast',
61
+ 'Contingency.Cause',
62
+ 'Contingency.Condition',
63
+ 'Contingency.Pragmatic condition',
64
+ 'Expansion.Alternative',
65
+ 'Expansion.Conjunction',
66
+ 'Expansion.Instantiation',
67
+ 'Expansion.List',
68
+ 'Expansion.Restatement',
69
+ 'Temporal.Asynchronous',
70
+ 'Temporal.Synchrony',
71
+ ]
72
+ PDTB_I_LABELS = [
73
+ 'Comparison.Concession',
74
+ 'Comparison.Contrast',
75
+ 'Contingency.Cause',
76
+ 'Contingency.Pragmatic cause',
77
+ 'Expansion.Alternative',
78
+ 'Expansion.Conjunction',
79
+ 'Expansion.Instantiation',
80
+ 'Expansion.List',
81
+ 'Expansion.Restatement',
82
+ 'Temporal.Asynchronous',
83
+ 'Temporal.Synchrony',
84
+ ]
85
+ PDTB_E_TEXT_COLUMNS = 2
86
+ PDTB_I_TEXT_COLUMNS = 2
87
+
88
+ # SP Constants:
89
+ SPARXIV = 'SParxiv'
90
+ SPROCSTORY = 'SProcstory'
91
+ SPWIKI = 'SPwiki'
92
+ SP_TRAIN_NAME = 'train.txt'
93
+ SP_VALID_NAME = 'valid.txt'
94
+ SP_TEST_NAME = 'test.txt'
95
+ SP_DATA_DIR = 'data/SP'
96
+ SP_DIRS = {SPARXIV: 'arxiv', SPROCSTORY: 'rocstory', SPWIKI: 'wiki'}
97
+ SP_LABELS = {
98
+ "0": 'First sentence',
99
+ "1": 'Second sentence',
100
+ "2": 'Third sentence',
101
+ "3": "Fourth sentence",
102
+ "4": "Fifth sentence",
103
+ }
104
+ SP_TEXT_COLUMNS = 5
105
+
106
+ # BSO Constants:
107
+ BSOARXIV = 'BSOarxiv'
108
+ BSOROCSTORY = 'BSOrocstory'
109
+ BSOWIKI = 'BSOwiki'
110
+ BSO_TRAIN_NAME = 'train.txt'
111
+ BSO_VALID_NAME = 'valid.txt'
112
+ BSO_TEST_NAME = 'test.txt'
113
+ BSO_DATA_DIR = 'data/BSO'
114
+ BSO_DIRS = {BSOARXIV: 'arxiv', BSOROCSTORY: 'rocstory', BSOWIKI: 'wiki'}
115
+ BSO_LABELS = {
116
+ "0": 'Incorrect order',
117
+ "1": 'Correct order',
118
+ }
119
+ BSO_TEXT_COLUMNS = 2
120
+
121
+ # DC Constants:
122
+ DCCHAT = 'DCchat'
123
+ DCWIKI = 'DCwiki'
124
+ DC_TRAIN_NAME = 'train.txt'
125
+ DC_VALID_NAME = 'valid.txt'
126
+ DC_TEST_NAME = 'test.txt'
127
+ DC_DATA_DIR = 'data/DC'
128
+ DC_DIRS = {DCCHAT: 'chat', DCWIKI: 'wiki'}
129
+ DC_LABELS = {
130
+ "0": "Incoherent",
131
+ "1": "Coherent",
132
+ }
133
+ DC_TEXT_COLUMNS = 6
134
+
135
+ # RST Constants:
136
+ RST = 'RST'
137
+ RST_TRAIN_NAME = 'RST_TRAIN.pkl'
138
+ RST_VALID_NAME = 'RST_DEV.pkl'
139
+ RST_TEST_NAME = 'RST_TEST.pkl'
140
+ RST_DATA_DIR = 'data/RST'
141
+ RST_LABELS = [
142
+ 'NS-Explanation',
143
+ 'NS-Evaluation',
144
+ 'NN-Condition',
145
+ 'NS-Summary',
146
+ 'SN-Cause',
147
+ 'SN-Background',
148
+ 'NS-Background',
149
+ 'SN-Summary',
150
+ 'NS-Topic-Change',
151
+ 'NN-Explanation',
152
+ 'SN-Topic-Comment',
153
+ 'NS-Elaboration',
154
+ 'SN-Attribution',
155
+ 'SN-Manner-Means',
156
+ 'NN-Evaluation',
157
+ 'NS-Comparison',
158
+ 'NS-Contrast',
159
+ 'SN-Condition',
160
+ 'NS-Temporal',
161
+ 'NS-Enablement',
162
+ 'SN-Evaluation',
163
+ 'NN-Topic-Comment',
164
+ 'NN-Temporal',
165
+ 'NN-Textual-organization',
166
+ 'NN-Same-unit',
167
+ 'NN-Comparison',
168
+ 'NN-Topic-Change',
169
+ 'SN-Temporal',
170
+ 'NN-Joint',
171
+ 'SN-Enablement',
172
+ 'SN-Explanation',
173
+ 'NN-Contrast',
174
+ 'NN-Cause',
175
+ 'SN-Contrast',
176
+ 'NS-Attribution',
177
+ 'NS-Topic-Comment',
178
+ 'SN-Elaboration',
179
+ 'SN-Comparison',
180
+ 'NS-Cause',
181
+ 'NS-Condition',
182
+ 'NS-Manner-Means'
183
+ ]
184
+ RST_TEXT_COLUMNS = 2
185
+
186
+ DATASET_NAMES = [
187
+ SSPABS,
188
+ PDTB_I,
189
+ PDTB_E,
190
+ SPARXIV,
191
+ SPROCSTORY,
192
+ SPWIKI,
193
+ BSOARXIV,
194
+ BSOROCSTORY,
195
+ BSOWIKI,
196
+ DCCHAT,
197
+ DCWIKI,
198
+ RST,
199
+ ]
200
+
201
+
202
+
203
  _CITATION = """\
204
  @InProceedings{mchen-discoeval-19,
205
  title = {Evaluation Benchmarks and Learning Criteria for Discourse-Aware Sentence Representations},
 
319
  for i in range(DiscoEvalConstants.RST_TEXT_COLUMNS)
320
  }
321
  features_dict[DiscoEvalConstants.LABEL_NAME] = datasets.ClassLabel(
322
+ names=list(DiscoEvalConstants.RST_LABELS.values())
323
  )
324
  features = datasets.Features(features_dict)
325
 
 
440
  data = pickle.load(open(filepath, "rb"))
441
  for key, line in enumerate(data):
442
  example = {DiscoEvalConstants.TEXT_COLUMN_NAME[i]: sent for i, sent in enumerate(line[1:])}
443
+ example[DiscoEvalConstants.LABEL_NAME] = DiscoEvalConstants.RST_DATA_DIR[line[0]]
444
  yield key, example
445
 
446
  else: