A method for generating adversarial examples for black-box recurrent neural networks

By extracting weighted finite automata and constructing a proxy model, the problem of low success rate of adversarial sample generation and high interrogation cost of black-box recurrent neural network is solved, achieving more efficient adversarial sample generation and reducing interrogation cost.

CN114036296BActive Publication Date: 2024-10-15PEKING UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202111339035.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-11-12
Publication Date
2024-10-15
Estimated Expiration
2041-11-12

AI Technical Summary

Technical Problem

The existing technology has a low success rate and low efficiency when generating black-box recurrent neural network adversarial samples, and the query cost is high in machine learning as a service scenarios, and it cannot effectively handle neural networks with complex alphabets or state spaces.

Method used

By extracting weighted finite automata, a proxy model is constructed to guide the generation of adversarial examples, clustering algorithms and n-state synthesis strategies are used to obtain discrete state sets, and fitness functions are designed to improve the success rate and efficiency of adversarial example generation.

Benefits of technology

It improves the success rate and efficiency of adversarial sample generation and reduces query costs. Especially in natural language tasks, the query cost is reduced by 92.7% compared to directly based on the original recurrent neural network.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure BDA0003351735530000041
    Figure BDA0003351735530000041
  • Figure BDA0003351735530000071
    Figure BDA0003351735530000071
  • Figure BDA0003351735530000123
    Figure BDA0003351735530000123
Patent Text Reader

Abstract

The present invention relates to the technical field of analysis and interpretation of recurrent neural networks, and to natural language processing, and provides a method for generating adversarial samples of a black-box recurrent neural network, comprising the following steps: extracting a weighted finite automaton, initializing a candidate sample set, predicting data, calculating a fitness value, judging a target threshold, and generating adversarial samples. Based on the present invention, adversarial data generation of natural language text is performed, and a weighted finite automaton is extracted from a target black-box recurrent neural network as a guide for adversarial sample generation of natural language text, providing proxy model guidance, increasing the success rate and efficiency of adversarial sample generation, and using the present invention for black-box recurrent neural network adversarial sample generation in a machine learning as a service scenario, increasing the success rate and efficiency of adversarial sample generation, effectively reducing the number of inquiries, and reducing the service inquiry cost.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of analysis and interpretation of recurrent neural networks, to natural language processing, and in particular to a method for generating adversarial samples of black-box recurrent neural networks. Background Art

[0002] In recent years, with the rapid development of computing resources and artificial intelligence-related technologies, deep learning networks have been widely used in many fields of production and life, attracting widespread attention from all walks of life. At the same time, the application of deep learning networks in safety-critical fields such as aerospace, autonomous driving, and medical diagnosis, as well as the black-box characteristics and unexplainability of deep learning networks, have also caused public concerns about their correctness, robustness, and credibility. Therefore, security analysis and interpretation of deep learning networks are very necessary. Among them, recurrent neural networks (RNNs) are mainly used for learning sequence data and have achieved great success in tasks such as natural language processing, speech recognition, and machine translation.

[0003] Adversarial examples refer to some interference factors that are purposefully added to normal samples, or in the field of image classification tasks, they are called noisy samples, which cause the neural network to misjudge. The method of generating adversarial examples belongs to a type of attack, which can generally be divided into two categories: black-box attack, which generally assumes that the attacker cannot interfere with the training process, does not know the specific parameters of the model, and can only obtain the final output; white-box attack, which generally assumes that the attacker can obtain the specific parameters of the model, including the weights of each layer of convolution kernels. The obtained adversarial samples are extracted and tested; when the deep learning system has a low recognition rate for the input adversarial samples, it means that the adversarial samples are more disruptive; the obtained adversarial samples can also be used to ensure the security of the deep learning system.

[0004] At present, in the field of adversarial sample generation research for recurrent neural networks, many machine learning models, including neural networks, are vulnerable to adversarial sample attacks and lead to misclassification. Adversarial samples refer to samples that are deliberately added with some slight malicious perturbations to the input, so that the system misclassifies the sample with high confidence. Existing research work has mostly focused on the generation and analysis of adversarial samples for image classification tasks, and there is a lack of adversarial sample generation for natural language tasks.

[0005] However, the method for generating and analyzing adversarial samples for image classification tasks is not suitable for generating adversarial samples for natural language tasks. For example, unlike the continuous pixel value perturbation of images, natural language is perturbed by discrete word replacement. Therefore, the gradient solution based on the network loss function cannot be directly applied to the generation of adversarial samples for natural language. Although, in the prior art, such as the patent document with publication number CN109117482A, a method for generating adversarial samples for Chinese text sentiment tendency detection is disclosed, which solves the technical problem that the method for generating adversarial samples using text types is not suitable for Chinese data, and provides a method for generating adversarial samples for Chinese text sentiment tendency detection. For example, the patent document with publication number CN111209370A discloses a text classification method based on neural network interpretability. This method uses a trained text classification model to classify the input text information, and has the advantages of high robustness. However, when generating adversarial samples, this type of prior art is an adversarial sample generation method based on random perturbations. Due to the lack of proxy model guidance, the success rate and efficiency of adversarial sample generation are low. In addition, in the machine learning as a service (MLaaS) scenario, free queries to black-box recurrent neural networks are limited, and each query requires additional costs.

[0006] In the prior art, there have been some studies on the exploration of proxy models. For example, the prior art document [1] discloses the use of the L* algorithm to extract deterministic finite automata (DFA) from binary output type recurrent neural networks. Furthermore, the prior art document [2] discloses that researchers designed a weighted extension of the L* algorithm to extract probabilistic deterministic finite automata from language model recurrent neural networks. In order to process recurrent neural networks with real-valued outputs, the prior art document [3] discloses the extraction of weighted finite automata from this type of neural network based on a weighted extension of the L* algorithm. However, such methods have limited scalability and are limited to processing simple grammatical languages ​​and synthesis tasks. They cannot process neural networks with complex alphabets or state spaces in actual tasks, nor can they be applied to general recurrent neural network classifiers. On the other hand, the combination method abstracts the specific state of the recurrent neural network through a clustering algorithm. Following the idea of ​​the combination method, the prior art document [4] discloses the study of key factors affecting the reliability of the DFA extraction process, including grammatical complexity, clustering parameters, etc. Although this method has better scalability, its approximation accuracy when applied to large recurrent neural networks is limited, and there is a lack of systematic guidance on the configuration of the degree of abstraction.

[0007] Therefore, the generation of adversarial samples for such black-box recurrent neural networks urgently requires the introduction of abstract techniques to accurately construct proxy models that simulate the behavior of the target system to solve the problems of low success rate and efficiency of adversarial sample generation and high query cost.

[0008] Prior art documents:

[0009] Document [1]. Weiss, G.; Goldberg, Y.; and Yahav, E. 2018. Extracting Automata from Recurrent Neural Networks Using Queries and Counterexamples. In Dy, J.; and Krause, A., eds., Proceedings of the 35th International Conference on Machine Learning, volume 80 of Proceedings of Machine Learning Research. Stockholm, Sweden: PMLR.

[0010] Document [2]. Weiss, G.; Goldberg, Y.; and Yahav, E. 2019. Learning Deterministic Weighted Automata with Queries and Counterexamples. In Wallach, H.; Larochelle, H.; Beygelzimer, A.; d Alché-Buc, F.; Fox, E.; and Garnett, R., eds., Advances in Neural Information Processing Systems 32, 8560–8571. Curran Associates, Inc.

[0011] Document [3]. Okudono, T.; Waga, M.; Sekiyama, T.; and Hasuo, I. 2020. Weighted Automata Extraction from Recurrent Neural Networks via Regression on State Spaces. AAAI.

[0012] Literature [4]. Wang, Q.; Zhang, K.; Ororbia II, AG; Summary of the invention

[0013] In order to accurately construct a proxy model that simulates the behavior of the target system to support the problems of low success rate and efficiency of adversarial sample generation and high query cost of black-box recurrent neural network classifiers, the present invention provides a method for generating black-box recurrent neural network adversarial samples.

[0014] The present invention seeks protection for the following technical solutions:

[0015] The present invention provides a method for generating a black-box recurrent neural network adversarial sample, characterized in that it comprises the following steps:

