Matías Rojas
commited on
Commit
·
d73a877
1
Parent(s):
8d5c2e6
uploading files
Browse files
.DS_Store
ADDED
Binary file (6.15 kB). View file
|
|
data.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
task1a.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import csv
|
2 |
+
import datasets
|
3 |
+
|
4 |
+
_DOWNLOAD_URL = "https://huggingface.co/datasets/mrojas/task1a/resolve/main/data.csv"
|
5 |
+
|
6 |
+
class Task1a(datasets.GeneratorBasedBuilder):
|
7 |
+
"""Task1a classification dataset."""
|
8 |
+
|
9 |
+
def _info(self):
|
10 |
+
return datasets.DatasetInfo(
|
11 |
+
features=datasets.Features(
|
12 |
+
{
|
13 |
+
"filename": datasets.Value("string"),
|
14 |
+
"text": datasets.Value("string"),
|
15 |
+
"label": datasets.ClassLabel(names = ["0", "1"]),
|
16 |
+
}
|
17 |
+
)
|
18 |
+
)
|
19 |
+
|
20 |
+
def _split_generators(self, dl_manager):
|
21 |
+
path = dl_manager.download_and_extract(_DOWNLOAD_URL)
|
22 |
+
return [
|
23 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": path, "is_test": False}),
|
24 |
+
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": path, "is_test": True}),
|
25 |
+
]
|
26 |
+
|
27 |
+
def _generate_examples(self, filepath, is_test, test_size = 0.3):
|
28 |
+
"""Generate examples."""
|
29 |
+
with open(filepath, encoding="utf-8") as csv_file:
|
30 |
+
train_threshold = 122
|
31 |
+
csv_reader = csv.reader(
|
32 |
+
csv_file
|
33 |
+
)
|
34 |
+
# next(csv_reader, None) # skip the headers
|
35 |
+
for id_, row in enumerate(csv_reader):
|
36 |
+
if id_ > 0:
|
37 |
+
text, label = row
|
38 |
+
current_row = id_, {"text": text, "label": int(label)}
|
39 |
+
if (id_ < train_threshold) & (not is_test):
|
40 |
+
yield current_row
|
41 |
+
if (id_ >= train_threshold) & (is_test):
|
42 |
+
yield current_row
|