Datasets:
Tasks:
Other
Modalities:
Text
Sub-tasks:
named-entity-recognition
Languages:
Polish
Size:
10K - 100K
Tags:
structure-prediction
License:
File size: 7,790 Bytes
b194823 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
# coding=utf-8
# Copyright 2021 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Lint as: python3
"""KPWR-NER tagging dataset."""
import csv
from typing import List, Tuple, Dict, Generator
import datasets
_DESCRIPTION = """KPWR-NER tagging dataset."""
_URLS = {
"train": "https://huggingface.co/datasets/clarin-pl/kpwr-ner/resolve/main/data/kpwr-ner-n82-train-tune.iob",
"test": "https://huggingface.co/datasets/clarin-pl/kpwr-ner/resolve/main/data/kpwr-ner-n82-test.iob",
}
_HOMEPAGE = "https://clarin-pl.eu/dspace/handle/11321/294"
_NER_TAGS = [
"B-nam_adj",
"B-nam_adj_city",
"B-nam_adj_country",
"B-nam_adj_person",
"B-nam_eve",
"B-nam_eve_human",
"B-nam_eve_human_cultural",
"B-nam_eve_human_holiday",
"B-nam_eve_human_sport",
"B-nam_fac_bridge",
"B-nam_fac_goe",
"B-nam_fac_goe_stop",
"B-nam_fac_park",
"B-nam_fac_road",
"B-nam_fac_square",
"B-nam_fac_system",
"B-nam_liv_animal",
"B-nam_liv_character",
"B-nam_liv_god",
"B-nam_liv_habitant",
"B-nam_liv_person",
"B-nam_loc",
"B-nam_loc_astronomical",
"B-nam_loc_country_region",
"B-nam_loc_gpe_admin1",
"B-nam_loc_gpe_admin2",
"B-nam_loc_gpe_admin3",
"B-nam_loc_gpe_city",
"B-nam_loc_gpe_conurbation",
"B-nam_loc_gpe_country",
"B-nam_loc_gpe_district",
"B-nam_loc_gpe_subdivision",
"B-nam_loc_historical_region",
"B-nam_loc_hydronym",
"B-nam_loc_hydronym_lake",
"B-nam_loc_hydronym_ocean",
"B-nam_loc_hydronym_river",
"B-nam_loc_hydronym_sea",
"B-nam_loc_land",
"B-nam_loc_land_continent",
"B-nam_loc_land_island",
"B-nam_loc_land_mountain",
"B-nam_loc_land_peak",
"B-nam_loc_land_region",
"B-nam_num_house",
"B-nam_num_phone",
"B-nam_org_company",
"B-nam_org_group",
"B-nam_org_group_band",
"B-nam_org_group_team",
"B-nam_org_institution",
"B-nam_org_nation",
"B-nam_org_organization",
"B-nam_org_organization_sub",
"B-nam_org_political_party",
"B-nam_oth",
"B-nam_oth_currency",
"B-nam_oth_data_format",
"B-nam_oth_license",
"B-nam_oth_position",
"B-nam_oth_tech",
"B-nam_oth_www",
"B-nam_pro",
"B-nam_pro_award",
"B-nam_pro_brand",
"B-nam_pro_media",
"B-nam_pro_media_periodic",
"B-nam_pro_media_radio",
"B-nam_pro_media_tv",
"B-nam_pro_media_web",
"B-nam_pro_model_car",
"B-nam_pro_software",
"B-nam_pro_software_game",
"B-nam_pro_title",
"B-nam_pro_title_album",
"B-nam_pro_title_article",
"B-nam_pro_title_book",
"B-nam_pro_title_document",
"B-nam_pro_title_song",
"B-nam_pro_title_treaty",
"B-nam_pro_title_tv",
"B-nam_pro_vehicle",
"I-nam_adj_country",
"I-nam_eve",
"I-nam_eve_human",
"I-nam_eve_human_cultural",
"I-nam_eve_human_holiday",
"I-nam_eve_human_sport",
"I-nam_fac_bridge",
"I-nam_fac_goe",
"I-nam_fac_goe_stop",
"I-nam_fac_park",
"I-nam_fac_road",
"I-nam_fac_square",
"I-nam_fac_system",
"I-nam_liv_animal",
"I-nam_liv_character",
"I-nam_liv_god",
"I-nam_liv_person",
"I-nam_loc",
"I-nam_loc_astronomical",
"I-nam_loc_country_region",
"I-nam_loc_gpe_admin1",
"I-nam_loc_gpe_admin2",
"I-nam_loc_gpe_admin3",
"I-nam_loc_gpe_city",
"I-nam_loc_gpe_conurbation",
"I-nam_loc_gpe_country",
"I-nam_loc_gpe_district",
"I-nam_loc_gpe_subdivision",
"I-nam_loc_historical_region",
"I-nam_loc_hydronym",
"I-nam_loc_hydronym_lake",
"I-nam_loc_hydronym_ocean",
"I-nam_loc_hydronym_river",
"I-nam_loc_hydronym_sea",
"I-nam_loc_land",
"I-nam_loc_land_continent",
"I-nam_loc_land_island",
"I-nam_loc_land_mountain",
"I-nam_loc_land_peak",
"I-nam_loc_land_region",
"I-nam_num_house",
"I-nam_num_phone",
"I-nam_org_company",
"I-nam_org_group",
"I-nam_org_group_band",
"I-nam_org_group_team",
"I-nam_org_institution",
"I-nam_org_nation",
"I-nam_org_organization",
"I-nam_org_organization_sub",
"I-nam_org_political_party",
"I-nam_oth",
"I-nam_oth_currency",
"I-nam_oth_data_format",
"I-nam_oth_license",
"I-nam_oth_position",
"I-nam_oth_tech",
"I-nam_oth_www",
"I-nam_pro",
"I-nam_pro_award",
"I-nam_pro_brand",
"I-nam_pro_media",
"I-nam_pro_media_periodic",
"I-nam_pro_media_radio",
"I-nam_pro_media_tv",
"I-nam_pro_media_web",
"I-nam_pro_model_car",
"I-nam_pro_software",
"I-nam_pro_software_game",
"I-nam_pro_title",
"I-nam_pro_title_album",
"I-nam_pro_title_article",
"I-nam_pro_title_book",
"I-nam_pro_title_document",
"I-nam_pro_title_song",
"I-nam_pro_title_treaty",
"I-nam_pro_title_tv",
"I-nam_pro_vehicle",
"O",
]
class KPWRNER(datasets.GeneratorBasedBuilder):
def _info(self) -> datasets.DatasetInfo:
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{
"tokens": datasets.Sequence(datasets.Value("string")),
"lemmas": datasets.Sequence(datasets.Value("string")),
"orth": datasets.Sequence(datasets.Value("string")),
"ner": datasets.Sequence(
datasets.features.ClassLabel(
names=_NER_TAGS, num_classes=len(_NER_TAGS)
)
),
}
),
homepage=_HOMEPAGE,
)
def _split_generators(
self, dl_manager: datasets.DownloadManager
) -> List[datasets.SplitGenerator]:
urls_to_download = _URLS
downloaded_files = dl_manager.download_and_extract(urls_to_download)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={"filepath": downloaded_files["train"]},
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={"filepath": downloaded_files["test"]},
),
]
def _generate_examples(
self, filepath: str
) -> Generator[Tuple[int, Dict[str, str]], None, None]:
with open(filepath, "r", encoding="utf-8") as f:
reader = csv.reader(f, delimiter="\t", quoting=csv.QUOTE_NONE)
tokens = []
lemma = []
orth = []
ner = []
gid = 0
for line in reader:
if not line:
yield gid, {
"tokens": tokens,
"lemmas": lemma,
"orth": orth,
"ner": ner,
}
gid += 1
tokens = []
lemma = []
orth = []
ner = []
elif len(line) == 1: # ignore DOCS
continue
else:
tokens.append(line[0])
lemma.append(line[1])
orth.append(line[2])
ner.append(line[3])
|