[0016] Extracting weighted finite automata: Analyze the target black box recurrent neural network, specifically analyze the transfer trajectory of processing training sequence data in the output layer state of the target recurrent neural network; then gradually construct the various components of the weighted finite automata corresponding to the target recurrent neural network, including: constructing an alphabet according to the training sequence data; obtaining an initial discrete state set based on a clustering algorithm and the number of discrete partitions and obtaining a discrete state set with enhanced context information through an n-state synthesis strategy; obtaining a discrete state transition matrix corresponding to each letter in the alphabet based on the obtained specific transfer trajectory of the target recurrent neural network; establishing an initial vector of a weighted finite automata; constructing a final vector of the weighted finite automata based on the label vectors on each abstract state of the weighted finite automata; thereby completing the extraction of the weighted finite automata;

[0017] Initialize the candidate sample set: set the sample data volume of the algorithm based on the type of the algorithm, iterate according to the sample data volume, and obtain the initialized candidate adversarial sample data set;

[0018] Predicting data: using the extracted weighted finite automaton to further design a fitness function; and performing predictive reasoning on the current sample, and providing the next step of calculating the fitness function value based on the predicted output vector of the weighted automaton;

[0019] Calculating the fitness value: for the current candidate sample set, using the weighted finite automaton as a query guide, calculating the fitness function value;

[0020] Determine the target threshold: detect whether the fitness value corresponding to the sample set reaches the target threshold; if it is judged that the target threshold is not reached, select the two sample data with the largest objective function value to cross-synthesize new sample data, then mutate the new sample data, randomly select words in the sequence to replace them with their neighboring words, return to the data prediction step again, and enter the loop; if it is judged that the target threshold is reached, execute the next step;

[0021] Generate adversarial samples: When the target threshold is reached, the adversarial samples that meet the conditions are returned. When the maximum number of iterations is reached, that is, the upper limit of the number of overall algorithm cycles, the final adversarial sample set at the end of the iteration is returned.

[0022] Preferably, the present invention also provides another method for generating adversarial samples of black-box recurrent neural networks, based on a genetic algorithm framework, using a weighted finite automaton extracted from a target black-box recurrent neural network as a query object to generate adversarial samples, comprising the following steps:

[0023] Extracting weighted finite automata: Analyze the target recurrent neural network, specifically analyze the transfer trajectory of processing training sequence data in the output layer state of the target recurrent neural network; then gradually construct the various components of the weighted finite automata corresponding to the target recurrent neural network, including: constructing an alphabet based on the training sequence data; obtaining an initial discrete state set based on a clustering algorithm and the number of discrete partitions and obtaining a discrete state set with enhanced context information through an n-state synthesis strategy; obtaining a discrete state transition matrix corresponding to each letter in the alphabet based on the obtained specific transfer trajectory of the target recurrent neural network; establishing an initial vector of a weighted finite automata; constructing a final vector of the weighted finite automata based on the label vectors on each abstract state of the weighted finite automata; thereby completing the extraction of the weighted finite automata;

[0024] Initialize candidate sample set Population: Set the population size of the genetic algorithm to N. For any sample data, randomly select a word in the sequence of the sample data, replace the word in the sequence of the sample data with any of its K-nearest neighbor words, and iterate N times to obtain the initialized candidate adversarial text data.

[0025] Predict data: Using the extracted weighted finite automaton, further design the fitness function as Fitness(x, A), where A is the weighted finite automaton extracted from the target black box recurrent neural network in step (1); and perform predictive reasoning on the current individual x, and output the predicted vector of the weighted automaton on the current individual x for the next step of calculating the fitness function value;

[0026] Calculate the fitness value: for the current candidate sample set Population, after performing predictive reasoning calculations on the sample data on the extracted weighted finite automaton, use the weighted finite automaton as a query guide to calculate the fitness function value;

[0027] Determine the target threshold and generate adversarial samples: detect whether the fitness value corresponding to the sample set reaches the target threshold; if it is judged that the target threshold is not reached, select the two sample data with the largest objective function value to cross-synthesize a new sample, then mutate the new sentence, randomly select words in the sequence and replace them with their K-nearest neighbor words, return to the data prediction step again, and enter the loop; if it is judged that the target threshold is reached, execute the next step;

[0028] Generate adversarial samples: When the target threshold is reached, the adversarial samples that meet the conditions are returned. When the maximum number of iterations is reached, that is, the upper limit of the number of overall algorithm cycles, the final set of adversarial samples at the end of the iteration is returned.

[0029] Furthermore, the fitness function is designed as follows:

[0030]

[0031] Where C is the label set, c * =argmax(Prob) and Prob=A(x), which is the predicted probability vector of the weighted finite automaton for x.

[0032] Furthermore, in the step of extracting the weighted finite automaton, the target recurrent neural network is analyzed, specifically including:

[0033] Define the target recurrent neural network R and the training sequence data set X; input each sequence data w in the set X into R, and obtain the probability vector δ of the output layer of each time step i when processing the sequence input in R p (w[:i])(0≤i≤|w|); For the training sequence data set X, generate the output vector set Δ p ={δ p (w[:i])|0≤i≤|w|, w∈X}.

[0034] Furthermore, each time step i includes but is not limited to: a word in a text sequence, a letter in a grammatical language, etc.

[0035] Furthermore, the alphabet is a set ∑, which is initialized to an empty set. For each sequence data w in the set X, take the token at each position i, that is, w[i], and determine whether w[i] is already in the alphabet set ∑. If not, update the corresponding token into the alphabet set ∑; until all the sequence data in X are processed.

[0036] Furthermore, in the step of extracting the weighted finite automaton, the abstract state set is a discrete state set Q, and the construction of the discrete state set Q of the weighted finite automaton is divided into three steps: the first step is to estimate the number of discrete partitions through decision pattern recognition; the second step is to obtain the initial discrete state set Q based on the clustering algorithm and the number of discrete partitions. Init ; The third step is to obtain the discrete state set Q that enhances the context information through the n-state synthesis strategy.

[0037] Furthermore, the first step estimates the number of discrete partitions, and estimates the number of clusters by identifying the number of diversity of decision patterns, and specifically adopts a decision-oriented heuristic method for cluster number estimation.

[0038] Furthermore, the decision-oriented heuristic method for cluster number estimation refers to the introduction of the concept of decision confidence mode, estimating the number of clusters by identifying the diversity of decision modes, specifically including: estimating the number of clusters based on DCP, obtaining the output probability vector set Δ of the target recurrent neural network R p ={δ p (w[:i])|0≤i≤|w|, w∈X}, the derived decision mode set P=dcp is calculated k,t )(y)|y∈Δ p}, where |P|, the number of decision patterns, is taken as an estimate of the number of clusters;

[0039] Wherein, the mapping function dcp k,t , is the mapping function dcp that defines the probability vector to DCP under k, t configuration k,t :Y→([1,m]×I t ) k ;

[0040] The definition of DCP is: In an m-classification task, given a probability vector (y1, y2, ..., y m )satisfy Define the decision confidence model DCP as where (c1, c2, ..., c k ) is the top-k ranked category, η t is the confidence interval mapping function defined as follows;

[0041] The configuration parameter t is used to more finely characterize the difference in prediction confidence corresponding to the main prediction category. The probability range [0, 1] is divided into t equal intervals. Each probability value can be mapped to one of the t intervals. The configuration parameter t is used to characterize different levels of probability confidence. The corresponding probability confidence interval set is Define the probability vector group from elements y to I t The mapping function η t :y→I t ;

[0042] The configuration parameter k specifies the number of main prediction categories to be observed when extracting the mode, denoted as k-DCP; wherein, when k-DCP is 2-DCP, it is only necessary to pay attention to the changes of the prediction categories ranked in the top two in the output probability vector.

[0043] Furthermore, the second step obtains the initial discrete state set Q Init , including:

[0044] Based on the number of discrete partitions estimated in the first step, the k-means algorithm is used to sort the output layer vector set Δ p To perform clustering, the specific steps are as follows:

[0045] (1) Initialization: randomly select |P| samples as the initial cluster centers a=(a1, a2, ..., a |P| );

[0046] (2) For the output layer vector set Δ p The distance between each sample in the dataset and different cluster centers is calculated, and the sample is divided into the partition corresponding to the cluster center closest to the sample.

[0047] (3) For each discrete partition a i , based on the samples currently classified into this category, recalculate the mean of the samples and update its cluster center;

