A character-level adversarial sample generation method for Chinese text classification tasks
By constructing a multitone dictionary and global matching replacement operation to generate high-quality character-level adversarial samples, the problem of large amplitude of adversarial samples in the prior art is solved and the robustness of the model is improved.
Patent Information
- Application Number
- CN202210219212.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-08
- Publication Date
- 2024-12-13
- Estimated Expiration
- 2042-03-08
AI Technical Summary
In the Chinese text classification task, the existing adversarial sample generation method has a large perturbation amplitude and is easily recognized by the model, resulting in poor performance of adversarial sample.
By constructing a multi-sounding dictionary, character-level adversarial samples are generated using Chinese character feature information, and adversarial samples with the same shape as the original text but different pronunciations are generated through global matching replacement operations. The perturbation value is adjusted through the target discrimination model to generate high-quality adversarial samples.
The quality of the adversarial samples is improved, making them less likely to be recognized by the model in Chinese text classification tasks, and the robustness of the model is enhanced.
Smart Images

Figure CN114579763B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence, in particular to the field of natural language processing, and specifically to a method for generating character-level adversarial samples for Chinese text classification tasks. Technical Background
[0002] In the field of text, a large amount of text data is used for various analyses. When using text data for related tasks, adversarial samples are needed to detect model robustness or enhance data. At the same time, adding adversarial samples to training data can improve model robustness.
[0003] In the current adversarial sample generation methods, there is a problem that the disturbance amplitude is large and is easily recognized by the model, so that the adversarial sample does not perform at its best. How to generate high-quality adversarial samples that are not recognized by the model to the greatest extent is crucial and is also the problem to be solved by the present invention. Summary of the invention
[0004] In response to the above problems, the present invention deeply mines text feature information, utilizes the characteristics of Chinese characters themselves, generates high-quality adversarial samples, and provides technical support for various tasks that require adversarial sample data.
[0005] The present invention provides a method for generating character-level adversarial samples for Chinese text classification tasks.
[0006] The method for profiling and analyzing the willingness of airline passengers to pay for seat selection described in the present invention is characterized by comprising the following steps:
[0007] A) Data acquisition and storage: Obtain raw data from numerous online reviews and store them.
[0008] B) Polyphonetic word dictionary construction: construct a polyphonetic word dictionary based on the original data.
[0009] The polyphone dictionary is represented as a dictionary that contains the relationship between characters and pronunciations, and is described by a four-tuple (w, x, y, i).
[0010] Among them, w is the Chinese representation of the polyphone, x is the pinyin representation of w, y is the specific meaning of w, and i represents the i-th pronunciation of w, i∈[1,7].
[0011] C) Polyphonetic Dictionary Annotation: Annotation is performed according to the polyphonetic dictionary format to determine the specific value of the quadruple (w, x, y, i) of each character in the polyphonetic dictionary.
[0012] D) Adversarial sample generation: taking the original sample as input, using the data in the constructed polyphone dictionary, performing global matching in the original data, finding the characters with the same w, performing replacement operations, and obtaining adversarial samples with the same shape as the original character but different pronunciation.
[0013] The method for profiling and analyzing the willingness of airline passengers to pay for seat selection described in the present invention is characterized by:
[0014] In line
[0007] , the original data includes structured data and unstructured data.
[0015] The method for generating character-level adversarial samples for Chinese text classification tasks described in the present invention is characterized by:
[0016] Inputting the adversarial sample into a target discrimination model to obtain a judgment category of the sample output by the target discrimination model;
[0017] According to the judgment category, the difference between the current judgment and the original data category is obtained, a disturbance value is obtained, and the disturbance is returned to the adversarial sample generation process. Wherein, the target judgment category is different from the original category.
[0018] By adopting the above technical solution, the present invention generates high-quality adversarial samples by deeply mining text feature information and utilizing Chinese polyphone information.
[0019] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] The accompanying drawings are used to better understand the present invention and do not constitute a limitation of the present invention.
[0021] Figure 1 This is a replacement vector description of a character-level adversarial sample generation method for Chinese text classification tasks. DETAILED DESCRIPTION
[0022] The following description is combined with the accompanying drawings to help understand the content of the invention.
[0023] The method for generating character-level adversarial samples for Chinese text classification tasks described in the present invention comprises the following steps:
[0024] A) Data acquisition and storage: Obtain raw data from numerous online comments and store them. This step includes crawling data from major website platforms, including but not limited to opinion comments in Xiaohongshu, customer comments in Taobao, event comments in Weibo, and other structured and unstructured data information, cleaning the acquired data, and then storing it.
[0025] B) Polyphonetic word dictionary construction: construct a polyphonetic word dictionary based on the original data.
[0026] The polyphone dictionary is represented as a dictionary that contains the relationship between characters and pronunciations, and is described by a four-tuple (w, x, y, i).
[0027] Among them, w is the Chinese representation of the polyphone, x is the pinyin representation of w, y is the specific meaning of w, and i represents the i-th pronunciation of w, i∈[1,7].
[0028] C) Polyphone dictionary construction and annotation: According to the polyphone dictionary format, construction and annotation are performed to determine the specific value of the four-tuple (w, x, y, i) of each character in the polyphone dictionary.
[0029] For polyphonetic dictionary, the annotation information needs to calculate the information between pinyin and data. The calculation method is as follows:
[0030] The connection between pronunciation and meaning corresponds to the classification task, which is completed using the point mutual information PMI algorithm. PMI can more accurately measure the correlation between pronunciation and meaning. Its calculation is as follows:
[0031]
[0032] Among them, x represents the pinyin representation of the polyphone w, and y represents the specific meaning of the polyphone w. If x is unrelated to y, then p(x,y)=p(x)p(y), indicating that the pronunciation does not have this meaning; if x is related to y, the larger the ratio of p(x,y) and p(x)p(y), the greater the ratio, indicating that the pronunciation has this meaning.
[0033] Through the PMI algorithm, the pinyin of polyphonetic characters is classified and linked with their specific meanings.
[0034] Let polyphone w i The meaning set is W i ={w1,w2,w3,…,w l}, then the constructed <Pinyin-Meaning> set W is:
[0035]
[0036] Among them, w ijRepresents the set of <pinyin-meaning> consisting of the i-th pronunciation of word Wi and the corresponding meaning, where i∈[1,7],n∈[1,7], and each polyphone may have multiple meanings with different pronunciations.
[0037] According to the obtained <Pinyin-Meaning> set W, based on the definition, the constructed polyphone dictionary can be obtained, and the information contained therein is as described above.
[0038] The detailed algorithm steps for constructing the polyphone dictionary are as follows:
[0039] 1. Input information includes a polyphone set D containing polyphone characters {wi}, pronunciation {xi} and meaning {yi}, an empty dictionary DI, and a threshold σ
[0040] 2. Output information is the target polyphone dictionary DI
[0041] 3. Initialize the polyphone dictionary D, DI
[0042] 4. When {wi},{xi},{yi} are all in D
[0043] 5. When i∈[1,7]
[0044] 6. Calculate the PIM value between X and Y
[0045] 7. If the PIM value is greater than the threshold σ
[0046] 8. Add (xi,yi) to DI
[0047] 9. Otherwise, output "x does not match y and cannot be added to dictionary DI"
[0048] 10. Wait for the loop to end
[0049] 11. Final output target dictionary DI
[0050] D) Adversarial sample generation: Adversarial sample generation specifically includes the following detailed steps, which are described in detail with reference to the accompanying drawings.
[0051] First, perturbation positioning is performed to determine the position of the replacement word.
[0052] Segment the input sample W to obtain W = [w1,w2,w3,w4,…,w n ], where n represents the character length of the input sample. The input sample is then pinyinized and compared with the constructed polyphone dictionary to find the positions of all polyphones in the input sample. For the i-th polyphone in the sequence W, the input score difference between the entire sample and the sample after deleting the word is calculated:
[0053] TDS(w i)=f(w1,…,w i-1 ,w i ,w i+1 ,…,w n )-f(w1,…,w i-1 ,w i+1 ,…,w n )
[0054] Attached Figure 1 The present invention describes in detail the process of obtaining homographs with different meanings and different pronunciations through matrix transformation, which is specifically described as follows:
[0055] The sentence consists of [X1,X2,…,X T ], and then transform it into [X1,X2,…,X T ]
[0056] Among them, X i Represented as a matrix corresponding to Chinese characters.
[0057] Through the content of the present invention, a replacement operation is performed on Chinese characters containing polyphonic characters, that is, Figure 1 The 0 in the red box is changed to 1, and the changed matrix M is obtained. i , you can get the updated X new .
[0058] The detailed algorithm steps for generating adversarial samples are as follows:
[0059] The input information is the polyphone dictionary DI, the text X = [x1, x2, x3, ..., xn], the scoring mechanism TDS, the conversion function T, and the threshold λ
[0060] The output target is the adversarial sample X'
[0061] 1. Segment the text into vectors X = [x1, x2, x3, ..., xn]
[0062] 2. When x is in X
[0063] 3. When i is in the range of 1-n
[0064] 4. i's score Score = TDS(xi)
[0065] 5. Score judgment, if the score is greater than λ
[0066] 6. Output label is yes
[0067] 7 Otherwise, no
[0068] 8. Choose the appropriate x from DI
[0069] 9. Equivalent the index value of x' to T(x indexi )
[0070] 10. Return to the final destination X'
[0071] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this disclosure can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved, and this document does not limit this.
[0072] The above specific implementations do not constitute a limitation on the protection scope of the present disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present disclosure shall be included in the protection scope of the present disclosure.
Claims
1. A character-level adversarial sample generation method for Chinese text classification tasks, characterized by The following steps are involved: A) Data acquisition and storage: Obtain raw data from numerous online reviews and store them; B) polyphonetic word dictionary construction: constructing a polyphonetic word dictionary based on the original data; The polyphone dictionary is represented as a dictionary containing the relationship between characters and pronunciations, and is described by a four-tuple (w, x, y, i); Where w is the Chinese representation of the polyphonetic character, x is the pinyin representation of w, y is the specific meaning of w, i represents the i-th pronunciation of w, i∈[1,7]; For the polyphone dictionary, the information between the pinyin and the data is calculated as follows: The connection between pronunciation and meaning is completed using the point mutual information PMI algorithm, which is calculated as follows: Wherein, x represents the phonetic representation of the polyphone w, and y represents the specific meaning of the polyphone w; if x is unrelated to y, then p(x, y) = p(x)p(y), indicating that the pronunciation does not have this meaning; if x is related to y, the larger the ratio of p(x, y) to p(x)p(y), the greater the ratio, indicating that the pronunciation has this meaning; Through the PMI algorithm, the pinyin of polyphonetic characters is classified and linked with their specific meanings; Let polyphone w i The meaning set is W i ={w1, w2, w3, ..., w n }, then the constructed <Pinyin-Meaning> set W is: Among them, w ij Represents word W i The set of <pinyin-meaning> consisting of the i-th pronunciation and the corresponding meaning, where i∈[1,7], n∈[1,7], and each polyphonic character may have multiple meanings for different pronunciations; According to the set W of <Pinyin-Meaning>, the constructed polyphone dictionary is obtained; C) polyphone dictionary annotation: marking according to the polyphone dictionary format, and determining the specific value of the four-tuple (w, x, y, i) of each word in the polyphone dictionary; D) Adversarial sample generation: taking the original sample as input, using the data in the constructed polyphone dictionary, performing global matching in the original data, finding the word with the same w, performing a replacement operation, and obtaining an adversarial sample with the same shape as the original word but different pronunciation; the main steps are described as follows: First, perturbation positioning is performed to determine the replacement word position; Segment the input sample W to obtain W = [w1, w2, w3, w4, ..., w n ], where n represents the character length of the input sample. The input sample is then pinyinized and compared with the constructed polyphone dictionary to find the positions of all polyphones in the input sample. For the i-th polyphone in the sequence W, the input score difference between the entire sample and the sample after deleting the word is calculated: TDS(w i )=f(w1,…,w i-1 ,w i ,w i+1 ,…,w n )-f(w1,…,w i-1 ,w i+1 ,…,w n ) The sentence consists of [X1, X2, …, X T ]T Chinese characters, and the Hankel matrix operation is performed on them, and they are transformed into [X1,X2,…,X T ] Among them, X i Represented as a matrix corresponding to Chinese characters; Through the content of the present invention, a replacement operation is performed on Chinese characters containing polyphones to obtain a changed matrix M i , you can get the updated X new。 2. According to claim 1, a method for generating character-level adversarial samples for Chinese text classification tasks is characterized by: In step A), the original data includes structured data and unstructured data.
3. The method for generating character-level adversarial samples for Chinese text classification tasks according to claim 1, characterized in that: Inputting the adversarial sample into a target discrimination model to obtain a judgment category of the sample output by the target discrimination model; According to the judgment category, the difference between the current judgment and the original data category is obtained, a disturbance value is obtained, and the disturbance is returned to the adversarial sample generation process; wherein the target judgment category is different from the original category.
