Character-level adversarial sample generation method and device, equipment and storage medium

By constructing a multitone dictionary and large language model, adversarial samples are generated in the dialogue text classification scenario, which solves the problem of adversarial sample attack caused by the difference between dialect and Mandarin, and improves the robustness and security of the model.

CN119066200APending Publication Date: 2024-12-03CHINA PING AN PROPERTY INSURANCE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411208491.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-30
Publication Date
2024-12-03

AI Technical Summary

Technical Problem

In the customer service conversation text classification scenario, the accent difference between the user's dialect and Mandarin may be maliciously exploited to generate adversarial samples to attack the security and reliability of the text classification model.

Method used

By constructing a character-level multi-sounding dictionary, combining a large pre-trained language model, keyword replacement and semantic rewriting of the target dialogue text is generated, adversarial samples are generated, and multi-sounding dictionary and language model are optimized through machine learning to improve the robustness of the model.

Benefits of technology

Without changing the original semantics, the robustness of the text classification model is effectively detected and improved, and high-quality adversarial samples are generated, which solves the impact of the difference between dialect and Mandarin on the ASR system and prevents adversarial sample attacks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119066200A_ABST
    Figure CN119066200A_ABST
Patent Text Reader

Abstract

The invention discloses a character-level adversarial sample generation method and device, equipment and a storage medium, and the method comprises the steps: carrying out the keyword or keyword polyphone replacement and semantic rewriting of an obtained target dialogue text through a constructed character-level polyphone dictionary in combination with a large pre-training language model, and enabling the target dialogue text to be subjected to the keyword or keyword polyphone replacement and semantic rewriting on the premise of not changing the original semanteme. The robustness of a text classification model is effectively detected and improved, meanwhile, due to the fact that disturbance of polyphone replacement is not large, an adversarial sample with high quality can be generated, and the problem that in a customer service dialogue text classification scene, accent differences of users, especially differences between dialects and mandarin, may affect an ASR system is solved. And the difference in pronunciation may be maliciously utilized to generate an adversarial sample, so that a text classification model is attacked.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of text classification, and particularly to a character-level adversarial sample generation method, apparatus, device, and storage medium. Background Art

[0002] With the rapid development of artificial intelligence technology, deep learning has been increasingly widely applied in fields such as text classification and speech recognition. However, while these technologies bring convenience, they also face new challenges, one of which is the attack of adversarial samples. Adversarial samples refer to adding carefully designed tiny perturbations to input data, causing an originally accurate model to make incorrect judgments. This attack method poses a serious threat to the security and reliability of the model.

[0003] In the scenario of customer service dialogue text classification, the accent differences of users, especially the differences between dialects and Mandarin, may affect the automatic speech recognition (ASR) system. For example, there are obvious differences in the pronunciation of polyphonic characters between Cantonese and Mandarin, which may lead to incorrect recognition by the ASR system, thereby affecting the accuracy of text classification. The following are some specific examples of pronunciation differences:

[0004] "Jing": In Cantonese, it may be pronounced as zing (literary reading) or zeng (colloquial reading) according to the context, while in Mandarin, it is usually pronounced as jing.

[0005] "Zheng": In Cantonese, it may be pronounced as zang (literary reading) or zaang (colloquial reading), while in Mandarin, it is pronounced as zheng.

[0006] "Sheng": In Cantonese, the literary reading is sang, and the colloquial reading is saang, while in Mandarin, it is uniformly pronounced as sheng.

[0007] "Geng": In Cantonese, the literary reading is gang, and the colloquial reading is gaang, while in Mandarin, it is uniformly pronounced as geng.

[0008] If these pronunciation differences are not processed, they may be maliciously exploited to generate adversarial samples, thereby attacking the text classification model. Therefore, researching how to generate effective adversarial samples and using these samples to detect and improve the robustness of the model has important practical significance. Summary of the Invention

[0009] The present application provides a character-level adversarial sample generation method, apparatus, device, and storage medium, which solves the technical problem that in the scenario of customer service dialogue text classification, the accent differences of users, especially the differences between dialects and Mandarin, may affect the ASR system, and the pronunciation differences may be maliciously exploited to generate adversarial samples, thereby attacking the text classification model.

[0010] In view of this, the first aspect of the present application provides a method for generating character-level adversarial samples, the method comprising:

[0011] Step S1, constructing a character-level polyphonic dictionary, wherein the polyphonic dictionary contains target pronunciations of several target characters, as well as context information and usage frequency information corresponding to the target pronunciations;

[0012] Step S2, obtaining a target dialogue text, and performing word segmentation and feature extraction on the target dialogue text in sequence to obtain keywords or key words of the target dialogue text;

[0013] Step S3, performing a replacement process on the keyword or key word based on the polyphone dictionary to determine a replacement character or replacement word;

[0014] Step S4, semantically rewriting the target dialogue text based on a large pre-trained language model to obtain a rewritten dialogue text;

[0015] Step S5: combining the rewritten dialogue text and the replacement character or replacement word to generate an adversarial sample of the target dialogue text.

[0016] Optionally, after step S5, the following steps are further included:

[0017] Step S6: input the adversarial sample into the target text classification model for text classification, and obtain the probability results of the adversarial sample in each preset classification;

[0018] Step S7: optimizing the polyphone dictionary and the large pre-trained language model according to the probability result.

[0019] Optionally, the step S7 specifically includes:

[0020] adjusting the context information and usage frequency information corresponding to the target pronunciation of the replacement character or replacement word contained in the polyphone dictionary according to the probability result;

