Privacy-Preserving 3-Layer Neural Network Training
In this manuscript, we consider the problem of privacy-preserving training of
neural networks in the mere homomorphic encryption setting. We combine several
exsiting techniques available, extend some of them, and finally enable the
training of 3-layer neural networks for both the regression and classification
problems using mere homomorphic encryption technique.
John Chiang
# Privacy-Preserving 3-Layer Neural Network Training using

###### Abstract

In this manuscript, we consider the problem of privacy-preserving training of neural networks in the mere homomorphic encryption setting. We combine several exsiting techniques available, extend some of them, and finally enable the training of 3-layer neural networks for both the regression and classification problems using mere homomorphic encryption technique.

## 1 Introduction

### Background

In the age of artificial intelligence and machine learning, neural networks have emerged as state-of-the-art models, exhibiting exceptional predictive capabilities for both regression and classification tasks. These networks are favored across diverse domains like healthcare and finance due to their remarkable performance. However, achieving high accuracy in training neural network models demands access to substantial volumes of private and sensitive data. This creates a requirement for individuals and institutions to securely share sensitive data, thereby extracting valuable insights from it. Homomorphic Encryption emerges as a straightforward solution for preserving privacy during neural network training in such scenarios, offering a high level of security.

### Related work

Several papers already discussed privacy-preserving training of binary logistic regression [23; 5; 7; 18; 1; 24; 11; 20] and homomorphic inference on neural networks [13; 17; 22]. Sav et al. [26] address the challenge of preserving privacy during the training and evaluation of neural networks within a multi-party federated learning framework.

The research most closely related to this paper is the work of Chiang et al. [16]. They also employed machine learning based on homomorphic encryption but used a faster gradient variant called Quadratic Gradient [11; 12; 15] extending from the (Simplified) Fixed Hessian [5; 4; 3; 2]. However, it's important to note that in their work they only completed the training for classification problems using multiclass logisitic regression, namely a simple 2-layer neural network without any hidden layer.

### Contributions

In this study, we extend homomorphic multiclass logistic regression training in the work [16] to 3-layer neural networks with one single hidden layer of various numbles of nodes, for both regression and classification problems. We demonstrate the feasibility of training a homomorphic 3-layer neural network in the HE-encrypted domain and extend the loss function, Squared Likelihood Error, to its two variants that can be used for classification problems in privacy-preserving neural network training
using mere homomorphic encryption. The Mean Squared Error (MSE) loss function is HE-friendly and can be applied for regression tasks in this paper.

## 2 Preliminaries

Let "\(\odot\)" denote the component-wise multiplication between matrices. The Sigmoid function is represented as follows:

\[Sigmoid(x)=\frac{1}{1+\exp(-x)}.\]

### Fully Homomorphic Encryption

Homomorphic encryption is an important technique in cryptography and is hailed as the Holy Grail in the field of cryptography. It is a special encryption method that allows calculations to be performed in an encrypted state without the need to decrypt the data. This means that by using homomorphic encryption, it is possible to perform various operations on encrypted data, such as addition, multiplication, etc., without having to decrypt them first. This provides a powerful tool for protecting data privacy, as the data remains encrypted at all times.

HE is especially useful for handling sensitive data, such as medical records and financial information. However, due to the computational complexity of homomorphic encryption, it can be slower than traditional encryption methods. In recent years, with the continuous development of technology [19; 6; 27; 9], researchers have continuously worked hard to improve the efficiency of homomorphic encryption to make it more feasible in practical applications.

### Database Encoding Method

The current efficient database encoding method [23] for a given dataset matrix \(M\) is to flatten the matrix \(M\) into a vector first and then encrypt this vector into a single ciphertext, but finally to see the resulting ciphertext as encrypting a matrix directly. This database encoding method could make full use of the HE computation and storage resources:

\[M=\left[\begin{array}{ccccc}x_{10}&x_{11}&\ldots&x_{1d}\\ x_{20}&x_{21}&\ldots&x_{2d}\\ \vdots&\vdots&\ddots&\vdots\\ x_{n0}&x_{n1}&\ldots&x_{nd}\end{array}\right]\]

\[\Big{\downarrow}\]

Flatents the input dataset in a row-by-row manner

\[\left[\begin{array}{ccccccccc}x_{10}&x_{11}&\ldots&x_{1d}&x_{20}&x_{21}& \ldots&x_{2d}&\ldots&\ldots&\ldots&x_{n0}&x_{n1}&\ldots&x_{nd}\end{array}\right]\]

\[\Big{\downarrow}\]

Encrts the row vector

\[Enc\left[\begin{array}{ccccccccc}x_{10}&x_{11}&\ldots&x_{1d}&x_{20}&x_{21}& \ldots&x_{2d}&\ldots&\ldots&\ldots&x_{n0}&x_{n1}&\ldots&x_{nd}\end{array}\right]\]

\[\Big{\downarrow}\]

Seen as encrypting the dataset directly

\[Enc\left[\begin{array}{ccccc}x_{10}&x_{11}&\ldots&x_{1d}\\ x_{20}&x_{21}&\ldots&x_{2d}\\ \vdots&\vdots&\ddots&\vdots\\ x_{n0}&x_{n1}&\ldots&x_{nd}\end{array}\right]=EncM.\]

Based on this database encoding, two simple operations, the complete row shifting and the \(incomplete\) column shifting, can be obtained by shifting the encrypted vector by two different
positions \((1+d)\) and \(1\), respectively:

\[Enc\left[\begin{array}{cccc}x_{10}&x_{11}&\ldots&x_{1d}\\ x_{20}&x_{21}&\ldots&x_{2d}\\ \vdots&\vdots&\ddots&\vdots\\ x_{n0}&x_{n1}&\ldots&x_{nd}\end{array}\right]\stackrel{{\text{ complete row shifting}}}{{\longmapsto}}Enc\left[\begin{array}{cccc}x_{20}&x_{21}&\ldots&x_{2d}\\ \vdots&\vdots&\ddots&\vdots\\ x_{n0}&x_{n1}&\ldots&x_{nd}\\ x_{10}&x_{11}&\ldots&x_{1d}\end{array}\right],\]

\[Enc\left[\begin{array}{cccc}x_{10}&x_{11}&\ldots&x_{1d}\\ x_{20}&x_{21}&\ldots&x_{2d}\\ \vdots&\vdots&\ddots&\vdots\\ x_{n0}&x_{n1}&\ldots&x_{nd}\end{array}\right]\stackrel{{\text{ incomplete column shifting}}}{{\longmapsto}}Enc\left[\begin{array}{cccc}x_{11}&\ldots&x_{1d}&x_{20}\\ x_{21}&\ldots&x_{2d}&x_{30}\\ \vdots&\vdots&\ddots&\vdots\\ x_{n1}&\ldots&x_{nd}&x_{10}\end{array}\right].\]

