Skip to content

Commit ba90314

Browse files
shs037tensorflower-gardener
authored andcommitted
Update MIA README to include epsilon lower bound.
PiperOrigin-RevId: 689814531
1 parent d965556 commit ba90314

File tree

2 files changed

+471
-459
lines changed

2 files changed

+471
-459
lines changed

tensorflow_privacy/privacy/privacy_tests/membership_inference_attack/README.md

Lines changed: 88 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ memorization is present and thus the less privacy-preserving the model is.
1010

1111
The privacy vulnerability (or memorization potential) is measured via the area
1212
under the ROC-curve (`auc`) or via max{|fpr - tpr|} (`advantage`) of the attack
13-
classifier. These measures are very closely related.
13+
classifier. These measures are very closely related. We can also obtain a lower
14+
bound for the differential privacy epsilon.
1415

1516
The tests provided by the library are "black box". That is, only the outputs of
1617
the model are used (e.g., losses, logits, predictions). Neither model internals
@@ -38,9 +39,8 @@ from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack.data_s
3839
# loss_test shape: (n_test, )
3940

4041
attacks_result = mia.run_attacks(
41-
AttackInputData(
42-
loss_train = loss_train,
43-
loss_test = loss_test))
42+
AttackInputData(loss_train=loss_train, loss_test=loss_test)
43+
)
4444
```
4545

4646
This example calls `run_attacks` with the default options to run a host of
@@ -57,9 +57,11 @@ Then, we can view the attack results by:
5757
```python
5858
print(attacks_result.summary())
5959
# Example output:
60-
# -> Best-performing attacks over all slices
61-
# THRESHOLD_ATTACK (with 50000 training and 10000 test examples) achieved an AUC of 0.59 on slice Entire dataset
62-
# THRESHOLD_ATTACK (with 50000 training and 10000 test examples) achieved an advantage of 0.20 on slice Entire dataset
60+
# Best-performing attacks over all slices
61+
# LOGISTIC_REGRESSION (with 7041 training and 3156 test examples) achieved an AUC of 0.72 on slice CORRECTLY_CLASSIFIED=False
62+
# LOGISTIC_REGRESSION (with 7041 training and 3156 test examples) achieved an advantage of 0.34 on slice CORRECTLY_CLASSIFIED=False
63+
# LOGISTIC_REGRESSION (with 5000 training and 1000 test examples) achieved a positive predictive value of 1.00 on slice CLASS=0
64+
# THRESHOLD_ATTACK (with 50000 training and 10000 test examples) achieved top-5 epsilon lower bounds of 4.6254, 4.6121, 4.5986, 4.5850, 4.5711 on slice Entire dataset
6365
```
6466

6567
### Other codelabs
@@ -100,16 +102,17 @@ First, similar as before, we specify the input for the attack as an
100102
# loss_test shape: (n_test, )
101103

102104
attack_input = AttackInputData(
103-
logits_train = logits_train,
104-
logits_test = logits_test,
105-
loss_train = loss_train,
106-
loss_test = loss_test,
107-
labels_train = labels_train,
108-
labels_test = labels_test)
105+
logits_train=logits_train,
106+
logits_test=logits_test,
107+
loss_train=loss_train,
108+
loss_test=loss_test,
109+
labels_train=labels_train,
110+
labels_test=labels_test,
111+
)
109112
```
110113

111114
Instead of `logits`, you can also specify `probs_train` and `probs_test` as the
112-
predicted probabilty vectors of each example.
115+
predicted probability vectors of each example.
113116

114117
Then, we specify some details of the attack. The first part includes the
115118
specifications of the slicing of the data. For example, we may want to evaluate
@@ -118,91 +121,107 @@ the model's classification. These can be specified by a `SlicingSpec` object.
118121

119122
```python
120123
slicing_spec = SlicingSpec(
121-
entire_dataset = True,
122-
by_class = True,
123-
by_percentiles = False,
124-
by_classification_correctness = True)
124+
entire_dataset=True,
125+
by_class=True,
126+
by_percentiles=False,
127+
by_classification_correctness=True,
128+
)
125129
```
126130

