Datasets:
Tasks:
Token Classification
Sub-tasks:
named-entity-recognition
Languages:
Portuguese
Multilinguality:
monolingual
Size Categories:
10K<n<100K
Language Creators:
expert-generated
Annotations Creators:
expert-generated
Source Datasets:
original
License:
Create new file
Browse files
NERDE.py
ADDED
@@ -0,0 +1,140 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
|
2 |
+
#
|
3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
+
# you may not use this file except in compliance with the License.
|
5 |
+
# You may obtain a copy of the License at
|
6 |
+
#
|
7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
#
|
9 |
+
# Unless required by applicable law or agreed to in writing, software
|
10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
+
# See the License for the specific language governing permissions and
|
13 |
+
# limitations under the License.
|
14 |
+
|
15 |
+
"""
|
16 |
+
(pt) NERDE: NER na Defesa Econômica
|
17 |
+
(en) NERDE: NER on Economic Defense
|
18 |
+
"""
|
19 |
+
|
20 |
+
|
21 |
+
import datasets
|
22 |
+
|
23 |
+
|
24 |
+
logger = datasets.logging.get_logger(__name__)
|
25 |
+
|
26 |
+
|
27 |
+
#_CITATION = """"""
|
28 |
+
|
29 |
+
_DESCRIPTION = """
|
30 |
+
(pt) NERDE é um dataset para NER a partir de documentos jurídicos da defesa econômica em português do Brasil, foi criado em colaboração com o Cade e o laboratório LATITUDE/UnB.
|
31 |
+
(en) NERDE is a NER dataset from economic defense legal documents in Brazilian Portuguese, created in collaboration with Cade and the LATITUDE/UnB laboratory.
|
32 |
+
"""
|
33 |
+
|
34 |
+
_HOMEPAGE = "https://github.com/guipaiva/NERDE"
|
35 |
+
|
36 |
+
_TRAINING_FILE = "train.conll"
|
37 |
+
_DEV_FILE = "dev.conll"
|
38 |
+
_TEST_FILE = "test.conll"
|
39 |
+
|
40 |
+
|
41 |
+
class NerdeDataset(datasets.GeneratorBasedBuilder):
|
42 |
+
|
43 |
+
VERSION = datasets.Version("1.0.0")
|
44 |
+
|
45 |
+
BUILDER_CONFIGS = [
|
46 |
+
datasets.BuilderConfig(name="NERDE", version=VERSION, description="Economic Defense NER dataset"),
|
47 |
+
]
|
48 |
+
|
49 |
+
def _info(self):
|
50 |
+
return datasets.DatasetInfo(
|
51 |
+
description=_DESCRIPTION,
|
52 |
+
features=datasets.Features(
|
53 |
+
{
|
54 |
+
"id": datasets.Value("string"),
|
55 |
+
"tokens": datasets.Sequence(datasets.Value("string")),
|
56 |
+
"ner_tags": datasets.Sequence(
|
57 |
+
datasets.features.ClassLabel(
|
58 |
+
names=[
|
59 |
+
"O",
|
60 |
+
"B-ORG",
|
61 |
+
"I-ORG",
|
62 |
+
"B-PER",
|
63 |
+
"I-PER",
|
64 |
+
"B-TEMPO",
|
65 |
+
"I-TEMPO",
|
66 |
+
"B-LOC",
|
67 |
+
"I-LOC",
|
68 |
+
"B-LEG",
|
69 |
+
"I-LEG",
|
70 |
+
"B-DOCS",
|
71 |
+
"I-DOCS",
|
72 |
+
"B-VALOR",
|
73 |
+
"I-VALOR"
|
74 |
+
]
|
75 |
+
)
|
76 |
+
),
|
77 |
+
}
|
78 |
+
),
|
79 |
+
supervised_keys=None,
|
80 |
+
homepage=_HOMEPAGE
|
81 |
+
)
|
82 |
+
|
83 |
+
|
84 |
+
def _split_generators(self, dl_manager):
|
85 |
+
"""Returns SplitGenerators."""
|
86 |
+
urls_to_download = {
|
87 |
+
"train": _TRAINING_FILE,
|
88 |
+
"dev": _DEV_FILE,
|
89 |
+
"test": _TEST_FILE,
|
90 |
+
}
|
91 |
+
downloaded_files = dl_manager.download_and_extract(urls_to_download)
|
92 |
+
|
93 |
+
return [
|
94 |
+
datasets.SplitGenerator(
|
95 |
+
name=datasets.Split.TRAIN,
|
96 |
+
gen_kwargs={"filepath": downloaded_files["train"], "split": "train"},
|
97 |
+
),
|
98 |
+
datasets.SplitGenerator(
|
99 |
+
name=datasets.Split.VALIDATION,
|
100 |
+
gen_kwargs={"filepath": downloaded_files["dev"], "split": "validation"},
|
101 |
+
),
|
102 |
+
datasets.SplitGenerator(
|
103 |
+
name=datasets.Split.TEST,
|
104 |
+
gen_kwargs={"filepath": downloaded_files["test"], "split": "test"},
|
105 |
+
),
|
106 |
+
]
|
107 |
+
|
108 |
+
def _generate_examples(self, filepath, split):
|
109 |
+
"""Yields examples."""
|
110 |
+
|
111 |
+
logger.info("⏳ Generating examples from = %s", filepath)
|
112 |
+
|
113 |
+
with open(filepath, encoding="utf-8") as f:
|
114 |
+
|
115 |
+
guid = 0
|
116 |
+
tokens = []
|
117 |
+
ner_tags = []
|
118 |
+
|
119 |
+
for line in f:
|
120 |
+
if line == "" or line == "\n":
|
121 |
+
if tokens:
|
122 |
+
yield guid, {
|
123 |
+
"id": str(guid),
|
124 |
+
"tokens": tokens,
|
125 |
+
"ner_tags": ner_tags,
|
126 |
+
}
|
127 |
+
guid += 1
|
128 |
+
tokens = []
|
129 |
+
ner_tags = []
|
130 |
+
else:
|
131 |
+
splits = line.split(" ")
|
132 |
+
tokens.append(splits[0])
|
133 |
+
ner_tags.append(splits[1].rstrip())
|
134 |
+
|
135 |
+
# last example
|
136 |
+
yield guid, {
|
137 |
+
"id": str(guid),
|
138 |
+
"tokens": tokens,
|
139 |
+
"ner_tags": ner_tags,
|
140 |
+
}
|