[0048] (4) Repeat (2) and (3) until the change in the cluster center between the two times is less than a specific threshold. The algorithm ends and the obtained discrete categories are used as the discrete state set Q of the weighted finite automaton. Init .

[0049] Furthermore, the third step obtains a discrete state set Q for enhancing context information through an n-state synthesis strategy, specifically including:

[0050] For any input sequence data w, the corresponding internal abstract state trajectory is Define the composite state after n-state synthesis Whenever there are less than n-1 states before the current state, fill the first element τ1 of the sequence; thus, for each sequence data w, a composite state set with enhanced context information is obtained

[0051] Together they constitute the discrete state set Q of the weighted finite automaton.

[0052] Furthermore, in the step of extracting the weighted finite automaton, the discrete state transition matrix corresponding to each letter in the alphabet is the transition matrix E σ ; Obtain the discrete state transfer matrix E corresponding to each letter in the alphabet σ The specific steps are:

[0053] Get the specific transfer trajectory of the target recurrent neural network, recorded as a triple (δ p (w[:i]),w[i],δ p (w[:i+1])); where, for any input sequence data w, position i, obtain the current output layer vector δ of the target neural network p (w[:i]), the next token w[i] to be processed, and the output layer vector 6 after reading w[i] and transferring the updated output layer vector p (w[:i+1]);

[0054] Based on any specific transition triple, create and update the transition matrix corresponding to token σ = w[i]; where the abstraction function λ to δ is applied p (w[:i]) and δ p (w[:i+1]), get the corresponding abstract state q source and q target ; Find the transfer matrix E corresponding to the letter σ σ , update its qth source Line q target The transfer frequency of the column; when there is no transfer matrix E corresponding to the letter σ σ When , the initial creation is performed;

[0055] The same updating process is performed on all transfer triplets to obtain the transfer frequency matrix corresponding to each letter σ in the alphabet ∑, and the probability transfer matrix is ​​obtained by normalizing the row vectors in the transfer frequency matrix.

[0056] Furthermore, the abstract function λ is the specific output layer vector Δ of the target recurrent neural network p ={δ p An abstract function from (w[:i])|0≤i≤|w|, w∈X} to the discrete state Q of the automaton.

[0057] Furthermore, the initial vector of the weighted finite automaton is the initial vector I, which describes the initial distribution on the abstract state of the automaton. The initial state q0 of the automaton is set, and the initial vector is set to a single-point distribution in the initial state q0.

[0058] Furthermore, in the step of extracting the weighted finite automaton, the final vector of the weighted finite automaton is a vector T, and constructing the final vector T of the weighted finite automaton includes:

[0059] Initialize the label vector on a certain abstract state q of the weighted finite automaton to be uniformly distributed on the label y (1≤y≤m);

[0060] Get the neural network output layer vector δ mapped to state q p The corresponding output label y (1≤y≤m) on the recurrent neural network, and update the frequency of the state corresponding to the label y;

[0061] Finally, all label frequencies are normalized as the label vector on the abstract state q. The final vector T of the weighted finite automaton is composed of the label vectors on each abstract state q.

[0062] The present invention also provides an application of a weighted finite automaton extracted from a black box neural network, characterized in that the application of the weighted finite automaton extracted in the step of extracting the weighted finite automaton in claim 1 is adopted, including: for any new sequence data, starting from a single point distribution or initial vector on an initial state, using the weighted finite automaton extracted in claim 1 to calculate the final prediction or inference result.

[0063] Preferably, in the method for generating a black-box recurrent neural network adversarial sample described in the present invention, in the data prediction step: using the extracted weighted finite automaton, further designing a fitness function as Fitness(x, A), wherein A is the weighted finite automaton extracted from the target black-box recurrent neural network in step (1); and performing predictive reasoning on the current individual x; including: for the current sample x or individual x, starting from the single point distribution or initial vector on the initial state, using the weighted finite automaton extracted in claim 1 to calculate the final prediction or reasoning result.

[0064] Preferably, the extracted weighted finite automaton is used to perform reasoning on new sequence data, including:

[0065] For any new sequence data w, starting from the single point distribution or initial vector I on the initial state q0, the weighted finite automaton extracted in claim 1 is used to calculate the final prediction or inference result;

[0066] The calculation process is as follows:

[0067]

[0068] Starting from the initial vector, that is, the initial distribution of the discrete state, multiply each input element w i The corresponding transfer matrix The discrete state distribution of each token after processing the sequence data is obtained, and finally multiplied by the final vector to obtain the prediction result inferred by the weighted finite automaton.

[0069] Furthermore, in the reasoning process on the new sequence data, a synonym transfer strategy is preferably adopted to avoid the problem of loss of transfer rules, specifically: finding a synonym of the unknown word in the alphabet ∑, and using the transfer rule of the synonym as a substitute for the dynamic transfer behavior;

[0070] The synonym transfer strategy includes:

[0071] First, the semantic distance between the unknown words and the known words in state q is calculated using the pre-trained GloVe word vectors;

[0072] Get the word σ with the minimum semantic distance to the unknown word, and get its corresponding transfer matrix E σ The transition rule E on state q σ (q, *);

[0073] Finally, use the located synonym transfer rule E σ (q,*) is predicted and inferred as a surrogate for lost transfer behavior.

[0074] Compared with the prior art, the present invention provides a method for generating adversarial samples of black-box recurrent neural networks. The method generally generates adversarial data of natural language samples based on an optimization search algorithm, extracts a weighted finite automaton from a target recurrent neural network as a guide for generating adversarial samples, and is used for generating adversarial samples of black-box recurrent neural networks in machine learning as a service scenarios, thereby reducing the cost of service inquiries. The method is based on the extracted weighted finite automaton as a query guide, which increases the attack success rate by an average of 37% compared to random generation. In the machine learning as a service (MLaaS) scenario, since each query requires additional cost, the present invention is used for generating adversarial samples of black-box recurrent neural networks in machine learning as a service scenarios, which increases the success rate and efficiency of adversarial sample generation and reduces the cost of inquiries. Specifically, compared with existing advanced technologies, the proposed weighted finite automaton extraction technology has stronger scalability and approximation accuracy, and can be used as a proxy model of the target network for predictive reasoning. Furthermore, by changing the original query to the target network to predictive reasoning on the weighted finite automaton, the query cost of the black box recurrent neural network in the machine learning as a service scenario is reduced, effectively reducing the number of queries and the service query cost. In particular, compared with the same natural language task, the use of weighted finite automaton extraction reduces the query cost by 92.7% compared to that directly based on the original recurrent neural network. BRIEF DESCRIPTION OF THE DRAWINGS

[0075] Figure 1 .A schematic diagram of the steps of a method for generating adversarial samples of a black-box recurrent neural network provided by the present invention.

[0076] Figure 2 .A method for generating adversarial samples of a black-box recurrent neural network provided by the present invention includes a flow chart of a weighted finite automaton extraction method for a black-box recurrent neural network.

[0077] Figure 3 .A schematic diagram of obtaining an estimated number of abstract states based on decision pattern recognition in a method for generating adversarial samples of a black-box recurrent neural network provided by the present invention.

[0078] Figure 4 .In a method for generating a black-box recurrent neural network adversarial sample provided by the present invention, the schematic diagram in the step of obtaining n-state state synthesis specifically refers to a 2-state context window synthesis schematic diagram.

[0079] Figure 5 Another schematic diagram of generating adversarial samples of a black-box recurrent neural network provided by the present invention is to generate adversarial data of natural language text based on a genetic algorithm.

[0080] Figure 6The present invention provides a method for generating adversarial samples of a black-box recurrent neural network, which is a schematic diagram or flow chart of the reasoning process on new sequence data based on the extracted weighted finite automaton, wherein the reasoning is performed through the calculated I*E*T formula.

[0081] Figure 7 .The present invention provides a schematic diagram of a synonym transfer rule in a method for generating a black-box recurrent neural network adversarial sample. DETAILED DESCRIPTION

[0082] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only embodiments of a part of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.

[0083] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0084] First, some nouns or terms that appear in the description of the embodiments of the present application are subject to the following explanations:

[0085] The concept of decision confidence pattern. The probability vector of the output layer has been widely used to characterize decision-making behavior and is a suitable observation object for identifying decision patterns. The reasons include the following two points:

