Upload wolf_data_processing.py
Browse files- wolf_data_processing.py +75 -0
wolf_data_processing.py
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
# --- dataset class --
|
3 |
+
import csv
|
4 |
+
import datasets
|
5 |
+
from datasets import load_dataset
|
6 |
+
from datasets.tasks import TextClassification
|
7 |
+
|
8 |
+
_TRAIN_DOWNLOAD_URL = 'https://raw.githubusercontent.com/ZhangLe59151/goginBE/main/wolf_t.csv' #'./corpus.json'
|
9 |
+
_TEST_DOWNLOAD_URL = 'https://raw.githubusercontent.com/ZhangLe59151/goginBE/main/wolf_v.csv'
|
10 |
+
|
11 |
+
_DESCRIPTION = 'My Third Dataset'
|
12 |
+
_HOMEPAGE = ''
|
13 |
+
_LICENSE = ''
|
14 |
+
_CITATION = '''\\n@inproceedings{Casanueva2020,
|
15 |
+
author = Mulin,
|
16 |
+
title = Second Dataset,
|
17 |
+
year = {2021},
|
18 |
+
month = {Sep},
|
19 |
+
note = {},
|
20 |
+
url = {},
|
21 |
+
booktitle = {}
|
22 |
+
}'''
|
23 |
+
class MulinThird(datasets.GeneratorBasedBuilder):
|
24 |
+
VERSION = datasets.Version('1.1.0')
|
25 |
+
def _info(self):
|
26 |
+
features = datasets.Features(
|
27 |
+
{'text': datasets.Value('string'),
|
28 |
+
'label': datasets.features.ClassLabel(
|
29 |
+
names=[
|
30 |
+
'Ask for ideas',
|
31 |
+
'Explain ideas',
|
32 |
+
'Ask action',
|
33 |
+
'Reject answer',
|
34 |
+
'Ask to do',
|
35 |
+
'Explain actions',
|
36 |
+
'Polite',
|
37 |
+
'Reject',
|
38 |
+
'Encourage',
|
39 |
+
'Check emotion',
|
40 |
+
'Explain ideas,Encourage',
|
41 |
+
'Explain ideas,Polite',
|
42 |
+
'Reject answer,Reject',
|
43 |
+
'Ask for ideas,Ask to do',
|
44 |
+
'Explain actions,Polite',
|
45 |
+
'Explain ideas,Explain actions',
|
46 |
+
'Polite,Encourage',
|
47 |
+
'Polite,Explain actions',
|
48 |
+
'Polite,Ask to do',
|
49 |
+
'Polite,Encourage,Explain ideas,Explain actions',
|
50 |
+
'Explain ideas,Polite,Explain actions,Encourage'])})
|
51 |
+
return datasets.DatasetInfo(
|
52 |
+
description=_DESCRIPTION,
|
53 |
+
features=features,
|
54 |
+
supervised_keys=None,
|
55 |
+
homepage=_HOMEPAGE,
|
56 |
+
license=_LICENSE,
|
57 |
+
citation=_CITATION,
|
58 |
+
task_templates=[TextClassification(text_column='text', label_column='label')]
|
59 |
+
)
|
60 |
+
def _split_generators(self, dl_manager):
|
61 |
+
train_path = dl_manager.download_and_extract(_TRAIN_DOWNLOAD_URL)
|
62 |
+
test_path = dl_manager.download_and_extract(_TEST_DOWNLOAD_URL)
|
63 |
+
print(train_path)
|
64 |
+
return [
|
65 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": train_path}),
|
66 |
+
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": test_path})
|
67 |
+
]
|
68 |
+
|
69 |
+
def _generate_examples(self, filepath):
|
70 |
+
with open(filepath, encoding='utf-8') as f:
|
71 |
+
csv_reader = csv.reader(f, quotechar='"', delimiter=",", quoting=csv.QUOTE_ALL, skipinitialspace=True)
|
72 |
+
next(csv_reader)
|
73 |
+
for id_, row in enumerate(csv_reader):
|
74 |
+
id, label, text = row
|
75 |
+
yield id_, {"text": text, "label": label}
|