GadidGC commited on
Commit
958be8d
·
1 Parent(s): 5443447

Create new file

Browse files
Files changed (1) hide show
  1. tesis.py +94 -0
tesis.py ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ """IMDB movie reviews dataset."""
18
+
19
+ import datasets
20
+ from datasets.tasks import TextClassification
21
+
22
+
23
+ _DESCRIPTION = """
24
+ """
25
+
26
+ _CITATION = """
27
+ """
28
+
29
+ _DOWNLOAD_URL = "aclImdb_v1.tar.gz"
30
+
31
+
32
+ class IMDBReviewsConfig(datasets.BuilderConfig):
33
+ """BuilderConfig for IMDBReviews."""
34
+
35
+ def __init__(self, **kwargs):
36
+ """BuilderConfig for IMDBReviews.
37
+ Args:
38
+ **kwargs: keyword arguments forwarded to super.
39
+ """
40
+ super(IMDBReviewsConfig, self).__init__(version=datasets.Version("1.0.0", ""), **kwargs)
41
+
42
+
43
+ class Imdb(datasets.GeneratorBasedBuilder):
44
+ """IMDB movie reviews dataset."""
45
+
46
+ BUILDER_CONFIGS = [
47
+ IMDBReviewsConfig(
48
+ name="plain_text",
49
+ description="Plain text",
50
+ )
51
+ ]
52
+
53
+ def _info(self):
54
+ return datasets.DatasetInfo(
55
+ description=_DESCRIPTION,
56
+ features=datasets.Features(
57
+ {"text": datasets.Value("string"), "label": datasets.features.ClassLabel(names=["neg", "pos"])}
58
+ ),
59
+ supervised_keys=None,
60
+ homepage="http://ai.stanford.edu/~amaas/data/sentiment/",
61
+ citation=_CITATION,
62
+ task_templates=[TextClassification(text_column="text", label_column="label")],
63
+ )
64
+
65
+ def _split_generators(self, dl_manager):
66
+ archive = dl_manager.download(_DOWNLOAD_URL)
67
+ return [
68
+ datasets.SplitGenerator(
69
+ name=datasets.Split.TRAIN, gen_kwargs={"files": dl_manager.iter_archive(archive), "split": "train"}
70
+ ),
71
+ datasets.SplitGenerator(
72
+ name=datasets.Split.TEST, gen_kwargs={"files": dl_manager.iter_archive(archive), "split": "test"}
73
+ ),
74
+ datasets.SplitGenerator(
75
+ name=datasets.Split("unsupervised"),
76
+ gen_kwargs={"files": dl_manager.iter_archive(archive), "split": "train", "labeled": False},
77
+ ),
78
+ ]
79
+
80
+ def _generate_examples(self, files, split, labeled=True):
81
+ """Generate aclImdb examples."""
82
+ # For labeled examples, extract the label from the path.
83
+ if labeled:
84
+ label_mapping = {"pos": 1, "neg": 0}
85
+ for path, f in files:
86
+ if path.startswith(f"aclImdb/{split}"):
87
+ label = label_mapping.get(path.split("/")[2])
88
+ if label is not None:
89
+ yield path, {"text": f.read().decode("utf-8"), "label": label}
90
+ else:
91
+ for path, f in files:
92
+ if path.startswith(f"aclImdb/{split}"):
93
+ if path.split("/")[2] == "unsup":
94
+ yield path, {"text": f.read().decode("utf-8"), "label": -1}