Ano woy commited on
Commit
2ead69c
·
verified ·
1 Parent(s): c1da515

Update bias_detector.py

Browse files
Files changed (1) hide show
  1. bias_detector.py +13 -8
bias_detector.py CHANGED
@@ -451,11 +451,16 @@ Output: "They pursue excellence and they work hard. They have delivered results.
451
  # company names (ORG) and locations (LOC) from person names (PER),
452
  # eliminating false positives like "Luminary Analytics" or "Machine Learning".
453
  ner_results = self.ner(anonymized)
454
- person_spans = [
455
- (ent["start"], ent["end"], ent["word"])
456
- for ent in ner_results
457
- if ent["entity_group"] == "PER"
458
- ]
 
 
 
 
 
459
 
460
  # Count frequency by normalised name (lower-case first token)
461
  name_freq: Counter = Counter()
@@ -523,7 +528,7 @@ Output: "They pursue excellence and they work hard. They have delivered results.
523
  full_name_label[name.strip()] = label
524
  # Also register individual tokens (first name, last name separately)
525
  for token in name.strip().split():
526
- if len(token) > 2:
527
  full_name_label.setdefault(token, label)
528
  # Also add email-derived names that NER missed
529
  for first, last, full in email_names:
@@ -540,7 +545,7 @@ Output: "They pursue excellence and they work hard. They have delivered results.
540
  token_label: dict = {}
541
  for full_name, label in full_name_label.items():
542
  for token in full_name.split():
543
- if len(token) > 2 and token not in token_label:
544
  token_label[token] = label
545
 
546
  # Replace full names first (longest first), then individual tokens
@@ -837,4 +842,4 @@ I, Prof. Michael Davies, am delighted to recommend her for this position."""
837
  result = bd.anonymize_document(test_cv)
838
  print(f"SURFACE:\n{result['surface_anonymized']}\n")
839
  print(f"FULLY ANONYMIZED:\n{result['fully_anonymized']}")
840
- print(f"Sustainability: {result['sustainability']}")
 
451
  # company names (ORG) and locations (LOC) from person names (PER),
452
  # eliminating false positives like "Luminary Analytics" or "Machine Learning".
453
  ner_results = self.ner(anonymized)
454
+ person_spans = []
455
+ for ent in ner_results:
456
+ if ent["entity_group"] != "PER":
457
+ continue
458
+ # Clean BERT subword artifacts (## prefixes from tokenizer)
459
+ word = ent["word"].replace("##", "").strip()
460
+ # Skip if too short to be a real name token (avoids partial matches)
461
+ if len(word) < 3:
462
+ continue
463
+ person_spans.append((ent["start"], ent["end"], word))
464
 
465
  # Count frequency by normalised name (lower-case first token)
466
  name_freq: Counter = Counter()
 
528
  full_name_label[name.strip()] = label
529
  # Also register individual tokens (first name, last name separately)
530
  for token in name.strip().split():
531
+ if len(token) >= 4:
532
  full_name_label.setdefault(token, label)
533
  # Also add email-derived names that NER missed
534
  for first, last, full in email_names:
 
545
  token_label: dict = {}
546
  for full_name, label in full_name_label.items():
547
  for token in full_name.split():
548
+ if len(token) >= 4 and token not in token_label:
549
  token_label[token] = label
550
 
551
  # Replace full names first (longest first), then individual tokens
 
842
  result = bd.anonymize_document(test_cv)
843
  print(f"SURFACE:\n{result['surface_anonymized']}\n")
844
  print(f"FULLY ANONYMIZED:\n{result['fully_anonymized']}")
845
+ print(f"Sustainability: {result['sustainability']}")