[0086] First, compared with the internal state layer, the probability output layer is a mapping from high-dimensional space to low-dimensional space. While retaining important state information, it provides more computational feasibility due to the reduction of dimension. Second, the probability output has clear semantics and represents the confidence of the prediction of the input data. The greater probability of label prediction indicates that the deep learning model is more confident in the decision and can be used to identify decision patterns.

[0087] K-MEANS algorithm, also known as k-means clustering algorithm, is an iterative clustering analysis algorithm. Its steps are: divide the data into K groups in advance, randomly select K objects as the initial cluster centers, and then calculate the distance between each object and each seed cluster center, and assign each object to the cluster center closest to it. The cluster centers and the objects assigned to them represent a cluster. Each time a sample is assigned, the cluster center of the cluster will be recalculated based on the existing objects in the cluster. This process will be repeated until a certain termination condition is met. The termination condition can be that no (or the minimum number) of objects are reassigned to different clusters, no (or the minimum number) of cluster centers change again, and the sum of squared errors is locally minimized.

[0088] GloVe (Global Vectors for Word Representation) is a word representation tool based on count-based & overall statistics. It can express a word as a vector composed of real numbers. These vectors capture some semantic features between words, such as similarity, analogy, etc. By operating on vectors, such as Euclidean distance or cosine similarity, the semantic similarity between two words can be calculated.

[0089] In order to make the advantages of the technical solution of the present invention more clear, the present invention is described in detail below with reference to the accompanying drawings and embodiments.

[0090] Figure 1 It is a schematic diagram of the steps of a method for generating a black-box recurrent neural network adversarial sample provided by the present invention.

[0091] like Figure 1 As shown, the method comprises the following steps:

[0092] The first step is to extract the weighted finite automaton: analyze the target black box recurrent neural network, specifically analyze the transfer trajectory of processing the training sequence data in the output layer state of the target recurrent neural network; then gradually construct the various components of the weighted finite automaton corresponding to the target recurrent neural network, including: constructing an alphabet according to the training sequence data; obtaining an initial discrete state set based on a clustering algorithm and the number of discrete partitions and obtaining a discrete state set with enhanced context information through an n-state synthesis strategy; obtaining a discrete state transition matrix corresponding to each letter in the alphabet based on the obtained specific transfer trajectory of the target recurrent neural network; establishing an initial vector of the weighted finite automaton; constructing a final vector of the weighted finite automaton based on the label vectors on each abstract state of the weighted finite automaton; thereby completing the extraction of the weighted finite automaton.

[0093] It should be noted that the weighted finite automaton extracted in this embodiment is not limited to being used to generate countermeasures for this sample, but can also be used as a global explanation model of the target recurrent neural network to explain the decision changes when the target network processes sequence data. In addition, since the extracted weighted finite automaton is more lightweight and has a reduced computational complexity, it can be deployed in applications with limited resources such as mobile devices as a proxy model for prediction services.

[0094] The second step is to initialize the candidate sample set: set the number of samples of the algorithm to N, select any sample data in the test data set, randomly select words in the sample, replace the words in the sample with any of its K-nearest neighbor words, and iterate N times to obtain the initialized candidate adversarial sample data set. Initialization obtains the initial candidate adversarial sample data for subsequent fitness calculations, selection of the best candidate data, and the next iteration, so as to finally generate adversarial samples that meet the goal.

[0095] The third step is to determine the fitness function: using the extracted weighted finite automaton, further design the fitness function and perform predictive reasoning on the current sample x.

[0096] In this step, based on the weighted automaton as a guide, since the target constraint of the adversarial sample is that the label with the highest probability value in the predicted output probability vector is not the original true label (ground-truth label), the fitness function is designed to be the difference between the maximum value of the probability value corresponding to the non-real label and the probability value corresponding to the true label. In this way, data with high fitness function values ​​are selected, that is, candidate sample data is selected so that in the predicted output of the weighted automaton, the maximum value of other probability values ​​of the non-real label gradually approaches the true label probability value until it exceeds the true label probability value, and an adversarial sample that meets the requirements is obtained. The purpose of predictive reasoning is to serve as a proxy model for the target black-box recurrent neural network, change the original query to the target network to predictive reasoning for the weighted finite automaton, and reduce the query cost of the black-box recurrent neural network in the machine learning as a service scenario. The process is the same as Figure 5 As shown, the predicted output vector of the weighted automaton on the sequence data x is calculated for the next step of calculating the fitness function value.

[0097] The fourth step is to calculate the fitness value: for the current candidate sample set, after performing predictive reasoning calculations on the sample data on the extracted weighted finite automaton, the fitness function value is calculated using the weighted finite automaton as the query guide. Among them, the query cost is the unit price of each query * the number of queries. By using the extracted weighted automaton as a proxy model of the original target recurrent neural network to give a predicted output instead of directly querying the original target network, the number of queries in the adversarial sample generation process, that is, the query cost, is greatly reduced.

[0098] The fifth step is to determine the target threshold: detect whether the fitness value corresponding to the sample set reaches the target threshold; if it is determined that the target threshold is not reached, select the two sample data with the largest objective function value to cross-synthesize new sample data, and then mutate the new sample data, randomly select words in the sequence and replace them with their K-nearest neighbor words, and return to the third step again to enter the loop; if it is determined that the target threshold is reached, execute the next step.

[0099] Step 6: Generate adversarial samples: When the target threshold is reached, the adversarial samples that meet the conditions are returned. When the maximum number of iterations is reached, that is, the upper limit of the number of overall algorithm cycles, the final sample set at the time of iteration termination is returned.

[0100] Based on the above method disclosed by the present invention, compared with generating adversarial samples by random replacement of vocabulary, the weighted finite automaton extracted from the target recurrent neural network can be used as a proxy model of the target recurrent neural network to make predictions on the text data after perturbation replacement, and the fitness ability of the sequence data in the sample set to become adversarial samples is evaluated by fitness function calculation. By selecting the optimal candidate sample data in each iteration to replace the random perturbation replacement, the success rate and efficiency of adversarial sample generation can be greatly improved. In the machine learning as a service (MLaaS) scenario, since each query requires additional cost, the present invention is used for the generation of black box recurrent neural network adversarial samples in the machine learning as a service scenario, which increases the success rate and efficiency of adversarial sample generation, effectively reduces the number of queries, and reduces the cost of service queries.

[0101] In this embodiment, a proxy model guidance is provided to increase the success rate and efficiency of adversarial sample generation. Here, the process of extracting a weighted finite automaton from a target recurrent neural network is shown, such as Figure 2 It is a flow chart of a weighted finite automaton extraction method for a black-box recurrent neural network in a method for generating adversarial samples of a black-box recurrent neural network provided by the present invention. Figure 2 It mainly provides the process of extracting weighted finite automata from the target neural network, and is not limited to the application after extracting weighted automata, such as generating adversarial samples as query objects.

[0102] In the process of extracting the weighted finite automaton, the target recurrent neural network is analyzed, specifically including:

[0103] Define the target recurrent neural network R and the training sequence data set X; input each sequence data w in the set X into R, and obtain the hidden layer vector δ for each time step i when processing the sequence input in R s (w[:i])(0≤i≤|w|) and the probability vector δ of the output layer p (w[:i])(0≤i≤|w|); For the training sequence data set X, generate the corresponding hidden layer vector set Δ s ={δ s (w[:i])|0≤i≤|w|, w∈X}, and the set of output vectors Δ p ={δ p (w[:i])|0≤i≤|w|, w∈X}. Wherein, each time step i includes but is not limited to: a word in a text sequence, a letter in a grammatical language, etc.

[0104] Then, the components of the weighted finite automaton corresponding to the target recurrent neural network are gradually constructed, where:

[0105] The alphabet is a set ∑, which is initialized to an empty set. For each sequence data w in the set X, take the token at each position i, that is, w[i], and determine whether w[i] is already in the alphabet set ∑. If not, update the corresponding token into the alphabet set ∑; until all the sequence data in X are processed.

[0106] The abstract state set is a discrete state set Q. The construction of the discrete state set Q of the weighted finite automaton is divided into three steps: the first step is to estimate the number of discrete partitions through decision pattern recognition; the second step is to obtain the initial discrete state set Q based on the clustering algorithm and the number of discrete partitions. Init ; The third step is to obtain a discrete state set Q that enhances context information through an n-state synthesis strategy. The first step estimates the number of discrete partitions, and estimates the number of clusters by identifying the diversity of decision patterns, specifically using a decision-oriented heuristic method for cluster number estimation.

