WORKWITHSHAFISK commited on
Commit
478f522
·
verified ·
1 Parent(s): 9872b76

Update classifier_manager/deberta_model.py

Browse files
Files changed (1) hide show
  1. classifier_manager/deberta_model.py +30 -1
classifier_manager/deberta_model.py CHANGED
@@ -26,4 +26,33 @@ class PiiDebertaAnalyzer:
26
  print(f"✅ DeBERTa model '{model_name}' loaded successfully.")
27
 
28
  except Exception as e:
29
- print(f"Failed to load DeBERTa model: {e}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  print(f"✅ DeBERTa model '{model_name}' loaded successfully.")
27
 
28
  except Exception as e:
29
+ print(f"Failed to load DeBERTa model: {e}")
30
+
31
+ def scan(self, text: str):
32
+ if not self.model_loaded or not text:
33
+ return []
34
+
35
+ try:
36
+ results = self.pipe(text)
37
+ detections = []
38
+
39
+ for entity in results:
40
+ # entity looks like: {'entity_group': 'NAME_STUDENT', 'score': 0.99, 'word': 'John Doe', 'start': 0, 'end': 8}
41
+ original_label = entity.get('entity_group', 'UNKNOWN')
42
+ mapped_label = self.label_mapping.get(original_label, "DEFAULT")
43
+
44
+ # Only include known PII types
45
+ if mapped_label != "DEFAULT":
46
+ detections.append({
47
+ "text": entity['word'].strip(),
48
+ "label": mapped_label,
49
+ "start": entity['start'],
50
+ "end": entity['end'],
51
+ "source": "DeBERTa",
52
+ "score": float(entity['score'])
53
+ })
54
+ return detections
55
+
56
+ except Exception as e:
57
+ print(f"DeBERTa scan error: {e}")
58
+ return []