Spaces:
Running
Running
File size: 520 Bytes
f861dee |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
from transformers import pipeline
class BadQueryDetector:
def __init__(self):
self.detector = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")
def is_bad_query(self, query):
result = self.detector(query)[0]
label = result["label"]
score = result["score"]
if label == "NEGATIVE" and score > 0.8:
print(f"Detected malicious query with high confidence ({score:.4f}): {query}")
return True
return False
|