[0107] Preferably, Figure 3 As shown, in a method for generating a black-box recurrent neural network adversarial sample provided by the present invention, a schematic diagram of obtaining an estimated number of abstract states based on decision pattern recognition. The decision-oriented heuristic method for cluster number estimation refers to the introduction of the concept of decision confidence mode, estimating the number of clusters by identifying the diversity number of decision patterns, specifically including: estimating the number of clusters based on DCP, obtaining the output probability vector set Δ of the target recurrent neural network R p ={δ p (w[:i])|0≤i≤|w|, w∈X}, the derived decision mode set P=dcp is calculated k,t )(y)|y∈Δ p}, where |P|, the number of decision patterns, is taken as an estimate of the number of clusters;

[0108] Wherein, the mapping function dcp k,t , is the mapping function dcp that defines the probability vector to DCP under k, t configuration k,t :Y→([1,m]×It)k;The definition of DCP: In the m-classification task, given a probability vector (y1, y2, ..., y m )satisfy like Figure 3 As shown, the decision confidence model DCP is defined as where (c1, c2, ..., c k ) is the top-k ranked category, η tis the confidence interval mapping function defined as follows; the configuration parameter t is used to more finely characterize the difference in prediction confidence corresponding to the main prediction category. The probability range [0, 1] is divided into t equal intervals, and each probability value can be mapped to one of the t intervals. The configuration parameter t is used to characterize different levels of probability confidence, and the corresponding probability confidence interval set is

[0109]

[0110] ; Define the probability vector group from elements y to I t The mapping function η t :y→I t ; The configuration parameter k is used to specify the number of main prediction categories to be observed when extracting the mode, denoted as k-DCP; wherein, when k-DCP is 2-DCP, it is only necessary to pay attention to the changes in the prediction categories ranked in the top two in the output probability vector.

[0111] Furthermore, in this embodiment, based on the number of discrete partitions estimated in the first step, a k-means algorithm (K-MEANS algorithm) is used to perform a multiplication of the hidden layer vector set Δ s To perform clustering, the specific steps are as follows:

[0112] (1) Initialization: randomly select |P| samples as the initial cluster centers a=(a1, a2, ..., a |P| );

[0113] (2) For the hidden layer vector set Δ s The distance between each sample in the dataset and different cluster centers is calculated, and the sample is divided into the partition corresponding to the cluster center closest to the sample.

[0114] (3) For each discrete partition a i , based on the samples currently classified into this category, recalculate the mean of the samples and update its cluster center;

[0115] (4) Repeat (2) and (3) until the change in the cluster center between the two times is less than a specific threshold. The algorithm ends and the obtained discrete categories are used as the discrete state set Q of the weighted finite automaton. Init .

[0116] Furthermore, the discrete state set Q that enhances the context information is obtained through the n-state synthesis strategy, which specifically includes:

[0117] For any input sequence data w, the corresponding internal abstract state trajectory is Define the composite state after n-state synthesis Whenever there are less than n-1 states before the current state, fill the first element τ1 of the sequence; thus, for each sequence data w, a composite state set with enhanced context information is obtained Together they constitute the discrete state set Q of the weighted finite automaton.

[0118] like Figure 4 As shown, in a method for generating a black-box recurrent neural network adversarial sample provided by the present invention, a schematic diagram of the step of obtaining n-state state synthesis is specifically a schematic diagram of 2-state context window synthesis, wherein q0, q1, q2, q3 are discrete states directly obtained by an abstract function, assuming that the context window is set to 2-state, the current state is synthesized with its n-1 (here 2-1) state into a new state, q0q0, q0q1, q 01 q2, q2q3. The discrete states obtained by the abstract function are further refined due to the difference in their contexts. For example, the state q1 is refined into multiple states such as q0q1, q0′q1, ..., etc., which add context information.

[0119] In this embodiment, in the first step of extracting the weighted finite automaton, a discrete state transfer matrix corresponding to each letter in the alphabet is obtained based on the specific transfer trajectory of the target recurrent neural network; wherein, preferably, the discrete state transfer matrix corresponding to each letter in the alphabet is a transfer matrix E σ ; Obtain the discrete state transfer matrix E corresponding to each letter in the alphabet σ The specific steps are:

[0120] Get the specific transfer trajectory of the target recurrent neural network, recorded as a triple (δ s (w[:i]),w[i],δ s (w[:i+1])); where for any input sequence data w, position i, the current hidden layer vector δ of the target neural network is obtained s (w[:i]), the next token w[i] to be processed, and the hidden layer vector δ after transferring the updated hidden layer vector after reading w[i] s (w[:i+1]);

[0121] Based on any specific transition triple, create and update the transition matrix corresponding to token σ = w[i]; where the abstraction function λ to δ is applied s (w[:i]) and δ s (w[:i+1]), get the corresponding abstract state q sourc e and q target ; Find the transfer matrix E corresponding to the letter σσ , update its qth source Line q target The transfer frequency of the column; when there is no transfer matrix E corresponding to the letter σ σ When , the initial creation is performed;

[0122] The same updating process is performed on all transfer triplets to obtain the transfer frequency matrix corresponding to each letter σ in the alphabet ∑. Finally, the row vector of the transfer frequency matrix is ​​normalized to obtain the probability transfer matrix.

[0123] Wherein, the abstract function λ is the specific hidden layer vector Δ of the target recurrent neural network s ={δ s An abstract function from (w[:i])|0≤i≤|w|, w∈X} to the discrete state Q of the automaton.

[0124] In this embodiment, in the first step of extracting the weighted finite automaton, the initial vector of the weighted finite automaton is established, wherein, preferably, the initial vector of the weighted finite automaton is defined as the initial vector I, the initial vector I describes the initial distribution on the abstract state of the automaton, the initial state q0 of the automaton is set, and the initial vector is set to a single point distribution in the initial state q0.

[0125] Furthermore, in the step of extracting the weighted finite automaton, the final vector of the weighted finite automaton is a vector T, and constructing the final vector T of the weighted finite automaton includes:

[0126] Initialize the label vector on a certain abstract state q of the weighted finite automaton to be uniformly distributed on the label y (1≤y≤m);

[0127] Get the neural network hidden layer vector δ mapped to state q s The corresponding output label y (1≤y≤m) on the recurrent neural network, and update the frequency of the state corresponding to the label y;

[0128] Finally, all label frequencies are normalized as the label vector on the abstract state q. The final vector T of the weighted finite automaton is composed of the label vectors on each abstract state q.

[0129] The above completes the creation and extraction of the weighted finite automaton. Compared with the existing advanced technology, the weighted finite automaton extraction technology in this embodiment has stronger scalability and approximation accuracy. The weighted finite automaton is constructed for the target recurrent neural network. The main components include a finite state set Q, an alphabet ∑, and a transfer matrix E corresponding to a letter σ∈∑ in any alphabet σ, initial vector I, final vector T. The construction technology follows the abstract representation method of the internal state of the recurrent neural network in the combination method, avoids the scalability limitations brought by the L* algorithm, and can support the abstract model extraction of general recurrent neural network classifiers.

[0130] In addition to the above process, adversarial samples are generated based on the weighted automaton extracted as the query object. In the method for generating adversarial samples based on the genetic algorithm framework described in the present invention, the genetic algorithm (GA) is a heuristic search algorithm inspired by Darwin's theory of evolution and belongs to the natural evolution algorithm (EA). The genetic algorithm can generate solutions for optimization and search problems by simulating operations such as mutation, selection and crossover in the natural selection process. The main feature of the algorithm is that it directly operates on the target object, uses probability and statistics to obtain the optimal solution, does not require specific rules, and can adaptively adjust and optimize the search direction. Therefore, this embodiment is based on the genetic algorithm as an example, and the process of extracting the weighted finite automaton in the first step is adaptively changed.

[0131] Figure 5 It is another schematic diagram of generating a black-box recurrent neural network adversarial sample provided by the present invention, which generates adversarial data of natural language text based on a genetic algorithm.

