cfigueroa commited on
Commit
1bee3a6
1 Parent(s): b8c73b0

Upload glosas_etiquetadas.py

Browse files
Files changed (1) hide show
  1. glosas_etiquetadas.py +47 -47
glosas_etiquetadas.py CHANGED
@@ -1,47 +1,47 @@
1
- import csv
2
- import datasets
3
-
4
- _DOWNLOAD_URL = "https://huggingface.co/datasets/cfigueroa/glosas_etiquetadas/resolve/main/dataset4.csv"
5
-
6
- class GlosasEtiquetadas(datasets.GeneratorBasedBuilder):
7
- """Glosas Etiquetadas classification dataset."""
8
-
9
- def _info(self):
10
- return datasets.DatasetInfo(
11
- features=datasets.Features(
12
- {
13
- "text": datasets.Value("string"),
14
- "label": datasets.ClassLabel(names = ["ACCESORIOS","ALIMENTOS","ANTEOJOS","ASEOPERSONAL","AUTOMOTOR",
15
- "BANO","BEBE","BEBIDAS","BICICLETAS","CALEFONT","CARNE","CERVEZA","CONSTRUCCION",
16
- "DECORACION","DEPORTE","DORMITORIO","ELECTRONICA","EQUIPAJE","FERRETERIA",
17
- "GRIFERIA","ILUMINACION","JARDIN","JOYERIA","JUGUETERIA","LACTEO","LAVANDERIA",
18
- "LIBRO","LICORES","LIMPIEZA","MASCOTAS","MENAJE","MOBILIARIO","MUSICA","NIEVE",
19
- "ORGANIZACION","OUTDOOR","PANADERIA","PARRILLAS","PESCADERIA","PISCINAS","PISOSMUROS","PUERTASVENTANAS",
20
- "RODADOS","SERVICIOS","TECNOLOGIA","TERRAZAS","UTILES","VESTUARIO","VINOS","ZAPATERIA"] ),
21
- }
22
- )
23
- )
24
-
25
- def _split_generators(self, dl_manager):
26
- path = dl_manager.download_and_extract(_DOWNLOAD_URL)
27
- return [
28
- datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": path, "is_test": False}),
29
- datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": path, "is_test": True}),
30
- ]
31
-
32
- def _generate_examples(self, filepath, is_test, test_size = 0.3):
33
- """Generate Glosas Etiquetadas examples."""
34
- with open(filepath, 'r', encoding='latin-1') as csv_file:
35
- train_threshold = 40001
36
- csv_reader = csv.reader(
37
- csv_file, delimiter=';'
38
- )
39
- # next(csv_reader, None) # skip the headers
40
- for id_, row in enumerate(csv_reader):
41
- if id_ > 0:
42
- text, label = row
43
- current_row = id_, {"text": text, "label": int(label)}
44
- if (id_ < train_threshold) & (not is_test):
45
- yield current_row
46
- if (id_ >= train_threshold) & (is_test):
47
- yield current_row
 
1
+ import csv
2
+ import datasets
3
+
4
+ _DOWNLOAD_URL = "https://huggingface.co/datasets/cfigueroa/glosas_etiquetadas/resolve/main/dataset4.csv"
5
+
6
+ class GlosasEtiquetadas(datasets.GeneratorBasedBuilder):
7
+ """Glosas Etiquetadas classification dataset."""
8
+
9
+ def _info(self):
10
+ return datasets.DatasetInfo(
11
+ features=datasets.Features(
12
+ {
13
+ "text": datasets.Value("string"),
14
+ "label": datasets.ClassLabel(names = ["ACCESORIOS","ALIMENTOS","ANTEOJOS","ASEOPERSONAL","AUTOMOTOR",
15
+ "BANO","BEBE","BEBIDAS","BICICLETAS","CALEFONT","CARNE","CERVEZA","CONSTRUCCION",
16
+ "DECORACION","DEPORTE","DORMITORIO","ELECTRONICA","EQUIPAJE","FERRETERIA",
17
+ "GRIFERIA","ILUMINACION","JARDIN","JOYERIA","JUGUETERIA","LACTEO","LAVANDERIA",
18
+ "LIBRO","LICORES","LIMPIEZA","MASCOTAS","MENAJE","MOBILIARIO","MUSICA","NIEVE",
19
+ "ORGANIZACION","OUTDOOR","PANADERIA","PARRILLAS","PESCADERIA","PISCINAS","PISOSMUROS","PUERTASVENTANAS",
20
+ "RODADOS","SERVICIOS","TECNOLOGIA","TERRAZAS","UTILES","VESTUARIO","VINOS","ZAPATERIA"] ),
21
+ }
22
+ )
23
+ )
24
+
25
+ def _split_generators(self, dl_manager):
26
+ path = dl_manager.download_and_extract(_DOWNLOAD_URL)
27
+ return [
28
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": path, "is_test": False}),
29
+ datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": path, "is_test": True}),
30
+ ]
31
+
32
+ def _generate_examples(self, filepath, is_test, test_size = 0.3):
33
+ """Generate Glosas Etiquetadas examples."""
34
+ with open(filepath, 'r', encoding='latin-1') as csv_file:
35
+ train_threshold = 40001
36
+ csv_reader = csv.reader(
37
+ csv_file, delimiter=';'
38
+ )
39
+ # next(csv_reader, None) # skip the headers
40
+ for id_, row in enumerate(csv_reader):
41
+ if id_ > 0:
42
+ text, label = row
43
+ current_row = id_, {"text": text, "label": int(label)}
44
+ if (id_ < train_threshold) & (not is_test):
45
+ yield current_row
46
+ if (id_ >= train_threshold) & (is_test):
47
+ yield current_row