Datasets:
Tasks:
Token Classification
Modalities:
Text
Sub-tasks:
named-entity-recognition
Languages:
English
Size:
1K - 10K
License:
add reader for BTC
Browse files- broad_twitter_corpus.py +165 -0
- dataset_infos.json +1 -0
broad_twitter_corpus.py
ADDED
@@ -0,0 +1,165 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
"""Introduction to the CoNLL-2003 Shared Task: Language-Independent Named Entity Recognition"""
|
18 |
+
|
19 |
+
import os
|
20 |
+
|
21 |
+
import datasets
|
22 |
+
|
23 |
+
|
24 |
+
logger = datasets.logging.get_logger(__name__)
|
25 |
+
|
26 |
+
|
27 |
+
_CITATION = """\
|
28 |
+
@inproceedings{derczynski2016broad,
|
29 |
+
title={Broad twitter corpus: A diverse named entity recognition resource},
|
30 |
+
author={Derczynski, Leon and Bontcheva, Kalina and Roberts, Ian},
|
31 |
+
booktitle={Proceedings of COLING 2016, the 26th International Conference on Computational Linguistics: Technical Papers},
|
32 |
+
pages={1169--1179},
|
33 |
+
year={2016}
|
34 |
+
}
|
35 |
+
"""
|
36 |
+
|
37 |
+
_DESCRIPTION = """\
|
38 |
+
This is the Broad Twitter corpus, a dataset of tweets collected over stratified times, places and social uses.
|
39 |
+
The goal is to represent a broad range of activities, giving a dataset more representative of the language used
|
40 |
+
in this hardest of social media formats to process. Further, the BTC is annotated for named entities.
|
41 |
+
|
42 |
+
For more details see [https://aclanthology.org/C16-1111/](https://aclanthology.org/C16-1111/)
|
43 |
+
"""
|
44 |
+
|
45 |
+
_URL = "https://github.com/GateNLP/broad_twitter_corpus/archive/refs/heads/master.zip"
|
46 |
+
_subpath = "broad_twitter_corpus-master/"
|
47 |
+
_A_FILE = _subpath + "a.conll"
|
48 |
+
_B_FILE = _subpath + "b.conll"
|
49 |
+
_E_FILE = _subpath + "e.conll"
|
50 |
+
_F_FILE = _subpath + "f.conll"
|
51 |
+
_G_FILE = _subpath + "g.conll"
|
52 |
+
_H_FILE = _subpath + "h.conll"
|
53 |
+
|
54 |
+
# _TRAINING_FILE = "train.txt"
|
55 |
+
_DEV_FILE = _H_FILE
|
56 |
+
_TEST_FILE = _F_FILE
|
57 |
+
|
58 |
+
|
59 |
+
class BroadTwitterCorpusConfig(datasets.BuilderConfig):
|
60 |
+
"""BuilderConfig for BroadTwitterCorpus"""
|
61 |
+
|
62 |
+
def __init__(self, **kwargs):
|
63 |
+
"""BuilderConfig for BroadTwitterCorpus.
|
64 |
+
|
65 |
+
Args:
|
66 |
+
**kwargs: keyword arguments forwarded to super.
|
67 |
+
"""
|
68 |
+
super(BroadTwitterCorpusConfig, self).__init__(**kwargs)
|
69 |
+
|
70 |
+
|
71 |
+
class BroadTwitterCorpus(datasets.GeneratorBasedBuilder):
|
72 |
+
"""BroadTwitterCorpus dataset."""
|
73 |
+
|
74 |
+
BUILDER_CONFIGS = [
|
75 |
+
BroadTwitterCorpusConfig(name="broad-twitter-corpus", version=datasets.Version("1.0.0"), description="Broad Twitter Corpus"),
|
76 |
+
]
|
77 |
+
|
78 |
+
def _info(self):
|
79 |
+
return datasets.DatasetInfo(
|
80 |
+
description=_DESCRIPTION,
|
81 |
+
features=datasets.Features(
|
82 |
+
{
|
83 |
+
"id": datasets.Value("string"),
|
84 |
+
"tokens": datasets.Sequence(datasets.Value("string")),
|
85 |
+
"ner_tags": datasets.Sequence(
|
86 |
+
datasets.features.ClassLabel(
|
87 |
+
names=[
|
88 |
+
"O",
|
89 |
+
"B-PER",
|
90 |
+
"I-PER",
|
91 |
+
"B-ORG",
|
92 |
+
"I-ORG",
|
93 |
+
"B-LOC",
|
94 |
+
"I-LOC",
|
95 |
+
]
|
96 |
+
)
|
97 |
+
),
|
98 |
+
}
|
99 |
+
),
|
100 |
+
supervised_keys=None,
|
101 |
+
homepage="https://aclanthology.org/C16-1111/",
|
102 |
+
citation=_CITATION,
|
103 |
+
)
|
104 |
+
|
105 |
+
def _split_generators(self, dl_manager):
|
106 |
+
"""Returns SplitGenerators."""
|
107 |
+
downloaded_file = dl_manager.download_and_extract(_URL)
|
108 |
+
|
109 |
+
data_files = {
|
110 |
+
"a": os.path.join(downloaded_file, _A_FILE),
|
111 |
+
"b": os.path.join(downloaded_file, _B_FILE),
|
112 |
+
"e": os.path.join(downloaded_file, _E_FILE),
|
113 |
+
"f": os.path.join(downloaded_file, _F_FILE),
|
114 |
+
"g": os.path.join(downloaded_file, _G_FILE),
|
115 |
+
"h": os.path.join(downloaded_file, _H_FILE),
|
116 |
+
"dev": os.path.join(downloaded_file, _DEV_FILE),
|
117 |
+
"test": os.path.join(downloaded_file, _TEST_FILE),
|
118 |
+
}
|
119 |
+
|
120 |
+
"""
|
121 |
+
btc_section_a = datasets.SplitGenerator(name="BTC_A", gen_kwargs={"filepath": data_files["a"]})
|
122 |
+
btc_section_b = datasets.SplitGenerator(name="BTC_B", gen_kwargs={"filepath": data_files["b"]})
|
123 |
+
btc_section_e = datasets.SplitGenerator(name="BTC_E", gen_kwargs={"filepath": data_files["e"]})
|
124 |
+
btc_section_f = datasets.SplitGenerator(name="BTC_F", gen_kwargs={"filepath": data_files["f"]})
|
125 |
+
btc_section_g = datasets.SplitGenerator(name="BTC_G", gen_kwargs={"filepath": data_files["g"]})
|
126 |
+
btc_section_h = datasets.SplitGenerator(name="BTC_H", gen_kwargs={"filepath": data_files["h"]})
|
127 |
+
"""
|
128 |
+
return [
|
129 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN,
|
130 |
+
gen_kwargs={"filepaths": [data_files['a'], data_files['b'], data_files['e'], data_files['g']]}
|
131 |
+
),
|
132 |
+
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepaths": [data_files["dev"]]}),
|
133 |
+
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepaths": [data_files["test"]]}),
|
134 |
+
]
|
135 |
+
|
136 |
+
def _generate_examples(self, filepaths):
|
137 |
+
guid = 0
|
138 |
+
for filepath in filepaths:
|
139 |
+
with open(filepath, encoding="utf-8") as f:
|
140 |
+
logger.info("⏳ Generating examples from = %s", filepath)
|
141 |
+
tokens = []
|
142 |
+
ner_tags = []
|
143 |
+
for line in f:
|
144 |
+
if line.startswith("-DOCSTART-") or line.strip() == "" or line == "\n":
|
145 |
+
if tokens:
|
146 |
+
yield guid, {
|
147 |
+
"id": str(guid),
|
148 |
+
"tokens": tokens,
|
149 |
+
"ner_tags": ner_tags,
|
150 |
+
}
|
151 |
+
guid += 1
|
152 |
+
tokens = []
|
153 |
+
ner_tags = []
|
154 |
+
else:
|
155 |
+
# btc entries are tab separated
|
156 |
+
fields = line.split("\t")
|
157 |
+
tokens.append(fields[0])
|
158 |
+
ner_tags.append(fields[1].rstrip())
|
159 |
+
# last example
|
160 |
+
yield guid, {
|
161 |
+
"id": str(guid),
|
162 |
+
"tokens": tokens,
|
163 |
+
"ner_tags": ner_tags,
|
164 |
+
}
|
165 |
+
guid += 1 # for when files roll over
|
dataset_infos.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"broad-twitter-corpus": {"description": "This is the Broad Twitter corpus, a dataset of tweets collected over stratified times, places and social uses. \nThe goal is to represent a broad range of activities, giving a dataset more representative of the language used \nin this hardest of social media formats to process. Further, the BTC is annotated for named entities.\n\nFor more details see [https://aclanthology.org/C16-1111/](https://aclanthology.org/C16-1111/)\n", "citation": "@inproceedings{derczynski2016broad,\n title={Broad twitter corpus: A diverse named entity recognition resource},\n author={Derczynski, Leon and Bontcheva, Kalina and Roberts, Ian},\n booktitle={Proceedings of COLING 2016, the 26th International Conference on Computational Linguistics: Technical Papers},\n pages={1169--1179},\n year={2016}\n}\n", "homepage": "https://aclanthology.org/C16-1111/", "license": "", "features": {"id": {"dtype": "string", "id": null, "_type": "Value"}, "tokens": {"feature": {"dtype": "string", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}, "ner_tags": {"feature": {"num_classes": 7, "names": ["O", "B-PER", "I-PER", "B-ORG", "I-ORG", "B-LOC", "I-LOC"], "id": null, "_type": "ClassLabel"}, "length": -1, "id": null, "_type": "Sequence"}}, "post_processed": null, "supervised_keys": null, "task_templates": null, "builder_name": "broad_twitter_corpus", "config_name": "broad-twitter-corpus", "version": {"version_str": "1.0.0", "description": null, "major": 1, "minor": 0, "patch": 0}, "splits": {"train": {"name": "train", "num_bytes": 1522066, "num_examples": 5342, "dataset_name": "broad_twitter_corpus"}, "validation": {"name": "validation", "num_bytes": 514159, "num_examples": 2002, "dataset_name": "broad_twitter_corpus"}, "test": {"name": "test", "num_bytes": 621542, "num_examples": 2002, "dataset_name": "broad_twitter_corpus"}}, "download_checksums": {"https://github.com/GateNLP/broad_twitter_corpus/archive/refs/heads/master.zip": {"num_bytes": 39344594, "checksum": "4e1d1a7d0d9e7563f5df2adf078c25a7305ab6a5e74eadae123881e4d175a12f"}}, "download_size": 39344594, "post_processing_size": null, "dataset_size": 2657767, "size_in_bytes": 42002361}}
|