127131
The second part specifies the classifiers for the attacker to use. Currently,
128132
our API supports five classifiers, including `AttackType.THRESHOLD_ATTACK` for
129133
simple threshold attack, `AttackType.LOGISTIC_REGRESSION`,
130134
`AttackType.MULTI_LAYERED_PERCEPTRON`, `AttackType.RANDOM_FOREST`, and
131135
`AttackType.K_NEAREST_NEIGHBORS` which use the corresponding machine learning
132-
models. For some model, different classifiers can yield pertty different
133-
results. We can put multiple classifers in a list:
136+
models. For some model, different classifiers can yield pretty different
137+
results. We can put multiple classifiers in a list:
134138

135139
```python
136140
attack_types = [
137141
AttackType.THRESHOLD_ATTACK,
138-
AttackType.LOGISTIC_REGRESSION
142+
AttackType.LOGISTIC_REGRESSION,
139143
]
140144
```
141145

142146
Now, we can call the `run_attacks` methods with all specifications:
143147

144148
```python
145-
attacks_result = mia.run_attacks(attack_input=attack_input,
146-
slicing_spec=slicing_spec,
147-
attack_types=attack_types)
149+
attacks_result = mia.run_attacks(
150+
attack_input=attack_input,
151+
slicing_spec=slicing_spec,
152+
attack_types=attack_types,
153+
)
148154
```
149155

150156
This returns an object of type `AttackResults`. We can, for example, use the
151-
following code to see the attack results specificed per-slice, as we have
152-
request attacks by class and by model's classification correctness.
157+
following code to see the attack results specified per-slice, as we have request
158+
attacks by class and by model's classification correctness.
153159

