Datasets:
ArXiv:
License:
File size: 13,752 Bytes
821e463 7bab76c 2cb7d00 7bab76c 91ebc59 1339f17 2cb7d00 1339f17 bba7c8f 637de97 a63f3a7 516549d 2cb7d00 a63f3a7 4cba128 2cb7d00 4cba128 2cb7d00 a362b8b b07144f 2cb7d00 4cba128 78d3cbe 4cba128 821e463 0e1af0f 2cb7d00 bba7c8f c7ca5de 0e1af0f 6c980bf 0e1af0f bba7c8f c7ca5de 0e1af0f bba7c8f 6c980bf 0e1af0f bba7c8f 637de97 bba7c8f 2cb7d00 a63f3a7 c7ca5de 0e1af0f 516549d bba7c8f 0e1af0f c7ca5de 4cba128 0e1af0f 516549d 0e1af0f bba7c8f 0e1af0f c7ca5de 0e1af0f 2cb7d00 5779ae4 0e1af0f 7bab76c 2cb7d00 0e1af0f a63f3a7 91ebc59 4cba128 7bab76c 0e1af0f 821e463 7bab76c 2cb7d00 7bab76c 91ebc59 1339f17 2cb7d00 1339f17 bba7c8f 637de97 a63f3a7 516549d 2cb7d00 a63f3a7 4cba128 2cb7d00 4cba128 2cb7d00 a362b8b b07144f 2cb7d00 4cba128 78d3cbe 4cba128 821e463 c7ca5de 821e463 c7ca5de 821e463 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from glob import glob
import json
import os
from pathlib import Path
import datasets
_URLS = {
"amazon_reviews_multi": "data/amazon_reviews_multi.jsonl",
"autshumato": "data/autshumato.jsonl",
"bible_para": "data/bible_para.jsonl",
"bsd_ja_en": "data/bsd_ja_en.jsonl",
"bucc2018": "data/bucc2018.jsonl",
"cmu_hinglish_dog": "data/cmu_hinglish_dog.jsonl",
"ecb": "data/ecb.jsonl",
"emea": "data/emea.jsonl",
"europa_eac_tm": "data/europa_eac_tm.jsonl",
"europa_ecdc_tm": "data/europa_ecdc_tm.jsonl",
"hind_encorp": "data/hind_encorp.jsonl",
"hrenwac_para": "data/hrenwac_para.jsonl",
"id_panl_bppt": "data/id_panl_bppt.jsonl",
"iwslt2017": "data/iwslt2017.jsonl",
"kde4": "data/kde4.jsonl",
"menyo20k_mt": "data/menyo20k_mt.jsonl",
"mike0307": "data/mike0307.jsonl",
"multi_para_crawl": "data/multi_para_crawl.jsonl",
"nbnn": "data/nbnn.jsonl",
"nordic_langid": "data/nordic_langid.jsonl",
"open_subtitles": "data/open_subtitles.jsonl",
"para_crawl_en_bg": "data/para_crawl_en_bg.jsonl",
"para_crawl_en_cs": "data/para_crawl_en_cs.jsonl",
"para_crawl_en_da": "data/para_crawl_en_da.jsonl",
"para_crawl_en_de": "data/para_crawl_en_de.jsonl",
"para_crawl_en_el": "data/para_crawl_en_el.jsonl",
"para_crawl_en_es": "data/para_crawl_en_es.jsonl",
"para_crawl_en_et": "data/para_crawl_en_et.jsonl",
"para_crawl_en_fi": "data/para_crawl_en_fi.jsonl",
"para_crawl_en_fr": "data/para_crawl_en_fr.jsonl",
"para_crawl_en_ga": "data/para_crawl_en_ga.jsonl",
"para_crawl_en_hr": "data/para_crawl_en_hr.jsonl",
"para_crawl_en_hu": "data/para_crawl_en_hu.jsonl",
"para_crawl_en_it": "data/para_crawl_en_it.jsonl",
"para_crawl_en_lt": "data/para_crawl_en_lt.jsonl",
"para_crawl_en_lv": "data/para_crawl_en_lv.jsonl",
"para_crawl_en_mt": "data/para_crawl_en_mt.jsonl",
"para_crawl_en_nl": "data/para_crawl_en_nl.jsonl",
"para_crawl_en_pl": "data/para_crawl_en_pl.jsonl",
"para_crawl_en_pt": "data/para_crawl_en_pt.jsonl",
"para_crawl_en_ro": "data/para_crawl_en_ro.jsonl",
"para_crawl_en_sk": "data/para_crawl_en_sk.jsonl",
"para_crawl_en_sl": "data/para_crawl_en_sl.jsonl",
"para_crawl_en_sv": "data/para_crawl_en_sv.jsonl",
"para_pat_cs_en": "data/para_pat_cs_en.jsonl",
"para_pat_de_en": "data/para_pat_de_en.jsonl",
"para_pat_de_fr": "data/para_pat_de_fr.jsonl",
"para_pat_el_en": "data/para_pat_el_en.jsonl",
"para_pat_en_es": "data/para_pat_en_es.jsonl",
"para_pat_en_hu": "data/para_pat_en_hu.jsonl",
"para_pat_en_ja": "data/para_pat_en_ja.jsonl",
"para_pat_en_ko": "data/para_pat_en_ko.jsonl",
"para_pat_en_pt": "data/para_pat_en_pt.jsonl",
"para_pat_en_ro": "data/para_pat_en_ro.jsonl",
"para_pat_en_ru": "data/para_pat_en_ru.jsonl",
"para_pat_en_sk": "data/para_pat_en_sk.jsonl",
"para_pat_en_uk": "data/para_pat_en_uk.jsonl",
"para_pat_en_zh": "data/para_pat_en_zh.jsonl",
"para_pat_es_fr": "data/para_pat_es_fr.jsonl",
"para_pat_fr_ja": "data/para_pat_fr_ja.jsonl",
"para_pat_fr_ko": "data/para_pat_fr_ko.jsonl",
"para_pat_fr_ru": "data/para_pat_fr_ru.jsonl",
"php": "data/php.jsonl",
"scandi_langid": "data/scandi_langid.jsonl",
"stsb_multi_mt": "data/stsb_multi_mt.jsonl",
"tatoeba": "data/tatoeba.jsonl",
"xnli": "data/xnli.jsonl",
}
_CITATION = """\
@dataset{language_identification,
author = {Xing Tian},
title = {language_identification},
month = aug,
year = 2024,
publisher = {Xing Tian},
version = {1.0},
}
"""
LANGUAGE_MAP = {
"ar": "arabic",
"bg": "bulgarian",
"bn": "bengali",
"bs": "bosnian",
"cs": "czech",
"da": "danish",
"de": "german",
"el": "modern greek",
"en": "english",
"eo": "esperanto",
"es": "spanish",
"et": "estonian",
"fi": "finnish",
"fo": "faroese",
"fr": "french",
"ga": "irish",
"gl": "galician",
"hi": "hindi",
"hi_en": "hindi english",
"hr": "croatian",
"hu": "hungarian",
"hy": "armenian",
"id": "indonesian",
"is": "icelandic",
"it": "italian",
"ja": "japanese",
"ko": "korean",
"lt": "lithuanian",
"lv": "latvian",
"mr": "marathi",
"mt": "maltese",
"nl": "dutch",
"no": "norwegian",
"no-b": "norwegian (bokmål)",
"no-n": "norwegian (nynorsk)",
"pl": "polish",
"pt": "portuguese",
"ro": "romanian",
"ru": "russian",
"sk": "slovak",
"sl": "slovenian",
"sw": "swahili",
"sv": "swedish",
"th": "thai",
"tl": "tagalog",
"tn": "serpeti",
"tr": "turkish",
"ts": "dzonga",
"uk": "ukrainian",
"ur": "urdu",
"vi": "vietnamese",
"yo": "yoruba",
"zh": "chinese",
"zh-cn": "simplified chinese",
"zh-tw": "traditional chinese",
"zu": "zulu, south africa",
}
class LanguageIdentification(datasets.GeneratorBasedBuilder):
VERSION = datasets.Version("1.0.0")
BUILDER_CONFIGS = [
datasets.BuilderConfig(name="amazon_reviews_multi", version=VERSION, description="amazon_reviews_multi"),
datasets.BuilderConfig(name="autshumato", version=VERSION, description="autshumato"),
datasets.BuilderConfig(name="bible_para", version=VERSION, description="bible_para"),
datasets.BuilderConfig(name="bsd_ja_en", version=VERSION, description="bsd_ja_en"),
datasets.BuilderConfig(name="bucc2018", version=VERSION, description="bucc2018"),
datasets.BuilderConfig(name="cmu_hinglish_dog", version=VERSION, description="cmu_hinglish_dog"),
datasets.BuilderConfig(name="ecb", version=VERSION, description="ecb"),
datasets.BuilderConfig(name="emea", version=VERSION, description="emea"),
datasets.BuilderConfig(name="europa_eac_tm", version=VERSION, description="europa_eac_tm"),
datasets.BuilderConfig(name="europa_ecdc_tm", version=VERSION, description="europa_ecdc_tm"),
datasets.BuilderConfig(name="hind_encorp", version=VERSION, description="hind_encorp"),
datasets.BuilderConfig(name="hrenwac_para", version=VERSION, description="hrenwac_para"),
datasets.BuilderConfig(name="id_panl_bppt", version=VERSION, description="id_panl_bppt"),
datasets.BuilderConfig(name="iwslt2017", version=VERSION, description="iwslt2017"),
datasets.BuilderConfig(name="kde4", version=VERSION, description="kde4"),
datasets.BuilderConfig(name="menyo20k_mt", version=VERSION, description="menyo20k_mt"),
datasets.BuilderConfig(name="mike0307", version=VERSION, description="mike0307"),
datasets.BuilderConfig(name="multi_para_crawl", version=VERSION, description="multi_para_crawl"),
datasets.BuilderConfig(name="nbnn", version=VERSION, description="nbnn"),
datasets.BuilderConfig(name="nordic_langid", version=VERSION, description="nordic_langid"),
datasets.BuilderConfig(name="open_subtitles", version=VERSION, description="open_subtitles"),
datasets.BuilderConfig(name="para_crawl_en_bg", version=VERSION, description="para_crawl_en_bg"),
datasets.BuilderConfig(name="para_crawl_en_cs", version=VERSION, description="para_crawl_en_cs"),
datasets.BuilderConfig(name="para_crawl_en_da", version=VERSION, description="para_crawl_en_da"),
datasets.BuilderConfig(name="para_crawl_en_de", version=VERSION, description="para_crawl_en_de"),
datasets.BuilderConfig(name="para_crawl_en_el", version=VERSION, description="para_crawl_en_el"),
datasets.BuilderConfig(name="para_crawl_en_es", version=VERSION, description="para_crawl_en_es"),
datasets.BuilderConfig(name="para_crawl_en_et", version=VERSION, description="para_crawl_en_et"),
datasets.BuilderConfig(name="para_crawl_en_fi", version=VERSION, description="para_crawl_en_fi"),
datasets.BuilderConfig(name="para_crawl_en_fr", version=VERSION, description="para_crawl_en_fr"),
datasets.BuilderConfig(name="para_crawl_en_ga", version=VERSION, description="para_crawl_en_ga"),
datasets.BuilderConfig(name="para_crawl_en_hr", version=VERSION, description="para_crawl_en_hr"),
datasets.BuilderConfig(name="para_crawl_en_hu", version=VERSION, description="para_crawl_en_hu"),
datasets.BuilderConfig(name="para_crawl_en_it", version=VERSION, description="para_crawl_en_it"),
datasets.BuilderConfig(name="para_crawl_en_lt", version=VERSION, description="para_crawl_en_lt"),
datasets.BuilderConfig(name="para_crawl_en_lv", version=VERSION, description="para_crawl_en_lv"),
datasets.BuilderConfig(name="para_crawl_en_mt", version=VERSION, description="para_crawl_en_mt"),
datasets.BuilderConfig(name="para_crawl_en_nl", version=VERSION, description="para_crawl_en_nl"),
datasets.BuilderConfig(name="para_crawl_en_pl", version=VERSION, description="para_crawl_en_pl"),
datasets.BuilderConfig(name="para_crawl_en_pt", version=VERSION, description="para_crawl_en_pt"),
datasets.BuilderConfig(name="para_crawl_en_ro", version=VERSION, description="para_crawl_en_ro"),
datasets.BuilderConfig(name="para_crawl_en_sk", version=VERSION, description="para_crawl_en_sk"),
datasets.BuilderConfig(name="para_crawl_en_sl", version=VERSION, description="para_crawl_en_sl"),
datasets.BuilderConfig(name="para_crawl_en_sv", version=VERSION, description="para_crawl_en_sv"),
datasets.BuilderConfig(name="para_pat_cs_en", version=VERSION, description="para_pat_cs_en"),
datasets.BuilderConfig(name="para_pat_de_en", version=VERSION, description="para_pat_de_en"),
datasets.BuilderConfig(name="para_pat_de_fr", version=VERSION, description="para_pat_de_fr"),
datasets.BuilderConfig(name="para_pat_el_en", version=VERSION, description="para_pat_el_en"),
datasets.BuilderConfig(name="para_pat_en_es", version=VERSION, description="para_pat_en_es"),
datasets.BuilderConfig(name="para_pat_en_hu", version=VERSION, description="para_pat_en_hu"),
datasets.BuilderConfig(name="para_pat_en_ja", version=VERSION, description="para_pat_en_ja"),
datasets.BuilderConfig(name="para_pat_en_ko", version=VERSION, description="para_pat_en_ko"),
datasets.BuilderConfig(name="para_pat_en_pt", version=VERSION, description="para_pat_en_pt"),
datasets.BuilderConfig(name="para_pat_en_ro", version=VERSION, description="para_pat_en_ro"),
datasets.BuilderConfig(name="para_pat_en_ru", version=VERSION, description="para_pat_en_ru"),
datasets.BuilderConfig(name="para_pat_en_sk", version=VERSION, description="para_pat_en_sk"),
datasets.BuilderConfig(name="para_pat_en_uk", version=VERSION, description="para_pat_en_uk"),
datasets.BuilderConfig(name="para_pat_en_zh", version=VERSION, description="para_pat_en_zh"),
datasets.BuilderConfig(name="para_pat_es_fr", version=VERSION, description="para_pat_es_fr"),
datasets.BuilderConfig(name="para_pat_fr_ja", version=VERSION, description="para_pat_fr_ja"),
datasets.BuilderConfig(name="para_pat_fr_ko", version=VERSION, description="para_pat_fr_ko"),
datasets.BuilderConfig(name="para_pat_fr_ru", version=VERSION, description="para_pat_fr_ru"),
datasets.BuilderConfig(name="php", version=VERSION, description="php"),
datasets.BuilderConfig(name="scandi_langid", version=VERSION, description="scandi_langid"),
datasets.BuilderConfig(name="stsb_multi_mt", version=VERSION, description="stsb_multi_mt"),
datasets.BuilderConfig(name="tatoeba", version=VERSION, description="tatoeba"),
datasets.BuilderConfig(name="xnli", version=VERSION, description="xnli"),
]
def _info(self):
features = datasets.Features(
{
"text": datasets.Value("string"),
"language": datasets.Value("string"),
"data_source": datasets.Value("string"),
}
)
return datasets.DatasetInfo(
features=features,
supervised_keys=None,
homepage="",
license="",
citation=_CITATION,
)
def _split_generators(self, dl_manager):
"""Returns SplitGenerators."""
url = _URLS[self.config.name]
dl_path = dl_manager.download(url)
archive_path = dl_path
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={"archive_path": archive_path, "split": "train"},
),
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
gen_kwargs={"archive_path": archive_path, "split": "validation"},
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={"archive_path": archive_path, "split": "test"},
),
]
def _generate_examples(self, archive_path, split):
archive_path = Path(archive_path)
idx = 0
with open(archive_path, "r", encoding="utf-8") as f:
for row in f:
sample = json.loads(row)
if sample["split"] != split:
continue
language = sample["language"]
if language not in LANGUAGE_MAP.keys():
raise AssertionError(language)
yield idx, {
"text": sample["text"],
"language": language,
"data_source": sample["data_source"],
}
idx += 1
if __name__ == '__main__':
pass
|