
Privacy-Preserving Text Classification on BERT Embeddings
with Homomorphic Encryption
Garam Lee*1 Minsoo Kim*2 Jai Hyun Park*2
Seung-won Hwang†2 Jung Hee Cheon1,2
1CryptoLab 2Seoul National University
garamlee@cryptolab.co.kr
{minsoo9574, jhyunp, seungwonh, jhcheon}@snu.ac.kr
Abstract
Embeddings, which compress informa-
tion in raw text into semantics-preserving
low-dimensional vectors, have been widely
adopted for their efficacy. However, recent
research has shown that embeddings can
potentially leak private information about
sensitive attributes of the text, and in some
cases, can be inverted to recover the original
input text. To address these growing privacy
challenges, we propose a privatization mecha-
nism for embeddings based on homomorphic
encryption, to prevent potential leakage of
any piece of information in the process of
text classification. In particular, our method
performs text classification on the encryption
of embeddings from state-of-the-art models
like BERT, supported by an efficient GPU
implementation of CKKS encryption scheme.
We show that our method offers encrypted
protection of BERT embeddings, while largely
preserving their utility on downstream text
classification tasks.
1 Introduction
In recent years, the increasingly wide adoption of
vector-based representations of text such as BERT,
eLMo, and GPT (Devlin et al.,2019;Peters et al.,
2018;Radford et al.,2019), has called attention
to the privacy ramifications of embedding mod-
els. For example, Coavoux et al. (2018); Li et al.
(2018) show that sensitive information such as the
authors’ gender and age can be partially recovered
from an embedded representation of text. Song
and Raghunathan (2020) report that BERT-based
sentence embeddings can be inverted to recover up
to 50%–70% of the input words.
Previously proposed solutions such as
dχ
-
privacy, a relaxed variant of local differential pri-
vacy based on perturbation/noise (Qu et al.,2021),
require manually controlling the noise injected into
*Equal contribution.
†Corresponding author.
embeddings, to control the privacy-utility trade-off
to a level suitable for each downstream task. In
this work, we propose a privacy solution based on
Approximate Homomorphic Encryption, which is
able to achieve little to no accuracy loss of BERT
embeddings on text classification
1
, while ensuring
a desired level of encrypted protection, i.e. 128-bit
security.
Homomorphic Encryption (HE) is a crypto-
graphic primitive that serves computations over en-
crypted data without any decryption process. While
previous works have focused on homomorphic
computation where the inputs are numerical data,
in applications such as privacy-preserving machine
learning algorithms (Lauter,2021), logistic regres-
sion (Kim et al.,2018), and neural network infer-
ence (Gilad-Bachrach et al.,2016), they have rarely
been applied to unstructured data such as text. Re-
cent works in this direction include Podschwadt
and Takabi (2020), who conduct sentiment clas-
sification over encrypted word embeddings using
RNN. However, they use a simple embedding layer
which maps words in a dictionary to real-valued
vectors, and model training is only supported on
plaintext. The most closely related work to ours is
PrivFT (Badawi et al.,2020), a homomorphic en-
cryption based method for privacy preserving text
classification built on fastText (Joulin et al.,2017).
We next describe our approach, focusing on our
distinctions from PrivFT:
•BERT Embedding-based Method
: The princi-
ple behind PrivFT is to perform all neural network
computations in encrypted state. For this purpose,
it adopts fastText (Joulin et al.,2017), which takes
bag-of-words vectors as input, followed by a two-
layer network and an embedding layer. However,
PrivFT does not utilize pre-training; as a conse-
quence, the embedding matrix and classifer of
PrivFT must be updated from scratch, taking sev-
eral days to train on a single dataset.
1
Code and data are available at:
https://www.
github.com/mnskim/hebert
arXiv:2210.02574v1 [cs.CL] 5 Oct 2022