Datasets:
Tasks:
Text Classification
Sub-tasks:
topic-classification
Languages:
English
Size:
1M<n<10M
License:
File size: 8,424 Bytes
37a25a0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
import csv
import os
import textwrap
import datasets
from datasets import TextClassification
logger = datasets.logging.get_logger(__name__)
_DESCRIPTION = textwrap.dedent(
"""\
The Consumer Complaint Database is a collection of complaints about consumer financial products and services that we sent to companies for response. Complaints are published after the company responds, confirming a commercial relationship with the consumer, or after 15 days, whichever comes first. Complaints referred to other regulators, such as complaints about depository institutions with less than $10 billion in assets, are not published in the Consumer Complaint Database. The database generally updates daily.
There are multiple Text Classification problems that can be solved with this dataset:
- Complaint Type Identification
- Complaint Sub-Product Identification
- Complaint from vulnerable or Service-person
"""
)
_CITATION = """\
"""
_BASE_DOWNLOAD_URL = "https://files.consumerfinance.gov/ccdb/complaints.csv.zip"
_HOMEPAGE = "https://www.consumerfinance.gov/data-research/consumer-complaints/"
_LICENSE = "https://cfpb.github.io/source-code-policy/"
_SUPPORTED_VERSIONS = [
datasets.Version("1.0.0", "Initial Version"),
]
_DEFAULT_VERSION = datasets.Version("1.0.0", "Initial Version")
_url = _BASE_DOWNLOAD_URL
_TAGS = ["Servicemember", "Older American", "Older American, Servicemember", ""]
_SUB_PRODUCT_CATEGORIES = [
"Credit reporting",
"General-purpose credit card or charge card",
"Checking account",
"Other debt",
"Second mortgage",
"Conventional home mortgage",
"I do not know",
"Credit card debt",
"Medical debt",
"Federal student loan servicing",
"FHA mortgage",
"Conventional fixed mortgage",
"Loan",
"Other (i.e. phone, health club, etc.)",
"Store credit card",
"Installment loan",
"Credit card",
"Medical",
"Mobile or digital wallet",
"Private student loan",
"Non-federal student loan",
"Domestic (US) money transfer",
"VA mortgage",
"Vehicle loan",
"Auto debt",
"Payday loan",
"Conventional adjustable mortgage (ARM)",
"Other personal consumer report",
"Payday loan debt",
"Savings account",
"Virtual currency",
"Other bank product/service",
"Other type of mortgage",
"Other banking product or service",
"Other mortgage",
"International money transfer",
"Lease",
"General-purpose prepaid card",
"Home equity loan or line of credit (HELOC)",
"Government benefit card",
"Mortgage debt",
"Personal line of credit",
"Home equity loan or line of credit",
"Federal student loan debt",
"Private student loan debt",
"Credit repair services",
"Title loan",
"Auto",
"Vehicle lease",
"Mortgage",
"Reverse mortgage",
"General purpose card",
"CD (Certificate of Deposit)",
"Federal student loan",
"Payroll card",
"Debt settlement",
"Check cashing service",
"Traveler's check or cashier's check",
"Gift card",
"(CD) Certificate of deposit",
"Money order",
"Foreign currency exchange",
"Refund anticipation check",
"Gift or merchant card",
"Cashing a check without an account",
"ID prepaid card",
"Mobile wallet",
"Government benefit payment card",
"Pawn loan",
"Other special purpose card",
"Check cashing",
"Credit repair",
"Traveler’s/Cashier’s checks",
"Transit card",
"Student prepaid card",
"Electronic Benefit Transfer / EBT card",
"",
]
_PRODUCT_CATEGORIES = [
"Credit reporting, credit repair services, or other personal consumer reports",
"Debt collection",
"Mortgage",
"Credit card or prepaid card",
"Checking or savings account",
"Credit reporting",
"Student loan",
"Money transfer, virtual currency, or money service",
"Credit card",
"Vehicle loan or lease",
"Bank account or service",
"Payday loan, title loan, or personal loan",
"Consumer Loan",
"Payday loan",
"Money transfers",
"Prepaid card",
"Other financial service",
"Virtual currency",
]
class ConsumerComplaints(datasets.GeneratorBasedBuilder):
"""Consumer Complaints dataset."""
def _info(self):
features = datasets.Features(
{
"Date Received": datasets.Value("timestamp[s]"),
"Product": datasets.features.ClassLabel(names=_PRODUCT_CATEGORIES),
"Sub Product": datasets.features.ClassLabel(names=_SUB_PRODUCT_CATEGORIES),
"Issue": datasets.Value("string"),
"Sub Issue": datasets.Value("string"),
"Complaint Text": datasets.Value("string"),
"Company Public Response": datasets.Value("string"),
"Company": datasets.Value("string"),
"State": datasets.Value("string"),
"Zip Code": datasets.Value("string"),
"Tags": datasets.features.ClassLabel(names=_TAGS),
"Consumer Consent Provided": datasets.Value("string"),
"Submitted via": datasets.Value("string"),
"Date Sent To Company": datasets.Value("string"),
"Company Response To Consumer": datasets.Value("string"),
"Timely Response": datasets.Value("string"),
"Consumer Disputed": datasets.Value("string"),
"Complaint ID": datasets.Value("string"),
}
)
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=features,
homepage=_HOMEPAGE,
license=_LICENSE,
citation=_CITATION,
task_templates=[
TextClassification(text_column="Complaint Text", label_column="Product"),
TextClassification(text_column="Complaint Text", label_column="Sub Product"),
TextClassification(text_column="Complaint Text", label_column="Tags"),
],
)
def _split_generators(self, dl_manager):
path = dl_manager.download_and_extract(_url)
path = os.path.join(path, "complaints.csv")
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={"filepath": path},
)
]
def _generate_examples(self, filepath):
"""Generate consumer complaints examples."""
with open(filepath, encoding="utf-8") as csv_file:
csv_reader = csv.reader(
csv_file, quotechar='"', delimiter=",", quoting=csv.QUOTE_ALL, skipinitialspace=True
)
next(csv_reader) # skip header row
for id_, row in enumerate(csv_reader):
(
date_received,
product,
sub_product,
issue,
sub_issue,
complaint_text,
company_public_response,
company,
state,
zip_code,
tags,
consumer_consent_provided,
submitted_via,
date_sent_to_company,
company_response_to_consumer,
timely_response,
consumer_disputed,
complaint_id,
) = row
yield id_, {
"Date Received": date_received,
"Product": product,
"Sub Product": sub_product,
"Issue": issue,
"Sub Issue": sub_issue,
"Complaint Text": complaint_text,
"Company Public Response": company_public_response,
"Company": company,
"State": state,
"Zip Code": zip_code,
"Tags": tags,
"Consumer Consent Provided": consumer_consent_provided,
"Submitted via": submitted_via,
"Date Sent To Company": date_sent_to_company,
"Company Response To Consumer": company_response_to_consumer,
"Timely Response": timely_response,
"Consumer Disputed": consumer_disputed,
"Complaint ID": complaint_id,
}
|