dd123 commited on
Commit
1498666
1 Parent(s): 37712ba
Files changed (1) hide show
  1. live_stream_dataset_huggingface.py +85 -0
live_stream_dataset_huggingface.py ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ """live_stream_dataset_huggingface dataset."""
16
+
17
+ import csv
18
+
19
+ import datasets
20
+ from datasets.tasks import TextClassification
21
+
22
+ _DESCRIPTION = """"""
23
+
24
+ _HOMEPAGE = "https://github.com/freeziyou/live_stream_dataset"
25
+
26
+ _LICENSE = "Creative Commons Attribution 4.0 International"
27
+
28
+ _TRAIN_DOWNLOAD_URL = "https://raw.githubusercontent.com/freeziyou/live_stream_dataset/main/train.csv"
29
+ # _TRAIN_DOWNLOAD_URL = "https://gitee.com/didi233/test_date_gitee/raw/master/train.csv"
30
+ _TEST_DOWNLOAD_URL = "https://raw.githubusercontent.com/freeziyou/live_stream_dataset/main/test.csv"
31
+ # _TEST_DOWNLOAD_URL = "https://gitee.com/didi233/test_date_gitee/raw/master/test.csv"
32
+
33
+
34
+ class test_data_huggingface(datasets.GeneratorBasedBuilder):
35
+ """test_data dataset."""
36
+
37
+ VERSION = datasets.Version("1.2.0")
38
+
39
+ def _info(self):
40
+ features = datasets.Features(
41
+ {
42
+ "text": datasets.Value("string"),
43
+ "label": datasets.features.ClassLabel(
44
+ names=[
45
+ "none",
46
+ "like",
47
+ "unlike",
48
+ "hope",
49
+ "questioning",
50
+ "express_surprise",
51
+ "normal_interaction",
52
+ "express_sad",
53
+ "tease",
54
+ "meme",
55
+ "express_abashed"
56
+ ])
57
+ }
58
+ )
59
+ return datasets.DatasetInfo(
60
+ description=_DESCRIPTION,
61
+ features=features,
62
+ supervised_keys=None,
63
+ homepage=_HOMEPAGE,
64
+ license=_LICENSE,
65
+ task_templates=[TextClassification(text_column="text", label_column="label")],
66
+ )
67
+
68
+ def _split_generators(self, dl_manager):
69
+ """Returns SplitGenerators."""
70
+ train_path = dl_manager.download_and_extract(_TRAIN_DOWNLOAD_URL)
71
+ test_path = dl_manager.download_and_extract(_TEST_DOWNLOAD_URL)
72
+ return [
73
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": train_path}),
74
+ datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": test_path}),
75
+ ]
76
+
77
+ def _generate_examples(self, filepath):
78
+ """Yields examples as (key, example) tuples."""
79
+ with open(filepath, encoding="utf-8") as f:
80
+ csv_reader = csv.reader(f, quotechar='"', delimiter=",", quoting=csv.QUOTE_ALL, skipinitialspace=True)
81
+ # call next to skip header
82
+ next(csv_reader)
83
+ for id_, row in enumerate(csv_reader):
84
+ text, label = row
85
+ yield id_, {"text": text, "label": label}