[0021] According to the probability results, parameters of the large pre-trained language model are optimized by machine learning technology.

[0022] Optionally, the target text classification model is specifically a BERT-CNN model.

[0023] Optionally, the step S2 specifically includes:

[0024] Get the target dialogue text;

[0025] Performing word segmentation processing on the target dialogue text based on a deep learning word segmentation model or a tokenize method;

[0026] The keywords or key words in the target conversation text after word segmentation are identified by TF-IDF or Word2Vec.

[0027] A second aspect of the present application provides a device for generating character-level adversarial samples, the device comprising:

[0028] A dictionary construction unit, used to construct a character-level polyphonic dictionary, wherein the polyphonic dictionary contains target pronunciations of a plurality of target characters, and context information and usage frequency information corresponding to the target pronunciations;

[0029] A text preprocessing unit, used to obtain a target dialogue text, and perform word segmentation and feature extraction on the target dialogue text in sequence to obtain keywords or key words of the target dialogue text;

[0030] A first processing unit, configured to perform a replacement process on the keyword or key word based on the polyphone dictionary to determine a replacement character or replacement word;

[0031] A second processing unit is used to semantically rewrite the target dialogue text based on a large pre-trained language model to obtain a rewritten dialogue text;

[0032] A generating unit is used to generate an adversarial sample of the target dialogue text by combining the rewritten dialogue text and the replacement character or replacement word.

[0033] Optionally, it also includes:

[0034] A classification unit, used for inputting the adversarial sample into a target text classification model for text classification, and obtaining a probability result of the adversarial sample in each preset classification;

[0035] An optimization unit is used to optimize the polyphone dictionary and the large pre-trained language model according to the probability result.

[0036] Optionally, the optimization unit is specifically used for:

[0037] adjusting the context information and usage frequency information corresponding to the target pronunciation of the replacement character or replacement word contained in the polyphone dictionary according to the probability result;

[0038] According to the probability results, parameters of the large pre-trained language model are optimized by machine learning technology.

[0039] Optionally, the target text classification model is specifically a BERT-CNN model.

[0040] Optionally, the text preprocessing unit is specifically used to:

[0041] Get the target dialogue text;

[0042] Performing word segmentation processing on the target dialogue text based on a deep learning word segmentation model or a tokenize method;

[0043] The keywords or key words in the target conversation text after word segmentation are identified by TF-IDF or Word2Vec.

[0044] A third aspect of the present application provides a character-level adversarial sample generation device, the device comprising a processor and a memory:

[0045] The memory is used to store program code and transmit the program code to the processor;

[0046] The processor is used to execute the steps of the method for generating character-level adversarial samples as described in the first aspect above according to the instructions in the program code.

[0047] A fourth aspect of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium is used to store program code, and the program code is used to execute the method described in the first aspect above.

[0048] It can be seen from the above technical solutions that the embodiments of the present application have the following advantages:

[0049] In the present application, a method, apparatus, device and storage medium for generating character-level adversarial samples are provided. By constructing a character-level polyphone dictionary and combining it with a large pre-trained language model, the acquired target dialogue text is respectively replaced with polyphones of keywords or key words and semantically rewritten, so that the robustness of the text classification model can be effectively detected and improved without changing the original semantics. At the same time, since the disturbance caused by the polyphone replacement is not large, high-quality adversarial samples can be generated, which solves the technical problem that in the scenario of customer service dialogue text classification, the differences in users' accents, especially the differences between dialects and Mandarin, may affect the ASR system, and the differences in pronunciation may be maliciously used to generate adversarial samples, thereby attacking the text classification model. BRIEF DESCRIPTION OF THE DRAWINGS

[0050] Figure 1 This is a flow chart of a method for generating character-level adversarial samples in an embodiment of the present application;

[0051] Figure 2 This is a schematic diagram of the structure of a device for generating character-level adversarial samples in an embodiment of the present application;

[0052] Figure 3 Schematic diagram of the structure of a character-level adversarial sample generation device in an embodiment of the present application. DETAILED DESCRIPTION

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

[0054] This application designs a character-level adversarial sample generation method, device, equipment and storage medium, which solves the technical problem that in the scenario of customer service conversation text classification, the differences in users' accents, especially the differences between dialects and Mandarin, may affect the ASR system, and the differences in pronunciation may be maliciously used to generate adversarial samples, thereby attacking the text classification model.

[0055] For easier understanding, see Figure 1 , Figure 1 is a flow chart of the method for generating character-level adversarial samples in an embodiment of the present application, such as Figure 1 As shown, specifically:

[0056] Step S1, constructing a character-level polyphonic dictionary, wherein the polyphonic dictionary contains target pronunciations of several target characters, as well as context information and usage frequency information corresponding to the target pronunciations;

[0057] It should be noted that the collection and organization of common polyphones includes but is not limited to their usage in written and spoken language.

[0058] Provide at least two pronunciations for each polyphone, each with detailed context information and usage frequency statistics. In addition, each pronunciation can be constructed in the form of phonemes, corresponding to multiple homophones of different Chinese characters. Especially in the field of dialects, each pronunciation may be converted into a different Chinese character. It is not the traditional case of one word with multiple pronunciations, but more of a case of multiple homophones. Therefore, it is necessary to enrich and optimize the polyphone dictionary.

[0059] Furthermore, natural language processing techniques, such as part-of-speech tagging and semantic analysis, can be used to enrich dictionary content and ensure its accuracy and practicality.

