system HF staff commited on
Commit
fcf3ca7
0 Parent(s):

Update files from the datasets library (from 1.2.0)

Browse files

Release notes: https://github.com/huggingface/datasets/releases/tag/1.2.0

.gitattributes ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bin.* filter=lfs diff=lfs merge=lfs -text
5
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.model filter=lfs diff=lfs merge=lfs -text
12
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
13
+ *.onnx filter=lfs diff=lfs merge=lfs -text
14
+ *.ot filter=lfs diff=lfs merge=lfs -text
15
+ *.parquet filter=lfs diff=lfs merge=lfs -text
16
+ *.pb filter=lfs diff=lfs merge=lfs -text
17
+ *.pt filter=lfs diff=lfs merge=lfs -text
18
+ *.pth filter=lfs diff=lfs merge=lfs -text
19
+ *.rar filter=lfs diff=lfs merge=lfs -text
20
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
21
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
22
+ *.tflite filter=lfs diff=lfs merge=lfs -text
23
+ *.tgz filter=lfs diff=lfs merge=lfs -text
24
+ *.xz filter=lfs diff=lfs merge=lfs -text
25
+ *.zip filter=lfs diff=lfs merge=lfs -text
26
+ *.zstandard filter=lfs diff=lfs merge=lfs -text
27
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,174 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ annotations_creators:
3
+ - expert-generated
4
+ language_creators:
5
+ - found
6
+ languages:
7
+ - pt
8
+ licenses:
9
+ - unknown
10
+ multilinguality:
11
+ - monolingual
12
+ size_categories:
13
+ - n<1K
14
+ source_datasets:
15
+ - original
16
+ task_categories:
17
+ - structure-prediction
18
+ task_ids:
19
+ - named-entity-recognition
20
+ ---
21
+
22
+ # Dataset Card for [Dataset Name]
23
+
24
+ ## Table of Contents
25
+ - [Dataset Description](#dataset-description)
26
+ - [Dataset Summary](#dataset-summary)
27
+ - [Supported Tasks](#supported-tasks-and-leaderboards)
28
+ - [Languages](#languages)
29
+ - [Dataset Structure](#dataset-structure)
30
+ - [Data Instances](#data-instances)
31
+ - [Data Fields](#data-fields)
32
+ - [Data Splits](#data-splits)
33
+ - [Dataset Creation](#dataset-creation)
34
+ - [Curation Rationale](#curation-rationale)
35
+ - [Source Data](#source-data)
36
+ - [Annotations](#annotations)
37
+ - [Personal and Sensitive Information](#personal-and-sensitive-information)
38
+ - [Considerations for Using the Data](#considerations-for-using-the-data)
39
+ - [Social Impact of Dataset](#social-impact-of-dataset)
40
+ - [Discussion of Biases](#discussion-of-biases)
41
+ - [Other Known Limitations](#other-known-limitations)
42
+ - [Additional Information](#additional-information)
43
+ - [Dataset Curators](#dataset-curators)
44
+ - [Licensing Information](#licensing-information)
45
+ - [Citation Information](#citation-information)
46
+
47
+ ## Dataset Description
48
+
49
+ - **Homepage:** [HAREM homepage](https://www.linguateca.pt/primeiroHAREM/harem_coleccaodourada_en.html)
50
+ - **Repository:** [HAREM repository](https://www.linguateca.pt/primeiroHAREM/harem_coleccaodourada_en.html)
51
+ - **Paper:** [HAREM: An Advanced NER Evaluation Contest for Portuguese](http://comum.rcaap.pt/bitstream/10400.26/76/1/SantosSecoCardosoVilelaLREC2006.pdf)
52
+ - **Point of Contact:** [Diana Santos](mailto:diana.santos@sintef.no)
53
+
54
+ ### Dataset Summary
55
+
56
+ The HAREM is a Portuguese language corpus commonly used for Named Entity Recognition tasks. It includes about 93k words, from 129 different texts,
57
+ from several genres, and language varieties. The split of this dataset version follows the division made by [1], where 7% HAREM
58
+ documents are the validation set and the miniHAREM corpus (with about 65k words) is the test set. There are two versions of the dataset set,
59
+ a version that has a total of 10 different named entity classes (Person, Organization, Location, Value, Date, Title, Thing, Event,
60
+ Abstraction, and Other) and a "selective" version with only 5 classes (Person, Organization, Location, Value, and Date).
61
+
62
+ It's important to note that the original version of the HAREM dataset has 2 levels of NER details, namely "Category" and "Sub-type".
63
+ The dataset version processed here ONLY USE the "Category" level of the original dataset.
64
+
65
+ [1] Souza, Fábio, Rodrigo Nogueira, and Roberto Lotufo. "BERTimbau: Pretrained BERT Models for Brazilian Portuguese." Brazilian Conference on Intelligent Systems. Springer, Cham, 2020.
66
+
67
+ ### Supported Tasks and Leaderboards
68
+
69
+ [More Information Needed]
70
+
71
+ ### Languages
72
+
73
+ Portuguese
74
+
75
+ ## Dataset Structure
76
+
77
+ ### Data Instances
78
+
79
+ ```
80
+ {
81
+ "id": "HAREM-871-07800",
82
+ "ner_tags": [3, 0, 0, 3, 4, 4, 4, 4, 4, 4, 4, 4,
83
+ ],
84
+ "tokens": [
85
+ "Abraço", "Página", "Principal", "ASSOCIAÇÃO", "DE", "APOIO", "A", "PESSOAS", "COM", "VIH", "/", "SIDA"
86
+ ]
87
+ }
88
+ ```
89
+
90
+ ### Data Fields
91
+
92
+ - `id`: id of the sample
93
+ - `tokens`: the tokens of the example text
94
+ - `ner_tags`: the NER tags of each token
95
+
96
+ The NER tags correspond to this list:
97
+ ```
98
+ "O", "B-PESSOA", "I-PESSOA", "B-ORGANIZACAO", "I-ORGANIZACAO", "B-LOCAL", "I-LOCAL", "B-TEMPO", "I-TEMPO", "B-VALOR", "I-VALOR", "B-ABSTRACCAO", "I-ABSTRACCAO", "B-ACONTECIMENTO", "I-ACONTECIMENTO", "B-COISA", "I-COISA", "B-OBRA", "I-OBRA", "B-OUTRO", "I-OUTRO"
99
+ ```
100
+
101
+ The NER tags have the same format as in the CoNLL shared task: a B denotes the first item of a phrase and an I any non-initial word.
102
+
103
+ ### Data Splits
104
+
105
+ The data is split into train, validation and test set for each of the two versions (default and selective). The split sizes are as follow:
106
+
107
+ | Train | Val | Test |
108
+ | ------ | ----- | ---- |
109
+ | 121 | 8 | 128 |
110
+
111
+ ## Dataset Creation
112
+
113
+ ### Curation Rationale
114
+
115
+ [More Information Needed]
116
+
117
+ ### Source Data
118
+
119
+ #### Initial Data Collection and Normalization
120
+
121
+ [More Information Needed]
122
+
123
+ #### Who are the source language producers?
124
+
125
+ [More Information Needed]
126
+
127
+ ### Annotations
128
+
129
+ #### Annotation process
130
+
131
+ [More Information Needed]
132
+
133
+ #### Who are the annotators?
134
+
135
+ [More Information Needed]
136
+
137
+ ### Personal and Sensitive Information
138
+
139
+ [More Information Needed]
140
+
141
+ ## Considerations for Using the Data
142
+
143
+ ### Social Impact of Dataset
144
+
145
+ [More Information Needed]
146
+
147
+ ### Discussion of Biases
148
+
149
+ [More Information Needed]
150
+
151
+ ### Other Known Limitations
152
+
153
+ [More Information Needed]
154
+
155
+ ## Additional Information
156
+
157
+ ### Dataset Curators
158
+
159
+ [More Information Needed]
160
+
161
+ ### Licensing Information
162
+
163
+ [More Information Needed]
164
+
165
+ ### Citation Information
166
+
167
+ ```
168
+ @inproceedings{santos2006harem,
169
+ title={Harem: An advanced ner evaluation contest for portuguese},
170
+ author={Santos, Diana and Seco, Nuno and Cardoso, Nuno and Vilela, Rui},
171
+ booktitle={quot; In Nicoletta Calzolari; Khalid Choukri; Aldo Gangemi; Bente Maegaard; Joseph Mariani; Jan Odjik; Daniel Tapias (ed) Proceedings of the 5 th International Conference on Language Resources and Evaluation (LREC'2006)(Genoa Italy 22-28 May 2006)},
172
+ year={2006}
173
+ }
174
+ ```
dataset_infos.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"default": {"description": "\nThe HAREM is a Portuguese language corpus commonly used for Named Entity Recognition tasks. It includes about 93k words, from 129 different texts,\nfrom several genres, and language varieties. The split of this dataset version follows the division made by [1], where 7% HAREM\ndocuments are the validation set and the miniHAREM corpus (with about 65k words) is the test set. There are two versions of the dataset set,\na version that has a total of 10 different named entity classes (Person, Organization, Location, Value, Date, Title, Thing, Event,\nAbstraction, and Other) and a \"selective\" version with only 5 classes (Person, Organization, Location, Value, and Date).\n\nIt's important to note that the original version of the HAREM dataset has 2 levels of NER details, namely \"Category\" and \"Sub-type\".\nThe dataset version processed here ONLY USE the \"Category\" level of the original dataset.\n\n[1] Souza, F\u00e1bio, Rodrigo Nogueira, and Roberto Lotufo. \"BERTimbau: Pretrained BERT Models for Brazilian Portuguese.\" Brazilian Conference on Intelligent Systems. Springer, Cham, 2020.\n", "citation": "\n@inproceedings{santos2006harem,\n title={Harem: An advanced ner evaluation contest for portuguese},\n author={Santos, Diana and Seco, Nuno and Cardoso, Nuno and Vilela, Rui},\n booktitle={quot; In Nicoletta Calzolari; Khalid Choukri; Aldo Gangemi; Bente Maegaard; Joseph Mariani; Jan Odjik; Daniel Tapias (ed) Proceedings of the 5 th International Conference on Language Resources and Evaluation (LREC'2006)(Genoa Italy 22-28 May 2006)},\n year={2006}\n}\n", "homepage": "https://www.linguateca.pt/primeiroHAREM/harem_coleccaodourada_en.html", "license": "", "features": {"id": {"dtype": "string", "id": null, "_type": "Value"}, "tokens": {"feature": {"dtype": "string", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}, "ner_tags": {"feature": {"num_classes": 21, "names": ["O", "B-PESSOA", "I-PESSOA", "B-ORGANIZACAO", "I-ORGANIZACAO", "B-LOCAL", "I-LOCAL", "B-TEMPO", "I-TEMPO", "B-VALOR", "I-VALOR", "B-ABSTRACCAO", "I-ABSTRACCAO", "B-ACONTECIMENTO", "I-ACONTECIMENTO", "B-COISA", "I-COISA", "B-OBRA", "I-OBRA", "B-OUTRO", "I-OUTRO"], "names_file": null, "id": null, "_type": "ClassLabel"}, "length": -1, "id": null, "_type": "Sequence"}}, "post_processed": null, "supervised_keys": null, "builder_name": "harem", "config_name": "default", "version": {"version_str": "1.0.0", "description": null, "major": 1, "minor": 0, "patch": 0}, "splits": {"train": {"name": "train", "num_bytes": 1506373, "num_examples": 121, "dataset_name": "harem"}, "test": {"name": "test", "num_bytes": 1062714, "num_examples": 128, "dataset_name": "harem"}, "validation": {"name": "validation", "num_bytes": 51318, "num_examples": 8, "dataset_name": "harem"}}, "download_checksums": {"https://raw.githubusercontent.com/neuralmind-ai/portuguese-bert/master/ner_evaluation/data/FirstHAREM-total-train.json": {"num_bytes": 1060674, "checksum": "3542944e1e56145c5d1f4df1750df8ec81d0f9e0a7cc0c3e74b0b26df5869763"}, "https://raw.githubusercontent.com/neuralmind-ai/portuguese-bert/master/ner_evaluation/data/FirstHAREM-total-dev.json": {"num_bytes": 47603, "checksum": "a08705c45caef5bdb82b7fe394491de114edb24d14e007a9f3978be030219537"}, "https://raw.githubusercontent.com/neuralmind-ai/portuguese-bert/master/ner_evaluation/data/MiniHAREM-total.json": {"num_bytes": 779004, "checksum": "9a31f28df9664d7de4ceab6f2ec427ad1761463348083d35c7fa97cae87505db"}}, "download_size": 1887281, "post_processing_size": null, "dataset_size": 2620405, "size_in_bytes": 4507686}, "selective": {"description": "\nThe HAREM is a Portuguese language corpus commonly used for Named Entity Recognition tasks. It includes about 93k words, from 129 different texts,\nfrom several genres, and language varieties. The split of this dataset version follows the division made by [1], where 7% HAREM\ndocuments are the validation set and the miniHAREM corpus (with about 65k words) is the test set. There are two versions of the dataset set,\na version that has a total of 10 different named entity classes (Person, Organization, Location, Value, Date, Title, Thing, Event,\nAbstraction, and Other) and a \"selective\" version with only 5 classes (Person, Organization, Location, Value, and Date).\n\nIt's important to note that the original version of the HAREM dataset has 2 levels of NER details, namely \"Category\" and \"Sub-type\".\nThe dataset version processed here ONLY USE the \"Category\" level of the original dataset.\n\n[1] Souza, F\u00e1bio, Rodrigo Nogueira, and Roberto Lotufo. \"BERTimbau: Pretrained BERT Models for Brazilian Portuguese.\" Brazilian Conference on Intelligent Systems. Springer, Cham, 2020.\n", "citation": "\n@inproceedings{santos2006harem,\n title={Harem: An advanced ner evaluation contest for portuguese},\n author={Santos, Diana and Seco, Nuno and Cardoso, Nuno and Vilela, Rui},\n booktitle={quot; In Nicoletta Calzolari; Khalid Choukri; Aldo Gangemi; Bente Maegaard; Joseph Mariani; Jan Odjik; Daniel Tapias (ed) Proceedings of the 5 th International Conference on Language Resources and Evaluation (LREC'2006)(Genoa Italy 22-28 May 2006)},\n year={2006}\n}\n", "homepage": "https://www.linguateca.pt/primeiroHAREM/harem_coleccaodourada_en.html", "license": "", "features": {"id": {"dtype": "string", "id": null, "_type": "Value"}, "tokens": {"feature": {"dtype": "string", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}, "ner_tags": {"feature": {"num_classes": 11, "names": ["O", "B-PESSOA", "I-PESSOA", "B-ORGANIZACAO", "I-ORGANIZACAO", "B-LOCAL", "I-LOCAL", "B-TEMPO", "I-TEMPO", "B-VALOR", "I-VALOR"], "names_file": null, "id": null, "_type": "ClassLabel"}, "length": -1, "id": null, "_type": "Sequence"}}, "post_processed": null, "supervised_keys": null, "builder_name": "harem", "config_name": "selective", "version": {"version_str": "1.0.0", "description": null, "major": 1, "minor": 0, "patch": 0}, "splits": {"train": {"name": "train", "num_bytes": 1506373, "num_examples": 121, "dataset_name": "harem"}, "test": {"name": "test", "num_bytes": 1062714, "num_examples": 128, "dataset_name": "harem"}, "validation": {"name": "validation", "num_bytes": 51318, "num_examples": 8, "dataset_name": "harem"}}, "download_checksums": {"https://raw.githubusercontent.com/neuralmind-ai/portuguese-bert/master/ner_evaluation/data/FirstHAREM-selective-train.json": {"num_bytes": 969734, "checksum": "afb49c5d11116ff297d7abb7657f524917cb5704b221d5e3fb687e064a71e494"}, "https://raw.githubusercontent.com/neuralmind-ai/portuguese-bert/master/ner_evaluation/data/FirstHAREM-selective-dev.json": {"num_bytes": 38988, "checksum": "2ea2d350c587d35b08a86d067f6de27df6e3587339e80d10df787c7443fca7f3"}, "https://raw.githubusercontent.com/neuralmind-ai/portuguese-bert/master/ner_evaluation/data/MiniHAREM-selective.json": {"num_bytes": 707151, "checksum": "7a5d88cf1319ddae1940a02d3fde7dd5841863e05e616cfb2b574613407b7f37"}}, "download_size": 1715873, "post_processing_size": null, "dataset_size": 2620405, "size_in_bytes": 4336278}}
dummy/default/1.0.0/dummy_data.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c24820cb6b58636abc0c1275fb1b02c4897b6cb6ef0bfbf5f99f31a06be5d87f
3
+ size 29509
dummy/selective/1.0.0/dummy_data.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:683f2e657970d34b20dc17fc756474f75ffbffb5d5bd8c2b632ada16312c4315
3
+ size 27902
harem.py ADDED
@@ -0,0 +1,311 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
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
+ """HAREM dataset"""
16
+
17
+ from __future__ import absolute_import, division, print_function
18
+
19
+ import json
20
+ import logging
21
+ import unicodedata
22
+ from typing import List, Tuple
23
+
24
+ import datasets
25
+
26
+
27
+ _CITATION = """
28
+ @inproceedings{santos2006harem,
29
+ title={Harem: An advanced ner evaluation contest for portuguese},
30
+ author={Santos, Diana and Seco, Nuno and Cardoso, Nuno and Vilela, Rui},
31
+ booktitle={quot; In Nicoletta Calzolari; Khalid Choukri; Aldo Gangemi; Bente Maegaard; Joseph Mariani; Jan Odjik; Daniel Tapias (ed) Proceedings of the 5 th International Conference on Language Resources and Evaluation (LREC'2006)(Genoa Italy 22-28 May 2006)},
32
+ year={2006}
33
+ }
34
+ """
35
+
36
+ _DESCRIPTION = """
37
+ The HAREM is a Portuguese language corpus commonly used for Named Entity Recognition tasks. It includes about 93k words, from 129 different texts,
38
+ from several genres, and language varieties. The split of this dataset version follows the division made by [1], where 7% HAREM
39
+ documents are the validation set and the miniHAREM corpus (with about 65k words) is the test set. There are two versions of the dataset set,
40
+ a version that has a total of 10 different named entity classes (Person, Organization, Location, Value, Date, Title, Thing, Event,
41
+ Abstraction, and Other) and a "selective" version with only 5 classes (Person, Organization, Location, Value, and Date).
42
+
43
+ It's important to note that the original version of the HAREM dataset has 2 levels of NER details, namely "Category" and "Sub-type".
44
+ The dataset version processed here ONLY USE the "Category" level of the original dataset.
45
+
46
+ [1] Souza, Fábio, Rodrigo Nogueira, and Roberto Lotufo. "BERTimbau: Pretrained BERT Models for Brazilian Portuguese." Brazilian Conference on Intelligent Systems. Springer, Cham, 2020.
47
+ """
48
+
49
+ _HOMEPAGE = "https://www.linguateca.pt/primeiroHAREM/harem_coleccaodourada_en.html"
50
+
51
+ _LICENSE = ""
52
+
53
+ _URLs = {
54
+ "default": {
55
+ "train": "https://raw.githubusercontent.com/neuralmind-ai/portuguese-bert/master/ner_evaluation/data/FirstHAREM-total-train.json",
56
+ "dev": "https://raw.githubusercontent.com/neuralmind-ai/portuguese-bert/master/ner_evaluation/data/FirstHAREM-total-dev.json",
57
+ "test": "https://raw.githubusercontent.com/neuralmind-ai/portuguese-bert/master/ner_evaluation/data/MiniHAREM-total.json",
58
+ },
59
+ "selective": {
60
+ "train": "https://raw.githubusercontent.com/neuralmind-ai/portuguese-bert/master/ner_evaluation/data/FirstHAREM-selective-train.json",
61
+ "dev": "https://raw.githubusercontent.com/neuralmind-ai/portuguese-bert/master/ner_evaluation/data/FirstHAREM-selective-dev.json",
62
+ "test": "https://raw.githubusercontent.com/neuralmind-ai/portuguese-bert/master/ner_evaluation/data/MiniHAREM-selective.json",
63
+ },
64
+ }
65
+
66
+
67
+ # method extracted from https://github.com/huggingface/transformers/blob/master/src/transformers/tokenization_utils.py#L77-L89
68
+ def _is_punctuation(char):
69
+ """Checks whether `char` is a punctuation character."""
70
+ cp = ord(char)
71
+ # We treat all non-letter/number ASCII as punctuation.
72
+ # Characters such as "^", "$", and "`" are not in the Unicode
73
+ # Punctuation class but we treat them as punctuation anyways, for
74
+ # consistency.
75
+ if (cp >= 33 and cp <= 47) or (cp >= 58 and cp <= 64) or (cp >= 91 and cp <= 96) or (cp >= 123 and cp <= 126):
76
+ return True
77
+ cat = unicodedata.category(char)
78
+ if cat.startswith("P"):
79
+ return True
80
+ return False
81
+
82
+
83
+ # method extracted from https://github.com/huggingface/transformers/blob/master/src/transformers/tokenization_utils.py#L53-L62
84
+ def _is_whitespace(char):
85
+ """Checks whether `char` is a whitespace character."""
86
+ # \t, \n, and \r are technically control characters but we treat them
87
+ # as whitespace since they are generally considered as such.
88
+ if char == " " or char == "\t" or char == "\n" or char == "\r":
89
+ return True
90
+ cat = unicodedata.category(char)
91
+ if cat == "Zs":
92
+ return True
93
+ return False
94
+
95
+
96
+ class Token:
97
+ """Info about a single token."""
98
+
99
+ def __init__(self, text: str, tail: str = ""):
100
+
101
+ if not isinstance(text, str) or not text:
102
+ raise TypeError("text should be a non-empty string.")
103
+ self.text = text
104
+ self.tail = tail
105
+
106
+ def __len__(self):
107
+ return len(self.text) + len(self.tail)
108
+
109
+ def __add__(self, char):
110
+ self.text += char
111
+ return self
112
+
113
+
114
+ def reconstruct_text_from_tokens(tokens: List[Token], include_last_tail: bool = False) -> str:
115
+ """Concatenates the text of a sequence of tokens."""
116
+
117
+ def text_generator(tokens):
118
+ for i, token in enumerate(tokens):
119
+ yield token.text
120
+ if i < len(tokens) - 1 or include_last_tail:
121
+ yield token.tail
122
+
123
+ return "".join(piece for piece in text_generator(tokens))
124
+
125
+
126
+ def tokenize(text: str) -> Tuple[List[Token], List[int]]:
127
+ """ Perform whitespace and punctuation tokenization keeping track of char alignment"""
128
+ doc_tokens = []
129
+ char_to_word_offset = []
130
+
131
+ new_word = True
132
+ curr_token = None
133
+
134
+ def begin_new_token(doc_tokens, text):
135
+ token = Token(text=text)
136
+ doc_tokens.append(token)
137
+ return token
138
+
139
+ for offset, c in enumerate(text):
140
+ if _is_whitespace(c):
141
+ new_word = True
142
+ if curr_token:
143
+ curr_token.tail += c
144
+ else:
145
+ if _is_punctuation(c):
146
+ curr_token = begin_new_token(doc_tokens, c)
147
+ new_word = True
148
+ else:
149
+ if new_word:
150
+ curr_token = begin_new_token(doc_tokens, c)
151
+ else:
152
+ curr_token += c
153
+ new_word = False
154
+
155
+ # OBS: Whitespaces that appear before any tokens will have offset -1
156
+ # char_to_word_offset.append(len(doc_tokens) - 1)
157
+ char_to_word_offset.append(max(0, len(doc_tokens) - 1))
158
+
159
+ return doc_tokens, char_to_word_offset
160
+
161
+
162
+ class HAREM(datasets.GeneratorBasedBuilder):
163
+ """HAREM dataset."""
164
+
165
+ VERSION = datasets.Version("1.0.0")
166
+
167
+ BUILDER_CONFIGS = [
168
+ datasets.BuilderConfig(
169
+ name="default",
170
+ version=VERSION,
171
+ description="All the tags (PESSOA, ORGANIZACAO, LOCAL, TEMPO, VALOR, ABSTRACCAO, ACONTECIMENTO, COISA, OBRA, OUTRO) will be used",
172
+ ),
173
+ datasets.BuilderConfig(
174
+ name="selective",
175
+ version=VERSION,
176
+ description="Only a subset of the tags (PESSOA, ORGANIZACAO, LOCAL, TEMPO, VALOR) will be used",
177
+ ),
178
+ ]
179
+
180
+ DEFAULT_CONFIG_NAME = "default"
181
+
182
+ def _info(self):
183
+
184
+ tags = [
185
+ "O",
186
+ "B-PESSOA",
187
+ "I-PESSOA",
188
+ "B-ORGANIZACAO",
189
+ "I-ORGANIZACAO",
190
+ "B-LOCAL",
191
+ "I-LOCAL",
192
+ "B-TEMPO",
193
+ "I-TEMPO",
194
+ "B-VALOR",
195
+ "I-VALOR",
196
+ ]
197
+
198
+ if self.config.name == "default":
199
+ tags += [
200
+ "B-ABSTRACCAO",
201
+ "I-ABSTRACCAO",
202
+ "B-ACONTECIMENTO",
203
+ "I-ACONTECIMENTO",
204
+ "B-COISA",
205
+ "I-COISA",
206
+ "B-OBRA",
207
+ "I-OBRA",
208
+ "B-OUTRO",
209
+ "I-OUTRO",
210
+ ]
211
+
212
+ features = datasets.Features(
213
+ {
214
+ "id": datasets.Value("string"),
215
+ "tokens": datasets.Sequence(datasets.Value("string")),
216
+ "ner_tags": datasets.Sequence(datasets.features.ClassLabel(names=tags)),
217
+ }
218
+ )
219
+
220
+ return datasets.DatasetInfo(
221
+ description=_DESCRIPTION,
222
+ features=features,
223
+ supervised_keys=None,
224
+ homepage=_HOMEPAGE,
225
+ citation=_CITATION,
226
+ )
227
+
228
+ def _split_generators(self, dl_manager):
229
+ """Returns SplitGenerators."""
230
+
231
+ my_urls = _URLs[self.config.name]
232
+ data_dir = dl_manager.download_and_extract(my_urls)
233
+
234
+ return [
235
+ datasets.SplitGenerator(
236
+ name=datasets.Split.TRAIN,
237
+ gen_kwargs={"filepath": data_dir["train"], "split": "train"},
238
+ ),
239
+ datasets.SplitGenerator(
240
+ name=datasets.Split.TEST,
241
+ gen_kwargs={"filepath": data_dir["test"], "split": "test"},
242
+ ),
243
+ datasets.SplitGenerator(
244
+ name=datasets.Split.VALIDATION,
245
+ gen_kwargs={"filepath": data_dir["dev"], "split": "dev"},
246
+ ),
247
+ ]
248
+
249
+ def _generate_examples(self, filepath, split):
250
+ """ Yields examples. """
251
+
252
+ logging.info("⏳ Generating examples from = %s", filepath)
253
+
254
+ with open(filepath, "r", encoding="utf-8") as f:
255
+
256
+ input_data = json.load(f)
257
+ id_ = 0
258
+
259
+ for document in input_data:
260
+ doc_text = document["doc_text"]
261
+ doc_id = document["doc_id"]
262
+
263
+ doc_tokens, char_to_word_offset = tokenize(doc_text)
264
+ tags = ["O"] * len(doc_tokens)
265
+
266
+ def set_label(index, tag):
267
+ if tags[index] != "O":
268
+ logging.warning(
269
+ "Overwriting tag %s at position %s to %s",
270
+ tags[index],
271
+ index,
272
+ tag,
273
+ )
274
+ tags[index] = tag
275
+
276
+ for entity in document["entities"]:
277
+ entity_text = entity["text"]
278
+ entity_type = entity["label"]
279
+ start_token = None
280
+ end_token = None
281
+
282
+ entity_start_offset = entity["start_offset"]
283
+ entity_end_offset = entity["end_offset"]
284
+ start_token = char_to_word_offset[entity_start_offset]
285
+
286
+ # end_offset is NOT inclusive to the text, e.g.,
287
+ # entity_text == doc_text[start_offset:end_offset]
288
+ end_token = char_to_word_offset[entity_end_offset - 1]
289
+
290
+ assert start_token <= end_token, "End token cannot come before start token."
291
+ reconstructed_text = reconstruct_text_from_tokens(doc_tokens[start_token : (end_token + 1)])
292
+ assert (
293
+ entity_text.strip() == reconstructed_text
294
+ ), "Entity text and reconstructed text are not equal: %s != %s" % (
295
+ entity_text,
296
+ reconstructed_text,
297
+ )
298
+
299
+ for token_index in range(start_token, end_token + 1):
300
+ if token_index == start_token:
301
+ tag = "B-" + entity_type
302
+ else:
303
+ tag = "I-" + entity_type
304
+ set_label(token_index, tag)
305
+
306
+ yield id_, {
307
+ "id": doc_id,
308
+ "tokens": [x.text for x in doc_tokens],
309
+ "ner_tags": tags,
310
+ }
311
+ id_ += 1