From 06bb0475259bf9642ce0c3ba7c4c06d001e3fd58 Mon Sep 17 00:00:00 2001 From: "A. Unique TensorFlower" Date: Tue, 11 Aug 2020 06:17:15 -0700 Subject: [PATCH] Consistent string formatting. PiperOrigin-RevId: 326007570 --- .../membership_inference_attack/data_structures.py | 8 ++++---- .../membership_inference_attack/dataset_slicing.py | 2 +- .../membership_inference_attack_new.py | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tensorflow_privacy/privacy/membership_inference_attack/data_structures.py b/tensorflow_privacy/privacy/membership_inference_attack/data_structures.py index 5697096..36f7b75 100644 --- a/tensorflow_privacy/privacy/membership_inference_attack/data_structures.py +++ b/tensorflow_privacy/privacy/membership_inference_attack/data_structures.py @@ -56,7 +56,7 @@ class SingleSliceSpec: if self.feature == SlicingFeature.PERCENTILE: return 'Loss percentiles: %d-%d' % self.value - return f'{self.feature.name}={self.value}' + return '%s=%s' % (self.feature.name, self.value) @dataclass @@ -98,7 +98,7 @@ class AttackType(enum.Enum): # Return LOGISTIC_REGRESSION instead of AttackType.LOGISTIC_REGRESSION def __str__(self): - return f'{self.name}' + return '%s' % self.name @dataclass @@ -125,7 +125,7 @@ class AttackInputData: def num_classes(self): if self.labels_train is None or self.labels_test is None: raise ValueError( - "Can't identify the number of classes as no labels were provided. " + 'Can\'t identify the number of classes as no labels were provided. ' 'Please set labels_train and labels_test') return int(max(np.max(self.labels_train), np.max(self.labels_test))) + 1 @@ -204,7 +204,7 @@ class RocCurve: over all available classifier thresholds. Returns: - a single float number with membership attaker's advantage. + a single float number with membership attacker's advantage. """ return max(np.abs(self.tpr - self.fpr)) diff --git a/tensorflow_privacy/privacy/membership_inference_attack/dataset_slicing.py b/tensorflow_privacy/privacy/membership_inference_attack/dataset_slicing.py index 99b8dec..d62be31 100644 --- a/tensorflow_privacy/privacy/membership_inference_attack/dataset_slicing.py +++ b/tensorflow_privacy/privacy/membership_inference_attack/dataset_slicing.py @@ -137,7 +137,7 @@ def get_slice(data: AttackInputData, elif slice_spec.feature == SlicingFeature.CORRECTLY_CLASSIFIED: data_slice = _slice_by_classification_correctness(data, slice_spec.value) else: - raise ValueError(f'Unknown slice spec feature "{slice_spec.feature}"') + raise ValueError('Unknown slice spec feature "%s"' % slice_spec.feature) data_slice.slice_spec = slice_spec return data_slice diff --git a/tensorflow_privacy/privacy/membership_inference_attack/membership_inference_attack_new.py b/tensorflow_privacy/privacy/membership_inference_attack/membership_inference_attack_new.py index 6eb8d49..b0ce912 100644 --- a/tensorflow_privacy/privacy/membership_inference_attack/membership_inference_attack_new.py +++ b/tensorflow_privacy/privacy/membership_inference_attack/membership_inference_attack_new.py @@ -54,8 +54,8 @@ def run_trained_attack(attack_input: AttackInputData, attack_type: AttackType): elif attack_type == AttackType.K_NEAREST_NEIGHBORS: attacker = models.KNearestNeighborsAttacker() else: - raise NotImplementedError( - 'Attack type {} not implemented yet.'.format(attack_type)) + raise NotImplementedError('Attack type %s not implemented yet.' % + attack_type) prepared_attacker_data = models.create_attacker_data(attack_input)