How shivammitra/data-anonymization works
Purpose and Entry Points
This is a Python text anonymization utility that detects sensitive entities and replaces them with category placeholders while retaining surrounding text. The primary executable and importable entry point is data_anonymizer.py; it exposes the DataAnonymizer workflow and can be run directly. app.py may provide an additional application-facing entry point, but its role is not established by the supplied documentation.
Core Anonymization Orchestrator
data_anonymizer.py is the architectural center. Its anonymizer class/function accepts raw text, coordinates entity detection, and emits anonymized text. This module is intended to be embedded in other data-processing pipelines as well as used as a standalone script.
Paths:
• data_anonymizer.py
• app.py
Remote BERT NER Stage
Named-entity recognition is delegated to Hugging Face’s hosted inference API using the dbmdz/bert-large-cased-finetuned-conll03-english model. The model supplies context-sensitive entity identification, including person, organization, location, and miscellaneous entity categories. This is an external-service boundary: anonymization depends on network availability and Hugging Face API behavior.
Paths:
• data_anonymizer.py
• requirements.txt
Credential and Runtime Boundary
The runtime is Python 3.8+ and requires dependencies installed from requirements.txt. A Hugging Face token is expected through the HF_TOKENS environment variable, typically loaded from a local .env file. Secrets are intentionally outside the committed repository tree and must be provisioned by deployment environments.
Paths:
• requirements.txt
• data_anonymizer.py
Deterministic Regex Detection Stage
Alongside model-based NER, the pipeline performs regex-based detection for emails and phone numbers. This covers structured identifiers that may be missed, fragmented, or inconsistently labeled by the NER model. Regex detection is a local processing boundary and does not require the remote inference service.
Paths:
• data_anonymizer.py
Replacement and Output Semantics
Detected values are transformed into stable semantic labels such as [Person], [SURNAME], [ORGANIZATION], [LOCATION], [EMAIL], and [PHONE]. The output is plain anonymized text, not a separate structured entity record. Correct replacement ordering and text-span handling are therefore central: model entities and regex matches must be applied without corrupting offsets or overlapping replacements.
Paths:
• data_anonymizer.py
Deployment Characteristics and Extension Direction
The current design is lightweight and service-dependent rather than GPU- or local-model-dependent. It is suited to batch scripts or integration as a Python module. Planned evolution includes offline Hugging Face Transformers inference, domain-specific NER models, multilingual support, and a Streamlit UI; these would primarily extend the inference boundary or add a presentation layer without changing the core text-in/text-out contract.
Paths:
• data_anonymizer.py
• app.py
Main entry points: data_anonymizer.py DataAnonymizer · app.py Application entry point · requirements.txt Python dependencies
Components 12
Runtime
- Script or Python consumer · Runs or imports the anonymization workflow.
- Application entry point · Application-facing role is not established.
app.py - Python dependencies · Defines required runtime packages.
requirements.txt - HF_TOKENS · Deployment-provided Hugging Face API token.
Anonymization Pipeline
- DataAnonymizer · Coordinates text-in/text-out anonymization and supports direct execution.
data_anonymizer.py - Raw text
- Remote NER detection · Obtains contextual named entities.
data_anonymizer.py - Regex detection · Finds email addresses and phone numbers.
data_anonymizer.py - Span replacement · Orders overlapping matches and replaces values without corrupting offsets.
data_anonymizer.py - Anonymized text · Plain text containing semantic placeholders.
data_anonymizer.py
External Service
- Hugging Face Inference API · Network-dependent NER service boundary.
- BERT CoNLL03 model · dbmdz/bert-large-cased-finetuned-conll03-english.
Connections 12
- Script or Python consumer → DataAnonymizer: runs or imports
- Application entry point → DataAnonymizer: possible integration
- Python dependencies → DataAnonymizer: provides packages
- Raw text → DataAnonymizer: text input
- DataAnonymizer → Remote NER detection: coordinates
- DataAnonymizer → Regex detection: coordinates
- HF_TOKENS → Remote NER detection: authenticates
- Remote NER detection → Hugging Face Inference API: inference request
- Hugging Face Inference API → BERT CoNLL03 model: serves
- Remote NER detection → Span replacement: NER spans
- Regex detection → Span replacement: email and phone spans
- Span replacement → Anonymized text: semantic placeholders