sandeep12345
commited on
Commit
·
24888af
1
Parent(s):
8064c80
Upload 3 files
Browse files- data_loader.py +56 -0
- transformed_test.csv +0 -0
- transformed_train.csv +0 -0
data_loader.py
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
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 |
+
|
16 |
+
# Lint as: python3
|
17 |
+
|
18 |
+
|
19 |
+
import csv
|
20 |
+
|
21 |
+
import datasets
|
22 |
+
from datasets.tasks import TextClassification
|
23 |
+
|
24 |
+
_TRAIN_DOWNLOAD_URL = "transformed_train.csv"
|
25 |
+
_TEST_DOWNLOAD_URL = "transformed_test.csv"
|
26 |
+
|
27 |
+
|
28 |
+
class AGNews(datasets.GeneratorBasedBuilder):
|
29 |
+
"""AG News topic classification dataset."""
|
30 |
+
|
31 |
+
def _info(self):
|
32 |
+
return datasets.DatasetInfo(
|
33 |
+
features=datasets.Features(
|
34 |
+
{
|
35 |
+
"text": datasets.Value("string"),
|
36 |
+
"label": datasets.features.ClassLabel(names=["name", "description", "authors"]),
|
37 |
+
}
|
38 |
+
)
|
39 |
+
)
|
40 |
+
|
41 |
+
def _split_generators(self, dl_manager):
|
42 |
+
train_path = _TRAIN_DOWNLOAD_URL
|
43 |
+
test_path = _TEST_DOWNLOAD_URL
|
44 |
+
return [
|
45 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": train_path}),
|
46 |
+
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": test_path}),
|
47 |
+
]
|
48 |
+
|
49 |
+
def _generate_examples(self, filepath):
|
50 |
+
with open(filepath, encoding="utf-8") as csv_file:
|
51 |
+
csv_reader = csv.reader(
|
52 |
+
csv_file, quotechar='"', delimiter=",", quoting=csv.QUOTE_ALL, skipinitialspace=True
|
53 |
+
)
|
54 |
+
for id_, row in enumerate(csv_reader):
|
55 |
+
text, label = row
|
56 |
+
yield id_, {"text": text, "label": label}
|
transformed_test.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
transformed_train.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|