Francisco Castillo commited on
Commit
c6088d0
1 Parent(s): c996b67

First commit

Browse files
Files changed (5) hide show
  1. .gitattributes +3 -0
  2. production.csv +3 -0
  3. training.csv +3 -0
  4. validation.csv +3 -0
  5. xtreme_en.py +177 -0
.gitattributes CHANGED
@@ -35,3 +35,6 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
35
  *.mp3 filter=lfs diff=lfs merge=lfs -text
36
  *.ogg filter=lfs diff=lfs merge=lfs -text
37
  *.wav filter=lfs diff=lfs merge=lfs -text
 
 
 
 
35
  *.mp3 filter=lfs diff=lfs merge=lfs -text
36
  *.ogg filter=lfs diff=lfs merge=lfs -text
37
  *.wav filter=lfs diff=lfs merge=lfs -text
38
+ training.csv filter=lfs diff=lfs merge=lfs -text
39
+ validation.csv filter=lfs diff=lfs merge=lfs -text
40
+ production.csv filter=lfs diff=lfs merge=lfs -text
production.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c1fba58898a0cf79fb773665f687022f11044afe0a02abd47eba6179361fedd0
3
+ size 2196116
training.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6ea888cd792d83af844f697c1cb216bf97b9c07121428bd3074ebc12503c4a2a
3
+ size 757973
validation.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:067a81b0112d05e36551ce0d7296376170d5f74dafb5e07241ccbfde8abfc582
3
+ size 74350
xtreme_en.py ADDED
@@ -0,0 +1,177 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ # Lint as: python3
16
+ """IMDb movie revies dataset mixed with Trip Advisor Hotel Reviews to simulate drift accross time."""
17
+
18
+
19
+ import csv
20
+ import json
21
+ import os
22
+
23
+ import datasets
24
+ from datasets.tasks import TextClassification
25
+
26
+
27
+
28
+ # TODO: Add BibTeX citation to our BLOG
29
+ # Find for instance the citation on arxiv or on the dataset repo/website
30
+ _CITATION = ""
31
+ # _CITATION = """\
32
+ # @InProceedings{huggingface:dataset,
33
+ # title = {A great new dataset},
34
+ # author={huggingface, Inc.
35
+ # },
36
+ # year={2020}
37
+ # }
38
+ # """
39
+
40
+ # TODO: Add description of the dataset here
41
+ # You can copy an official description
42
+ _DESCRIPTION = """\
43
+ This dataset was crafted to be used in our tutorial [Link to the tutorial when
44
+ ready]. It consists on product reviews from an e-commerce store. The reviews
45
+ are labeled on a scale from 1 to 5 (stars). The training & validation sets are
46
+ fully composed by reviews written in english. However, the production set has
47
+ some reviews written in spanish. At Arize, we work to surface this issue and
48
+ help you solve it.
49
+ """
50
+
51
+ # TODO: Add a link to an official homepage for the dataset here
52
+ _HOMEPAGE = ""
53
+
54
+ # TODO: Add the licence for the dataset here if you can find it
55
+ _LICENSE = ""
56
+
57
+ # TODO: Add link to the official dataset URLs here
58
+ # The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
59
+ # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
60
+ _URL = "https://huggingface.co/datasets/arize-ai/xtreme_en/resolve/main/"
61
+ _URLS = {
62
+ "training": _URL + "training.csv",
63
+ "validation": _URL + "validation.csv",
64
+ "production": _URL + "production.csv",
65
+ }
66
+
67
+
68
+ # TODO: Name of the dataset usually match the script name with CamelCase instead of snake_case
69
+ class XtremeEn(datasets.GeneratorBasedBuilder):
70
+ """TODO: Short description of my dataset."""
71
+
72
+ VERSION = datasets.Version("1.0.0")
73
+
74
+ # This is an example of a dataset with multiple configurations.
75
+ # If you don't want/need to define several sub-sets in your dataset,
76
+ # just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
77
+
78
+ # If you need to make complex sub-parts in the datasets with configurable options
79
+ # You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
80
+ # BUILDER_CONFIG_CLASS = MyBuilderConfig
81
+
82
+ # You will be able to load one or the other configurations in the following list with
83
+ # data = datasets.load_dataset('my_dataset', 'first_domain')
84
+ # data = datasets.load_dataset('my_dataset', 'second_domain')
85
+ BUILDER_CONFIGS = [
86
+ datasets.BuilderConfig(name="default", version=VERSION, description="Default"),
87
+ ]
88
+
89
+ DEFAULT_CONFIG_NAME = "default" # It's not mandatory to have a default configuration. Just use one if it make sense.
90
+
91
+ def _info(self):
92
+ # This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
93
+ features = datasets.Features(
94
+ # These are the features of your dataset like images, labels ...
95
+ {
96
+ "prediction_ts": datasets.Value("float"),
97
+ "language":datasets.Value("string"),
98
+ "split_text": datasets.Sequence(datasets.Value("string")),
99
+ "ner_tags": datasets.Sequence(
100
+ datasets.features.ClassLabel(
101
+ names=[
102
+ "O",
103
+ "B-PER",
104
+ "I-PER",
105
+ "B-ORG",
106
+ "I-ORG",
107
+ "B-LOC",
108
+ "I-LOC",
109
+ ]
110
+ )
111
+ ),
112
+ }
113
+ )
114
+
115
+ return datasets.DatasetInfo(
116
+ # This is the description that will appear on the datasets page.
117
+ description=_DESCRIPTION,
118
+ # This defines the different columns of the dataset and their types
119
+ features=features, # Here we define them above because they are different between the two configurations
120
+ # Homepage of the dataset for documentation
121
+ # License for the dataset if available
122
+ license=_LICENSE,
123
+ # Citation for the dataset
124
+ citation=_CITATION,
125
+ )
126
+
127
+ def _split_generators(self, dl_manager):
128
+ # This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
129
+ # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
130
+
131
+ # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
132
+ # It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
133
+ # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
134
+ extracted_paths = dl_manager.download_and_extract(_URLS)
135
+ return [
136
+ datasets.SplitGenerator(
137
+ name=datasets.Split("training"),
138
+ # These kwargs will be passed to _generate_examples
139
+ gen_kwargs={
140
+ "filepath": extracted_paths['training'],
141
+ },
142
+ ),
143
+ datasets.SplitGenerator(
144
+ name=datasets.Split("validation"),
145
+ # These kwargs will be passed to _generate_examples
146
+ gen_kwargs={
147
+ "filepath": extracted_paths['validation'],
148
+ },
149
+ ),
150
+ datasets.SplitGenerator(
151
+ name=datasets.Split("production"),
152
+ # These kwargs will be passed to _generate_examples
153
+ gen_kwargs={
154
+ "filepath": extracted_paths['production'],
155
+ },
156
+ ),
157
+ ]
158
+
159
+
160
+ # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
161
+ def _generate_examples(self, filepath):
162
+ # This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
163
+ # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
164
+ with open(filepath) as csv_file:
165
+ csv_reader = csv.reader(csv_file, delimiter='\t')
166
+ for id_, row in enumerate(csv_reader):
167
+ prediction_ts,language,text,ner_tags = row
168
+ ner_tags_list = list(ner_tags.strip('[]').split(' '))
169
+ tokens = text.split(":-:")
170
+ if id_==0: # Skip headers
171
+ continue
172
+ yield id_, {
173
+ "prediction_ts":prediction_ts,
174
+ "language":language,
175
+ "split_text": tokens,
176
+ "ner_tags":ner_tags_list,
177
+ }