[0132] like Figure 5 As shown, the method for generating adversarial samples of black-box recurrent neural networks is used to generate adversarial samples for genetic algorithms by taking the weighted finite automaton extracted from the target black-box recurrent neural network as the query object. In order to support the generation of adversarial samples for black-box recurrent neural network classifiers, the proxy model of the target recurrent neural network is first extracted by automaton extraction technology, and then the extracted weighted finite automaton is used as the query guidance to give an evaluation of the currently generated text data as a proxy model. Based on the genetic algorithm, the fitness function value is designed. Starting from the initialization of candidate texts, adversarial text data that meets the objective function is generated through crossover and mutation, which can be applied to black-box recurrent neural networks and reduce the query cost.

[0133] The specific process includes the following:

[0134] The first step is to extract a weighted finite automaton (proxy model) from the target neural network: analyze the target recurrent neural network, specifically analyze the transfer trajectory of processing the training sequence data in the output layer state of the target recurrent neural network; then gradually construct the various components of the weighted finite automaton corresponding to the target recurrent neural network, including: constructing an alphabet based on the training sequence data; obtaining an initial discrete state set based on a clustering algorithm and the number of discrete partitions and obtaining a discrete state set that enhances context information through an n-state synthesis strategy; obtaining a discrete state transition matrix corresponding to each letter in the alphabet based on the obtained specific transfer trajectory of the target recurrent neural network; establishing an initial vector of the weighted finite automaton; constructing a final vector of the weighted finite automaton based on the label vectors on each abstract state of the weighted finite automaton; thereby completing the extraction of the weighted finite automaton.

[0135] In the first step of extracting the weighted finite automaton, the target recurrent neural network is analyzed. In the framework of the genetic algorithm, there is no need to consider hidden vectors, only the output vector corresponding to the sample data is needed. Specifically, it includes: defining the current target recurrent neural network R and the training sequence data set X; inputting each sequence data w in the set X into R, and obtaining the probability vector δ of the output layer of each time step i when processing the sequence input in R p (w[:i])(0≤i≤|w|); For the training sequence data set X, generate the corresponding output vector set Δ p ={δ p (w[:i])|0≤i≤|w|, w∈X}. Wherein, each time step i includes but is not limited to: a word in a text sequence, a letter in a grammatical language, etc.

[0136] Furthermore, in this embodiment, based on the number of discrete partitions estimated in the first step, the output layer vector set Δ p To perform clustering, the specific steps are as follows:

[0137] (1) Initialization: randomly select |P| samples as the initial cluster centers a=(a1, a2, ..., a |P| );

[0138] (2) For the output layer vector set Δ p The distance between each sample in the dataset and different cluster centers is calculated, and the sample is divided into the partition corresponding to the cluster center closest to the sample.

[0139] (3) For each discrete partition a i, based on the samples currently classified into this category, recalculate the mean of the samples and update its cluster center;

[0140] (4) Repeat (2) and (3) until the change in the cluster center between the two times is less than a specific threshold. The algorithm ends and the obtained discrete categories are used as the discrete state set Q of the weighted finite automaton. Init .

[0141] Furthermore, in this embodiment, the specific transfer trajectory of the target recurrent neural network is obtained, which is recorded as a triple (δ p (w[:i]),w[i],δ p (w[:i+1])); where, for any input sequence data w, position i, obtain the current output layer vector δ of the target neural network p (w[:i]), the next token w[i] to be processed, and the output layer vector δ after reading w[i] and transferring the updated output layer vector p (w[:i+1]); Based on any specific transfer triple, create and update the transfer matrix corresponding to tokenσ=w[i]; where the abstract function λ to δ is applied p (w[:i]) and δ p (w[:i+1]), get the corresponding abstract state q source and q target ; Find the transfer matrix E corresponding to the letter σ σ , update its qth source Line q target The transfer frequency of the column; when there is no transfer matrix E corresponding to the letter σ σ When , the initial creation is performed; the same update process is performed on all transfer triples, so as to obtain the transfer frequency matrix of each letter σ in the corresponding alphabet ∑. Wherein, the abstract function λ is the specific output layer vector Δ of the target recurrent neural network p ={δ p An abstract function from (w[:i])|0≤i≤|w|, w∈X} to the discrete state Q of the automaton.

[0142] Among them, in the second step of initializing the candidate sample set Population process: set the population size (population size) of the genetic algorithm to N, and for any sample data, randomly select words in the sequence of the sample data, replace the words in the sequence of the sample data with any of its K-nearest neighbor words, and iterate N times to obtain the initialized candidate adversarial text data.

[0143] Among them, in the third step of predicting data: perform predictive reasoning calculations on the data on the weighted finite automaton. And determine the fitness function: the fitness function is designed to be Fitness(x, A), where A is the weighted finite automaton extracted from the target black box recurrent neural network in step (1), which is used to predict and reason the current sample data (individual) x. The designed fitness function is preferably: Where C is the label set, c * =argmax(Prob) and Prob=A(x), which is the predicted probability vector of the weighted finite automaton for x.

[0144] Among them, in the fourth step of calculating the fitness value: for the current candidate sample set Population, the fitness function value is calculated using the weighted finite automaton as the query guide; the score (fitness score) obtained by calculating the fitness function based on the weighted finite automaton prediction reasoning result.

[0145] Among them, in the process of judging the target threshold in the fifth step: detect whether the fitness value corresponding to the sample set reaches the target threshold; when it is judged that the target threshold is not reached, select two sample data with the largest objective function value (i.e., high fitness sample data) to cross-synthesize a new sample, and then mutate the new sample, randomly select a word in the sequence to replace it with its K-nearest neighbor word, and return to the third step of the prediction data again to enter the loop; when it is judged that the target threshold is reached, execute the next step;

[0146] Among them, the sixth step generates adversarial samples: when it is judged that the target threshold is reached, that is, f(x′)≠f(x), the adversarial samples that meet the conditions are returned. When the maximum number of iterations is reached, that is, the upper limit of the number of cycles of the overall algorithm, the last sample set when the iteration terminates is returned.

[0147] By designing the fitness function in the genetic algorithm, the generation of adversarial samples can be changed from the untargeted label category to the targeted label category, which shows the strong scalability of the proposed algorithm. Specifically, the maximum value of the non-real label in the designed fitness function can be Replace it with the predicted probability value of the specific label category t, and modify the fitness function accordingly, Fitness(x, A) = Prob(t)-Prob(c * ), the generated data is the adversarial sample with a specific label t. Similarly, this optimization search algorithm can also be applied to optimal path planning and strategy selection for machine control.

[0148] The advantages of genetic algorithm applications are: based on the extracted weighted finite automaton as a guide, it has fast search capabilities, starting from the group, it has parallelism, can be compared with multiple individuals at the same time, and has strong scalability. From the results, it can be seen that starting from the group can effectively improve the search success rate, and parallel search can effectively reduce the query cost by selecting the best (high) fitness function.

[0149] In addition to the above process, the weighted finite automaton extracted in the method of the present invention can process not only simple or synthetic grammatical tasks, but also natural language processing tasks (NLP tasks) on the task object, so it can be used as a proxy model for the black box recurrent neural network to process natural language tasks for adversarial data generation. For simple or synthetic grammatical tasks, for example, based on the weighted finite automaton extracted above, new sequence data is predicted and inferred.

[0150] The present invention also provides an application of a weighted finite automaton extracted from a black box neural network, including: for any new sequence data, starting from a single point distribution or initial vector on an initial state, using a weighted finite automaton extracted from a target black box recurrent neural network to calculate a final prediction or reasoning result. Using the weighted finite automaton extracted in the first step as a proxy model of the original target neural network, new sequence data can also be predicted and reasoned.

[0151] For example, in the third step of predicting data in the method described in this embodiment: using the extracted weighted finite automaton, further design the fitness function as Fitness(x, A), where A is the weighted finite automaton extracted from the target black box recurrent neural network in step (1); and perform predictive reasoning on the current individual x; including: for the current sample x or individual x, starting from the single point distribution or initial vector on the initial state, using the weighted finite automaton extracted in the first step to calculate the final prediction or reasoning result. The process is as follows Figure 6 As shown, the specific process is as follows.

[0152] Or, as inference on new sequence data, including:

[0153] For any new sequence data w, starting from the single point distribution or initial vector I on the initial state q0, the weighted finite automaton extracted from the target black box recurrent neural network in claim 1 is used to calculate the final prediction or inference result;

