Datasets:
ArXiv:
License:
| #!/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", | |
| } | |
| _CITATION = """\ | |
| @dataset{language_identification, | |
| author = {Xing Tian}, | |
| title = {language_identification}, | |
| month = aug, | |
| year = 2024, | |
| publisher = {Xing Tian}, | |
| version = {1.0}, | |
| } | |
| """ | |
| class LanguageIdentification(datasets.GeneratorBasedBuilder): | |
| VERSION = datasets.Version("1.0.0") | |
| BUILDER_CONFIGS = [ | |
| datasets.BuilderConfig(name="amazon_reviews_multi", version=VERSION, description="amazon_reviews_multi"), | |
| ] | |
| 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 | |
| yield idx, { | |
| "text": sample["text"], | |
| "language": sample["language"], | |
| "data_source": sample["data_source"], | |
| } | |
| idx += 1 | |
| if __name__ == '__main__': | |
| pass | |