ebrigham commited on
Commit
6b5eea3
·
1 Parent(s): 717edde

Update labels.py

Browse files
Files changed (1) hide show
  1. labels.py +31 -18
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 = ["Society & Culture", "Science & Mathematics", "Health", "Education & Reference", "Computers & Internet", "Sports", "Business & Finance", "Entertainment & Music", "Family & Relationships", "Politics & Government"]
 
 
 
 
 
 
 
 
 
 
 
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
- "text": datasets.Value("string"),
64
- "label": datasets.features.ClassLabel(names=["Society & Culture", "Science & Mathematics", "Health", "Education & Reference", "Computers & Internet", "Sports", "Business & Finance", "Entertainment & Music", "Family & Relationships", "Politics & Government"]),
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
- """Generate AG News examples."""
79
- with open(filepath, encoding="utf-8") as csv_file:
80
- csv_reader = csv.reader(
81
- csv_file, quotechar='"', delimiter=",", quoting=csv.QUOTE_ALL, skipinitialspace=True
82
- )
83
- for id_, row in enumerate(csv_reader):
84
- label, title, content, description = row
85
- # Original labels are [1, 2, 3, 4] ->
86
- # ['World', 'Sports', 'Business', 'Sci/Tech']
87
- # Re-map to [0, 1, 2, 3].
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