Blanca commited on
Commit
6557b01
1 Parent(s): 99e32d4

Upload guiacat.py

Browse files
Files changed (1) hide show
  1. guiacat.py +104 -0
guiacat.py ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Loading script for the ReviewsFinder dataset.
2
+
3
+
4
+ import json
5
+ import csv
6
+
7
+ import datasets
8
+
9
+
10
+ logger = datasets.logging.get_logger(__name__)
11
+
12
+
13
+ _CITATION = """ """
14
+
15
+
16
+ _DESCRIPTION = """ guiacat dataset"""
17
+
18
+
19
+ _HOMEPAGE = """ """
20
+
21
+
22
+
23
+ _URL = "/gpfs/projects/bsc88/corpora/guiacat/v1/s1/data_splits/"
24
+ _TRAINING_FILE = "train.csv"
25
+ _DEV_FILE = "dev.csv"
26
+ _TEST_FILE = "test.csv"
27
+
28
+
29
+ class GuiacatConfig(datasets.BuilderConfig):
30
+ """ Builder config for the reviews_finder dataset """
31
+
32
+ def __init__(self, **kwargs):
33
+ """BuilderConfig for reviews_finder.
34
+ Args:
35
+ **kwargs: keyword arguments forwarded to super.
36
+ """
37
+ super(GuiacatConfig, self).__init__(**kwargs)
38
+
39
+
40
+ class Guiacat(datasets.GeneratorBasedBuilder):
41
+ """ ReviewsFinder Dataset """
42
+
43
+
44
+ BUILDER_CONFIGS = [
45
+ GuiacatConfig(
46
+ name="Guiacat",
47
+ version=datasets.Version("1.0.0"),
48
+ description="Guiacat dataset",
49
+ ),
50
+ ]
51
+
52
+
53
+ def _info(self):
54
+ return datasets.DatasetInfo(
55
+ description=_DESCRIPTION,
56
+ features=datasets.Features(
57
+ {
58
+ "text": datasets.Value("string"),
59
+ "label": datasets.features.ClassLabel
60
+ (names=
61
+ [
62
+ "molt bo",
63
+ "bo",
64
+ "regular",
65
+ "dolent",
66
+ "molt dolent"
67
+ ]
68
+ ),
69
+ }
70
+ ),
71
+ homepage=_HOMEPAGE,
72
+ citation=_CITATION,
73
+ )
74
+
75
+
76
+ def _split_generators(self, dl_manager):
77
+ """Returns SplitGenerators."""
78
+ urls_to_download = {
79
+ "train": f"{_URL}{_TRAINING_FILE}",
80
+ "dev": f"{_URL}{_DEV_FILE}",
81
+ "test": f"{_URL}{_TEST_FILE}",
82
+ }
83
+ downloaded_files = dl_manager.download_and_extract(urls_to_download)
84
+
85
+ return [
86
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
87
+ datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["dev"]}),
88
+ datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}),
89
+ ]
90
+
91
+
92
+ def _generate_examples(self, filepath):
93
+ """This function returns the examples in the raw (text) form."""
94
+ logger.info("generating examples from = %s", filepath)
95
+ with open(filepath) as f:
96
+ read = csv.reader(f)
97
+ data = [item for item in read]
98
+ for id_, article in enumerate(data): # ["data"] , perquè hi havia això?
99
+ text = article[5]
100
+ label = article[6]
101
+ yield id_, {
102
+ "text": text,
103
+ "label": label,
104
+ }