import os import datasets _DESCRIPTION = """\ OVText """ _CITATION = """\ """ _BASE_URL = "https://huggingface.co/datasets/duyhngoc/OV_Text/resolve/main/data/" TRAIN_FILE = "train.txt" VALIDATION_FILE = "validation.txt" TEST_FILE = "test.txt" class OVTextConfig(datasets.BuilderConfig): """BuilderConfig""" def __init__(self, **kwargs): super(OVTextConfig, self).__init__(**kwargs) class UTSText(datasets.GeneratorBasedBuilder): """OV Word Tokenize datasets""" VERSION = datasets.Version("1.0.0") BUILDER_CONFIGS = [ OVTextConfig( name="products", version=VERSION, description="OV_Text Product"), OVTextConfig( name="small", version=VERSION, description="OV_Text Small"), OVTextConfig( name="base", version=VERSION, description="OV_Text Base"), OVTextConfig( name="large", version=VERSION, description="OV_Text Large") ] def _info(self): return datasets.DatasetInfo( description=_DESCRIPTION, features=datasets.Features( { "text": datasets.Value("string"), } ), supervised_keys=None, homepage=None, citation=_CITATION ) def _split_generators(self, dl_manager): """Returns SplitGenerators.""" subset_folder = self.config.name train_file = dl_manager.download(os.path.join(_BASE_URL, subset_folder, TRAIN_FILE)) validation_file = dl_manager.download(os.path.join(_BASE_URL, subset_folder, VALIDATION_FILE)) test_file = dl_manager.download(os.path.join(_BASE_URL, subset_folder, TEST_FILE)) splits = [ datasets.SplitGenerator( name=datasets.Split.TRAIN, gen_kwargs={"filepath": train_file} ), datasets.SplitGenerator( name=datasets.Split.VALIDATION, gen_kwargs={"filepath": validation_file} ), datasets.SplitGenerator( name=datasets.Split.TEST, gen_kwargs={"filepath": test_file} ), ] return splits def _generate_examples(self, filepath): print(filepath) guid = 0 with open(filepath, encoding="utf-8") as f: for line in f: print(line) if line.strip() != "": item = { "text": line.strip() } yield guid, item guid += 1