Update labels.py
Browse files
labels.py
CHANGED
|
@@ -47,8 +47,8 @@ _CITATION = """\
|
|
| 47 |
}
|
| 48 |
"""
|
| 49 |
|
| 50 |
-
|
| 51 |
-
|
| 52 |
|
| 53 |
_TOPICS = [
|
| 54 |
"Society & Culture",
|
|
@@ -63,8 +63,17 @@ _TOPICS = [
|
|
| 63 |
"Politics & Government",
|
| 64 |
]
|
| 65 |
|
| 66 |
-
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
def _info(self):
|
| 70 |
return datasets.DatasetInfo(
|
|
@@ -83,11 +92,17 @@ class AGNews(datasets.GeneratorBasedBuilder):
|
|
| 83 |
)
|
| 84 |
|
| 85 |
def _split_generators(self, dl_manager):
|
| 86 |
-
|
| 87 |
-
|
|
|
|
|
|
|
| 88 |
return [
|
| 89 |
-
datasets.SplitGenerator(
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
]
|
| 92 |
|
| 93 |
def _generate_examples(self, filepath):
|
|
@@ -96,7 +111,7 @@ class AGNews(datasets.GeneratorBasedBuilder):
|
|
| 96 |
for i, row in enumerate(rows):
|
| 97 |
yield i, {
|
| 98 |
"id": i,
|
| 99 |
-
"topic": int(row[
|
| 100 |
"question_title": row[1],
|
| 101 |
"question_content": row[2],
|
| 102 |
"best_answer": row[3],
|
|
|
|
| 47 |
}
|
| 48 |
"""
|
| 49 |
|
| 50 |
+
_URL = "https://github.com/edubrigham/data/blob/541db4cdbb566aa5909e3eb4904d64f9683e5d4a"
|
| 51 |
+
|
| 52 |
|
| 53 |
_TOPICS = [
|
| 54 |
"Society & Culture",
|
|
|
|
| 63 |
"Politics & Government",
|
| 64 |
]
|
| 65 |
|
| 66 |
+
|
| 67 |
+
class YahooAnswersTopics(datasets.GeneratorBasedBuilder):
|
| 68 |
+
"Yahoo! Answers Topic Classification Dataset"
|
| 69 |
+
|
| 70 |
+
VERSION = datasets.Version("1.0.0")
|
| 71 |
+
BUILDER_CONFIGS = [
|
| 72 |
+
datasets.BuilderConfig(
|
| 73 |
+
name="yahoo_answers_topics",
|
| 74 |
+
version=datasets.Version("1.0.0", ""),
|
| 75 |
+
),
|
| 76 |
+
]
|
| 77 |
|
| 78 |
def _info(self):
|
| 79 |
return datasets.DatasetInfo(
|
|
|
|
| 92 |
)
|
| 93 |
|
| 94 |
def _split_generators(self, dl_manager):
|
| 95 |
+
data_dir = dl_manager.download_and_extract(_URL)
|
| 96 |
+
|
| 97 |
+
# Extracting (un-taring) the training data
|
| 98 |
+
data_dir = os.path.join(data_dir, "yahoo_answers_csv")
|
| 99 |
return [
|
| 100 |
+
datasets.SplitGenerator(
|
| 101 |
+
name=datasets.Split.TRAIN, gen_kwargs={"filepath": os.path.join(data_dir, "train.csv")}
|
| 102 |
+
),
|
| 103 |
+
datasets.SplitGenerator(
|
| 104 |
+
name=datasets.Split.TEST, gen_kwargs={"filepath": os.path.join(data_dir, "test.csv")}
|
| 105 |
+
),
|
| 106 |
]
|
| 107 |
|
| 108 |
def _generate_examples(self, filepath):
|
|
|
|
| 111 |
for i, row in enumerate(rows):
|
| 112 |
yield i, {
|
| 113 |
"id": i,
|
| 114 |
+
"topic": int(row[0]) - 1,
|
| 115 |
"question_title": row[1],
|
| 116 |
"question_content": row[2],
|
| 117 |
"best_answer": row[3],
|