Datasets:
Tasks:
Text Classification
Modalities:
Text
Sub-tasks:
multi-class-classification
Languages:
English
Size:
10K - 100K
ArXiv:
License:
Delete loading script
Browse files
raft.py
DELETED
|
@@ -1,295 +0,0 @@
|
|
| 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 |
-
|
| 16 |
-
import csv
|
| 17 |
-
import json
|
| 18 |
-
import os
|
| 19 |
-
from pathlib import Path
|
| 20 |
-
|
| 21 |
-
import datasets
|
| 22 |
-
|
| 23 |
-
# TODO: Add BibTeX citation
|
| 24 |
-
_CITATION = """\
|
| 25 |
-
@InProceedings{huggingface:dataset,
|
| 26 |
-
title = {A great new dataset},
|
| 27 |
-
author={huggingface, Inc.
|
| 28 |
-
},
|
| 29 |
-
year={2020}
|
| 30 |
-
}
|
| 31 |
-
"""
|
| 32 |
-
|
| 33 |
-
_DESCRIPTION = """Large pre-trained language models have shown promise for few-shot learning, completing text-based tasks given only a few task-specific examples. Will models soon solve classification tasks that have so far been reserved for human research assistants?
|
| 34 |
-
|
| 35 |
-
[RAFT](https://raft.elicit.org) is a few-shot classification benchmark that tests language models:
|
| 36 |
-
|
| 37 |
-
- across multiple domains (lit review, tweets, customer interaction, etc.)
|
| 38 |
-
- on economically valuable classification tasks (someone inherently cares about the task)
|
| 39 |
-
- in a setting that mirrors deployment (50 examples per task, info retrieval allowed, hidden test set)
|
| 40 |
-
"""
|
| 41 |
-
|
| 42 |
-
_HOMEPAGE = "https://raft.elicit.org"
|
| 43 |
-
|
| 44 |
-
# TODO: Add the licence for the dataset here if you can find it
|
| 45 |
-
_LICENSE = ""
|
| 46 |
-
|
| 47 |
-
DATA_DIR = "data/"
|
| 48 |
-
TASKS = {
|
| 49 |
-
"ade_corpus_v2": {
|
| 50 |
-
"name": "ade_corpus_v2",
|
| 51 |
-
"description": "",
|
| 52 |
-
"data_columns": ["Sentence", "ID"],
|
| 53 |
-
"label_columns": {"Label": ["ADE-related", "not ADE-related"]},
|
| 54 |
-
},
|
| 55 |
-
"banking_77": {
|
| 56 |
-
"name": "banking_77",
|
| 57 |
-
"description": "",
|
| 58 |
-
"data_columns": ["Query", "ID"],
|
| 59 |
-
"label_columns": {
|
| 60 |
-
"Label": [
|
| 61 |
-
"Refund_not_showing_up",
|
| 62 |
-
"activate_my_card",
|
| 63 |
-
"age_limit",
|
| 64 |
-
"apple_pay_or_google_pay",
|
| 65 |
-
"atm_support",
|
| 66 |
-
"automatic_top_up",
|
| 67 |
-
"balance_not_updated_after_bank_transfer",
|
| 68 |
-
"balance_not_updated_after_cheque_or_cash_deposit",
|
| 69 |
-
"beneficiary_not_allowed",
|
| 70 |
-
"cancel_transfer",
|
| 71 |
-
"card_about_to_expire",
|
| 72 |
-
"card_acceptance",
|
| 73 |
-
"card_arrival",
|
| 74 |
-
"card_delivery_estimate",
|
| 75 |
-
"card_linking",
|
| 76 |
-
"card_not_working",
|
| 77 |
-
"card_payment_fee_charged",
|
| 78 |
-
"card_payment_not_recognised",
|
| 79 |
-
"card_payment_wrong_exchange_rate",
|
| 80 |
-
"card_swallowed",
|
| 81 |
-
"cash_withdrawal_charge",
|
| 82 |
-
"cash_withdrawal_not_recognised",
|
| 83 |
-
"change_pin",
|
| 84 |
-
"compromised_card",
|
| 85 |
-
"contactless_not_working",
|
| 86 |
-
"country_support",
|
| 87 |
-
"declined_card_payment",
|
| 88 |
-
"declined_cash_withdrawal",
|
| 89 |
-
"declined_transfer",
|
| 90 |
-
"direct_debit_payment_not_recognised",
|
| 91 |
-
"disposable_card_limits",
|
| 92 |
-
"edit_personal_details",
|
| 93 |
-
"exchange_charge",
|
| 94 |
-
"exchange_rate",
|
| 95 |
-
"exchange_via_app",
|
| 96 |
-
"extra_charge_on_statement",
|
| 97 |
-
"failed_transfer",
|
| 98 |
-
"fiat_currency_support",
|
| 99 |
-
"get_disposable_virtual_card",
|
| 100 |
-
"get_physical_card",
|
| 101 |
-
"getting_spare_card",
|
| 102 |
-
"getting_virtual_card",
|
| 103 |
-
"lost_or_stolen_card",
|
| 104 |
-
"lost_or_stolen_phone",
|
| 105 |
-
"order_physical_card",
|
| 106 |
-
"passcode_forgotten",
|
| 107 |
-
"pending_card_payment",
|
| 108 |
-
"pending_cash_withdrawal",
|
| 109 |
-
"pending_top_up",
|
| 110 |
-
"pending_transfer",
|
| 111 |
-
"pin_blocked",
|
| 112 |
-
"receiving_money",
|
| 113 |
-
"request_refund",
|
| 114 |
-
"reverted_card_payment?",
|
| 115 |
-
"supported_cards_and_currencies",
|
| 116 |
-
"terminate_account",
|
| 117 |
-
"top_up_by_bank_transfer_charge",
|
| 118 |
-
"top_up_by_card_charge",
|
| 119 |
-
"top_up_by_cash_or_cheque",
|
| 120 |
-
"top_up_failed",
|
| 121 |
-
"top_up_limits",
|
| 122 |
-
"top_up_reverted",
|
| 123 |
-
"topping_up_by_card",
|
| 124 |
-
"transaction_charged_twice",
|
| 125 |
-
"transfer_fee_charged",
|
| 126 |
-
"transfer_into_account",
|
| 127 |
-
"transfer_not_received_by_recipient",
|
| 128 |
-
"transfer_timing",
|
| 129 |
-
"unable_to_verify_identity",
|
| 130 |
-
"verify_my_identity",
|
| 131 |
-
"verify_source_of_funds",
|
| 132 |
-
"verify_top_up",
|
| 133 |
-
"virtual_card_not_working",
|
| 134 |
-
"visa_or_mastercard",
|
| 135 |
-
"why_verify_identity",
|
| 136 |
-
"wrong_amount_of_cash_received",
|
| 137 |
-
"wrong_exchange_rate_for_cash_withdrawal",
|
| 138 |
-
]
|
| 139 |
-
},
|
| 140 |
-
},
|
| 141 |
-
"terms_of_service": {
|
| 142 |
-
"name": "terms_of_service",
|
| 143 |
-
"description": "",
|
| 144 |
-
"data_columns": ["Sentence", "ID"],
|
| 145 |
-
"label_columns": {"Label": ["not potentially unfair", "potentially unfair"]},
|
| 146 |
-
},
|
| 147 |
-
"tai_safety_research": {
|
| 148 |
-
"name": "tai_safety_research",
|
| 149 |
-
"description": "",
|
| 150 |
-
"data_columns": [
|
| 151 |
-
"Title",
|
| 152 |
-
"Abstract Note",
|
| 153 |
-
"Url",
|
| 154 |
-
"Publication Year",
|
| 155 |
-
"Item Type",
|
| 156 |
-
"Author",
|
| 157 |
-
"Publication Title",
|
| 158 |
-
"ID",
|
| 159 |
-
],
|
| 160 |
-
"label_columns": {"Label": ["TAI safety research", "not TAI safety research"]},
|
| 161 |
-
},
|
| 162 |
-
"neurips_impact_statement_risks": {
|
| 163 |
-
"name": "neurips_impact_statement_risks",
|
| 164 |
-
"description": "",
|
| 165 |
-
"data_columns": ["Paper title", "Paper link", "Impact statement", "ID"],
|
| 166 |
-
"label_columns": {"Label": ["doesn't mention a harmful application", "mentions a harmful application"]},
|
| 167 |
-
},
|
| 168 |
-
"overruling": {
|
| 169 |
-
"name": "overruling",
|
| 170 |
-
"description": "",
|
| 171 |
-
"data_columns": ["Sentence", "ID"],
|
| 172 |
-
"label_columns": {"Label": ["not overruling", "overruling"]},
|
| 173 |
-
},
|
| 174 |
-
"systematic_review_inclusion": {
|
| 175 |
-
"name": "systematic_review_inclusion",
|
| 176 |
-
"description": "",
|
| 177 |
-
"data_columns": ["Title", "Abstract", "Authors", "Journal", "ID"],
|
| 178 |
-
"label_columns": {"Label": ["included", "not included"]},
|
| 179 |
-
},
|
| 180 |
-
"one_stop_english": {
|
| 181 |
-
"name": "one_stop_english",
|
| 182 |
-
"description": "",
|
| 183 |
-
"data_columns": ["Article", "ID"],
|
| 184 |
-
"label_columns": {"Label": ["advanced", "elementary", "intermediate"]},
|
| 185 |
-
},
|
| 186 |
-
"tweet_eval_hate": {
|
| 187 |
-
"name": "tweet_eval_hate",
|
| 188 |
-
"description": "",
|
| 189 |
-
"data_columns": ["Tweet", "ID"],
|
| 190 |
-
"label_columns": {"Label": ["hate speech", "not hate speech"]},
|
| 191 |
-
},
|
| 192 |
-
"twitter_complaints": {
|
| 193 |
-
"name": "twitter_complaints",
|
| 194 |
-
"description": "",
|
| 195 |
-
"data_columns": ["Tweet text", "ID"],
|
| 196 |
-
"label_columns": {"Label": ["complaint", "no complaint"]},
|
| 197 |
-
},
|
| 198 |
-
"semiconductor_org_types": {
|
| 199 |
-
"name": "semiconductor_org_types",
|
| 200 |
-
"description": "",
|
| 201 |
-
"data_columns": ["Paper title", "Organization name", "ID"],
|
| 202 |
-
"label_columns": {"Label": ["company", "research institute", "university"]},
|
| 203 |
-
},
|
| 204 |
-
}
|
| 205 |
-
|
| 206 |
-
_URLs = {s: {"train": f"{DATA_DIR}{s}/train.csv", "test": f"{DATA_DIR}{s}/test_unlabeled.csv"} for s in TASKS}
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
class Raft(datasets.GeneratorBasedBuilder):
|
| 210 |
-
"""RAFT Dataset"""
|
| 211 |
-
VERSION = datasets.Version("1.1.0")
|
| 212 |
-
BUILDER_CONFIGS = []
|
| 213 |
-
|
| 214 |
-
for key in TASKS:
|
| 215 |
-
td = TASKS[key]
|
| 216 |
-
name = td["name"]
|
| 217 |
-
description = td["description"]
|
| 218 |
-
BUILDER_CONFIGS.append(datasets.BuilderConfig(name=name, version=VERSION, description=description))
|
| 219 |
-
|
| 220 |
-
DEFAULT_CONFIG_NAME = (
|
| 221 |
-
"tai_safety_research" # It's not mandatory to have a default configuration. Just use one if it make sense.
|
| 222 |
-
)
|
| 223 |
-
|
| 224 |
-
def _info(self):
|
| 225 |
-
DEFAULT_LABEL_NAME = "Unlabeled"
|
| 226 |
-
|
| 227 |
-
task = TASKS[self.config.name]
|
| 228 |
-
data_columns = {col_name: (datasets.Value("string") if col_name != "ID" else datasets.Value("int32")) for col_name in task["data_columns"]}
|
| 229 |
-
|
| 230 |
-
label_columns = {}
|
| 231 |
-
for label_name in task["label_columns"]:
|
| 232 |
-
labels = [DEFAULT_LABEL_NAME] + task["label_columns"][label_name]
|
| 233 |
-
label_columns[label_name] = datasets.ClassLabel(len(labels), labels)
|
| 234 |
-
|
| 235 |
-
# Merge dicts
|
| 236 |
-
features = datasets.Features(**data_columns, **label_columns)
|
| 237 |
-
|
| 238 |
-
return datasets.DatasetInfo(
|
| 239 |
-
# This is the description that will appear on the datasets page.
|
| 240 |
-
description=_DESCRIPTION,
|
| 241 |
-
# This defines the different columns of the dataset and their types
|
| 242 |
-
features=features, # Here we define them above because they are different between the two configurations
|
| 243 |
-
# If there's a common (input, target) tuple from the features,
|
| 244 |
-
# specify them here. They'll be used if as_supervised=True in
|
| 245 |
-
# builder.as_dataset.
|
| 246 |
-
supervised_keys=None,
|
| 247 |
-
# Homepage of the dataset for documentation
|
| 248 |
-
homepage=_HOMEPAGE,
|
| 249 |
-
# License for the dataset if available
|
| 250 |
-
license=_LICENSE,
|
| 251 |
-
# Citation for the dataset
|
| 252 |
-
citation=_CITATION,
|
| 253 |
-
)
|
| 254 |
-
|
| 255 |
-
def _split_generators(self, dl_manager):
|
| 256 |
-
"""Returns SplitGenerators."""
|
| 257 |
-
# TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
|
| 258 |
-
# If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
|
| 259 |
-
|
| 260 |
-
# dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLs
|
| 261 |
-
# 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.
|
| 262 |
-
# By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
|
| 263 |
-
data_dir = dl_manager.download_and_extract(_URLs)
|
| 264 |
-
dataset = self.config.name
|
| 265 |
-
return [
|
| 266 |
-
datasets.SplitGenerator(
|
| 267 |
-
name=datasets.Split.TRAIN, gen_kwargs={"filepath": data_dir[dataset]["train"], "split": "train"}
|
| 268 |
-
),
|
| 269 |
-
datasets.SplitGenerator(
|
| 270 |
-
name=datasets.Split.TEST, gen_kwargs={"filepath": data_dir[dataset]["test"], "split": "test"}
|
| 271 |
-
),
|
| 272 |
-
]
|
| 273 |
-
|
| 274 |
-
def _generate_examples(
|
| 275 |
-
self, filepath, split # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
| 276 |
-
):
|
| 277 |
-
"""Yields examples as (key, example) tuples."""
|
| 278 |
-
# This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
|
| 279 |
-
# The `key` is here for legacy reason (tfds) and is not important in itself.
|
| 280 |
-
|
| 281 |
-
task = TASKS[self.config.name]
|
| 282 |
-
labels = list(task["label_columns"])
|
| 283 |
-
|
| 284 |
-
with open(filepath, encoding="utf-8") as f:
|
| 285 |
-
csv_reader = csv.reader(f, quotechar='"', delimiter=",", quoting=csv.QUOTE_ALL, skipinitialspace=True)
|
| 286 |
-
column_names = next(csv_reader)
|
| 287 |
-
# Test csvs don't have any label columns.
|
| 288 |
-
if split == "test":
|
| 289 |
-
column_names += labels
|
| 290 |
-
|
| 291 |
-
for id_, row in enumerate(csv_reader):
|
| 292 |
-
if split == "test":
|
| 293 |
-
row += ["Unlabeled"] * len(labels)
|
| 294 |
-
# dicts don't have inherent ordering in python, right??
|
| 295 |
-
yield id_, {name: value for name, value in zip(column_names, row)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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