How microsoft/analysing_pii_leakage works
Main Components
• Data Preparation & Dataset Management: Represent the dataset components and tagging process. This includes the ECHR dataset wrapper and the Flair NER tagging setup (for PII identification that is cached after the one-time tagging).
• Model Fine-Tuning Module: Group the components responsible for fine-tuning the language models. This includes:
• The pre-trained GPT-2 (from HuggingFace) as a base.
• Three different fine-tuning approaches (“no defense”, “scrubbing”, and “differential privacy (DP)”). Note the use of external libraries such as the dp-transformers and opacus for the DP variant.
• Attack Modules: Include individual attack implementations.
• PII Extraction: Extracting PII from generated text.
• PII Reconstruction: Reconstructing PII from masked sentences.
• PII Inference: Inferring which PII candidate is most likely in a masked sentence.
• Evaluation Framework: A module that verifies precision, recall, and accuracy of the various attacks.
• Common Utilities & Configuration: This encapsulates:
• Configuration files (present in the “configs” folder) that drive different pipelines.
• Argument parsing mechanisms (the “arguments” package under src/pii_leakage/arguments).
• Utility functions, dataset factories, model factories, and global configurations.
Relationships and Interactions
• Data flows from raw datasets (ECHR dataset) into the PII tagging process using Flair NER.
• The fine-tuning module takes the processed datasets and fine-tunes variations of the GPT-2 model based on configuration parameters.
• PII Extraction,
• PII Reconstruction, and
• PII Inference.
• The Evaluation module consumes the outputs of these attack modules and verifies performance.
• The configuration files feed into each of these modules, providing runtime parameters and model checkpoint locations.
• Lastly, there is clear integration with external libraries (PyTorch, HuggingFace, dp-transformers, opacus, and Flair).
Architectural Patterns and Design Principles
• Modular Design: The project is divided into distinct modules (dataset, model training, attack strategies) that interact through well-defined interfaces.
• Config-Driven Execution: Central use of configuration files allows quick switching between fine-tuning strategies and attack configurations.
• Separation of Concerns: Splitting out argument definitions, data loading, model building, and attack implementations fosters a clean architecture.
Relevant Technologies
• Python 3.10, PyTorch 1.11, and HuggingFace GPT-2.
• Differential privacy libraries (dp-transformers, opacus) and Flair for NER tagging.
• Workflow Automation & CI used via GitHub actions (as seen in .github/workflows).