Spaces:
Runtime error
Runtime error
First Commit
Browse files- app.py +93 -0
- id2label.json +1 -0
- label2id.json +1 -0
app.py
ADDED
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# import gradio as gr
|
2 |
+
# from peft import PeftModel, PeftConfig
|
3 |
+
# from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
4 |
+
# import torch
|
5 |
+
# import json
|
6 |
+
|
7 |
+
# # Load id2label
|
8 |
+
# with open('id2label.json', 'r') as f:
|
9 |
+
# id2label = json.load(f)
|
10 |
+
|
11 |
+
# # Load label2id
|
12 |
+
# with open('label2id.json', 'r') as f:
|
13 |
+
# label2id = json.load(f)
|
14 |
+
|
15 |
+
# print("ID2LABEL", id2label)
|
16 |
+
# print("LABEL2ID", label2id)
|
17 |
+
|
18 |
+
# # Download model from end-point
|
19 |
+
# MODEL ="xlm-roberta-large"
|
20 |
+
# peft_model_id = "JAdeojo/xlm-roberta-large-lora-consumer-complaints-cfpb"
|
21 |
+
# config = PeftConfig.from_pretrained(peft_model_id)
|
22 |
+
# inference_model = AutoModelForSequenceClassification.from_pretrained(
|
23 |
+
# MODEL,
|
24 |
+
# num_labels=len(id2label),
|
25 |
+
# id2label=id2label, label2id=label2id,
|
26 |
+
# # ignore_mismatched_sizes=True
|
27 |
+
# )
|
28 |
+
# tokenizer = AutoTokenizer.from_pretrained(MODEL)
|
29 |
+
# model = PeftModel.from_pretrained(inference_model, "JAdeojo/xlm-roberta-large-lora-consumer-complaints-cfpb")
|
30 |
+
|
31 |
+
# # run inference
|
32 |
+
# def classify_complaint(Complaints, id2label):
|
33 |
+
# inputs = tokenizer(Complaints, return_tensors="pt")
|
34 |
+
# with torch.no_grad():
|
35 |
+
# logits = model(**inputs).logits
|
36 |
+
# # tokens = inputs.tokens()
|
37 |
+
# predictions = torch.argmax(logits, dim=-1)
|
38 |
+
# predicted_label = predictions.item()
|
39 |
+
# predicted_class = id2label[predicted_label]
|
40 |
+
# return predicted_class
|
41 |
+
|
42 |
+
# demo = gr.Interface(fn=classify_complaint, inputs="text", outputs="text")
|
43 |
+
|
44 |
+
# demo.launch()
|
45 |
+
|
46 |
+
|
47 |
+
import gradio as gr
|
48 |
+
from peft import PeftModel, PeftConfig
|
49 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
50 |
+
import torch
|
51 |
+
import json
|
52 |
+
|
53 |
+
# Load id2label
|
54 |
+
with open('id2label.json', 'r') as f:
|
55 |
+
id2label = json.load(f)
|
56 |
+
|
57 |
+
# Load label2id
|
58 |
+
with open('label2id.json', 'r') as f:
|
59 |
+
label2id = json.load(f)
|
60 |
+
|
61 |
+
print("ID2LABEL", id2label)
|
62 |
+
print("LABEL2ID", label2id)
|
63 |
+
|
64 |
+
# Download model from end-point
|
65 |
+
MODEL ="xlm-roberta-large"
|
66 |
+
peft_model_id = "JAdeojo/xlm-roberta-large-lora-consumer-complaints-cfpb_49k"
|
67 |
+
config = PeftConfig.from_pretrained(peft_model_id)
|
68 |
+
inference_model = AutoModelForSequenceClassification.from_pretrained(
|
69 |
+
MODEL,
|
70 |
+
num_labels=len(id2label),
|
71 |
+
id2label=id2label, label2id=label2id,
|
72 |
+
# ignore_mismatched_sizes=True
|
73 |
+
)
|
74 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL)
|
75 |
+
model = PeftModel.from_pretrained(inference_model, peft_model_id)
|
76 |
+
|
77 |
+
# run inference
|
78 |
+
def classify_complaint(Complaints):
|
79 |
+
inputs = tokenizer(Complaints, return_tensors="pt")
|
80 |
+
with torch.no_grad():
|
81 |
+
logits = model(**inputs).logits
|
82 |
+
predictions = torch.argmax(logits, dim=-1)
|
83 |
+
predicted_label = predictions.item()
|
84 |
+
predicted_class = id2label[str(predicted_label)] # Make sure to access id2label with a string key
|
85 |
+
return predicted_class
|
86 |
+
|
87 |
+
# demo = gr.Interface(fn=classify_complaint, inputs=("text", "Enter the financial complaint:"), outputs=("text", "Complaint Category"))
|
88 |
+
# demo.launch()
|
89 |
+
input_component = gr.inputs.Textbox(label="Enter the financial complaint:")
|
90 |
+
output_component = gr.outputs.Textbox(label="Complaint Category")
|
91 |
+
|
92 |
+
demo = gr.Interface(fn=classify_complaint, inputs=input_component, outputs=output_component)
|
93 |
+
demo.launch()
|
id2label.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"0": "Account information incorrect", "1": "Account opened as a result of fraud", "2": "Account sold or transferred to another company", "3": "Account status", "4": "Account status incorrect", "5": "Account terms", "6": "Account terms and changes", "7": "Add-on products and services", "8": "Application denied", "9": "Attempted to collect wrong amount", "10": "Attempted to/Collected exempt funds", "11": "Banking errors", "12": "Billing dispute", "13": "Billing dispute for services", "14": "Billing problem", "15": "Bounced checks or returned payments", "16": "Called after sent written cease of comm", "17": "Called before 8am or after 9pm", "18": "Called outside of 8am-9pm", "19": "Can't close your account", "20": "Can't decrease my monthly payments", "21": "Can't get flexible payment options", "22": "Can't get other flexible options for repaying your loan", "23": "Can't qualify for a loan", "24": "Can't stop withdrawals from your account", "25": "Can't temporarily delay making payments", "26": "Can't temporarily postpone payments", "27": "Can't use card to make purchases", "28": "Card company isn't resolving a dispute about a purchase or transfer", "29": "Card opened as result of identity theft or fraud", "30": "Card was charged for something you did not purchase with the card", "31": "Cashing a check", "32": "Changes in terms from what was offered or advertised", "33": "Changes in terms mid-deal or after closing", "34": "Charged for a purchase or transfer you did not make with the card", "35": "Charged too much interest", "36": "Collected or attempted to collect exempt funds", "37": "Company closed your account", "38": "Confusing or misleading advertising", "39": "Confusing or misleading advertising about the card", "40": "Confusing or misleading advertising about the credit card", "41": "Confusing or misleading advertising or marketing", "42": "Confusing or missing disclosures", "43": "Contacted employer after asked not to", "44": "Contacted me after I asked not to", "45": "Contacted me instead of my attorney", "46": "Contacted you after you asked them to stop", "47": "Contacted you instead of your attorney", "48": "Contacted your employer", "49": "Credit card company forcing arbitration", "50": "Credit card company isn't resolving a dispute about a purchase on your statement", "51": "Credit card company won't increase or decrease your credit limit", "52": "Credit card company won't work with you while you're going through financial hardship", "53": "Credit denial", "54": "Credit inquiries on your report that you don't recognize", "55": "Debt is not mine", "56": "Debt is not yours", "57": "Debt resulted from identity theft", "58": "Debt was already discharged in bankruptcy and is no longer owed", "59": "Debt was discharged in bankruptcy", "60": "Debt was paid", "61": "Debt was result of identity theft", "62": "Delay in processing application", "63": "Denied loan", "64": "Denied request to lower payments", "65": "Deposits and withdrawals", "66": "Deposits or withdrawals", "67": "Didn't receive advertised or promotional terms", "68": "Didn't receive enough information to verify debt", "69": "Didn't receive notice of right to dispute", "70": "Didn't receive services that were advertised", "71": "Didn't receive terms that were advertised", "72": "Difficulty submitting a dispute or getting information about a dispute over the phone", "73": "Don't agree with fees charged", "74": "Don't agree with the fees charged", "75": "Don't want a card provided by your employer or the government", "76": "Excess mileage, damage, or wear fees, or other problem after the lease is finish", "77": "Fee problem", "78": "Fees charged for closing account", "79": "Filed for bankruptcy", "80": "Fraudulent loan", "81": "Frequent or repeated calls", "82": "Funds not handled or disbursed as instructed", "83": "Funds not received from closed account", "84": "Having problems with customer service", "85": "High-pressure sales tactics", "86": "Impersonated an attorney or official", "87": "Impersonated attorney, law enforcement, or government official", "88": "Inadequate help over the phone", "89": "Indicated committed crime not paying", "90": "Indicated shouldn't respond to lawsuit", "91": "Indicated you were committing crime by not paying debt", "92": "Information belongs to someone else", "93": "Information is incorrect", "94": "Information is missing that should be on the report", "95": "Information is not mine", "96": "Information that should be on the report is missing", "97": "Investigation took more than 30 days", "98": "Investigation took too long", "99": "Keep getting calls about my loan", "100": "Keep getting calls about your loan", "101": "Late or other fees", "102": "Lender trying to repossess or disable the vehicle", "103": "Loan balance remaining after the vehicle is repossessed and sold", "104": "Loan sold or transferred to another company", "105": "Money was taken from your account on the wrong day or for the wrong amount", "106": "Need information about my balance/terms", "107": "Need information about your loan balance or loan terms", "108": "No notice of investigation status/result", "109": "Non-sufficient funds and associated fees", "110": "Not disclosed as an attempt to collect", "111": "Not given enough info to verify debt", "112": "Notification didn't disclose it was an attempt to collect a debt", "113": "Old information reappears or never goes away", "114": "Other problem", "115": "Other problem getting your report or credit score", "116": "Overcharged for a purchase or transfer you did make with the card", "117": "Overcharged for something you did purchase with the card", "118": "Overdraft charges", "119": "Overdrafts and overdraft fees", "120": "Personal information", "121": "Personal information incorrect", "122": "Privacy issues", "123": "Problem accessing account", "124": "Problem adding money", "125": "Problem after you declared or threatened to declare bankruptcy", "126": "Problem canceling credit monitoring or identify theft protection service", "127": "Problem cancelling or closing account", "128": "Problem during payment process", "129": "Problem extending the lease", "130": "Problem getting a working replacement card", "131": "Problem getting my free annual report", "132": "Problem getting report or credit score", "133": "Problem getting your free annual credit report", "134": "Problem lowering your monthly payments", "135": "Problem making or receiving payments", "136": "Problem related to refinancing", "137": "Problem using a debit or ATM card", "138": "Problem using the card to withdraw money from an ATM", "139": "Problem when attempting to purchase vehicle at the end of the lease", "140": "Problem while selling or giving up the vehicle", "141": "Problem with a check written from your prepaid card account", "142": "Problem with a trade-in", "143": "Problem with additional add-on products or services purchased with the loan", "144": "Problem with additional products or services purchased with the loan", "145": "Problem with balance transfer", "146": "Problem with cash advances", "147": "Problem with convenience check", "148": "Problem with customer service", "149": "Problem with direct deposit", "150": "Problem with fees", "151": "Problem with fees charged", "152": "Problem with fees or penalties", "153": "Problem with fraud alerts", "154": "Problem with paying off the loan", "155": "Problem with personal statement of dispute", "156": "Problem with product or service terms changing", "157": "Problem with renewal", "158": "Problem with rewards from credit card", "159": "Problem with signing the paperwork", "160": "Problem with statement of dispute", "161": "Problem with the interest rate", "162": "Public record", "163": "Public record information inaccurate", "164": "Qualified for a better loan than the one offered", "165": "Qualify for a better loan than offered", "166": "Received bad information about my loan", "167": "Received bad information about your loan", "168": "Received marketing offer after opted out", "169": "Received unsolicited financial product or insurance offers after opting out", "170": "Received unwanted marketing or advertising", "171": "Receiving unwanted marketing/advertising", "172": "Reinserted previously deleted info", "173": "Report improperly shared by CRC", "174": "Report provided to employer without your written authorization", "175": "Report shared with employer w/o consent", "176": "Reporting company used your report improperly", "177": "Right to dispute notice not received", "178": "Seized or attempted to seize your property", "179": "Seized/Attempted to seize property", "180": "Sent card you never applied for", "181": "Sued w/o proper notification of suit", "182": "Sued where didn't live/sign for debt", "183": "Sued you in a state where you do not live or did not sign for the debt", "184": "Sued you without properly notifying you of lawsuit", "185": "Talked to a third party about my debt", "186": "Talked to a third-party about your debt", "187": "Termination fees or other problem when ending the lease early", "188": "Their investigation did not fix an error on your report", "189": "Threatened arrest/jail if do not pay", "190": "Threatened or suggested your credit would be damaged", "191": "Threatened to arrest you or take you to jail if you do not pay", "192": "Threatened to sue on too old debt", "193": "Threatened to sue you for very old debt", "194": "Threatened to take legal action", "195": "Told you not to respond to a lawsuit they filed against you", "196": "Transaction was not authorized", "197": "Trouble closing card", "198": "Trouble getting a working replacement card", "199": "Trouble getting information about the card", "200": "Trouble getting, activating, or registering a card", "201": "Trouble using the card to pay a bill", "202": "Trouble using the card to send money to another person", "203": "Trouble using the card to spend money in a store or online", "204": "Trouble with how payments are being handled", "205": "Trouble with how payments are handled", "206": "Unable to open an account", "207": "Unable to receive car title or other problem after the loan is paid off", "208": "Unexpected increase in interest rate", "209": "Used obscene, profane, or other abusive language", "210": "Used obscene/profane/abusive language", "211": "Was not notified of investigation status or results", "212": "You never received your bill or did not know a payment was due", "213": "You told them to stop contacting you, but they keep trying"}
|
label2id.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"Account information incorrect": 0, "Account opened as a result of fraud": 1, "Account sold or transferred to another company": 2, "Account status": 3, "Account status incorrect": 4, "Account terms": 5, "Account terms and changes": 6, "Add-on products and services": 7, "Application denied": 8, "Attempted to collect wrong amount": 9, "Attempted to/Collected exempt funds": 10, "Banking errors": 11, "Billing dispute": 12, "Billing dispute for services": 13, "Billing problem": 14, "Bounced checks or returned payments": 15, "Called after sent written cease of comm": 16, "Called before 8am or after 9pm": 17, "Called outside of 8am-9pm": 18, "Can't close your account": 19, "Can't decrease my monthly payments": 20, "Can't get flexible payment options": 21, "Can't get other flexible options for repaying your loan": 22, "Can't qualify for a loan": 23, "Can't stop withdrawals from your account": 24, "Can't temporarily delay making payments": 25, "Can't temporarily postpone payments": 26, "Can't use card to make purchases": 27, "Card company isn't resolving a dispute about a purchase or transfer": 28, "Card opened as result of identity theft or fraud": 29, "Card was charged for something you did not purchase with the card": 30, "Cashing a check": 31, "Changes in terms from what was offered or advertised": 32, "Changes in terms mid-deal or after closing": 33, "Charged for a purchase or transfer you did not make with the card": 34, "Charged too much interest": 35, "Collected or attempted to collect exempt funds": 36, "Company closed your account": 37, "Confusing or misleading advertising": 38, "Confusing or misleading advertising about the card": 39, "Confusing or misleading advertising about the credit card": 40, "Confusing or misleading advertising or marketing": 41, "Confusing or missing disclosures": 42, "Contacted employer after asked not to": 43, "Contacted me after I asked not to": 44, "Contacted me instead of my attorney": 45, "Contacted you after you asked them to stop": 46, "Contacted you instead of your attorney": 47, "Contacted your employer": 48, "Credit card company forcing arbitration": 49, "Credit card company isn't resolving a dispute about a purchase on your statement": 50, "Credit card company won't increase or decrease your credit limit": 51, "Credit card company won't work with you while you're going through financial hardship": 52, "Credit denial": 53, "Credit inquiries on your report that you don't recognize": 54, "Debt is not mine": 55, "Debt is not yours": 56, "Debt resulted from identity theft": 57, "Debt was already discharged in bankruptcy and is no longer owed": 58, "Debt was discharged in bankruptcy": 59, "Debt was paid": 60, "Debt was result of identity theft": 61, "Delay in processing application": 62, "Denied loan": 63, "Denied request to lower payments": 64, "Deposits and withdrawals": 65, "Deposits or withdrawals": 66, "Didn't receive advertised or promotional terms": 67, "Didn't receive enough information to verify debt": 68, "Didn't receive notice of right to dispute": 69, "Didn't receive services that were advertised": 70, "Didn't receive terms that were advertised": 71, "Difficulty submitting a dispute or getting information about a dispute over the phone": 72, "Don't agree with fees charged": 73, "Don't agree with the fees charged": 74, "Don't want a card provided by your employer or the government": 75, "Excess mileage, damage, or wear fees, or other problem after the lease is finish": 76, "Fee problem": 77, "Fees charged for closing account": 78, "Filed for bankruptcy": 79, "Fraudulent loan": 80, "Frequent or repeated calls": 81, "Funds not handled or disbursed as instructed": 82, "Funds not received from closed account": 83, "Having problems with customer service": 84, "High-pressure sales tactics": 85, "Impersonated an attorney or official": 86, "Impersonated attorney, law enforcement, or government official": 87, "Inadequate help over the phone": 88, "Indicated committed crime not paying": 89, "Indicated shouldn't respond to lawsuit": 90, "Indicated you were committing crime by not paying debt": 91, "Information belongs to someone else": 92, "Information is incorrect": 93, "Information is missing that should be on the report": 94, "Information is not mine": 95, "Information that should be on the report is missing": 96, "Investigation took more than 30 days": 97, "Investigation took too long": 98, "Keep getting calls about my loan": 99, "Keep getting calls about your loan": 100, "Late or other fees": 101, "Lender trying to repossess or disable the vehicle": 102, "Loan balance remaining after the vehicle is repossessed and sold": 103, "Loan sold or transferred to another company": 104, "Money was taken from your account on the wrong day or for the wrong amount": 105, "Need information about my balance/terms": 106, "Need information about your loan balance or loan terms": 107, "No notice of investigation status/result": 108, "Non-sufficient funds and associated fees": 109, "Not disclosed as an attempt to collect": 110, "Not given enough info to verify debt": 111, "Notification didn't disclose it was an attempt to collect a debt": 112, "Old information reappears or never goes away": 113, "Other problem": 114, "Other problem getting your report or credit score": 115, "Overcharged for a purchase or transfer you did make with the card": 116, "Overcharged for something you did purchase with the card": 117, "Overdraft charges": 118, "Overdrafts and overdraft fees": 119, "Personal information": 120, "Personal information incorrect": 121, "Privacy issues": 122, "Problem accessing account": 123, "Problem adding money": 124, "Problem after you declared or threatened to declare bankruptcy": 125, "Problem canceling credit monitoring or identify theft protection service": 126, "Problem cancelling or closing account": 127, "Problem during payment process": 128, "Problem extending the lease": 129, "Problem getting a working replacement card": 130, "Problem getting my free annual report": 131, "Problem getting report or credit score": 132, "Problem getting your free annual credit report": 133, "Problem lowering your monthly payments": 134, "Problem making or receiving payments": 135, "Problem related to refinancing": 136, "Problem using a debit or ATM card": 137, "Problem using the card to withdraw money from an ATM": 138, "Problem when attempting to purchase vehicle at the end of the lease": 139, "Problem while selling or giving up the vehicle": 140, "Problem with a check written from your prepaid card account": 141, "Problem with a trade-in": 142, "Problem with additional add-on products or services purchased with the loan": 143, "Problem with additional products or services purchased with the loan": 144, "Problem with balance transfer": 145, "Problem with cash advances": 146, "Problem with convenience check": 147, "Problem with customer service": 148, "Problem with direct deposit": 149, "Problem with fees": 150, "Problem with fees charged": 151, "Problem with fees or penalties": 152, "Problem with fraud alerts": 153, "Problem with paying off the loan": 154, "Problem with personal statement of dispute": 155, "Problem with product or service terms changing": 156, "Problem with renewal": 157, "Problem with rewards from credit card": 158, "Problem with signing the paperwork": 159, "Problem with statement of dispute": 160, "Problem with the interest rate": 161, "Public record": 162, "Public record information inaccurate": 163, "Qualified for a better loan than the one offered": 164, "Qualify for a better loan than offered": 165, "Received bad information about my loan": 166, "Received bad information about your loan": 167, "Received marketing offer after opted out": 168, "Received unsolicited financial product or insurance offers after opting out": 169, "Received unwanted marketing or advertising": 170, "Receiving unwanted marketing/advertising": 171, "Reinserted previously deleted info": 172, "Report improperly shared by CRC": 173, "Report provided to employer without your written authorization": 174, "Report shared with employer w/o consent": 175, "Reporting company used your report improperly": 176, "Right to dispute notice not received": 177, "Seized or attempted to seize your property": 178, "Seized/Attempted to seize property": 179, "Sent card you never applied for": 180, "Sued w/o proper notification of suit": 181, "Sued where didn't live/sign for debt": 182, "Sued you in a state where you do not live or did not sign for the debt": 183, "Sued you without properly notifying you of lawsuit": 184, "Talked to a third party about my debt": 185, "Talked to a third-party about your debt": 186, "Termination fees or other problem when ending the lease early": 187, "Their investigation did not fix an error on your report": 188, "Threatened arrest/jail if do not pay": 189, "Threatened or suggested your credit would be damaged": 190, "Threatened to arrest you or take you to jail if you do not pay": 191, "Threatened to sue on too old debt": 192, "Threatened to sue you for very old debt": 193, "Threatened to take legal action": 194, "Told you not to respond to a lawsuit they filed against you": 195, "Transaction was not authorized": 196, "Trouble closing card": 197, "Trouble getting a working replacement card": 198, "Trouble getting information about the card": 199, "Trouble getting, activating, or registering a card": 200, "Trouble using the card to pay a bill": 201, "Trouble using the card to send money to another person": 202, "Trouble using the card to spend money in a store or online": 203, "Trouble with how payments are being handled": 204, "Trouble with how payments are handled": 205, "Unable to open an account": 206, "Unable to receive car title or other problem after the loan is paid off": 207, "Unexpected increase in interest rate": 208, "Used obscene, profane, or other abusive language": 209, "Used obscene/profane/abusive language": 210, "Was not notified of investigation status or results": 211, "You never received your bill or did not know a payment was due": 212, "You told them to stop contacting you, but they keep trying": 213}
|