Commit ·
93e006e
1
Parent(s): 80ade01
Delete loading script
Browse files- go_emotions.py +0 -158
go_emotions.py
DELETED
|
@@ -1,158 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 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 |
-
"""GoEmotions dataset"""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
import csv
|
| 21 |
-
import os
|
| 22 |
-
|
| 23 |
-
import datasets
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
_DESCRIPTION = """\
|
| 27 |
-
The GoEmotions dataset contains 58k carefully curated Reddit comments labeled for 27 emotion categories or Neutral.
|
| 28 |
-
The emotion categories are admiration, amusement, anger, annoyance, approval, caring, confusion, curiosity, desire,
|
| 29 |
-
disappointment, disapproval, disgust, embarrassment, excitement, fear, gratitude, grief, joy, love, nervousness,
|
| 30 |
-
optimism, pride, realization, relief, remorse, sadness, surprise.
|
| 31 |
-
"""
|
| 32 |
-
|
| 33 |
-
_CITATION = """\
|
| 34 |
-
@inproceedings{demszky2020goemotions,
|
| 35 |
-
author = {Demszky, Dorottya and Movshovitz-Attias, Dana and Ko, Jeongwoo and Cowen, Alan and Nemade, Gaurav and Ravi, Sujith},
|
| 36 |
-
booktitle = {58th Annual Meeting of the Association for Computational Linguistics (ACL)},
|
| 37 |
-
title = {{GoEmotions: A Dataset of Fine-Grained Emotions}},
|
| 38 |
-
year = {2020}
|
| 39 |
-
}
|
| 40 |
-
"""
|
| 41 |
-
|
| 42 |
-
_CLASS_NAMES = [
|
| 43 |
-
"admiration",
|
| 44 |
-
"amusement",
|
| 45 |
-
"anger",
|
| 46 |
-
"annoyance",
|
| 47 |
-
"approval",
|
| 48 |
-
"caring",
|
| 49 |
-
"confusion",
|
| 50 |
-
"curiosity",
|
| 51 |
-
"desire",
|
| 52 |
-
"disappointment",
|
| 53 |
-
"disapproval",
|
| 54 |
-
"disgust",
|
| 55 |
-
"embarrassment",
|
| 56 |
-
"excitement",
|
| 57 |
-
"fear",
|
| 58 |
-
"gratitude",
|
| 59 |
-
"grief",
|
| 60 |
-
"joy",
|
| 61 |
-
"love",
|
| 62 |
-
"nervousness",
|
| 63 |
-
"optimism",
|
| 64 |
-
"pride",
|
| 65 |
-
"realization",
|
| 66 |
-
"relief",
|
| 67 |
-
"remorse",
|
| 68 |
-
"sadness",
|
| 69 |
-
"surprise",
|
| 70 |
-
"neutral",
|
| 71 |
-
]
|
| 72 |
-
|
| 73 |
-
_BASE_DOWNLOAD_URL = "https://github.com/google-research/google-research/raw/master/goemotions/data/"
|
| 74 |
-
_RAW_DOWNLOAD_URLS = [
|
| 75 |
-
"https://storage.googleapis.com/gresearch/goemotions/data/full_dataset/goemotions_1.csv",
|
| 76 |
-
"https://storage.googleapis.com/gresearch/goemotions/data/full_dataset/goemotions_2.csv",
|
| 77 |
-
"https://storage.googleapis.com/gresearch/goemotions/data/full_dataset/goemotions_3.csv",
|
| 78 |
-
]
|
| 79 |
-
_HOMEPAGE = "https://github.com/google-research/google-research/tree/master/goemotions"
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
class GoEmotionsConfig(datasets.BuilderConfig):
|
| 83 |
-
@property
|
| 84 |
-
def features(self):
|
| 85 |
-
if self.name == "simplified":
|
| 86 |
-
return {
|
| 87 |
-
"text": datasets.Value("string"),
|
| 88 |
-
"labels": datasets.Sequence(datasets.ClassLabel(names=_CLASS_NAMES)),
|
| 89 |
-
"id": datasets.Value("string"),
|
| 90 |
-
}
|
| 91 |
-
elif self.name == "raw":
|
| 92 |
-
d = {
|
| 93 |
-
"text": datasets.Value("string"),
|
| 94 |
-
"id": datasets.Value("string"),
|
| 95 |
-
"author": datasets.Value("string"),
|
| 96 |
-
"subreddit": datasets.Value("string"),
|
| 97 |
-
"link_id": datasets.Value("string"),
|
| 98 |
-
"parent_id": datasets.Value("string"),
|
| 99 |
-
"created_utc": datasets.Value("float"),
|
| 100 |
-
"rater_id": datasets.Value("int32"),
|
| 101 |
-
"example_very_unclear": datasets.Value("bool"),
|
| 102 |
-
}
|
| 103 |
-
d.update({label: datasets.Value("int32") for label in _CLASS_NAMES})
|
| 104 |
-
return d
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
class GoEmotions(datasets.GeneratorBasedBuilder):
|
| 108 |
-
"""GoEmotions dataset"""
|
| 109 |
-
|
| 110 |
-
BUILDER_CONFIGS = [
|
| 111 |
-
GoEmotionsConfig(
|
| 112 |
-
name="raw",
|
| 113 |
-
),
|
| 114 |
-
GoEmotionsConfig(
|
| 115 |
-
name="simplified",
|
| 116 |
-
),
|
| 117 |
-
]
|
| 118 |
-
BUILDER_CONFIG_CLASS = GoEmotionsConfig
|
| 119 |
-
DEFAULT_CONFIG_NAME = "simplified"
|
| 120 |
-
|
| 121 |
-
def _info(self):
|
| 122 |
-
return datasets.DatasetInfo(
|
| 123 |
-
description=_DESCRIPTION,
|
| 124 |
-
features=datasets.Features(self.config.features),
|
| 125 |
-
homepage=_HOMEPAGE,
|
| 126 |
-
citation=_CITATION,
|
| 127 |
-
)
|
| 128 |
-
|
| 129 |
-
def _split_generators(self, dl_manager):
|
| 130 |
-
if self.config.name == "raw":
|
| 131 |
-
paths = dl_manager.download_and_extract(_RAW_DOWNLOAD_URLS)
|
| 132 |
-
return [datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepaths": paths, "raw": True})]
|
| 133 |
-
if self.config.name == "simplified":
|
| 134 |
-
train_path = dl_manager.download_and_extract(os.path.join(_BASE_DOWNLOAD_URL, "train.tsv"))
|
| 135 |
-
dev_path = dl_manager.download_and_extract(os.path.join(_BASE_DOWNLOAD_URL, "dev.tsv"))
|
| 136 |
-
test_path = dl_manager.download_and_extract(os.path.join(_BASE_DOWNLOAD_URL, "test.tsv"))
|
| 137 |
-
return [
|
| 138 |
-
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepaths": [train_path]}),
|
| 139 |
-
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepaths": [dev_path]}),
|
| 140 |
-
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepaths": [test_path]}),
|
| 141 |
-
]
|
| 142 |
-
|
| 143 |
-
def _generate_examples(self, filepaths, raw=False):
|
| 144 |
-
"""Generate AG News examples."""
|
| 145 |
-
for file_idx, filepath in enumerate(filepaths):
|
| 146 |
-
with open(filepath, "r", encoding="utf-8") as f:
|
| 147 |
-
if raw:
|
| 148 |
-
reader = csv.DictReader(f)
|
| 149 |
-
else:
|
| 150 |
-
reader = csv.DictReader(f, delimiter="\t", fieldnames=list(self.config.features.keys()))
|
| 151 |
-
|
| 152 |
-
for row_idx, row in enumerate(reader):
|
| 153 |
-
if raw:
|
| 154 |
-
row["example_very_unclear"] = row["example_very_unclear"] == "TRUE"
|
| 155 |
-
else:
|
| 156 |
-
row["labels"] = [int(ind) for ind in row["labels"].split(",")]
|
| 157 |
-
|
| 158 |
-
yield f"{file_idx}_{row_idx}", row
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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