pnrr commited on
Commit
631df12
1 Parent(s): 442cd5c

Create data.py

Browse files
Files changed (1) hide show
  1. data.py +93 -0
data.py ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ """datas."""
16
+
17
+
18
+ import csv
19
+
20
+ import datasets
21
+ from datasets.tasks import TextClassification
22
+
23
+
24
+ _CITATION = """\
25
+ @inproceedings{Casanueva2020,
26
+ author = pnr,
27
+ title = {sentiment},
28
+ year = {2022},
29
+ month = {mar},
30
+ note = {Data available at https://github.com/PnrSvc/dataset},
31
+ url = {a},
32
+ booktitle = {a}
33
+ }
34
+ """
35
+
36
+ _DESCRIPTION = """\
37
+ description
38
+ """
39
+
40
+ _HOMEPAGE = "https://github.com/PnrSvc/dataset"
41
+
42
+
43
+ _TRAIN_DOWNLOAD_URL = (
44
+ "https://github.com/PnrSvc/dataset/blob/main/turkish/train.csv"
45
+ )
46
+ _TEST_DOWNLOAD_URL = "https://github.com/PnrSvc/dataset/blob/main/turkish/test.csv"
47
+
48
+
49
+ class Datas(datasets.GeneratorBasedBuilder):
50
+ """datas dataset."""
51
+
52
+ VERSION = datasets.Version("1.1.0")
53
+
54
+ def _info(self):
55
+ features = datasets.Features(
56
+ {
57
+ "label": datasets.Value("string"),
58
+ "target": datasets.features.ClassLabel(
59
+ names=[
60
+ "negative",
61
+ "neutral",
62
+ "positive"
63
+ ]
64
+ ),
65
+ }
66
+ )
67
+ return datasets.DatasetInfo(
68
+ description=_DESCRIPTION,
69
+ features=features,
70
+ supervised_keys=None,
71
+ homepage=_HOMEPAGE,
72
+ citation=_CITATION,
73
+ task_templates=[TextClassification(text_column="label", label_column="target")],
74
+ )
75
+
76
+ def _split_generators(self, dl_manager):
77
+ """Returns SplitGenerators."""
78
+ train_path = dl_manager.download_and_extract(_TRAIN_DOWNLOAD_URL)
79
+ test_path = dl_manager.download_and_extract(_TEST_DOWNLOAD_URL)
80
+ return [
81
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": train_path}),
82
+ datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": test_path}),
83
+ ]
84
+
85
+ def _generate_examples(self, filepath):
86
+ """Yields examples as (key, example) tuples."""
87
+ with open(filepath, encoding="utf-8") as f:
88
+ csv_reader = csv.reader(f, quotechar='"', delimiter=",", quoting=csv.QUOTE_ALL, skipinitialspace=True)
89
+ # call next to skip header
90
+ next(csv_reader)
91
+ for id_, row in enumerate(csv_reader):
92
+ label, target = row
93
+ yield id_, {"text": label, "label": target}