[0154] like Figure 6As shown, the present invention provides a method for generating a black-box recurrent neural network adversarial sample, a schematic diagram of the reasoning process on new sequence data based on the extracted weighted finite automaton, and the reasoning is calculated through the calculated I*E*T (as shown below) formula.

[0155] The calculation process is as follows:

[0156]

[0157] Starting from the initial vector, that is, the initial distribution of the discrete state, multiply each input element w i The corresponding transfer matrix The discrete state distribution of each token after processing the sequence data is obtained, and finally multiplied by the final vector to obtain the prediction result inferred by the weighted finite automaton. Figure 5 As shown, from the initial distribution I q0 Start by multiplying the transfer matrix E corresponding to the input element I I , get the discrete state distribution D after processing sequence data token "I" updated I ; Continue to multiply the transfer matrix E corresponding to the input element like like , get the discrete state distribution D after processing the sequence data token "I like" updated like ; Continue to multiply the transfer matrix E corresponding to the input element this this , get the discrete state distribution D after processing the sequence data token "I like this" this ; Continue to multiply the transfer matrix E corresponding to the input element film film , get the updated discrete state distribution D of the processed sequence data token "I like this film" film ; Finally, multiply it by the final vector T to get the prediction result Pred inferred by the weighted finite automaton.

[0158] In the reasoning process, due to the emergence of new unknown words (tokens) in specific sequence data tasks, such as natural language processing tasks, it is impossible to find the transfer matrix E corresponding to the token during the reasoning process, which is called the transfer rule loss problem. To address this problem, the present invention proposes a synonym transfer strategy as a supplement. Intuitively, in this case, a synonym of the unknown word in the alphabet ∑ is found, and the synonym transfer strategy is used as a substitute for the dynamic transfer behavior.

[0159] Preferably, a synonym transfer strategy is used to avoid the problem of loss of transfer rules, specifically by finding a synonym of the unknown word in the alphabet ∑, and using the synonym transfer strategy as a substitute for the dynamic transfer behavior. Figure 7The present invention provides a schematic diagram of a synonym transfer strategy in a method for generating a black-box recurrent neural network adversarial sample, wherein the synonym transfer strategy includes:

[0160] First, the semantic distance between the unknown word and the known word in state q is calculated using the pre-trained GloVe word vector. Figure 6 In the example, toad is an unknown word, and the Euclidean distance between its GloVe word vector and the GloVe word vectors of other words in the alphabet is calculated;

[0161] Get the word σ with the minimum semantic distance to the unknown word, and get its corresponding transfer matrix E σ The transition rule E on state q σ (q, *). Figure 6 As shown, frog is the word with the closest semantic distance to the unknown word, and its transfer matrix E is obtained. frog (q, *);

[0162] Finally, use the located synonym transfer rule E σ (q, *) is used as a substitute for the lost transfer behavior for prediction and reasoning. Figure 7 As shown, due to the missing E in the transfer matrix toad (q, *) transfer rule, we use E frog (q, *) performs inference calculation.

[0163] It should be noted here that the method for generating black-box recurrent neural network adversarial samples described in the present invention is not only applicable to the applications listed above (inference on new sequence data, genetic algorithms, etc.), but also includes specific applications that can be implemented in this field.

[0164] In summary, compared with the prior art, the advantages of the present invention are:

[0165] The content of the present invention is to generate adversarial samples for black-box recurrent neural networks. This method is based on the extracted weighted finite automaton as a query guide, which increases the attack success rate by an average of 37% compared to random generation.

[0166] Among them, the weighted finite automaton extraction technology has stronger scalability and approximation accuracy compared with existing advanced technologies. The weighted finite automaton is constructed for the target recurrent neural network. The main components include the finite state set Q, the alphabet ∑, and the transfer matrix E corresponding to any letter σ∈∑ in the alphabet σ, initial vector I, final vector T. The construction technology follows the abstract representation method of the internal state of the recurrent neural network in the combination method, avoiding the scalability limitations brought by the L* algorithm, and can support the abstract model extraction of general recurrent neural network classifiers. On the task object, it can not only handle simple or synthetic grammatical tasks, but also natural language processing tasks (NLP tasks). Therefore, it can be used as a proxy model for black-box recurrent neural networks to process natural language tasks for adversarial data generation. Compared with adversarial data generation based on the original recurrent neural network, the query cost is reduced by 92.7%.

[0167] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principle of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.

Claims

1. A method for generating adversarial examples of black-box recurrent neural networks, characterized in that: The following steps are involved: Extracting weighted finite automata: analyzing the target black box recurrent neural network, specifically analyzing the transfer trajectory of processing training sequence data in the output layer state of the target recurrent neural network; Then, each component of the weighted finite automaton corresponding to the target recurrent neural network is gradually constructed, including: constructing an alphabet according to the training sequence data; Based on the clustering algorithm and the number of discrete divisions, an initial discrete state set is obtained, and a discrete state set with enhanced context information is obtained through an n-state synthesis strategy; based on the obtained specific transfer trajectory of the target recurrent neural network, a discrete state transition matrix corresponding to each letter in the alphabet is obtained; an initial vector of a weighted finite automaton is established; based on the label vectors on each abstract state of the weighted finite automaton, a final vector of the weighted finite automaton is constructed; thereby, the extraction of the weighted finite automaton is completed; Initialize the candidate sample set: set the sample data volume of the algorithm based on the type of the algorithm, iterate according to the sample data volume, and obtain the initialized candidate adversarial sample data set; Predicting data: using the extracted weighted finite automaton to further design a fitness function; and performing predictive reasoning on the current sample, and providing the next step of calculating the fitness function value based on the predicted output vector of the weighted finite automaton; Calculating the fitness value: for the current candidate sample set, using the weighted finite automaton as a query guide, calculating the fitness function value; Determine the target threshold: detect whether the fitness value corresponding to the sample set reaches the target threshold; if it is judged that the target threshold is not reached, select the two sample data with the largest objective function value to cross-synthesize new sample data, then mutate the new sample data, randomly select words in the sequence to replace them with their neighboring words, return to the data prediction step again, and enter the loop; if it is judged that the target threshold is reached, execute the next step; Generate adversarial samples: When the target threshold is reached, the adversarial samples that meet the conditions are returned. When the maximum number of iterations is reached, that is, the upper limit of the number of overall algorithm cycles, the final adversarial sample set at the end of the iteration is returned.

2. The method for generating a black-box recurrent neural network adversarial sample according to claim 1, characterized in that: Based on the genetic algorithm framework, the weighted finite automaton extracted from the target black box recurrent neural network is used as the query object to generate adversarial samples, including the following steps: Extracting weighted finite automata: Analyzing the target recurrent neural network, specifically analyzing the transfer trajectory of processing training sequence data in the output layer state of the target recurrent neural network; then gradually constructing the various components of the weighted finite automata corresponding to the target recurrent neural network, including: constructing an alphabet based on the training sequence data; obtaining an initial discrete state set based on a clustering algorithm and the number of discrete partitions and obtaining a discrete state set with enhanced context information through an n-state synthesis strategy; obtaining a discrete state transition matrix corresponding to each letter in the alphabet based on the obtained specific transfer trajectory of the target recurrent neural network; establishing an initial vector of a weighted finite automata; constructing a final vector of the weighted finite automata based on the label vectors on each abstract state of the weighted finite automata; thereby completing the extraction of the weighted finite automata; Initialize candidate sample set Population: Set the population size of the genetic algorithm to N. For any sample data, randomly select a word in the sequence of the sample data, replace the word in the sequence of the sample data with any of its K-nearest neighbor words, and iterate N times to obtain the initialized candidate adversarial text data. Predict data: Using the extracted weighted finite automaton, further design the fitness function as Fitness(x, A), where A is the weighted finite automaton extracted from the target black box recurrent neural network in step (1); and perform predictive reasoning on the current individual x, and output the predicted vector of the weighted finite automaton on the current individual x for the next step of calculating the fitness function value; Calculate the fitness value: for the current candidate sample set Population, after performing predictive reasoning calculations on the sample data on the extracted weighted finite automaton, use the weighted finite automaton as a query guide to calculate the fitness function value; Determine the target threshold and generate adversarial samples: detect whether the fitness value corresponding to the sample set reaches the target threshold; if it is judged that the target threshold is not reached, select the two sample data with the largest objective function value to cross-synthesize a new sample, then mutate the new sentence, randomly select words in the sequence and replace them with their K-nearest neighbor words, return to the data prediction step again, and enter the loop; if it is judged that the target threshold is reached, execute the next step; Generate adversarial samples: When the target threshold is reached, the adversarial samples that meet the conditions are returned. When the maximum number of iterations is reached, that is, the upper limit of the number of overall algorithm cycles, the final adversarial sample set at the end of the iteration is returned.

