Update labels.py
Browse files
labels.py
CHANGED
|
@@ -51,44 +51,68 @@ _CITATION = """\
|
|
| 51 |
_TRAIN_DOWNLOAD_URL = "https://github.com/edubrigham/data/blob/541db4cdbb566aa5909e3eb4904d64f9683e5d4a/yahoo_answers_csv/train.csv"
|
| 52 |
_TEST_DOWNLOAD_URL = "https://github.com/edubrigham/data/blob/541db4cdbb566aa5909e3eb4904d64f9683e5d4a/yahoo_answers_csv/test.csv"
|
| 53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
-
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
def _info(self):
|
| 59 |
return datasets.DatasetInfo(
|
| 60 |
description=_DESCRIPTION,
|
| 61 |
features=datasets.Features(
|
| 62 |
{
|
| 63 |
-
"
|
| 64 |
-
"
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
| 66 |
),
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
task_templates=[TextClassification(text_column="text", label_column="labels")],
|
| 70 |
)
|
|
|
|
| 71 |
|
| 72 |
def _split_generators(self, dl_manager):
|
| 73 |
train_path = dl_manager.download_and_extract(_TRAIN_DOWNLOAD_URL)
|
| 74 |
test_path = dl_manager.download_and_extract(_TEST_DOWNLOAD_URL)
|
| 75 |
return [
|
| 76 |
-
datasets.SplitGenerator(
|
| 77 |
-
|
|
|
|
|
|
|
|
|
|
| 78 |
]
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
""
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
label = int(label) - 1
|
| 92 |
-
text = " ".join((title, description))
|
| 93 |
-
yield id_, {"text": text, "labels": label}
|
| 94 |
|
|
|
|
| 51 |
_TRAIN_DOWNLOAD_URL = "https://github.com/edubrigham/data/blob/541db4cdbb566aa5909e3eb4904d64f9683e5d4a/yahoo_answers_csv/train.csv"
|
| 52 |
_TEST_DOWNLOAD_URL = "https://github.com/edubrigham/data/blob/541db4cdbb566aa5909e3eb4904d64f9683e5d4a/yahoo_answers_csv/test.csv"
|
| 53 |
|
| 54 |
+
_TOPICS = [
|
| 55 |
+
"Society & Culture",
|
| 56 |
+
"Science & Mathematics",
|
| 57 |
+
"Health",
|
| 58 |
+
"Education & Reference",
|
| 59 |
+
"Computers & Internet",
|
| 60 |
+
"Sports",
|
| 61 |
+
"Business & Finance",
|
| 62 |
+
"Entertainment & Music",
|
| 63 |
+
"Family & Relationships",
|
| 64 |
+
"Politics & Government",
|
| 65 |
+
]
|
| 66 |
|
| 67 |
+
|
| 68 |
+
class YahooAnswersTopics(datasets.GeneratorBasedBuilder):
|
| 69 |
+
"Yahoo! Answers Topic Classification Dataset"
|
| 70 |
+
|
| 71 |
+
VERSION = datasets.Version("1.0.0")
|
| 72 |
+
BUILDER_CONFIGS = [
|
| 73 |
+
datasets.BuilderConfig(
|
| 74 |
+
name="yahoo_answers_topics",
|
| 75 |
+
version=datasets.Version("1.0.0", ""),
|
| 76 |
+
),
|
| 77 |
+
]
|
| 78 |
|
| 79 |
def _info(self):
|
| 80 |
return datasets.DatasetInfo(
|
| 81 |
description=_DESCRIPTION,
|
| 82 |
features=datasets.Features(
|
| 83 |
{
|
| 84 |
+
"id": datasets.Value("int32"),
|
| 85 |
+
"topic": datasets.features.ClassLabel(names=_TOPICS),
|
| 86 |
+
"question_title": datasets.Value("string"),
|
| 87 |
+
"question_content": datasets.Value("string"),
|
| 88 |
+
"best_answer": datasets.Value("string"),
|
| 89 |
+
},
|
| 90 |
),
|
| 91 |
+
supervised_keys=None,
|
| 92 |
+
homepage="https://github.com/LC-John/Yahoo-Answers-Topic-Classification-Dataset",
|
|
|
|
| 93 |
)
|
| 94 |
+
|
| 95 |
|
| 96 |
def _split_generators(self, dl_manager):
|
| 97 |
train_path = dl_manager.download_and_extract(_TRAIN_DOWNLOAD_URL)
|
| 98 |
test_path = dl_manager.download_and_extract(_TEST_DOWNLOAD_URL)
|
| 99 |
return [
|
| 100 |
+
datasets.SplitGenerator(
|
| 101 |
+
name=datasets.Split.TRAIN, gen_kwargs={"filepath": train_path}
|
| 102 |
+
),
|
| 103 |
+
datasets.SplitGenerator(
|
| 104 |
+
name=datasets.Split.TEST, gen_kwargs={"filepath": test_path}),
|
| 105 |
]
|
| 106 |
+
|
| 107 |
+
def _generate_examples(self, filepath):
|
| 108 |
+
with open(filepath, encoding="utf-8") as f:
|
| 109 |
+
rows = csv.reader(f)
|
| 110 |
+
for i, row in enumerate(rows):
|
| 111 |
+
yield i, {
|
| 112 |
+
"id": i,
|
| 113 |
+
"topic": int(row[0]) - 1,
|
| 114 |
+
"question_title": row[1],
|
| 115 |
+
"question_content": row[2],
|
| 116 |
+
"best_answer": row[3],
|
| 117 |
+
}
|
|
|
|
|
|
|
|
|
|
| 118 |
|