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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
|
3 |
+
'''Ulysses-Ner dataset'''
|
4 |
+
|
5 |
+
import datasets
|
6 |
+
import os
|
7 |
+
|
8 |
+
from pathlib import Path
|
9 |
+
|
10 |
+
# Também dá para criar uma citação para o C corpus
|
11 |
+
_CITATION_PL_CORPUS = """
|
12 |
+
@InProceedings{10.1007\/978-3-030-98305-5_1,
|
13 |
+
author="Albuquerque, Hidelberg O.
|
14 |
+
and Costa, Rosimeire
|
15 |
+
and Silvestre, Gabriel
|
16 |
+
and Souza, Ellen
|
17 |
+
and da Silva, N{\\'a}dia F. F.
|
18 |
+
and Vit{\\'o}rio, Douglas
|
19 |
+
and Moriyama, Gyovana
|
20 |
+
and Martins, Lucas
|
21 |
+
and Soezima, Luiza
|
22 |
+
and Nunes, Augusto
|
23 |
+
and Siqueira, Felipe
|
24 |
+
and Tarrega, Jo{\~a}o P.
|
25 |
+
and Beinotti, Joao V.
|
26 |
+
and Dias, Marcio
|
27 |
+
and Silva, Matheus
|
28 |
+
and Gardini, Miguel
|
29 |
+
and Silva, Vinicius
|
30 |
+
and de Carvalho, Andr{\\'e} C. P. L. F.
|
31 |
+
and Oliveira, Adriano L. I.",
|
32 |
+
editor="Pinheiro, Vl{\\'a}dia
|
33 |
+
and Gamallo, Pablo
|
34 |
+
and Amaro, Raquel
|
35 |
+
and Scarton, Carolina
|
36 |
+
and Batista, Fernando
|
37 |
+
and Silva, Diego
|
38 |
+
and Magro, Catarina
|
39 |
+
and Pinto, Hugo",
|
40 |
+
title="UlyssesNER-Br: A Corpus of Brazilian Legislative Documents for Named Entity Recognition",
|
41 |
+
booktitle="Computational Processing of the Portuguese Language",
|
42 |
+
year="2022",
|
43 |
+
publisher="Springer International Publishing",
|
44 |
+
address="Cham",
|
45 |
+
pages="3--14",
|
46 |
+
abstract="The amount of legislative documents produced within the past decade has risen dramatically, making it difficult for law practitioners to consult and update legislation. Named Entity Recognition (NER) systems have the untapped potential to extract information from legal documents, which can improve information retrieval and decision-making processes. We introduce the UlyssesNER-Br, a corpus of Brazilian Legislative Documents for NER with quality baselines. The presented corpus consists of bills and legislative consultations from Brazilian Chamber of Deputies. We implemented Conditional Random Field (CRF) and Hidden Markov Model (HMM) models, and the promising F1-score of 80.8{\%} in the analysis by categories and 81.04{\%} in the analysis by types, was achieved with the CRF model. The entities with the best average F1-score results were ``FUNDlei'' and ``DATA'', and the ones with the worst results were ``EVENTO'' and ``PESSOAgrupoind''. The corpus was also evaluated using a BiLSTM-CRF and Glove architectures provided by the pioneering state-of-the-art paper, achieving F1-score of 76.89{\%} in the analysis by categories and 59.67{\%} in the analysis by types.",
|
47 |
+
isbn="978-3-030-98305-5"
|
48 |
+
}
|
49 |
+
"""
|
50 |
+
|
51 |
+
_DESCRIPTION = """
|
52 |
+
The amount of legislative documents produced within the past decade has risen dramatically, making it difficult for law practitioners to consult and update legislation.
|
53 |
+
Named Entity Recognition (NER) systems have the untapped potential to extract information from legal documents, which can improve information retrieval and decision-making processes.
|
54 |
+
We introduce the UlyssesNER-Br, a corpus of Brazilian Legislative Documents for NER with quality baselines.
|
55 |
+
The presented corpus consists of bills and legislative consultations from Brazilian Chamber of Deputies.
|
56 |
+
We implemented Conditional Random Field (CRF) and Hidden Markov Model (HMM) models, and the promising F1-score of 80.8% in the analysis by categories and 81.04 in the analysis by types, was achieved with the CRF model. The entities with the best average F1-score results were “FUNDlei” and “DATA”, and the ones with the worst results were “EVENTO” and “PESSOAgrupoind”. The corpus was also evaluated using a BiLSTM-CRF and Glove architectures provided by the pioneering state-of-the-art paper, achieving F1-score of 76.89% in the analysis by categories and 59.67% in the analysis by types.
|
57 |
+
|
58 |
+
Keywords: Annotation Schema · Named Entity Recognition · Legal Information Retrieval.
|
59 |
+
"""
|
60 |
+
|
61 |
+
_URL = 'https://github.com/ulysses-camara/ulysses-ner-br'
|
62 |
+
_HOMEPAGE = 'https://github.com/ulysses-camara'
|
63 |
+
_LICENSE = ''
|
64 |
+
|
65 |
+
_URLS = {
|
66 |
+
'pl_corpus_categorias' : {
|
67 |
+
'train' : 'https://raw.githubusercontent.com/ulysses-camara/ulysses-ner-br/main/annotated-corpora/PL_corpus_conll/pl_corpus_categorias/train.txt',
|
68 |
+
'valid' : 'https://raw.githubusercontent.com/ulysses-camara/ulysses-ner-br/main/annotated-corpora/PL_corpus_conll/pl_corpus_categorias/valid.txt',
|
69 |
+
'test' : 'https://raw.githubusercontent.com/ulysses-camara/ulysses-ner-br/main/annotated-corpora/PL_corpus_conll/pl_corpus_categorias/test.txt',
|
70 |
+
},
|
71 |
+
'pl_corpus_tipos' : {
|
72 |
+
'train' : 'https://raw.githubusercontent.com/ulysses-camara/ulysses-ner-br/main/annotated-corpora/PL_corpus_conll/pl_corpus_tipos/train.txt',
|
73 |
+
'valid' : 'https://raw.githubusercontent.com/ulysses-camara/ulysses-ner-br/main/annotated-corpora/PL_corpus_conll/pl_corpus_tipos/valid.txt',
|
74 |
+
'test' : 'https://raw.githubusercontent.com/ulysses-camara/ulysses-ner-br/main/annotated-corpora/PL_corpus_conll/pl_corpus_tipos/test.txt',
|
75 |
+
},
|
76 |
+
'c_corpus_categorias' : {
|
77 |
+
'train' : 'https://raw.githubusercontent.com/ulysses-camara/ulysses-ner-br/main/annotated-corpora/C_corpus_conll/c_corpus_categorias/train.txt',
|
78 |
+
'valid' : 'https://raw.githubusercontent.com/ulysses-camara/ulysses-ner-br/main/annotated-corpora/C_corpus_conll/c_corpus_categorias/valid.txt',
|
79 |
+
'test' : 'https://raw.githubusercontent.com/ulysses-camara/ulysses-ner-br/main/annotated-corpora/C_corpus_conll/c_corpus_categorias/test.txt',
|
80 |
+
},
|
81 |
+
'c_corpus_tipos' : {
|
82 |
+
'train' : 'https://raw.githubusercontent.com/ulysses-camara/ulysses-ner-br/main/annotated-corpora/C_corpus_conll/c_corpus_tipos/train.txt',
|
83 |
+
'valid' : 'https://raw.githubusercontent.com/ulysses-camara/ulysses-ner-br/main/annotated-corpora/C_corpus_conll/c_corpus_tipos/valid.txt',
|
84 |
+
'test' : 'https://raw.githubusercontent.com/ulysses-camara/ulysses-ner-br/main/annotated-corpora/C_corpus_conll/c_corpus_tipos/test.txt',
|
85 |
+
},
|
86 |
+
}
|
87 |
+
|
88 |
+
# https://github.com/huggingface/datasets/blob/main/templates/new_dataset_script.py
|
89 |
+
# https://huggingface.co/docs/datasets/v3.0.0/dataset_script
|
90 |
+
# https://huggingface.co/docs/datasets/v3.0.0/share
|
91 |
+
# https://huggingface.co/docs/datasets/v3.0.0/repository_structure
|
92 |
+
# https://huggingface.co/docs/hub/repositories-pull-requests-discussions#pull-requests-advanced-usage
|
93 |
+
# https://github.com/ulysses-camara/ulysses-ner-br/tree/main/annotated-corpora
|
94 |
+
# pl_corpus_categorias
|
95 |
+
# pl_corpus_tipos
|
96 |
+
# c_corpus_categorias
|
97 |
+
# c_corpus_tipos
|
98 |
+
|
99 |
+
|
100 |
+
class UlyssesNerBrConfig(datasets.BuilderConfig):
|
101 |
+
'''Builder Config for UlyssesNER-Br'''
|
102 |
+
|
103 |
+
def __init__(self, features, data_url, citation, url, version, label_classes=("False", "True"), **kwargs):
|
104 |
+
"""BuilderConfig for UlyssesNER-Br.
|
105 |
+
|
106 |
+
Args:
|
107 |
+
features: *list[string]*, list of the features that will appear in the
|
108 |
+
feature dict. Should not include "label".
|
109 |
+
data_url: *string*, url to download the zip file from.
|
110 |
+
citation: *string*, citation for the data set.
|
111 |
+
url: *string*, url for information about the data set.
|
112 |
+
label_classes: *list[string]*, the list of classes for the label if the
|
113 |
+
label is present as a string. Non-string labels will be cast to either
|
114 |
+
'False' or 'True'.
|
115 |
+
**kwargs: keyword arguments forwarded to super.
|
116 |
+
"""
|
117 |
+
|
118 |
+
# Version history:
|
119 |
+
# 1.0.2: Fixed non-nondeterminism in ReCoRD.
|
120 |
+
# 1.0.1: Change from the pre-release trial version of SuperGLUE (v1.9) to
|
121 |
+
# the full release (v2.0).
|
122 |
+
# 1.0.0: S3 (new shuffling, sharding and slicing mechanism).
|
123 |
+
# 0.0.2: Initial version.
|
124 |
+
super().__init__(version=version, **kwargs)
|
125 |
+
self.features = features
|
126 |
+
self.label_classes = label_classes
|
127 |
+
self.data_url = data_url
|
128 |
+
self.citation = citation
|
129 |
+
self.url = url
|
130 |
+
|
131 |
+
|
132 |
+
class UlyssesNerBr(datasets.GeneratorBasedBuilder):
|
133 |
+
|
134 |
+
VERSION = datasets.Version("1.0.0")
|
135 |
+
|
136 |
+
# BUILDER_CONFIG_CLASS = UlyssesNerBrConfig
|
137 |
+
BUILDER_CONFIG_CLASS = datasets.BuilderConfig
|
138 |
+
|
139 |
+
BUILDER_CONFIGS = [
|
140 |
+
datasets.BuilderConfig(
|
141 |
+
name='pl_corpus_categorias',
|
142 |
+
version=VERSION,
|
143 |
+
description=''
|
144 |
+
),
|
145 |
+
datasets.BuilderConfig(
|
146 |
+
name='pl_corpus_tipos',
|
147 |
+
version=VERSION,
|
148 |
+
description=''
|
149 |
+
),
|
150 |
+
datasets.BuilderConfig(
|
151 |
+
name='c_corpus_categorias',
|
152 |
+
version=VERSION,
|
153 |
+
description=''
|
154 |
+
),
|
155 |
+
datasets.BuilderConfig(
|
156 |
+
name='c_corpus_tipos',
|
157 |
+
version=VERSION,
|
158 |
+
description=''
|
159 |
+
)
|
160 |
+
]
|
161 |
+
|
162 |
+
DEFAULT_CONFIG_NAME = 'pl_corpus_categorias'
|
163 |
+
|
164 |
+
def _info(self):
|
165 |
+
|
166 |
+
if self.config.name == 'pl_corpus_categorias' \
|
167 |
+
or self.config.name == 'c_corpus_categorias' :
|
168 |
+
features = datasets.Features(
|
169 |
+
{
|
170 |
+
'id' : datasets.Value('string'),
|
171 |
+
'tokens' : datasets.Sequence(datasets.Value('string')),
|
172 |
+
'ner_tags' : datasets.Sequence(
|
173 |
+
datasets.features.ClassLabel(
|
174 |
+
names=[
|
175 |
+
'O',
|
176 |
+
'B-DATA',
|
177 |
+
'I-DATA',
|
178 |
+
'B-PESSOA',
|
179 |
+
'I-PESSOA',
|
180 |
+
'B-ORGANIZACAO',
|
181 |
+
'I-ORGANIZACAO',
|
182 |
+
'B-FUNDAMENTO',
|
183 |
+
'I-FUNDAMENTO',
|
184 |
+
'B-LOCAL',
|
185 |
+
'I-LOCAL',
|
186 |
+
'B-PRODUTODELEI',
|
187 |
+
'I-PRODUTODELEI',
|
188 |
+
'B-EVENTO',
|
189 |
+
'I-EVENTO',
|
190 |
+
]
|
191 |
+
)
|
192 |
+
),
|
193 |
+
}
|
194 |
+
)
|
195 |
+
elif self.config.name == 'pl_corpus_tipos':
|
196 |
+
features = datasets.Features(
|
197 |
+
{
|
198 |
+
'id' : datasets.Value('string'),
|
199 |
+
'tokens' : datasets.Sequence(datasets.Value('string')),
|
200 |
+
'ner_tags' : datasets.Sequence(
|
201 |
+
datasets.features.ClassLabel(
|
202 |
+
names=[
|
203 |
+
'O',
|
204 |
+
'B-DATA',
|
205 |
+
'I-DATA',
|
206 |
+
'B-PESSOAgrupocargo',
|
207 |
+
'I-PESSOAgrupocargo',
|
208 |
+
'B-PESSOAindividual',
|
209 |
+
'I-PESSOAindividual',
|
210 |
+
'B-PESSOAcargo',
|
211 |
+
'I-PESSOAcargo',
|
212 |
+
'B-ORGgovernamental',
|
213 |
+
'I-ORGgovernamental',
|
214 |
+
'B-ORGnaogovernamental',
|
215 |
+
'I-ORGnaogovernamental',
|
216 |
+
'B-ORGpartido',
|
217 |
+
'I-ORGpartido',
|
218 |
+
'B-FUNDlei',
|
219 |
+
'I-FUNDlei',
|
220 |
+
'B-FUNDprojetodelei',
|
221 |
+
'I-FUNDprojetodelei',
|
222 |
+
'B-FUNDapelido',
|
223 |
+
'I-FUNDapelido',
|
224 |
+
'B-LOCALconcreto',
|
225 |
+
'I-LOCALconcreto',
|
226 |
+
'B-LOCALvirtual',
|
227 |
+
'I-LOCALvirtual',
|
228 |
+
'B-PRODUTOprograma',
|
229 |
+
'I-PRODUTOprograma',
|
230 |
+
'B-PRODUTOsistema',
|
231 |
+
'I-PRODUTOsistema',
|
232 |
+
'B-PRODUTOoutros',
|
233 |
+
'I-PRODUTOoutros',
|
234 |
+
'B-EVENTO',
|
235 |
+
'I-EVENTO',
|
236 |
+
]
|
237 |
+
)
|
238 |
+
),
|
239 |
+
}
|
240 |
+
)
|
241 |
+
elif self.config.name == 'c_corpus_tipos' :
|
242 |
+
features = datasets.Features(
|
243 |
+
{
|
244 |
+
'id' : datasets.Value('string'),
|
245 |
+
'tokens' : datasets.Sequence(datasets.Value('string')),
|
246 |
+
'ner_tags' : datasets.Sequence(
|
247 |
+
datasets.features.ClassLabel(
|
248 |
+
names=[
|
249 |
+
'O',
|
250 |
+
'B-DATA',
|
251 |
+
'I-DATA',
|
252 |
+
'B-EVENTO',
|
253 |
+
'I-EVENTO',
|
254 |
+
'B-FUNDapelido',
|
255 |
+
'I-FUNDapelido',
|
256 |
+
'B-FUNDlei',
|
257 |
+
'I-FUNDlei',
|
258 |
+
'B-FUNDprojetodelei',
|
259 |
+
'I-FUNDprojetodelei',
|
260 |
+
'B-LOCALconcreto',
|
261 |
+
'I-LOCALconcreto',
|
262 |
+
'B-LOCALvirtual',
|
263 |
+
'I-LOCALvirtual',
|
264 |
+
'B-ORGgovernamental',
|
265 |
+
'I-ORGgovernamental',
|
266 |
+
'B-ORGnaogovernamental',
|
267 |
+
'I-ORGnaogovernamental',
|
268 |
+
'B-ORGpartido',
|
269 |
+
'I-ORGpartido',
|
270 |
+
'B-PESSOAcargo',
|
271 |
+
'I-PESSOAcargo',
|
272 |
+
'B-PESSOAgrupocargo',
|
273 |
+
'I-PESSOAgrupocargo',
|
274 |
+
'B-PESSOAgrupoind',
|
275 |
+
'I-PESSOAgrupoind',
|
276 |
+
'B-PESSOAindividual',
|
277 |
+
'I-PESSOAindividual',
|
278 |
+
'B-PRODUTOoutros',
|
279 |
+
'I-PRODUTOoutros',
|
280 |
+
'B-PRODUTOprograma',
|
281 |
+
'I-PRODUTOprograma',
|
282 |
+
'B-PRODUTOsistema',
|
283 |
+
'I-PRODUTOsistema',
|
284 |
+
]
|
285 |
+
)
|
286 |
+
),
|
287 |
+
}
|
288 |
+
)
|
289 |
+
|
290 |
+
return datasets.DatasetInfo(
|
291 |
+
description=_DESCRIPTION,
|
292 |
+
features=features,
|
293 |
+
supervised_keys=None,
|
294 |
+
homepage=_HOMEPAGE,
|
295 |
+
citation=_CITATION_PL_CORPUS
|
296 |
+
)
|
297 |
+
|
298 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager | datasets.StreamingDownloadManager):
|
299 |
+
'''
|
300 |
+
'''
|
301 |
+
urls = _URLS[self.config.name]
|
302 |
+
|
303 |
+
data_fir = dl_manager.download_and_extract(urls)
|
304 |
+
|
305 |
+
return [
|
306 |
+
datasets.SplitGenerator(
|
307 |
+
name=datasets.Split.TRAIN,
|
308 |
+
gen_kwargs={
|
309 |
+
'filepath' : data_fir['train'],
|
310 |
+
'split' : 'train',
|
311 |
+
}
|
312 |
+
),
|
313 |
+
datasets.SplitGenerator(
|
314 |
+
name=datasets.Split.VALIDATION,
|
315 |
+
gen_kwargs={
|
316 |
+
'filepath' : data_fir['valid'],
|
317 |
+
'split' : 'validation',
|
318 |
+
}
|
319 |
+
),
|
320 |
+
datasets.SplitGenerator(
|
321 |
+
name=datasets.Split.TEST,
|
322 |
+
gen_kwargs={
|
323 |
+
'filepath' : data_fir['test'],
|
324 |
+
'split' : 'test',
|
325 |
+
}
|
326 |
+
),
|
327 |
+
]
|
328 |
+
|
329 |
+
def _generate_examples(self, filepath, split):
|
330 |
+
|
331 |
+
guid = 0
|
332 |
+
sentence = list()
|
333 |
+
label = list()
|
334 |
+
with open(filepath, encoding='utf-8') as file :
|
335 |
+
|
336 |
+
for line in file:
|
337 |
+
splited = line.strip()
|
338 |
+
if line == '' or line == '\n':
|
339 |
+
if sentence:
|
340 |
+
yield guid, {
|
341 |
+
'id' : str(guid),
|
342 |
+
'tokens' : sentence,
|
343 |
+
'ner_tags' : label,
|
344 |
+
}
|
345 |
+
guid += 1
|
346 |
+
sentence = list()
|
347 |
+
label = list()
|
348 |
+
else:
|
349 |
+
splited = line.split(' ')
|
350 |
+
sentence.append(splited[0])
|
351 |
+
label.append(splited[1])
|
352 |
+
|