Update labels.py
Browse files
labels.py
CHANGED
|
@@ -1,5 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The 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.
|
|
@@ -12,87 +61,83 @@
|
|
| 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 |
|
| 17 |
|
| 18 |
import csv
|
| 19 |
-
import os
|
| 20 |
|
| 21 |
import datasets
|
|
|
|
| 22 |
|
| 23 |
|
| 24 |
-
_DESCRIPTION = """
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
"""
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
class YahooAnswersTopics(datasets.GeneratorBasedBuilder):
|
| 48 |
-
"Yahoo! Answers Topic Classification Dataset"
|
| 49 |
-
|
| 50 |
-
VERSION = datasets.Version("1.0.0")
|
| 51 |
-
BUILDER_CONFIGS = [
|
| 52 |
-
datasets.BuilderConfig(
|
| 53 |
-
name="yahoo_answers_topics",
|
| 54 |
-
version=datasets.Version("1.0.0", ""),
|
| 55 |
-
),
|
| 56 |
-
]
|
| 57 |
|
| 58 |
def _info(self):
|
| 59 |
return datasets.DatasetInfo(
|
| 60 |
description=_DESCRIPTION,
|
| 61 |
features=datasets.Features(
|
| 62 |
{
|
| 63 |
-
"
|
| 64 |
-
"
|
| 65 |
-
|
| 66 |
-
"question_content": datasets.Value("string"),
|
| 67 |
-
"best_answer": datasets.Value("string"),
|
| 68 |
-
},
|
| 69 |
),
|
| 70 |
-
|
| 71 |
-
|
|
|
|
| 72 |
)
|
| 73 |
|
| 74 |
def _split_generators(self, dl_manager):
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
# Extracting (un-taring) the training data
|
| 78 |
-
data_dir = os.path.join(data_dir, "yahoo_answers_csv")
|
| 79 |
return [
|
| 80 |
-
datasets.SplitGenerator(
|
| 81 |
-
|
| 82 |
-
),
|
| 83 |
-
datasets.SplitGenerator(
|
| 84 |
-
name=datasets.Split.TEST, gen_kwargs={"filepath": os.path.join(data_dir, "test.csv")}
|
| 85 |
-
),
|
| 86 |
]
|
| 87 |
|
| 88 |
def _generate_examples(self, filepath):
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Hugging Face's logo
|
| 2 |
+
Hugging Face
|
| 3 |
+
Search models, datasets, users...
|
| 4 |
+
Models
|
| 5 |
+
Datasets
|
| 6 |
+
Spaces
|
| 7 |
+
Docs
|
| 8 |
+
Solutions
|
| 9 |
+
Pricing
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
Datasets:
|
| 13 |
+
ag_news Copied
|
| 14 |
+
like
|
| 15 |
+
11
|
| 16 |
+
Tasks:
|
| 17 |
+
topic-classification
|
| 18 |
+
Task Categories:
|
| 19 |
+
text-classification
|
| 20 |
+
Languages:
|
| 21 |
+
en
|
| 22 |
+
Multilinguality:
|
| 23 |
+
monolingual
|
| 24 |
+
Size Categories:
|
| 25 |
+
100K<n<1M
|
| 26 |
+
Licenses:
|
| 27 |
+
unknown
|
| 28 |
+
Language Creators:
|
| 29 |
+
found
|
| 30 |
+
Annotations Creators:
|
| 31 |
+
found
|
| 32 |
+
Source Datasets:
|
| 33 |
+
original
|
| 34 |
+
Dataset card
|
| 35 |
+
Files and versions
|
| 36 |
+
ag_news
|
| 37 |
+
/
|
| 38 |
+
ag_news.py
|
| 39 |
+
system's picture
|
| 40 |
+
system
|
| 41 |
+
HF STAFF
|
| 42 |
+
Update files from the datasets library (from 1.8.0)
|
| 43 |
+
bb6b9e5
|
| 44 |
+
about 2 months ago
|
| 45 |
+
raw
|
| 46 |
+
history
|
| 47 |
+
blame
|
| 48 |
+
Safe
|
| 49 |
+
3.97 kB
|
| 50 |
# coding=utf-8
|
| 51 |
+
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 52 |
#
|
| 53 |
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 54 |
# you may not use this file except in compliance with the License.
|
|
|
|
| 61 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 62 |
# See the License for the specific language governing permissions and
|
| 63 |
# limitations under the License.
|
| 64 |
+
|
| 65 |
+
# Lint as: python3
|
| 66 |
+
"""AG News topic classification dataset."""
|
| 67 |
|
| 68 |
|
| 69 |
import csv
|
|
|
|
| 70 |
|
| 71 |
import datasets
|
| 72 |
+
from datasets.tasks import TextClassification
|
| 73 |
|
| 74 |
|
| 75 |
+
_DESCRIPTION = """\
|
| 76 |
+
AG is a collection of more than 1 million news articles. News articles have been
|
| 77 |
+
gathered from more than 2000 news sources by ComeToMyHead in more than 1 year of
|
| 78 |
+
activity. ComeToMyHead is an academic news search engine which has been running
|
| 79 |
+
since July, 2004. The dataset is provided by the academic comunity for research
|
| 80 |
+
purposes in data mining (clustering, classification, etc), information retrieval
|
| 81 |
+
(ranking, search, etc), xml, data compression, data streaming, and any other
|
| 82 |
+
non-commercial activity. For more information, please refer to the link
|
| 83 |
+
http://www.di.unipi.it/~gulli/AG_corpus_of_news_articles.html .
|
| 84 |
+
The AG's news topic classification dataset is constructed by Xiang Zhang
|
| 85 |
+
(xiang.zhang@nyu.edu) from the dataset above. It is used as a text
|
| 86 |
+
classification benchmark in the following paper: Xiang Zhang, Junbo Zhao, Yann
|
| 87 |
+
LeCun. Character-level Convolutional Networks for Text Classification. Advances
|
| 88 |
+
in Neural Information Processing Systems 28 (NIPS 2015).
|
| 89 |
"""
|
| 90 |
|
| 91 |
+
_CITATION = """\
|
| 92 |
+
@inproceedings{Zhang2015CharacterlevelCN,
|
| 93 |
+
title={Character-level Convolutional Networks for Text Classification},
|
| 94 |
+
author={Xiang Zhang and Junbo Jake Zhao and Yann LeCun},
|
| 95 |
+
booktitle={NIPS},
|
| 96 |
+
year={2015}
|
| 97 |
+
}
|
| 98 |
+
"""
|
| 99 |
+
|
| 100 |
+
_TRAIN_DOWNLOAD_URL = "https://github.com/edubrigham/data/blob/541db4cdbb566aa5909e3eb4904d64f9683e5d4a/yahoo_answers_csv/train.csv"
|
| 101 |
+
_TEST_DOWNLOAD_URL = "https://github.com/edubrigham/data/blob/541db4cdbb566aa5909e3eb4904d64f9683e5d4a/yahoo_answers_csv/test.csv"
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
class AGNews(datasets.GeneratorBasedBuilder):
|
| 105 |
+
"""AG News topic classification dataset."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
|
| 107 |
def _info(self):
|
| 108 |
return datasets.DatasetInfo(
|
| 109 |
description=_DESCRIPTION,
|
| 110 |
features=datasets.Features(
|
| 111 |
{
|
| 112 |
+
"text": datasets.Value("string"),
|
| 113 |
+
"label": datasets.features.ClassLabel(names=[""Society & Culture", "Science & Mathematics", "Health","Education & Reference","Computers & Internet","Sports","Business & Finance","Entertainment & Music","Family & Relationships","Politics & Government"]),
|
| 114 |
+
}
|
|
|
|
|
|
|
|
|
|
| 115 |
),
|
| 116 |
+
homepage="http://groups.di.unipi.it/~gulli/AG_corpus_of_news_articles.html",
|
| 117 |
+
citation=_CITATION,
|
| 118 |
+
task_templates=[TextClassification(text_column="text", label_column="label")],
|
| 119 |
)
|
| 120 |
|
| 121 |
def _split_generators(self, dl_manager):
|
| 122 |
+
train_path = dl_manager.download_and_extract(_TRAIN_DOWNLOAD_URL)
|
| 123 |
+
test_path = dl_manager.download_and_extract(_TEST_DOWNLOAD_URL)
|
|
|
|
|
|
|
| 124 |
return [
|
| 125 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": train_path}),
|
| 126 |
+
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": test_path}),
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
]
|
| 128 |
|
| 129 |
def _generate_examples(self, filepath):
|
| 130 |
+
"""Generate AG News examples."""
|
| 131 |
+
with open(filepath, encoding="utf-8") as csv_file:
|
| 132 |
+
csv_reader = csv.reader(
|
| 133 |
+
csv_file, quotechar='"', delimiter=",", quoting=csv.QUOTE_ALL, skipinitialspace=True
|
| 134 |
+
)
|
| 135 |
+
for id_, row in enumerate(csv_reader):
|
| 136 |
+
label, title, description = row
|
| 137 |
+
# Original labels are [1, 2, 3, 4] ->
|
| 138 |
+
# ['World', 'Sports', 'Business', 'Sci/Tech']
|
| 139 |
+
# Re-map to [0, 1, 2, 3].
|
| 140 |
+
label = int(label) - 1
|
| 141 |
+
text = " ".join((title, description))
|
| 142 |
+
yield id_, {"text": text, "label": label}
|
| 143 |
+
|