File size: 2,181 Bytes
1bee3a6 ba4e753 1bee3a6 ba4e753 1bee3a6 ba4e753 1bee3a6 |
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 |
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
|