Private Text Classification with Convolutional Neural Networks (2021)

Abstract: Text classifiers are regularly applied to personal texts, leaving users of these classifiers vulnerable to privacy breaches. We propose a solution for privacy-preserving text classification that is based on Convolutional Neural Networks (CNNs) and Secure Multiparty Computation (MPC). Our method enables the inference of a class label for a personal text in such a way that (1) the owner of the personal text does not have to disclose their text to anyone in an unencrypted manner, and (2) the owner of the text classifier does not have to reveal the trained model parameters to the text owner or to anyone else. To demonstrate the feasibility of our protocol for practical private text classification, we implemented it in the PyTorch-based MPC framework CrypTen, using a well-known additive secret sharing scheme in the honest-but-curious setting. We test the runtime of our privacy-preserving text classifier, which is fast enough to be used in practice.

## introduction text classification is inherently a two-party computation problem between the owner of a text classifier and the owner of a personal text. text classifiers are used for a wide variety of purposes, such as detection of spam and misinformation, sentiment analysis, tailored advertising, surveillance, etc. in these applications, the text classifier is often owned by a company or organization who wants to keep their model private because it offers a competitive advantage and/or it was trained on a proprietary dataset. deep learning models in particular are powerful enough to memorize specific examples from the training data @xcite , hence disclosing a trained model can leak very specific information about training data. furthermore, in applications such as spam or misinformation detection, disclosing the model would help adversaries to develop strategies for evading detection. the common practice nowadays is therefore for the owner of the personal text to disclose their text to the company or application developer. this in turn also raises serious privacy concerns, stemming from misuse of the data by the company for purposes beyond the originally professed scope. furthermore, while most companies make reasonable efforts to keep data private, the data itself is a valuable asset that is routinely sold when companies undergo bankruptcy and/or it can become subject of accidental or intentional public exposure @xcite @xcite . data breaches and intentional misuse of data have given rise to new laws and regulations, such as the european general data protection regulation (gdpr) and the california consumer privacy act (ccpa), and, orthogonal to this, the use of privacyenhancing technologies (pets) for the development of algorithms that do not leak personal information about their inputs, thereby protecting the privacy of all the users involved. in this paper we propose such an algorithm for private text classification that, as illustrated in fig. 1 , allows the owner of a personal text (bob) to infer a label using alice's text classifier, without requiring bob to disclose anything about his text in an unencrypted manner to alice, and without requiring alice to show her trained model parameters to anyone. to this end, we use secure multiparty computation (mpc) @xcite , an umbrella term for cryptographic approaches that allow two or more parties to jointly compute a specified output (the class label) from their private information (the classifier and the personal text) in a distributed fashion, without revealing the private information to each other. initial solutions for private classification of unstructured text with mpc have been proposed for logistic regression models and tree based models @xcite , and for naive bayes classifiers @xcite . all of this existing work relies on an mpc subprotocol for private feature extraction, in which a boolean word occurrence figure 1 : private text classification process vector is created that indicates which words from alice's predefined vocabulary occur in bob's text. in contrast with this, and in line with the fact that deep learning is current state-of-the-art for many tasks in natural language processing (nlp), we propose to perform mpc-based private text classification with a convolutional neural network (cnn) that has been trained to extract relevant features automatically. to the best of our knowledge this has not been explored yet in the literature. the mpc protocols for text classification with cnns that we use in this paper, are very similar to existing mpc protocols for image classification with cnns @xcite @xcite @xcite . the main distinguishing aspect is that image classification is based on 2-dimensional (2d) cnns, while for text classification it is common to use 1-dimensional (1d) cnns in which the filters move in only one direction. existing mpc protocols for inference with 2d cnns can be straightforwardly adjusted to 1d cnns. our main contribution is therefore in designing the first application of mpc protocols for cnn-based text classification, and in particular in addressing a question that has remained open in the literature thus far, namely to what extent such provably secure protocols can enable accurate and fast text classification. among deep learning architectures, our choice for cnns is deliberate. cnns have been successfully applied for text classification @xcite and offer the important advantage of being computationally less intensive than long short-term memory (lstm) networks or other state-of-theart architectures. as such, cnns are an excellent "mpc-friendly" starting point to explore deep learning based private text classification. in sec. 2 we describe a multi-channel cnn architecture that we designed for sentiment analysis of product reviews. the trained cnn f is owned by alice in fig. 1 . in sec. 4 we present results obtained with an implementation of π text in crypten @xcite , a recently proposed mpc framework built upon pytorch. crypten realizes mpc through a well-known additive secret sharing scheme (see sec. 3) that guards against honest-but-curious adversaries. a party corrupted by such an adversary still follows the instructions of the mpc protocol but attempts to learn information about the data from the intermediate values and communications between the parties. a correctly designed mpc protocol (as π text ) prevents such attacks from being successful. to implement π text , we adapted and extended existing functionality for private image classification in crypten to text classification with 1-dimensional (1d) convolutional layers and 1d max pooling. our results in tab. 2 demonstrate the practicality of π t ext as the runtimes are low enough to be used in practice. the data consists of product reviews for software offered on amazon's storefront. there are 132,084 reviews total, each with an associated star rating ranging from one to five (see tab. 1 ). the average length of a review is 63.6 words. we split the data into 80% for training and 20% for validation, using a stratified split to ensure the distribution of the star ratings is identical in both sets. as described below, we trained a binary classifier for sentiment analysis over this dataset, treating reviews with star @xmath0, and the rest as negative. we note that, with reproducibility of results in mind, we used a publicly available dataset. during deployment of our private text classification solution, it can be replaced by proprietary text data. model architecture. the text classifier consists of two parts: a public sentence transformer and the private cnn belonging to alice. the sentence transformer we employ is stsb-distilbert-base (reimers and gurevych, 2019), a model fine-tuned to produce sentence vectors. this takes as input the raw text and outputs a 768 dimensional embedding vector. as this transformer is public, bob can also use the sentence transformer to prepare his data for classification by alice's model. alice's model consists of three parallel series of convolution and pooling layers, followed by fully-connected layers, ending in a sigmoid activated classification layer (see fig. 2 ). this model is then trained with a learning rate of 0.002 with a batch size of 50, and loss is calculated using cross entropy. a dropout of 0.25 is added to the concatenation layer. the trained model obtains 85% accuracy on the validation data. in the additive secret sharing mpc scheme that we use, all computations are done on integers modulo q, i.e., in a ring z @xmath1, 1, . . . , q -1}. to map real numbers, such as the trained cnn model parameters, into this ring, we use a fixed point representation with 16 bits of precision for the mantissa. a value x is secret-shared over z q between parties alice and bob by picking x a , x @xmath2, and then revealing x a to alice and x b to bob. we denote this secret sharing by @xcite ], which can be thought of as a shorthand for (x a , x b ). secret-sharing based mpc works by first having the parties split their respective data in secret shares and send some of these shares to each other. to any individual party, their shares of x look like random noise. only when all of the shares are combined together is the true value of x revealed. when alice and bob have secret-shared numbers @xcite ] and [[y]], they can straightforwardly compute @xcite ] by adding their own shares. to compute [[x • y]], alice and bob run a secure multiplication protocol π mul that requires communication between the parties, using a well-known technique with beaver triples @xcite . these triples can be generated by a trusted initializer (ti) that distributes correlated randomness to alice and bob and otherwise does not participate in the computations at all. this is the technique used in crypten @xcite ) and adopted in the experiments in sec. 4. such a ti can be thought of as a third party, next to alice and bob, making the setting used in our experiments effectively a three-party configuration. in case a ti is not available or desirable, the required triples can be pre-computed by alice and bob in an online phase using an mpc protocol to emulate the ti @xcite ; this method is currently not yet supported in crypten. building on the cryptographic primitives for addition and multiplication, mpc protocols for other operations have been developed in the literature, many of which we use in turn to build our protocol π text . of note is the secure comparison protocol π comp , which works by computing the difference of two secret-shared numbers @xcite ] and [[y]] and extracting the most significant bit, effectively returning [[1]] if @xmath3, and [[0]] otherwise (more details in @xcite ). mpc protocol π text . at the start of the protocol for private text classification, alice has a cnn model with trained model parameters f , and bob has an embedding vector d of his text obtained after preprocessing. ## results we implemented π text in crypten, taking advantage of crypten's architecture, which allows to overwrite torch functions with mpc protocols. all subprotocols needed for π text already existed in the branch crypten-v0.1, barring the π conv1d and π m axp ool1d protocols. we ported π conv1d from the master branch of crypten, and we constructed π m axp ool1d ourselves. in our tests, using π sigmoid to approximate the sigmoid function made no statistically significant impact on the accuracies. on a test set containing 20,417 instances, using π sigmoid resulted in 17,351 correct classifications, whereas its plaintext counterpart provided 17,350 correct classifications, i.e. an accuracy of 85% across the line. in other words, our use of mpc does not cause accuracy loss. the code we used to run our tests is located on our fork of the crypten repository, foot_1 on the branch "crypten-v0.1". for our tests, we set up three vms on azure, namely one for alice, one for bob, and one for the ti. the vms are standard l16s_v2, with 16 vc-pus, 128 gib memory, and an expected network bandwidth of 6400 mbps. in our experiments, despite having access to large amounts of memory, the parties never used more than 5 gib at a time. the ti never sees alice's or bob's data. since the ti's activities are independent of the data that is used as input for the mpc protocols, mpc protocols can be separated in an off-line phase -during which the ti generates correlated randomness and distributes it to alice and bob -and an online l16s: private text classifier runtimes # instances sequential (sec) batched (sec) 200 151 21 400 296 44 600 445 65 800 596 88 1000 734 110 ## conclusion and future work we have presented and evaluated the first application of mpc-based privacy-preserving text classification with cnns. our solution involves model owner alice, who has a multi-channel cnn for text classification, and text owner bob who transforms his text into an embedding vector using a publicly available bert model. next alice and bob secret share their inputs and run an mpc protocol to label bob's text with alice's model in a provably privacypreserving manner. our protocol takes ∼ 0.74 sec to classify a text when run in sequential mode, and ∼ 0.11 sec when run in batch mode on standard l16s_v2 azure virtual machines with an expected bandwidth of 6400 mbps. these runtimes are independent of the length of the text, as the embedding vector has a fixed length. our work serves as a baseline for mpc-based text classification with deep learning that can be improved upon in many ways. from an nlp point of view, we have assumed that bob can preprocess his text based on public knowledge, in particular with a sentence transformer model that is in no way dependent on alice's training data or model parameters. while many text preprocessing algorithms are standard and publicly available to all parties (e.g. for stemming, tokenization, etc.), others may involve proprietary information. pre-trained versions of language representation models that are publicly available can for instance be fine-tuned by model builders (such as alice) on task specific data, leading to proprietary word or sentence embedding models that the model owners would not want to disclose. the development of effective and efficient mpc protocols for converting raw text into embedding vectors with state-of-the-art transformer architectures is an open problem. from a security perspective, there exist a variety of mpc schemes beyond the one we considered in this paper, designed for different numbers of parties and offering various level of security that correspond to different threat models and come with different computational costs. regarding threat models, besides honest-but-curious adversaries, there exist mpc schemes that protect against malicious adversaries that corrupt parties to deviate from the protocol instructions. regarding the number of parties, some of the most efficient mpc schemes have been developed for three computing servers, out of which at most one is corrupted (i.e. honest majority) by an honest-but-curious or a malicious adversary. while text classification is inherently a (dishonest majority) two-party computation problem between the model owner alice and the text owner bob, mlaas (machine learning as a service) set-ups in which alice and bob secret share with, and outsource the computations to, three servers in the cloud are growing in popularity in the privacypreserving ml literature because of their efficiency @xcite @xcite @xcite . the use of these different mpc schemes for privacy-preserving text classification is an interesting direction for future work.