Skip to content

Conversation

@omri374
Copy link
Collaborator

@omri374 omri374 commented Dec 7, 2025

This pull request updates the evaluation logic for span matching, focusing on improving the accuracy of character-based IoU calculations and adjusting the threshold for matches. It also adds new tests to ensure correct behavior, especially for split entities. The most important changes are grouped below:

Evaluation Logic Improvements

  • Changed the default iou_threshold in SpanEvaluator from 0.9 to 0.75 to allow more flexibility in span matching.
  • Fixed an off-by-one error in character span calculation within _calculate_combined_iou by removing the unnecessary + 1 in the range calls for both annotation and prediction spans. This ensures that character indices are properly exclusive at the end, improving the accuracy of IoU calculations. [1] [2]

Testing Enhancements

  • Added two new tests in test_span_evaluator.py:
    • test_calculate_combined_iou_char_based_split_entity verifies that split predictions covering an annotation result in an IoU of 1.0, confirming the off-by-one bug is fixed.
    • test_calculate_combined_iou_char_based_exact_match checks that exact matches yield an IoU of 1.0, ensuring no regression in the basic matching logic.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request addresses character-based IoU calculation issues in span matching evaluation by fixing an off-by-one error and adjusting the matching threshold for more flexible span matching.

  • Fixed off-by-one error in character span calculation by removing unnecessary + 1 in range calls for both annotation and prediction end indices
  • Reduced the default IoU threshold from 0.9 to 0.75 to allow more flexibility in span matching
  • Added comprehensive tests to verify the fix for split entity scenarios and exact matches

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
presidio_evaluator/evaluation/span_evaluator.py Updated IoU threshold default to 0.75 and fixed off-by-one error in character-based IoU calculations by making end indices properly exclusive
tests/test_span_evaluator.py Added two new test cases to verify character-based IoU calculations work correctly for split entities and exact matches
presidio_evaluator/evaluation/scorers.py Removed obsolete scoring pipeline code that is no longer needed

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

generic_entities: Optional[List[str]] = None,
skip_words: Optional[List] = None,
iou_threshold: float = 0.9,
iou_threshold: float = 0.75,
Copy link

Copilot AI Dec 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation comment at line 35 states the default iou_threshold is 0.5, but the actual default has been changed to 0.75. The documentation should be updated to reflect this change:

:param iou_threshold: Minimum Intersection over Union (IoU) threshold for considering spans as matching.
                    Value between 0 and 1, where higher values require more overlap (default: 0.75)

Copilot uses AI. Check for mistakes.
@omri374 omri374 removed the request for review from negruber1 December 7, 2025 21:30
@omri374 omri374 changed the title minor bug fixes and obsolete code removal minor bug fixes Dec 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants