import csv import datasets _DOWNLOAD_URL = "https://huggingface.co/datasets/cfigueroa/glosas_etiquetadas/resolve/main/datasetNew.csv" class GlosasEtiquetadas(datasets.GeneratorBasedBuilder): """Glosas Etiquetadas classification dataset.""" def _info(self): return datasets.DatasetInfo( features=datasets.Features( { "text": datasets.Value("string"), "label": datasets.ClassLabel(names = ["LIBRERIA_ACCESORIOS","ALIMENTOS","ASEOPERSONAL","VEHICULOS", "BANO","BEBE","BEBIDAS","CARNE","CERVEZA","CONSTRUCCION", "DECORACION","DEPORTE","DORMITORIO","ELECTRONICA","EQUIPAJE","FERRETERIA", "GRIFERIA","ILUMINACION","JARDIN","JOYERIA","JUGUETERIA","LACTEO","LAVANDERIA", "LICORES","LIMPIEZA","MASCOTAS","MENAJE","MOBILIARIO", "ORGANIZACION","OUTDOOR","PANADERIA","PISOSMUROS","PUERTASVENTANAS", "SERVICIOS","TECNOLOGIA","TERRAZAS","VESTUARIO","VINOS","ZAPATERIA", "ILEGIBLE"] ), } ) ) def _split_generators(self, dl_manager): path = dl_manager.download_and_extract(_DOWNLOAD_URL) return [ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": path, "is_test": False}), datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": path, "is_test": True}), ] def _generate_examples(self, filepath, is_test, test_size = 0.3): """Generate Glosas Etiquetadas examples.""" with open(filepath, 'r', encoding='latin-1') as csv_file: train_threshold = 40001 csv_reader = csv.reader( csv_file, delimiter=';' ) # next(csv_reader, None) # skip the headers for id_, row in enumerate(csv_reader): if id_ > 0: text, label = row current_row = id_, {"text": text, "label": int(label)} if (id_ < train_threshold) & (not is_test): yield current_row if (id_ >= train_threshold) & (is_test): yield current_row