Update testaunic23.py
Browse files- testaunic23.py +158 -158
testaunic23.py
CHANGED
|
@@ -1,159 +1,159 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 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 |
-
"""test testaunic23"""
|
| 18 |
-
|
| 19 |
-
import logging
|
| 20 |
-
|
| 21 |
-
import datasets
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
_CITATION = """\
|
| 25 |
-
test testaunic23
|
| 26 |
-
"""
|
| 27 |
-
|
| 28 |
-
_DESCRIPTION = """\
|
| 29 |
-
test testaunic23
|
| 30 |
-
"""
|
| 31 |
-
|
| 32 |
-
_URL = "https://
|
| 33 |
-
_TRAINING_FILE = "train.txt"
|
| 34 |
-
_DEV_FILE = "dev.txt"
|
| 35 |
-
_TEST_FILE = "test.txt"
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
class testaunic23Config(datasets.BuilderConfig):
|
| 39 |
-
"""BuilderConfig for testaunic23"""
|
| 40 |
-
|
| 41 |
-
def __init__(self, **kwargs):
|
| 42 |
-
"""BuilderConfig for testaunic23.
|
| 43 |
-
Args:
|
| 44 |
-
**kwargs: keyword arguments forwarded to super.
|
| 45 |
-
"""
|
| 46 |
-
super(testaunic23Config, self).__init__(**kwargs)
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
class testaunic23(datasets.GeneratorBasedBuilder):
|
| 50 |
-
"""testaunic23 dataset."""
|
| 51 |
-
|
| 52 |
-
BUILDER_CONFIGS = [
|
| 53 |
-
testaunic23Config(name="testaunic23", version=datasets.Version("1.0.0"), description="testaunic23 dataset"),
|
| 54 |
-
]
|
| 55 |
-
|
| 56 |
-
def _info(self):
|
| 57 |
-
return datasets.DatasetInfo(
|
| 58 |
-
description=_DESCRIPTION,
|
| 59 |
-
features=datasets.Features(
|
| 60 |
-
{
|
| 61 |
-
"id": datasets.Value("string"),
|
| 62 |
-
"document_id": datasets.Value("int32"),
|
| 63 |
-
"sentence_id": datasets.Value("int32"),
|
| 64 |
-
"tokens": datasets.Sequence(datasets.Value("string")),
|
| 65 |
-
"pos_tags": datasets.Sequence(
|
| 66 |
-
datasets.features.ClassLabel(
|
| 67 |
-
names=[
|
| 68 |
-
"-X-"
|
| 69 |
-
]
|
| 70 |
-
)
|
| 71 |
-
),
|
| 72 |
-
"ner_tags": datasets.Sequence(
|
| 73 |
-
datasets.features.ClassLabel(
|
| 74 |
-
names=[
|
| 75 |
-
"O",
|
| 76 |
-
"B-ENTITY",
|
| 77 |
-
"I-ENTITY",
|
| 78 |
-
"B-SYSTEM",
|
| 79 |
-
"I-SYSTEM",
|
| 80 |
-
"B-DOCUMENT",
|
| 81 |
-
"I-DOCUMENT",
|
| 82 |
-
"B-ORG",
|
| 83 |
-
"I-ORG",
|
| 84 |
-
"B-LOC",
|
| 85 |
-
"I-LOC"
|
| 86 |
-
]
|
| 87 |
-
)
|
| 88 |
-
),
|
| 89 |
-
}
|
| 90 |
-
),
|
| 91 |
-
supervised_keys=None,
|
| 92 |
-
homepage="",
|
| 93 |
-
citation=_CITATION,
|
| 94 |
-
)
|
| 95 |
-
|
| 96 |
-
def _split_generators(self, dl_manager):
|
| 97 |
-
"""Returns SplitGenerators."""
|
| 98 |
-
urls_to_download = {
|
| 99 |
-
"train": f"{_URL}{_TRAINING_FILE}",
|
| 100 |
-
"dev": f"{_URL}{_DEV_FILE}",
|
| 101 |
-
"test": f"{_URL}{_TEST_FILE}",
|
| 102 |
-
}
|
| 103 |
-
downloaded_files = dl_manager.download_and_extract(urls_to_download)
|
| 104 |
-
|
| 105 |
-
return [
|
| 106 |
-
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
|
| 107 |
-
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["dev"]}),
|
| 108 |
-
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}),
|
| 109 |
-
]
|
| 110 |
-
|
| 111 |
-
def _generate_examples(self, filepath):
|
| 112 |
-
logging.info("⏳ Generating examples from = %s", filepath)
|
| 113 |
-
with open(filepath, encoding="utf-8") as f:
|
| 114 |
-
guid = 0
|
| 115 |
-
document_id = 0
|
| 116 |
-
sentence_id = 0
|
| 117 |
-
tokens = []
|
| 118 |
-
pos_tags = []
|
| 119 |
-
chunk_tags = []
|
| 120 |
-
ner_tags = []
|
| 121 |
-
for line in f:
|
| 122 |
-
if line.startswith("-DOCSTART-") or line == "" or line == "\n":
|
| 123 |
-
if line.startswith("-DOCSTART-"):
|
| 124 |
-
document_id += 1
|
| 125 |
-
sentence_id = 0
|
| 126 |
-
if tokens:
|
| 127 |
-
yield guid, {
|
| 128 |
-
"id": str(guid),
|
| 129 |
-
"document_id": document_id,
|
| 130 |
-
"sentence_id": sentence_id,
|
| 131 |
-
"tokens": tokens,
|
| 132 |
-
"pos_tags": pos_tags,
|
| 133 |
-
"chunk_tags": chunk_tags,
|
| 134 |
-
"ner_tags": ner_tags,
|
| 135 |
-
}
|
| 136 |
-
sentence_id += 1
|
| 137 |
-
guid += 1
|
| 138 |
-
tokens = []
|
| 139 |
-
pos_tags = []
|
| 140 |
-
chunk_tags = []
|
| 141 |
-
ner_tags = []
|
| 142 |
-
else:
|
| 143 |
-
# conll2003 tokens are space separated
|
| 144 |
-
splits = line.split(" ")
|
| 145 |
-
tokens.append(splits[0])
|
| 146 |
-
pos_tags.append(splits[1])
|
| 147 |
-
chunk_tags.append(splits[2])
|
| 148 |
-
ner_tags.append(splits[3].rstrip())
|
| 149 |
-
# last example
|
| 150 |
-
if tokens:
|
| 151 |
-
yield guid, {
|
| 152 |
-
"id": str(guid),
|
| 153 |
-
"document_id": document_id,
|
| 154 |
-
"sentence_id": sentence_id,
|
| 155 |
-
"tokens": tokens,
|
| 156 |
-
"pos_tags": pos_tags,
|
| 157 |
-
"chunk_tags": chunk_tags,
|
| 158 |
-
"ner_tags": ner_tags,
|
| 159 |
}
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
# Copyright 2020 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 |
+
"""test testaunic23"""
|
| 18 |
+
|
| 19 |
+
import logging
|
| 20 |
+
|
| 21 |
+
import datasets
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
_CITATION = """\
|
| 25 |
+
test testaunic23
|
| 26 |
+
"""
|
| 27 |
+
|
| 28 |
+
_DESCRIPTION = """\
|
| 29 |
+
test testaunic23
|
| 30 |
+
"""
|
| 31 |
+
|
| 32 |
+
_URL = "https://raw.githubusercontent.com/andreyokamura-unicamp/test_dataset/refs/heads/main/"
|
| 33 |
+
_TRAINING_FILE = "train.txt"
|
| 34 |
+
_DEV_FILE = "dev.txt"
|
| 35 |
+
_TEST_FILE = "test.txt"
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
class testaunic23Config(datasets.BuilderConfig):
|
| 39 |
+
"""BuilderConfig for testaunic23"""
|
| 40 |
+
|
| 41 |
+
def __init__(self, **kwargs):
|
| 42 |
+
"""BuilderConfig for testaunic23.
|
| 43 |
+
Args:
|
| 44 |
+
**kwargs: keyword arguments forwarded to super.
|
| 45 |
+
"""
|
| 46 |
+
super(testaunic23Config, self).__init__(**kwargs)
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
class testaunic23(datasets.GeneratorBasedBuilder):
|
| 50 |
+
"""testaunic23 dataset."""
|
| 51 |
+
|
| 52 |
+
BUILDER_CONFIGS = [
|
| 53 |
+
testaunic23Config(name="testaunic23", version=datasets.Version("1.0.0"), description="testaunic23 dataset"),
|
| 54 |
+
]
|
| 55 |
+
|
| 56 |
+
def _info(self):
|
| 57 |
+
return datasets.DatasetInfo(
|
| 58 |
+
description=_DESCRIPTION,
|
| 59 |
+
features=datasets.Features(
|
| 60 |
+
{
|
| 61 |
+
"id": datasets.Value("string"),
|
| 62 |
+
"document_id": datasets.Value("int32"),
|
| 63 |
+
"sentence_id": datasets.Value("int32"),
|
| 64 |
+
"tokens": datasets.Sequence(datasets.Value("string")),
|
| 65 |
+
"pos_tags": datasets.Sequence(
|
| 66 |
+
datasets.features.ClassLabel(
|
| 67 |
+
names=[
|
| 68 |
+
"-X-"
|
| 69 |
+
]
|
| 70 |
+
)
|
| 71 |
+
),
|
| 72 |
+
"ner_tags": datasets.Sequence(
|
| 73 |
+
datasets.features.ClassLabel(
|
| 74 |
+
names=[
|
| 75 |
+
"O",
|
| 76 |
+
"B-ENTITY",
|
| 77 |
+
"I-ENTITY",
|
| 78 |
+
"B-SYSTEM",
|
| 79 |
+
"I-SYSTEM",
|
| 80 |
+
"B-DOCUMENT",
|
| 81 |
+
"I-DOCUMENT",
|
| 82 |
+
"B-ORG",
|
| 83 |
+
"I-ORG",
|
| 84 |
+
"B-LOC",
|
| 85 |
+
"I-LOC"
|
| 86 |
+
]
|
| 87 |
+
)
|
| 88 |
+
),
|
| 89 |
+
}
|
| 90 |
+
),
|
| 91 |
+
supervised_keys=None,
|
| 92 |
+
homepage="",
|
| 93 |
+
citation=_CITATION,
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
+
def _split_generators(self, dl_manager):
|
| 97 |
+
"""Returns SplitGenerators."""
|
| 98 |
+
urls_to_download = {
|
| 99 |
+
"train": f"{_URL}{_TRAINING_FILE}",
|
| 100 |
+
"dev": f"{_URL}{_DEV_FILE}",
|
| 101 |
+
"test": f"{_URL}{_TEST_FILE}",
|
| 102 |
+
}
|
| 103 |
+
downloaded_files = dl_manager.download_and_extract(urls_to_download)
|
| 104 |
+
|
| 105 |
+
return [
|
| 106 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
|
| 107 |
+
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["dev"]}),
|
| 108 |
+
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}),
|
| 109 |
+
]
|
| 110 |
+
|
| 111 |
+
def _generate_examples(self, filepath):
|
| 112 |
+
logging.info("⏳ Generating examples from = %s", filepath)
|
| 113 |
+
with open(filepath, encoding="utf-8") as f:
|
| 114 |
+
guid = 0
|
| 115 |
+
document_id = 0
|
| 116 |
+
sentence_id = 0
|
| 117 |
+
tokens = []
|
| 118 |
+
pos_tags = []
|
| 119 |
+
chunk_tags = []
|
| 120 |
+
ner_tags = []
|
| 121 |
+
for line in f:
|
| 122 |
+
if line.startswith("-DOCSTART-") or line == "" or line == "\n":
|
| 123 |
+
if line.startswith("-DOCSTART-"):
|
| 124 |
+
document_id += 1
|
| 125 |
+
sentence_id = 0
|
| 126 |
+
if tokens:
|
| 127 |
+
yield guid, {
|
| 128 |
+
"id": str(guid),
|
| 129 |
+
"document_id": document_id,
|
| 130 |
+
"sentence_id": sentence_id,
|
| 131 |
+
"tokens": tokens,
|
| 132 |
+
"pos_tags": pos_tags,
|
| 133 |
+
"chunk_tags": chunk_tags,
|
| 134 |
+
"ner_tags": ner_tags,
|
| 135 |
+
}
|
| 136 |
+
sentence_id += 1
|
| 137 |
+
guid += 1
|
| 138 |
+
tokens = []
|
| 139 |
+
pos_tags = []
|
| 140 |
+
chunk_tags = []
|
| 141 |
+
ner_tags = []
|
| 142 |
+
else:
|
| 143 |
+
# conll2003 tokens are space separated
|
| 144 |
+
splits = line.split(" ")
|
| 145 |
+
tokens.append(splits[0])
|
| 146 |
+
pos_tags.append(splits[1])
|
| 147 |
+
chunk_tags.append(splits[2])
|
| 148 |
+
ner_tags.append(splits[3].rstrip())
|
| 149 |
+
# last example
|
| 150 |
+
if tokens:
|
| 151 |
+
yield guid, {
|
| 152 |
+
"id": str(guid),
|
| 153 |
+
"document_id": document_id,
|
| 154 |
+
"sentence_id": sentence_id,
|
| 155 |
+
"tokens": tokens,
|
| 156 |
+
"pos_tags": pos_tags,
|
| 157 |
+
"chunk_tags": chunk_tags,
|
| 158 |
+
"ner_tags": ner_tags,
|
| 159 |
}
|