{'fraction_non_alphanumeric': 0.027896352879502734, 'fraction_numerical': 0.00662772410694226, 'mean_word_length': 4.717619353457504, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Generative Poisoning Attack Method Against Neural Networks

Poisoning attack is identified as a severe security threat to machine learning algorithms. In many applications, for example, deep neural network (DNN) models collect public data as the inputs to perform re-training, where the input data can be poisoned. Although poisoning attack against support vector machines (SVM) has been extensively studied before, there is still very limited knowledge about how such attack can be implemented on neural networks (NN), especially DNNs. In this work, we first examine the possibility of applying traditional gradient-based method (named as the direct gradient method) to generate poisoned data against NNs by leveraging the gradient of the target model w.r.t. the normal data. We then propose a generative method to accelerate the generation rate of the poisoned data: an auto-encoder (generator) used to generate poisoned data is updated by a reward function of the loss, and the target NN model (discriminator) receives the poisoned data to calculate the loss w.r.t. the normal data. Our experiment results show that the generative method can speed up the poisoned data generation rate by up to 239.38x compared with the direct gradient method, with slightly lower model accuracy degradation. A countermeasure is also designed to detect such poisoning attack methods by checking the loss of the target model.


I. INTRODUCTION
Machine learning has been widely used in information processing to help users understand the underlying property of the data. The example applications include image classification and recognition, feature extraction, language processing, video analysis and etc. As one of the major types of machine learning models, NN processes input data by multiplying them with layers of weighted connections. NNs have been deployed to a large variety of embedded systems to offer machine intelligence, where the NNs need to collect input data to perform re-training. For example, a small-footprint large vocabulary speech recognizer for mobile devices [12], a small robust deep-learning model designed to provide high quality text-to-speech functionality on smart devices [3], and an audio sensing framework built from coupled DNNs [4]. Such applications, however, introduce at least two types of security issues -causative attack and exploratory attack [1], [8].
Exploratory attack does not change the parameters of the target model. Instead, the attacker sends new data to the target model and observes the model's decisions on these carefully crafted input data. One recent example of exploratory attack is adversarial example [15], [7]. The authors show that DNN can be fooled by adding small perturbations onto the inputs even though these perturbed inputs can still be easily recognized by humans. No parameters of the NN are changed during the attack. Another recently proposed exploratory attack scheme leverages the model's transfer learning ability to replicate the target model without the prior knowledge of its parameters and structure [17].
On the contrary, causative attack allows attackers to manipulate training dataset in order to change the parameters of the target model and reconstruct it. One important type of causative attack is poisoning attack where artificially poisoned data are sent into the target model with attacking labels. The target model then updates itself with the poisoned data and gradually compromises. Several schemes have been proposed to conduct poisoning attack against SVMs [2], [16]. However, we have not seen many works about poisoning attacks against NNs. One possible reason may come from the vague mathematic understanding of NN. In a NN, for example, there is no explicit direct expression of gradient calculation as the gradients are updated during backpropagation. This fact prevents gradient-based poisoning attack from being deployed in NNs where the second partial derivative needs to be calculated.
In this work, we first examine the possibility of applying traditional gradient-based direct gradient method to generate the poisoned data against NN. We then propose a generative method to speed up the generation rate of the poisoned data by bypassing the gradient calculation, which is the bottleneck in the direct gradient method. The proposed scheme is partially inspired by the concept of Generative Adversarial Network (GAN) [6]: An autoencoder (generator) is used to generate the poisoned data and updated by a reward function of loss, and then sends the poisoned data to a discriminator. The target NN model (discriminator) receives the poisoned data and calculates the loss w.r.t. the normal data, and then sends the calculated gradients back to the generator. We also design a reward function and a strategy of sending back the gradients. Different from a traditional method that periodically checks the accuracy of the model [13], we also propose a lossbased method to detect poisoning attack with much lower computation overhead. The proposed countermeasure is based on the fact that a normal input only introduces a small loss since it is close to the original decision region, while a poisoned input usually incurs a large loss as it is far away from this region. Hence, we are able to distinguish the types of the input by checking this loss difference.
Our major contributions can be summarized as: • We examine traditional gradient-based poisoning attack on NN and identify the poisoned data generation rate as the bottleneck of its implementation; • Based on our examination, we propose a generative method to substantially speed up the poisoned data generation rate with slightly degraded model attack effectiveness, i.e., target model accuracy degradation; • We proposed a loss-based countermeasure to detect the poisoning attack with very minimum overhead; • The effectiveness of the proposed schemes are extensively evaluated by performing experiments on MNIST and CIFAR-10 datasets under different configurations.

II. RELATED WORK
The security attacks against learning algorithms can be mainly categorized into two types: exploratory attack (exploitation of the classifier) and causative attack (manipulation of training data) [1], [8] Poisoning attack belongs to the latter type and has been investigated in many prior arts.
One of the earliest studies on poisoning attack was performed on design of anomaly detector [14]. The author showed how an attacker can substantially increase his chance to evade the detection by only introducing moderate amounts of poisoned data to the detector. A PCA-based detector was also proposed based on the fact that poisoning attack significantly distorts the model produced by the original PCA method. A similar work was presented in [9].
There are many existing works about poisoning attack against SVM, thanks to its clear mathematic basis. In [2], the author proposed a gradient ascent strategy in which the gradients are computed based on properties of the SVM's optimal solution. In learning algorithms, gradient calculation is the basis of many optimization problems, such as the training of NNs using gradient backpropagation. It also inspired the schemes proposed in our work. In [16], the author studied optimizations of label flipping attack -another version of poisoning attack. Label flipping attack is interpreted as a linear programming problem, which can be solved by approximating the original problem with a simpler problem. Although the demonstrated solutions are effective, their applications may be limited due to the specific target model.
A systematic, algorithm-independent poisoning attack approach was presented in [13]. The proposed attack procedure is able to generate the poisoned input data based on only the distribution of training data. However, the author gives neither the proof of why the method works nor how to ensure the effectiveness of the proposed approach.

III. POISONING ATTACK AGAINST NEURAL NETWORKS A. Notations
In this manuscript, we use x i and x p to denote the normal data and the poisoned data, respectively. Here, the subscripts i and p indicate the variables of the normal data and the poisoned data, respectively. We also use superscripts (o) and (p) to indicate the variables of the original model and the poisoned model, respectively. For example, L k denotes only the parameters of layer k. ϕ() is the activation function, e.g., hyperbolic tangent (Tanh) or rectified linear unit (ReLU).

B. The Attacking Process
Causative attack allows an attacker to arbitrarily manipulate the input dataset of the model, such as adding, changing, and removing some of the input data. As one type of causative attack, we assume that poisoning attack allows the attacker to insert arbitrary data x p with artificial label t p into the training dataset.
Here we assume the attacker has already known the details of the original NN model, including the network structure and the exact weight values. Although the attacker may not directly modify the model, he may still be able to poison the input training data to compromise the model, i.e., to degrade the model's accuracy.
Assuming we already have a method to generate the poisoned data, the poisoning attack process can be formulated as below: Step 1: Generate the poisoned data x p using the given method; Step 2: Inject x p into the original model w (o) to produce w (p) ; Step 3: Send the normal data x i into w (p) to get some useful information, e.g., loss and gradients from different time stamps; Step 4: Based on the information obtained in Step 3, update the configurations and parameters of the method of poisoned data generation; Step 5: Repeat the procedure from Step 1.

C. The Data Gradient and Direct Gradient Method
The goal of poisoning attack is to minimize the accuracy of the target model w (o) by injecting poisoned data x p . Mathematically, this goal is the same as maximizing the loss of the model w.r.t. the normal data x i . When the target model adopts the mean square error (MSE) or cross entropy as its loss function, the goal of poisoning attack can be respectively represented by where t i is the label corresponding to x i .
As indicated in Eqs. (1) and (2), the maximum feasible solution in the loss space can be obtained by calculating gradients w.r.t. x p and adopting the gradient ascent procedure. In this subsection, we will show the mathematical deduction of these gradients in NNs, regardless of the actual loss function. The procedure is depicted in Figure 1.
Next, the poisoned data x p and its corresponding label t p are injected. There are many ways to choose the initial x p , e.g., sampling from a uniform distribution with an arbitrary label or randomly choosing from one of the normal data with an incorrect label (e.g., the label that to be attacked). We then calculate the loss L (o) p , update the network to w (p) through backpropagation with the newly calculated gradients, and obtain the loss L (p) i as: Finally, we need to calculate the derivative of the sum of L ∂xp , and then update the poisoned data along the direction of the gradient using a pre-determined coefficient ∂xp can be expanded using the chain rule and expressed as the multiplication of multiple derivatives, such as Here δ (i) k represents the sensitivity of the neurons in layer k to the loss. o represents the output of the neurons in layer k. • is the Hadamard product.
The term is a second partial derivative. However, it it difficult to calculate this term with an explicit formula or a backpropagation-alike method because both the first derivatives p ∂xp are complex functions of each other.

Algorithm 1 Direct gradient method.
Input: Training dataset Dt, validation dataset Dv, attacking class tp, generating rate α, threshold of loss L th . Preprocess: 1. Initialize and train the network w (o) with normal training data xi in Dt. Choose an initial poisoned data from Dt as xp(0) and change its label to Ta. Reset the round number t = 0 and the initial loss L (p) Instead of calculating from Eq. (7)-(10), we propose to directly compute based on its definition. Algorithm 1 summarizes the poisoned data generation process of the direct gradient method that is based on our proposed Here the attacker is provided with a training dataset to generate the target model and the poisoned data. The attacker is also provided with a validation dataset for testing. The selection of the initial poisoned data will be discussed in Section IV in details. The key of our proposed algorithm is to respectively calculate the gradient w.r.t. each element of x p , which will be summed up to a combined gradient L (p) i xp . As a result, x p is updated by multiplying the direction of the gradient, i.e., sign( L (p) i xp ), with a coefficient α. The change rate α can be fixed at a pre-determined value (e.g., α = 0.1) or adaptively change in the process.
As we shall present in Section IV, the poisoned data generated by direct gradient method can effectively degrade the accuracy of the target model. However, the data generation can be very time-consuming because of the element-wise gradient calculation. Very importantly, the computation cost of the poisoned data generation in direct gradient method is proportional to the dimension of the input data and the complexity of the target model. Hence, the scalability of direct gradient method may be a severe issue, especially considering the rapid growth of the sizes of the popular NNs and their training datasets.

D. A Generative Method to Accelerate Poisoned Data Generation
Inspired by the concept of GAN [15], we propose a generative method which can bypass the costly gradient calculation and therefore speed up the poisoned data generation.The key of our method is to train an extra model to generate x p . The gradients of the target model (the first derivative derivation) are sent to the extra model and update the model (another first derivative derivation) in order to generate the new x p . Therefore, the second partial derivative is implicitly calculated. We name the original target model as discriminator (D) and the extra model as generator (G). In this work, we choose a general autoencoder as our generator. As a feature extractor, the autoencoder understands the fundamental ingredient of the original pattern, thus changes it from a smaller (compressed) dimension compared with the original one. The gradients and loss from the discriminator will be collected and calculated to guide the training of the generator. Figure 2 illustrates the overview of the proposed generative method for poisoned data generation. The generator is used to generate poisoned data and updated by a weighted function of the loss and the gradients, and then sends the poisoned data to the discriminator. The discriminator receives the poisoned data and calculates the loss w.r.t. the normal data, and then sends the calculated gradients back to the generator. The structure of the generator is designed as 784-200-200-784 for MNIST dataset, which will be adopted in some experiments in Section IV.
Algorithm 2 formulates the detailed steps of the generative method. We assume the same prerequisites of the direct gradient method are provided for the attacker, except for a pre-trained autoencoder serving as a generator. The initial data is sent into the generator in the first step to generate poisoned data, which is then injected to the target model. The gradients of the target model w.r.t. the normal data ∂L (p) i ∂xi are collected, and the obtained weighted gradients are used to update the generator. In this way, we no longer have to calculate the direct gradients L (p) i xp element-wisely and only one update of target model is needed in each iteration. As a result, the time consumption of poisoned data generation is greatly reduced, especially when the target model is complex. i (t) and the gradients i (t − 1)); 5. Update the poisoned data xp(t) to xp(t + 1) via G; One critical problem here is how to design the gradients for the generator. We propose to use the difference of two losses from two consecutive attacks to build a reward function. Combing this difference with the gradients of the target model w.r.t. the normal data, we can obtain a weighted gradient for the generator. The reward function suggests if this update is a good one while the gradients of the target model determines the detailed directions of the weighted gradient. If the update is not a good one, it will be punished.

