system HF staff commited on
Commit
50eeb28
1 Parent(s): ad8f596

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 (1) hide show
  1. turkish_product_reviews.py +11 -18
turkish_product_reviews.py CHANGED
@@ -42,26 +42,19 @@ class TurkishProductReviews(datasets.GeneratorBasedBuilder):
42
 
43
  def _split_generators(self, dl_manager):
44
  """Returns SplitGenerators."""
45
- dl_paths = dl_manager.download_and_extract(_URL)
46
- filenames = list(os.listdir(dl_paths))
47
  return [
48
- datasets.SplitGenerator(
49
- name=datasets.Split.TRAIN, gen_kwargs={"filepath": dl_paths, "filenames": filenames}
50
- ),
51
  ]
52
 
53
- def _generate_examples(self, filepath, filenames):
54
  """Generate TurkishProductReviews examples."""
55
- logger.info("⏳ Generating examples from = %s", filepath)
56
- for file_idx, f in enumerate(sorted(filenames)):
57
- filename, file_extension = os.path.splitext(f)
58
  label = "negative" if file_extension == ".neg" else "positive"
59
-
60
- file_fullpath = os.path.join(filepath, f)
61
- with open(file_fullpath, encoding="utf-8") as f:
62
- for idx, line in enumerate(f):
63
- line = line.strip()
64
- yield f"{file_idx}_{idx}", {
65
- "sentence": line,
66
- "sentiment": label,
67
- }
 
42
 
43
  def _split_generators(self, dl_manager):
44
  """Returns SplitGenerators."""
45
+ archive = dl_manager.download(_URL)
 
46
  return [
47
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"files": dl_manager.iter_archive(archive)}),
 
 
48
  ]
49
 
50
+ def _generate_examples(self, files):
51
  """Generate TurkishProductReviews examples."""
52
+ for file_idx, (path, f) in enumerate(files):
53
+ _, file_extension = os.path.splitext(path)
 
54
  label = "negative" if file_extension == ".neg" else "positive"
55
+ for idx, line in enumerate(f):
56
+ line = line.decode("utf-8").strip()
57
+ yield f"{file_idx}_{idx}", {
58
+ "sentence": line,
59
+ "sentiment": label,
60
+ }