












\section*{Checklist}

















\input{tex/appendix}


\end{document}

\section{Appendix}
\subsection{Reproducibility}

We use SimCLR to train our self-supervised models in the experiments. The implementations follows the code from Keras library (\url{https://keras.io/examples/vision/semisupervised_simclr/}) with default hyper-parameters.

For the implementation of the MIA, we use an MLP with 5 ReLU-activated hidden layers. We train the classifier using 2,000 probability pairs with half labeled `in'. We use the Keras library to train the binary classifier with learning rate 0.001 and default parameters.

All the experiments are done using a single Nvidia K80 / T4 GPU.

\section{Membership Inference Attack}
First, the attacker construct a shadow model to mimic the \textsc{victim model}'s behavior without directly having access to its training dataset or its learning algorithm.

In the next step, the attacker splits its training dataset into two partitions from which it uses only one to train the shadow model. 

After that, The attacker collects the shadow model's outputs corresponding to the seen and the unseen data records and trains a binary classifier to predict if a data record is 'in' or 'out' of the training dataset of the shadow model.

In our later experiments, we use a 3-tuple format to populate the binary classifier's training dataset.
The first element of the tuple is the output probability vectors that the shadow model generates from either partitions of its training dataset.
The second element consists of the ground truth labels about the output in the first element to help the MIA distinguish between the members and non-members.
The third element is a label that indicates which partition of datasets this record belongs to. 
Once the classifier is well-trained, we apply it to the \textsc{victim model} and infer the its training data.

\section{Proofs}
\subsection{Proof on Theorem \ref{thm:epsilon}}
\begin{proof}
    Let $f: \mathcal{X} \longrightarrow \mathbb{R}$ be a function, take arbitrary $x, y$ from $\mathcal{X}$, then we can compute the privacy budget of our mechanism $M_{AL}$. Refer to definition \ref{def:DP}, take any $z \in \mathcal{Y}$, we can show that our mechanism is differentially private by showing there exists an $\epsilon$ such that:
    \begin{center}
        $\mathrm{P}[M_{AL} (x, f, s) = z] \le \exp (\epsilon) \mathrm{P}[M_{AL} (y, f, s) = z]$.
    \end{center}
    This is equivalent to showing there exists an $\epsilon$ such that:
    \begin{equation}
        \log \left(\frac{\mathrm{P}[M_{AL} (x, f, s) = z]}{\mathrm{P}[M_{AL} (y, f, s)=z]} \right) \le \epsilon
    \end{equation}
    Then we can start the proof:
    \begin{equation}
        \label{proof:dp}
        \begin{split}
        \log \left(\frac{\mathrm{P}[M_{AL} (x, f, s) = z]}{\mathrm{P}[M_{AL} (y, f, s)=z]} \right) & = \log(\mathrm{P}[M_{AL} (x, f, s) = z]) - \log(\mathrm{P}[M_{AL} (y, f, s)=z]) \\
        & = \log(\mathrm{P}[f(x)+n=z])-\log(\mathrm{P}[f(y)+n=z])\\
        & = \log(\mathrm{P}[n=z-f(x)]) - \log(\mathrm{P}[n=z-f(y)]) \\
        & = \log \left(\frac{\exp(\frac{-(z-f(x))}{s})}{s(1 + \exp(\frac{-(z-f(x))}{s}) )^2} \right) - \log\left(\frac{\exp(\frac{-(z-f(x))}{s})}{s(1 + \exp(\frac{-(z-f(x))}{s}) )^2} \right)\\
        & = \frac{-(z-f(x))}{s} - \log(s) - 2 \log(1 + \exp(\frac{-(z-f(x))}{s}))\\
        & - \frac{-(z-f(y))}{s} +\log(s) + 2 \log(1 + \exp(\frac{-(z-f(x))}{s})) \\
        & = \frac{f(x) - f(y)}{s} + 2 \log \left( \frac{1 + \exp(\frac{f(y)-z}{s})}{1 + \exp(\frac{f(x)-z}{s})} \right)
        \end{split}
    \end{equation}
    
    Let $\gamma = |f(x) - f(y)|$, then we have two cases: $f(x) \ge f(y)$ or $f(x) < f(y)$. 
    
    In the first case, $\gamma = |f(x) - f(y)| = f(x) - f(y)$, then $f(x) = f(y) + \gamma$. We substitute $f(x)$ in Equation \ref{proof:dp} with $f(y) + \gamma$ and get
    \begin{equation}
        \label{eq:case1}
        \frac{\gamma}{s} + 2 \log \left( \frac{1 + \exp(\frac{f(y)-z}{s})}{1 + \exp(\frac{f(y)+\gamma-z}{s})} \right) \le \frac{\gamma}{s} + 2 \log \left( \frac{1 + \exp(\frac{f(y)-z}{s})}{1 + \exp(\frac{f(y)-z}{s})} \right) = \frac{\gamma}{s}.
    \end{equation}
    
    In the second case, $\gamma = |f(x) - f(y)| = f(y) - f(x)$. We substitute $f(y)$ Equation \ref{proof:dp} with $f(x) + \gamma$ and get
    \begin{equation}
        \label{eq:case2}
        \begin{split}
            \frac{-\gamma}{s} + 2 \log \left( \frac{1 + \exp(\frac{f(x)+\gamma -z}{s})}{1 + \exp(\frac{f(x)-z}{s})} \right) & = \frac{-\gamma}{s} + 2 \log \left( \frac{\exp(\gamma) (\frac{1}{\exp(\gamma)} +  \exp(\frac{f(x)-z}{s})) }{1 + \exp(\frac{f(x)-z}{s})} \right) \\
            & \le \frac{-\gamma}{s} + 2 \log \left( \frac{\exp(\frac{\gamma}{s}) (1 +  \exp(\frac{f(x)-z}{s})) }{1 + \exp(\frac{f(x)-z}{s})} \right) \\
            & = \frac{-\gamma}{s} + 2 \log (\exp(\gamma/s)) = \frac{-\gamma}{s} + 2 \frac{\gamma}{s} = \frac{\gamma}{s}.
        \end{split}
    \end{equation}
    
    In both cases, we get a bound of $\frac{\gamma}{s}$. From \textbf{Definition \ref{def: sensitivity}}, we know $\gamma = |f(x) - f(y)| \le \Delta$, where $\Delta$ is the sensitivity of $f$. Therefore, we can get $\epsilon = \frac{\Delta}{s}$. Hence we have proved that our additive exponential mechanism is $\frac{\lambda \Delta}{c}$-differentially private.
\end{proof}

\subsection{Proof on Remark \ref{remark:1-norm}}
\begin{proof}
    Given a function $f: \mathcal{X} \longrightarrow \mathbb{R}^n$, similar to the previous proof, we want to show that 
    \begin{center}
        $\mathrm{P}[M_{AL} (x, f, s) = \Vec{z}] \le \exp (\epsilon) \mathrm{P}[M_{AL} (y, f, s) = \Vec{z}]$.
    \end{center}
    Denote $\Delta_i = |f(x)_i - f(y)_i|$ for $i \in \mathbb{Z}^+$ and $i <= n$. We move the probabilities to one side and continue the proof:
    \begin{equation} 
    \label{proof:dp2}
    \begin{split}
    \frac{\mathrm{P}[M_{AL} (x, f, s) = \Vec{z}]}{\mathrm{P}[M_{AL} (y, f, s) = \Vec{z}]} 
     & = \frac{ \prod_{i=1}^n  \mathrm{P}[f(x)_i + Log(s)_i = \Vec{z}_i]}{\prod_{i=1}^n \mathrm{P}[f(y)_i + Log(s)_i = \Vec{z}_i]} \\
     & = \prod_{i=1}^n \frac{\mathrm{P}[Log(s)_i = \Vec{z}_i - f(x)_i]}{\mathrm{P}[Log(s)_i = \Vec{z}_i - f(y)_i]} \\
     & \le \prod_{i=1}^n \exp(\frac{\Delta_i}{s}) = \exp(\sum_{i=1}^n \frac{\Delta_i}{s}) = \exp(\frac{\sum_{i=1}^n \Delta_i}{s}) = \exp (\epsilon).
    \end{split}
    \end{equation}
    Note that $\sum_{i=1}^n \Delta_i = \sum_{i=1}^n |f(x)_i - f(y)_i|$ is the 1-norm of the vector $f(x)-f(y)$.
\end{proof}

\subsection{Proof on Proposition \ref{prop:epsilon}}
\begin{proof}
    Let $D$ and $D'$ be adjacent datasets, $\mathcal{A_H}$ be the machine learning algorithm, $M_{AL}: \mathbb{R}^n \longrightarrow \mathbb{R}^n$ be our additive logistic mechanism with parameter $s$. We train the algorithm $\mathcal{A_H}$ using $D$ and $D'$ respectively to obtain two models $NN_{\theta}: \mathcal{X} \longrightarrow \mathbb{R}^n$ and $NN_{\theta'}: \mathcal{X} \longrightarrow \mathbb{R}^n$, with parameters $\theta = \mathcal{A_H}(D)$ and $\theta' = \mathcal{A_H}(D')$.
    
    We migrate Equation \ref{proof:dp2} to this scenario and get
    \begin{equation}
        \frac{\mathrm{P}[M_{AL} (x, \mathcal{A_H}, s) = \Vec{z}]}{\mathrm{P}[M_{AL} (y, \mathcal{A_H}, s) = \Vec{z}]} 
        = \prod_{i=1}^n \frac{\mathrm{P}[Log(s)_i = \Vec{z}_i - \mathcal{A_H}(x)_i]}{\mathrm{P}[Log(s)_i = \Vec{z}_i - \mathcal{A_H}(y)_i]}
        \le \exp(\sum_{i=1}^n \frac{\Delta_i}{s}) = \exp (\epsilon).
    \end{equation}
    We have shown that $\mathrm{P}[M_{AL} (x, \mathcal{A_H}, s) = \Vec{z}] \le \exp (\epsilon) \cdot \mathrm{P}[M_{AL} (y, \mathcal{A_H}, s)]$, by Definition \ref{prop:DP}, we conclude that the machine learning algorithm $\mathcal{A_H}$ is $\frac{\Delta_{\mathcal{H}}}{s}$-differentially private.
    
    From Remark \ref{remark:1-norm} we know that $\Delta_{\mathcal{H}} = \sum_{i=1}^n |\mathcal{A_H}(x)_i - \mathcal{A_H}(y)_i| = \sum_{i=1}^n \Delta_i$ is the sensitivity of $\mathcal{A_H}$ that computed in 1-norm distance.
\end{proof}

\section{Conclusion}
In this work, we introduce a privacy mechanism named additive logistic mechanism. We theoretically prove that the additive logistic mechanism satisfies differential privacy and compute the privacy budget in terms of the parameters of the logistic distribution.
We then propose a post-training protection algorithm for the fine-tuning stage of the self-supervised learning algorithm. The protection algorithm deploys the additive logistic mechanism to enforce differential privacy to the fine-tuning data.
We have verified the effectiveness of our proposed protection algorithm with the additive logistic mechanism by showing the decreasing MIA accuracies on the protected models.
Finally, we demonstrate how the additive logistic mechanism stands out from the existing additive noise mechanisms in protecting self-supervised learning algorithms. 
A limitation of the post-training protection with the additive logistic mechanism is that the utility loss can increase as more layers in the protected neural network.
As an extension to this work, we are interested in developing a moment accountant for this mechanism for adapting DP-SGD, which is less sensitive to the scale of the neural network.



\section{Empirical Analysis of Privacy-Performance Trade-off}
\label{sec:experiment}

The proposed post-training protection algorithm that deploys the ALM can lead to a loss in the neural network's performance while protecting its privacy. We define the term \textit{utility loss} to measure how the protection algorithm degrades the network's performance. We apply Algorithm \ref{algo: mechanism} to a set of queries from the validation dataset to obtain a set of protected outputs $\tilde y$. We feed the same set of queries to the unprotected neural networks to get a set of unprotected outputs $y$ and keep the ground truth labels $y_{GT}$ corresponding to these queries.
\begin{definition}
    \label{def:util_loss}
    Let $M$ be an evaluation metric that takes a set of predictions $y$ and its ground truth label set $y_{GT}$ as input and returns a numerical value to indicate the quality of the predictions. The \textbf{\textsc{Utility Loss}} caused by the protection algorithm is
    \begin{center}
        $\mathcal{L}_{util} = 1 - \frac{M(\tilde y, y_{GT})}{M(y, y_{GT})}$.
    \end{center}
\end{definition}

The base encoder $NN_\theta$ learns to generate \textit{representations}—projections of the input data onto the output space of $NN_\theta$.
A well-constructed base encoder maps the representations that consist of identical features into the same topological space \citep{Goodfellow-et-al-2016, bengio2014representation, yang2021}.
The projection head $MP_\omega$ divides the output space into a set of topological spaces and assigns each space a predicted label \citep{naitzat2020topology}.
Adding noise to the weights of the projection head modifies the boundary of the topological spaces and hence changes some of the label assignments.

Once the projection head is fully optimized, any changes in assignments leads to a loss of utility.
If the noise we add does not lead any individual to switch between spaces, then the noise will have a negligible impact on the outcomes. 
Conversely, large noise can push the representation beyond its original space and potentially lead to a loss in utility.
Therefore, it is desirable to have a mechanism that minimizes the amount of noise added in order to achieve a certain privacy level.
In this section, we empirically study relationship between the noise level, privacy budget, and utility loss.

\subsection{Privacy Budget vs. Utility Loss}
We performed the ALQH on Cifar 10 \citep{cifar}, Cifar 100 \citep{cifar}, and STL 10 \citep{deng2009imagenet} datasets to quantify the trade-off between privacy and performance of the self-supervised neural networks. We built the target image classifiers using Keras library \citep{chollet2015keras} and trained it following SimCLR \citep{chen2020simple} framework—one of the state of the arts self-supervised learning framework. We partitioned each dataset into pretraining and fine-tuning datasets, followed Algorithm \ref{algo: mechanism} to fine-tune the model, and added noise to the weights of fine-tuning layers.

We computed \textit{empirical sensitivities} of the fine-tuned models for all three datasets, following Algorithm \ref{algo:Sensitivity Sampler}. We recorded the sensitivities and other experimental specifications in Table \ref{tab:util_spec}.
We took the sensitivity $\Delta$ and parameter $s$ of the ALM to compute the privacy budget $\epsilon$ based on Proposition \ref{prop:epsilon}. Then, we observed a negative correlation between the privacy budget and the model's utility in Figure \ref{fig:util_loss_eps}.

\begin{table}[!ht]
    \centering
    \caption{Specifications on the fine-tuned self-supervised models. $m$ is the sample size of the Sensitivity Sampler. |D| is the size of pretraining dataset and |d| is the size of fine-tuning dataset.}
    \begin{tabular}{||c|c|c|c|c|c||}
         \hline
         Dataset & |D| & |d| & m & 1-norm sensitivity & 2-norm sensitivity \\
         \hline
         Cifar 10 & 40000 & 10000 & 500 & 0.017492 & 0.013842 \\
         Cifar 100 & 40000 & 10000 & 500 & 0.020738 & 0.016391 \\
         STL 10 & 100000 & 5000 & 250 & 0.013242 & 0.010856\\
         \hline
    \end{tabular}
    \label{tab:util_spec}
\end{table}

We then repeated the experiments on two of the most well-known additive noise mechanisms: the Laplace mechanism and the Gaussian mechanism. We applied Algorithm \ref{algo: mechanism} but replaced the ALM $M_{AL}(\tilde r, \mathcal{A_S}, s)$ in the algorithm with the Gaussian $M_{Gauss}(\tilde r, \mathcal{A_S}, \sigma)$ and the Laplace mechanisms $M_{Lap}(\tilde r, \mathcal{A_S}, b)$, respectively. $\sigma$ and $b$ are the distribution parameters stated in Remark \ref{remark:anm}.

The Gaussian mechanism $M_{Gauss}$ is ($\epsilon, \delta$)-differentially private; we chose $\delta=1e-5$ for all the experiments and used the 2-norm sensitivity to compute $\epsilon$. The Laplace mechanism and the ALM are $\epsilon$-differentially private; hence, we chose $\delta=0$ and used the 1-norm sensitivity in the experiments.

\begin{figure}[t]
    \centering
    \resizebox{.33\linewidth}{!}{\input{figures/eps_util_cifar}}
    \resizebox{.33\linewidth}{!}{\input{figures/eps_util_cifar100}}
    \resizebox{.33\linewidth}{!}{\input{figures/eps_util_imgnet}}
    \caption{Comparison between the ALM, the Gaussian mechanism, and the Laplace mechanism, in terms of the utility loss at each privacy budget. The plots from left to right are the results on Cifar 10, Cifar 100, and STL 10, respectively.}
    \label{fig:util_loss_eps}
\end{figure}

We compare the privacy-utility trade-off of the three additive noise mechanisms in Figure \ref{fig:util_loss_eps}.
We observe that the utility loss caused by the ALM was approximately equal to the utility loss by the Laplace mechanism at each privacy budget tested, whereas the Gaussian mechanism led to a significantly higher utility loss.

The Gaussian mechanism is $(\epsilon, \delta)$-differentially privacy, while the Laplace mechanism and the ALM are $\epsilon$-differentially private. 
To maintain the same privacy budget $\epsilon$, the Gaussian mechanism has to draw noise from a distribution with a higher variance compared with the distributions of the other two mechanisms.
Sampling noise from a distribution with a larger variance amplifies the changes in label assignments, which leads to a larger utility loss.

\subsection{Privacy Protection against Membership Inference Attack}
The post-training protection algorithm with the ALM could effectively protect self-supervised models against MIAs.
We first performed MIAs on the queries from the fine-tuning datasets with the unprotected outputs to acquire benchmark attack accuracies. We got benchmark MIA accuracies of \textbf{62\%} on Cifar 10, \textbf{61\%} on STL 10, and \textbf{71\%} on Cifar 100.
Then, we performed MIAs on the same set of queries with the protected outputs obtained from Algorithm \ref{algo: mechanism}. We state the implementation and experimental setup of MIA in the Appendix.
Our experiments shows that the ALM is able to effectively reduce the MIA accuracy to approximately 50\%, which is equivalent to random guessing. 

Then, we replaced the ALM in the Algorithm \ref{algo: mechanism} with the Gaussian mechanism and the Laplace mechanism, respectively, and repeated the MIA experiments. We compared the performance of the Gaussian mechanism and the Laplace mechanism with the ALM in protecting against MIAs. We present the results in Figure \ref{fig:mia_eps}.

\begin{figure}[t]
    \centering
    \resizebox{.33\linewidth}{!}{\input{figures/eps_mia_cifar}}
    \resizebox{.33\linewidth}{!}{\input{figures/eps_mia_cifar100}}
    \resizebox{.33\linewidth}{!}{\input{figures/eps_mia_imgnet}}
    
    \resizebox{.33\linewidth}{!}{\input{figures/util_mia_cifar}}
    \resizebox{.33\linewidth}{!}{\input{figures/util_mia_cifar100}}
    \resizebox{.33\linewidth}{!}{\input{figures/util_mia_imgnet}}
    \caption{The top row shows the MIA accuracy at each privacy budget $\epsilon$. The bottom row shows the trade-off between the MIA accuracy and the model's utility loss. The columns from the left to right present the results on Cifar 10, Cifar 100, and STL 10, respectively.}
    \label{fig:mia_eps}
\end{figure}

We have two observations from Figure \ref{fig:mia_eps}: first, the Gaussian mechanism and the ALM achieve the MIA accuracies closer to 50\% at each privacy budget, while the Laplace mechanism maintains the highest MIA accuracy.


Stronger protection leads to a lower MIA accuracy, simultaneously, it also results in a bigger utility loss to the neural network.
We quantify this trade-off between the MIA accuracy and utility loss, named the protection-utility trade-off.
We have shown and justified that the Gaussian mechanism could lead to a significantly higher utility loss than the other two mechanisms at the same privacy budget $\epsilon$.

As for the second observation, the ALM is able to maintain the lowest utility loss at a fixed MIA accuracy compared to Gaussian and Laplace mechanisms.
The ALM provides slightly weaker protections against MIAs compared to the Gaussian mechanism. However, the utility loss caused by the ALM is significantly lower than the Gaussian mechanism. Hence we can observe that the ALM achieves a better protection-utility trade-off.
On the other hand, the ALM maintains approximately equal utility loss with the Laplace mechanism, while the ALM is able to reduce the MIA accuracy closer to 50\%.
Therefore, we conclude that the ALM outperforms the other two mechanisms in protecting against MIAs since it achieves the best protection-utility trade-off.




\section{Introduction}

Machine learning algorithms, and their outcomes, are known to be vulnerable to privacy attacks. Attackers may, for example, infer the size of the training data \citep{dalenius1977towards, Dwork2010OnTD}, individuals’ information in the training dataset \citep{Shokri_2017}, and parameters of machine learning models \citep{Ateniese2015HackingSM, Ohrimenko2016ObliviousMM} by only observing the inputs and outputs of these models.

We focus on the vulnerability due to privacy attacks in the \textit{fine-tuning stage of self-supervised learning algorithms}. Many self-supervised models are first pre-trained using public databases and then fine-tuned using private datasets for specific purposes \citep{chen2020simple, Devlin2019BERTPO}. Our first contribution is an empirical demonstration of this vulnerability. To this end, we devise a membership inference attack that obtains an accuracy of 71\% on the Cifar 100 dataset \citep{cifar} and 61\% on the STL 10 dataset \citep{deng2009imagenet}. Note that such attack accuracy is significantly higher than the accuracy of random guessing, hence protections against privacy attacks are necessary.

Federated learning \citep{konen2015federated} and data encryption \citep{encryption} are among the commonly used protection mechanisms against privacy attacks to machine learning algorithms. On the other hand, they have limited applicability for self-supervised learning. Fine-tuning datasets are often small; therefore, partitioning of the dataset as in federated learning is not practical or may result in a loss of convergence. Data encryption, when applied only on fine-tuning datasets, may introduce inconsistency between pre-training and fine-tuning datasets, again resulting in a loss of convergence. 

As for the second contribution, we develop a new differential privacy mechanism for protecting self-supervised learning algorithms against privacy attacks.
This new mechanism, which we call \textit{the additive logistic mechanism}, adds small amounts of statistical noise sampled from a logistic distribution to conceal the contributions of individual parties in the fine-tuning dataset. Besides the additive logistic mechanism, several other additive noise mechanisms have been developed to protect the privacy of machine learning models \citep{Abadi2016DeepLW, ji2014differential}. Two of the most commonly used additive noise mechanisms are the Gaussian mechanism \citep{gaussian-mechanism} and the Laplace mechanism \citep{laplace-mechanism}, drawing noise from a Gaussian or Laplace distribution.
The proposed additive logistic mechanism uses a bell-shaped distribution that resembles the distribution of the Gaussian mechanism, and it satisfies pure $\epsilon$-differential privacy similar to the Laplace mechanism.
We later empirically show how the proposed additive logistic mechanism outperforms these two in protecting self-supervised learning algorithms.

While the new mechanism is broadly applicable, as the third contribution, we show that it can be adopted for the protection of self-supervised neural networks. Specifically, we develop a post-training protection algorithm that deploys the additive logistic mechanism to the self-supervised neural network. This protection algorithm provides privacy to the network by adding noise to its fine-tuning layer-weights. We theoretically prove that the protection algorithm satisfies differential privacy and compute the privacy budget in terms of the parameters of the logistic distribution. This post-training protection applies to already fine-tuned networks, hence, it avoids the aforementioned loss of convergence. 

As for the final contribution, we illustrate the privacy-performance trade-off in the protected self-supervised network. Adding noise to the layer-weights degrades the performance of the self-supervised neural network. We show the negative correlation between the privacy and performance of the self-supervised network and indicate the additive logistic mechanism can achieve a high privacy level- $\epsilon < 1$- with a performance loss below 10\%.

In the empirical analysis, we perform membership inference attacks to show that the protection algorithm can effectively reduce the attack accuracy to approximately random guessing. Then, we evaluate and compare the privacy-performance trade-offs of the three mechanisms- the Gaussian mechanism, the Laplace mechanism, and the additive logistic mechanism- to show the performance loss of the additive logistic mechanism is lower than the other two under the same privacy budget $\epsilon$. Additionally, we compare the protection strength against membership inference attacks of these three mechanisms. We show that the proposed additive logistic mechanism achieves the strongest protection against membership inference attacks while having the lowest loss in performance among all three mechanisms.

The privacy attacks and protections on self-supervised learning we have addressed in this paper are notable because self-supervised learning has contributed to the state of the arts in multiple fields and many of them are irreplaceable. Self-supervised learning algorithms have been used in language generation \citep{Devlin2019BERTPO, Radford2018ImprovingLU, mikolov2013efficient}, image classification \citep{chen2020simple, contrastive}, image and video enhancing or super-resolution \citep{zhang2021idr, laine2019highquality, Huang2021Neighbor2NeighborSD}, robotics \citep{Endrawis2021EfficientSD}, etc. These algorithms are the state of the arts in their own fields and there is no substitution that can achieve the same performances yet. Therefore, it is important to notice the privacy vulnerabilities of self-supervised learning and address these vulnerabilities.


\section{Preliminary}
\label{sec:prelim}

\paragraph{Self-Supervised Learning}
is a machine learning technique that can learn features from unlabeled training data. We focus on self-supervised learning algorithms applied to neural networks. These algorithms typically train neural networks in two stages \citep{ssl1, ssl2}: the \textit{pre-training stage} and \textit{the fine-tuning stage}.
In the pre-training stage, we initialize the network weights by solving a separate machine learning task using ``pseudo-labels". Pseudo-labels are automatically generated labels from a given \textit{pre-training dataset}. For example, we can rotate a training image and consider the rotation angle as a pseudo-label. We refer to the resulting machine learning model in this stage as the \textit{base encoder}.
In the fine-tuning stage, we fine-tune the base encoder for the main machine learning task that could be supervised, unsupervised, or reinforcement learning.
In particular, attach a \textit{projection head}, which is basically a collection of additional layers of nodes, to the base encoder's output layer. In the fine-tuning stage, it is the projection weights that are updated. We refer to the training dataset that we use in this stage as the \textit{fine-tuning dataset}. The base encoder preserves the features of the input data while mapping the data to the output space. The projection head uses these features to solve the actual task.

\paragraph{Membership Inference Attack (MIA)}
is one of the well-known privacy attacks that can be applied to neural networks to infer whether a selected data record belongs to the training dataset of the networks \citep{jia202110, yeom2017privacy, Salem2019}. Researchers have developed several effective MIA techniques and have evaluated the vulnerability of various neural networks to MIAs \citep{Shokri_2017, li2020membership, Liu2021MLDoctorHR}. We follow the framework of \textsc{shadow models} \citep{Shokri_2017} to perform black-box MIAs, in which the attacker can only access the input and output layer of the networks.

A shadow model must mimic the behavior of the victim model using a known training dataset, where each record in the dataset consists of a sample and a ground-truth label. Then, we feed a record into the shadow model to obtain an output and concatenate the output with its label to form an output-label pair. We train a binary classifier that takes the output-label pair as input to determine if the record has been used in training of the shadow model. We describe the detailed implementations in the Appendix.

\paragraph{Differential Privacy}
is a concept for publicly communicating messages about a dataset by describing the patterns of groups within the dataset while concealing the information of individual records in the dataset. The work \citep{laplace-mechanism} has introduced the concept of $\epsilon$-differential privacy. The value of $\epsilon$ evaluates the privacy budget of an algorithm by measuring the contribution of each individual records to the algorithm.
\begin{definition}[\textbf{\textsc{$\epsilon$-differential privacy}}]
    \label{def:DP}
    \citep{gaussian-mechanism}.
    Let $\epsilon$ be a positive real number and $M$ be a randomized algorithm that takes a dataset as input. Let $\mathcal{Y}$ be the image of $M$. The algorithm $M$ is $\epsilon$-differentially private if, for all datasets $D_1$ and $D_2$ that differ in a single element, and all $R \subseteq \mathcal{Y}$:
    \begin{equation}
        \mathbb{P}[M(D_1) \in R] \le \exp (\epsilon) \mathbb{P}[M(D_2) \in R].
    \end{equation}
    
    Derived from the definition of $\epsilon$-differential privacy, an \textbf{\textsc{$(\epsilon, \delta)$-differential privacy}} must satisfy the following:
    \begin{equation}
        \mathbb{P}[M(D_1) \in R] \le \exp (\epsilon) \mathbb{P}[M(D_2) \in R] + \delta,
    \end{equation}
    where $\delta$ captures the probability that $\epsilon$-differential privacy fails.
\end{definition}

We use $\epsilon$ to quantify the privacy budget of the randomized algorithm. A lower $\epsilon$ indicates the algorithm maintains better privacy. If $\epsilon < 1$, then we can say that the algorithm maintains high privacy. An $\epsilon$ between 1 and 10 is a reasonable privacy level; and if $\epsilon > 10$ then we would consider this algorithm privacy risky \citep{gaussian-mechanism}.

\section{Related Works} 
K-anonymity \citep{k-anonymity}, plausible deniability \citep{plausible-deniability}, and data obfuscation \citep{obfuscate} are pre-training protections that add noise sampled from a Gaussian distribution to the raw training data before feeding them into the networks. Adding noise to the raw data is inefficient when dealing with large-scale data records, such as images and videos. The protection algorithm that deploys the additive logistic mechanism is operating on the weights of the networks, hence not concerning the scale of data records.

DP-SGD \citep{Abadi2016DeepLW} clips the gradient and adds noise to the gradient during training, which significantly increases computation complexity. Deploying DP-SGD with a defined noise level required retraining the network. By contrast, we can adjust the noise level of the post-training protection without retraining the network.
\cite{he2021quantifying} develops a privacy-preserving contrastive learning mechanism, Talos, relying on adversarial training. Talos is in-training protection operated in the pretraining stage, which slows down the pretraining stage. The post-training protection algorithm does not increase the training time in any stage.

Existing post-training protections \citep{yang2021privacy, lu2022differentially} add noises to the neurons of the network. The privacy budget of such protections increases when the size of queries grows. The proposed protection algorithm that deploys the additive logistic mechanism adds noises to the trainable weights, hence will not be affected by the data scale.




\section{Additive Logistic Mechanism}

In this section, we introduce a new differentially private mechanism called additive logistic mechanism. We introduce the mechanism in Definition \ref{def:alm}.

\begin{definition}
    \label{def:alm}
    Let $f: \mathcal{X} \mapsto \mathcal{Y}$ be a fixed function and $\mathcal{Y}$ be a space in which addition is properly defined.
    The \textbf{\textsc{additive logistic mechanism (ALM)}} $M_{AL}$ takes the function $f$, a query point $x \in \mathcal{X}$, and a distribution parameter $s \in \mathbb{R}$ as inputs and returns a noisy output:
    \begin{center}
        $M_{AL}(x, f, s) = f(x) + Log(s)$,
    \end{center}
    where $Log(s)$ is an $n$-dimensional vector $\Vec{v}=\{v_1,...,v_n\} \in \mathbb{R}^n$ and each $v_i \in \Vec{v}$ is sampled from a logistic distribution with the location parameter $\mu = 0$ and the scale parameter $s$. The probability density function (PDF) of the logistic distribution is as follows:
    \begin{equation}
    \label{eq:pdf}
        p(x; s, \mu) = \frac{\exp(-(x - \mu)/s)}{s(1 + \exp(-(x - \mu)/s))^2}.
    \end{equation}
\end{definition}

\subsection{Differentially Private Additive Logistic Mechanism}
\label{sec:alm}
We claim that the ALM is $\epsilon$-differentially private and express the privacy budget $\epsilon$ in terms of the parameter $s$ (in Equation \ref{eq:pdf}). We begin the claim by introducing the concept of \textit{sensitivity}. When we take a function $f$ and feed a set of inputs to $f$, individual inputs may impact the output of $f$ differently. Sensitivity $\Delta_f$ is a measurement of the extend to which an individual component impacts the overall outcome of $f$ \citep{laplace-mechanism}. We formally define sensitivity as follows:
\begin{definition}
    \label{def: sensitivity}
    Let a function $f:\mathcal{X}\mapsto \mathcal{Y}$ be a mapping from a dataset domain $\mathcal{X}$ to a normed space $\mathcal{Y}$. Then, the sensitivity of the function $f$, denoted $\Delta_f$, is
    \begin{equation}
        \Delta_f := \sup_{D,D'} \|f(D) - f(D')\|,
    \end{equation}
    where $\|\cdot\|$ is the norm operator and $D$ and $D'$ are any two \textit{adjacent} datasets and the notion of adjacency is formally defined as follows:
\end{definition}

\begin{definition}
    \label{def:adjacent}
    Let $f$ be a given function. Define two datasets $D$ and $D'$, both in the input domain of $f$, \textit{adjacent} if the number of entries in which the two datasets hold different values is at most one.
\end{definition}

Once we compute the sensitivity $\Delta_f$, we can set the parameter $s$ of the ALM for a given privacy budget $\epsilon$.

\begin{theorem}
\label{thm:epsilon}
    Let $f$ be a given function and $\Delta_f$ be its sensitivity. For a given $\epsilon>0$, the additive logistic mechanism $M_{AL} (x, f, s)$ is $\epsilon$-differentially private for $\epsilon = \frac{\Delta_f}{s}$.
\end{theorem}

\begin{remark}
\label{remark:1-norm}
    Let $f: \mathcal{X} \mapsto \mathbb{R}^n$ be a function whose outputs are vector-valued; Theorem \ref{thm:epsilon} still holds. In this case, the sensitivity $\Delta_f$ is computed with respect to the 1-norm distance, denoted \textit{1-norm sensitivity}.
\end{remark}

\subsection{Existing Additive Noise Mechanisms for Differential Privacy}
We now review two of the most well-known additive noise mechanisms, the Laplace mechanism $M_{Lap}$ \citep{laplace-mechanism} and the Gaussian mechanism $M_{Gauss}$ \citep{gaussian-mechanism}. We use these two mechanisms as benchmarks and compare them with the additive logistic mechanism that we proposed.
The Gaussian mechanism and the Laplace mechanism have been proved to be differentially private and have been widely utilized in privacy protection algorithms \citep{Abadi2016DeepLW, yang2021privacy, lu2022differentially}. We now state the definitions of the two mechanisms.
\begin{remark}
    \label{remark:anm}
    The Laplace mechanism adds noise drawn from a Laplace distribution:
    \begin{center}
        $M_{Lap}(x, f, \epsilon) = f(x) + Lap(\mu=0, b=\frac{\Delta_f}{\epsilon})$
    \end{center}
    and is $\epsilon$-differentially private. $\Delta_f$ is the 1-norm sensitivity of $f$.
    
    The Gaussian mechanism adds noise drawn from a Gaussian distribution:
    \begin{center}
        $M_{Gauss}(x, f, \epsilon, \delta) = f(x) + \mathcal{N} \left( \mu=0, \sigma^2 = \frac{2 \ln(1.25/\delta) \cdot (\Delta_f)^2}{\epsilon^2} \right)$
    \end{center}
    and is $(\epsilon, \delta)$-differentially private \citep{10.1007/11761679_29}, where $\delta$ is typically less than $\frac{1}{N}$ and $N$ is the dataset size. $\Delta_f$ is the sensitivity of $f$ computed in the 2-norm distance, denoted \textit{2-norm sensitivity}.
\end{remark}

\subsection{Differential Privacy for Machine Learning Algorithms}
\label{sec:app}
We refer to a machine learning algorithm as an algorithm that is used to optimize the weights of a neural network using a given training dataset. A machine learning algorithm $\mathcal{A_H}$ takes in as input a set of hyper parameters $\mathcal{H}$ and a training dataset and outputs a set of weights in the real coordinate space.
Therefore, we claim that Theorem \ref{thm:epsilon} can be used in the context of machine learning algorithms that are used to train neural networks.


We deploy a randomized mechanism in the machine learning algorithm to add noise to the outputs of the algorithm. The randomized mechanism helps the algorithm satisfy differential privacy. Hence we can construct an ad-hoc \textit{differentially private machine learning algorithm}.

\begin{definition}
    \label{prop:DP}
    [\textbf{\textsc{Differentially Private Machine Learning Algorithm}}].
    
    Let $\mathcal{H}$ be a set of hyper-parameters and $\mathcal{A_H}: \mathcal{X} \mapsto \mathbb{R}^n$ be a machine learning algorithm that maps any training dataset $D \in \mathcal{X}$ to a vector of network weights.
    Let $M:\mathbb{R}^n \mapsto \mathbb{R}^n$ be a randomized mechanism, $D$ and $D'$ be two adjacent training datasets.
    We say $M(\mathcal{A_H})$ is $(\epsilon, \delta)$-differnetially private if, for all $R\subseteq \mathbb{R}^n$, all adjacent $D$ and $D'$, and all $x\in \mathcal X$,
    \begin{equation}
    \label{eq:diff privacy}
        \mathrm{P}\left[M(\mathcal{A_H}(D)) \in R \right] \le
        \exp(\epsilon) \cdot \mathrm{P}\left[M(\mathcal{A_H}(D')) \in R \right] + \delta.
    \end{equation}
    If $\delta = 0$, we call the algorithm $M(\mathcal{A_H}): \mathcal{X} \mapsto \mathbb{R}^n$ an \textit{$\epsilon$-differentially private machine learning algorithm}.
\end{definition}

Feeding two adjacent training datasets $D$ and $D'$ results in two different sets of network weights being trained. The sensitivity establishes an upper bound on the difference between these weights for any possible pair of adjacent training datasets. We consider $\mathcal{A_H}$ as the function $f$ in Definition \ref{def: sensitivity} to obtain the sensitivity of the machine learning algorithm that trains neural networks.

We have so far defined differentially private machine learning algorithms and the way of computing sensitivity.
We know from Remark \ref{remark:1-norm} that the ALM $M_{AL}(x, f, s)$ satisfies differential privacy if the output space of $f$ is a real coordinate space $\mathbb{R}^n$.
The machine learning algorithm in Definition \ref{prop:DP} is $\mathcal{A_H}: \mathcal{X} \mapsto \mathbb{R}^n$, whose input and output spaces are identical with $f$ in Remark \ref{remark:1-norm}.
Therefore, we deploy the ALM in the machine learning algorithm $\mathcal{A_H}$ and claim that $M_{AL}(x, \mathcal{A_H}, s)$ is an $\epsilon$-differentially private machine learning algorithm.
We can compute the privacy budget $\epsilon$ of the algorithm as the following:

\begin{proposition}
\label{prop:epsilon}
    The additive logistic mechanism $M_{AL} (x, \mathcal{A_H}, s)$ with machine learning algorithm $\mathcal{A_H}$ is $\epsilon$-differentially private for $\epsilon = \frac{\Delta_{\mathcal{H}}}{s}$.
    $\Delta_{\mathcal{H}}$ is the sensitivity of $\mathcal{A_H}$ and computed in the 1-norm distance.
\end{proposition}

\section{Post-training Protection on Self-Supervised Learning}

We have introduced the ALM and shown that the mechanism satisfy differential privacy in Section \ref{sec:alm}. We then show that we can construct a differentially private machine learning algorithm by deploying the ALM in a given machine learning algorithm in Section \ref{sec:app}.
In this section, we propose a post-training protection algorithm for deploying the ALM in self-supervised neural networks.

Recall that self-supervised learning contains two stages: pretraining stage and fine-tuning stage.
In the pretraining stage, the self-supervision algorithm $\mathcal{A_H}$ with the set of hyper-parameters $\mathcal{H}$ trains a base encoder $NN_{\mathcal{A_H}}$ by creating and fitting to pseudo-labels. In the fine-tuning stage, we apply an algorithm $\mathcal{A_S}$ with the set of hyper-parameters $\mathcal{S}$ to train a projection head $MP_{\mathcal{A_S}}$ to solve actual task.

We propose a post-training protection algorithm to provide differential privacy to $\mathcal{A_S}$. We implement an Additive Logistic Query Handler (ALQH) that deploys the ALM in constructing a differentially private machine learning algorithm $M_{AL}(\mathcal{A_S})$.

\begin{algorithm}
\caption{\textsc{Additive Logistic Query Handler}}
\label{algo: mechanism}
\KwIn{pretraining algorithm $\mathcal{A_H}$,
		pretraining dataset $D$,
		fine-tuning algorithm $\mathcal{A_S}$,
		fine-tuning dataset $d$,
		ALM parameter $s$,
		query point $x$}
\KwOut{protected output $\tilde y$}
$\theta \leftarrow \mathcal{A_\mathcal{H}}(D)$ \Comment*[r]{Train base encoder $NN_{\theta}$}

$\tilde r \leftarrow NN_{\theta} (d)$ \Comment*[r]{Obtain the outputs from the base encoder}

$\tilde \omega \sim \mathrm{M_{AL}(\tilde r, \mathcal{A_S}, s)}$ \Comment*[r]{Train the projection head $MP_{\omega}$ and add noise to its weights}

$\tilde y \sim MP_{\tilde \omega} ( NN_{\theta}(x) )$ \Comment*[r]{Output with respect to the query point $x$}
\end{algorithm}

The query handler applies the ALM to the weights $\omega$ of the projection head to preserve privacy in the fine-tuning stage. There is no need to re-train the base encoder $NN_\theta$ and the projection head $MP_\omega$ if we only adjust the parameter $s$ in the query handler without modifying the training algorithm and datasets.
We have shown that the mechanism $M_{AL}(x, \mathcal{A_S}, s)$ with hyper-parameter $s$ is $\epsilon$-differentially private in Proposition \ref{prop:epsilon}. Since we only apply the mechanism once to the weights $\omega$, there is no composition of privacy mechanisms.

We then need to compute the sensitivity $\Delta$ over the weights of the projection heads $\omega$ to determine the privacy budget $\epsilon$. Computing sensitivity is extremely time-consuming. From Definition \ref{def: sensitivity}, we have to compute the sensitivity by looping through every pair of adjacent datasets and train two networks for each pair of datasets.  Therefore, we use a Sensitivity Sampler (Algorithm \ref{algo:Sensitivity Sampler}) to estimate the sensitivity the self-supervised learning algorithm \citep{sensitivity_sampler}.
\begin{algorithm}[!ht]
\caption{\textsc{Sensitivity Sampler}}\label{algo:Sensitivity Sampler}
\KwIn{pretraining algorithm $\mathcal{A_H}$,
		pretraining dataset $D$,
		fine-tuning algorithm $\mathcal{A_S}$,
		fine-tuning dataset $d$,
		sample size $m$,
		random sampler $randint(\text{upper bound})$}
\KwOut{$\Delta$}

$\theta \leftarrow \mathcal{A_H}(D)$ \Comment*[r]{Train the base encoder $NN_{\theta}$}
\For{$k=1$ to $m$}{
$d_i, d_j \leftarrow d[randint(|d|)], d[randint(|d|)]$ \Comment*[r]{Select two random elements from the fine-tuning dataset $d$}
$D_1, D_2 \leftarrow d \setminus d_i, d \setminus d_j$ \;

$\omega_1, \omega_2 \leftarrow \mathcal{A_S}( NN_{\theta} (D_1) ), \mathcal{A_S}( NN_{\theta} (D_2) )$ \Comment*[r]{Fine-tune the models and obtain weights of the projection heads}

$\bar \Delta^{(i)} \leftarrow \| \omega_1 - \omega_2 \|_1$\;
}
$\Delta \leftarrow  \max_i \bar \Delta^{(i)}$\;
\end{algorithm}