[0060] Step S2, obtaining a target dialogue text, and performing word segmentation and feature extraction on the target dialogue text in sequence to obtain keywords or key words of the target dialogue text;

[0061] Specifically:

[0062] Get the target dialogue text;

[0063] Perform word segmentation on the target dialogue text based on a deep learning word segmentation model or tokenize method;

[0064] Use TF-IDF or Word2Vec to identify keywords or key words in the target conversation text after word segmentation.

[0065] It should be noted that advanced word segmentation algorithms, such as LSTM or Transformer-based deep learning models, are used to improve word segmentation accuracy.

[0066] Apply feature extraction techniques, such as TF-IDF or Word2Vec, to identify keywords and phrases in the text. You can use TF-IDF to extract text keywords and use Word2Vec or BERT to generate word vectors to represent the text semantics.

[0067] Consider the semantic structure of the text to ensure that feature extraction is not limited to surface form but also deeply understands the deeper meaning of the text.

[0068] Furthermore, attention mechanisms can be used in deep learning models to better understand the key parts of the text.

[0069] Step S3, performing a replacement process on the keyword or key word based on the polyphone dictionary to determine a replacement character or replacement word;

[0070] It should be noted that the keywords or key words obtained after word segmentation in the target dialogue text are replaced based on the polyphone dictionary.

[0071] Algorithms can be developed to automatically select replacement words based on context and frequency of use, taking into account text fluency indicators.

[0072] The algorithm should first evaluate the meaning of the word to be replaced in the current context and select the replacement word with the closest semantics to maintain the accuracy of the text. Define and calculate quantitative indicators of fluency, such as grammatical correctness of sentences, reading difficulty, and naturalness. Ensure that the replaced text is semantically coherent and does not cause logical errors or confusion in meaning. Refer to the frequency of use of polyphones in similar contexts and give priority to high-frequency replacement words to improve the naturalness of the replacement. Evaluate the fluency of the replaced text through automated readability tests, such as Flesch Reading Ease or Gunning Fog index. Train machine learning models, such as gradient boosting decision trees or neural networks, to predict the impact of replacement words on fluency. Use iterative optimization methods during the replacement process to continuously adjust the replacement strategy until the best balance between fluency and accuracy is achieved. In addition, language models can be used to evaluate the readability of the replaced text to ensure that the generated text is close to natural language. At the same time, consider the fluency and readability of the text when replacing to avoid generating adversarial samples that are too different from the original meaning.

[0073] Step S4: semantically rewrite the target dialogue text based on the large pre-trained language model to obtain a rewritten dialogue text;

[0074] It should be noted that large pre-trained language models, such as BERT or GPT, are used to perform deep semantic rewriting of the target dialogue text.

[0075] During the rewriting process, the original intent and emotional color of the text are maintained while introducing subtle changes to enhance the concealment of adversarial samples.

[0076] Step S5: Generate an adversarial sample of the target dialogue text by combining the rewritten dialogue text and the replacement characters or words.

[0077] It should be noted that the final adversarial sample is generated by combining the rewritten dialogue text and the replacement characters or words.

[0078] Adversarial examples should be highly concealed and able to affect the classification results of the target model without arousing suspicion.

[0079] Furthermore, after step S5, the following steps are further included:

[0080] Step S6: input the adversarial sample into the target text classification model for text classification, and obtain the probability results of the adversarial sample in each preset classification;

[0081] It should be noted that the generated adversarial samples are input into the target text classification model for classification testing.

[0082] Record the probability results for each preset classification and analyze the model's response to adversarial samples.

[0083] Step S7, optimizing the polyphone dictionary and the large pre-trained language model according to the probability results;

[0084] Specifically:

[0085] Adjusting the context information and usage frequency information corresponding to the target pronunciation of the replacement characters or replacement words contained in the polyphone dictionary according to the probability result;

[0086] Based on the probability results, machine learning techniques are used to optimize the parameters of large pre-trained language models.

[0087] It should be noted that the effectiveness of adversarial samples is evaluated based on the results of classification tests, and the polyphone dictionary and language model are optimized accordingly.

[0088] Adjust the contextual information and usage frequency in the dictionary to improve the adaptability and accuracy of the replacement word or words.

[0089] Use machine learning techniques, such as reinforcement learning, to automatically adjust the parameters of the language model to better meet the needs of adversarial sample generation.

[0090] When optimizing polyphone dictionaries and large language models, you can apply a variety of machine learning techniques to improve the performance and robustness of the model. For example:

[0091] Dictionary Learning, Sparse Coding, Optimization Algorithms, Reinforcement Learning, Fine-Tuning, Quantization Technology, Multimodal Learning, Mixture of Experts (MoE), etc.

[0092] By combining these technologies, the construction of polyphonetic word dictionaries and the training of large language models can be effectively optimized, thereby improving the performance and robustness of the models in dealing with complex language phenomena.

[0093] Furthermore, the target text classification model is specifically a BERT-CNN model.

[0094] It should be noted that the BERT-CNN model is constructed by hierarchically connecting the BERT model with the CNN model. Specifically, the output of each layer of the BERT model is used as the input of the CNN, and the semantic feature vectors of the sentence are extracted through convolution and maximum pooling operations. These feature vectors are then input into a fully connected layer, and finally the classification task is completed through the classifier.

[0095] Parameter initialization: The parameters of the BERT model are initialized with the pre-trained parameters, while the parameters of the CNN model are initialized by randomly generating them according to the normal distribution.