E. The Loss-based Countermeasure against Poisoning Attack
Moreover, we propose an universal method to detect the aforementioned poisoning attack methods, which is shown in Algorithm 3. Once a data (no matter normal or poisoned) is injected into the target model, the loss of the target model is recorded. If the loss exceeds the pre-determined threshold L th , a warning will show up. If the number of warnings exceeds the threshold W th , the accuracy check will be triggered to examine if a poisoning attack is indeed being conducted. Our method is based on the phenomenon that the poisoned input and label pair usually results in a larger loss, compared with the normal one. This is naturally understandable as the goal of poisoning attack is to minimize the model accuracy, which is realized through maximizing the loss. The poisoned data alters target model's original decision boundary. On the contrary, normal data stays inside the decision region (at least most of time), inducing a relatively smaller loss. We are able to monitor the condition of inputs by checking the loss periodically. This approach, hence, is much computational less extensively.

IV. EXPERIMENT RESULTS
We examine the poisoned data generation process on two datasets -MNIST [11] and CIFAR-10 [10]. We compare the target model accuracy degradation and the time consumption of the direct gradient and the generative attack methods. We also evaluate the feasibility of the loss-based countermeasure

A. The Effectiveness of Poisoning Attacks Against NN
Two widely used datasets, MNIST and CIFAR-10, are used to evaluate the effectiveness of the proposed poisoning attack method. We choose MXNet [5] as our deep learning library. The target model for MNIST is a two-layer feed-forward neural network with a structure of 784-64-10. Its original recognition accuracy is 96.82%. We use Lenet [11] that consists of two convolutional layers and two fully-connected layers as the target model for CIFAR-10, of which the original accuracy is 71.20%. We did not stress the fine-tuning when obtaining these original target models, as the phenomenon of the poisoning attack requires continuous model re-training. To better demonstrate the data generation process, we conduct the single poisoning attack, that is, injecting one poisoned data per attack. Figure 3 demonstrates a few poisoned data generation processes of selected sample images. Starting from a normal initial data follows the intuitive thinking -setting the label of a normal data to an incorrect class could compromise the model by making it learn in a wrong way. Figure 3(a) applies the direct gradient method to a normal digit 5 image in MNIST with a wrong label 6. As the impact from gradients accumulates, the generated poisoned image gradually transforms to a pattern alike "5" until convergence. Figure 3(b) starts from a random data sampling from a uniform distribution with label 6, where the direct gradient method is used. It serves as a control experiment to understand if any preference in the poisoned data generation. It is interesting that the random data ends as a fuzzy image close to "6". The observation is different from our initial thought that the converged pattern should be very unlike the attacking class, i.e., "6" in this example. This could possibly be explained as a pattern with a similar structure but very different features to the normal one will compromise the learning process the most.   Figure 3(c), the generative method shows a similar result as the direct gradient method. It is hard to identify the exact converged pattern of the bird image labeled as cat from CIFAR-10. This is because the data in CIFAR-10 has a much larger dimension than MNIST's (3,072 vs. 784).
The direct gradient method leverages the loss of the poisoned model w.r.t. the normal data L (p) i . Therefore, the group size of the normal data (or, group size) that is used to calculate L (p) i has a strong influence on the convergence speed of the poison data generation and thus the attack effectiveness. More specific, large group size provides a more general consideration of the entire dataset, alleviating the impact of some particular data. The typical group size is 100 in this work. 10 and 1000 are used as references. Figure 4 shows detailed comparisons of the group size and the initial data selection for MNIST dataset. The blue lines represent the accuracy of the poisoned model and the red line denotes the average loss of the model w.r.t. the normal data group. As can be seen from the figures, the loss increase and the accuracy degradation of the normal initial data (solid lines) are much faster than the trend of random initial data (dashed lines). The results imply that normal initial data is a better choice than the random one.
In the figure, the first point of a line refers to the result of the original target model, while the second point corresponds to that of the model poisoned by the initial data. The performance degradation at the second point indicates that normal or random initial data could comprise the target model, but the effectiveness is far from enough. For example, the accuracy of the second iteration is ∼70% when the group size is 100.
Comparing the accuracy degradations in three sub-figures, we note that the curve obtained from a larger group size is more stable than that of a smaller group size. When starting from a random data, the larger group size also results in smaller converged accuracy. Generally speaking, a larger group size has a better attack effectiveness but also introduces more computation overhead. Detailed performance comparison shall be presented and discussed in Section IV-B. The normal initial data of the small target model designed for MINIST dataset converges at ∼10%. In reality, regularly continuous re-training process for a neural network in a much larger scale could alleviate the attack. So we may not obtain such a significant accuracy degradation in the poisoning attack. Even though, the results prove the effectiveness of our proposed methods and suggest potential study prospect.

