Datasets:
Tasks:
Token Classification
Modalities:
Text
Formats:
parquet
Sub-tasks:
named-entity-recognition
Languages:
Kazakh
Size:
100K - 1M
License:
Delete the script
Browse files- ner-kazakh.py +0 -158
ner-kazakh.py
DELETED
|
@@ -1,158 +0,0 @@
|
|
| 1 |
-
"""ner_kazakh"""
|
| 2 |
-
|
| 3 |
-
import os
|
| 4 |
-
import re
|
| 5 |
-
|
| 6 |
-
import datasets
|
| 7 |
-
|
| 8 |
-
logger = datasets.logging.get_logger(__name__)
|
| 9 |
-
|
| 10 |
-
_CITATION = """\
|
| 11 |
-
"""
|
| 12 |
-
|
| 13 |
-
_DESCRIPTION = "ner_kazakh"
|
| 14 |
-
_URL = "./"
|
| 15 |
-
_TRAINING_FILE = "ner_kazakh_train.txt"
|
| 16 |
-
_DEV_FILE = "ner_kazakh_valid.txt"
|
| 17 |
-
_TEST_FILE = "ner_kazakh_test.txt"
|
| 18 |
-
|
| 19 |
-
class ner_kazakhConfig(datasets.BuilderConfig):
|
| 20 |
-
"""BuilderConfig for ner_kazakh"""
|
| 21 |
-
|
| 22 |
-
def __init__(self, **kwargs):
|
| 23 |
-
"""BuilderConfig for ner_kazakh.
|
| 24 |
-
Args:
|
| 25 |
-
**kwargs: keyword arguments forwarded to super.
|
| 26 |
-
"""
|
| 27 |
-
super(ner_kazakhConfig, self).__init__(**kwargs)
|
| 28 |
-
|
| 29 |
-
class ner_kazakh(datasets.GeneratorBasedBuilder):
|
| 30 |
-
"""ner_kazakh dataset."""
|
| 31 |
-
|
| 32 |
-
BUILDER_CONFIGS = [
|
| 33 |
-
ner_kazakhConfig(name = "ner_kazakh", version = datasets.Version("1.0.0"), description = "ner_kazakh"),
|
| 34 |
-
]
|
| 35 |
-
|
| 36 |
-
def _info(self):
|
| 37 |
-
return datasets.DatasetInfo(
|
| 38 |
-
description =_DESCRIPTION,
|
| 39 |
-
features = datasets.Features(
|
| 40 |
-
{
|
| 41 |
-
"index": datasets.Value("string"),
|
| 42 |
-
"sentence_id": datasets.Value("string"),
|
| 43 |
-
"tokens": datasets.Sequence(datasets.Value("string")),
|
| 44 |
-
"ner_tags": datasets.Sequence(
|
| 45 |
-
datasets.features.ClassLabel(
|
| 46 |
-
names = [
|
| 47 |
-
"O",
|
| 48 |
-
"B-ADAGE",
|
| 49 |
-
"I-ADAGE",
|
| 50 |
-
"B-ART",
|
| 51 |
-
"I-ART",
|
| 52 |
-
"B-CARDINAL",
|
| 53 |
-
"I-CARDINAL",
|
| 54 |
-
"B-CONTACT",
|
| 55 |
-
"I-CONTACT",
|
| 56 |
-
"B-DATE",
|
| 57 |
-
"I-DATE",
|
| 58 |
-
"B-DISEASE",
|
| 59 |
-
"I-DISEASE",
|
| 60 |
-
"B-EVENT",
|
| 61 |
-
"I-EVENT",
|
| 62 |
-
"B-FACILITY",
|
| 63 |
-
"I-FACILITY",
|
| 64 |
-
"B-GPE",
|
| 65 |
-
"I-GPE",
|
| 66 |
-
"B-LANGUAGE",
|
| 67 |
-
"I-LANGUAGE",
|
| 68 |
-
"B-LAW",
|
| 69 |
-
"I-LAW",
|
| 70 |
-
"B-LOCATION",
|
| 71 |
-
"I-LOCATION",
|
| 72 |
-
"B-MISCELLANEOUS",
|
| 73 |
-
"I-MISCELLANEOUS",
|
| 74 |
-
"B-MONEY",
|
| 75 |
-
"I-MONEY",
|
| 76 |
-
"B-NON_HUMAN",
|
| 77 |
-
"I-NON_HUMAN",
|
| 78 |
-
"B-NORP",
|
| 79 |
-
"I-NORP",
|
| 80 |
-
"B-ORDINAL",
|
| 81 |
-
"I-ORDINAL",
|
| 82 |
-
"B-ORGANISATION",
|
| 83 |
-
"I-ORGANISATION",
|
| 84 |
-
"B-PERSON",
|
| 85 |
-
"I-PERSON",
|
| 86 |
-
"B-PERCENTAGE",
|
| 87 |
-
"I-PERCENTAGE",
|
| 88 |
-
"B-POSITION",
|
| 89 |
-
"I-POSITION",
|
| 90 |
-
"B-PRODUCT",
|
| 91 |
-
"I-PRODUCT",
|
| 92 |
-
"B-PROJECT",
|
| 93 |
-
"I-PROJECT",
|
| 94 |
-
"B-QUANTITY",
|
| 95 |
-
"I-QUANTITY",
|
| 96 |
-
"B-TIME",
|
| 97 |
-
"I-TIME",
|
| 98 |
-
]
|
| 99 |
-
)
|
| 100 |
-
),
|
| 101 |
-
}
|
| 102 |
-
),
|
| 103 |
-
supervised_keys = None,
|
| 104 |
-
homepage = "",
|
| 105 |
-
citation = _CITATION,
|
| 106 |
-
)
|
| 107 |
-
|
| 108 |
-
def _split_generators(self, dl_manager):
|
| 109 |
-
"""Returns SplitGenerators."""
|
| 110 |
-
data_files = {
|
| 111 |
-
"train": f"{_URL}{_TRAINING_FILE}",
|
| 112 |
-
"dev": f"{_URL}{_DEV_FILE}",
|
| 113 |
-
"test": f"{_URL}{_TEST_FILE}",
|
| 114 |
-
}
|
| 115 |
-
downloaded_files = dl_manager.download_and_extract(data_files)
|
| 116 |
-
|
| 117 |
-
return [
|
| 118 |
-
datasets.SplitGenerator(name = datasets.Split.TRAIN, gen_kwargs = {"filepath": downloaded_files["train"]}),
|
| 119 |
-
datasets.SplitGenerator(name = datasets.Split.VALIDATION, gen_kwargs = {"filepath": downloaded_files["dev"]}),
|
| 120 |
-
datasets.SplitGenerator(name = datasets.Split.TEST, gen_kwargs = {"filepath": downloaded_files["test"]}),
|
| 121 |
-
]
|
| 122 |
-
|
| 123 |
-
def _generate_examples(self, filepath):
|
| 124 |
-
logger.info("⏳ Generating examples from = %s", filepath)
|
| 125 |
-
with open(filepath, encoding="utf-8") as f:
|
| 126 |
-
index = 0
|
| 127 |
-
sent_ids = []
|
| 128 |
-
tokens = []
|
| 129 |
-
ner_tags = []
|
| 130 |
-
for line in f:
|
| 131 |
-
if line.startswith("-DOCSTART-") or line == "" or line == "\n":
|
| 132 |
-
if tokens:
|
| 133 |
-
yield index, {
|
| 134 |
-
"index": str(index),
|
| 135 |
-
"sentence_id": sent_ids,
|
| 136 |
-
"tokens": tokens,
|
| 137 |
-
"ner_tags": ner_tags,
|
| 138 |
-
}
|
| 139 |
-
index += 1
|
| 140 |
-
sent_ids = []
|
| 141 |
-
tokens = []
|
| 142 |
-
ner_tags = []
|
| 143 |
-
else:
|
| 144 |
-
# ner_kazakh tokens are space separated
|
| 145 |
-
splits = line.split(" ")
|
| 146 |
-
if re.match(r"[A-Z]{3}\d{6}[A-Z]{3}", line):
|
| 147 |
-
sent_ids.append(splits[0])
|
| 148 |
-
else:
|
| 149 |
-
tokens.append(splits[0])
|
| 150 |
-
ner_tags.append(splits[1].rstrip())
|
| 151 |
-
# last example
|
| 152 |
-
if tokens:
|
| 153 |
-
yield index, {
|
| 154 |
-
"index": str(index),
|
| 155 |
-
"sentence_id": sent_ids,
|
| 156 |
-
"tokens": tokens,
|
| 157 |
-
"ner_tags": ner_tags,
|
| 158 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|