[0096] Finally, the probability of each category is output. The specific formula is as follows:

[0097] Among them, x i Represents the raw score (logit) of the i-th category, which is the model's original prediction value for the input data belonging to the i-th category, usually obtained by the last layer of linear output of the model. Represents x i The exponential of Softmax(x i ) represents the probability of the i-th category calculated by the softmax function.

[0098] Furthermore, the obtained adversarial samples can be tested on different text classification models to evaluate their cross-model robustness.

[0099] See also Figure 2 , Figure 2 Schematic diagram of the structure of the device for generating character-level adversarial samples in the embodiment of the present application. Figure 2 As shown, specifically:

[0100] A dictionary construction unit 201 is used to construct a character-level polyphonic dictionary, wherein the polyphonic dictionary contains target pronunciations of several target characters, as well as context information and usage frequency information corresponding to the target pronunciations;

[0101] It should be noted that the collection and organization of common polyphones includes but is not limited to their usage in written and spoken language.

[0102] Provide at least two pronunciations for each polyphone, each with detailed context information and usage frequency statistics. In addition, each pronunciation can be constructed in the form of phonemes, corresponding to multiple homophones of different Chinese characters. Especially in the field of dialects, each pronunciation may be converted into a different Chinese character. It is not the traditional case of one word with multiple pronunciations, but more of a case of multiple homophones. Therefore, it is necessary to enrich and optimize the polyphone dictionary.

[0103] Furthermore, natural language processing techniques, such as part-of-speech tagging and semantic analysis, can be used to enrich dictionary content and ensure its accuracy and practicality.

[0104] The text preprocessing unit 202 is used to obtain the target dialogue text, and perform word segmentation and feature extraction on the target dialogue text in sequence to obtain the keywords or key words of the target dialogue text;

[0105] Specifically:

[0106] Get the target dialogue text;

[0107] Perform word segmentation on the target dialogue text based on a deep learning word segmentation model or tokenize method;

[0108] Use TF-IDF or Word2Vec to identify keywords or key words in the target conversation text after word segmentation.

[0109] It should be noted that advanced word segmentation algorithms, such as LSTM or Transformer-based deep learning models, are used to improve word segmentation accuracy.

[0110] Apply feature extraction techniques, such as TF-IDF or Word2Vec, to identify keywords and phrases in the text. You can use TF-IDF to extract text keywords and use Word2Vec or BERT to generate word vectors to represent the text semantics.

[0111] Consider the semantic structure of the text to ensure that feature extraction is not limited to surface form but also deeply understands the deeper meaning of the text.

[0112] Furthermore, attention mechanisms can be used in deep learning models to better understand the key parts of the text.

[0113] The first processing unit 203 is used to perform a replacement process on the keyword or key word based on the polyphone dictionary to determine a replacement character or replacement word;

[0114] It should be noted that the keywords or key words obtained after word segmentation in the target dialogue text are replaced based on the polyphone dictionary.

[0115] Algorithms can be developed to automatically select replacement words based on context and frequency of use, taking into account text fluency indicators.

[0116] The algorithm should first evaluate the meaning of the word to be replaced in the current context and select the replacement word with the closest semantics to maintain the accuracy of the text. Define and calculate quantitative indicators of fluency, such as grammatical correctness of sentences, reading difficulty, and naturalness. Ensure that the replaced text is semantically coherent and does not cause logical errors or confusion in meaning. Refer to the frequency of use of polyphones in similar contexts and give priority to high-frequency replacement words to improve the naturalness of the replacement. Evaluate the fluency of the replaced text through automated readability tests, such as Flesch Reading Ease or Gunning Fog index. Train machine learning models, such as gradient boosting decision trees or neural networks, to predict the impact of replacement words on fluency. Use iterative optimization methods during the replacement process to continuously adjust the replacement strategy until the best balance between fluency and accuracy is achieved. In addition, language models can be used to evaluate the readability of the replaced text to ensure that the generated text is close to natural language. At the same time, consider the fluency and readability of the text when replacing to avoid generating adversarial samples that are too different from the original meaning.

[0117] The second processing unit 204 is used to semantically rewrite the target dialogue text based on the large pre-trained language model to obtain a rewritten dialogue text;

[0118] It should be noted that large pre-trained language models, such as BERT or GPT, are used to perform deep semantic rewriting of the target dialogue text.

[0119] During the rewriting process, the original intent and emotional color of the text are maintained while introducing subtle changes to enhance the concealment of adversarial samples.

[0120] The generating unit 205 is used to generate an adversarial sample of the target dialogue text by combining the rewritten dialogue text and the replacement characters or replacement words.

[0121] It should be noted that the final adversarial sample is generated by combining the rewritten dialogue text and the replacement characters or words.

[0122] Adversarial examples should be highly concealed and able to affect the classification results of the target model without arousing suspicion.

[0123] Furthermore, it also includes:

[0124] A classification unit is used to input the adversarial sample into the target text classification model for text classification, and obtain the probability results of the adversarial sample in each preset classification;

[0125] It should be noted that the generated adversarial samples are input into the target text classification model for classification testing.

[0126] Record the probability results for each preset classification and analyze the model's response to adversarial samples.

[0127] The optimization unit is used to optimize the polyphone dictionary and the large pre-trained language model based on the probability results.

[0128] Specifically:

[0129] Adjusting the context information and usage frequency information corresponding to the target pronunciation of the replacement characters or replacement words contained in the polyphone dictionary according to the probability result;

[0130] Based on the probability results, machine learning techniques are used to optimize the parameters of large pre-trained language models.