154160
```python
155161
print(attacks_result.summary(by_slices = True))
156162
# Example output:
157-
# -> Best-performing attacks over all slices
158-
# THRESHOLD_ATTACK achieved an AUC of 0.75 on slice CORRECTLY_CLASSIFIED=False
159-
# THRESHOLD_ATTACK achieved an advantage of 0.38 on slice CORRECTLY_CLASSIFIED=False
160-
#
161-
# Best-performing attacks over slice: "Entire dataset"
162-
# LOGISTIC_REGRESSION achieved an AUC of 0.61
163-
# THRESHOLD_ATTACK achieved an advantage of 0.22
164-
#
165-
# Best-performing attacks over slice: "CLASS=0"
166-
# LOGISTIC_REGRESSION achieved an AUC of 0.62
167-
# LOGISTIC_REGRESSION achieved an advantage of 0.24
168-
#
169-
# Best-performing attacks over slice: "CLASS=1"
170-
# LOGISTIC_REGRESSION achieved an AUC of 0.61
171-
# LOGISTIC_REGRESSION achieved an advantage of 0.19
172-
#
173-
# ...
174-
#
175-
# Best-performing attacks over slice: "CORRECTLY_CLASSIFIED=True"
176-
# LOGISTIC_REGRESSION achieved an AUC of 0.53
177-
# THRESHOLD_ATTACK achieved an advantage of 0.05
178-
#
179-
# Best-performing attacks over slice: "CORRECTLY_CLASSIFIED=False"
180-
# THRESHOLD_ATTACK achieved an AUC of 0.75
181-
# THRESHOLD_ATTACK achieved an advantage of 0.38
163+
# Best-performing attacks over all slices
164+
# LOGISTIC_REGRESSION (with 7041 training and 3156 test examples) achieved an AUC of 0.72 on slice CORRECTLY_CLASSIFIED=False
165+
# LOGISTIC_REGRESSION (with 7041 training and 3156 test examples) achieved an advantage of 0.34 on slice CORRECTLY_CLASSIFIED=False
166+
# LOGISTIC_REGRESSION (with 5000 training and 1000 test examples) achieved a positive predictive value of 1.00 on slice CLASS=0
167+
# THRESHOLD_ATTACK (with 50000 training and 10000 test examples) achieved top-5 epsilon lower bounds of 4.6254, 4.6121, 4.5986, 4.5850, 4.5711 on slice Entire dataset
168+
169+
# Best-performing attacks over slice: "Entire dataset"
170+
# LOGISTIC_REGRESSION (with 50000 training and 10000 test examples) achieved an AUC of 0.58
171+
# LOGISTIC_REGRESSION (with 50000 training and 10000 test examples) achieved an advantage of 0.17
172+
# THRESHOLD_ATTACK (with 50000 training and 10000 test examples) achieved a positive predictive value of 0.86
173+
# THRESHOLD_ATTACK (with 50000 training and 10000 test examples) achieved top-5 epsilon lower bounds of 4.6254, 4.6121, 4.5986, 4.5850, 4.5711
174+
175+
# Best-performing attacks over slice: "CLASS=0"
176+
# LOGISTIC_REGRESSION (with 5000 training and 1000 test examples) achieved an AUC of 0.63
177+
# LOGISTIC_REGRESSION (with 5000 training and 1000 test examples) achieved an advantage of 0.19
178+
# LOGISTIC_REGRESSION (with 5000 training and 1000 test examples) achieved a positive predictive value of 1.00
179+
# THRESHOLD_ATTACK (with 5000 training and 1000 test examples) achieved top-5 epsilon lower bounds of 4.1920, 4.1645, 4.1364, 4.1074, 4.0775
180+
181+
# ...
182+
183+
# Best-performing attacks over slice: "CORRECTLY_CLASSIFIED=True"
184+
# LOGISTIC_REGRESSION (with 42959 training and 6844 test examples) achieved an AUC of 0.51
185+
# LOGISTIC_REGRESSION (with 42959 training and 6844 test examples) achieved an advantage of 0.05
186+
# LOGISTIC_REGRESSION (with 42959 training and 6844 test examples) achieved a positive predictive value of 0.94
187+
# THRESHOLD_ATTACK (with 42959 training and 6844 test examples) achieved top-5 epsilon lower bounds of 0.9495, 0.6358, 0.5630, 0.4536, 0.4341
188+
189+
# Best-performing attacks over slice: "CORRECTLY_CLASSIFIED=False"
190+
# LOGISTIC_REGRESSION (with 7041 training and 3156 test examples) achieved an AUC of 0.72
191+
# LOGISTIC_REGRESSION (with 7041 training and 3156 test examples) achieved an advantage of 0.34
192+
# LOGISTIC_REGRESSION (with 7041 training and 3156 test examples) achieved a positive predictive value of 0.97
193+
# LOGISTIC_REGRESSION (with 7041 training and 3156 test examples) achieved top-5 epsilon lower bounds of 3.8844, 3.8678, 3.8510, 3.8339, 3.8165
182194
```
183195

184196
#### Viewing and plotting the attack results
185197

186198
We have seen an example of using `summary()` to view the attack results as text.
187199
We also provide some other ways for inspecting the attack results.
188200

189-
To get the attack that achieves the maximum attacker advantage or AUC, we can do
201+
To get the attack that achieves the maximum attacker advantage, AUC, or epsilon
202+
lower bound, we can do
190203

191204
```python
192205
max_auc_attacker = attacks_result.get_result_with_max_auc()
193206
max_advantage_attacker = attacks_result.get_result_with_max_attacker_advantage()
207+
max_epsilon_attacker = attacks_result.get_result_with_max_epsilon()
194208
```
195209

196210
Then, for individual attack, such as `max_auc_attacker`, we can check its type,
197-
attacker advantage and AUC by
211+
attacker advantage, AUC, and epsilon lower bound by
198212