The complete column shifting to obtain the matrix \(Z^{{}^{\prime\prime\prime}}\) can also be achieved by two Rot, two cMult, and an Add.

\[Enc\left[\begin{array}{cccc}x_{10}&x_{11}&\ldots&x_{1d}\\ x_{20}&x_{21}&\ldots&x_{2d}\\ \vdots&\vdots&\ddots&\vdots\\ x_{n0}&x_{n1}&\ldots&x_{nd}\end{array}\right]\stackrel{{\text{ complete column shifting}}}{{\longmapsto}}Enc\left[\begin{array}{cccc}x_{11}&\ldots&x_{1d}&x_{10}\\ x_{21}&\ldots&x_{2d}&x_{20}\\ \vdots&\vdots&\ddots&\vdots\\ x_{n1}&\ldots&x_{nd}&x_{n0}\end{array}\right].\]

The same database encoding method also facilitates the development of other procedures [20, 13], such as SumRowVec and SumColVec to compute the sum of each row and column, respectively.

To address the homomorphic evaluation of training 3-layer neural networks for regression and classification tasks, we introduce two procedures KeepOnly and RollFill :

\[Enc\left[\begin{array}{cccccccc}x_{10}&x_{11}&\ldots&x_{ij}&\ldots&x_{n0}&x _{n1}&\ldots&x_{nd}\end{array}\right]\]

\[\odot\]

\[\left[\begin{array}{cccccccc}0&0&\ldots&1&\ldots&0&0&\ldots&0\end{array}\right]\]

\[\parallel\]

\[Enc\left[\begin{array}{cccccccc}0&0&\ldots&x_{ij}&\ldots&0&0&\ldots&0\end{array}\right]\]

\[Enc\left[\begin{array}{cccccccc}x_{10}&x_{11}&\ldots&x_{ij}&\ldots&x_{n0}&x _{n1}&\ldots&x_{nd}\end{array}\right]\]

\[\Big{\downarrow}\]
the transpose of the first matrix is equally viable, leading to a multiplication algorithm similar to Algorithm 2 presented in [13].

Furthermore, should either of the matrices prove too extensive to be encrypted into a single ciphertext, an alternative approach involves encrypting the matrices into two separate groups, labeled as Team \(A\) and Team \(B\), each comprising multiple ciphertexts. In this particular context, the encoding methodology referred to as Double Volley Revolver [16] begins to come into play, which encompasses two distinct loops. The outer loop manages calculations involving ciphertexts from both teams, while the inner loop performs calculations on two sub-matrices encrypted by the respective ciphertexts \(A_{[i]}\) and \(B_{[j]}\), following the fundamental Volley Revolver algorithm.

#### 2.3.1 Datasets

We adopt three common datasets in our experiments: Boston Housing Prices, Iris and MNIST. Table 1 describes the three datasets.

## 3 Technical details

### 3-Layer Neural Networks

Neural networks (NNs) are powerful machine learning algorithms engineered to capture complex nonlinear connections between input and output data, even though they may lack reasonable interpretability [14, 21, 8]. A typical NN consists of a series of layers, where iterative feedforward and backpropagation steps implement linear and non-linear transformations (activations) on input data. Each training iteration comprises a forward pass and a backward pass.

In our implementations, we utilize a 3-layer neural network comprising a single hidden layer with 12 nodes for the regression task using the Boston Housing Prices dataset. Similarly, for the classification tasks involving the Iris and MNIST datasets, we employ a 3-layer neural network featuring a single hidden layer equipped with 120 nodes.

Figure 1 illustrates the neural network architecture created for the regression task, whereas Figure 2 depicts the network architecture designed for the classification challenges.

Given the matrix \(X\in\mathbb{R}^{n\times(1+d)}\), the column vector \(Y\in\mathbb{N}^{n\times 1}\), the matrix \(\bar{Y}\in\mathbb{R}^{n\times c}\), the matrix \(W\in\mathbb{R}^{m\times(1+d)}\), and the matrix \(V\in\mathbb{R}^{c\times(1+m)}\), we interpret these entities as follows: \(X\) represents the dataset, \(Y\) denotes the class labels in column vector format, \(\bar{Y}\) signifies the one-hot encoding of the class labels, \(W\) stands for the weight matrix connecting the first two layers of the neural network, and \(V\) symbolizes the weight matrix linking the last two layers. Here, \(m\) is the number of nodes in the hidden layer.

\begin{table}
\begin{tabular}{|c|c|c|c|c|} \hline Dataset & No. Samples & No. Samples & No. Features & No. Classes \\ \hline Boston Housing Prices & 506 & - & 13 & - \\ \hline Iris & 150 & - & 4 & 3 \\ \hline MNIST & 60,000 & 10,000 & 28\(\times\)28 & 10 \\ \hline \end{tabular}
\end{table}
Table 1: Characteristics of the several datasets used in our experiments
Figure 1: The neural network architecture created for the regression task

Figure 2: The network architecture designed for the classification challenges
\[X=\begin{bmatrix}x_{[1]}\\ x_{[2]}\\ \vdots\\ x_{[n]}\end{bmatrix}=\begin{bmatrix}1&x_{[1][1]}&\cdots&x_{[1][d]}\\ 1&x_{[2][1]}&\cdots&x_{[2][d]}\\ \vdots&\vdots&\ddots&\vdots\\ 1&x_{[n][1]}&\cdots&x_{[n][d]}\end{bmatrix}=\begin{bmatrix}x_{[1][0]}&x_{[1][1]} &\cdots&x_{[1][d]}\\ x_{[2][0]}&x_{[2][1]}&\cdots&x_{[2][d]}\\ \vdots&\vdots&\ddots&\vdots\\ \vdots&\vdots&\ddots&\vdots\\ x_{[n][0]}&x_{[n][1]}&\cdots&x_{[n][d]}\end{bmatrix},\] \[Y=\begin{bmatrix}y_{1}\\ y_{2}\\ \vdots\\ y_{n}\end{bmatrix}\underbrace{\text{\small one-hot encoding}}_{\text{\small$y_{2}$}}\ Y=\begin{bmatrix}y_{[1]}\\ \mathcal{Y}_{[2]}\\ \vdots\\ \mathcal{Y}_{[n]}\end{bmatrix}=\begin{bmatrix}y_{[1][1]}&y_{[1][2]}&\cdots&y_{ [1][c]}\\ y_{[2][1]}&y_{[2][2]}&\cdots&y_{[2][c]}\\ \vdots&\vdots&\ddots&\vdots\\ y_{[n][1]}&y_{[n][2]}&\cdots&y_{[n][c]}\end{bmatrix},\] \[W=\begin{bmatrix}w_{[1]}\\ w_{[2]}\\ w_{[m]}\\ \vdots\\ w_{[m]}\end{bmatrix}=\begin{bmatrix}w_{[1][0]}&w_{[1][1]}&\cdots&w_{[1][d]}\\ w_{[2][0]}&w_{[2][1]}&\cdots&w_{[2][d]}\\ \vdots&\vdots&\ddots&\vdots\\ w_{[m][0]}&w_{[m][1]}&\cdots&w_{[m][d]}\end{bmatrix},\] \[V=\begin{bmatrix}v_{[1]}\\ v_{[2]}\\ \vdots\\ v_{[c]}\end{bmatrix}=\begin{bmatrix}v_{[1][0]}&v_{[1][1]}&\cdots&v_{[1][m]}\\ v_{[2][0]}&v_{[2][1]}&\cdots&v_{[2][m]}\\ \vdots&\vdots&\ddots&\vdots\\ v_{[c][0]}&v_{[c][1]}&\cdots&v_{[c][m]}\end{bmatrix}.\]

