linxinyuan
commited on
Commit
•
e591af8
1
Parent(s):
58034aa
Create cola.py
Browse files
cola.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import csv
|
2 |
+
import datasets
|
3 |
+
from datasets.tasks import TextClassification
|
4 |
+
|
5 |
+
_TRAIN_DOWNLOAD_URL = "https://huggingface.co/datasets/linxinyuan/cola/resolve/main/train.csv"
|
6 |
+
_TEST_DOWNLOAD_URL = "https://huggingface.co/datasets/linxinyuan/cola/resolve/main/test.csv"
|
7 |
+
|
8 |
+
class mind(datasets.GeneratorBasedBuilder):
|
9 |
+
def _info(self):
|
10 |
+
return datasets.DatasetInfo(
|
11 |
+
description="cola",
|
12 |
+
features=datasets.Features(
|
13 |
+
{
|
14 |
+
"text": datasets.Value("string"),
|
15 |
+
"label": datasets.features.ClassLabel(names=['0', '1']),
|
16 |
+
}
|
17 |
+
),
|
18 |
+
task_templates=[TextClassification(text_column="text", label_column="label")],
|
19 |
+
)
|
20 |
+
|
21 |
+
def _split_generators(self, dl_manager):
|
22 |
+
train_path = dl_manager.download_and_extract(_TRAIN_DOWNLOAD_URL)
|
23 |
+
test_path = dl_manager.download_and_extract(_TEST_DOWNLOAD_URL)
|
24 |
+
return [
|
25 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": train_path}),
|
26 |
+
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": test_path}),
|
27 |
+
]
|
28 |
+
|
29 |
+
def _generate_examples(self, filepath):
|
30 |
+
with open(filepath, encoding="utf-8") as csv_file:
|
31 |
+
csv_reader = csv.reader(csv_file, delimiter="\t")
|
32 |
+
for id_, row in enumerate(csv_reader):
|
33 |
+
yield id_, {"text": row[3], "label": (int)(row[1])}
|