ebrigham commited on
Commit
2bacebe
·
1 Parent(s): b34f145

Update labels.py

Browse files
Files changed (1) hide show
  1. labels.py +17 -41
labels.py CHANGED
@@ -50,64 +50,40 @@ _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
- "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
-
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(
80
  description=_DESCRIPTION,
81
  features=datasets.Features(
82
  {
83
- "id": datasets.Value("int32"),
84
- "topic": datasets.features.ClassLabel(names=_TOPICS),
85
- "question_title": datasets.Value("string"),
86
- "question_content": datasets.Value("string"),
87
- "best_answer": datasets.Value("string"),
88
- },
89
  ),
90
- supervised_keys=None
 
 
91
  )
92
-
93
  def _split_generators(self, dl_manager):
94
  train_path = dl_manager.download_and_extract(_TRAIN_DOWNLOAD_URL)
95
  test_path = dl_manager.download_and_extract(_TEST_DOWNLOAD_URL)
96
  return [
97
- datasets.SplitGenerator(
98
- name=datasets.Split.TRAIN, gen_kwargs={"filepath": train_path}
99
- ),
100
- datasets.SplitGenerator(
101
- name=datasets.Split.TEST, gen_kwargs={"filepath": test_path}),
102
  ]
103
-
104
  def _generate_examples(self, filepath):
105
  """Generate AG News examples."""
106
- with open(filepath, encoding="utf-8") as f:
107
- rows = csv.reader(
108
- f, quotechar='"', delimiter=",", quoting=csv.QUOTE_ALL, skipinitialspace=True
109
  )
110
- for id_, row in enumerate(rows):
111
  label, title, description = row
112
  # Original labels are [1, 2, 3, 4] ->
113
  # ['World', 'Sports', 'Business', 'Sci/Tech']
 
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."""
 
 
 
 
 
 
 
 
 
57
 
58
  def _info(self):
59
  return datasets.DatasetInfo(
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
+ homepage="http://groups.di.unipi.it/~gulli/AG_corpus_of_news_articles.html",
68
+ citation=_CITATION,
69
+ task_templates=[TextClassification(text_column="text", label_column="label")],
70
  )
71
+
72
  def _split_generators(self, dl_manager):
73
  train_path = dl_manager.download_and_extract(_TRAIN_DOWNLOAD_URL)
74
  test_path = dl_manager.download_and_extract(_TEST_DOWNLOAD_URL)
75
  return [
76
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": train_path}),
77
+ datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": test_path}),
 
 
 
78
  ]
79
+
80
  def _generate_examples(self, filepath):
81
  """Generate AG News examples."""
82
+ with open(filepath, encoding="utf-8") as csv_file:
83
+ csv_reader = csv.reader(
84
+ csv_file, quotechar='"', delimiter=",", quoting=csv.QUOTE_ALL, skipinitialspace=True
85
  )
86
+ for id_, row in enumerate(csv_reader):
87
  label, title, description = row
88
  # Original labels are [1, 2, 3, 4] ->
89
  # ['World', 'Sports', 'Business', 'Sci/Tech']