NN training conssits of two stages: Forward inference and Backward training.

#### Forward inference

Step 1:

\[X\times W^{\intercal}=\begin{bmatrix}z_{[1][1]}&z_{[1][2]}&\cdots&z_{[1][m]} \\ z_{[2][1]}&z_{[2][2]}&\cdots&z_{[2][m]}\\ \vdots&\vdots&\ddots&\vdots\\ z_{[n][1]}&z_{[n][2]}&\cdots&z_{[n][m]}\end{bmatrix}=Z_{0},\]

Step 2: we select the square function as the activation function denoted as \(\phi(x)=x^{2}\)

\[Z_{0}\xrightarrow{\phi(Z)}Z_{1}=\begin{bmatrix}\phi(z_{[1][1]})&\phi(z_{[1][2 ]})&\cdots&\phi(z_{[1][m]})\\ \phi(z_{[2][1]})&\phi(z_{[2][2]})&\cdots&\phi(z_{[2][m]})\\ \vdots&\vdots&\ddots&\vdots\\ \phi(z_{[n][1]})&\phi(z_{[n][2]})&\cdots&\phi(z_{[n][m]})\end{bmatrix},\]

Step 3:

\[Z_{1}\mapsto Z=\begin{bmatrix}1&\phi(z_{[1][1]})&\phi(z_{[1][2]})&\cdots&\phi (z_{[1][m]})\\ 1&\phi(z_{[2][1]})&\phi(z_{[2][2]})&\cdots&\phi(z_{[2][m]})\\ \vdots&\vdots&\vdots&\ddots&\vdots\\ 1&\phi(z_{[n][1]})&\phi(z_{[n][2]})&\cdots&\phi(z_{[n][m]})\end{bmatrix},\]

Step 4:

\[Z\times V^{\intercal}=\bar{Y}=\begin{bmatrix}\bar{y}_{[1][1]}&\bar{y}_{[1][2]} &\cdots&\bar{y}_{[1][c]}\\ \bar{y}_{[2][1]}&\bar{y}_{[2][2]}&\cdots&\bar{y}_{[2][c]}\\ \vdots&\vdots&\ddots&\vdots\\ \bar{y}_{[n][1]}&\bar{y}_{[n][2]}&\cdots&\bar{y}_{[n][c]}\end{bmatrix},\]
Backward training\(\nabla W=(S\times\bar{V}\odot Z^{{}^{\prime}})^{\intercal}\times X\), \(\nabla V=S^{\intercal}\times Z\) where \(\bar{V}\) is

\[\bar{V}=\begin{bmatrix}v_{[1][1]}&v_{[1][2]}&\cdots&v_{[1][m]}\\ v_{[2][1]}&v_{[2][2]}&\cdots&v_{[2][m]}\\ \vdots&\vdots&\ddots&\vdots\\ v_{[c][1]}&v_{[c][2]}&\cdots&v_{[c][m]}\end{bmatrix},\]

and \(Z^{{}^{\prime}}\) is obtained from

\[Z_{1}\xrightarrow{\nabla}Z^{{}^{\prime}}=\begin{bmatrix}\phi^{{}^{\prime}}( z_{[1][1]})&\phi^{{}^{\prime}}(z_{[1][2]})&\cdots&\phi^{{}^{\prime}}(z_{[1][m]}) \\ \phi^{{}^{\prime}}(z_{[2][1]})&\phi^{{}^{\prime}}(z_{[2][2]})&\cdots&\phi^{{} }(z_{[2][m]})\\ \vdots&\vdots&\ddots&\vdots\\ \phi^{{}^{\prime}}(z_{[n][1]})&\phi^{{}^{\prime}}(z_{[n][2]})&\cdots&\phi^{{} ^{\prime}}(z_{[n][m]})\end{bmatrix}.\]

Finally, various first-order gradient descent algorithms with a certain learning rate scheme can be used to modify the NN parameters \(W\) and \(V\). In our work, we just adopt the raw gradient descent with a fixed learning rate \(\eta\): \(W=W-\eta\cdot\nabla W\) and \(V=V-\eta\cdot\nabla V\).

### Approximating Softmax Function

The conventional training approach for classification involves utilizing the log-likelihood loss function, which incorporates the Softmax function:

\[\bar{Y}\xrightarrow{Softmax}S_{0}=\] \[\begin{bmatrix}\exp(\bar{y}_{[1][1]})/\sum_{i=1}^{c}\exp(\bar{y}_ {[1][i]})&\exp(\bar{y}_{[1][2]})/\sum_{i=1}^{c}\exp(\bar{y}_{[1][i]})&\cdots& \exp(\bar{y}_{[1][c]})/\sum_{i=1}^{c}\exp(\bar{y}_{[1][i]})\\ \exp(\bar{y}_{[2][1]})/\sum_{i=1}^{c}\exp(\bar{y}_{[2][i]})&\exp(\bar{y}_{[2][ 2]})/\sum_{i=1}^{c}\exp(\bar{y}_{[2][i]})&\cdots&\exp(\bar{y}_{[2][c]})/\sum_{i =1}^{c}\exp(\bar{y}_{[2][i]})\\ \vdots&\vdots&\ddots&\vdots\\ \exp(\bar{y}_{[n][1]})/\sum_{i=1}^{c}\exp(\bar{y}_{[n][i]})&\exp(\bar{y}_{[n][ 2]})/\sum_{i=1}^{c}\exp(\bar{y}_{[n][i]})&\cdots&\exp(\bar{y}_{[n][c]})/\sum_{i =1}^{c}\exp(\bar{y}_{[n][i]})\end{bmatrix},\] \[S_{0}\xrightarrow{\arg\max}output=\begin{bmatrix}\arg\max_{j} \exp(\bar{y}_{[1][j]})/\sum_{i=1}^{c}\exp(\bar{y}_{[1][i]})\\ \arg\max_{j}\exp(\bar{y}_{[2][j]})/\sum_{i=1}^{c}\exp(\bar{y}_{[1][i]})\\ \vdots\\ \arg\max_{j}\exp(\bar{y}_{[n][j]})/\sum_{i=1}^{c}\exp(\bar{y}_{[1][i]})\end{bmatrix}.\]

