glosas_etiquetadas / glosas_etiquetadas.py
cfigueroa's picture
Update glosas_etiquetadas.py
9b8cd7e
raw
history blame
2.27 kB
import csv
import datasets
_DOWNLOAD_URL = "https://huggingface.co/datasets/cfigueroa/glosas_etiquetadas/resolve/main/dataset2.csv"
class GlosasEtiquetadas(datasets.GeneratorBasedBuilder):
"""Glosas Etiquetadas classification dataset."""
def _info(self):
return datasets.DatasetInfo(
features=datasets.Features(
{
"glosa": datasets.Value("string"),
"categoria": datasets.ClassLabel(names = ["ACCESORIOS","ALIMENTOS","ANTEOJOS","ASEOPERSONAL","AUTOMOTOR","BANO","BEBE","BEBIDAS","BICICLETAS",
"CALEFONT","CARNE","CERVEZA","CONSTRUCCION","DECORACION","DEPORTE","DORMITORIO","ELECTRONICA","ELETRONICA","EQUIPAJE","FERRETERIA","GRIFERIA","HERRAMIENTAS","ILUMINACION",
"JARDIN","JOYERIA","JUGUETERIA","LACTEO","LAVANDERIA","LIBRO","LICOR","LIMPIEZA","MASCOTAS","MENAJE","MOBILIARIO","MUSICA","NIEVE","ORGANIZACION","OUTDOOR","PANADERIA",
"PARRILLAS","PESCADERIA","PISCINAS","PISOSMUROS","PUERTASVENTANAS","RODADOS","SERVICIOS","TECNOLOGIA","TERRAZAS","UTILES","VESTUARIO","VINO","ZAPATERIA"] ),
}
)
)
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('dataset2.csv', 'r', encoding='utf-8', errors='ignore') as csv_file:
train_threshold = 40001
csv_reader = csv.reader(
csv_file
)
# next(csv_reader, None) # skip the headers
for id_, row in enumerate(csv_reader):
if id_ > 0:
glosa, categoria = row
current_row = id_, {"glosa": glosa, "categoria": int(categoria)}
if (id_ < train_threshold) & (not is_test):
yield current_row
if (id_ >= train_threshold) & (is_test):
yield current_row