Delete FromTo.py
Browse files
FromTo.py
DELETED
|
@@ -1,164 +0,0 @@
|
|
| 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 |
-
"""The FromTo Emerging Entities Dataset."""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
import datasets
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
logger = datasets.logging.get_logger(__name__)
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
_CITATION = """\
|
| 27 |
-
@inproceedings{derczynski-etal-2017-results,
|
| 28 |
-
title = "Results of the {WNUT}2017 Shared Task on Novel and Emerging Entity Recognition",
|
| 29 |
-
author = "Derczynski, Leon and
|
| 30 |
-
Nichols, Eric and
|
| 31 |
-
van Erp, Marieke and
|
| 32 |
-
Limsopatham, Nut",
|
| 33 |
-
booktitle = "Proceedings of the 3rd Workshop on Noisy User-generated Text",
|
| 34 |
-
month = sep,
|
| 35 |
-
year = "2017",
|
| 36 |
-
address = "Copenhagen, Denmark",
|
| 37 |
-
publisher = "Association for Computational Linguistics",
|
| 38 |
-
url = "https://www.aclweb.org/anthology/W17-4418",
|
| 39 |
-
doi = "10.18653/v1/W17-4418",
|
| 40 |
-
pages = "140--147",
|
| 41 |
-
abstract = "This shared task focuses on identifying unusual, previously-unseen entities in the context of emerging discussions.
|
| 42 |
-
Named entities form the basis of many modern approaches to other tasks (like event clustering and summarization),
|
| 43 |
-
but recall on them is a real problem in noisy text - even among annotators.
|
| 44 |
-
This drop tends to be due to novel entities and surface forms.
|
| 45 |
-
Take for example the tweet {``}so.. kktny in 30 mins?!{''} {--} even human experts find the entity {`}kktny{'}
|
| 46 |
-
hard to detect and resolve. The goal of this task is to provide a definition of emerging and of rare entities,
|
| 47 |
-
and based on that, also datasets for detecting these entities. The task as described in this paper evaluated the
|
| 48 |
-
ability of participating entries to detect and classify novel and emerging named entities in noisy text.",
|
| 49 |
-
}
|
| 50 |
-
"""
|
| 51 |
-
|
| 52 |
-
_DESCRIPTION = """\
|
| 53 |
-
WNUT 17: Emerging and Rare entity recognition
|
| 54 |
-
This shared task focuses on identifying unusual, previously-unseen entities in the context of emerging discussions.
|
| 55 |
-
Named entities form the basis of many modern approaches to other tasks (like event clustering and summarisation),
|
| 56 |
-
but recall on them is a real problem in noisy text - even among annotators. This drop tends to be due to novel entities and surface forms.
|
| 57 |
-
Take for example the tweet “so.. kktny in 30 mins?” - even human experts find entity kktny hard to detect and resolve.
|
| 58 |
-
This task will evaluate the ability to detect and classify novel, emerging, singleton named entities in noisy text.
|
| 59 |
-
The goal of this task is to provide a definition of emerging and of rare entities, and based on that, also datasets for detecting these entities.
|
| 60 |
-
"""
|
| 61 |
-
|
| 62 |
-
_URL = "https://raw.githubusercontent.com/stephaneDoss/emerging_entities_fromTo/main/"
|
| 63 |
-
_TRAINING_FILE = "train.conll"
|
| 64 |
-
_DEV_FILE = "dev.conll"
|
| 65 |
-
_TEST_FILE = "test.conll"
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
class FromToConfig(datasets.BuilderConfig):
|
| 69 |
-
"""The FromTo Emerging Entities Dataset."""
|
| 70 |
-
|
| 71 |
-
def __init__(self, **kwargs):
|
| 72 |
-
"""BuilderConfig for FromTo.
|
| 73 |
-
Args:
|
| 74 |
-
**kwargs: keyword arguments forwarded to super.
|
| 75 |
-
"""
|
| 76 |
-
super(FromToConfig, self).__init__(**kwargs)
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
class FromTo(datasets.GeneratorBasedBuilder):
|
| 80 |
-
"""The FromTo Emerging Entities Dataset."""
|
| 81 |
-
|
| 82 |
-
BUILDER_CONFIGS = [
|
| 83 |
-
FromToConfig(
|
| 84 |
-
name="FromTo", version=datasets.Version("1.0.0"), description="The FromTo Emerging Entities Dataset"
|
| 85 |
-
),
|
| 86 |
-
]
|
| 87 |
-
|
| 88 |
-
def _info(self):
|
| 89 |
-
return datasets.DatasetInfo(
|
| 90 |
-
description=_DESCRIPTION,
|
| 91 |
-
features=datasets.Features(
|
| 92 |
-
{
|
| 93 |
-
"id": datasets.Value("string"),
|
| 94 |
-
"tokens": datasets.Sequence(datasets.Value("string")),
|
| 95 |
-
"ner_tags": datasets.Sequence(
|
| 96 |
-
datasets.features.ClassLabel(
|
| 97 |
-
names=[
|
| 98 |
-
"O",
|
| 99 |
-
"B-depart",
|
| 100 |
-
"I-depart",
|
| 101 |
-
"B-arrive",
|
| 102 |
-
"I-arrive",
|
| 103 |
-
]
|
| 104 |
-
)
|
| 105 |
-
),
|
| 106 |
-
}
|
| 107 |
-
),
|
| 108 |
-
supervised_keys=None,
|
| 109 |
-
homepage="http://noisy-text.github.io/2017/emerging-rare-entities.html",
|
| 110 |
-
citation=_CITATION,
|
| 111 |
-
)
|
| 112 |
-
|
| 113 |
-
def _split_generators(self, dl_manager):
|
| 114 |
-
"""Returns SplitGenerators."""
|
| 115 |
-
urls_to_download = {
|
| 116 |
-
"train": f"{_URL}{_TRAINING_FILE}",
|
| 117 |
-
"dev": f"{_URL}{_DEV_FILE}",
|
| 118 |
-
"test": f"{_URL}{_TRAINING_FILE}",
|
| 119 |
-
}
|
| 120 |
-
downloaded_files = dl_manager.download_and_extract(urls_to_download)
|
| 121 |
-
|
| 122 |
-
return [
|
| 123 |
-
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
|
| 124 |
-
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["dev"]}),
|
| 125 |
-
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}),
|
| 126 |
-
]
|
| 127 |
-
|
| 128 |
-
def _generate_examples(self, filepath):
|
| 129 |
-
logger.info("⏳ Generating examples from = %s", filepath)
|
| 130 |
-
with open(filepath, encoding="utf-8") as f:
|
| 131 |
-
current_tokens = []
|
| 132 |
-
current_labels = []
|
| 133 |
-
sentence_counter = 0
|
| 134 |
-
for row in f:
|
| 135 |
-
row = row.rstrip()
|
| 136 |
-
if row:
|
| 137 |
-
token, label = row.split("\t")
|
| 138 |
-
current_tokens.append(token)
|
| 139 |
-
current_labels.append(label)
|
| 140 |
-
else:
|
| 141 |
-
# New sentence
|
| 142 |
-
if not current_tokens:
|
| 143 |
-
# Consecutive empty lines will cause empty sentences
|
| 144 |
-
continue
|
| 145 |
-
assert len(current_tokens) == len(current_labels), "💔 between len of tokens & labels"
|
| 146 |
-
sentence = (
|
| 147 |
-
sentence_counter,
|
| 148 |
-
{
|
| 149 |
-
"id": str(sentence_counter),
|
| 150 |
-
"tokens": current_tokens,
|
| 151 |
-
"ner_tags": current_labels,
|
| 152 |
-
},
|
| 153 |
-
)
|
| 154 |
-
sentence_counter += 1
|
| 155 |
-
current_tokens = []
|
| 156 |
-
current_labels = []
|
| 157 |
-
yield sentence
|
| 158 |
-
# Don't forget last sentence in dataset 🧐
|
| 159 |
-
if current_tokens:
|
| 160 |
-
yield sentence_counter, {
|
| 161 |
-
"id": str(sentence_counter),
|
| 162 |
-
"tokens": current_tokens,
|
| 163 |
-
"ner_tags": current_labels,
|
| 164 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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