Given the presence of inherent uncertainties, it could be challenging to attain an acceptably-usable polynomial approximation of the Softmax function within the context of privacy-preserving computations. To tackle this challenge, Chiang [16] apply the mathematical strategy: transforming a complex problem into a simpler counterpart. Considering this, rather than attempting a direct approximation of the Softmax function, they shift their focus towards approximating the Sigmoid function within the encrypted domain. In doing so, they have developed a novel loss function named \(SLE\) (Squared Likelihood Error), which solely relies on the Sigmoid function, rather than using the Softmax function.

### Squared Likelihood Error

The SLE loss function is expected to yield the following neural network output:
\[\bar{Y}\xrightarrow{SLE_{1}}S_{1}=\] \[\begin{bmatrix}Sigmoid(\bar{y}_{[1|1]})&Sigmoid(\bar{y}_{[1|2]})& \cdots&Sigmoid(\bar{y}_{[1|[c]})\\ Sigmoid(\bar{y}_{[2|1]})&Sigmoid(\bar{y}_{[2|2]})&\cdots&Sigmoid(\bar{y}_{[ 2|[c]})\\ \vdots&\vdots&\ddots&\vdots\\ Sigmoid(\bar{y}_{[n|1]})&Sigmoid(\bar{y}_{[n|2]})&\cdots&Sigmoid(\bar{y}_{[ n|[c]})\end{bmatrix},\] \[S_{1}\xrightarrow{\arg\max}output=\begin{bmatrix}\arg\max_{j} Sigmoid(\bar{y}_{[1|[j]})\\ \arg\max_{j}Sigmoid(\bar{y}_{[2|[j]})\\ \vdots\\ \arg\max_{j}Sigmoid(\bar{y}_{[n|[j]})\end{bmatrix},\]

and thus has the \(S\):

\[S =\begin{bmatrix}S_{[1|1]}&S_{[1|2]}&\cdots&S_{[1|[c]}\\ S_{[2|1]}&S_{[2|2]}&\cdots&S_{[2|[c]}\\ \vdots&\vdots&\ddots&\vdots\\ S_{[n|1]}&S_{[n|2]}&\cdots&S_{[n|[c]}]\end{bmatrix}\] \[=\begin{bmatrix}1-Sigmoid(\bar{y}_{[1|[1]})-y_{[1|1]}&1-Sigmoid( \bar{y}_{[1|2]})-y_{[1|2]}&\cdots&1-Sigmoid(\bar{y}_{[1|[c]})-y_{[1|[c]}\\ 1-Sigmoid(\bar{y}_{[2|[1]})-y_{[2|1]}&1-Sigmoid(\bar{y}_{[2|[2]})-y_{[2|2]}& \cdots&1-Sigmoid(\bar{y}_{[2|[c]})-y_{[2|[c]}\\ \vdots&\vdots&\ddots&\vdots\\ 1-Sigmoid(\bar{y}_{[n|[1]})-y_{[n|1]}&1-Sigmoid(\bar{y}_{[n|[2]})-y_{[n|[2]}& \cdots&1-Sigmoid(\bar{y}_{[n|[c]})-y_{[n|[c]}]\end{bmatrix}.\]

The SLE loss function, denoted as \(L\), along with its logarithmic differential \(\mathrm{d}\ln L\), is defined as follows:

\[L=\prod_{i=1}^{n}\prod_{j=1}^{c}(Sigmoid(\bar{y}_{[i][j]})-y_{[i][j]})^{2} \longmapsto\ln L=\sum_{i=1}^{n}\sum_{j=1}^{c}\ln|Sigmoid(\bar{y}_{[i|[j]})- y_{[i][j]}|,\]

and

\[\mathrm{d}\ln L=\sum_{i=1}^{n}\sum_{j=1}^{c}(1-Sigmoid(\bar{y}_{[i][j]})-y_{[ i|[j]})\mathrm{d}\bar{y}_{[i|[j]}.\]

#### 3.3.1 First Variant of SLE

Although SLE demonstrates success in multiclass logistic regression, as evidenced in [16], it fails to yield effective results in neural networks with hidden layers. This could be attributed to a tendency to easily converge towards local minima.

We propose a variant of SLE that can address this issue still using only the Sigmoid function: 1st variant of SLE:

\[L_{1}=\sum_{i=1}^{n}\sum_{j=1}^{c}(Sigmoid(\bar{y}_{[i|[j]})-y_{[i][j]})^{2}.\]

Its differential \(\mathrm{d}L_{1}\), is defined as follows:

\[\mathrm{d}L_{1} =\sum_{i=1}^{n}\sum_{j=1}^{c}\mathrm{d}(Sigmoid(\bar{y}_{[i|[j] })-y_{[i|[j]})^{2}\] \[=\sum_{i=1}^{n}\sum_{j=1}^{c}2\cdot(Sigmoid(\bar{y}_{[i|[j]})-y_{[ i|[j]})\cdot Sigmoid(\bar{y}_{[i|[j]})\cdot(1-Sigmoid(\bar{y}_{[i|[j]}))\mathrm{d} \bar{y}_{[i|[j]},\]

and a simplified approximation of \(\mathrm{d}L_{1}\) also demonstrates remarkable performance while requiring fewer calculations:

\[\mathrm{d}L_{1}=\sum_{i=1}^{n}\sum_{j=1}^{c}2\cdot(Sigmoid(\bar{y}_{[i|[j]})-y _{[i|[j]})\cdot 0.25\mathrm{d}\bar{y}_{[i|[j]}.\]
For this variant of the \(SLE\) loss function, we can formulate the expression for \(S\) as follows:

\[S =\begin{bmatrix}s_{[1[1]}&s_{[1][2]}&\cdots&s_{[1][c]}\\ s_{[2[1]}&s_{[2][2]}&\cdots&s_{[2][c]}\\ \vdots&\vdots&\ddots&\vdots\\ s_{[n][1]}&s_{[n][2]}&\cdots&s_{[n][c]}\end{bmatrix}\] \[=\begin{bmatrix}2\cdot(Sigmoid(\bar{y}_{[1][1]})-y_{[1][1]}) \cdot 0.25&\cdots&2\cdot(Sigmoid(\bar{y}_{[1][c]})-y_{[1][c]})\cdot 0.25\\ 2\cdot(Sigmoid(\bar{y}_{[2][1]})-y_{[2][1]})\cdot 0.25&\cdots&2\cdot(Sigmoid(\bar{y}_{[ 2][c]})-y_{[2][c]})\cdot 0.25\\ \vdots&\ddots&\vdots\\ 2\cdot(Sigmoid(\bar{y}_{[n][1]})-y_{[n][1]})\cdot 0.25&\cdots&2\cdot(Sigmoid(\bar{y}_{[ n][c]})-y_{[n][c]})\cdot 0.25\end{bmatrix}.\]

#### 3.3.2 Second Variant of SLE

The aforementioned initial variant of SLE with the expression \(L_{1}\) demonstrates consistent, robust, and high performance when applied to neural networks with a single hidden layer. However, the input values to the Sigmoid function tend to be large. For instance, when implementing \(SLEL_{1}\) on the MNIST dataset, the Sigmoid function often encounters input values wider than the range of \([-25,+25]\). Even a minor discrepancy from the Sigmoid function itself can adversely affect the performance of the first variant of SLE. While existing HE techniques can achieve near-perfect approximations of the Sigmoid function within such a range, it requires a significant amount of homomorphic computations in the encrypted domain. This drawback results in a less-than-ideal practical solution.

We introduce a second novel variant of SLE that can address the limitations of the first version. This second variant bears a strong resemblance to the Mean Squared Error (MSE) loss function and solely relies on the Sigmoid function:

2nd variant of SLE:

\[L_{2}=\sum_{i=1}^{n}\sum_{j=1}^{c}(\bar{y}_{[i][j]}-y_{[i][j]})^{2}.\]

Its differential \(\mathrm{d}L_{2}\), is defined as follows:

\[\mathrm{d}L_{2}=\sum_{i=1}^{n}\sum_{j=1}^{c}2\cdot(\bar{y}_{[i][j]}-y_{[i][j]} )\cdot\mathrm{d}\bar{y}_{[i][j]}.\]

For this particular variant of the \(SLE\) loss function, we can deduce the expression for \(S\):

\[S =\begin{bmatrix}s_{[1][1]}&s_{[1][2]}&\cdots&s_{[1][c]}\\ s_{[2[1]}&s_{[2][2]}&\cdots&s_{[2][c]}\\ \vdots&\vdots&\ddots&\vdots\\ s_{[n][1]}&s_{[n][2]}&\cdots&s_{[n][c]}\end{bmatrix}\] \[=\begin{bmatrix}2\cdot(\bar{y}_{[1][1]}-y_{[1][1]})&2\cdot(\bar{y }_{[1][2]}-y_{[1][2]})&\cdots&2\cdot(\bar{y}_{[1][c]}-y_{[1][c]})\\ 2\cdot(\bar{y}_{[2][1]}-y_{[2][1]})&2\cdot(\bar{y}_{[2][2]}-y_{[2][2]})&\cdots &2\cdot(\bar{y}_{[2][c]}-y_{[2][c]})\\ \vdots&\vdots&\ddots&\vdots\\ 2\cdot(\bar{y}_{[n][1]}-y_{[n][1]})&2\cdot(\bar{y}_{[n][2]}-y_{[n][2]})&\cdots &2\cdot(\bar{y}_{[n][c]}-y_{[n][c]})\end{bmatrix}.\]

Performance EvaluationThe two variants of SLE possess their individual advantages and disadvantages. We employ the first \(5,000\) MNIST training images to train the NN model with 120 hidden nodes, while utilizing the complete MNIST testing dataset to evaluate the generated performance of the resulting model. This test is repeated 12 times, utilizing two distinct learning rates for the two loss function variants. The average performances in terms of loss and accuracy are presented in Figure 3 and Figure 4.

## 4 Homomorphic NN Training

For simplicity, we utilize the extreme case of the "Double Volley Revolver" methodology to illustrate the feasibility of homomorphic training for a 3-layer neural network (NN) in both regression and
classification tasks. In this scenario, we make the assumption that each individual ciphertext can only encrypt a single row vector such as \(x_{[i]}\), \(y[j]\), \(w[k]\), or \(v_{[g]}\):

\[X=\begin{bmatrix}x_{[1][0]}&x_{[1][1]}&\cdots&x_{[1][d]}\\ x_{[2][0]}&x_{[2][1]}&\cdots&x_{[2][d]}\\ \vdots&\vdots&\ddots&\vdots\\ x_{[n][0]}&x_{[n][1]}&\cdots&x_{[n][d]}\end{bmatrix}\longrightarrow\begin{bmatrix} \mathtt{Enc}\left[x_{[1][0]}&x_{[1][1]}&\ldots&x_{[1][d]}&0&\ldots&0\right]\\ \mathtt{Enc}\left[x_{[2][0]}&x_{[2][1]}&\ldots&x_{[2][d]}&0&\ldots&0\right] \\ \vdots&\vdots&\ddots&\vdots\\ \mathtt{Enc}\left[x_{[n][1]}&x_{[n][1]}&\ldots&x_{[n][d]}&0&\ldots&0\right] \end{bmatrix},\]

\[Y=\begin{bmatrix}y_{[1][1]}&y_{[1][2]}&\cdots&y_{[1][c]}\\ y_{[2][1]}&y_{[2][2]}&\cdots&y_{[2][c]}\\ \vdots&\vdots&\ddots&\vdots\\ y_{[n][1]}&y_{[n][2]}&\cdots&y_{[n][c]}\end{bmatrix}\longrightarrow\begin{bmatrix} \mathtt{Enc}\left[y_{[1][1]}&y_{[1][2]}&\ldots&y_{[1][c]}&0&\ldots&0\right] \\ \mathtt{Enc}\left[y_{[2][1]}&y_{[2][2]}&\ldots&y_{[2][c]}&0&\ldots&0\right] \\ \vdots&\vdots&\ddots&\vdots\\ \mathtt{Enc}\left[y_{[n][1]}&y_{[n][2]}&\ldots&y_{[n][c]}&0&\ldots&0\right] \end{bmatrix},\]

\[W=\begin{bmatrix}w_{[1][0]}&w_{[1][1]}&\cdots&w_{[1][d]}\\ w_{[2][0]}&w_{[2][1]}&\cdots&w_{[2][d]}\\ \vdots&\vdots&\ddots&\vdots\\ w_{[m][0]}&w_{[m][1]}&\cdots&w_{[m][d]}\end{bmatrix}\longrightarrow\begin{bmatrix} \mathtt{Enc}\left[w_{[1][0]}&w_{[1][1]}&\ldots&w_{[1][d]}&0&\ldots&0\right] \\ \mathtt{Enc}\left[w_{[2][0]}&w_{[2][1]}&\ldots&w_{[2][d]}&0&\ldots&0\right] \\ \vdots&\vdots&\vdots&\vdots\\ \mathtt{Enc}\left[w_{[m][0]}&w_{[m][1]}&\ldots&w_{[m][d]}&0&\ldots&0\right] \end{bmatrix},\]

Figure 3: Training and testing experimental results for the two variants of SLE are provided using the same learning rate \(0.12\)
\[V=\begin{bmatrix}v_{[1][0]}&v_{[1][1]}&\cdots&v_{[1][m]}\\ v_{[2][0]}&v_{[2][1]}&\cdots&v_{[2][m]}\\ \vdots&\vdots&\ddots&\vdots\\ v_{[c][0]}&v_{[c][1]}&\cdots&v_{[c][m]}\end{bmatrix}\longrightarrow\begin{bmatrix} \text{Enc}\begin{bmatrix}v_{[1][0]}&v_{[1][1]}&\ldots&v_{[1][m]}&0&\ldots&0\\ \text{Enc}\begin{bmatrix}v_{[2][0]}&v_{[2][1]}&\ldots&v_{[2][m]}&0&\ldots&0\\ &\vdots&&&\\ \text{Enc}\begin{bmatrix}v_{[c][0]}&v_{[c][1]}&\ldots&v_{[c][m]}&0&\ldots&0 \end{bmatrix}\end{bmatrix}.\end{bmatrix}\]

By using HE operations merely we can obtain the ciphertexts that encrypt each row of the matrices \(S\), \(\bar{V}\), \(Z^{{}^{\prime}}\) and \(Z\) :

\[S=\begin{bmatrix}s_{[1][1]}&s_{[1][2]}&\cdots&s_{[1][c]}\\ s_{[2][1]}&s_{[2][2]}&\cdots&s_{[2][c]}\\ \vdots&\vdots&\ddots&\vdots\\ s_{[n][1]}&s_{[n][2]}&\cdots&s_{[n][c]}\end{bmatrix}\longrightarrow\begin{bmatrix} \text{Enc}\begin{bmatrix}s_{[1][1]}&s_{[1][2]}&\ldots&s_{[1][c]}&0&\ldots&0\\ \text{Enc}\begin{bmatrix}s_{[2][1]}&s_{[2][2]}&\ldots&s_{[2][c]}&0&\ldots&0 \end{bmatrix}\\ \vdots&\vdots&\ddots&\vdots\\ \vdots&&&\\ \text{Enc}\begin{bmatrix}s_{[n][1]}&s_{[n][2]}&\ldots&s_{[n][c]}&0&\ldots&0 \end{bmatrix}\end{bmatrix},\]

\[\bar{V}=\begin{bmatrix}v_{[1][1]}&v_{[1][2]}&\cdots&v_{[1][m]}\\ v_{[2][1]}&v_{[2][2]}&\cdots&v_{[2][m]}\\ \vdots&\vdots&\ddots&\vdots\\ v_{[c][1]}&v_{[c][2]}&\cdots&v_{[c][m]}\end{bmatrix}\longrightarrow\begin{bmatrix} \text{Enc}\begin{bmatrix}v_{[1][1]}&v_{[1][2]}&\ldots&v_{[1][m]}&0&\ldots&0 \\ \text{Enc}\begin{bmatrix}v_{[2][1]}&v_{[2][2]}&\ldots&v_{[2][m]}&0&\ldots&0 \end{bmatrix}\\ \vdots&\vdots&\ddots&\vdots\\ \text{Enc}\begin{bmatrix}v_{[c][1]}&v_{[c][2]}&\ldots&v_{[c][m]}&0&\ldots&0 \end{bmatrix}\end{bmatrix},\]

Figure 4: Training and testing experimental results for the two variants of SLE are provided using the same learning rate \(0.01\)
\[Z^{\prime} =\begin{bmatrix}\phi^{{}^{\prime}}\left(z_{[1][1]}\right)&\phi^{{}^{ \prime}}\left(z_{[1][2]}\right)&\cdots&\phi^{{}^{\prime}}\left(z_{[1][m]}\right) \\ \phi^{{}^{\prime}}\left(z_{[2][1]}\right)&\phi^{{}^{\prime}}\left(z_{[2][2]} \right)&\cdots&\phi^{{}^{\prime}}\left(z_{[2][m]}\right)\\ \vdots&\vdots&\ddots&\vdots\\ \phi^{{}^{\prime}}\left(z_{[n][1]}\right)&\phi^{{}^{\prime}}\left(z_{[n][2]} \right)&\cdots&\phi^{{}^{\prime}}\left(z_{[n][m]}\right)\end{bmatrix}\] \[\longrightarrow\begin{bmatrix}\mathtt{Enc}\left[\phi^{{}^{\prime}} \left(z_{[1][1]}\right)&\phi^{{}^{\prime}}\left(z_{[1][2]}\right)&\cdots&\phi^ {{}^{\prime}}\left(z_{[1][m]}\right)&0&\ldots&0\\ \mathtt{Enc}\left[\phi^{{}^{\prime}}\left(z_{[2][1]}\right)&\phi^{{}^{ \prime}}\left(z_{[2][2]}\right)&\ldots&\phi^{{}^{\prime}}\left(z_{[2][m]} \right)&0&\ldots&0\right]\\ \mathtt{Enc}\left[\phi^{{}^{\prime}}\left(z_{[n][1]}\right)&\phi^{{}^{ \prime}}\left(z_{[n][2]}\right)&\cdots&\phi^{{}^{\prime}}\left(z_{[n][m]} \right)&0&\ldots&0\right]\end{bmatrix},\] \[Z =\begin{bmatrix}1&\phi\left(z_{[1][1]}\right)&\phi\left(z_{[1][2]} \right)&\cdots&\phi\left(z_{[1][m]}\right)\\ 1&\phi\left(z_{[2][1]}\right)&\phi\left(z_{[2][2]}\right)&\cdots&\phi\left(z_ {[2][m]}\right)\\ \vdots&\vdots&\ddots&\vdots\\ 1&\phi\left(z_{[n][1]}\right)&\phi\left(z_{[n][2]}\right)&\cdots&\phi\left(z_ {[n][m]}\right)\end{bmatrix}\] \[\longrightarrow\begin{bmatrix}\mathtt{Enc}\left[1&\phi\left(z_{[1] [1]}\right)&\phi\left(z_{[1][2]}\right)&\cdots&\phi\left(z_{[1][m]}\right)&0 &\ldots&0\\ \mathtt{Enc}\left[1&\phi\left(z_{[2][1]}\right)&\phi\left(z_{[2][2]}\right)& \cdots&\phi\left(z_{[2][m]}\right)&0&\ldots&0\right]\\ &&\vdots&\\ \mathtt{Enc}\left[1&\phi\left(z_{[n][1]}\right)&\phi\left(z_{[n][2]}\right)& \cdots&\phi\left(z_{[n][m]}\right)&0&\ldots&0\right]\end{bmatrix},\]

### For Classification Problems

We can first compute the gradients of \(w_{[k]}\) and \(v_{[k]}\) in the encrypted environment and then use the regular gradient descent method to update \(w_{[k]}\) and \(v_{[k]}\):
\[\begin{array}{ccccccccc}\frac{\mathrm{d}}{\mathrm{d}\mathsf{w}_{[k]}}L_{2}=\\ \mathtt{Enc}\big{[}s_{[1][1]}&\cdots&s_{[1][1]}&0&\cdots&0\big{]}\\ &\odot\\ &\mathtt{Enc}\big{[}v_{[1][1+k]}&\cdots&v_{[1][1+k]}&0&\ldots&0\big{]}\\ &\odot\\ &\mathtt{Enc}\big{[}\phi^{\prime}\left(z_{[1][k]}\right)&\cdots&\phi^{\prime} \left(z_{[1][k]}\right)&0&\ldots&0\big{]}\\ &\odot\\ &\mathtt{Enc}\big{[}x_{[1][0]}&\cdots&x_{[1][d]}&0&\ldots&0\big{]}\\ &\mathtt{Enc}\big{[}s_{[2][1]}&\cdots&s_{[2][1]}&0&\ldots&0\big{]}\\ &\mathtt{Enc}\big{[}v_{[1][1+k]}&\cdots&v_{[1][1+k]}&0&\ldots&0\big{]}\\ &\mathtt{Enc}\big{[}v_{[2][k]}&\cdots&\phi^{\prime}\left(z_{[2][k]}\right)&0 &\ldots&0\big{]}\\ &\mathtt{Enc}\big{[}x_{[1][0]}&\cdots&x_{[1][d]}&0&\ldots&0\big{]}\\ &\mathtt{Enc}\big{[}s_{[1][1]}&\cdots&s_{[2][1]}&0&\ldots&0\big{]}\\ &\mathtt{Enc}\big{[}v_{[1][1+k]}&\cdots&v_{[1][1+k]}&0&\ldots&0\big{]}\\ &\mathtt{Enc}\big{[}\phi^{\prime}\left(z_{[2][k]}\right)&\cdots&\phi^{\prime} \left(z_{[2][k]}\right)&0&\ldots&0\big{]}\\ &\mathtt{Enc}\big{[}x_{[1][0]}&\ldots&x_{[1][d]}&0&\ldots&0\big{]}\\ &\mathtt{Enc}\big{[}s_{[n][1]}&\ldots&s_{[n][1]}&0&\ldots&0\big{]}\\ &\mathtt{\odot}\\ &\mathtt{Enc}\big{[}v_{[1][1+k]}&\cdots&v_{[1][1+k]}&0&\ldots&0\big{]}\\ &\mathtt{Enc}\big{[}\phi^{\prime}\left(z_{[n][k]}\right)&\cdots&\phi^{\prime} \left(z_{[n][k]}\right)&0&\ldots&0\big{]}\\ &\mathtt{Enc}\big{[}x_{[1][0]}&\ldots&x_{[1][d]}&0&\ldots&0\big{]}\\ \end{array}\]

and

\[\begin{array}{ccccc}\frac{\mathrm{d}}{\mathrm{d}\mathsf{v}_{[k]}}L_{2}=\\ \mathtt{Enc}\big{[}s_{[1][k]}&s_{[1][k]}&\cdots&s_{[1][k]}&0&\ldots&0\big{]} \odot\mathtt{Enc}\big{[}1&\phi(z_{[1][1]})&\phi(z_{[1][2]})&\cdots&\phi(z_{[1 ][m]})&0&\ldots&0\big{]}\\ &\mathtt{+}\\ &\mathtt{Enc}\big{[}s_{[2][k]}&s_{[2][k]}&\ldots&s_{[2][k]}&0&\ldots&0\big{]} \odot\mathtt{Enc}\big{[}1&\phi(z_{[2][1]})&\phi(z_{[2][2]})&\cdots&\phi(z_{[2 ][m]})&0&\ldots&0\big{]}\\ &\mathtt{+}\\ &\mathtt{Enc}\big{[}x_{[1][0]}&\ldots&x_{[1][d]}&0&\ldots&0\big{]}\\ &\mathtt{Enc}\big{[}s_{[1][k]}&s_{[n][k]}&\ldots&s_{[n][k]}&0&\ldots&0\big{]} \odot\mathtt{Enc}\big{[}1&\phi(z_{[n][1]})&\phi(z_{[n][2]})&\cdots&\phi(z_{[n] [m]})&0&\ldots&0\big{]}.\end{array}\]

Since the Double Volley Revolver method only requires one of the two matrices to be transposed before encryption, and the expressions \(\frac{\mathrm{d}}{\mathrm{d}\mathsf{w}_{[k]}}L_{2}\) and \(\frac{\mathrm{d}}{\mathrm{d}\mathsf{v}_{[k]}}L_{2}\) happen to meet this requirement during matrix multiplication, we are able to carry out the homomorphic evaluation of the whole pipeline for
homomorphic 3-layer NN training: \(\mathrm{w}_{[k]}=\mathrm{w}_{[k]}-\eta\cdot\frac{\mathrm{d}}{\mathrm{d}\mathrm{w}_{ [k]}}L_{2}\) and \(\mathrm{v}_{[k]}=\mathrm{v}_{[k]}-\eta\cdot\frac{\mathrm{d}}{\mathrm{d}\mathrm{ v}_{[k]}}L_{2}\), where the learning rate \(\eta\) is set to \(0.01\).

\(L_{2}\) regularization, also referred to as Ridge Regression, introduces a penalty term proportional to the square of the model's parameters. This approach encourages the utilization of all parameters while minimizing their magnitudes, resulting in a less complex model that is less susceptible to overfitting. It is straightforward that \(L_{2}\) regularization can be used in this encoding method by initializing the \(\frac{\mathrm{d}}{\mathrm{d}\mathrm{w}_{[k]}}L_{2}\) and \(\frac{\mathrm{d}}{\mathrm{d}\mathrm{v}_{[k]}}L_{2}\) with their corresponding L2 gradient components:

\[\frac{\mathrm{d}}{\mathrm{d}\mathrm{w}_{[k]}}L_{2}= \lambda\cdot\mathtt{Enc}\left[w_{[k][0]}\quad w_{[k][1]}\quad \dots\quad w_{[k][d]}\quad 0\quad\dots\quad 0\right]+\cdots,\]

and

\[\frac{\mathrm{d}}{\mathrm{d}\mathrm{v}_{[k]}}L_{2}= \lambda\cdot\mathtt{Enc}\left[v_{[k][0]}\quad v_{[k][1]}\quad \dots\quad v_{[k][m]}\quad 0\quad\dots\quad 0\right]+\cdots,\]

where \(\lambda\) represents the \(L_{2}\) regularization parameter.

### For Regression Problems

The mean squared error (MSE) loss function can be used in conjunction with this encoding method for regression tasks. Interestingly, the special case of the \(L_{2}\) loss function for a dataset containing only a single class label has the same formulation as the MSE loss function.

### Approximated Activation Functions

The first variant of the SLE loss function requires approximated activation functions to replace the sigmoid function with polynomials. Various methods [10, 25] can be employed to accomplish this task. For example, both Python and MATLAB (Octave) offer a function called polyfit, which can be used to approximate functions with polynomials using the least-square approach.

In our implementation, the activation function in the hidden layer is simply set to the square function.

## 5 Experiments

The C++ source code required to carry out the experiments described in this section is openly accessible at: [https://github.com/petitioner/HE.NNtraining](https://github.com/petitioner/HE.NNtraining).

ImplementationWe implemented vanilla gradient descent using the \(L_{2}\) loss function, solely relying on homomorphic encryption (HE), with the HEAAN library. All the experiments involving ciphertexts were performed on a public cloud with \(64\) virtual CPUs and \(192\) GB of RAM.

We use the entire set of \(150\) Iris examples for training and employ a fixed learning rate of \(0.01\). The complete Iris dataset \(X\) and its corresponding one-hot encoded labels \(Y\) are encrypted into two distinct ciphertexts. Moreover, for each row of the weight matrices \(W\) and \(V\), we encrypt its multiple repetitions into a single ciphertext:
\(X\)\(\xrightarrow{\text{encoding \& encryption}}Enc\begin{bmatrix}x_{[1][0]}&x_{[1][1]}&\cdots&x_{[1][d] }\\ x_{[2][0]}&x_{[2][1]}&\cdots&x_{[2][d]}\\ \vdots&\vdots&\ddots&\vdots\\ x_{[m][0]}&x_{[m][1]}&\cdots&x_{[n][d]}\end{bmatrix},\)

\(Y\)\(\xrightarrow{\text{encoding \& encryption}}Enc\begin{bmatrix}y_{[1][1]}&y_{[1][2]}&\cdots&y_{[1][c]}\\ y_{[2][1]}&y_{[2][2]}&\cdots&y_{[2][c]}\\ \vdots&\vdots&\ddots&\vdots\\ y_{[n][1]}&y_{[n][2]}&\cdots&y_{[n][c]}\end{bmatrix},\)

\(W\)\(\xrightarrow{\text{encoding \& encryption}}Enc\begin{bmatrix}w_{[1][0]}&w_{[1][1]}&\cdots&w_{[1 ][d]}\\ w_{[1][0]}&w_{[1][1]}&\cdots&w_{[1][d]}\\ \vdots&\vdots&\ddots&\vdots\\ w_{[1][0]}&w_{[1][1]}&\cdots&w_{[1][d]}\end{bmatrix},\cdots,Enc\begin{bmatrix}w_{[m][ 0]}&w_{[m][1]}&\cdots&w_{[m][d]}\\ w_{[m][0]}&w_{[m][1]}&\cdots&w_{[m][d]}\\ \vdots&\vdots&\ddots&\vdots\\ w_{[m][0]}&w_{[m][1]}&\cdots&w_{[m][d]}\end{bmatrix},\)

\(V\)\(\xrightarrow{\text{encoding \& encryption}}Enc\begin{bmatrix}v_{[1][0]}&v_{[1][1]}&\cdots&v_{[1][m]}\\ v_{[1][0]}&v_{[1][1]}&\cdots&v_{[1][m]}\\ \vdots&\vdots&\ddots&\vdots\\ v_{[1][0]}&v_{[1][1]}&\cdots&v_{[1][m]}\end{bmatrix},\cdots,Enc\begin{bmatrix}v_{ [c][0]}&v_{[c][1]}&\cdots&v_{[c][m]}\\ v_{[c][0]}&v_{[c][1]}&\cdots&v_{[c][m]}\\ \vdots&\vdots&\ddots&\vdots\\ v_{[c][0]}&v_{[c][1]}&\cdots&v_{[c][m]}\end{bmatrix}.\)

We selected the following parameters for the HEAAN library: \(logN=16\), \(logQ=990\), \(logp=30\), \(slots=32768\), which collectively ensure a security level of \(\lambda=128\). For detailed information about these parameters, please refer to [23]. We did not employ bootstrapping to refresh the weight ciphertexts, which limits our algorithm to only perform \(2\) iterations. Each iteration takes approximately \(52\) minutes to complete. The maximum runtime memory usage under these conditions is around \(60\) GB. The dataset of 150 Iris examples is encrypted into a single ciphertext. In addition, the one-hot encoded labels \(Y\)are encrypted into a single ciphertext. The weight matrix \(W\) is encrypted into \(120\) ciphertexts, with each ciphertext encrypting multiple repetitions of each row. We initialized the weight matrices \(W\) and \(V\) with a normal distribution having a mean of \(0.0\) and a standard deviation of \(0.05\).

## 6 Conclusion

In this work, we implemented privacy-preserving 3-layer NN training using solely homomorphic encryption (HE) techniques. However, the current low-level encoding method within the framework of Double Volley Revolver is not well-suited for incorporating bootstrapping. Further research is necessary to investigate the integration of bootstrapping into our approach using an alternative low-level implementation.
