ebrigham commited on
Commit
5097fe1
·
1 Parent(s): 51efffd

Update labels.py

Browse files
Files changed (1) hide show
  1. labels.py +13 -10
labels.py CHANGED
@@ -102,14 +102,17 @@ class YahooAnswersTopics(datasets.GeneratorBasedBuilder):
102
  ]
103
 
104
  def _generate_examples(self, filepath):
105
- with open(filepath, encoding="utf-8") as f:
106
- rows = csv.reader(f)
107
- for i, row in enumerate(rows):
108
- yield i, {
109
- "id": i,
110
- "topic": int(row[0]) - 1,
111
- "question_title": row[1],
112
- "question_content": row[2],
113
- "best_answer": row[3],
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