B. Direct Gradient vs. Generative Methods
We compare the direct gradient and the generative methods for the two datasets with the normal initial data, under three group size settings (1000, 100, 10). Here, the structure of the autoencoder used as the generator for MNIST is 784-200-200-784. The generator for CIFAR-10 is a deeper fullyconnected autoencoder with 6 layers. Table I summarizes the comparison in terms of the average time to generate one poisoned data (TIME), the least accuracy achieved by the target model (ACCURACY), and the largest average normal data loss achieved of the data group (LOSS). The improvement of the generative method over the direct gradient method (faster time, lower accuracy, and higher loss) are also presented in the table.
The best result of each metric under each dataset is marked as bold.
According to the table, the direct gradient method costs more time than the generative method especially as the group size increases. For MNIST dataset, the generative method converges at a higher accuracy (i.e., the worst case is 16.59% vs. 8.84%) which is still in a reasonable range. This phenomenon is due to the fact that we use a small network on a small dataset, and the accuracy degradation converges too fast for generative method. For the bigger dataset CIFAR-10, the two methods show the similar accuracy levels. It implies that the generative method has a better scalability and works better for larger neural networks. Moreover, the time cost of the direct gradient method has a strong dependency on the group size while it is not observed in the generative method. In summary, the generative method is more effective and expects to have a great potential in poisoning attacking larger neural network models and bigger datasets.

