Update labels.py
Browse files
labels.py
CHANGED
|
@@ -102,14 +102,17 @@ class YahooAnswersTopics(datasets.GeneratorBasedBuilder):
|
|
| 102 |
]
|
| 103 |
|
| 104 |
def _generate_examples(self, filepath):
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
|
|
|
|
|
|
|
|
|
| 115 |
|
|
|
|
| 102 |
]
|
| 103 |
|
| 104 |
def _generate_examples(self, filepath):
|
| 105 |
+
"""Generate AG News examples."""
|
| 106 |
+
with open(filepath, encoding="utf-8") as csv_file:
|
| 107 |
+
csv_reader = csv.reader(
|
| 108 |
+
csv_file, quotechar='"', delimiter=",", quoting=csv.QUOTE_ALL, skipinitialspace=True
|
| 109 |
+
)
|
| 110 |
+
for id_, row in enumerate(csv_reader):
|
| 111 |
+
label, title, description = row
|
| 112 |
+
# Original labels are [1, 2, 3, 4] ->
|
| 113 |
+
# ['World', 'Sports', 'Business', 'Sci/Tech']
|
| 114 |
+
# Re-map to [0, 1, 2, 3].
|
| 115 |
+
label = int(label) - 1
|
| 116 |
+
text = " ".join((title, description))
|
| 117 |
+
yield id_, {"text": text, "label": label}
|
| 118 |
|