[0131] It should be noted that the effectiveness of adversarial samples is evaluated based on the results of classification tests, and the polyphone dictionary and language model are optimized accordingly.

[0132] Adjust the contextual information and usage frequency in the dictionary to improve the adaptability and accuracy of the replacement word or words.

[0133] Use machine learning techniques, such as reinforcement learning, to automatically adjust the parameters of the language model to better meet the needs of adversarial sample generation.

[0134] Furthermore, the optimization unit is specifically used for:

[0135] Adjusting the context information and usage frequency information corresponding to the target pronunciation of the replacement characters or replacement words contained in the polyphone dictionary according to the probability result;

[0136] Based on the probability results, machine learning techniques are used to optimize the parameters of large pre-trained language models.

[0137] When optimizing polyphone dictionaries and large language models, you can apply a variety of machine learning techniques to improve the performance and robustness of the model. For example:

[0138] Dictionary Learning, Sparse Coding, Optimization Algorithms, Reinforcement Learning, Fine-Tuning, Quantization Technology, Multimodal Learning, Mixture of Experts (MoE), etc.

[0139] By combining these technologies, the construction of polyphonetic word dictionaries and the training of large language models can be effectively optimized, thereby improving the performance and robustness of the models in dealing with complex language phenomena.

[0140] Furthermore, the target text classification model is specifically a BERT-CNN model.

[0141] It should be noted that the BERT-CNN model is constructed by hierarchically connecting the BERT model with the CNN model. Specifically, the output of each layer of the BERT model is used as the input of the CNN, and the semantic feature vectors of the sentence are extracted through convolution and maximum pooling operations. These feature vectors are then input into a fully connected layer, and finally the classification task is completed through the classifier.

[0142] Parameter initialization: The parameters of the BERT model are initialized with the pre-trained parameters, while the parameters of the CNN model are initialized by randomly generating them according to the normal distribution.

[0143] Finally, the probability of each category is output. The specific formula is as follows:

[0144] Among them, x i Represents the raw score (logit) of the i-th category, which is the model's original prediction value for the input data belonging to the i-th category, usually obtained by the last layer of linear output of the model. Represents x i The exponential of Softmax(x i ) represents the probability of the i-th category calculated by the softmax function.

[0145] Furthermore, the text preprocessing unit is specifically used for:

[0146] Get the target dialogue text;

[0147] Perform word segmentation on the target dialogue text based on a deep learning word segmentation model or tokenize method;

[0148] Use TF-IDF or Word2Vec to identify keywords or key words in the target conversation text after word segmentation.

[0149] Furthermore, the obtained adversarial samples can be tested on different text classification models to evaluate their cross-model robustness.

[0150] The present application embodiment also provides another character-level adversarial sample generation device, such as Figure 3 For the sake of convenience, only the parts related to the embodiments of the present application are shown. For specific technical details not disclosed, please refer to the method part of the embodiments of the present application. The terminal can be any terminal device including a mobile phone, a tablet computer, a personal digital assistant (English full name: Personal Digital Assistant, English abbreviation: PDA), a sales terminal (English full name: Point of Sales, English abbreviation: POS), a car computer, etc., taking the terminal as a mobile phone as an example:

[0151] Figure 3 FIG. 1 is a block diagram showing a partial structure of a mobile phone related to a terminal provided in an embodiment of the present application. Figure 3 The mobile phone includes: a radio frequency (RF) circuit 1010, a memory 1020, an input unit 1030, a display unit 1040, a sensor 1050, an audio circuit 1060, a wireless fidelity (WiFi) module 1070, a processor 1080, and a power supply 1090. Those skilled in the art can understand that Figure 3 The mobile phone structure shown in the figure does not constitute a limitation on the mobile phone, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.

[0152] Combine the following Figure 3 A detailed introduction to the various components of the mobile phone:

[0153] The RF circuit 1010 can be used for receiving and sending signals during information transmission or calls. In particular, after receiving the downlink information of the base station, it is sent to the processor 1080 for processing; in addition, the designed uplink data is sent to the base station. Generally, the RF circuit 1010 includes but is not limited to an antenna, at least one amplifier, a transceiver, a coupler, a low noise amplifier (full name: Low Noise Amplifier, English abbreviation: LNA), a duplexer, etc. In addition, the RF circuit 1010 can also communicate with the network and other devices through wireless communication. The above-mentioned wireless communications may use any communication standard or protocol, including but not limited to Global System of Mobile communications (Global System of Mobile communication, English abbreviation: GSM), General Packet Radio Service (General Packet Radio Service, GPRS), Code Division Multiple Access (Code Division Multiple Access, English abbreviation: CDMA), Wideband Code Division Multiple Access (WCDMA), Long Term Evolution (Long Term Evolution, English abbreviation: LTE), e-mail, Short Messaging Service (SMS), etc.

[0154] The memory 1020 can be used to store software programs and modules. The processor 1080 executes various functional applications and data processing of the mobile phone by running the software programs and modules stored in the memory 1020. The memory 1020 can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area can store data created according to the use of the mobile phone (such as audio data, a phone book, etc.), etc. In addition, the memory 1020 can include a high-speed random access memory, and can also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage devices.