199213
```python
200-
print("Attack type with max AUC: %s, AUC of %.2f, Attacker advantage of %.2f" %
201-
(max_auc_attacker.attack_type,
202-
max_auc_attacker.roc_curve.get_auc(),
203-
max_auc_attacker.roc_curve.get_attacker_advantage()))
214+
print(
215+
"Attack type with max AUC: %s, AUC of %.2f, Attacker advantage of %.2f, Epsilon lower bound of %s"
216+
% (
217+
max_auc_attacker.attack_type,
218+
max_auc_attacker.roc_curve.get_auc(),
219+
max_auc_attacker.roc_curve.get_attacker_advantage(),
220+
max_auc_attacker.get_epsilon_lower_bound()
221+
)
222+
)
204223
# Example output:
205-
# -> Attack type with max AUC: THRESHOLD_ATTACK, AUC of 0.75, Attacker advantage of 0.38
224+
# Attack type with max AUC: LOGISTIC_REGRESSION, AUC of 0.72, Attacker advantage of 0.34, Epsilon lower bound of [3.88435257 3.86781797 3.85100545 3.83390548 3.81650809]
206225
```
207226

208227
We can also plot its ROC curve by
@@ -217,24 +236,24 @@ which would give a figure like the one below
217236
![roc_fig](https://github.com/tensorflow/privacy/blob/master/tensorflow_privacy/privacy/privacy_tests/membership_inference_attack/codelab_roc_fig.png?raw=true)
218237

219238
Additionally, we provide functionality to convert the attack results into Pandas
220-
data frame:
239+
dataframe:
221240

222241
```python
223242
import pandas as pd
224243

225244
pd.set_option("display.max_rows", 8, "display.max_columns", None)
226245
print(attacks_result.calculate_pd_dataframe())
227246
# Example output:
228-
# slice feature slice value attack type Attacker advantage AUC
229-
# 0 entire_dataset threshold 0.216440 0.600630
230-
# 1 entire_dataset lr 0.212073 0.612989
231-
# 2 class 0 threshold 0.226000 0.611669
232-
# 3 class 0 lr 0.239452 0.624076
233-
# .. ... ... ... ... ...
234-
# 22 correctly_classfied True threshold 0.054907 0.471290
235-
# 23 correctly_classfied True lr 0.046986 0.525194
236-
# 24 correctly_classfied False threshold 0.379465 0.748138
237-
# 25 correctly_classfied False lr 0.370713 0.737148
247+
# slice feature slice value train size test size attack type Attacker advantage Positive predictive value AUC Epsilon lower bound_1 Epsilon lower bound_2 Epsilon lower bound_3 Epsilon lower bound_4 Epsilon lower bound_5
248+
# 0 Entire dataset 50000 10000 THRESHOLD_ATTACK 0.172520 0.862614 0.581630 4.625393 4.612104 4.598635 4.584982 4.571140
249+
# 1 Entire dataset 50000 10000 LOGISTIC_REGRESSION 0.173060 0.862081 0.583981 4.531399 4.513775 4.511974 4.498905 4.492165
250+
# 2 class 0 5000 1000 THRESHOLD_ATTACK 0.162000 0.877551 0.580728 4.191954 4.164547 4.136368 4.107372 4.077511
251+
# 3 class 0 5000 1000 LOGISTIC_REGRESSION 0.193800 1.000000 0.627758 3.289194 3.220285 3.146292 3.118849 3.066407
252+
# ...
253+
# 22 correctly_classified True 42959 6844 THRESHOLD_ATTACK 0.043953 0.862643 0.474713 0.949550 0.635773 0.563032 0.453640 0.434125
254+
# 23 correctly_classified True 42959 6844 LOGISTIC_REGRESSION 0.048963 0.943218 0.505334 0.597257 0.596095 0.594016 0.592702 0.590765
255+
# 24 correctly_classified False 7041 3156 THRESHOLD_ATTACK 0.326865 0.941176 0.707597 3.818741 3.805451 3.791982 3.778329 3.764488
256+
# 25 correctly_classified False 7041 3156 LOGISTIC_REGRESSION 0.336655 0.972222 0.717386 3.884353 3.867818 3.851005 3.833905 3.816508
238257
```
239258

240259
#### Advanced Membership Inference Attacks

0 commit comments

Comments
 (0)