Update labels.py
Browse files
labels.py
CHANGED
|
@@ -50,7 +50,18 @@ _CITATION = """\
|
|
| 50 |
_TRAIN_DOWNLOAD_URL = "https://github.com/edubrigham/data/blob/541db4cdbb566aa5909e3eb4904d64f9683e5d4a/yahoo_answers_csv/train.csv"
|
| 51 |
_TEST_DOWNLOAD_URL = "https://github.com/edubrigham/data/blob/541db4cdbb566aa5909e3eb4904d64f9683e5d4a/yahoo_answers_csv/test.csv"
|
| 52 |
|
| 53 |
-
_TOPICS = [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
class AGNews(datasets.GeneratorBasedBuilder):
|
| 56 |
"""AG News topic classification dataset."""
|
|
@@ -60,10 +71,15 @@ class AGNews(datasets.GeneratorBasedBuilder):
|
|
| 60 |
description=_DESCRIPTION,
|
| 61 |
features=datasets.Features(
|
| 62 |
{
|
| 63 |
-
"
|
| 64 |
-
"
|
| 65 |
-
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
)
|
| 68 |
|
| 69 |
def _split_generators(self, dl_manager):
|
|
@@ -75,17 +91,14 @@ class AGNews(datasets.GeneratorBasedBuilder):
|
|
| 75 |
]
|
| 76 |
|
| 77 |
def _generate_examples(self, filepath):
|
| 78 |
-
""
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
label = int(label)
|
| 89 |
-
text = " ".join((title, description))
|
| 90 |
-
yield id_, {"text": text, "label": label}
|
| 91 |
|
|
|
|
| 50 |
_TRAIN_DOWNLOAD_URL = "https://github.com/edubrigham/data/blob/541db4cdbb566aa5909e3eb4904d64f9683e5d4a/yahoo_answers_csv/train.csv"
|
| 51 |
_TEST_DOWNLOAD_URL = "https://github.com/edubrigham/data/blob/541db4cdbb566aa5909e3eb4904d64f9683e5d4a/yahoo_answers_csv/test.csv"
|
| 52 |
|
| 53 |
+
_TOPICS = [
|
| 54 |
+
"Society & Culture",
|
| 55 |
+
"Science & Mathematics",
|
| 56 |
+
"Health",
|
| 57 |
+
"Education & Reference",
|
| 58 |
+
"Computers & Internet",
|
| 59 |
+
"Sports",
|
| 60 |
+
"Business & Finance",
|
| 61 |
+
"Entertainment & Music",
|
| 62 |
+
"Family & Relationships",
|
| 63 |
+
"Politics & Government",
|
| 64 |
+
]
|
| 65 |
|
| 66 |
class AGNews(datasets.GeneratorBasedBuilder):
|
| 67 |
"""AG News topic classification dataset."""
|
|
|
|
| 71 |
description=_DESCRIPTION,
|
| 72 |
features=datasets.Features(
|
| 73 |
{
|
| 74 |
+
"id": datasets.Value("int32"),
|
| 75 |
+
"topic": datasets.features.ClassLabel(names=_TOPICS),
|
| 76 |
+
"question_title": datasets.Value("string"),
|
| 77 |
+
"question_content": datasets.Value("string"),
|
| 78 |
+
"best_answer": datasets.Value("string"),
|
| 79 |
+
},
|
| 80 |
+
),
|
| 81 |
+
supervised_keys=None,
|
| 82 |
+
homepage="https://github.com/LC-John/Yahoo-Answers-Topic-Classification-Dataset",
|
| 83 |
)
|
| 84 |
|
| 85 |
def _split_generators(self, dl_manager):
|
|
|
|
| 91 |
]
|
| 92 |
|
| 93 |
def _generate_examples(self, filepath):
|
| 94 |
+
with open(filepath, encoding="utf-8") as f:
|
| 95 |
+
rows = csv.reader(f)
|
| 96 |
+
for i, row in enumerate(rows):
|
| 97 |
+
yield i, {
|
| 98 |
+
"id": i,
|
| 99 |
+
"topic": int(row[0]) - 1,
|
| 100 |
+
"question_title": row[1],
|
| 101 |
+
"question_content": row[2],
|
| 102 |
+
"best_answer": row[3],
|
| 103 |
+
}
|
|
|
|
|
|
|
|
|
|
| 104 |
|