Datasets:

Modalities:
Text
Formats:
parquet
Languages:
Norwegian
ArXiv:
License:
vlhandfo commited on
Commit
9d928ea
·
verified ·
1 Parent(s): 1397fec

Delete norne.py

Browse files

Remove deprecated dataset script.

Files changed (1) hide show
  1. norne.py +0 -297
norne.py DELETED
@@ -1,297 +0,0 @@
1
- # coding=utf-8
2
- # Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
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
-
16
- # Lint as: python3
17
- """NorNE: Annotating Named Entities for Norwegian."""
18
-
19
- import conllu
20
-
21
- import datasets
22
-
23
-
24
- _CITATION = """\
25
- @inproceedings{johansen2019ner,
26
- title={NorNE: Annotating Named Entities for Norwegian},
27
- author={Fredrik Jørgensen, Tobias Aasmoe, Anne-Stine Ruud Husevåg,
28
- Lilja Øvrelid, and Erik Velldal},
29
- booktitle={LREC 2020},
30
- year={2020},
31
- url={https://arxiv.org/abs/1911.12146}
32
- }
33
- """
34
-
35
- _DESCRIPTION = """\
36
- NorNE is a manually annotated
37
- corpus of named entities which extends the annotation of the existing
38
- Norwegian Dependency Treebank. Comprising both of the official standards of
39
- written Norwegian (Bokmål and Nynorsk), the corpus contains around 600,000
40
- tokens and annotates a rich set of entity types including persons,
41
- organizations, locations, geo-political entities, products, and events,
42
- in addition to a class corresponding to nominals derived from names.
43
- """
44
-
45
- _HOMEPAGE = "https://github.com/ltgoslo/norne"
46
-
47
- _URL = "https://raw.githubusercontent.com/ltgoslo/norne/master/ud/"
48
- _BOKMAAL_TRAIN = "nob/no_bokmaal-ud-train.conllu"
49
- _BOKMAAL_DEV = "nob/no_bokmaal-ud-dev.conllu"
50
- _BOKMAAL_TEST = "nob/no_bokmaal-ud-test.conllu"
51
- _NYNORSK_TRAIN = "nno/no_nynorsk-ud-train.conllu"
52
- _NYNORSK_DEV = "nno/no_nynorsk-ud-dev.conllu"
53
- _NYNORSK_TEST = "nno/no_nynorsk-ud-test.conllu"
54
-
55
-
56
- class NorneConfig(datasets.BuilderConfig):
57
- """BuilderConfig for NorNE."""
58
-
59
- def __init__(self, **kwargs):
60
- """BuilderConfig for NorNE.
61
-
62
- Args:
63
- **kwargs: keyword arguments forwarded to super.
64
- """
65
- super(NorneConfig, self).__init__(**kwargs)
66
-
67
-
68
- class Norne(datasets.GeneratorBasedBuilder):
69
- """NorNE dataset."""
70
-
71
- BUILDER_CONFIGS = [
72
- NorneConfig(name="bokmaal", version=datasets.Version("1.0.0"), description="NorNE bokmaal dataset (full set)"),
73
- NorneConfig(name="nynorsk", version=datasets.Version("1.0.0"), description="NorNE nynorsk dataset (full set)"),
74
- NorneConfig(
75
- name="combined",
76
- version=datasets.Version("1.0.0"),
77
- description="NorNE bokmaal and nynorsk dataset (full set)",
78
- ),
79
- NorneConfig(
80
- name="bokmaal-7",
81
- version=datasets.Version("1.0.0"),
82
- description="NorNE bokmaal dataset (GPE_LOC/GPE_ORG as LOC/ORG)",
83
- ),
84
- NorneConfig(
85
- name="nynorsk-7",
86
- version=datasets.Version("1.0.0"),
87
- description="NorNE nynorsk dataset (GPE_LOC/GPE_ORG as LOC/ORG)",
88
- ),
89
- NorneConfig(
90
- name="combined-7",
91
- version=datasets.Version("1.0.0"),
92
- description="NorNE bokmaal and nynorsk dataset (GPE_LOC/GPE_ORG as LOC/ORG)",
93
- ),
94
- NorneConfig(
95
- name="bokmaal-8",
96
- version=datasets.Version("1.0.0"),
97
- description="NorNE bokmaal dataset (GPE_LOC/GPE_ORG as GPE)",
98
- ),
99
- NorneConfig(
100
- name="nynorsk-8",
101
- version=datasets.Version("1.0.0"),
102
- description="NorNE nynorsk dataset (GPE_LOC/GPE_ORG as GPE)",
103
- ),
104
- NorneConfig(
105
- name="combined-8",
106
- version=datasets.Version("1.0.0"),
107
- description="NorNE bokmaal and nynorsk dataset (GPE_LOC/GPE_ORG as GPE)",
108
- ),
109
- ]
110
-
111
- def _info(self):
112
- if self.config.name.endswith("-7"):
113
- ner_tags = datasets.Sequence(
114
- datasets.features.ClassLabel(
115
- names=[
116
- "O",
117
- "B-PER",
118
- "I-PER",
119
- "B-ORG",
120
- "I-ORG",
121
- "B-PROD",
122
- "I-PROD",
123
- "B-LOC",
124
- "I-LOC",
125
- "B-DRV",
126
- "I-DRV",
127
- "B-EVT",
128
- "I-EVT",
129
- "B-MISC",
130
- "I-MISC",
131
- ]
132
- )
133
- )
134
- elif self.config.name.endswith("-8"):
135
- ner_tags = datasets.Sequence(
136
- datasets.features.ClassLabel(
137
- names=[
138
- "O",
139
- "B-PER",
140
- "I-PER",
141
- "B-ORG",
142
- "I-ORG",
143
- "B-PROD",
144
- "I-PROD",
145
- "B-LOC",
146
- "I-LOC",
147
- "B-GPE",
148
- "I-GPE",
149
- "B-DRV",
150
- "I-DRV",
151
- "B-EVT",
152
- "I-EVT",
153
- "B-MISC",
154
- "I-MISC",
155
- ]
156
- )
157
- )
158
- else:
159
- ner_tags = datasets.Sequence(
160
- datasets.features.ClassLabel(
161
- names=[
162
- "O",
163
- "B-PER",
164
- "I-PER",
165
- "B-ORG",
166
- "I-ORG",
167
- "B-GPE_LOC",
168
- "I-GPE_LOC",
169
- "B-PROD",
170
- "I-PROD",
171
- "B-LOC",
172
- "I-LOC",
173
- "B-GPE_ORG",
174
- "I-GPE_ORG",
175
- "B-DRV",
176
- "I-DRV",
177
- "B-EVT",
178
- "I-EVT",
179
- "B-MISC",
180
- "I-MISC",
181
- ]
182
- )
183
- )
184
- return datasets.DatasetInfo(
185
- description=_DESCRIPTION,
186
- features=datasets.Features(
187
- {
188
- "idx": datasets.Value("string"),
189
- "lang": datasets.Value("string"),
190
- "text": datasets.Value("string"),
191
- "tokens": datasets.Sequence(datasets.Value("string")),
192
- "lemmas": datasets.Sequence(datasets.Value("string")),
193
- "pos_tags": datasets.Sequence(
194
- datasets.features.ClassLabel(
195
- names=[
196
- "NOUN",
197
- "PUNCT",
198
- "ADP",
199
- "NUM",
200
- "SYM",
201
- "SCONJ",
202
- "ADJ",
203
- "PART",
204
- "DET",
205
- "CCONJ",
206
- "PROPN",
207
- "PRON",
208
- "X",
209
- "ADV",
210
- "INTJ",
211
- "VERB",
212
- "AUX",
213
- ]
214
- )
215
- ),
216
- "ner_tags": ner_tags,
217
- }
218
- ),
219
- supervised_keys=None,
220
- homepage=_HOMEPAGE,
221
- citation=_CITATION,
222
- )
223
-
224
- def _split_generators(self, dl_manager):
225
- """Returns SplitGenerators."""
226
- train_filepaths = []
227
- dev_filepaths = []
228
- test_filepaths = []
229
- langs = []
230
- config_name = self.config.name.replace("-7", "").replace("-8", "")
231
- if config_name in ("bokmaal", "combined"):
232
- downloaded_files = dl_manager.download_and_extract(
233
- {
234
- "train": f"{_URL}{_BOKMAAL_TRAIN}",
235
- "dev": f"{_URL}{_BOKMAAL_DEV}",
236
- "test": f"{_URL}{_BOKMAAL_TEST}",
237
- }
238
- )
239
- train_filepaths.append(downloaded_files["train"])
240
- dev_filepaths.append(downloaded_files["dev"])
241
- test_filepaths.append(downloaded_files["test"])
242
- langs.append("bokmaal")
243
- if config_name in ("nynorsk", "combined"):
244
- downloaded_files = dl_manager.download_and_extract(
245
- {
246
- "train": f"{_URL}{_NYNORSK_TRAIN}",
247
- "dev": f"{_URL}{_NYNORSK_DEV}",
248
- "test": f"{_URL}{_NYNORSK_TEST}",
249
- }
250
- )
251
- train_filepaths.append(downloaded_files["train"])
252
- dev_filepaths.append(downloaded_files["dev"])
253
- test_filepaths.append(downloaded_files["test"])
254
- langs.append("nynorsk")
255
- return [
256
- datasets.SplitGenerator(
257
- name=datasets.Split.TRAIN, gen_kwargs={"filepaths": train_filepaths, "langs": langs}
258
- ),
259
- datasets.SplitGenerator(
260
- name=datasets.Split.VALIDATION, gen_kwargs={"filepaths": dev_filepaths, "langs": langs}
261
- ),
262
- datasets.SplitGenerator(
263
- name=datasets.Split.TEST, gen_kwargs={"filepaths": test_filepaths, "langs": langs}
264
- ),
265
- ]
266
-
267
- def _generate_examples(self, filepaths, langs):
268
- idx = 0
269
- if self.config.name.endswith("-7"):
270
-
271
- def filter_tags(x):
272
- return x.replace("GPE_", "")
273
-
274
- elif self.config.name.endswith("-8"):
275
-
276
- def filter_tags(x):
277
- return x.replace("_LOC", "").replace("_ORG", "")
278
-
279
- else:
280
-
281
- def filter_tags(x):
282
- return x
283
-
284
- for filepath, lang in zip(filepaths, langs):
285
- with open(filepath, "r", encoding="utf-8") as data_file:
286
- tokens = list(conllu.parse_incr(data_file))
287
- for sent in tokens:
288
- yield idx, {
289
- "idx": sent.metadata["sent_id"],
290
- "lang": lang,
291
- "text": sent.metadata["text"],
292
- "tokens": [token["form"] for token in sent],
293
- "lemmas": [token["lemma"] for token in sent],
294
- "pos_tags": [token["upos"] for token in sent],
295
- "ner_tags": [filter_tags(token["misc"].get("name", "O")) for token in sent],
296
- }
297
- idx += 1