Datasets:
wmt
/

Modalities:
Text
Libraries:
Datasets
albertvillanova HF staff commited on
Commit
e1ebc67
1 Parent(s): 6f885f7

Update wmt_utils with Yakut

Browse files
Files changed (1) hide show
  1. wmt_utils.py +23 -3
wmt_utils.py CHANGED
@@ -409,6 +409,13 @@ _TRAIN_SUBSETS = [
409
  url="https://huggingface.co/datasets/wmt/wikititles/resolve/main/v1/wikititles-v1.{src}-en.tsv.gz",
410
  path="",
411
  ),
 
 
 
 
 
 
 
412
  SubDataset(
413
  name="yandexcorpus",
414
  target="en",
@@ -799,6 +806,10 @@ class Wmt(datasets.GeneratorBasedBuilder):
799
  sub_generator = _parse_czeng
800
  elif ss_name == "hindencorp_01":
801
  sub_generator = _parse_hindencorp
 
 
 
 
802
  elif len(files) == 2:
803
  if ss_name.endswith("_frde"):
804
  sub_generator = _parse_frde_bitext
@@ -941,7 +952,7 @@ def _parse_tmx(path):
941
  elem.clear()
942
 
943
 
944
- def _parse_tsv(path, filename, language_pair=None):
945
  """Generates examples from TSV file."""
946
  if language_pair is None:
947
  lang_match = re.match(r".*\.([a-z][a-z])-([a-z][a-z])\.tsv", filename)
@@ -950,13 +961,15 @@ def _parse_tsv(path, filename, language_pair=None):
950
  else:
951
  l1, l2 = language_pair
952
  with open(path, encoding="utf-8") as f:
953
- for j, line in enumerate(f):
 
 
954
  cols = line.split("\t")
955
  if len(cols) != 2:
956
  logger.warning("Skipping line %d in TSV (%s) with %d != 2 columns.", j, path, len(cols))
957
  continue
958
  s1, s2 = cols
959
- yield j, {l1: s1.strip(), l2: s2.strip()}
960
 
961
 
962
  def _parse_wikiheadlines(path):
@@ -1007,3 +1020,10 @@ def _parse_hindencorp(path):
1007
  logger.warning("Skipping invalid HindEnCorp line: %s", line)
1008
  continue
1009
  yield line_id, {"translation": {"en": split_line[3].strip(), "hi": split_line[4].strip()}}
 
 
 
 
 
 
 
 
409
  url="https://huggingface.co/datasets/wmt/wikititles/resolve/main/v1/wikititles-v1.{src}-en.tsv.gz",
410
  path="",
411
  ),
412
+ SubDataset(
413
+ name="yakut",
414
+ target="ru",
415
+ sources={"sah"},
416
+ url="https://huggingface.co/datasets/wmt/yakut/resolve/main/data/yakut.zip",
417
+ path="yakut/sah-ru.parallel.uniq.tsv",
418
+ ),
419
  SubDataset(
420
  name="yandexcorpus",
421
  target="en",
 
806
  sub_generator = _parse_czeng
807
  elif ss_name == "hindencorp_01":
808
  sub_generator = _parse_hindencorp
809
+ elif ss_name == "yakut":
810
+ sub_generator, sub_generator_args = YakutParser.create_generator(
811
+ sub_generator_args=sub_generator_args, config=self.config
812
+ )
813
  elif len(files) == 2:
814
  if ss_name.endswith("_frde"):
815
  sub_generator = _parse_frde_bitext
 
952
  elem.clear()
953
 
954
 
955
+ def _parse_tsv(path, filename=None, language_pair=None, skiprows=None):
956
  """Generates examples from TSV file."""
957
  if language_pair is None:
958
  lang_match = re.match(r".*\.([a-z][a-z])-([a-z][a-z])\.tsv", filename)
 
961
  else:
962
  l1, l2 = language_pair
963
  with open(path, encoding="utf-8") as f:
964
+ for key, line in enumerate(f):
965
+ if skiprows and key < skiprows:
966
+ continue
967
  cols = line.split("\t")
968
  if len(cols) != 2:
969
  logger.warning("Skipping line %d in TSV (%s) with %d != 2 columns.", j, path, len(cols))
970
  continue
971
  s1, s2 = cols
972
+ yield key, {l1: s1.strip(), l2: s2.strip()}
973
 
974
 
975
  def _parse_wikiheadlines(path):
 
1020
  logger.warning("Skipping invalid HindEnCorp line: %s", line)
1021
  continue
1022
  yield line_id, {"translation": {"en": split_line[3].strip(), "hi": split_line[4].strip()}}
1023
+
1024
+
1025
+ class YakutParser:
1026
+ @staticmethod
1027
+ def create_generator(sub_generator_args=None, config=None):
1028
+ sub_generator = functools.partial(_parse_tsv, language_pair=config.language_pair, skiprows=1)
1029
+ return sub_generator, sub_generator_args