[0155] The input unit 1030 can be used to receive input digital or character information, and to generate key signal input related to the user settings and function control of the mobile phone. Specifically, the input unit 1030 may include a touch panel 1031 and other input devices 1032. The touch panel 1031, also known as a touch screen, can collect the user's touch operation on or near it (such as the user's operation on the touch panel 1031 or near the touch panel 1031 using any suitable object or accessory such as a finger, stylus, etc.), and drive the corresponding connection device according to a pre-set program. Optionally, the touch panel 1031 may include two parts: a touch detection device and a touch controller. Among them, the touch detection device detects the user's touch orientation, detects the signal brought by the touch operation, and transmits the signal to the touch controller; the touch controller receives the touch information from the touch detection device, converts it into contact coordinates, and then sends it to the processor 1080, and can receive and execute commands sent by the processor 1080. In addition, the touch panel 1031 can be implemented in various types such as resistive, capacitive, infrared, and surface acoustic waves. In addition to the touch panel 1031, the input unit 1030 may also include other input devices 1032. Specifically, the other input devices 1032 may include but are not limited to one or more of a physical keyboard, function keys (such as volume control keys, switch keys, etc.), a trackball, a mouse, a joystick, etc.

[0156] The display unit 1040 can be used to display information input by the user or information provided to the user and various menus of the mobile phone. The display unit 1040 may include a display panel 1041. Optionally, the display panel 1041 may be configured in the form of a liquid crystal display (full name in English: Liquid Crystal Display, English abbreviation: LCD), an organic light-emitting diode (full name in English: Organic Light-Emitting Diode, English abbreviation: OLED), etc. Further, the touch panel 1031 may cover the display panel 1041. When the touch panel 1031 detects a touch operation on or near it, it is transmitted to the processor 1080 to determine the type of touch event. Subsequently, the processor 1080 provides a corresponding visual output on the display panel 1041 according to the type of touch event. Although in Figure 3 In the embodiment, the touch panel 1031 and the display panel 1041 are used as two independent components to realize the input and output functions of the mobile phone, but in some embodiments, the touch panel 1031 and the display panel 1041 can be integrated to realize the input and output functions of the mobile phone.

[0157] The mobile phone may also include at least one sensor 1050, such as a light sensor, a motion sensor, and other sensors. Specifically, the light sensor may include an ambient light sensor and a proximity sensor, wherein the ambient light sensor may adjust the brightness of the display panel 1041 according to the brightness of the ambient light, and the proximity sensor may turn off the display panel 1041 and / or the backlight when the mobile phone is moved to the ear. As a type of motion sensor, the accelerometer sensor can detect the magnitude of acceleration in all directions (generally three axes), and can detect the magnitude and direction of gravity when stationary. It can be used for applications that identify the posture of the mobile phone (such as horizontal and vertical screen switching, related games, magnetometer posture calibration), vibration recognition related functions (such as pedometer, tapping), etc.; as for other sensors that can be configured in the mobile phone, such as gyroscopes, barometers, hygrometers, thermometers, infrared sensors, etc., they will not be repeated here.

[0158] The audio circuit 1060, the speaker 1061, and the microphone 1062 can provide an audio interface between the user and the mobile phone. The audio circuit 1060 can transmit the received audio data to the speaker 1061 after converting the received audio data into an electrical signal, which is converted into a sound signal for output; on the other hand, the microphone 1062 converts the collected sound signal into an electrical signal, which is received by the audio circuit 1060 and converted into audio data, and then the audio data is output to the processor 1080 for processing, and then sent to another mobile phone through the RF circuit 1010, or the audio data is output to the memory 1020 for further processing.

[0159] WiFi is a short-range wireless transmission technology. The mobile phone can help users send and receive emails, browse web pages and access streaming media through the WiFi module 1070. It provides users with wireless broadband Internet access. Figure 3 A WiFi module 1070 is shown, but it is understandable that it is not an essential component of the mobile phone and can be omitted as needed without changing the essence of the invention.

[0160] The processor 1080 is the control center of the mobile phone. It uses various interfaces and lines to connect various parts of the entire mobile phone. By running or executing software programs and / or modules stored in the memory 1020 and calling data stored in the memory 1020, it executes various functions of the mobile phone and processes data, thereby monitoring the mobile phone as a whole. Optionally, the processor 1080 may include one or more processing units; preferably, the processor 1080 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface and application programs, etc., and the modem processor mainly processes wireless communications. It is understandable that the above-mentioned modem processor may not be integrated into the processor 1080.

[0161] The mobile phone also includes a power supply 1090 (such as a battery) for supplying power to various components. Preferably, the power supply can be logically connected to the processor 1080 through a power management system, so that the power management system can manage functions such as charging, discharging, and power consumption.

[0162] Although not shown, the mobile phone may also include a camera, a Bluetooth module, etc., which will not be described in detail here.

[0163] In the embodiment of the present application, the processor 1080 included in the terminal also has the following functions:

[0164] Step S1, constructing a character-level polyphonic dictionary, wherein the polyphonic dictionary contains target pronunciations of several target characters, as well as context information and usage frequency information corresponding to the target pronunciations;

[0165] It should be noted that the collection and organization of common polyphones includes but is not limited to their usage in written and spoken language.

[0166] Provide at least two pronunciations for each polyphone, each with detailed context information and usage frequency statistics. In addition, each pronunciation can be constructed in the form of phonemes, corresponding to multiple homophones of different Chinese characters. Especially in the field of dialects, each pronunciation may be converted into a different Chinese character. It is not the traditional case of one word with multiple pronunciations, but more of a case of multiple homophones. Therefore, it is necessary to enrich and optimize the polyphone dictionary.

[0167] Furthermore, natural language processing techniques, such as part-of-speech tagging and semantic analysis, can be used to enrich dictionary content and ensure its accuracy and practicality.

