Instance-based Model Attack#
Instance-based model attack.
Detects when instance-based models (SVM, kNN) store training data as part of their model parameters (support vectors or neighbors), confirming a concrete data leakage pathway.
This module provides the InstanceBasedAttack class, which: - Checks if a model is an instance-based type (SVM or kNN) - Extracts the stored instances (support vectors or neighbors) - Compares them to the training data to confirm data leakage - Reports matching examples and available mitigations
- class sacroml.attacks.instance_based_attack.InstanceBasedAttack(output_dir: str = 'outputs', write_report: bool = True, n_examples: int = 10, atol: float = 1e-08, report_individual: bool = False)[source]#
Detect training data stored in instance-based model parameters.
Instance-based models such as SVM and kNN store training data points (support vectors or all neighbors) inside the fitted model. This attack extracts those stored instances, compares them to the training data, and reports whether the model leaks training data.
Methods
attack(target)Check whether an attack can be performed and run the attack.
attackable(target)Return whether a target can be assessed with this attack.
Get parameters for this attack.
- classmethod attackable(target: Target) bool[source]#
Return whether a target can be assessed with this attack.
Requires a model and training data. Non-instance-based models are handled gracefully (reported as not applicable).
- __init__(output_dir: str = 'outputs', write_report: bool = True, n_examples: int = 10, atol: float = 1e-08, report_individual: bool = False) None[source]#
Construct an instance-based model attack.
- Parameters:
- output_dirstr
Name of a directory to write outputs.
- write_reportbool
Whether to generate a JSON and PDF report.
- n_examplesint
Maximum number of matching examples to show in the PDF report. Does not limit how many matches are recorded; all matches are kept in the per-record results.
- atolfloat
Absolute tolerance for floating-point comparison when matching stored instances to training data.
- report_individualbool
Whether to report metrics for each individual record.
- get_params() dict#
Get parameters for this attack.
- Returns:
- paramsdict
Parameter names mapped to their values.
- record_level_results: InstanceBasedRecordLevelResults | None#
- results: InstanceBasedAttackResults | None#
- class sacroml.attacks.instance_based_attack.InstanceBasedAttackResults(model_type: str, is_instance_based: bool = False, is_dp_safe: bool = False, n_stored_instances: int = 0, n_training_samples: int = 0, storage_fraction: float = 0.0, n_matched: int = 0, n_checked: int = 0, match_fraction: float = 0.0, data_leakage_confirmed: bool = False, mitigations: list[str] = <factory>, details: dict | None = None)[source]#
Results of an instance-based model attack.
- Attributes:
- details
- __init__(model_type: str, is_instance_based: bool = False, is_dp_safe: bool = False, n_stored_instances: int = 0, n_training_samples: int = 0, storage_fraction: float = 0.0, n_matched: int = 0, n_checked: int = 0, match_fraction: float = 0.0, data_leakage_confirmed: bool = False, mitigations: list[str] = <factory>, details: dict | None = None) None#
- class sacroml.attacks.instance_based_attack.InstanceBasedRecordLevelResults(individual_risk: list[int])[source]#
Per-training-record outcomes for an instance-based attack.
Indexed by training record (length == n_training_samples), consistent with StructuralAttack’s individual block. A value of 1 means that training record is stored verbatim inside the model; 0 means it is not.
- sacroml.attacks.instance_based_attack.INSTANCE_MATCH_ATOL: float = 1e-08#
Absolute tolerance for matching stored instances to training rows.
Used by
numpy.allclose()so that stored support vectors (or kNN neighbours) that differ from the original training row only by floating point rounding (~1e-16 per element) still count as matches.Kept local to this module rather than a shared constants module: see issue #454.
StructuralAttackdoes not use a numerical tolerance because its equivalence classes come fromnumpy.unique()on deterministicpredict_probaoutputs, where identical inputs produce bit-identical outputs and exact equality is the right semantics.