Spaces:
Sleeping
Sleeping
aditya-nci commited on
Commit ·
263b8fa
1
Parent(s): c68f678
Added Gradio app, model files, and dependencies
Browse files- .DS_Store +0 -0
- app.py +56 -0
- model/config.json +39 -0
- model/model.safetensors +3 -0
- model/special_tokens_map.json +7 -0
- model/tokenizer_config.json +58 -0
- model/vocab.txt +0 -0
- requirements.txt +4 -0
.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
app.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
# Load the tokenizer and model from the model folder
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained("./model")
|
| 7 |
+
model = AutoModelForSequenceClassification.from_pretrained("./model", trust_remote_code=True)
|
| 8 |
+
|
| 9 |
+
# Set the device (CPU or GPU)
|
| 10 |
+
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
| 11 |
+
model = model.to(device)
|
| 12 |
+
|
| 13 |
+
# Define topic mapping
|
| 14 |
+
topic_mapping = {
|
| 15 |
+
0: 'Bank Account Services',
|
| 16 |
+
1: 'Credit Card or Prepaid Card',
|
| 17 |
+
2: 'Others',
|
| 18 |
+
3: 'Theft/Dispute Reporting',
|
| 19 |
+
4: 'Mortgage/Loan'
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
# Prediction function
|
| 23 |
+
def predict_complaint_topic(complaint_text):
|
| 24 |
+
encoding = tokenizer.encode_plus(
|
| 25 |
+
complaint_text,
|
| 26 |
+
add_special_tokens=True,
|
| 27 |
+
max_length=128,
|
| 28 |
+
return_token_type_ids=False,
|
| 29 |
+
padding='max_length',
|
| 30 |
+
truncation=True,
|
| 31 |
+
return_attention_mask=True,
|
| 32 |
+
return_tensors='pt'
|
| 33 |
+
)
|
| 34 |
+
input_ids = encoding['input_ids'].to(device)
|
| 35 |
+
attention_mask = encoding['attention_mask'].to(device)
|
| 36 |
+
|
| 37 |
+
with torch.no_grad():
|
| 38 |
+
outputs = model(input_ids=input_ids, attention_mask=attention_mask)
|
| 39 |
+
logits = outputs.logits
|
| 40 |
+
predicted_class_id = torch.argmax(logits, dim=1).item()
|
| 41 |
+
|
| 42 |
+
predicted_topic = topic_mapping[predicted_class_id]
|
| 43 |
+
return predicted_topic
|
| 44 |
+
|
| 45 |
+
# Create Gradio interface
|
| 46 |
+
iface = gr.Interface(
|
| 47 |
+
fn=predict_complaint_topic, # Function to call for prediction
|
| 48 |
+
inputs=gr.Textbox(label="Enter your complaint text"), # Input type (Textbox)
|
| 49 |
+
outputs=gr.Textbox(label="Predicted Complaint Topic"), # Output type (Textbox)
|
| 50 |
+
live=True, # Enable live prediction as the user types
|
| 51 |
+
title="Complaint Topic Classifier", # Title of the app
|
| 52 |
+
description="This model classifies complaints into different topics like 'Bank Account Services', 'Credit Card or Prepaid Card', etc." # Description of the app
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
# Launch the interface
|
| 56 |
+
iface.launch()
|
model/config.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_name_or_path": "distilbert-base-uncased",
|
| 3 |
+
"activation": "gelu",
|
| 4 |
+
"architectures": [
|
| 5 |
+
"DistilBertForSequenceClassification"
|
| 6 |
+
],
|
| 7 |
+
"attention_dropout": 0.1,
|
| 8 |
+
"dim": 768,
|
| 9 |
+
"dropout": 0.1,
|
| 10 |
+
"hidden_dim": 3072,
|
| 11 |
+
"id2label": {
|
| 12 |
+
"0": "LABEL_0",
|
| 13 |
+
"1": "LABEL_1",
|
| 14 |
+
"2": "LABEL_2",
|
| 15 |
+
"3": "LABEL_3",
|
| 16 |
+
"4": "LABEL_4"
|
| 17 |
+
},
|
| 18 |
+
"initializer_range": 0.02,
|
| 19 |
+
"label2id": {
|
| 20 |
+
"LABEL_0": 0,
|
| 21 |
+
"LABEL_1": 1,
|
| 22 |
+
"LABEL_2": 2,
|
| 23 |
+
"LABEL_3": 3,
|
| 24 |
+
"LABEL_4": 4
|
| 25 |
+
},
|
| 26 |
+
"max_position_embeddings": 512,
|
| 27 |
+
"model_type": "distilbert",
|
| 28 |
+
"n_heads": 12,
|
| 29 |
+
"n_layers": 6,
|
| 30 |
+
"pad_token_id": 0,
|
| 31 |
+
"problem_type": "single_label_classification",
|
| 32 |
+
"qa_dropout": 0.1,
|
| 33 |
+
"seq_classif_dropout": 0.2,
|
| 34 |
+
"sinusoidal_pos_embds": false,
|
| 35 |
+
"tie_weights_": true,
|
| 36 |
+
"torch_dtype": "float32",
|
| 37 |
+
"transformers_version": "4.49.0",
|
| 38 |
+
"vocab_size": 30522
|
| 39 |
+
}
|
model/model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9694300978a62b025d9cb16b3f7114e4761a6808bfbbbb27d527d5bf4aa83d1f
|
| 3 |
+
size 267841796
|
model/special_tokens_map.json
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cls_token": "[CLS]",
|
| 3 |
+
"mask_token": "[MASK]",
|
| 4 |
+
"pad_token": "[PAD]",
|
| 5 |
+
"sep_token": "[SEP]",
|
| 6 |
+
"unk_token": "[UNK]"
|
| 7 |
+
}
|
model/tokenizer_config.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"added_tokens_decoder": {
|
| 3 |
+
"0": {
|
| 4 |
+
"content": "[PAD]",
|
| 5 |
+
"lstrip": false,
|
| 6 |
+
"normalized": false,
|
| 7 |
+
"rstrip": false,
|
| 8 |
+
"single_word": false,
|
| 9 |
+
"special": true
|
| 10 |
+
},
|
| 11 |
+
"100": {
|
| 12 |
+
"content": "[UNK]",
|
| 13 |
+
"lstrip": false,
|
| 14 |
+
"normalized": false,
|
| 15 |
+
"rstrip": false,
|
| 16 |
+
"single_word": false,
|
| 17 |
+
"special": true
|
| 18 |
+
},
|
| 19 |
+
"101": {
|
| 20 |
+
"content": "[CLS]",
|
| 21 |
+
"lstrip": false,
|
| 22 |
+
"normalized": false,
|
| 23 |
+
"rstrip": false,
|
| 24 |
+
"single_word": false,
|
| 25 |
+
"special": true
|
| 26 |
+
},
|
| 27 |
+
"102": {
|
| 28 |
+
"content": "[SEP]",
|
| 29 |
+
"lstrip": false,
|
| 30 |
+
"normalized": false,
|
| 31 |
+
"rstrip": false,
|
| 32 |
+
"single_word": false,
|
| 33 |
+
"special": true
|
| 34 |
+
},
|
| 35 |
+
"103": {
|
| 36 |
+
"content": "[MASK]",
|
| 37 |
+
"lstrip": false,
|
| 38 |
+
"normalized": false,
|
| 39 |
+
"rstrip": false,
|
| 40 |
+
"single_word": false,
|
| 41 |
+
"special": true
|
| 42 |
+
}
|
| 43 |
+
},
|
| 44 |
+
"clean_up_tokenization_spaces": true,
|
| 45 |
+
"cls_token": "[CLS]",
|
| 46 |
+
"do_basic_tokenize": true,
|
| 47 |
+
"do_lower_case": true,
|
| 48 |
+
"extra_special_tokens": {},
|
| 49 |
+
"mask_token": "[MASK]",
|
| 50 |
+
"model_max_length": 512,
|
| 51 |
+
"never_split": null,
|
| 52 |
+
"pad_token": "[PAD]",
|
| 53 |
+
"sep_token": "[SEP]",
|
| 54 |
+
"strip_accents": null,
|
| 55 |
+
"tokenize_chinese_chars": true,
|
| 56 |
+
"tokenizer_class": "DistilBertTokenizer",
|
| 57 |
+
"unk_token": "[UNK]"
|
| 58 |
+
}
|
model/vocab.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
torch
|
| 3 |
+
transformers
|
| 4 |
+
safetensors
|