[0168] Step S2, obtaining a target dialogue text, and performing word segmentation and feature extraction on the target dialogue text in sequence to obtain keywords or key words of the target dialogue text;

[0169] Specifically:

[0170] Get the target dialogue text;

[0171] Perform word segmentation on the target dialogue text based on a deep learning word segmentation model or tokenize method;

[0172] Use TF-IDF or Word2Vec to identify keywords or key words in the target conversation text after word segmentation.

[0173] It should be noted that advanced word segmentation algorithms, such as LSTM or Transformer-based deep learning models, are used to improve word segmentation accuracy.

[0174] Apply feature extraction techniques, such as TF-IDF or Word2Vec, to identify keywords and phrases in the text. You can use TF-IDF to extract text keywords and use Word2Vec or BERT to generate word vectors to represent the text semantics.

[0175] Consider the semantic structure of the text to ensure that feature extraction is not limited to surface form but also deeply understands the deeper meaning of the text.

[0176] Furthermore, attention mechanisms can be used in deep learning models to better understand the key parts of the text.

[0177] Step S3, performing a replacement process on the keyword or key word based on the polyphone dictionary to determine a replacement character or replacement word;

[0178] It should be noted that the keywords or key words obtained after word segmentation in the target dialogue text are replaced based on the polyphone dictionary.

[0179] Algorithms can be developed to automatically select replacement words based on context and frequency of use, taking into account text fluency indicators.

[0180] The algorithm should first evaluate the meaning of the word to be replaced in the current context and select the replacement word with the closest semantics to maintain the accuracy of the text. Define and calculate quantitative indicators of fluency, such as grammatical correctness of sentences, reading difficulty, and naturalness. Ensure that the replaced text is semantically coherent and does not cause logical errors or confusion in meaning. Refer to the frequency of use of polyphones in similar contexts and give priority to high-frequency replacement words to improve the naturalness of the replacement. Evaluate the fluency of the replaced text through automated readability tests, such as Flesch Reading Ease or Gunning Fog index. Train machine learning models, such as gradient boosting decision trees or neural networks, to predict the impact of replacement words on fluency. Use iterative optimization methods during the replacement process to continuously adjust the replacement strategy until the best balance between fluency and accuracy is achieved. In addition, language models can be used to evaluate the readability of the replaced text to ensure that the generated text is close to natural language. At the same time, consider the fluency and readability of the text when replacing to avoid generating adversarial samples that are too different from the original meaning.

[0181] Step S4: semantically rewrite the target dialogue text based on the large pre-trained language model to obtain the rewritten dialogue text

[0182] It should be noted that large pre-trained language models, such as BERT or GPT, are used to perform deep semantic rewriting of the target dialogue text.

[0183] During the rewriting process, the original intent and emotional color of the text are maintained while introducing subtle changes to enhance the concealment of adversarial samples.

[0184] Step S5: Generate an adversarial sample of the target dialogue text by combining the rewritten dialogue text and the replacement characters or words.

[0185] It should be noted that the final adversarial sample is generated by combining the rewritten dialogue text and the replacement characters or words.

[0186] Adversarial examples should be highly concealed and able to affect the classification results of the target model without arousing suspicion.

[0187] Furthermore, after step S5, the following steps are further included:

[0188] Step S6: input the adversarial sample into the target text classification model for text classification, and obtain the probability results of the adversarial sample in each preset classification;

[0189] It should be noted that the generated adversarial samples are input into the target text classification model for classification testing.

[0190] Record the probability results for each preset classification and analyze the model's response to adversarial samples.

[0191] Step S7, optimizing the polyphone dictionary and the large pre-trained language model according to the probability results;

[0192] Specifically:

[0193] Adjusting the context information and usage frequency information corresponding to the target pronunciation of the replacement characters or replacement words contained in the polyphone dictionary according to the probability result;

[0194] Based on the probability results, machine learning techniques are used to optimize the parameters of large pre-trained language models.

[0195] It should be noted that the effectiveness of adversarial samples is evaluated based on the results of classification tests, and the polyphone dictionary and language model are optimized accordingly.

[0196] Adjust the contextual information and usage frequency in the dictionary to improve the adaptability and accuracy of the replacement word or words.

[0197] Use machine learning techniques, such as reinforcement learning, to automatically adjust the parameters of the language model to better meet the needs of adversarial sample generation.

[0198] When optimizing polyphone dictionaries and large language models, you can apply a variety of machine learning techniques to improve the performance and robustness of the model. For example:

[0199] Dictionary Learning, Sparse Coding, Optimization Algorithms, Reinforcement Learning, Fine-Tuning, Quantization Technology, Multimodal Learning, Mixture of Experts (MoE), etc.

[0200] By combining these technologies, the construction of polyphonetic word dictionaries and the training of large language models can be effectively optimized, thereby improving the performance and robustness of the models in dealing with complex language phenomena.

[0201] Furthermore, the target text classification model is specifically a BERT-CNN model.

[0202] It should be noted that the BERT-CNN model is constructed by hierarchically connecting the BERT model with the CNN model. Specifically, the output of each layer of the BERT model is used as the input of the CNN, and the semantic feature vectors of the sentence are extracted through convolution and maximum pooling operations. These feature vectors are then input into a fully connected layer, and finally the classification task is completed through the classifier.

[0203] Parameter initialization: The parameters of the BERT model are initialized with the pre-trained parameters, while the parameters of the CNN model are initialized by randomly generating them according to the normal distribution.

