Datasets:
Tasks:
Token Classification
Sub-tasks:
named-entity-recognition
Update wikiann.py
Browse files- wikiann.py +100 -0
wikiann.py
CHANGED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
""" NER dataset compiled by T-NER library https://github.com/asahi417/tner/tree/master/tner """
|
| 2 |
+
import json
|
| 3 |
+
from itertools import chain
|
| 4 |
+
import datasets
|
| 5 |
+
|
| 6 |
+
logger = datasets.logging.get_logger(__name__)
|
| 7 |
+
_DESCRIPTION = """[WikiAnn](https://aclanthology.org/P17-1178/)"""
|
| 8 |
+
_NAME = "wikiann"
|
| 9 |
+
_VERSION = "1.0.0"
|
| 10 |
+
_CITATION = """
|
| 11 |
+
@inproceedings{pan-etal-2017-cross,
|
| 12 |
+
title = "Cross-lingual Name Tagging and Linking for 282 Languages",
|
| 13 |
+
author = "Pan, Xiaoman and
|
| 14 |
+
Zhang, Boliang and
|
| 15 |
+
May, Jonathan and
|
| 16 |
+
Nothman, Joel and
|
| 17 |
+
Knight, Kevin and
|
| 18 |
+
Ji, Heng",
|
| 19 |
+
booktitle = "Proceedings of the 55th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers)",
|
| 20 |
+
month = jul,
|
| 21 |
+
year = "2017",
|
| 22 |
+
address = "Vancouver, Canada",
|
| 23 |
+
publisher = "Association for Computational Linguistics",
|
| 24 |
+
url = "https://aclanthology.org/P17-1178",
|
| 25 |
+
doi = "10.18653/v1/P17-1178",
|
| 26 |
+
pages = "1946--1958",
|
| 27 |
+
abstract = "The ambitious goal of this work is to develop a cross-lingual name tagging and linking framework for 282 languages that exist in Wikipedia. Given a document in any of these languages, our framework is able to identify name mentions, assign a coarse-grained or fine-grained type to each mention, and link it to an English Knowledge Base (KB) if it is linkable. We achieve this goal by performing a series of new KB mining methods: generating {``}silver-standard{''} annotations by transferring annotations from English to other languages through cross-lingual links and KB properties, refining annotations through self-training and topic selection, deriving language-specific morphology features from anchor links, and mining word translation pairs from cross-lingual links. Both name tagging and linking results for 282 languages are promising on Wikipedia data and on-Wikipedia data.",
|
| 28 |
+
}
|
| 29 |
+
"""
|
| 30 |
+
|
| 31 |
+
_HOME_PAGE = "https://github.com/asahi417/tner"
|
| 32 |
+
_URL = f'https://huggingface.co/datasets/tner/{_NAME}/raw/main/dataset'
|
| 33 |
+
_LANGUAGE = ["ace", "bg", "da", "fur", "ilo", "lij", "mzn", "qu", "su", "vi", "af", "bh", "de", "fy", "io", "lmo", "nap",
|
| 34 |
+
"rm", "sv", "vls", "als", "bn", "diq", "ga", "is", "ln", "nds", "ro", "sw", "vo", "am", "bo", "dv", "gan", "it",
|
| 35 |
+
"lt", "ne", "ru", "szl", "wa", "an", "br", "el", "gd", "ja", "lv", "nl", "rw", "ta", "war", "ang", "bs", "eml",
|
| 36 |
+
"gl", "jbo", "map-bms", "nn", "sa", "te", "wuu", "ar", "ca", "en", "gn", "jv", "mg", "no", "sah", "tg", "xmf",
|
| 37 |
+
"arc", "cbk-zam", "eo", "gu", "ka", "mhr", "nov", "scn", "th", "yi", "arz", "cdo", "es", "hak", "kk", "mi",
|
| 38 |
+
"oc", "sco", "tk", "yo", "as", "ce", "et", "he", "km", "min", "or", "sd", "tl", "zea", "ast", "ceb", "eu", "hi",
|
| 39 |
+
"kn", "mk", "os", "sh", "tr", "zh-classical", "ay", "ckb", "ext", "hr", "ko", "ml", "pa", "si", "tt",
|
| 40 |
+
"zh-min-nan", "az", "co", "fa", "hsb", "ksh", "mn", "pdc", "simple", "ug", "zh-yue", "ba", "crh", "fi", "hu",
|
| 41 |
+
"ku", "mr", "pl", "sk", "uk", "zh", "bar", "cs", "fiu-vro", "hy", "ky", "ms", "pms", "sl", "ur", "bat-smg",
|
| 42 |
+
"csb", "fo", "ia", "la", "mt", "pnb", "so", "uz", "be-x-old", "cv", "fr", "id", "lb", "mwl", "ps", "sq", "vec",
|
| 43 |
+
"be", "cy", "frr", "ig", "li", "my", "pt", "sr", "vep"]
|
| 44 |
+
_URLS = {
|
| 45 |
+
l: {
|
| 46 |
+
str(datasets.Split.TEST): [f'{_URL}/{l}/test.jsonl'],
|
| 47 |
+
str(datasets.Split.TRAIN): [f'{_URL}/{l}/train.jsonl'],
|
| 48 |
+
str(datasets.Split.VALIDATION): [f'{_URL}/{l}/dev.jsonl']
|
| 49 |
+
} for l in _LANGUAGE
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
class WikiAnnConfig(datasets.BuilderConfig):
|
| 54 |
+
"""BuilderConfig"""
|
| 55 |
+
|
| 56 |
+
def __init__(self, **kwargs):
|
| 57 |
+
"""BuilderConfig.
|
| 58 |
+
|
| 59 |
+
Args:
|
| 60 |
+
**kwargs: keyword arguments forwarded to super.
|
| 61 |
+
"""
|
| 62 |
+
super(WikiAnnConfig, self).__init__(**kwargs)
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
class WikiAnn(datasets.GeneratorBasedBuilder):
|
| 66 |
+
"""Dataset."""
|
| 67 |
+
|
| 68 |
+
BUILDER_CONFIGS = [
|
| 69 |
+
WikiAnnConfig(name=l, version=datasets.Version(_VERSION), description=f"{_DESCRIPTION} (language: {l})") for l in _LANGUAGE
|
| 70 |
+
]
|
| 71 |
+
|
| 72 |
+
def _split_generators(self, dl_manager):
|
| 73 |
+
downloaded_file = dl_manager.download_and_extract(_URLS[self.config.name])
|
| 74 |
+
return [datasets.SplitGenerator(name=i, gen_kwargs={"filepaths": downloaded_file[str(i)]})
|
| 75 |
+
for i in [datasets.Split.TRAIN, datasets.Split.VALIDATION, datasets.Split.TEST]]
|
| 76 |
+
|
| 77 |
+
def _generate_examples(self, filepaths):
|
| 78 |
+
_key = 0
|
| 79 |
+
for filepath in filepaths:
|
| 80 |
+
logger.info(f"generating examples from = {filepath}")
|
| 81 |
+
with open(filepath, encoding="utf-8") as f:
|
| 82 |
+
_list = [i for i in f.read().split('\n') if len(i) > 0]
|
| 83 |
+
for i in _list:
|
| 84 |
+
data = json.loads(i)
|
| 85 |
+
yield _key, data
|
| 86 |
+
_key += 1
|
| 87 |
+
|
| 88 |
+
def _info(self):
|
| 89 |
+
return datasets.DatasetInfo(
|
| 90 |
+
description=_DESCRIPTION,
|
| 91 |
+
features=datasets.Features(
|
| 92 |
+
{
|
| 93 |
+
"tokens": datasets.Sequence(datasets.Value("string")),
|
| 94 |
+
"tags": datasets.Sequence(datasets.Value("int32")),
|
| 95 |
+
}
|
| 96 |
+
),
|
| 97 |
+
supervised_keys=None,
|
| 98 |
+
homepage=_HOME_PAGE,
|
| 99 |
+
citation=_CITATION,
|
| 100 |
+
)
|