-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Additional Text Classification Datasets (#1121)
- Loading branch information
Showing
17 changed files
with
461 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#! /usr/bin/env python | ||
# coding=utf-8 | ||
# Copyright (c) 2019 Uber Technologies, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ============================================================================== | ||
from ludwig.datasets.base_dataset import BaseDataset, DEFAULT_CACHE_LOCATION | ||
from ludwig.datasets.mixins.download import TarDownloadMixin | ||
from ludwig.datasets.mixins.load import CSVLoadMixin | ||
from ludwig.datasets.mixins.process import * | ||
|
||
def load(cache_dir=DEFAULT_CACHE_LOCATION, split=True): | ||
dataset = AmazonPolarity(cache_dir=cache_dir) | ||
return dataset.load(split=split) | ||
|
||
class AmazonPolarity(TarDownloadMixin, MultifileJoinProcessMixin, | ||
CSVLoadMixin, BaseDataset): | ||
""" | ||
The Amazon Reviews Polarity dataset | ||
Details: | ||
34,686,770 Amazon reviews from 6,643,669 users on 2,441,053 \ | ||
products, from the Stanford Network Analysis Project (SNAP). \ | ||
This dataset contains 600,000 training samples and 130,000 \ | ||
testing samples in each class. | ||
Dataset source: | ||
Character-level Convolutional Networks for Text Classification | ||
Xiang Zhang et al., 2015 | ||
""" | ||
def __init__(self, cache_dir=DEFAULT_CACHE_LOCATION): | ||
super().__init__(dataset_name="amazon_review_polarity", cache_dir=cache_dir) | ||
|
||
def process_downloaded_dataset(self): | ||
super(AmazonPolarity, self).process_downloaded_dataset(header=None) | ||
processed_df = pd.read_csv(os.path.join(self.processed_dataset_path, | ||
self.csv_filename)) | ||
processed_df.columns = ['label', 'review_tile', 'review_text', 'split'] | ||
processed_df.to_csv( | ||
os.path.join(self.processed_dataset_path, self.csv_filename), | ||
index=False | ||
) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
version: 1.0 | ||
download_urls: | ||
- "https://s3.amazonaws.com/fast-ai-nlp/amazon_review_polarity_csv.tgz" | ||
split_filenames: | ||
train_file: train.csv | ||
test_file: test.csv | ||
download_file_type: csv | ||
csv_filename: amazon_review_polarity.csv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#! /usr/bin/env python | ||
# coding=utf-8 | ||
# Copyright (c) 2019 Uber Technologies, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ============================================================================== | ||
from ludwig.datasets.base_dataset import BaseDataset, DEFAULT_CACHE_LOCATION | ||
from ludwig.datasets.mixins.download import TarDownloadMixin | ||
from ludwig.datasets.mixins.load import CSVLoadMixin | ||
from ludwig.datasets.mixins.process import * | ||
|
||
def load(cache_dir=DEFAULT_CACHE_LOCATION, split=True): | ||
dataset = AmazonReviews(cache_dir=cache_dir) | ||
return dataset.load(split=split) | ||
|
||
class AmazonReviews(TarDownloadMixin, MultifileJoinProcessMixin, | ||
CSVLoadMixin, BaseDataset): | ||
""" | ||
The Amazon Reviews dataset | ||
Details: | ||
34,686,770 Amazon reviews from 6,643,669 users on 2,441,053 \ | ||
products, from the Stanford Network Analysis Project (SNAP). \ | ||
This dataset contains 600,000 training samples and 130,000 \ | ||
testing samples in each class. | ||
Dataset source: | ||
Character-level Convolutional Networks for Text Classification | ||
Xiang Zhang et al., 2015 | ||
""" | ||
def __init__(self, cache_dir=DEFAULT_CACHE_LOCATION): | ||
super().__init__(dataset_name="amazon_reviews", cache_dir=cache_dir) | ||
|
||
def process_downloaded_dataset(self): | ||
super(AmazonReviews, self).process_downloaded_dataset(header=None) | ||
processed_df = pd.read_csv(os.path.join(self.processed_dataset_path, | ||
self.csv_filename)) | ||
processed_df.columns = ['label', 'review_tile', 'review_text', 'split'] | ||
processed_df.to_csv( | ||
os.path.join(self.processed_dataset_path, self.csv_filename), | ||
index=False | ||
) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
version: 1.0 | ||
download_urls: | ||
- "https://s3.amazonaws.com/fast-ai-nlp/amazon_review_full_csv.tgz" | ||
split_filenames: | ||
train_file: train.csv | ||
test_file: test.csv | ||
download_file_type: csv | ||
csv_filename: amazon_reviews.csv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#! /usr/bin/env python | ||
# coding=utf-8 | ||
# Copyright (c) 2019 Uber Technologies, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ============================================================================== | ||
from ludwig.datasets.base_dataset import BaseDataset, DEFAULT_CACHE_LOCATION | ||
from ludwig.datasets.mixins.download import TarDownloadMixin | ||
from ludwig.datasets.mixins.load import CSVLoadMixin | ||
from ludwig.datasets.mixins.process import * | ||
|
||
def load(cache_dir=DEFAULT_CACHE_LOCATION, split=True): | ||
dataset = DBPedia(cache_dir=cache_dir) | ||
return dataset.load(split=split) | ||
|
||
class DBPedia(TarDownloadMixin, MultifileJoinProcessMixin, | ||
CSVLoadMixin, BaseDataset): | ||
""" | ||
The DBPedia Ontology dataset. | ||
Details: | ||
40,000 training samples and 5,000 testing samples from 14 \ | ||
nonoverlapping classes from DBpedia 2014. | ||
Dataset source: | ||
Character-level Convolutional Networks for Text Classification | ||
Xiang Zhang et al., 2015 | ||
""" | ||
def __init__(self, cache_dir=DEFAULT_CACHE_LOCATION): | ||
super().__init__(dataset_name="dbpedia", cache_dir=cache_dir) | ||
|
||
def process_downloaded_dataset(self): | ||
super(DBPedia, self).process_downloaded_dataset(header=None) | ||
processed_df = pd.read_csv(os.path.join(self.processed_dataset_path, | ||
self.csv_filename)) | ||
processed_df.columns = ['label', 'title', 'content', 'split'] | ||
processed_df.to_csv( | ||
os.path.join(self.processed_dataset_path, self.csv_filename), | ||
index=False | ||
) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
version: 1.0 | ||
download_urls: | ||
- "https://s3.amazonaws.com/fast-ai-nlp/dbpedia_csv.tgz" | ||
split_filenames: | ||
train_file: train.csv | ||
test_file: test.csv | ||
download_file_type: csv | ||
csv_filename: dbpedia.csv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#! /usr/bin/env python | ||
# coding=utf-8 | ||
# Copyright (c) 2019 Uber Technologies, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ============================================================================== | ||
from ludwig.datasets.base_dataset import BaseDataset, DEFAULT_CACHE_LOCATION | ||
from ludwig.datasets.mixins.download import UncompressedFileDownloadMixin | ||
from ludwig.datasets.mixins.load import CSVLoadMixin | ||
from ludwig.datasets.mixins.process import * | ||
|
||
def load(cache_dir=DEFAULT_CACHE_LOCATION, split=False): | ||
dataset = EthosBinary(cache_dir=cache_dir) | ||
return dataset.load(split=split) | ||
|
||
class EthosBinary(UncompressedFileDownloadMixin, IdentityProcessMixin, | ||
CSVLoadMixin, BaseDataset): | ||
"""The Ethos Hate Speech Dataset. | ||
Source Paper: | ||
ETHOS: an Online Hate Speech Detection Dataset | ||
Ioannis Mollas and Zoe Chrysopoulou and Stamatis Karlos and | ||
Grigorios Tsoumakas | ||
""" | ||
def __init__(self, cache_dir=DEFAULT_CACHE_LOCATION): | ||
super().__init__(dataset_name="ethos_binary", cache_dir=cache_dir) | ||
|
||
def load_processed_dataset(self, split): | ||
dataset_csv = os.path.join(self.processed_dataset_path, | ||
self.csv_filename) | ||
data_df = pd.read_csv(dataset_csv, sep=';') | ||
return data_df |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
version: 1.0 | ||
download_urls: | ||
- https://raw.githubusercontent.com/intelligence-csd-auth-gr/Ethos-Hate-Speech-Dataset/master/ethos/ethos_data/Ethos_Dataset_Binary.csv | ||
download_file_type: csv | ||
csv_filename: Ethos_Dataset_Binary.csv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.