Datasets:
Update samanantar.py
#3
by
knalin55
- opened
- samanantar.py +9 -10
samanantar.py
CHANGED
@@ -45,8 +45,6 @@ _URLS = {
|
|
45 |
}
|
46 |
_LANGUAGES = ["as", "bn", "gu", "hi", "kn", "ml", "mr", "or", "pa", "ta", "te"]
|
47 |
|
48 |
-
PATH_PATTERN = re.compile(r"/(?:existing|created)/(?P<data_source>[^/]+)/")
|
49 |
-
|
50 |
|
51 |
class SamanantarConfig(datasets.BuilderConfig):
|
52 |
VERSION = datasets.Version("0.3.0")
|
@@ -70,7 +68,6 @@ class Samanantar(datasets.GeneratorBasedBuilder):
|
|
70 |
"idx": datasets.Value("int64"),
|
71 |
"src": datasets.Value("string"),
|
72 |
"tgt": datasets.Value("string"),
|
73 |
-
"data_source": datasets.Value("string"),
|
74 |
}
|
75 |
),
|
76 |
supervised_keys=None,
|
@@ -94,10 +91,12 @@ class Samanantar(datasets.GeneratorBasedBuilder):
|
|
94 |
def _generate_examples(self, paths):
|
95 |
id_ = 0
|
96 |
for path in paths:
|
97 |
-
if
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
|
|
|
|
|
45 |
}
|
46 |
_LANGUAGES = ["as", "bn", "gu", "hi", "kn", "ml", "mr", "or", "pa", "ta", "te"]
|
47 |
|
|
|
|
|
48 |
|
49 |
class SamanantarConfig(datasets.BuilderConfig):
|
50 |
VERSION = datasets.Version("0.3.0")
|
|
|
68 |
"idx": datasets.Value("int64"),
|
69 |
"src": datasets.Value("string"),
|
70 |
"tgt": datasets.Value("string"),
|
|
|
71 |
}
|
72 |
),
|
73 |
supervised_keys=None,
|
|
|
91 |
def _generate_examples(self, paths):
|
92 |
id_ = 0
|
93 |
for path in paths:
|
94 |
+
if f"/en-{self.config.language}/train.{self.config.language}" in path:
|
95 |
+
with open(path, encoding="utf-8") as config_language, \
|
96 |
+
open(path.replace(f"train.{self.config.language}", "train.en"), encoding="utf-8") as en:
|
97 |
+
|
98 |
+
for line_src, line_tgt in zip(en, config_language):
|
99 |
+
yield id_, {"idx": id_ ,"src": line_src.strip(), "tgt": line_tgt.strip()}
|
100 |
+
id_ += 1
|
101 |
+
|
102 |
+
break # to prevent it from getting repeated examples (it seems the dataset gets repeated in en-te folder)
|