quocnhut134
commited on
Commit
·
793f56e
1
Parent(s):
a4c60e4
Initialize Project
Browse files- Dockerfile +1 -0
- requirements.txt +16 -2
- saved_models/distilbert_distilbert-base-uncased-finetuned-banking77/config.json +182 -0
- saved_models/distilbert_distilbert-base-uncased-finetuned-banking77/model.safetensors +3 -0
- saved_models/distilbert_distilbert-base-uncased-finetuned-banking77/special_tokens_map.json +7 -0
- saved_models/distilbert_distilbert-base-uncased-finetuned-banking77/tokenizer.json +0 -0
- saved_models/distilbert_distilbert-base-uncased-finetuned-banking77/tokenizer_config.json +56 -0
- saved_models/distilbert_distilbert-base-uncased-finetuned-banking77/training_args.bin +3 -0
- saved_models/distilbert_distilbert-base-uncased-finetuned-banking77/vocab.txt +0 -0
- src/streamlit_app.py +93 -38
- src/style.css +6 -0
Dockerfile
CHANGED
|
@@ -10,6 +10,7 @@ RUN apt-get update && apt-get install -y \
|
|
| 10 |
|
| 11 |
COPY requirements.txt ./
|
| 12 |
COPY src/ ./src/
|
|
|
|
| 13 |
|
| 14 |
RUN pip3 install -r requirements.txt
|
| 15 |
|
|
|
|
| 10 |
|
| 11 |
COPY requirements.txt ./
|
| 12 |
COPY src/ ./src/
|
| 13 |
+
COPY saved_models/ ./saved_models/
|
| 14 |
|
| 15 |
RUN pip3 install -r requirements.txt
|
| 16 |
|
requirements.txt
CHANGED
|
@@ -1,3 +1,17 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
pandas
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
transformers
|
| 2 |
+
datasets
|
| 3 |
+
torch
|
| 4 |
+
scikit-learn
|
| 5 |
+
jupyterlab
|
| 6 |
+
matplotlib
|
| 7 |
+
seaborn
|
| 8 |
+
sentencepiece
|
| 9 |
+
python-dotenv
|
| 10 |
+
evaluate
|
| 11 |
pandas
|
| 12 |
+
tqdm
|
| 13 |
+
streamlit
|
| 14 |
+
selenium==4.31.0
|
| 15 |
+
webdriver-manager==4.0.2
|
| 16 |
+
numpy
|
| 17 |
+
joblib
|
saved_models/distilbert_distilbert-base-uncased-finetuned-banking77/config.json
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"activation": "gelu",
|
| 3 |
+
"architectures": [
|
| 4 |
+
"DistilBertForSequenceClassification"
|
| 5 |
+
],
|
| 6 |
+
"attention_dropout": 0.1,
|
| 7 |
+
"dim": 768,
|
| 8 |
+
"dropout": 0.1,
|
| 9 |
+
"dtype": "float32",
|
| 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 |
+
"5": "LABEL_5",
|
| 18 |
+
"6": "LABEL_6",
|
| 19 |
+
"7": "LABEL_7",
|
| 20 |
+
"8": "LABEL_8",
|
| 21 |
+
"9": "LABEL_9",
|
| 22 |
+
"10": "LABEL_10",
|
| 23 |
+
"11": "LABEL_11",
|
| 24 |
+
"12": "LABEL_12",
|
| 25 |
+
"13": "LABEL_13",
|
| 26 |
+
"14": "LABEL_14",
|
| 27 |
+
"15": "LABEL_15",
|
| 28 |
+
"16": "LABEL_16",
|
| 29 |
+
"17": "LABEL_17",
|
| 30 |
+
"18": "LABEL_18",
|
| 31 |
+
"19": "LABEL_19",
|
| 32 |
+
"20": "LABEL_20",
|
| 33 |
+
"21": "LABEL_21",
|
| 34 |
+
"22": "LABEL_22",
|
| 35 |
+
"23": "LABEL_23",
|
| 36 |
+
"24": "LABEL_24",
|
| 37 |
+
"25": "LABEL_25",
|
| 38 |
+
"26": "LABEL_26",
|
| 39 |
+
"27": "LABEL_27",
|
| 40 |
+
"28": "LABEL_28",
|
| 41 |
+
"29": "LABEL_29",
|
| 42 |
+
"30": "LABEL_30",
|
| 43 |
+
"31": "LABEL_31",
|
| 44 |
+
"32": "LABEL_32",
|
| 45 |
+
"33": "LABEL_33",
|
| 46 |
+
"34": "LABEL_34",
|
| 47 |
+
"35": "LABEL_35",
|
| 48 |
+
"36": "LABEL_36",
|
| 49 |
+
"37": "LABEL_37",
|
| 50 |
+
"38": "LABEL_38",
|
| 51 |
+
"39": "LABEL_39",
|
| 52 |
+
"40": "LABEL_40",
|
| 53 |
+
"41": "LABEL_41",
|
| 54 |
+
"42": "LABEL_42",
|
| 55 |
+
"43": "LABEL_43",
|
| 56 |
+
"44": "LABEL_44",
|
| 57 |
+
"45": "LABEL_45",
|
| 58 |
+
"46": "LABEL_46",
|
| 59 |
+
"47": "LABEL_47",
|
| 60 |
+
"48": "LABEL_48",
|
| 61 |
+
"49": "LABEL_49",
|
| 62 |
+
"50": "LABEL_50",
|
| 63 |
+
"51": "LABEL_51",
|
| 64 |
+
"52": "LABEL_52",
|
| 65 |
+
"53": "LABEL_53",
|
| 66 |
+
"54": "LABEL_54",
|
| 67 |
+
"55": "LABEL_55",
|
| 68 |
+
"56": "LABEL_56",
|
| 69 |
+
"57": "LABEL_57",
|
| 70 |
+
"58": "LABEL_58",
|
| 71 |
+
"59": "LABEL_59",
|
| 72 |
+
"60": "LABEL_60",
|
| 73 |
+
"61": "LABEL_61",
|
| 74 |
+
"62": "LABEL_62",
|
| 75 |
+
"63": "LABEL_63",
|
| 76 |
+
"64": "LABEL_64",
|
| 77 |
+
"65": "LABEL_65",
|
| 78 |
+
"66": "LABEL_66",
|
| 79 |
+
"67": "LABEL_67",
|
| 80 |
+
"68": "LABEL_68",
|
| 81 |
+
"69": "LABEL_69",
|
| 82 |
+
"70": "LABEL_70",
|
| 83 |
+
"71": "LABEL_71",
|
| 84 |
+
"72": "LABEL_72",
|
| 85 |
+
"73": "LABEL_73",
|
| 86 |
+
"74": "LABEL_74",
|
| 87 |
+
"75": "LABEL_75",
|
| 88 |
+
"76": "LABEL_76"
|
| 89 |
+
},
|
| 90 |
+
"initializer_range": 0.02,
|
| 91 |
+
"label2id": {
|
| 92 |
+
"LABEL_0": 0,
|
| 93 |
+
"LABEL_1": 1,
|
| 94 |
+
"LABEL_10": 10,
|
| 95 |
+
"LABEL_11": 11,
|
| 96 |
+
"LABEL_12": 12,
|
| 97 |
+
"LABEL_13": 13,
|
| 98 |
+
"LABEL_14": 14,
|
| 99 |
+
"LABEL_15": 15,
|
| 100 |
+
"LABEL_16": 16,
|
| 101 |
+
"LABEL_17": 17,
|
| 102 |
+
"LABEL_18": 18,
|
| 103 |
+
"LABEL_19": 19,
|
| 104 |
+
"LABEL_2": 2,
|
| 105 |
+
"LABEL_20": 20,
|
| 106 |
+
"LABEL_21": 21,
|
| 107 |
+
"LABEL_22": 22,
|
| 108 |
+
"LABEL_23": 23,
|
| 109 |
+
"LABEL_24": 24,
|
| 110 |
+
"LABEL_25": 25,
|
| 111 |
+
"LABEL_26": 26,
|
| 112 |
+
"LABEL_27": 27,
|
| 113 |
+
"LABEL_28": 28,
|
| 114 |
+
"LABEL_29": 29,
|
| 115 |
+
"LABEL_3": 3,
|
| 116 |
+
"LABEL_30": 30,
|
| 117 |
+
"LABEL_31": 31,
|
| 118 |
+
"LABEL_32": 32,
|
| 119 |
+
"LABEL_33": 33,
|
| 120 |
+
"LABEL_34": 34,
|
| 121 |
+
"LABEL_35": 35,
|
| 122 |
+
"LABEL_36": 36,
|
| 123 |
+
"LABEL_37": 37,
|
| 124 |
+
"LABEL_38": 38,
|
| 125 |
+
"LABEL_39": 39,
|
| 126 |
+
"LABEL_4": 4,
|
| 127 |
+
"LABEL_40": 40,
|
| 128 |
+
"LABEL_41": 41,
|
| 129 |
+
"LABEL_42": 42,
|
| 130 |
+
"LABEL_43": 43,
|
| 131 |
+
"LABEL_44": 44,
|
| 132 |
+
"LABEL_45": 45,
|
| 133 |
+
"LABEL_46": 46,
|
| 134 |
+
"LABEL_47": 47,
|
| 135 |
+
"LABEL_48": 48,
|
| 136 |
+
"LABEL_49": 49,
|
| 137 |
+
"LABEL_5": 5,
|
| 138 |
+
"LABEL_50": 50,
|
| 139 |
+
"LABEL_51": 51,
|
| 140 |
+
"LABEL_52": 52,
|
| 141 |
+
"LABEL_53": 53,
|
| 142 |
+
"LABEL_54": 54,
|
| 143 |
+
"LABEL_55": 55,
|
| 144 |
+
"LABEL_56": 56,
|
| 145 |
+
"LABEL_57": 57,
|
| 146 |
+
"LABEL_58": 58,
|
| 147 |
+
"LABEL_59": 59,
|
| 148 |
+
"LABEL_6": 6,
|
| 149 |
+
"LABEL_60": 60,
|
| 150 |
+
"LABEL_61": 61,
|
| 151 |
+
"LABEL_62": 62,
|
| 152 |
+
"LABEL_63": 63,
|
| 153 |
+
"LABEL_64": 64,
|
| 154 |
+
"LABEL_65": 65,
|
| 155 |
+
"LABEL_66": 66,
|
| 156 |
+
"LABEL_67": 67,
|
| 157 |
+
"LABEL_68": 68,
|
| 158 |
+
"LABEL_69": 69,
|
| 159 |
+
"LABEL_7": 7,
|
| 160 |
+
"LABEL_70": 70,
|
| 161 |
+
"LABEL_71": 71,
|
| 162 |
+
"LABEL_72": 72,
|
| 163 |
+
"LABEL_73": 73,
|
| 164 |
+
"LABEL_74": 74,
|
| 165 |
+
"LABEL_75": 75,
|
| 166 |
+
"LABEL_76": 76,
|
| 167 |
+
"LABEL_8": 8,
|
| 168 |
+
"LABEL_9": 9
|
| 169 |
+
},
|
| 170 |
+
"max_position_embeddings": 512,
|
| 171 |
+
"model_type": "distilbert",
|
| 172 |
+
"n_heads": 12,
|
| 173 |
+
"n_layers": 6,
|
| 174 |
+
"pad_token_id": 0,
|
| 175 |
+
"problem_type": "single_label_classification",
|
| 176 |
+
"qa_dropout": 0.1,
|
| 177 |
+
"seq_classif_dropout": 0.2,
|
| 178 |
+
"sinusoidal_pos_embds": false,
|
| 179 |
+
"tie_weights_": true,
|
| 180 |
+
"transformers_version": "4.57.1",
|
| 181 |
+
"vocab_size": 30522
|
| 182 |
+
}
|
saved_models/distilbert_distilbert-base-uncased-finetuned-banking77/model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:feb9a1354f898d570a195359d2050bd80e97c505caef07372891ef72118af3d6
|
| 3 |
+
size 268063276
|
saved_models/distilbert_distilbert-base-uncased-finetuned-banking77/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 |
+
}
|
saved_models/distilbert_distilbert-base-uncased-finetuned-banking77/tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
saved_models/distilbert_distilbert-base-uncased-finetuned-banking77/tokenizer_config.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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": false,
|
| 45 |
+
"cls_token": "[CLS]",
|
| 46 |
+
"do_lower_case": true,
|
| 47 |
+
"extra_special_tokens": {},
|
| 48 |
+
"mask_token": "[MASK]",
|
| 49 |
+
"model_max_length": 512,
|
| 50 |
+
"pad_token": "[PAD]",
|
| 51 |
+
"sep_token": "[SEP]",
|
| 52 |
+
"strip_accents": null,
|
| 53 |
+
"tokenize_chinese_chars": true,
|
| 54 |
+
"tokenizer_class": "DistilBertTokenizer",
|
| 55 |
+
"unk_token": "[UNK]"
|
| 56 |
+
}
|
saved_models/distilbert_distilbert-base-uncased-finetuned-banking77/training_args.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f9251dd2260f588c4fa12d97412fa8019070e4a667daacda44f1836364a87079
|
| 3 |
+
size 5905
|
saved_models/distilbert_distilbert-base-uncased-finetuned-banking77/vocab.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
src/streamlit_app.py
CHANGED
|
@@ -1,40 +1,95 @@
|
|
| 1 |
-
import altair as alt
|
| 2 |
-
import numpy as np
|
| 3 |
-
import pandas as pd
|
| 4 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
|
| 10 |
-
If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
|
| 11 |
-
forums](https://discuss.streamlit.io).
|
| 12 |
-
|
| 13 |
-
In the meantime, below is an example of what you can do with just a few lines of code:
|
| 14 |
-
"""
|
| 15 |
-
|
| 16 |
-
num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
|
| 17 |
-
num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
|
| 18 |
-
|
| 19 |
-
indices = np.linspace(0, 1, num_points)
|
| 20 |
-
theta = 2 * np.pi * num_turns * indices
|
| 21 |
-
radius = indices
|
| 22 |
-
|
| 23 |
-
x = radius * np.cos(theta)
|
| 24 |
-
y = radius * np.sin(theta)
|
| 25 |
-
|
| 26 |
-
df = pd.DataFrame({
|
| 27 |
-
"x": x,
|
| 28 |
-
"y": y,
|
| 29 |
-
"idx": indices,
|
| 30 |
-
"rand": np.random.randn(num_points),
|
| 31 |
-
})
|
| 32 |
-
|
| 33 |
-
st.altair_chart(alt.Chart(df, height=700, width=700)
|
| 34 |
-
.mark_point(filled=True)
|
| 35 |
-
.encode(
|
| 36 |
-
x=alt.X("x", axis=None),
|
| 37 |
-
y=alt.Y("y", axis=None),
|
| 38 |
-
color=alt.Color("idx", legend=None, scale=alt.Scale()),
|
| 39 |
-
size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
|
| 40 |
-
))
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
from transformers import pipeline
|
| 4 |
+
from datasets import load_dataset
|
| 5 |
+
import torch
|
| 6 |
+
import os
|
| 7 |
+
|
| 8 |
+
def load_css(file_name):
|
| 9 |
+
current_dir = os.path.dirname(__file__)
|
| 10 |
+
css_file_path = os.path.join(current_dir, file_name)
|
| 11 |
+
with open(css_file_path) as f:
|
| 12 |
+
st.markdown(f'<style>{f.read()}</style>', unsafe_allow_html=True)
|
| 13 |
+
|
| 14 |
+
load_css("style.css")
|
| 15 |
+
|
| 16 |
+
st.set_page_config(
|
| 17 |
+
page_title="Intent Classification in Banking",
|
| 18 |
+
page_icon="🤖",
|
| 19 |
+
layout="centered"
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
@st.cache_resource
|
| 23 |
+
def load_model_and_mapping():
|
| 24 |
+
model_path = "saved_models/distilbert_distilbert-base-uncased-finetuned-banking77"
|
| 25 |
+
|
| 26 |
+
device = 0 if torch.cuda.is_available() else -1
|
| 27 |
+
classifier = pipeline("text-classification", model=model_path, device=device)
|
| 28 |
+
|
| 29 |
+
raw_datasets = load_dataset("mteb/banking77")
|
| 30 |
+
df_train = raw_datasets['train'].to_pandas()
|
| 31 |
+
|
| 32 |
+
label_mapping_df = df_train[['label', 'label_text']].drop_duplicates().reset_index(drop=True)
|
| 33 |
+
|
| 34 |
+
return classifier, label_mapping_df
|
| 35 |
+
|
| 36 |
+
classifier, label_mapping_df = load_model_and_mapping()
|
| 37 |
+
|
| 38 |
+
st.title("Intent Classification in Banking")
|
| 39 |
+
|
| 40 |
+
st.markdown(
|
| 41 |
+
"""
|
| 42 |
+
This is a demo for a language model that has been fine-tuned to classify 77 different types of customer requests in the banking sector.
|
| 43 |
+
"""
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
with st.form("intent_form"):
|
| 47 |
+
user_input = st.text_area("Please enter your request here:", "", height=100)
|
| 48 |
+
submitted = st.form_submit_button("Classify Intent")
|
| 49 |
+
|
| 50 |
+
if submitted and user_input:
|
| 51 |
+
with st.spinner('The model is analyzing...'):
|
| 52 |
+
predictions = classifier(user_input, top_k=5)
|
| 53 |
+
|
| 54 |
+
mapped_predictions = []
|
| 55 |
+
for pred in predictions:
|
| 56 |
+
label_id = int(pred['label'].split('_')[1])
|
| 57 |
+
|
| 58 |
+
matched_row = label_mapping_df[label_mapping_df['label'] == label_id]
|
| 59 |
+
|
| 60 |
+
if not matched_row.empty:
|
| 61 |
+
label_text = matched_row['label_text'].iloc[0]
|
| 62 |
+
else:
|
| 63 |
+
label_text = "Cannot find label"
|
| 64 |
+
|
| 65 |
+
mapped_predictions.append({'label': label_text, 'score': pred['score']})
|
| 66 |
+
|
| 67 |
+
top_prediction = mapped_predictions[0]
|
| 68 |
+
|
| 69 |
+
st.success(f"**The top predicted intent is:** `{top_prediction['label']}`")
|
| 70 |
+
st.metric(label="With confidence", value=f"{top_prediction['score']:.2%}")
|
| 71 |
+
|
| 72 |
+
st.markdown("---")
|
| 73 |
+
|
| 74 |
+
st.subheader("Other possibilities:")
|
| 75 |
+
|
| 76 |
+
df = pd.DataFrame(mapped_predictions)
|
| 77 |
+
df = df.rename(columns={'label': 'Intent', 'score': 'Confidence'})
|
| 78 |
+
df['Confidence'] = df['Confidence'].apply(lambda x: f"{x:.2%}")
|
| 79 |
+
|
| 80 |
+
st.dataframe(
|
| 81 |
+
df,
|
| 82 |
+
column_config={
|
| 83 |
+
"Confidence": st.column_config.ProgressColumn(
|
| 84 |
+
"Confidence",
|
| 85 |
+
format="%.3f",
|
| 86 |
+
min_value=0,
|
| 87 |
+
max_value=1,
|
| 88 |
+
),
|
| 89 |
+
},
|
| 90 |
+
hide_index=True,
|
| 91 |
+
width='stretch'
|
| 92 |
+
)
|
| 93 |
|
| 94 |
+
elif submitted and not user_input:
|
| 95 |
+
st.warning("Please enter a request to classify.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/style.css
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.stApp {
|
| 2 |
+
background-image: url("https://img.freepik.com/free-photo/abstract-luxury-gradient-blue-background-smooth-dark-blue-with-black-vignette-studio-banner_1258-63468.jpg");
|
| 3 |
+
background-size: cover;
|
| 4 |
+
background-repeat: no-repeat;
|
| 5 |
+
background-attachment: fixed;
|
| 6 |
+
}
|