system HF staff commited on
Commit
6f1b156
1 Parent(s): 3675a41

Update files from the datasets library (from 1.16.0)

Browse files

Release notes: https://github.com/huggingface/datasets/releases/tag/1.16.0

Files changed (2) hide show
  1. README.md +1 -0
  2. sogou_news.py +13 -9
README.md CHANGED
@@ -1,4 +1,5 @@
1
  ---
 
2
  paperswithcode_id: null
3
  ---
4
 
1
  ---
2
+ pretty_name: Sogou News
3
  paperswithcode_id: null
4
  ---
5
 
sogou_news.py CHANGED
@@ -19,7 +19,6 @@
19
 
20
  import csv
21
  import ctypes
22
- import os
23
 
24
  import datasets
25
 
@@ -71,20 +70,25 @@ class Sogou_News(datasets.GeneratorBasedBuilder):
71
  )
72
 
73
  def _split_generators(self, dl_manager):
74
- dl_dir = dl_manager.download_and_extract(_DATA_URL)
75
 
76
  return [
77
  datasets.SplitGenerator(
78
- name=datasets.Split.TEST, gen_kwargs={"filepath": os.path.join(dl_dir, "sogou_news_csv", "test.csv")}
 
79
  ),
80
  datasets.SplitGenerator(
81
- name=datasets.Split.TRAIN, gen_kwargs={"filepath": os.path.join(dl_dir, "sogou_news_csv", "train.csv")}
 
82
  ),
83
  ]
84
 
85
- def _generate_examples(self, filepath):
86
  """This function returns the examples in the raw (text) form."""
87
- with open(filepath, encoding="utf-8") as csv_file:
88
- data = csv.reader(csv_file)
89
- for id_, row in enumerate(data):
90
- yield id_, {"title": row[1], "content": row[2], "label": int(row[0]) - 1}
 
 
 
19
 
20
  import csv
21
  import ctypes
 
22
 
23
  import datasets
24
 
70
  )
71
 
72
  def _split_generators(self, dl_manager):
73
+ archive = dl_manager.download(_DATA_URL)
74
 
75
  return [
76
  datasets.SplitGenerator(
77
+ name=datasets.Split.TEST,
78
+ gen_kwargs={"filepath": "sogou_news_csv/test.csv", "files": dl_manager.iter_archive(archive)},
79
  ),
80
  datasets.SplitGenerator(
81
+ name=datasets.Split.TRAIN,
82
+ gen_kwargs={"filepath": "sogou_news_csv/train.csv", "files": dl_manager.iter_archive(archive)},
83
  ),
84
  ]
85
 
86
+ def _generate_examples(self, filepath, files):
87
  """This function returns the examples in the raw (text) form."""
88
+ for path, f in files:
89
+ if path == filepath:
90
+ lines = (line.decode("utf-8") for line in f)
91
+ data = csv.reader(lines)
92
+ for id_, row in enumerate(data):
93
+ yield id_, {"title": row[1], "content": row[2], "label": int(row[0]) - 1}
94
+ break