[0204] Finally, the probability of each category is output. The specific formula is as follows:

[0205] Among them, x i Represents the raw score (logit) of the i-th category, which is the original prediction value of the model for the input data belonging to the i-th category, usually obtained by the last layer of linear output of the model, Softmax(x i ) represents the probability of the i-th category calculated by the softmax function.

[0206] Furthermore, the obtained adversarial samples can be tested on different text classification models to evaluate their cross-model robustness.

[0207] An embodiment of the present application also provides a computer-readable storage medium for storing program code, which is used to execute any implementation of a character-level adversarial sample generation method described in the aforementioned embodiments.

[0208] In the embodiments of the present application, a method, apparatus, device and storage medium for generating character-level adversarial samples are provided. By constructing a character-level polyphone dictionary and combining it with a large pre-trained language model, the acquired target dialogue text is respectively replaced with polyphones of keywords or key words and semantically rewritten, so that the robustness of the text classification model can be effectively detected and improved without changing the original semantics. At the same time, since the disturbance caused by the polyphone replacement is not large, high-quality adversarial samples can be generated, which solves the technical problem that in the scenario of customer service dialogue text classification, the differences in users' accents, especially the differences between dialects and Mandarin, may affect the ASR system, and the differences in pronunciation may be maliciously used to generate adversarial samples, thereby attacking the text classification model.

[0209] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0210] The terms "first", "second", "third", "fourth", etc. (if any) in the specification of the present application 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 interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein, for example. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising 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.

[0211] It should be understood that in the present application, "at least one (item)" means one or more, and "plurality" means two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the objects associated before and after are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.

[0212] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.

[0213] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0214] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0215] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (full name in English: Read-Only Memory, English abbreviation: ROM), random access memory (full name in English: Random Access Memory, English abbreviation: RAM), disk or optical disk and other media that can store program codes.

[0216] As described above, the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.

Claims

1. A method for generating character-level adversarial samples, characterized in that: include: Step S1, constructing a character-level polyphonic dictionary, wherein the polyphonic dictionary contains target pronunciations of several target characters, as well as context information and usage frequency information corresponding to the target pronunciations; Step S2, obtaining a target dialogue text, and performing word segmentation and feature extraction on the target dialogue text in sequence to obtain keywords or key words of the target dialogue text; Step S3, performing a replacement process on the keyword or key word based on the polyphone dictionary to determine a replacement character or replacement word; Step S4, semantically rewriting the target dialogue text based on a large pre-trained language model to obtain a rewritten dialogue text; Step S5: combining the rewritten dialogue text and the replacement character or replacement word to generate an adversarial sample of the target dialogue text.

2. The character-level adversarial sample generation method according to claim 1, characterized in that: After step S5, the following steps are also included: Step S6: input the adversarial sample into the target text classification model for text classification, and obtain the probability results of the adversarial sample in each preset classification; Step S7: optimizing the polyphone dictionary and the large pre-trained language model according to the probability result.

3. The character-level adversarial sample generation method according to claim 2, characterized in that: The step S7 specifically includes: adjusting the context information and usage frequency information corresponding to the target pronunciation of the replacement character or replacement word contained in the polyphone dictionary according to the probability result; According to the probability results, parameters of the large pre-trained language model are optimized by machine learning technology.

4. The character-level adversarial sample generation method according to claim 2, characterized in that: The target text classification model is specifically a BERT-CNN model.

5. The character-level adversarial sample generation method according to claim 1, characterized in that: The step S2 specifically includes: Get the target dialogue text; Performing word segmentation processing on the target dialogue text based on a deep learning word segmentation model or a tokenize method; The keywords or key words in the target conversation text after word segmentation are identified by TF-IDF or Word2Vec.

6. The method for generating character-level adversarial samples according to claim 4, characterized in that: Before step S6, the following steps are also included: Build a BERT-CNN model and connect the BERT model with the CNN model hierarchically; Initializing the parameters of the BERT model using the parameters obtained through pre-training; The parameters of the CNN model are initialized in a random manner that satisfies the normal distribution.

7. The method for generating character-level adversarial samples according to claim 6, characterized in that: The probability results are specifically: Among them, x i represents the raw score of the ith category, Represents x i The exponential of Softmax(x i ) represents the probability of the i-th category calculated by the softmax function.

8. A character-level adversarial sample generation device, characterized in that: include: A dictionary construction unit, used to construct a character-level polyphonic dictionary, wherein the polyphonic dictionary contains target pronunciations of a plurality of target characters, and context information and usage frequency information corresponding to the target pronunciations; A text preprocessing unit, used to obtain a target dialogue text, and perform word segmentation and feature extraction on the target dialogue text in sequence to obtain keywords or key words of the target dialogue text; A first processing unit, configured to perform a replacement process on the keyword or key word based on the polyphone dictionary to determine a replacement character or replacement word; A second processing unit is used to semantically rewrite the target dialogue text based on a large pre-trained language model to obtain a rewritten dialogue text; A generating unit is used to generate an adversarial sample of the target dialogue text by combining the rewritten dialogue text and the replacement character or replacement word.

9. A character-level adversarial sample generation device, characterized in that: The device comprises a processor and a memory: The memory is used to store program code and transmit the program code to the processor; The processor is used to execute the character-level adversarial sample generation method described in any one of claims 1-5 according to the instructions in the program code.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium is used to store program code, and the program code is used to execute the character-level adversarial sample generation method described in any one of claims 1-5.