forked from Helsinki-NLP/HBMP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
corpora.py
204 lines (167 loc) · 8.82 KB
/
corpora.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
import torchtext
import torchtext.data as data
class AllNLI(data.TabularDataset):
dirname = 'snli_1.0'
name = 'snli'
@staticmethod
def sort_key(ex):
return data.interleave_keys(
len(ex.premise), len(ex.hypothesis))
@classmethod
def splits(cls, text_field, label_field, id_field, parse_field=None, root='.data',
train='all_nli.jsonl', validation='snli_1.0_dev.jsonl',
test='snli_1.0_test.jsonl'):
path = cls.download(root)
if parse_field is None:
return super(AllNLI, cls).splits(
path, root, train, validation, test,
format='json', fields={'sentence1': ('premise', text_field),
'sentence2': ('hypothesis', text_field),
'gold_label': ('label', label_field),
'pairID' : ('pair_id', id_field)},
filter_pred=lambda ex: ex.label != '-')
return super(AllNLI, cls).splits(
path, root, train, validation, test,
format='json', fields={'sentence1_binary_parse':
[('premise', text_field),
('premise_transitions', parse_field)],
'sentence2_binary_parse':
[('hypothesis', text_field),
('hypothesis_transitions', parse_field)],
'gold_label': ('label', label_field),
'pairID' : ('pair_id', id_field)},
filter_pred=lambda ex: ex.label != '-')
class StanfordNLI(data.TabularDataset):
dirname = 'snli_1.0'
name = 'snli'
@staticmethod
def sort_key(ex):
return data.interleave_keys(
len(ex.premise), len(ex.hypothesis))
@classmethod
def splits(cls, text_field, label_field, parse_field=None, root='.data',
train='snli_1.0_train.jsonl', validation='snli_1.0_dev.jsonl',
test='snli_1.0_test.jsonl'):
path = cls.download(root)
if parse_field is None:
return super(StanfordNLI, cls).splits(
path, root, train, validation, test,
format='json', fields={'sentence1': ('premise', text_field),
'sentence2': ('hypothesis', text_field),
'gold_label': ('label', label_field)},
filter_pred=lambda ex: ex.label != '-')
return super(StanfordNLI, cls).splits(
path, root, train, validation, test,
format='json', fields={'sentence1_binary_parse':
[('premise', text_field),
('premise_transitions', parse_field)],
'sentence2_binary_parse':
[('hypothesis', text_field),
('hypothesis_transitions', parse_field)],
'gold_label': ('label', label_field)},
filter_pred=lambda ex: ex.label != '-')
class BreakingNLI(data.TabularDataset):
dirname = 'data'
name = 'breaking_nli'
@staticmethod
def sort_key(ex):
return data.interleave_keys(
len(ex.premise), len(ex.hypothesis))
@classmethod
def splits(cls, text_field, label_field, category_field, parse_field=None, root='.data',
train='breaking_train.jsonl', validation='breaking_dev.jsonl',
test='breaking_test.jsonl'):
path = cls.download(root)
return super(BreakingNLI, cls).splits(
path, root, train, validation, test,
format='json', fields={'sentence1': ('premise', text_field),
'sentence2': ('hypothesis', text_field),
'category' : ('category', category_field),
'gold_label': ('label', label_field)},
filter_pred=lambda ex: ex.label != '-')
class MultiNLI(data.TabularDataset):
dirname = 'multinli_1.0'
name = 'multinli'
@staticmethod
def sort_key(ex):
return data.interleave_keys(
len(ex.premise), len(ex.hypothesis))
@classmethod
def splits_matched(cls, text_field, label_field, id_field, parse_field=None, genre_field=None, root='.data',
train='multinli_1.0_train.jsonl', validation='multinli_1.0_dev_matched.jsonl',
test='multinli_1.0_dev_matched.jsonl'):
path = cls.download(root)
if parse_field is None:
return super(MultiNLI, cls).splits(
path, root, train, validation, test,
format='json', fields={'sentence1': ('premise', text_field),
'sentence2': ('hypothesis', text_field),
'gold_label': ('label', label_field),
'pairID' : ('pair_id', id_field)},
filter_pred=lambda ex: ex.label != '-')
return super(MultiNLI, cls).splits(
path, root, train, validation, test,
format='json', fields={'sentence1_binary_parse':
[('premise', text_field),
('premise_transitions', parse_field)],
'sentence2_binary_parse':
[('hypothesis', text_field),
('hypothesis_transitions', parse_field)],
'gold_label': ('label', label_field),
'pairID' : ('pair_id', id_field),
'genre': ('genre', genre_field)},
filter_pred=lambda ex: ex.label != '-')
@classmethod
def splits_mismatched(cls, text_field, label_field, id_field, parse_field=None, genre_field=None, root='.data',
train='multinli_1.0_train.jsonl', validation='multinli_1.0_dev_mismatched.jsonl',
test='multinli_1.0_dev_mismatched.jsonl'):
path = cls.download(root)
if parse_field is None:
return super(MultiNLI, cls).splits(
path, root, train, validation, test,
format='json', fields={'sentence1': ('premise', text_field),
'sentence2': ('hypothesis', text_field),
'gold_label': ('label', label_field),
'pairID' : ('pair_id', id_field)},
filter_pred=lambda ex: ex.label != '-')
return super(MultiNLI, cls).splits(
path, root, train, validation, test,
format='json', fields={'sentence1_binary_parse':
[('premise', text_field),
('premise_transitions', parse_field)],
'sentence2_binary_parse':
[('hypothesis', text_field),
('hypothesis_transitions', parse_field)],
'gold_label': ('label', label_field),
'pairID' : ('pair_id', id_field),
'genre': ('genre', genre_field)},
filter_pred=lambda ex: ex.label != '-')
class SciTail(data.TabularDataset):
dirname = 'SciTailV1/snli_format'
name = 'scitail'
@staticmethod
def sort_key(ex):
return data.interleave_keys(
len(ex.premise), len(ex.hypothesis))
@classmethod
def splits(cls, text_field, label_field, parse_field=None, root='.data',
train='scitail_1.0_train.txt', validation='scitail_1.0_dev.txt',
test='scitail_1.0_test.txt'):
path = cls.download(root)
if parse_field is None:
return super(SciTail, cls).splits(
path, root, train, validation, test,
format='json', fields={'sentence1': ('premise', text_field),
'sentence2': ('hypothesis', text_field),
'gold_label': ('label', label_field)},
filter_pred=lambda ex: ex.label != '-')
return super(SciTail, cls).splits(
path, root, train, validation, test,
format='json', fields={'sentence1_binary_parse':
[('premise', text_field),
('premise_transitions', parse_field)],
'sentence2_binary_parse':
[('hypothesis', text_field),
('hypothesis_transitions', parse_field)],
'gold_label': ('label', label_field)},
filter_pred=lambda ex: ex.label != '-')