Spaces:
Runtime error
Runtime error
ScamDetect Bot commited on
Commit ·
2e4bf53
1
Parent(s): 9ee5fbd
Auto-sync backend and fix configuration
Browse files- backend/services/scam_detection.py +10 -12
- config.json +0 -40
- model.safetensors +0 -3
- tokenizer.json +0 -0
- tokenizer_config.json +0 -14
backend/services/scam_detection.py
CHANGED
|
@@ -227,18 +227,19 @@ def ensemble_analyze_text(text: str, finetuned_classifier, nlp_classifier, ds) -
|
|
| 227 |
|
| 228 |
# 2. Zero-shot model prediction
|
| 229 |
zs_risk = 0.0
|
|
|
|
| 230 |
if _nlp_clf():
|
| 231 |
try:
|
| 232 |
result_zs = _nlp_clf()(text, CANDIDATE_LABELS, multi_label=True)
|
| 233 |
-
|
| 234 |
|
| 235 |
malicious_scores = [
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
]
|
| 241 |
-
legit_score =
|
| 242 |
max_malicious = max(malicious_scores) if malicious_scores else 0
|
| 243 |
zs_risk = max_malicious
|
| 244 |
scores["zeroshot"] = zs_risk
|
|
@@ -269,7 +270,7 @@ def ensemble_analyze_text(text: str, finetuned_classifier, nlp_classifier, ds) -
|
|
| 269 |
weights["keyword"] * scores.get("keyword", 0)
|
| 270 |
)
|
| 271 |
|
| 272 |
-
return ensemble_risk * 100, list(set(categories)), scores
|
| 273 |
|
| 274 |
# Explainability Vocabularies (English + Hindi)
|
| 275 |
XAI_VOCAB = {
|
|
@@ -332,13 +333,10 @@ def analyze_text_with_nlp(text: str):
|
|
| 332 |
|
| 333 |
try:
|
| 334 |
# Use ensemble approach for better accuracy
|
| 335 |
-
ensemble_risk, ensemble_cats, component_scores = ensemble_analyze_text(
|
| 336 |
text, _finetuned(), _nlp_clf(), ds
|
| 337 |
)
|
| 338 |
-
|
| 339 |
-
# Get zero-shot scores for XAI explanations
|
| 340 |
-
result_zs = _nlp_clf()(text, CANDIDATE_LABELS, multi_label=True)
|
| 341 |
-
scores_zs = dict(zip(result_zs['labels'], result_zs['scores']))
|
| 342 |
|
| 343 |
# Apply adjustments
|
| 344 |
final_risk = ensemble_risk
|
|
|
|
| 227 |
|
| 228 |
# 2. Zero-shot model prediction
|
| 229 |
zs_risk = 0.0
|
| 230 |
+
scores_zs_out = {}
|
| 231 |
if _nlp_clf():
|
| 232 |
try:
|
| 233 |
result_zs = _nlp_clf()(text, CANDIDATE_LABELS, multi_label=True)
|
| 234 |
+
scores_zs_out = dict(zip(result_zs['labels'], result_zs['scores']))
|
| 235 |
|
| 236 |
malicious_scores = [
|
| 237 |
+
scores_zs_out.get("phishing", 0),
|
| 238 |
+
scores_zs_out.get("financial scam", 0),
|
| 239 |
+
scores_zs_out.get("threat or blackmail", 0),
|
| 240 |
+
scores_zs_out.get("identity theft", 0)
|
| 241 |
]
|
| 242 |
+
legit_score = scores_zs_out.get("legitimate communication", 0)
|
| 243 |
max_malicious = max(malicious_scores) if malicious_scores else 0
|
| 244 |
zs_risk = max_malicious
|
| 245 |
scores["zeroshot"] = zs_risk
|
|
|
|
| 270 |
weights["keyword"] * scores.get("keyword", 0)
|
| 271 |
)
|
| 272 |
|
| 273 |
+
return ensemble_risk * 100, list(set(categories)), scores, scores_zs_out
|
| 274 |
|
| 275 |
# Explainability Vocabularies (English + Hindi)
|
| 276 |
XAI_VOCAB = {
|
|
|
|
| 333 |
|
| 334 |
try:
|
| 335 |
# Use ensemble approach for better accuracy
|
| 336 |
+
ensemble_risk, ensemble_cats, component_scores, scores_zs = ensemble_analyze_text(
|
| 337 |
text, _finetuned(), _nlp_clf(), ds
|
| 338 |
)
|
| 339 |
+
|
|
|
|
|
|
|
|
|
|
| 340 |
|
| 341 |
# Apply adjustments
|
| 342 |
final_risk = ensemble_risk
|
config.json
DELETED
|
@@ -1,40 +0,0 @@
|
|
| 1 |
-
{
|
| 2 |
-
"activation": "gelu",
|
| 3 |
-
"architectures": [
|
| 4 |
-
"DistilBertForSequenceClassification"
|
| 5 |
-
],
|
| 6 |
-
"attention_dropout": 0.1,
|
| 7 |
-
"bos_token_id": null,
|
| 8 |
-
"dim": 768,
|
| 9 |
-
"dropout": 0.1,
|
| 10 |
-
"dtype": "float32",
|
| 11 |
-
"eos_token_id": null,
|
| 12 |
-
"hidden_dim": 3072,
|
| 13 |
-
"id2label": {
|
| 14 |
-
"0": "benign",
|
| 15 |
-
"1": "phishing",
|
| 16 |
-
"2": "upi_fraud",
|
| 17 |
-
"3": "investment_scam"
|
| 18 |
-
},
|
| 19 |
-
"initializer_range": 0.02,
|
| 20 |
-
"label2id": {
|
| 21 |
-
"benign": 0,
|
| 22 |
-
"investment_scam": 3,
|
| 23 |
-
"phishing": 1,
|
| 24 |
-
"upi_fraud": 2
|
| 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 |
-
"tie_word_embeddings": true,
|
| 37 |
-
"transformers_version": "5.3.0",
|
| 38 |
-
"use_cache": false,
|
| 39 |
-
"vocab_size": 30522
|
| 40 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
model.safetensors
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:859ce8c26878f233e0debf5686c1c2deb89ea600569ec0e73f7531f7a2e90793
|
| 3 |
-
size 267838720
|
|
|
|
|
|
|
|
|
|
|
|
tokenizer.json
DELETED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tokenizer_config.json
DELETED
|
@@ -1,14 +0,0 @@
|
|
| 1 |
-
{
|
| 2 |
-
"backend": "tokenizers",
|
| 3 |
-
"cls_token": "[CLS]",
|
| 4 |
-
"do_lower_case": true,
|
| 5 |
-
"is_local": false,
|
| 6 |
-
"mask_token": "[MASK]",
|
| 7 |
-
"model_max_length": 512,
|
| 8 |
-
"pad_token": "[PAD]",
|
| 9 |
-
"sep_token": "[SEP]",
|
| 10 |
-
"strip_accents": null,
|
| 11 |
-
"tokenize_chinese_chars": true,
|
| 12 |
-
"tokenizer_class": "BertTokenizer",
|
| 13 |
-
"unk_token": "[UNK]"
|
| 14 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|