cc100 / cc100.py
Yan-Jia Huang
fix: minor
6c9a0d9
raw
history blame
2.48 kB
import datasets
_VERSION = "0.0.1"
_LANGUAGES = [
"af",
"am",
"ar",
"as",
"az",
"be",
"bg",
"bn",
"bn_rom",
"br",
"bs",
"ca",
"cs",
"cy",
"da",
"de",
"el",
"en",
"eo",
"es",
"et",
"eu",
"fa",
"ff",
"fi",
"fr",
"fy",
"ga",
"gd",
"gl",
"gn",
"gu",
"ha",
"he",
"hi",
"hi_rom",
"hr",
"ht",
"hu",
"hy",
"id",
"ig",
"is",
"it",
"ja",
"jv",
"ka",
"kk",
"km",
"kn",
"ko",
"ku",
"ky",
"la",
"lg",
"li",
"ln",
"lo",
"lt",
"lv",
"mg",
"mk",
"ml",
"mn",
"mr",
"ms",
"my",
"my_zaw",
"ne",
"nl",
"no",
"ns",
"om",
"or",
"pa",
"pl",
"ps",
"pt",
"qu",
"rm",
"ro",
"ru",
"sa",
"sc",
"sd",
"si",
"sk",
"sl",
"so",
"sq",
"sr",
"ss",
"su",
"sv",
"sw",
"ta",
"ta_rom",
"te",
"te_rom",
"th",
"tl",
"tn",
"tr",
"ug",
"uk",
"ur",
"ur_rom",
"uz",
"vi",
"wo",
"xh",
"yi",
"yo",
"zh-Hans",
"zh-Hant",
"zu",
]
class Cc100Config(datasets.BuilderConfig):
def __init__(self, lang, *args, **kwargs):
super().__init__(name=lang, *args, **kwargs)
self.lang = lang
class Cc100(datasets.GeneratorBasedBuilder):
BUILDER_CONFIG_CLASS = Cc100Config
BUILDER_CONFIGS = [
Cc100Config(lang=lang, version=datasets.Version(_VERSION))
for lang in _LANGUAGES
]
def _info(self):
return datasets.DatasetInfo(
features=datasets.Features(
{
"id": datasets.Value("string"),
"text": datasets.Value("string"),
},
),
)
def _split_generators(self, dl_manager):
datapath = dl_manager.download_and_extract(
f"https://data.statmt.org/cc-100/{self.config.lang}.txt.xz"
)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={"datapath": datapath},
)
]
def _generate_examples(self, datapath):
with open(datapath, encoding="utf-8") as f:
for i, text in enumerate(f):
example = (i, {"id": str(i), "text": text})
yield example