Datasets:
SuzanaB
commited on
Commit
•
103a7d7
1
Parent(s):
023afe1
Add UD
Browse files- data.zip → data_ner.zip +0 -0
- data_ud.zip +0 -0
- hr500k.py +232 -112
data.zip → data_ner.zip
RENAMED
Binary files a/data.zip and b/data_ner.zip differ
|
|
data_ud.zip
ADDED
Binary file (2.16 MB). View file
|
|
hr500k.py
CHANGED
@@ -33,74 +33,125 @@ are encoded as class labels.
|
|
33 |
_HOMEPAGE = 'https://www.clarin.si/repository/xmlui/handle/11356/1183#'
|
34 |
_LICENSE = ''
|
35 |
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
40 |
|
41 |
|
42 |
class Hr500K(datasets.GeneratorBasedBuilder):
|
43 |
-
VERSION = datasets.Version('1.0.
|
44 |
|
45 |
BUILDER_CONFIGS = [
|
46 |
datasets.BuilderConfig(
|
47 |
-
name='
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
version=VERSION,
|
49 |
description=''
|
50 |
)
|
51 |
]
|
52 |
|
|
|
|
|
53 |
def _info(self):
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
datasets.
|
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 |
return datasets.DatasetInfo(
|
106 |
description=_DESCRIPTION,
|
@@ -113,78 +164,147 @@ class Hr500K(datasets.GeneratorBasedBuilder):
|
|
113 |
|
114 |
def _split_generators(self, dl_manager):
|
115 |
"""Returns SplitGenerators."""
|
116 |
-
data_dir = dl_manager.download_and_extract(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
|
118 |
return [
|
119 |
datasets.SplitGenerator(
|
120 |
name=datasets.Split.TRAIN, gen_kwargs={
|
121 |
-
'filepath': os.path.join(data_dir,
|
122 |
'split': 'train'}
|
123 |
),
|
124 |
datasets.SplitGenerator(
|
125 |
name=datasets.Split.VALIDATION, gen_kwargs={
|
126 |
-
'filepath': os.path.join(data_dir,
|
127 |
'split': 'dev'}
|
128 |
),
|
129 |
datasets.SplitGenerator(
|
130 |
name=datasets.Split.TEST, gen_kwargs={
|
131 |
-
'filepath': os.path.join(data_dir,
|
132 |
'split': 'test'}
|
133 |
),
|
134 |
]
|
135 |
|
136 |
def _generate_examples(self, filepath, split):
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
_HOMEPAGE = 'https://www.clarin.si/repository/xmlui/handle/11356/1183#'
|
34 |
_LICENSE = ''
|
35 |
|
36 |
+
_URLs = {
|
37 |
+
'ner': 'https://huggingface.co/datasets/classla/hr500k/raw/main/data_ner.zip',
|
38 |
+
'upos': 'https://huggingface.co/datasets/classla/hr500k/raw/main/data_ner.zip',
|
39 |
+
'ud': 'https://huggingface.co/datasets/classla/hr500k/raw/main/data_ud.zip'
|
40 |
+
}
|
41 |
|
42 |
|
43 |
class Hr500K(datasets.GeneratorBasedBuilder):
|
44 |
+
VERSION = datasets.Version('1.0.1')
|
45 |
|
46 |
BUILDER_CONFIGS = [
|
47 |
datasets.BuilderConfig(
|
48 |
+
name='upos',
|
49 |
+
version=VERSION,
|
50 |
+
description=''
|
51 |
+
),
|
52 |
+
datasets.BuilderConfig(
|
53 |
+
name='ner',
|
54 |
+
version=VERSION,
|
55 |
+
description=''
|
56 |
+
),
|
57 |
+
datasets.BuilderConfig(
|
58 |
+
name='ud',
|
59 |
version=VERSION,
|
60 |
description=''
|
61 |
)
|
62 |
]
|
63 |
|
64 |
+
DEFAULT_CONFIG_NAME = 'ner'
|
65 |
+
|
66 |
def _info(self):
|
67 |
+
if self.config.name == "upos":
|
68 |
+
features = datasets.Features(
|
69 |
+
{
|
70 |
+
'sent_id': datasets.Value('string'),
|
71 |
+
'text': datasets.Value('string'),
|
72 |
+
'tokens': datasets.Sequence(datasets.Value('string')),
|
73 |
+
'lemmas': datasets.Sequence(datasets.Value('string')),
|
74 |
+
'xpos_tags': datasets.Sequence(datasets.Value('string')),
|
75 |
+
'upos_tags': datasets.Sequence(
|
76 |
+
datasets.features.ClassLabel(
|
77 |
+
names=[
|
78 |
+
'X',
|
79 |
+
'INTJ',
|
80 |
+
'VERB',
|
81 |
+
'PROPN',
|
82 |
+
'ADV',
|
83 |
+
'ADJ',
|
84 |
+
'PUNCT',
|
85 |
+
'PRON',
|
86 |
+
'DET',
|
87 |
+
'NUM',
|
88 |
+
'SYM',
|
89 |
+
'SCONJ',
|
90 |
+
'NOUN',
|
91 |
+
'AUX',
|
92 |
+
'PART',
|
93 |
+
'CCONJ',
|
94 |
+
'ADP'
|
95 |
+
]
|
96 |
+
)
|
97 |
+
),
|
98 |
+
'feats': datasets.Sequence(datasets.Value('string')),
|
99 |
+
'iob_tags': datasets.Sequence(datasets.Value('string'))
|
100 |
+
}
|
101 |
+
)
|
102 |
+
elif self.config.name == "ner":
|
103 |
+
features = datasets.Features(
|
104 |
+
{
|
105 |
+
'sent_id': datasets.Value('string'),
|
106 |
+
'text': datasets.Value('string'),
|
107 |
+
'tokens': datasets.Sequence(datasets.Value('string')),
|
108 |
+
'lemmas': datasets.Sequence(datasets.Value('string')),
|
109 |
+
'xpos_tags': datasets.Sequence(datasets.Value('string')),
|
110 |
+
'upos_tags': datasets.Sequence(datasets.Value('string')),
|
111 |
+
'feats': datasets.Sequence(datasets.Value('string')),
|
112 |
+
'iob_tags': datasets.Sequence(
|
113 |
+
datasets.features.ClassLabel(
|
114 |
+
names=[
|
115 |
+
'I-org',
|
116 |
+
'B-misc',
|
117 |
+
'B-per',
|
118 |
+
'B-deriv-per',
|
119 |
+
'B-org',
|
120 |
+
'B-loc',
|
121 |
+
'I-deriv-per',
|
122 |
+
'I-misc',
|
123 |
+
'I-loc',
|
124 |
+
'I-per',
|
125 |
+
'O'
|
126 |
+
]
|
127 |
+
)
|
128 |
)
|
129 |
+
}
|
130 |
+
)
|
131 |
+
else:
|
132 |
+
features = datasets.Features(
|
133 |
+
{
|
134 |
+
'sent_id': datasets.Value('string'),
|
135 |
+
'text': datasets.Value('string'),
|
136 |
+
'tokens': datasets.Sequence(datasets.Value('string')),
|
137 |
+
'lemmas': datasets.Sequence(datasets.Value('string')),
|
138 |
+
'xpos_tags': datasets.Sequence(datasets.Value('string')),
|
139 |
+
'upos_tags': datasets.Sequence(datasets.Value('string')),
|
140 |
+
'feats': datasets.Sequence(datasets.Value('string')),
|
141 |
+
'iob_tags': datasets.Sequence(datasets.Value('string')),
|
142 |
+
'uds': datasets.Sequence(
|
143 |
+
datasets.features.ClassLabel(
|
144 |
+
names=[
|
145 |
+
'det', 'aux_pass', 'list', 'cc', 'csubj', 'xcomp', 'nmod', 'dislocated', 'acl', 'fixed',
|
146 |
+
'obj', 'dep', 'advmod_emph', 'goeswith', 'advmod', 'nsubj', 'punct', 'amod', 'expl_pv',
|
147 |
+
'mark', 'obl', 'flat_foreign', 'conj', 'compound', 'expl', 'csubj_pass', 'appos',
|
148 |
+
'case', 'advcl', 'parataxis', 'iobj', 'root', 'cop', 'aux', 'orphan', 'discourse',
|
149 |
+
'nummod', 'nsubj_pass', 'vocative', 'flat', 'ccomp'
|
150 |
+
]
|
151 |
+
)
|
152 |
)
|
153 |
+
}
|
154 |
+
)
|
|
|
155 |
|
156 |
return datasets.DatasetInfo(
|
157 |
description=_DESCRIPTION,
|
|
|
164 |
|
165 |
def _split_generators(self, dl_manager):
|
166 |
"""Returns SplitGenerators."""
|
167 |
+
data_dir = dl_manager.download_and_extract(_URLs[self.config.name])
|
168 |
+
|
169 |
+
if self.config.name == 'ud':
|
170 |
+
training_file = 'train_ner_ud.conllu'
|
171 |
+
dev_file = 'dev_ner_ud.conllu'
|
172 |
+
test_file = 'test_ner_ud.conllu'
|
173 |
+
else:
|
174 |
+
training_file = 'train_ner.conllu'
|
175 |
+
dev_file = 'dev_ner.conllu'
|
176 |
+
test_file = 'test_ner.conllu'
|
177 |
|
178 |
return [
|
179 |
datasets.SplitGenerator(
|
180 |
name=datasets.Split.TRAIN, gen_kwargs={
|
181 |
+
'filepath': os.path.join(data_dir, training_file),
|
182 |
'split': 'train'}
|
183 |
),
|
184 |
datasets.SplitGenerator(
|
185 |
name=datasets.Split.VALIDATION, gen_kwargs={
|
186 |
+
'filepath': os.path.join(data_dir, dev_file),
|
187 |
'split': 'dev'}
|
188 |
),
|
189 |
datasets.SplitGenerator(
|
190 |
name=datasets.Split.TEST, gen_kwargs={
|
191 |
+
'filepath': os.path.join(data_dir, test_file),
|
192 |
'split': 'test'}
|
193 |
),
|
194 |
]
|
195 |
|
196 |
def _generate_examples(self, filepath, split):
|
197 |
+
if self.config.name == 'ud':
|
198 |
+
with open(filepath, encoding='utf-8') as f:
|
199 |
+
sent_id = ''
|
200 |
+
text = ''
|
201 |
+
tokens = []
|
202 |
+
lemmas = []
|
203 |
+
xpos_tags = []
|
204 |
+
upos_tags = []
|
205 |
+
feats = []
|
206 |
+
iob_tags = []
|
207 |
+
uds = []
|
208 |
+
data_id = 0
|
209 |
+
for line in f:
|
210 |
+
if line and not line == '\n':
|
211 |
+
if line.startswith('#'):
|
212 |
+
if line.startswith('# sent_id'):
|
213 |
+
if tokens:
|
214 |
+
yield data_id, {
|
215 |
+
'sent_id': sent_id,
|
216 |
+
'text': text,
|
217 |
+
'tokens': tokens,
|
218 |
+
'lemmas': lemmas,
|
219 |
+
'upos_tags': upos_tags,
|
220 |
+
'xpos_tags': xpos_tags,
|
221 |
+
'feats': feats,
|
222 |
+
'iob_tags': iob_tags,
|
223 |
+
'uds': uds
|
224 |
+
}
|
225 |
+
tokens = []
|
226 |
+
lemmas = []
|
227 |
+
upos_tags = []
|
228 |
+
xpos_tags = []
|
229 |
+
feats = []
|
230 |
+
iob_tags = []
|
231 |
+
uds = []
|
232 |
+
data_id += 1
|
233 |
+
sent_id = line.split(' = ')[1].strip()
|
234 |
+
elif line.startswith('# text'):
|
235 |
+
text = line.split(' = ')[1].strip()
|
236 |
+
elif not line.startswith('_'):
|
237 |
+
splits = line.split('\t')
|
238 |
+
tokens.append(splits[1].strip())
|
239 |
+
lemmas.append(splits[2].strip())
|
240 |
+
upos_tags.append(splits[3].strip())
|
241 |
+
xpos_tags.append(splits[4].strip())
|
242 |
+
feats.append(splits[5].strip())
|
243 |
+
uds.append(splits[7].strip())
|
244 |
+
|
245 |
+
yield data_id, {
|
246 |
+
'sent_id': sent_id,
|
247 |
+
'text': text,
|
248 |
+
'tokens': tokens,
|
249 |
+
'lemmas': lemmas,
|
250 |
+
'upos_tags': upos_tags,
|
251 |
+
'xpos_tags': xpos_tags,
|
252 |
+
'feats': feats,
|
253 |
+
'iob_tags': iob_tags,
|
254 |
+
'uds': uds
|
255 |
+
}
|
256 |
+
else:
|
257 |
+
with open(filepath, encoding='utf-8') as f:
|
258 |
+
sent_id = ''
|
259 |
+
text = ''
|
260 |
+
tokens = []
|
261 |
+
lemmas = []
|
262 |
+
xpos_tags = []
|
263 |
+
upos_tags = []
|
264 |
+
feats = []
|
265 |
+
iob_tags = []
|
266 |
+
data_id = 0
|
267 |
+
for line in f:
|
268 |
+
if line and not line == '\n':
|
269 |
+
if line.startswith('#'):
|
270 |
+
if line.startswith('# sent_id'):
|
271 |
+
if tokens:
|
272 |
+
yield data_id, {
|
273 |
+
'sent_id': sent_id,
|
274 |
+
'text': text,
|
275 |
+
'tokens': tokens,
|
276 |
+
'lemmas': lemmas,
|
277 |
+
'upos_tags': upos_tags,
|
278 |
+
'xpos_tags': xpos_tags,
|
279 |
+
'feats': feats,
|
280 |
+
'iob_tags': iob_tags
|
281 |
+
}
|
282 |
+
tokens = []
|
283 |
+
lemmas = []
|
284 |
+
upos_tags = []
|
285 |
+
xpos_tags = []
|
286 |
+
feats = []
|
287 |
+
iob_tags = []
|
288 |
+
data_id += 1
|
289 |
+
sent_id = line.split(' = ')[1].strip()
|
290 |
+
elif line.startswith('# text'):
|
291 |
+
text = line.split(' = ')[1].strip()
|
292 |
+
elif not line.startswith('_'):
|
293 |
+
splits = line.split('\t')
|
294 |
+
tokens.append(splits[1].strip())
|
295 |
+
lemmas.append(splits[2].strip())
|
296 |
+
upos_tags.append(splits[3].strip())
|
297 |
+
xpos_tags.append(splits[4].strip())
|
298 |
+
feats.append(splits[5].strip())
|
299 |
+
iob_tags.append(splits[9].strip())
|
300 |
+
|
301 |
+
yield data_id, {
|
302 |
+
'sent_id': sent_id,
|
303 |
+
'text': text,
|
304 |
+
'tokens': tokens,
|
305 |
+
'lemmas': lemmas,
|
306 |
+
'upos_tags': upos_tags,
|
307 |
+
'xpos_tags': xpos_tags,
|
308 |
+
'feats': feats,
|
309 |
+
'iob_tags': iob_tags
|
310 |
+
}
|