fix(structured): default tabular entity selection to the mixed strategy (#1316) - #2261
Open
developer-rpai wants to merge 1 commit into
Open
developer-rpai wants to merge 1 commit into
developer-rpai wants to merge 1 commit into
Conversation
…gy (data-privacy-stack#1316) PandasAnalysisBuilder.generate_analysis defaulted to the most_common selection strategy, which counts raw detections per entity type and ignores their confidence scores. A column of email addresses was a concrete casualty: john.doe@example.com yields EMAIL_ADDRESS at 1.0, but the URL recognizer also fires on the domain part, so six URL hits at 0.5 outvoted three EMAIL_ADDRESS hits at 1.0 and the column was misidentified as URL. Default to the mixed strategy instead: the entity with the highest confidence is selected when its score exceeds mixed_strategy_threshold (0.5), otherwise selection falls back to the most common entity. This is the combination proposed in the issue thread. most_common and highest_confidence remain available explicitly. Adds a regression test pinning the issue's data to EMAIL_ADDRESS under the default, and marks Mixed as the default in the structured docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
PandasAnalysisBuilder.generate_analysisdefaulted to themost_commonentity selection strategy, which counts raw detections per entity type and ignores their confidence scores. A column of email addresses is a concrete casualty:john.doe@example.comyields oneEMAIL_ADDRESSat 1.0, but the URL recognizer also fires on the domain part, so sixURLdetections at 0.5 outvote threeEMAIL_ADDRESSdetections at 1.0 and the column is misidentified asURL. The resultingStructuredAnalysis(entity_mapping={'email': 'URL', ...})then drives the wrong anonymization for that column.Fixes #1316.
Fix
Default the selection strategy to
mixed: the entity with the highest confidence is selected when its score exceedsmixed_strategy_threshold(default 0.5); otherwise selection falls back to the most common entity — the combination proposed in the issue thread. Behavior is unchanged wherever no detection is confident (the fallback is exactly the old default), andmost_common/highest_confidenceremain available explicitly.Behavior change
generate_analysis()without an explicitselection_strategymay now return a different entity for a column when at least one detection exceeds the mixed threshold. Docs (docs/structured/index.md) updated to mark Mixed as the default.Tests
test_generate_analysis_tabular_default_strategy_detects_email_address(presidio-structured misidentifies email as URL #1316 regression test): asserts the default analysis mapsemail->EMAIL_ADDRESSon the issue's data.URL) and passes with the fix.presidio-structuredsuite: 30 passed (en_core_web_lg).