imvladikon commited on
Commit
d7212a4
1 Parent(s): bf7093c

Update hebrew_news.py

Browse files
Files changed (1) hide show
  1. hebrew_news.py +17 -16
hebrew_news.py CHANGED
@@ -55,25 +55,26 @@ class HebrewNews(datasets.GeneratorBasedBuilder):
55
  def _split_generators(self, dl_manager):
56
  """Returns SplitGenerators."""
57
  urls_to_download = "data/news.tar.gz"
58
- downloaded_files = dl_manager.download_and_extract(urls_to_download)
59
- filepath = os.path.join(downloaded_files, "news.csv")
60
  return [
61
  datasets.SplitGenerator(
62
  name=datasets.Split.TRAIN,
63
- gen_kwargs={"filepath": filepath},
64
  ),
65
  ]
66
 
67
- def _generate_examples(self, filepath):
68
- with open(filepath, encoding="utf-8") as f:
69
- fieldnames = ["articleBody", "description", "headline", "title"]
70
- reader = csv.DictReader(f, delimiter=",", fieldnames=fieldnames)
71
- next(reader)
72
- for idx, row in enumerate(reader):
73
- yield idx, {
74
- "id": idx,
75
- "articleBody": row["articleBody"],
76
- "description": row["description"],
77
- "headline": row["headline"],
78
- "title": row["title"],
79
- }
 
 
 
55
  def _split_generators(self, dl_manager):
56
  """Returns SplitGenerators."""
57
  urls_to_download = "data/news.tar.gz"
58
+ archive_iter = dl_manager.iter_archive(urls_to_download)
 
59
  return [
60
  datasets.SplitGenerator(
61
  name=datasets.Split.TRAIN,
62
+ gen_kwargs={"archive_iter":archive_iter },
63
  ),
64
  ]
65
 
66
+ def _generate_examples(self, archive_iter):
67
+ for path, f in archive_iter:
68
+ ##with open(filepath, encoding="utf-8") as f:
69
+ fieldnames = ["articleBody", "description", "headline", "title"]
70
+ reader = csv.DictReader(f, delimiter=",", fieldnames=fieldnames)
71
+ next(reader)
72
+ for idx, row in enumerate(reader):
73
+ yield idx, {
74
+ "id": idx,
75
+ "articleBody": row["articleBody"],
76
+ "description": row["description"],
77
+ "headline": row["headline"],
78
+ "title": row["title"],
79
+ }
80
+