albertvillanova HF staff commited on
Commit
fff9c79
1 Parent(s): c310749

Support streaming xtreme dataset for bucc18 config (#4026)

Browse files

Commit from https://github.com/huggingface/datasets/commit/369dadbd775a9db07a2db9a571d1a69cdf20b13c

Files changed (1) hide show
  1. xtreme.py +15 -26
xtreme.py CHANGED
@@ -659,22 +659,20 @@ class Xtreme(datasets.GeneratorBasedBuilder):
659
  ]
660
  if self.config.name.startswith("bucc18"):
661
  lang = self.config.name.split(".")[1]
662
- bucc18_dl_test_dir = dl_manager.download_and_extract(
663
  self.config.data_url + f"bucc2018-{lang}-en.training-gold.tar.bz2"
664
  )
665
- bucc18_dl_dev_dir = dl_manager.download_and_extract(
666
  self.config.data_url + f"bucc2018-{lang}-en.sample-gold.tar.bz2"
667
  )
668
  return [
669
  datasets.SplitGenerator(
670
  name=datasets.Split.VALIDATION,
671
- # These kwargs will be passed to _generate_examples
672
- gen_kwargs={"filepath": os.path.join(bucc18_dl_dev_dir, "bucc2018", lang + "-en")},
673
  ),
674
  datasets.SplitGenerator(
675
  name=datasets.Split.TEST,
676
- # These kwargs will be passed to _generate_examples
677
- gen_kwargs={"filepath": os.path.join(bucc18_dl_test_dir, "bucc2018", lang + "-en")},
678
  ),
679
  ]
680
  if self.config.name.startswith("udpos"):
@@ -886,26 +884,17 @@ class Xtreme(datasets.GeneratorBasedBuilder):
886
  },
887
  }
888
  if self.config.name.startswith("bucc18"):
889
- files = sorted(os.listdir(filepath))
890
- target_file = "/"
891
- source_file = "/"
892
- source_target_file = "/"
893
- for file in files:
894
- if file.endswith("en"):
895
- target_file = os.path.join(filepath, file)
896
- elif file.endswith("gold"):
897
- source_target_file = os.path.join(filepath, file)
898
- else:
899
- source_file = os.path.join(filepath, file)
900
- with open(target_file, encoding="utf-8") as f:
901
- data = csv.reader(f, delimiter="\t")
902
- target_sentences = [row for row in data]
903
- with open(source_file, encoding="utf-8") as f:
904
- data = csv.reader(f, delimiter="\t")
905
- source_sentences = [row for row in data]
906
- with open(source_target_file, encoding="utf-8") as f:
907
- data = csv.reader(f, delimiter="\t")
908
- source_target_ids = [row for row in data]
909
  for id_, pair in enumerate(source_target_ids):
910
  source_id = pair[0]
911
  target_id = pair[1]
 
659
  ]
660
  if self.config.name.startswith("bucc18"):
661
  lang = self.config.name.split(".")[1]
662
+ bucc18_dl_test_archive = dl_manager.download(
663
  self.config.data_url + f"bucc2018-{lang}-en.training-gold.tar.bz2"
664
  )
665
+ bucc18_dl_dev_archive = dl_manager.download(
666
  self.config.data_url + f"bucc2018-{lang}-en.sample-gold.tar.bz2"
667
  )
668
  return [
669
  datasets.SplitGenerator(
670
  name=datasets.Split.VALIDATION,
671
+ gen_kwargs={"filepath": dl_manager.iter_archive(bucc18_dl_dev_archive)},
 
672
  ),
673
  datasets.SplitGenerator(
674
  name=datasets.Split.TEST,
675
+ gen_kwargs={"filepath": dl_manager.iter_archive(bucc18_dl_test_archive)},
 
676
  ),
677
  ]
678
  if self.config.name.startswith("udpos"):
 
884
  },
885
  }
886
  if self.config.name.startswith("bucc18"):
887
+ lang = self.config.name.split(".")[1]
888
+ data_dir = f"bucc2018/{lang}-en"
889
+ for path, file in filepath:
890
+ if path.startswith(data_dir):
891
+ csv_content = [line.decode("utf-8") for line in file]
892
+ if path.endswith("en"):
893
+ target_sentences = list(csv.reader(csv_content, delimiter="\t"))
894
+ elif path.endswith("gold"):
895
+ source_target_ids = list(csv.reader(csv_content, delimiter="\t"))
896
+ else:
897
+ source_sentences = list(csv.reader(csv_content, delimiter="\t"))
 
 
 
 
 
 
 
 
 
898
  for id_, pair in enumerate(source_target_ids):
899
  source_id = pair[0]
900
  target_id = pair[1]