C. Evaluating The Proposed Poisoning Attack Detection
As mentioned in Section III, poisoned data deviates the decision boundary of the target model and aggravate its loss. Hence, periodically monitoring the loss anomaly appears to be an effective way of detecting poisoning attack. For the MNIST dataset, we measure the difference between the normal loss and the loss introduced by poisoning attack (or, poisoned loss) and show the result in Figure 5. The horizontal axis represents different randomly selected input data with artificial labels. The vertical axis denotes the normalized loss incurred by retraining the target model on these data. Each point on the vertical axis is bind with the above two losses. A clear gap exists between the least poisoned loss and the largest normal loss. This is even true if we choose the input data from a uniform distribution which is the worst case without human interference. The result proves the feasibility of our proposed poisoning attack detection method.
Moreover, the loss of the target model is usually calculated during re-training. Implementing the proposed poisoning attack detection technique in Algorithm 3, therefore, requires marginal extra computation and hardware overheads. It is impossible to completely prevent poisoning attack since no one can learn right from wrong. However, we could extend the monitor mechanism to other parameters and criteria of the model to provide a fast alarm system which can invoke the poisoning attack detection in time.

V. CONCLUSION
In this paper, we study the general process of poisoned data generation for neural networks (NNs). We propose two poisoning attack methods against NNs, including a direct gradient method and a generative method. We also develop a preliminary countermeasure that performs a loss-based poisoning attack detection. Experiments on MNIST and CIFAR-10 show that the generative method can substantially improve the poisoned data generation rate compared with the direct gradient method. Particularly the former one demonstrates great potential in attacking large neural network models and big datasets. Our future work will focus on designing a better generator and gradient policy that can achieve both improved poisoned data generation rate and model attack effectiveness.