3. The method for generating a black-box recurrent neural network adversarial sample according to claim 2, characterized in that: The fitness function designed is: Fitness(x,A)=max j∈C\c *Prob(j)-Prob(c * ), Where C is the label set, c * =argmax(Prob) and Prob=A(x), that is, the predicted probability vector of x by the weighted finite automaton, j is the label index.

4. The method for generating a black-box recurrent neural network adversarial sample according to claim 2, further comprising: In the step of extracting the weighted finite automaton, the target recurrent neural network is analyzed, specifically including: Define the target recurrent neural network R and the training sequence data set X; input each sequence data w in the set X into R, and obtain the probability vector δ of the output layer of each time step i when processing the sequence input in R p (w[:i])(0≤i≤|w|); for the training sequence data set X, generate the output vector set Δ p ={δ p (w[:i])|0≤i≤|w|,w∈X}.

5. The method for generating a black-box recurrent neural network adversarial sample according to claim 4, further characterized in that: Each time step i includes but is not limited to: a word in the text sequence, a letter in the grammatical language.

6. The method for generating a black-box recurrent neural network adversarial sample according to claim 1 or 2, further characterized in that: The alphabet is a set Σ, which is initialized to an empty set. For each sequence data w in the set X, take the token of each time step i, that is, w[i], and determine whether w[i] is already in the alphabet set Σ. If not, update the corresponding token into the alphabet set Σ; Until all the sequence data in X are processed.

7. The method for generating a black-box recurrent neural network adversarial sample according to claim 4, further characterized in that: In the step of extracting the weighted finite automaton, the abstract state set is a discrete state set Q. The construction of the discrete state set Q of the weighted finite automaton is divided into three steps: the first step is to estimate the number of discrete partitions through decision pattern recognition; the second step is to obtain the initial discrete state set Q based on the clustering algorithm and the number of discrete partitions. Init ; The third step is to obtain the discrete state set Q that enhances the context information through the n-state synthesis strategy.

8. The method for generating a black-box recurrent neural network adversarial sample according to claim 7, further characterized in that: The first step estimates the number of discrete partitions, and estimates the number of clusters by identifying the diversity number of decision patterns, and specifically adopts a decision-oriented heuristic method for cluster number estimation.

9. The method for generating a black-box recurrent neural network adversarial sample according to claim 8, characterized in that: The decision-oriented heuristic method for cluster number estimation introduces the concept of decision confidence mode and estimates the number of clusters by identifying the diversity of decision modes. Specifically, the method includes: estimating the number of clusters based on DCP, obtaining the output probability vector set Δ of the target recurrent neural network R p ={δ p (w[:i])|0≤i≤|w|,w∈X}, the derived decision mode set P=dcp is calculated k,t )(y)|y∈Δ p }, where |P|, the number of decision patterns, is taken as an estimate of the number of clusters; Among them, the mapping function dcp k,t , is the mapping function dcp that defines the probability vector to DCP under the k, t configuration k,t :Y→([1,m]×I t ) k ; The definition of DCP is: In an m-classification task, given a probability vector (y1, y2, ..., y m )satisfy Define the decision confidence model DCP as where (c1, c2, …, c k ) is the top-k ranked category, η t is the confidence interval mapping function defined as follows; Configuration parameter t is used to more finely characterize the difference in prediction confidence corresponding to the main prediction category. The probability range [0,1] is divided into t equal intervals. Each probability value can be mapped to one of the t intervals. The configuration parameter t is used to characterize different levels of probability confidence. The corresponding probability confidence interval set is Define the probability vector group from elements y to I t The mapping function η t :y→I t ; The configuration parameter k specifies the number of main prediction categories to be observed when extracting patterns, denoted as k-DCP; when k-DCP is 2-DCP, it means that only the changes in the prediction categories ranked in the top two in the output probability vector need to be paid attention to.

10. The method for generating a black-box recurrent neural network adversarial sample according to claim 7, further characterized in that: The second step obtains the initial discrete state set Q Init , including: Based on the number of discrete partitions estimated in the first step, the output layer vector set Δ p To perform clustering, the specific steps are as follows: (1) Initialization: randomly select |P| samples as the initial cluster centers a=(a1, a2, …, a |P| ); (2) For the output layer vector set Δ p The distance between each sample in the dataset and different cluster centers is calculated, and the sample is divided into the partition corresponding to the cluster center closest to the sample. (3) For each discrete partition a i , based on the samples currently classified into this category, recalculate the mean of the samples and update its cluster center; (4) Repeat (2) and (3) until the change in the cluster center between the two times is less than a specific threshold. The algorithm ends and the obtained discrete categories are used as the discrete state set Q of the weighted finite automaton. Init .

11. The method for generating a black-box recurrent neural network adversarial sample according to claim 7, further characterized in that: The third step is to obtain a discrete state set Q of enhanced context information through an n-state synthesis strategy, specifically including: For any input sequence data w, the corresponding internal abstract state trajectory is Define the composite state after n-state synthesis Whenever there are less than n-1 states before the current state, fill the first element τ1 of the sequence; thus, for each sequence data w, a composite state set with enhanced context information is obtained Together they constitute the discrete state set Q of the weighted finite automaton.

12. The method for generating a black-box recurrent neural network adversarial sample according to claim 2, further characterized in that: In the step of extracting the weighted finite automaton, the discrete state transition matrix corresponding to each letter in the alphabet is the transition matrix E σ ; Obtain the discrete state transfer matrix E corresponding to each letter in the alphabet σ The specific steps are: Get the specific transfer trajectory of the target recurrent neural network, recorded as a triple (δ p (w[:i]),w[i],δ p (w[:i+1])); where, for any input sequence data w, time step i, the current output layer vector δ of the target recurrent neural network is obtained p (w[:i]), the next token w[i] to be processed, and the output layer vector δ after reading w[i] and transferring the updated output layer vector p (w[:i+1]); Based on any specific transition triple, create and update the transition matrix corresponding to token σ = w[i]; where the abstraction function λ to δ is applied p (w[:i]) and δ p (w[:i+1]), get the corresponding abstract state q source and q target ; Find the transfer matrix E corresponding to the letter σ σ , update its qth source Line q target The transfer frequency of the column; when there is no transfer matrix E corresponding to the letter σ σ When , the initial creation is performed; Perform the same update process as above for all transfer triplets to obtain the transfer frequency matrix of each letter σ in the corresponding alphabet Σ. Finally, the transfer frequency matrix E of each letter σ is σ , normalize the frequencies of all its row vectors and construct a probability transfer matrix between discrete states.

13. The method for generating a black-box recurrent neural network adversarial sample according to claim 12, further characterized in that: The abstract function λ is the specific output layer vector Δ of the target recurrent neural network p ={δ p (w[:i])|0≤i≤|w|,w∈X} to the abstract function of the discrete state Q of the automaton.

14. The method for generating a black-box recurrent neural network adversarial sample according to claim 1 or 2, further characterized in that: The initial vector of the weighted finite automaton is the initial vector I, which describes the initial distribution on the abstract state of the automaton. The initial state q0 of the automaton is set, and the initial vector is set to a single-point distribution in the initial state q0.

15. The method for generating a black-box recurrent neural network adversarial sample according to claim 2, further characterized in that: In the step of extracting the weighted finite automaton, the final vector of the weighted finite automaton is a vector T, and constructing the final vector T of the weighted finite automaton includes: Initialize the label vector on a certain abstract state q of the weighted finite automaton to be uniformly distributed on the label z (1≤z≤m); Get the neural network output layer vector δ mapped to state q p The corresponding output label z (1≤z≤m) on the recurrent neural network, and update the frequency of the state corresponding to the label z; Finally, all label frequencies are normalized as the label vector on the abstract state q. The final vector T of the weighted finite automaton is composed of the label vectors on each abstract state q.