CN117521674B - Method, device, computer equipment and storage medium for generating countermeasure information - Google Patents

Method, device, computer equipment and storage medium for generating countermeasure information Download PDF

Info

Publication number
CN117521674B
CN117521674B CN202410023557.0A CN202410023557A CN117521674B CN 117521674 B CN117521674 B CN 117521674B CN 202410023557 A CN202410023557 A CN 202410023557A CN 117521674 B CN117521674 B CN 117521674B
Authority
CN
China
Prior art keywords
information
countermeasure
layer
coding
result
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202410023557.0A
Other languages
Chinese (zh)
Other versions
CN117521674A (en
Inventor
陆笛
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Tencent Technology Shenzhen Co Ltd
Original Assignee
Tencent Technology Shenzhen Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Tencent Technology Shenzhen Co Ltd filed Critical Tencent Technology Shenzhen Co Ltd
Priority to CN202410023557.0A priority Critical patent/CN117521674B/en
Publication of CN117521674A publication Critical patent/CN117521674A/en
Application granted granted Critical
Publication of CN117521674B publication Critical patent/CN117521674B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/30Semantic analysis
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/30Information retrieval; Database structures therefor; File system structures therefor of unstructured textual data
    • G06F16/35Clustering; Classification
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/40Processing or translation of natural language
    • G06F40/58Use of machine translation, e.g. for multi-lingual retrieval, for server-side translation for client devices or for real-time translation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/04Architecture, e.g. interconnection topology
    • G06N3/045Combinations of networks
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/04Architecture, e.g. interconnection topology
    • G06N3/0475Generative networks
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/08Learning methods
    • G06N3/094Adversarial learning

Abstract

The present application relates to a method, an apparatus, a computer device, a storage medium and a computer program product for generating countermeasure information. The method can be applied to cloud technology, artificial intelligence and other scenes, and comprises the following steps: when a countermeasure information generation task for the original information is received, selecting target countermeasure instruction information from at least one candidate countermeasure instruction information of a countermeasure instruction library; performing semantic coding on spliced information obtained by splicing the original information and the target countermeasure indication information to obtain a semantic vector; performing attention processing on the semantic vector and the spliced information to obtain a prediction vector; and generating countermeasure information under the countermeasure type indicated by the target countermeasure indication information based on the prediction vector, wherein the countermeasure information is used for training a first language model, and the first language model is used for executing a language information processing task. The method can improve the processing effect of the language model on the language information processing task.

Description

Method, device, computer equipment and storage medium for generating countermeasure information
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a method and apparatus for generating countermeasure information, a computer device, and a storage medium.
Background
In natural language processing tasks, a text challenge attack method based on challenge samples is generally employed to evaluate the robustness of a language model or to train a highly robust language processing model.
At present, a manner of obtaining an countermeasure sample is mainly to add disturbance on the sample, however, due to the technical limitation of disturbance addition, the added disturbance cannot enable the model to have the understanding capability of complex semantics, so that the processing effect of a language information processing task of the language model is poor.
Disclosure of Invention
In view of the foregoing, it is desirable to provide a countermeasure information generation method, apparatus, computer device, and storage medium that can improve the processing effect of a language information processing task.
In a first aspect, the present application provides a method for generating challenge information. The method comprises the following steps:
when a countermeasure information generation task for the original information is received, selecting target countermeasure instruction information from at least one candidate countermeasure instruction information of a countermeasure instruction library;
performing semantic coding on spliced information obtained by splicing the original information and the target countermeasure indication information to obtain a semantic vector;
performing attention processing on the semantic vector and the spliced information to obtain a prediction vector;
And generating countermeasure information under the countermeasure type indicated by the target countermeasure indication information based on the prediction vector, wherein the countermeasure information is used for training a first language model, and the first language model is used for executing a language information processing task.
In a second aspect, the present application further provides a device for generating countermeasure information. The device comprises:
a countermeasure instruction information selection module for selecting target countermeasure instruction information from at least one candidate countermeasure instruction information of a countermeasure instruction library when a countermeasure information generation task for the original information is received;
the semantic coding module is used for carrying out semantic coding on the spliced information obtained by splicing the original information and the target countermeasure indication information to obtain a semantic vector;
the vector prediction module is used for carrying out attention processing on the semantic vector and the spliced information to obtain a prediction vector;
and the information generation module is used for generating countermeasure information under the countermeasure type indicated by the target countermeasure indication information based on the prediction vector, wherein the countermeasure information is used for training a first language model, and the first language model is used for executing a language information processing task.
In a third aspect, the present application also provides a computer device. The computer device comprises a memory storing a computer program and a processor which when executing the computer program performs the steps of:
When a countermeasure information generation task for the original information is received, selecting target countermeasure instruction information from at least one candidate countermeasure instruction information of a countermeasure instruction library;
performing semantic coding on spliced information obtained by splicing the original information and the target countermeasure indication information to obtain a semantic vector;
performing attention processing on the semantic vector and the spliced information to obtain a prediction vector;
and generating countermeasure information under the countermeasure type indicated by the target countermeasure indication information based on the prediction vector, wherein the countermeasure information is used for training a first language model, and the first language model is used for executing a language information processing task.
In a fourth aspect, the present application also provides a computer-readable storage medium. The computer readable storage medium having stored thereon a computer program which when executed by a processor performs the steps of:
when a countermeasure information generation task for the original information is received, selecting target countermeasure instruction information from at least one candidate countermeasure instruction information of a countermeasure instruction library;
performing semantic coding on spliced information obtained by splicing the original information and the target countermeasure indication information to obtain a semantic vector;
Performing attention processing on the semantic vector and the spliced information to obtain a prediction vector;
and generating countermeasure information under the countermeasure type indicated by the target countermeasure indication information based on the prediction vector, wherein the countermeasure information is used for training a first language model, and the first language model is used for executing a language information processing task.
In a fifth aspect, the present application also provides a computer program product. The computer program product comprises a computer program which, when executed by a processor, implements the steps of:
when a countermeasure information generation task for the original information is received, selecting target countermeasure instruction information from at least one candidate countermeasure instruction information of a countermeasure instruction library;
performing semantic coding on spliced information obtained by splicing the original information and the target countermeasure indication information to obtain a semantic vector;
performing attention processing on the semantic vector and the spliced information to obtain a prediction vector;
and generating countermeasure information under the countermeasure type indicated by the target countermeasure indication information based on the prediction vector, wherein the countermeasure information is used for training a first language model, and the first language model is used for executing a language information processing task.
The above-described countermeasure information generation method, apparatus, computer device, storage medium, and computer program product, by constructing in advance a countermeasure instruction library containing at least one candidate countermeasure instruction information, each of which is used for instructing generation of countermeasure information under a corresponding countermeasure type, so that when a countermeasure information generation task for original information is received, target countermeasure instruction information can be selected from at least one candidate countermeasure instruction information of the countermeasure instruction library, generation of target countermeasure instruction information guiding countermeasure information can be realized by encoding and decoding spliced information of the original information and the target countermeasure instruction information, and finally countermeasure information conforming to expectations can be obtained; in addition, in the process of generating the countermeasure information, semantic vectors carrying context semantics can be obtained by carrying out semantic coding on spliced information, and the objective countermeasure indication information can fully play a role in guiding in the process of generating the countermeasure information by carrying out attention processing on the semantic vectors and the spliced information, so that the countermeasure information which is more in accordance with expectations is obtained; in addition, different candidate countermeasure fingers can be adopted for the same original information to indicate countermeasure information under different countermeasure types, so that diversity of the countermeasure information is improved, and the first language model is trained by using accurate and rich countermeasure information, so that the first language model can better adapt to and process various complex and challenging language information, and the processing effect of the first language model on language information processing tasks is improved.
Drawings
FIG. 1 is an application environment diagram of a method of generating challenge information in one embodiment;
FIG. 2 is a flow chart of a method for generating challenge information in one embodiment;
FIG. 3 is a schematic diagram of an encoder in one embodiment;
FIG. 4 is a schematic diagram of a decoder in one embodiment;
FIG. 5 is a schematic diagram of a dialog page in one embodiment;
FIG. 6 is a flowchart of a method for generating challenge information according to another embodiment;
FIG. 7 is a schematic diagram of a challenge scenario in one embodiment;
FIG. 8 is a schematic diagram of a model performance evaluation scenario in one embodiment;
FIG. 9 is a schematic diagram of a model training scenario in one embodiment;
FIG. 10 is a flow chart of a method of generating challenge information in yet another embodiment;
FIG. 11 is a flow diagram of the challenge-indicator library construction step in one embodiment;
FIG. 12 is a flowchart of a challenge instruction library construction step in another embodiment;
FIG. 13 is a schematic diagram of a challenge information generating process in one embodiment;
FIG. 14 is a block diagram showing a construction of a countermeasure information generation apparatus in one embodiment;
fig. 15 is a block diagram showing the construction of a countermeasure information generation apparatus in another embodiment;
Fig. 16 is an internal structural view of a computer device in one embodiment.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the present application will be further described in detail with reference to the accompanying drawings and examples. It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the present application.
The application provides a method for generating countermeasure information, which relates to the technologies of artificial intelligence such as machine learning, natural language processing and the like, wherein:
artificial intelligence (Artificial Intelligence, AI) is the theory, method, technique and application system that uses a digital computer or a machine controlled by a digital computer to simulate, extend and extend human intelligence, sense the environment, acquire knowledge and use the knowledge to obtain optimal results. In other words, artificial intelligence is an integrated technology of computer science that attempts to understand the essence of intelligence and to produce a new intelligent machine that can react in a similar way to human intelligence. Artificial intelligence, i.e. research on design principles and implementation methods of various intelligent machines, enables the machines to have functions of sensing, reasoning and decision.
The artificial intelligence technology is a comprehensive subject, and relates to the technology with wide fields, namely the technology with a hardware level and the technology with a software level. Artificial intelligence infrastructure technologies generally include, for example, sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, big data processing technologies, pre-training model technologies, operation/interaction systems, mechatronics, and the like. The pre-training model is also called a large model and a basic model, and can be widely applied to all large-direction downstream tasks of artificial intelligence after fine adjustment. The artificial intelligence software technology mainly comprises a computer vision technology, a voice processing technology, a natural language processing technology, machine learning/deep learning and other directions.
Machine Learning (ML) is a multi-domain interdisciplinary, involving multiple disciplines such as probability theory, statistics, approximation theory, convex analysis, algorithm complexity theory, etc. It is specially studied how a computer simulates or implements learning behavior of a human to acquire new knowledge or skills, and reorganizes existing knowledge structures to continuously improve own performance. Machine learning is the core of artificial intelligence, a fundamental approach to letting computers have intelligence, which is applied throughout various areas of artificial intelligence. Machine learning and deep learning typically include techniques such as artificial neural networks, confidence networks, reinforcement learning, transfer learning, induction learning, teaching learning, and the like. The pre-training model is the latest development result of deep learning, and integrates the technology.
The Pre-training model (Pre-training model), also called a matrix model and a large model, refers to a deep neural network (Deep neural network, DNN) with large parameters, trains massive unlabeled data, utilizes the function approximation capability of the large-parameter DNN to enable PTM to extract common features on the data, and is suitable for downstream tasks through fine tuning (fine tuning), efficient fine tuning (PEFT) of parameters, prompt-tuning and other technologies. Therefore, the pre-training model can achieve ideal effects in a small sample (Few-shot) or Zero sample (Zero-shot) scene. PTM can be classified according to the data modality of the process into a language model (ELMO, BERT, GPT), a visual model (swin-transducer, viT, V-MOE), a speech model (VALL-E), a multi-modal model (ViBERT, CLIP, flamingo, gato), etc., wherein a multi-modal model refers to a model that builds a representation of the characteristics of two or more data modalities. The pre-training model is an important tool for outputting Artificial Intelligence Generation Content (AIGC), and can also be used as a general interface for connecting a plurality of specific task models.
Natural language processing (Nature Language processing, NLP) is an important direction in the fields of computer science and artificial intelligence. It is studying various theories and methods that enable effective communication between a person and a computer in natural language. The natural language processing relates to natural language, namely the language used by people in daily life, and is closely researched with linguistics; and also to computer science and mathematics. An important technique for model training in the artificial intelligence domain, a pre-training model, is developed from a large language model (Large Language Model) in the NLP domain. Through fine tuning, the large language model can be widely applied to downstream tasks. Natural language processing techniques typically include text processing, semantic understanding, machine translation, robotic questions and answers, knowledge graph techniques, and the like.
With research and advancement of artificial intelligence technology, research and application of artificial intelligence technology is being developed in various fields, such as common smart home, smart wearable devices, virtual assistants, smart speakers, smart marketing, unmanned, autopilot, unmanned, digital twin, virtual man, robot, artificial Intelligence Generated Content (AIGC), conversational interactions, smart medical, smart customer service, game AI, etc., and it is believed that with the development of technology, artificial intelligence technology will be applied in more fields and with increasing importance value.
The method for generating the countermeasure information provided by the embodiment of the application can be applied to an application environment shown in fig. 1. Wherein the terminal 102 communicates with the server 104 via a network. The data storage system may store data that the server 104 needs to process. The data storage system may be provided separately, and the data storage system may be integrated on the server 104, or may be placed on a cloud or other server. The method of generating the countermeasure information may be performed by the terminal 102 or the server 104 alone or by the terminal 102 and the server 104 in cooperation. In some embodiments, the method of generating the pair of countermeasure information is performed by the terminal 102, and when the terminal 102 receives a countermeasure information generation task for the original information, the target countermeasure instruction information is selected from at least one candidate countermeasure instruction information of the countermeasure instruction library; carrying out semantic coding on spliced information obtained by splicing the original information and the target countermeasure indication information to obtain a semantic vector; performing attention processing on the semantic vector and the spliced information to obtain a prediction vector; the countermeasure information under the countermeasure type indicated by the target countermeasure instruction information is generated based on the prediction vector, the countermeasure information is used for training a first language model, and the first language model is used for executing the language information processing task.
The terminal 102 may be, but not limited to, various desktop computers, notebook computers, smart phones, tablet computers, internet of things devices, and portable wearable devices, where the internet of things devices may be smart speakers, smart televisions, smart air conditioners, smart vehicle devices, and the like. The portable wearable device may be a smart watch, smart bracelet, headset, or the like. The server 104 may be an independent physical server, a server cluster or a distributed system formed by a plurality of physical servers, or a cloud server providing cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDNs, basic cloud computing services such as big data and artificial intelligence platforms, and the like. The terminal 102 and the server 104 may be directly or indirectly connected through wired or wireless communication, which is not limited herein.
In one embodiment, as shown in fig. 2, a method of generating challenge information is provided, which may be performed by a computer device, which may be, for example, the terminal 102 or the server 104 shown in fig. 1. The method may comprise the steps of:
S202, when a countermeasure information generation task for the original information is received, target countermeasure instruction information is selected from at least one candidate countermeasure instruction information of the countermeasure instruction library.
The original information is basic data for generating countermeasure information, and the original information can be text information, and can be a phrase, a sentence, a text, an article and the like. For example, the original information is "dishonest arrival, gold and stone arrival".
The challenge information generating task refers to a task for creating challenge information, which is specifically designed to test or enhance the robustness and performance of a machine learning model, and the challenge information often simulates interference and challenges that may be encountered in practical applications, such as noise data, fraudulent input, etc., and by training the model to identify and process such challenge information, the robustness of the model can be significantly enhanced, making it better to face real-world complex and unpredictable data.
The countermeasure indication library is a pre-constructed storage system, and mainly stores various candidate countermeasure indication information, wherein the candidate countermeasure indication information is used for guiding or guiding the generation of countermeasure information under a specific countermeasure type, and each candidate countermeasure information corresponds to one countermeasure type, for example, the indication library comprises candidate countermeasure indication information 1, candidate countermeasure indication information 2, candidate countermeasure indication information 3 and candidate countermeasure indication information 4, wherein the candidate countermeasure indication information 1 is used for reorganizing the information to enable the information to have more fluency, the candidate countermeasure indication information 2 is used for summarizing the concept by using a simpler language, the candidate countermeasure indication information 3 is used for "expressing the concept by using a more formal language," the candidate countermeasure indication information 4 is used for describing the scene by using a more vivid adjective word, the countermeasure indication type corresponding to the candidate countermeasure indication information 1 is used for "structural reorganization," the countermeasure indication type corresponding to the candidate countermeasure indication information 2 is "simplified representation," the countermeasure indication type corresponding to the candidate countermeasure indication information 3 is used for "style adjustment," the candidate countermeasure indication information 4 is used for "descriptive enhancement" corresponding to the countermeasure indication information, the candidate countermeasure indication information 1 is used for guiding the guide for guiding the more fluency, the candidate countermeasure indication information is used for improving the original information by using a more formal language model or changing the original text model corresponding to the more vivid fluctuation, making the scene description more vivid and concrete.
The target countermeasure indication information refers to specific countermeasure indication information selected from the countermeasure indication library.
It should be noted that, in the existing scheme, the challenge information is mainly generated by adopting a challenge information generating method based on a word granularity or a word granularity, that is, a disturbance is added on a word level to generate the challenge information, the disturbance of the word granularity or the word granularity cannot enable the model to have understanding capability of complex semantics, and each embodiment of the challenge information generating method provided in the application is a method for adding the disturbance on a sentence level to generate the challenge information, which may also be referred to as a challenge information generating method based on the sentence granularity, and based on a challenge instruction library, diversified challenge information may be generated, so that the first language model may be trained by using accurate and abundant challenge information subsequently, so that the first language model may better adapt and process various complex and challenging language information, and thus the processing effect of the first language model on the language information processing task is improved.
Specifically, when it is necessary to train a language model using the original information or evaluate the performance of the pre-trained language model, the computer device triggers an countermeasure information generation task for the original information, determines a corresponding information selection policy based on the countermeasure information generation task when the countermeasure information generation task for the original information is received, and selects target countermeasure instruction information from at least one candidate countermeasure instruction information stored in the countermeasure instruction library in accordance with the determined information selection policy.
The information selection strategy can be random selection, sequential selection or conditional selection, wherein the random selection refers to that one or more candidate countermeasure indication information is selected from the indication library randomly to serve as target countermeasure information; the order selection refers to selecting one or more candidate countermeasure indication information as target countermeasure information according to the order of the candidate countermeasure indication information in the countermeasure indication library, wherein the order can be the order of the candidate countermeasure indication information and the order after the candidate countermeasure indication information is ordered according to a preset standard, or can be the addition order of the candidate countermeasure indication information into the countermeasure indication library; the condition selection refers to selecting one or more candidate countermeasure indication information from the countermeasure indication library as target countermeasure information according to a selection condition specified by the countermeasure information generation task, and the selection condition can be specifically a characteristic condition based on original information or a selection condition based on a point to be reinforced of a model to be processed.
Taking the original information and the countermeasure information of the original information as examples to train a natural language processing model for emotion analysis to explain the process of selecting target countermeasure instruction information, assuming that a natural language processing model for emotion analysis needs to be trained, the task of the model is to identify emotion tendencies in user comments, wherein the emotion tendencies specifically comprise positive emotion, negative emotion or neutral emotion, the user comments refer to comments of a user on a movie, such as some user comments concentrate on the episodes of the movie, and other comments focus on performances of actors, when a countermeasure information generating task aiming at a certain original user comment is received by computer equipment, the original user comment can be subjected to feature analysis to obtain attribute information of the original user comment, and if the attribute information characterizes the episodes of the original user comment focused on the movie, candidate countermeasure instruction information for guiding the countermeasure information for generating rich movie episodes can be selected from a countermeasure instruction library as target countermeasure instruction information, so that the recognition capability of the model on the emotion in the user comments related to complex episodes of the movie is improved when the obtained countermeasure information is trained in the natural language processing model for emotion analysis; if the attribute information characterizes that the original user comment focuses on the actors of the movie, candidate countermeasure indication information used for guiding the countermeasure information for generating rich actor performance modes can be selected from the countermeasure indication library as target countermeasure indication information, so that the recognition capability of the model on emotion tendencies in the user comments related to complex performance modes is improved when a natural language processing model for emotion analysis is trained by using the obtained countermeasure information.
It may be understood that the countermeasure information generating task for a certain original information may further specify the generation number of the countermeasure information, for example, the preset number is h, and then h candidate countermeasure information may be selected from at least one candidate countermeasure information in the countermeasure instruction library as target countermeasure instruction information, specifically, one candidate countermeasure information may be selected from the countermeasure instruction library as target countermeasure instruction information, then steps S204 to S208 are performed, and then the step of selecting one candidate countermeasure information from the countermeasure instruction library as target countermeasure instruction information is performed again until h countermeasure information is obtained; the h candidate countermeasure indication information may be directly selected from the countermeasure indication library as the target countermeasure indication information, and then steps S204 to S208 are performed for each selected target countermeasure indication information to obtain h countermeasure information.
S204, performing semantic coding on the spliced information obtained by splicing the original information and the target countermeasure indication information to obtain a semantic vector.
The splicing refers to a process of connecting two or more character strings, sequences, vectors or data structures together to form a single new entity, and the splicing information refers to the new entity formed by connecting two or more character strings, sequences, vectors or data structures together. For example, the original information is "jingzheng", the target countermeasure instruction information is "coming a sentence close to the original intention", and the obtained spliced information is "jingzheng", the jingshi is coming a sentence close to the original intention ".
Semantic coding refers to capturing semantic content in spliced information to convert the semantic content into a vector representation, wherein the vector representation is a semantic vector.
Specifically, the computer device may splice the original information and the selected target countermeasure indication information to obtain spliced information, input each spliced information into a pre-trained language model, and perform semantic coding on the spliced information through the language model to obtain a semantic vector corresponding to the spliced information.
The pre-trained language model is a deep learning model trained on a large-scale text data set, and can be a model BERT, GPT, transformer and the like.
In one embodiment, the concatenation information input to the pre-trained language model may be a vector representation sequence obtained by concatenation, after the computer device concatenates the original information and the selected target countermeasure instruction information to obtain concatenation information, word segmentation processing may be performed on the concatenation information to obtain each word, and each word is converted by using a word embedding layer to obtain a vector representation corresponding to each word, and the vector representations corresponding to each word are arranged according to the sequence of each word in the concatenation information to obtain a vector representation sequence corresponding to the concatenation information, and the vector representation sequence is input to the pre-trained language processing model.
The Word embedding layer is used for converting words into numerical vectors with fixed lengths, namely each Word is mapped into a point in a high-dimensional space, the position of the point reflects the semantic characteristics of the Word and the relation with other words, and the Word embedding layer can be Word2Vec, gloVe and the like.
S206, performing attention processing on the semantic vector and the spliced information to obtain a prediction vector.
Wherein the attention process (Attention Mechanism) is used for processing sequence-to-sequence tasks such as machine translation, text summarization, dialog generation, etc., for focusing on specific parts of the input sequence when processing sequence data.
The prediction vector is a comprehensive representation of the splice information (including the original text and the countermeasure indication information), that is, the result of processing the splice information.
Specifically, after performing semantic coding on the spliced information to obtain a semantic vector of the spliced information, the computer device may first fuse the semantic vector with the spliced information represented by the vector to obtain fused information, and perform attention processing on the fused information to obtain a prediction vector.
The fusion can be specifically splicing, adding, multiplying and the like, wherein the splicing refers to directly connecting the semantic vector and the splicing information represented by the vector in series according to a certain sequence, the adding can be specifically weighted average, and the weighted average refers to giving different weights according to the importance of the semantic vector and the splicing information represented by the vector and then carrying out weighted combination; the multiplication can be specifically matrix punishment, wherein matrix multiplication refers to that spliced data of semantic vectors and vector representations are regarded as two matrices, and matrix multiplication operation is performed to obtain fusion data.
The process of fusing the semantic vector and the splicing information represented by the vector may specifically be to directly fuse the semantic vector and the splicing information represented by the vector to obtain fused information; or performing self-attention processing on the vector-represented spliced information to obtain a processed spliced vector, and fusing the semantic vector and the processed spliced vector to obtain fused information.
Self-attention processing is a mechanism for assigning different degrees of attention to different parts inside the information, namely focusing on the relationship between elements inside a single sequence, and the resulting processed splice vector is an enhanced splice vector which is focused more on the most important part in the spliced information.
S208 generates countermeasure information under the countermeasure type indicated by the target countermeasure instruction information based on the prediction vector.
The countermeasure information is used for training a first language model, the first language model is used for executing language information processing tasks, and specifically, the first language model can be trained by using the original information and the countermeasure information together, so that the first language model can be helped to learn correct responses when facing complex or fraudulent input, and after the countermeasure training, the first language model can be used for executing various language information processing tasks, such as tasks of text classification, emotion analysis, text generation, machine translation and the like.
Specifically, the computer apparatus may input the predicted vector into the Softmax classifier after obtaining the predicted vector, output a probability distribution of the predicted vector in the vocabulary through the Softmax classifier, and determine predicted words based on the probability distribution, and perform this step for each predicted vector, so that countermeasure information under the countermeasure type indicated by the target countermeasure instruction information composed of the respective predicted words may be obtained.
It can be understood that steps S202 to S208 may be performed multiple times for the same original information, so that countermeasure information under multiple countermeasure types may be obtained, and diversity of the countermeasure information may be improved.
In the above method for generating countermeasure information, by constructing in advance a countermeasure instruction library including at least one candidate countermeasure instruction information, each candidate countermeasure instruction information being used for instructing generation of countermeasure information under a corresponding countermeasure type, so that when a countermeasure information generation task for original information is received, target countermeasure instruction information can be selected from the at least one candidate countermeasure instruction information of the countermeasure instruction library, generation of target countermeasure instruction information guiding countermeasure information can be realized by encoding and decoding spliced information of the original information and the target countermeasure instruction information, and finally countermeasure information conforming to expectations can be obtained; in addition, in the process of generating the countermeasure information, semantic vectors carrying context semantics can be obtained by carrying out semantic coding on spliced information, and the objective countermeasure indication information can fully play a role in guiding in the process of generating the countermeasure information by carrying out attention processing on the semantic vectors and the spliced information, so that the countermeasure information which is more in accordance with expectations is obtained; in addition, different candidate countermeasure fingers can be adopted for the same original information to indicate countermeasure information under different countermeasure types, so that diversity of the countermeasure information is improved, and the first language model is trained by using accurate and rich countermeasure information, so that the first language model can better adapt to and process various complex and challenging language information, and the processing effect of the first language model on language information processing tasks is improved.
In one embodiment, the method for generating countermeasure information further includes a process of constructing a countermeasure instruction library, and the process specifically includes the following steps: selecting indicative text information from a data source; carrying out availability classification on the text information to obtain classification categories of the text information; taking the text information classified into available indication categories as candidate countermeasure indication information; the candidate countermeasure indication information is stored in a countermeasure indication library.
The data source refers to a source or collection of providing data, and the data source may be an online data source, such as a website, a blog, a news website, a social media platform, etc., or may be a public data set, such as Wikipedia, project Gutenberg (books in public areas), common Crawl (network grabbing data), etc., or may be a professional document, such as a scientific paper, a technical report, a legal document, etc.
The indicative text information refers to text containing explicit instructions or requests for guiding the receiver and some specific operation of Xinin, such as "coming a sentence close to the original intention", "changing the sentence to be rewritten by me", "going to playground to run a circle", "changing the sentence to be antisense", etc., are indicative sentences; for example, "sky appears beautiful pale blue, several clouds drift long, i have borrowed a few books yesterday, i know weather forecast for tomorrow, i have really been too wonderful, i have possibly arrived late due to traffic congestion, etc. are all non-indicative sentences.
Availability classification is used to evaluate whether the acquired text information meets the requirement as countermeasure instruction information, and the classification mode may be at least one of manual classification or machine classification, wherein manual classification refers to manual examination and classification of the text information by human experts or reviewers, machine classification refers to automatic classification of the text information by using algorithms and machine learning models, the classification category may specifically comprise an available instruction category and an unavailable instruction category, the text information of the available instruction category has definite instruction properties, and the countermeasure information of a specific countermeasure type can be guided or generated, such as text information of 'come a sentence similar to the original intention', 'update me to the sentence', the text information of the unavailable category lacks definite instruction, the indicated content is opposite to or irrelevant to the target task, such as 'go to play a game circle', 'change the sentence into antisense'.
Specifically, the computer device constructs the countermeasure instruction library in advance, determines candidate data sources capable of providing indicative text information, screens out data sources with data access rights from the candidate data sources, accesses the data sources, acquires candidate text information from the data sources, selects indicative text information meeting selection conditions from the candidate text information, classifies the text information in an availability classification mode by using at least one of manual classification and machine classification to obtain classification types of the text information, takes the text information classified into the available classification types as candidate countermeasure instruction information, and stores the candidate countermeasure instruction information into the constructed countermeasure instruction library.
In one embodiment, after obtaining the indicative text information of the preset information quantity, the computer device may select a specified quantity of indicative text information from the indicative text information of the preset information quantity, classify the specified quantity of indicative text information by means of manual classification, obtain a classification class of the specified quantity of text information, train the initial classifier based on the specified quantity of text information and the classification class, obtain an information classifier, and classify the remaining text information in the text information of the preset information quantity by means of the information classifier, so as to obtain a classification class of the remaining text information, where the remaining text information refers to a part other than the specified quantity in the preset information quantity.
In the above embodiment, the computer device classifies the availability of the text information by selecting the indicative text information from the data source to obtain the classification category of the text information, so that the text information classified into the available indication category can be used as candidate countermeasure indication information to construct a countermeasure indication library, and further, the candidate countermeasure indication information indicating various countermeasure types in the countermeasure indication library can be used to guide the generation of the countermeasure information, thereby realizing the generation of the countermeasure information based on the sentence granularity, and improving the diversity of the countermeasure information of the sentence granularity.
In one embodiment, the process of classifying the availability of the indication information by the computer device to obtain the classification category of the text information includes the steps of: extracting characteristics of the text information through a pre-trained information classifier to obtain characteristic vectors; a classification category of the text information is determined based on the feature vector.
The information classifier is used for automatically classifying the text information into different preset categories, and specifically can be a classifier based on a machine learning algorithm, such as naive Bayes, logistic regression, support vector machine, random forest or deep neural network, and the like.
Specifically, after obtaining the text information, the computer device may input the text information to a pre-trained information classifier for any one text information, extract feature vectors of the text information from the extracted feature vectors through a feature extraction network of the information classifier, input the feature vectors to a classification network of the information classifier, and predict the classification of the text information through the classification network to obtain the classification of the text information.
In the above embodiment, the computer device performs feature extraction on the text information through the pre-trained information classifier to obtain the feature vector, and determines the classification category of the text information based on the feature vector, so that the text information can be rapidly and accurately classified, and further the construction efficiency of the countermeasure instruction library and the accuracy of the candidate countermeasure instruction information in the countermeasure instruction library can be improved.
In one embodiment, the process of the computer device regarding text information classified into available indication categories as candidate countermeasure indication information includes the steps of: acquiring the classification accuracy of the information classifier; when the classification accuracy rate does not reach the accuracy rate threshold value, the classification category of the indication information is checked to obtain a checked classification category; and taking the indication information of which the classified category is the available category after the collation as candidate countermeasure indication information.
The classification accuracy is an index for evaluating the performance of the classification model, and represents the proportion of the model to correctly classify samples.
Specifically, before classifying the indicative text information through the information classifier, the computer device may divide all the text information to be classified into a plurality of subsets, each subset includes at least 2 text information, each round classifies the text information in one subset through the classifier to obtain classification categories of each text information in the subset, determines classification accuracy of the information classifier based on real categories and classification categories of each text information in the subset, optimizes the information classifier by adopting the real categories of each text information and text information in the subset when the classification accuracy is lower than an accuracy threshold, obtains an optimized information classifier, determines classification accuracy of the optimized information classifier, classifies the text information in the next subset through the optimized information classifier, and determines that the classification result of the optimized information classifier is reliable if the classification accuracy of the optimized information classifier reaches an accuracy threshold, and directly uses the text information classified as available indication candidate information; if the classification accuracy of the optimized information classifier does not reach the accuracy threshold, determining that the classification result of the information classifier is unreliable, and correcting the classification class output by the classifier based on the real class of the text information in the next subset to obtain the corrected classification class; and taking the indication information of which the classified category is the available category after the collation as candidate countermeasure indication information, and simultaneously continuing to optimize the information classifier based on the text information in the next subset and the real category of the text information.
For example, describing the classification accuracy of the information classifier after optimization, assuming that the test set contains P pieces of text information, P is a positive integer greater than or equal to 2, classifying the P pieces of text information in the test set by the classifier to obtain classification categories of the P pieces of text information, checking the classification categories of the P pieces of text information based on true categories of the P pieces of text, counting a first information number TP (True Positives) correctly classified as an available indication category, a second information number TN (True Negatives) correctly classified as an unavailable indication, a third information number FP (False Positives) incorrectly classified as an available indication category, a fourth information number FN (False Negatives) incorrectly classified as an unavailable indication, and determining the classification accuracy of the information classifier based on the text information number P, the first information number TP, the second information number TN, the third information number FP and the fourth information number FN, wherein the text information number P, the first information number TP, the second information number TN, the third information number FP and the fourth information number FN satisfy the following relation:
the classification accuracy, the first information number TP, the second information number TN, the third information number FP, and the fourth information number FN satisfy the following relationship:
In the above embodiment, the computer device obtains the classification accuracy of the information classifier, and when the classification accuracy does not reach the accuracy threshold, checks the classification category of the indication information to obtain the checked classification category; the indication information of which the classified category is available after the correction is used as candidate countermeasure indication information, so that the indication information of which only the available category with high classification accuracy is added into a countermeasure indication library can be ensured, and the accuracy of the candidate countermeasure indication information in the countermeasure indication library is improved.
In one embodiment, the process of obtaining the semantic vector by the computer device by semantically encoding the spliced information obtained by splicing the original information and the target countermeasure indication information includes the steps of: splicing the original information and the target countermeasure indication information to obtain spliced information; carrying out semantic coding on the spliced information through an encoder of the second language model to obtain a semantic vector; the computer equipment performs attention processing on the semantic vector and the spliced information, and the process of obtaining the prediction vector comprises the following steps: and performing attention processing on the semantic vector and the spliced information through a decoder of the second language model to obtain a prediction vector.
The splicing refers to a process of connecting two or more character strings, sequences, vectors or data structures together to form a single new entity, and the splicing information refers to the new entity formed by connecting two or more character strings, sequences, vectors or data structures together.
The second language model is a deep learning model trained on a large-scale text data set, and may specifically be a deep learning model adopting a transform structure, and includes an encoder for processing input data and converting it into an intermediate representation, in this embodiment, a semantic vector, and a decoder for converting the intermediate representation of the encoder output into a final output, in this embodiment, a prediction vector.
Specifically, the computer device performs splicing on the original information and the target countermeasure indication information to obtain spliced information, inputs the spliced information into an encoder of the second language model, performs semantic coding on the spliced information through each network layer of the encoder to obtain semantic vectors, inputs the obtained semantic vectors and the spliced information as input data into a decoder of the second language model, and performs attention processing on the semantic vectors and the spliced information through the decoder to obtain prediction vectors.
In the above embodiment, the computer device obtains the splicing information by splicing the original information and the target countermeasure instruction information; carrying out semantic coding on the spliced information through an encoder of the second language model to obtain a semantic vector; the decoder of the second language model is used for carrying out attention processing on the semantic vector and the spliced information to obtain a predicted vector, the spliced model can be used for considering the context relation between the original information and the countermeasure indication information during processing, so that the countermeasure information which is more natural and more in line with the indication type corresponding to the indication information can be generated, the model can understand and capture the slight semantic difference in the text through semantic coding, the decoder is used for carrying out attention processing, the model can be used for focusing on the information part which has the most influence on the prediction, the accuracy of the countermeasure information generation is improved, the aim of giving full play to the guidance effect of the target countermeasure indication information in the countermeasure information generation process can be realized, and the countermeasure information which is more in line with the expectation can be generated by the more indicating information.
In one embodiment, the encoder comprises M encoding layers, the decoder comprises N decoding layers, M and N are positive integers greater than or equal to 2; the computer equipment carries out semantic coding on the spliced information through an encoder of the second language model, and the process of obtaining the semantic vector comprises the following steps: carrying out semantic coding on the spliced information through M coding layers, and carrying out semantic coding on the semantic coding result obtained by each coding layer as input data of the next coding layer in the semantic coding process to obtain a semantic vector; the computer device performs attention processing on the semantic vector and the spliced information through a decoder of the second language model, and the process of obtaining the prediction vector comprises the following steps: and performing attention processing on the semantic vectors and the splicing information through N decoding layers, and performing attention processing on attention processing results and semantic vectors obtained by each decoding layer as input data of the next decoding layer in the attention processing process to obtain a prediction vector.
Specifically, after obtaining splicing information, the computer device inputs the splicing information into a 1 st coding layer of the encoder, performs semantic coding on the splicing information through the 1 st coding layer to obtain a 1 st coding result, inputs the 1 st coding result into a 2 nd coding layer, performs semantic coding on the 1 st coding result through the 2 nd coding layer to obtain a 2 nd coding result, and so on until an Mth coding layer performs semantic coding on an M-1 st coding result to obtain an Mth coding result, the Mth coding result is the obtained semantic vector, the semantic vector and the splicing information are input into a 1 st decoding layer of the decoder, performs attention processing on the semantic vector and the splicing information through the 1 st decoding layer to obtain a 1 st decoding result, inputs the 1 st decoding result and the splicing information into a 2 nd decoding layer, performs attention processing on the 1 st decoding result and the splicing information through the 2 nd decoding layer to obtain a 2 nd decoding result, and so on until an Nth decoding layer performs attention processing on the Nth decoding result and the splicing information to obtain an N-1 st decoding result, namely the N-th decoding result is the obtained predictive vector.
In the above embodiment, the computer device performs semantic coding on the spliced information through M coding layers, and performs semantic coding on the semantic coding result obtained by each coding layer as input data of the next coding layer in the process of semantic coding to obtain a semantic vector; the semantic vector and the spliced information are subjected to attention processing through N decoding layers, in the attention processing process, attention processing results and semantic vectors obtained by each decoding layer are used as input data of the next decoding layer to be subjected to attention processing, a prediction vector is obtained, and the multi-layer coding and decoding can enable a model to extract and learn deep and complex features in text data, so that the accuracy of generating countermeasure information can be improved, and the aim of giving full play to guiding effect to target countermeasure indication information in the countermeasure information generation process can be realized, so that countermeasure information which accords with expectations is generated by more information.
In one embodiment, the coding layers include a first attention sub-layer, a first normalization sub-layer, a feedforward network sub-layer and a second normalization sub-layer, the computer device performs semantic coding on the spliced information through M coding layers, and in the process of semantic coding, the semantic coding result obtained by each coding layer is used as input data of the next coding layer to perform semantic coding, and the process of obtaining the semantic vector includes the following steps: performing attention processing on input data of the ith coding layer through a first attention sub-layer of the ith coding layer to obtain a first coding result; i is a positive integer less than or equal to M; fusing a first coding result and input data through a first normalization sub-layer of an ith coding layer, and normalizing the fused result to obtain a second coding result; performing feature processing on the second coding result through a feedforward network sub-layer of the ith coding layer to obtain a third coding result; fusing the third coding result and the second coding result through a second normalization sub-layer of the ith coding layer, and normalizing the fused result to obtain a semantic coding result of the ith coding layer; when i is smaller than M, taking the semantic coding result of the ith coding layer as input data of the (i+1) th coding layer, reassigning i=i+1, and returning to execute the step of performing attention processing on the input data of the ith coding layer through the first attention sub-layer of the ith coding layer; when i=m, the semantic coding result of the ith coding layer is taken as a semantic vector.
Wherein the first attention sub-layer may use a self-attention mechanism; the first normalization sub-layer and the second normalization sub-layer are used for carrying out normalization processing on data input into the corresponding sub-layer, wherein normalization is a normalization processing process and aims at adjusting and scaling the data to enable the data to meet specific standards or distribution; the feed forward network sub-layer includes a linear transformation layer (which may also be referred to as a fully-connected layer) for linearly transforming data of the layer.
Specifically, starting from the 1 st coding layer, the computer device inputs splicing information into the first attention sub-layer of the 1 st coding layer, performs attention processing on the splicing information through the first attention sub-layer to obtain a first coding result, inputs the first coding result and the splicing information into the first normalization sub-layer of the 1 st coding layer, performs weighted fusion on the first coding result and the splicing information through the first normalization sub-layer, performs normalization processing on the result obtained by weighted fusion to obtain a second coding result, inputs the second coding result into the feedforward network sub-layer of the 1 st coding layer, performs linear transformation on the second coding result through the feedforward network sub-layer to obtain a third coding result, inputs the third coding result and the second coding result into the second normalization sub-layer of the 1 st coding layer, performs weighted fusion on the third coding result and the second coding result through the second normalization sub-layer, performs weighted fusion on the result obtained by weighted fusion to obtain a 1 st coding result, namely, inputs the 1 st coding result as a semantic vector coding result into the 2 nd coding result, namely, and sequentially inputs the M coding result into the M coding result as the first coding result of the 1 st coding layer until M coding result is input into the 2 nd coding layer, namely, and the M coding result is sequentially obtained as a semantic vector coding result is obtained.
Referring to the schematic structure of the coding layers of the encoder shown in fig. 3, the encoder shown in the figure includes M coding layers, each of which includes a self-attention mechanism, a first weighted sum normalization layer, a feed forward network layer, and a second weighted sum normalization layer, and the data processing procedure of each layer will be described by taking the data processing procedure of the 1 st coding layer as an example:
1) Self-attention mechanism:
the encoder applies a self-attention mechanism, the process of which can be characterized as follows:
wherein, Q is input data, and for the 1 st coding layer, Q is vector representation of splicing information of original information and indication information, for example, original information "jingzheng" and indication information "are spliced to obtain a sentence similar to the original intention, and input data" jingzheng and jinshi "are obtained to obtain a sentence similar to the original intention; in the self-attention mechanism k=q, v=q.
2) First weighting and normalization layer:
and carrying out weighted summation on the output of the self-Attention mechanism and the original input data through a first weighted summation normalization layer to strengthen the original information, and normalizing to obtain a normalized result x1, namely, norm (Q+attention (Q, K, V)), wherein Norm is a normalization function.
3) Feed forward network layer:
the normalized result x1 is further processed by the feedforward network layer to fully fuse information, and a result feed_forward (x 1) is obtained, wherein feed_forward is a calculation unit of the feedforward network.
4) Second weighted sum normalization layer:
and carrying out weighted summation and normalization on the result feed_forward (x 1) output by the feedforward network layer and the original input data through the second weighted summation normalization layer to obtain Norm (x1+feed_forward (x 1)).
It will be appreciated that the Norm (x1+feed_forward (x 1)) output by the second weighted and normalized layer in the 1 st coding layer is the output result of the 1 st coding layer, and the output result will be input as the input data of the 2 nd coding layer to the 2 nd coding layer, and the Norm (x1+feed_forward (x 1)) output by the second weighted and normalized layer in the M th coding layer is the output result of the encoder, where M may be a value of 6 in some embodiments.
In the above embodiment, the computer device processes the input data through a series of sub-layers in each coding layer, so that deep semantic information can be captured and utilized more effectively, and further, performance of the model can be improved.
In one embodiment, the decoding layer includes a second attention sub-layer, a third normalization sub-layer, a third attention sub-layer, a fourth normalization sub-layer, a feed forward network sub-layer; the computer device performs attention processing on semantic vectors and splicing information through N decoding layers, and in the process of attention processing, attention processing is performed on attention processing results and semantic vectors obtained by each decoding layer as input data of the next decoding layer, and the process of obtaining a prediction vector comprises the following steps: performing attention processing on input data of the j decoding layer through a second attention sub-layer of the j decoding layer to obtain a first fusion result; fusing the first fusion result and the input data through a third normalization sub-layer of the j decoding layer, and normalizing the fusion result to obtain a second fusion result; performing attention processing on the second fusion result and the semantic vector through a third attention sub-layer of the j-th coding layer to obtain a third fusion result; fusing the third fusion result and the second fusion result through a fourth normalization sub-layer of the j decoding layer, and normalizing the fusion result to obtain a fourth fusion result; performing feature processing on the fourth fusion result through a feedforward network sub-layer of the j decoding layer to obtain an attention processing result of the j decoding layer; when j is smaller than N, taking the attention processing result of the j decoding layer as the input data of the j+1th decoding layer, reassigning j=j+1, and returning to execute the step of performing attention processing on the input data of the j decoding layer through the second attention sub-layer of the j decoding layer; when j=n, the attention processing result of the j-th decoding layer is used as the output result of the decoder, and a prediction vector is obtained.
Wherein the second attention sub-layer may use a self-attention mechanism; the third normalization sub-layer and the fourth normalization sub-layer are used for carrying out normalization processing on the data input into the corresponding sub-layer, wherein normalization is a normalization processing process and aims at adjusting and scaling the data to enable the data to meet specific standards or distribution; the feed forward network sub-layer includes a linear transformation layer (which may also be referred to as a fully-connected layer) for linearly transforming data of the layer.
Specifically, starting from the 1 st decoding layer, the computer equipment inputs splicing information as input data of the 1 st decoding layer to a second attention sub-layer of the 1 st decoding layer, attention processing is performed on the splicing information through the second attention sub-layer to obtain a first fusion result, the first fusion result and the splicing information are input to a third normalization sub-layer of the 1 st decoder, the first fusion result and the splicing information are subjected to weighted fusion through the third normalization sub-layer, the weighted fusion result is subjected to normalization processing, a second fusion result is obtained, semantic vectors output by the encoder and the second fusion result are input to a third attention sub-layer of the 1 st decoding layer, attention processing is performed on the semantic vectors and the second fusion result through the third attention sub-layer to obtain a third fusion result, the third fusion result and the second fusion result are input to a fourth normalization sub-layer of the 1 st decoding layer, the fourth fusion result is also subjected to be referred to as a first decoding result, the fourth fusion result is input to the fourth layer, namely, the decoding result is subjected to the fourth layer 1 st decoding result is subjected to the linear fusion, and the first decoding result is subjected to the first layer, the first layer is subjected to the first layer, and the decoding result is subjected to the first layer 1-layer is subjected to the linear fusion processing, and inputting the first fusion result and the 1 st layer decoding result into a third normalization sub-layer of the 2 nd decoding layer, carrying out weighted fusion on the first fusion result and the 1 st layer decoding result through the third normalization sub-layer, carrying out normalization processing on the result obtained by the weighted fusion to obtain a second fusion result, inputting the semantic vector output by the encoder and the second fusion result into a third attention sub-layer of the 1 st decoding layer, and the like until an N-th decoding result is obtained, namely, an attention processing result of the N-th decoding layer is obtained, and taking the attention processing result of the N-th decoding layer as a prediction vector output by the decoder.
Referring to the schematic structure of the decoding layers of the encoder shown in fig. 4, the decoder shown in the figure includes M decoding layers, each of which includes a first self-attention mechanism, a first weighted sum normalization layer, a second self-attention mechanism, a second weighted sum normalization layer, and a feed forward network layer, and the data processing procedure of each layer will be described by taking the data processing procedure of the 1 st decoding layer as an example:
1) First self-attention mechanism:
the decoder applies a self-attention mechanism, the processing of which can be characterized as follows:
wherein, Q is input data, and for the 1 st decoding layer, Q is vector representation of concatenation information of original information and indication information, for example, original information "jingzheng" and indication information "are spliced to obtain a sentence similar to original intention, and input data is obtained as" jingzheng and jinshi "to obtain a sentence similar to original intention; in the self-attention mechanism k=q, v=q.
2) First weighting and normalization layer:
and carrying out weighted summation on the output of the first self-Attention mechanism and the original input data through a first weighted summation normalization layer to strengthen the original information, and normalizing to obtain a normalized result Y1, namely, norm (Q+attention (Q, K, V)), wherein Norm is a normalization function.
3) Second self-attention mechanism:
and fusing the output result of the encoder with the output result of the first weighting and normalization layer through a second attention mechanism, wherein in the process of realizing the fusion through the second attention mechanism, the output result of the encoder is taken as the values of Q and K in the second self-attention mechanism, and the output result of the first weighting and normalization layer is taken as the value of V in the second self-attention mechanism.
4) Second weighted sum normalization layer:
and carrying out weighted summation and normalization on the output result of the second attention mechanism and the output result of the first weighted summation normalization layer through the second weighted summation normalization layer.
5) Feed forward network layer:
the output result of the second weighting and normalizing layer is further processed by the feedforward network layer to fully fuse the information.
It will be appreciated that the output result of the feed-forward network layer in the 1 st decoding layer is the output result of the 1 st decoding layer, the output result is input as the input data of the 2 nd decoding layer to the 2 nd decoding layer, the output result of the feed-forward network layer of the nth decoding layer is the output result of the decoder, and in some embodiments, N may take a value of 6.
As can be seen from fig. 4, a softmax layer may be further included after the decoder, the output result of the decoder may be input to the softmax layer, the corresponding characters may be predicted by processing the output result of the decoder through the softmax layer, and the countermeasure information composed of the predicted characters may be obtained by predicting the characters one by one. The corresponding expression of the softmax layer is:
where p (y-x) is the probability size of the softmax type prediction output being y under the condition that the output result of the decoder is x,for the learned weight vector associated with y, -/->Is the learned weight vector associated with the C-th category in vocabulary C.
In addition, it should be noted that, when the decoder outputs the predicted vector, the decoder outputs the predicted vector character by character, and when the first character is predicted, the data of the decoder is the splicing result of the splicing information and the preset keyword, and the preset keyword may specifically be a start identifier, and the start identifier may also be referred to as a start identifier, for example [ CLS ]; when predicting the next character, the input of the decoder is the splicing information, the starting identifier and the splicing result of the predicted character, taking the splicing information as an example of a sentence which is 'dishonest to, golden stone to come a section of the sentence close to the original intention', describing the prediction process of the decoder, and the candidate generation result is taken as a parameter beam_number=1 of beam search (beam search), and the example is as follows:
1) The encoder performs semantic coding on the spliced information to obtain semantic vectors, and inputs the semantic vectors into the decoder.
2) The decoder inputs a starter ([ CLS) as an initial input, and outputs a result with the highest probability, and the output character is "heart".
3) Splicing the initial input and output characters in the 2) to obtain a 'CLS heart', taking the 'CLS heart' as the input of a decoder, outputting a result with the maximum probability by the decoder, and outputting the character as 'honest'.
4) Splicing the input and output characters in 3) to obtain "[ CLS ] heart honest", taking "[ CLS ] heart honest" as the input of a decoder, outputting a result with the highest probability by the decoder, and outputting the character as "then".
5) Splicing the input and output characters in 4) to obtain the ' CLS ' heart honest rule ', taking the ' CLS heart honest rule ' as the input of a decoder, outputting the result with the maximum probability by the decoder, and outputting the character as ' Ling '.
6) Splicing the input and output characters in the step 5) to obtain the 'CLS' Xinchengzhiling ', taking the' CLS 'Xinchengzhiling' as the input of a decoder, outputting a result with the maximum probability by the decoder, and outputting the character as a terminator 'EOS'.
7) When the decoder outputs the terminator, the generation ends.
8) And (3) post-processing, namely removing the initiator [ CLS ] and the terminator [ EOS ], wherein the finally generated countermeasure information is 'Xinchengzhiling'.
In the above embodiment, the computer device processes the input data and the semantic vector through a series of sublayers in each decoding layer, so that the analysis effect on the data and the semantic vector can be gradually improved, and the accuracy of the prediction vector is further improved, so that the model can process and generate complex data more accurately; through the attention mechanism, the model can concentrate on the information part which has the most influence on prediction, so that the accuracy of the generation of the countermeasure information is improved, and the aim of fully playing a guiding role of the countermeasure indication information in the countermeasure information generation process can be realized, so that the countermeasure information which meets the expectations is generated by the more information.
In an embodiment, in the method for generating countermeasure information, after obtaining the countermeasure information, the computer device may further train a first language model based on the obtained countermeasure information, where the process of training the first language model includes the following steps: acquiring a label of the countermeasure information; performing language processing on the countermeasure information through the language model to be trained to obtain a first processing result; and carrying out parameter optimization on the language model to be trained based on the first processing result and the label to obtain a first language model.
The first language model is a model for executing a language processing task, the language processing task may specifically be a text classification task, a text emotion analysis person, a language understanding task, a machine translation task, a text generation task, and the like, the tag of the countermeasure information refers to classification or description information associated with the countermeasure information, the tag of the countermeasure information may be different for different language processing tasks, for example, under the text classification task, the tag generally represents a category to which the text belongs, for example, "entertainment", "sports" and the like in news classification, the tag of the countermeasure information is a true category of the countermeasure information, under the text emotion analysis task, the tag generally describes an emotion tendency of the text, for example, "positive", "negative" or "neutral", the tag of the countermeasure information is a true emotion category of the countermeasure information, under the language understanding task, the tag represents existence or semantic relation of a specific concept in the text, the tag of the countermeasure information is true semantics of the countermeasure information, under the machine translation task, the tag of the countermeasure information is generally a correct translation of the text, the tag of the countermeasure information is a correct translation version corresponding to the countermeasure information, under the text generation task, the tag of the countermeasure information represents a true text to be generated by the context, and the tag of the countermeasure information is true text.
The first processing result refers to a prediction result output by the model to be trained, wherein the prediction result is a result of understanding and processing input data by the model based on current parameters and a learning algorithm, for example, under a text classification task, the prediction result is a predicted classification category, such as "junk mail" and "non-junk mail"; under the text emotion analysis task, the predicted result is the predicted emotion tendency category, such as positive, negative and neutral; under the task of language understanding, the predicted result is predicted entity semantics and relationship semantics, such as name of person, name of place, relationship between the object A and the object B, and the like; under the task of machine translation, the predicted result is the text of the predicted target language; under the text generation task, the prediction results are generated text content, such as answer sentences of a given prompt.
Specifically, after obtaining the countermeasure information, the computer device may use the tag of the original information as the tag of the countermeasure information corresponding to the tag, extract the countermeasure information and the feature through the language model to be trained, obtain the countermeasure feature, perform language processing based on the countermeasure feature, obtain a first processing result, determine a training loss value according to the first processing result and the tag of the countermeasure information, and perform parameter adjustment on the language model to be trained based on the training loss value, until reaching the convergence condition, and stop training, thereby obtaining the trained first language model.
The convergence condition is used for determining when the training process should be stopped, and can be specifically a loss threshold condition, a performance threshold condition, an iteration number condition, or a custom condition, wherein the loss threshold condition can be specifically a specific loss function threshold value, and when the loss value of the model is reduced below the threshold value, the model is considered to be optimized enough to stop training; the performance threshold condition may specifically be based on the performance of the model on the verification set, such as accuracy, recall, etc., and if the model performance no longer significantly improves or reaches a predetermined performance level, the training is stopped; the iteration number condition can be specifically that the maximum iteration number of training is set, no matter how the model performance is, and training is stopped after the iteration number is reached; the custom condition may specifically be a set of rules for stopping training based on a specific task or requirement, and the set of rules may be a combination of the above conditions or a condition based on other specific criteria.
It should be noted that, in the process of training the first language model using the countermeasure information, the first language model may be specifically trained using a training data set composed of the original information and the countermeasure information.
In the above embodiment, the computer device trains the model by using the countermeasure information, so that the model can learn to identify and correctly process the information which may mislead the model, the resistance of the model to actual attacks is improved, the model can keep the performance in more diversified and complex data environments, and the robustness of the model is improved.
In one embodiment, in the method for generating countermeasure information, the computer device may further optimize the pre-training language model after obtaining the countermeasure information, and the process specifically includes the following steps: acquiring a label of the countermeasure information; performing language processing on the countermeasure information through a pre-training language model to obtain a second processing result; determining a performance index value of the pre-training language model based on the second processing result and the label; when the performance index value does not reach the index value threshold value, misjudged target countermeasure information is selected from the countermeasure information, and parameter optimization is performed on the pre-training language model based on the target countermeasure information, so that a first language model is obtained.
The pre-training language model can be a language model obtained by pre-training original information, the second processing result refers to a prediction result output by the pre-training language model, and the prediction result is a result of understanding and processing the input data by the model based on the current parameters and a learning algorithm.
The performance index value is a quantization index for measuring and evaluating the performance of the model, and specifically may be at least one of an accuracy rate, and a recall rate, or may be other indexes determined based on at least one of the accuracy rate, and the recall rate.
Specifically, after obtaining a plurality of countermeasure information, the computer device may take the tag of the original information as the tag of the corresponding countermeasure information, sequentially perform feature extraction on the plurality of countermeasure information through the pre-training language model to obtain countermeasure features, perform language processing based on the countermeasure features to obtain second processing results corresponding to each countermeasure information, verify the corresponding second processing results based on the tag of each countermeasure information to obtain a verification result, determine a performance index value of the model to be processed based on the verification result, select misjudged target countermeasure information from the countermeasure information based on the verification result when the performance index value does not reach the index value threshold, and perform parameter optimization on the pre-training language model based on the target countermeasure information to obtain the first language model.
In the above embodiment, the computer device acquires the tag of the countermeasure information; performing language processing on the countermeasure information through a pre-training language model to obtain a second processing result; determining a performance index value of the pre-training language model based on the second processing result and the label; when the performance index value does not reach the index value threshold, misjudged target countermeasure information is selected from the countermeasure information, and parameter optimization is carried out on the pre-training language model based on the target countermeasure information, so that a first language model is obtained, performance of the model in countermeasure attack can be accurately estimated through the countermeasure information, when the performance fails to reach expectations, weak points aiming at the model can be further reinforced by using the target countermeasure information with successful attack, continuous improvement of the model is achieved, and therefore performance of the model in processing complex and potential hostile input can be improved, and stability and reliability of the model in a variable environment can be ensured.
In one embodiment, in the method for generating countermeasure information, after obtaining the first language model, the computer device may use the first language model to perform a language processing task, where the processing procedure specifically includes the following steps: acquiring context data formed by a target object in a man-machine conversation process; extracting the characteristics of the context data through a first language model to obtain a characteristic vector; dialogue data is generated based on the feature vectors.
The man-machine conversation refers to natural language interaction between a person and a computer, for example, man-machine conversation realized by a chat robot or a voice assistant. The context data refers to dialog content that has been generated when the man-machine dialog is performed.
It will be appreciated that each time a target object or machine speaks while talking to the machine, the target object or machine will be stored in a session, which may be an array, list or other data structure, for holding all of the conversational content in chronological order, new utterances will be added to the session as the conversation progresses to ensure that the context data is up-to-date.
Specifically, the terminal acquires a session formed by a conversation between a target object and a machine, extracts context data from the session according to a preset time window, obtains the context data formed by the target object in the human-computer conversation process, inputs the context data into a trained first language model, extracts the context data features through each network layer of the first language model, obtains feature vectors, and generates conversation data based on the feature vectors.
FIG. 5 is a diagram of a dialog page in one embodiment, where the context data is "user: i have recently worked very late, fatiguing every day. And (5) an assistant: working too long does affect your physical well-being. What results in you needing to work so late? The user: i have too many items at hand and the expiration date of each item is very tight. And (5) an assistant: and the pressure that sounds true is great. Do you want some advice to better manage your time? The user: if so, please give me some advice ", the generated dialogue data is" first, advice you to rest regularly, after 50 minutes of work per hour, rest for 10 minutes, ensuring you have enough rest and good diet, which helps to improve efficiency. "
In the above embodiment, the computer device obtains the context data of the man-machine conversation and performs feature extraction on the context data through the first language model, so that the first language model can better consider the context when processing the conversation, so as to provide more accurate and relevant response.
In one embodiment, as shown in fig. 6, a method of generating challenge information is provided, which may be performed by a computer device, which may be, for example, the terminal 102 or the server 104 shown in fig. 1. The method may comprise the steps of:
S602, selecting indicative text information from a data source.
And S604, extracting the characteristics of the text information through a pre-trained information classifier to obtain characteristic vectors.
S606, determining the classification category of the text information based on the feature vector.
S608, obtaining the classification accuracy of the information classifier.
And S610, when the classification accuracy rate does not reach the accuracy rate threshold value, checking the classification category of the indication information to obtain the checked classification category.
And S612, taking the indication information of which the classified category is the available category after the collation as candidate countermeasure indication information.
S614 stores the candidate countermeasure instruction information in the countermeasure instruction library.
S616, when a countermeasure information generation task for the original information is received, target countermeasure instruction information is selected from at least one candidate countermeasure instruction information of the countermeasure instruction library.
And S618, splicing the original information and the target countermeasure indication information to obtain splicing information.
S620, performing semantic coding on the spliced information through M coding layers of an encoder of the second language model, and performing semantic coding on semantic coding results obtained by each coding layer as input data of the next coding layer in the process of semantic coding to obtain semantic vectors.
S622, attention processing is carried out on the semantic vectors and the splicing information through N decoding layers of a decoder of the second language model, and in the attention processing process, attention processing results and the semantic vectors obtained by each decoding layer are used as input data of the next decoding layer to carry out attention processing, so that prediction vectors are obtained.
S624, generating countermeasure information under the countermeasure type indicated by the target countermeasure instruction information based on the prediction vector, the countermeasure information being used to train a first language model for executing the language information processing task.
The present application further provides an application scenario, which may specifically be a challenge scenario, referring to a challenge scenario schematic diagram shown in fig. 7, where a challenge task is an experimental task in a machine learning security study, and is aimed at exploring and testing vulnerability of a machine learning model when facing hostile input, in this task, an attacker creates (generates) and applies challenge information, which is specially designed input data, and can cause the machine learning model to make erroneous predictions or classifications without significantly changing the data, where the machine learning model is a task model trained by using data samples, and the challenge information for executing a challenge task may be challenge information generated by using a challenge information generating method based on word granularity or word granularity, or may be challenge information generated by applying a challenge information generating method based on sentence granularity, so that an attack result may be obtained by the challenge information on the machine learning model, where the challenge result may evaluate the robustness of the challenge information, that is, the robustness of the challenge model to the hostile input when facing hostile input, may be analyzed, and how the security model may be enhanced by the challenge model.
The application scenario is a model performance evaluation scenario, and referring to a schematic diagram of the model performance evaluation scenario shown in fig. 8, in the end of model training or in the training process, each performance index of the model is detected, so as to ensure that the model achieves a predetermined effect, wherein when the robustness is evaluated, challenge information can be used to test the robustness of the model, specifically, the performance of the model when the model faces an attack is evaluated by running the model on a data set containing the challenge information, wherein the challenge information can be the challenge information generated by adopting a challenge information generation method based on word granularity or word granularity, or the challenge information generated by adopting the challenge information generation method based on sentence granularity, and after the model achieves the predetermined effect, the model can be put on line for training.
The application also provides an application scene, which is a model training scene of a natural language processing model, and refers to a model training scene schematic diagram shown in fig. 9, a task model trained by a data sample is adopted, and a challenge is carried out on the task model through a data set containing challenge information to obtain a challenge result, wherein the challenge information can be the challenge information generated by a challenge information generation method based on word granularity or word granularity, or the challenge information generated by the challenge information generation method based on sentence granularity; the vulnerability of the task model can be found according to the attack result, the target countermeasure information of successful attack is selected from the data set, and the task model is further trained based on the data set containing the target countermeasure information, so that the performance of the task model is improved.
The application further provides an application scenario, where the application scenario applies the method for generating the challenge information, as shown in fig. 10, where the method specifically includes two phases, namely a challenge instruction library construction phase and a challenge instruction library generation challenge information phase, where the challenge instruction library construction phase includes a phase 1 and a phase 2, the phase 1 refers to a manual classification and storage sub-phase, the phase 2 refers to a machine classification and storage sub-phase, and the manual classification and storage sub-phase may also be referred to as a cold start phase, referring to a flow diagram of a challenge instruction library construction step shown in fig. 11, the phase 1 includes the following steps:
and a1, collecting original natural language instruction data to obtain a non-labeling corpus A.
Specifically, from a public data set or other source, an indication (promt) short sentence related to the Chinese text is collected through a data acquisition tool, such as 'coming a sentence similar to the original intention', 'helping me rewrite the sentence to change the sentence to be more vivid', 'going to the playground to run around' and 'changing the sentence to be antisense'.
And b1, manually labeling the categories of the indication short sentences in the non-labeling corpus A.
The indication (promt) phrases in the unlabeled corpus a are divided into two categories: an "available" category and an "unavailable" category, wherein the "available" category refers to an indication (promt) that the corresponding indication phrase is a challenge sample that can be used to generate close semantics; the "unavailable" category refers to an indication (promt) that the corresponding indication phrase is a challenge sample that cannot be used to generate close semantics.
For example, "a sentence from a paragraph that is similar to the original intent" may indicate that the model generates a similar semantic sentence, labeled "available"; 'help me rewrite the sentence more vividly', can instruct the model to generate a similar semantic sentence, and is marked as 'available'; the model cannot be indicated to generate similar semantic sentences by going to the playground to run for one circle, and the sentences are marked as unavailable; "changing this paragraph to antisense" does not indicate that the model generates a close semantic sentence, labeled "unavailable".
And c1, constructing a countermeasure instruction library.
The indication phrases marked as "available" categories in step b1 in the unlabeled corpus a are imported into the countermeasure indication library.
Referring to the schematic flow chart of the challenge instruction library construction step shown in fig. 12, stage 2 includes the steps of:
and a2, training a text classifier.
Specifically, a text classifier is trained based on a labeled corpus B obtained by labeling a non-labeled corpus A in a stage 1, and the text classifier can execute two classification tasks to divide input text into two types of "available" and "unavailable".
And b2, collecting original natural language instruction data to obtain a non-labeling corpus C.
Specifically, instruction (promt) phrases associated with chinese text are collected by a data acquisition tool from a source such as a public dataset.
Step c2. machine classification.
And C, classifying the indication phrases in the non-labeling corpus C by the trained text classifier in the step a2, and classifying the non-labeling indication phrases into two types of available/unavailable.
And step d2, manually checking the machine classification result.
And c2, carrying out quality inspection in a manual auditing mode aiming at the classification result of each indication phrase in the step c2.
Step e2, updating the antagonism indication library.
And d2, updating the corresponding indication phrases of the accurate classification results which are checked and completed in the step to the countermeasure indication library.
The step a2 to the step e2 are continuously and circularly executed in the stage 2, the effect of the classification model is continuously iterated, the indication short sentence is obtained, and the countermeasure indication library is updated, wherein when the classification accuracy of the classification model reaches 95%, the step d2 of manually checking the machine classification result is not executed in the subsequent iteration process, so that the updating efficiency of the countermeasure indication library can be improved on the basis of ensuring the classification accuracy.
Referring to fig. 10, the phase of generating countermeasure information using the countermeasure instruction library specifically includes the steps of:
step a3. selects an indication phrase from the antagonism indication library.
When it is necessary to generate countermeasure information for a certain original information, an instruction phrase is randomly extracted from a countermeasure instruction library.
Step b3. constructs model input data.
And c, splicing the original information with the indication phrases extracted in the step a3 to obtain model input data.
For example, if the short sentence "get a sentence close to the original intention" get in good faith with the original information ", the jinshi is" spliced, and the input data is constructed as "get in good faith", the jinshi is "get in good faith, get a sentence close to the original intention".
Step c3. inputs the model.
Inputting the data constructed in the step b3 into a large-scale language model so as to output countermeasure information through the large-scale language model.
Step d3. obtains challenge information.
Outputting the countermeasure information through the large-scale language model in the step c3, as shown in fig. 13, aiming at the sentence which is similar to the original intention and is "the dishonest arrival, the sentence is" the dishonest arrival "is output.
It can be understood that steps a3 to d3 are repeatedly performed, and the diversified sentence granularity attack resistance information for the original information "dishonest to the jinshi" can be continuously obtained by using the process.
It should be understood that, although the steps in the flowcharts related to the embodiments described above are sequentially shown as indicated by arrows, these steps are not necessarily sequentially performed in the order indicated by the arrows. The steps are not strictly limited to the order of execution unless explicitly recited herein, and the steps may be executed in other orders. Moreover, at least some of the steps in the flowcharts described in the above embodiments may include a plurality of steps or a plurality of stages, which are not necessarily performed at the same time, but may be performed at different times, and the order of the steps or stages is not necessarily performed sequentially, but may be performed alternately or alternately with at least some of the other steps or stages.
Based on the same inventive concept, the embodiment of the application also provides a countermeasure information generating apparatus for implementing the countermeasure information generating method referred to above. The implementation of the solution provided by the device is similar to the implementation described in the above method, so the specific limitation in the embodiments of the device for generating the challenge information provided below may refer to the limitation of the method for generating the challenge information hereinabove, and will not be repeated here.
In one embodiment, as shown in fig. 14, there is provided a countermeasure information generating apparatus including: a challenge instruction information selection module 1402, a semantic coding module 1404, a vector prediction module 1406, and an information generation module 1408, wherein:
the countermeasure-instruction-information selecting module 1402 is configured to select target countermeasure instruction information from at least one candidate countermeasure instruction information of the countermeasure instruction library when a countermeasure-information generating task for the original information is received.
The semantic coding module 1404 is configured to perform semantic coding on the spliced information obtained by splicing the original information and the target countermeasure instruction information, so as to obtain a semantic vector.
The vector prediction module 1406 is configured to perform attention processing on the semantic vector and the concatenation information to obtain a predicted vector.
The information generating module 1408 is configured to generate, based on the prediction vector, countermeasure information under the countermeasure type indicated by the target countermeasure instruction information, the countermeasure information being used to train a first language model, the first language model being used to perform a language information processing task.
In the above embodiment, by constructing in advance the countermeasure instruction library including at least one candidate countermeasure instruction information, each of the candidate countermeasure instruction information being used for instructing generation of countermeasure information under the corresponding countermeasure type, it is possible to select target countermeasure instruction information from the at least one candidate countermeasure instruction information of the countermeasure instruction library when a countermeasure information generation task for the original information is received, it is possible to realize that the target countermeasure instruction information instructs generation of countermeasure information by encoding and decoding spliced information of the original information and the target countermeasure instruction information, and finally obtain countermeasure information conforming to expectations; in addition, in the process of generating the countermeasure information, semantic vectors carrying context semantics can be obtained by carrying out semantic coding on spliced information, and the objective countermeasure indication information can fully play a role in guiding in the process of generating the countermeasure information by carrying out attention processing on the semantic vectors and the spliced information, so that the countermeasure information which is more in accordance with expectations is obtained; in addition, different candidate countermeasure fingers can be adopted for the same original information to indicate countermeasure information under different countermeasure types, so that diversity of the countermeasure information is improved, and the first language model is trained by using accurate and rich countermeasure information, so that the first language model can better adapt to and process various complex and challenging language information, and the processing effect of the first language model on language information processing tasks is improved.
In one embodiment, as shown in FIG. 15, the apparatus further comprises a challenge instruction library construction module 1410 for: selecting indicative text information from a data source; carrying out availability classification on the text information to obtain classification categories of the text information; taking the text information classified into available indication categories as candidate countermeasure indication information; the candidate countermeasure indication information is stored in a countermeasure indication library.
In one embodiment, the antagonism indication library construction module 1410 is further configured to: extracting characteristics of the text information through a pre-trained information classifier to obtain characteristic vectors; a classification category of the text information is determined based on the feature vector.
In one embodiment, the antagonism indication library construction module 1410: acquiring the classification accuracy of the information classifier; when the classification accuracy rate does not reach the accuracy rate threshold value, the classification category of the indication information is checked to obtain a checked classification category; and taking the indication information of which the classified category is the available category after the collation as candidate countermeasure indication information.
In one embodiment, semantic encoding module 1404 is further to: splicing the original information and the target countermeasure indication information to obtain spliced information; carrying out semantic coding on the spliced information through an encoder of the second language model to obtain a semantic vector; the vector prediction module 1406 is further configured to: and performing attention processing on the semantic vector and the spliced information through a decoder of the second language model to obtain a prediction vector.
In one embodiment, the encoder comprises M encoding layers, the decoder comprises N decoding layers, M and N are positive integers greater than or equal to 2; semantic encoding module 1404 is also configured to: carrying out semantic coding on the spliced information through M coding layers, and carrying out semantic coding on the semantic coding result obtained by each coding layer as input data of the next coding layer in the semantic coding process to obtain a semantic vector; the vector prediction module 1406 is further configured to: and performing attention processing on the semantic vectors and the splicing information through N decoding layers, and performing attention processing on attention processing results and semantic vectors obtained by each decoding layer as input data of the next decoding layer in the attention processing process to obtain a prediction vector.
In one embodiment, the encoding layer includes a first attention sub-layer, a first normalization sub-layer, a feed forward network sub-layer, and a second normalization sub-layer; semantic encoding module 1404 is also configured to: performing attention processing on input data of the ith coding layer through a first attention sub-layer of the ith coding layer to obtain a first coding result; i is a positive integer less than or equal to M; fusing a first coding result and input data through a first normalization sub-layer of an ith coding layer, and normalizing the fused result to obtain a second coding result;
Performing feature processing on the second coding result through a feedforward network sub-layer of the ith coding layer to obtain a third coding result; fusing the third coding result and the second coding result through a second normalization sub-layer of the ith coding layer, and normalizing the fused result to obtain a semantic coding result of the ith coding layer; when i is smaller than M, taking the semantic coding result of the ith coding layer as input data of the (i+1) th coding layer, reassigning i=i+1, and returning to execute the step of performing attention processing on the input data of the ith coding layer through the first attention sub-layer of the ith coding layer; when i=m, the semantic coding result of the ith coding layer is taken as a semantic vector.
In one embodiment, the decoding layer includes a second attention sub-layer, a third normalization sub-layer, a third attention sub-layer, a fourth normalization sub-layer, a feed forward network sub-layer; the vector prediction module 1406 is further configured to: performing attention processing on input data of the j decoding layer through a second attention sub-layer of the j decoding layer to obtain a first fusion result; fusing the first fusion result and the input data through a third normalization sub-layer of the j decoding layer, and normalizing the fusion result to obtain a second fusion result; performing attention processing on the second fusion result and the semantic vector through a third attention sub-layer of the j-th coding layer to obtain a third fusion result; fusing the third fusion result and the second fusion result through a fourth normalization sub-layer of the j decoding layer, and normalizing the fusion result to obtain a fourth fusion result; performing feature processing on the fourth fusion result through a feedforward network sub-layer of the j decoding layer to obtain an attention processing result of the j decoding layer; when j is smaller than N, taking the attention processing result of the j decoding layer as the input data of the j+1th decoding layer, reassigning j=j+1, and returning to execute the step of performing attention processing on the input data of the j decoding layer through the second attention sub-layer of the j decoding layer; when j=n, the attention processing result of the j-th decoding layer is used as the output result of the decoder, and a prediction vector is obtained.
In one embodiment, as shown in fig. 15, the apparatus further includes a model training module 1412 for: acquiring a label of the countermeasure information; performing language processing on the countermeasure information through the language model to be trained to obtain a first processing result; and carrying out parameter optimization on the language model to be trained based on the first processing result and the label to obtain a first language model.
In one embodiment, as shown in fig. 15, the apparatus further includes a model optimization module 1414 for: acquiring a label of the countermeasure information; performing language processing on the countermeasure information through a pre-training language model to obtain a second processing result; determining a performance index value of the pre-training language model based on the second processing result and the label; when the performance index value does not reach the index value threshold value, misjudged target countermeasure information is selected from the countermeasure information, and parameter optimization is performed on the pre-training language model based on the target countermeasure information, so that a first language model is obtained.
In one embodiment, as shown in fig. 15, the apparatus further comprises a data processing module 1416: acquiring context data formed by a target object in a man-machine conversation process; extracting the characteristics of the context data through a first language model to obtain a characteristic vector; dialogue data is generated based on the feature vectors.
The respective modules in the above-described countermeasure information generation apparatus may be implemented in whole or in part by software, hardware, or a combination thereof. The above modules may be embedded in hardware or may be independent of a processor in the computer device, or may be stored in software in a memory in the computer device, so that the processor may call and execute operations corresponding to the above modules.
In one embodiment, a computer device is provided, which may be a terminal, and the internal structure thereof may be as shown in fig. 16. The computer device includes a processor, a memory, an input/output interface, a communication interface, a display unit, and an input means. The processor, the memory and the input/output interface are connected through a system bus, and the communication interface, the display unit and the input device are connected to the system bus through the input/output interface. Wherein the processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage media. The input/output interface of the computer device is used to exchange information between the processor and the external device. The communication interface of the computer device is used for carrying out wired or wireless communication with an external terminal, and the wireless mode can be realized through WIFI, a mobile cellular network, NFC (near field communication) or other technologies. The computer program is executed by a processor to implement a method of generating challenge information. The display unit of the computer equipment is used for forming a visual picture, and can be a display screen, a projection device or a virtual reality imaging device, wherein the display screen can be a liquid crystal display screen or an electronic ink display screen, the input device of the computer equipment can be a touch layer covered on the display screen, can also be a key, a track ball or a touch pad arranged on a shell of the computer equipment, and can also be an external keyboard, a touch pad or a mouse and the like.
It will be appreciated by those skilled in the art that the structure shown in fig. 16 is merely a block diagram of a portion of the structure associated with the present application and is not limiting of the computer device to which the present application is applied, and that a particular computer device may include more or fewer components than shown, or may combine certain components, or have a different arrangement of components.
In an embodiment, there is also provided a computer device comprising a memory and a processor, the memory having stored therein a computer program, the processor implementing the steps of the method embodiments described above when the computer program is executed.
In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored which, when executed by a processor, carries out the steps of the method embodiments described above.
In an embodiment, a computer program product is provided, comprising a computer program which, when executed by a processor, implements the steps of the method embodiments described above.
It should be noted that, the user information (including, but not limited to, user equipment information, user personal information, etc.) and the data (including, but not limited to, data for analysis, stored data, presented data, etc.) referred to in the present application are information and data authorized by the user or sufficiently authorized by each party, and the collection, use and processing of the related data are required to comply with the related laws and regulations and standards of the related countries and regions.
Those skilled in the art will appreciate that implementing all or part of the above described methods may be accomplished by way of a computer program stored on a non-transitory computer readable storage medium, which when executed, may comprise the steps of the embodiments of the methods described above. Any reference to memory, database, or other medium used in the various embodiments provided herein may include at least one of non-volatile and volatile memory. The nonvolatile Memory may include Read-Only Memory (ROM), magnetic tape, floppy disk, flash Memory, optical Memory, high density embedded nonvolatile Memory, resistive random access Memory (ReRAM), magnetic random access Memory (Magnetoresistive Random Access Memory, MRAM), ferroelectric Memory (Ferroelectric Random Access Memory, FRAM), phase change Memory (Phase Change Memory, PCM), graphene Memory, and the like. Volatile memory can include random access memory (Random Access Memory, RAM) or external cache memory, and the like. By way of illustration, and not limitation, RAM can be in the form of a variety of forms, such as static random access memory (Static Random Access Memory, SRAM) or dynamic random access memory (Dynamic Random Access Memory, DRAM), and the like. The databases referred to in the various embodiments provided herein may include at least one of relational databases and non-relational databases. The non-relational database may include, but is not limited to, a blockchain-based distributed database, and the like. The processors referred to in the embodiments provided herein may be general purpose processors, central processing units, graphics processors, digital signal processors, programmable logic units, quantum computing-based data processing logic units, etc., without being limited thereto.
The technical features of the above embodiments may be arbitrarily combined, and all possible combinations of the technical features in the above embodiments are not described for brevity of description, however, as long as there is no contradiction between the combinations of the technical features, they should be considered as the scope of the description.
The above examples only represent a few embodiments of the present application, which are described in more detail and are not to be construed as limiting the scope of the present application. It should be noted that it would be apparent to those skilled in the art that various modifications and improvements could be made without departing from the spirit of the present application, which would be within the scope of the present application. Accordingly, the scope of protection of the present application shall be subject to the appended claims.

Claims (15)

1. A method of generating challenge information, the method comprising:
when a countermeasure information generation task for the original information is received, selecting target countermeasure instruction information from at least one candidate countermeasure instruction information of a countermeasure instruction library;
performing semantic coding on spliced information obtained by splicing the original information and the target countermeasure indication information to obtain a semantic vector;
Fusing the semantic vector and the splicing information to obtain fused information, and performing attention processing on the fused information to obtain a prediction vector;
and generating countermeasure information under the countermeasure type indicated by the target countermeasure indication information based on the prediction vector, wherein the countermeasure information is used for training a first language model, and the first language model is used for executing a language information processing task.
2. The method according to claim 1, wherein the method further comprises:
selecting indicative text information from a data source;
carrying out availability classification on the text information to obtain classification categories of the text information;
taking the text information with the classification category as an available indication category as candidate countermeasure indication information;
storing the candidate countermeasure indication information to the countermeasure indication library.
3. The method of claim 2, wherein said classifying the availability of the text information to obtain a classification class of the text information comprises:
extracting the characteristics of the text information through a pre-trained information classifier to obtain a characteristic vector;
a classification category of the text information is determined based on the feature vector.
4. A method according to claim 3, wherein said classifying the text information of the category as an available indication category as candidate countermeasure indication information includes:
acquiring the classification accuracy of the information classifier;
when the classification accuracy rate does not reach the accuracy rate threshold value, the classification category of the indication information is checked to obtain a checked classification category;
and taking the indication information of which the classified category is available after the collation as candidate countermeasure indication information.
5. The method according to claim 1, wherein said semantically encoding the spliced information obtained by splicing the original information and the target countermeasure indication information to obtain a semantic vector, comprises:
splicing the original information and the target countermeasure indication information to obtain spliced information;
carrying out semantic coding on the spliced information through an encoder of the second language model to obtain a semantic vector;
the step of fusing the semantic vector and the splicing information to obtain fusion information, the step of performing attention processing on the fusion information to obtain a prediction vector comprises the following steps:
and fusing the semantic vector and the splicing information through a decoder of the second language model to obtain fusion information, and performing attention processing on the fusion information to obtain a prediction vector.
6. The method of claim 5, wherein the encoder comprises M encoding layers, the decoder comprises N decoding layers, M and N are each positive integers greater than or equal to 2; the encoder for performing semantic coding on the spliced information through the second language model to obtain a semantic vector, which comprises the following steps:
carrying out semantic coding on the spliced information through the M coding layers, and carrying out semantic coding on a semantic coding result obtained by each coding layer as input data of the next coding layer in the semantic coding process to obtain a semantic vector;
the method for obtaining the prediction vector by fusing the semantic vector and the splicing information through the decoder of the second language model to obtain fusion information, and performing attention processing on the fusion information to obtain the prediction vector comprises the following steps:
and fusing the semantic vectors and the splicing information through the N decoding layers to obtain fusion information, performing attention processing on the fusion information, and performing attention processing on the attention processing result obtained by each decoding layer and the semantic vectors as input data of the next decoding layer in the attention processing process to obtain a prediction vector.
7. The method of claim 6, wherein the encoding layer comprises a first attention sub-layer, a first normalization sub-layer, a feed forward network sub-layer, and a second normalization sub-layer; the step of performing semantic coding on the spliced information through the M coding layers, and performing semantic coding on a semantic coding result obtained by each coding layer as input data of a next coding layer in a semantic coding process to obtain a semantic vector, wherein the step of performing semantic coding comprises the following steps of:
performing attention processing on input data of an ith coding layer through a first attention sub-layer of the ith coding layer to obtain a first coding result; i is a positive integer less than or equal to M;
fusing the first coding result and the input data through a first normalization sub-layer of the ith coding layer, and normalizing the fused result to obtain a second coding result;
performing feature processing on the second coding result through the feedforward network sub-layer of the ith coding layer to obtain a third coding result;
fusing the third coding result and the second coding result through a second normalization sub-layer of the ith coding layer, and normalizing the fused result to obtain a semantic coding result of the ith coding layer;
When i is smaller than M, taking the semantic coding result of the ith coding layer as input data of the (i+1) th coding layer, reassigning i=i+1, and returning to the step of executing the attention processing on the input data of the ith coding layer through the first attention sub-layer of the ith coding layer;
and when i=M, taking the semantic coding result of the ith coding layer as a semantic vector.
8. The method of claim 6, wherein the decoding layer comprises a second attention sub-layer, a third normalization sub-layer, a third attention sub-layer, a fourth normalization sub-layer, a feed forward network sub-layer; the method for processing the semantic vector and the splicing information by the N decoding layers to obtain fusion information, performing attention processing on the fusion information, and performing attention processing on an attention processing result obtained by each decoding layer and the semantic vector as input data of the next decoding layer in the attention processing process to obtain a prediction vector, wherein the method comprises the following steps of:
performing attention processing on input data of a j decoding layer through a second attention sub-layer of the j decoding layer to obtain a first fusion result;
Fusing the first fusion result and the input data through a third normalization sub-layer of the j decoding layer, and normalizing the fusion result to obtain a second fusion result;
fusing the second fusion result and the semantic vector through a third attention sub-layer of the j decoding layer to obtain fusion information, and performing attention processing on the fusion information to obtain a third fusion result;
fusing the third fusion result and the second fusion result through a fourth normalization sub-layer of the j decoding layer, and normalizing the fusion result to obtain a fourth fusion result;
performing feature processing on the fourth fusion result through a feedforward network sub-layer of the j decoding layer to obtain an attention processing result of the j decoding layer;
when j is smaller than N, taking the attention processing result of the j decoding layer as the input data of the j+1th decoding layer, reassigning j=j+1, and returning to the step of executing the attention processing on the input data of the j decoding layer through the second attention sub-layer of the j decoding layer;
And when j=N, taking the attention processing result of the j-th decoding layer as the output result of the decoder to obtain a prediction vector.
9. The method according to any one of claims 1 to 8, further comprising:
acquiring a label of the countermeasure information;
performing language processing on the countermeasure information through a language model to be trained to obtain a first processing result;
and carrying out parameter optimization on the language model to be trained based on the first processing result and the label to obtain the first language model.
10. The method according to any one of claims 1 to 8, further comprising:
acquiring a label of the countermeasure information;
performing language processing on the countermeasure information through a pre-training language model to obtain a second processing result;
determining a performance index value of the pre-training language model based on the second processing result and the label;
and when the performance index value does not reach the index value threshold, selecting misjudged target countermeasure information from the countermeasure information, and carrying out parameter optimization on the pre-training language model based on the target countermeasure information to obtain the first language model.
11. The method according to any one of claims 1 to 8, further comprising:
acquiring context data formed by a target object in a man-machine conversation process;
extracting the characteristics of the context data through the first language model to obtain characteristic vectors;
dialogue data is generated based on the feature vector.
12. An apparatus for generating countermeasure information, the apparatus comprising:
a countermeasure instruction information selection module for selecting target countermeasure instruction information from at least one candidate countermeasure instruction information of a countermeasure instruction library when a countermeasure information generation task for the original information is received;
the semantic coding module is used for carrying out semantic coding on the spliced information obtained by splicing the original information and the target countermeasure indication information to obtain a semantic vector;
the vector prediction module is used for fusing the semantic vector and the splicing information to obtain fusion information, and performing attention processing on the fusion information to obtain a prediction vector;
and the information generation module is used for generating countermeasure information under the countermeasure type indicated by the target countermeasure indication information based on the prediction vector, wherein the countermeasure information is used for training a first language model, and the first language model is used for executing a language information processing task.
13. A computer device comprising a memory and a processor, the memory storing a computer program, characterized in that the processor implements the steps of the method of any one of claims 1 to 11 when the computer program is executed.
14. A computer readable storage medium, on which a computer program is stored, characterized in that the computer program, when being executed by a processor, implements the steps of the method of any of claims 1 to 11.
15. A computer program product comprising a computer program, characterized in that the computer program, when being executed by a processor, implements the steps of the method of any one of claims 1 to 11.
CN202410023557.0A 2024-01-08 2024-01-08 Method, device, computer equipment and storage medium for generating countermeasure information Active CN117521674B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202410023557.0A CN117521674B (en) 2024-01-08 2024-01-08 Method, device, computer equipment and storage medium for generating countermeasure information

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202410023557.0A CN117521674B (en) 2024-01-08 2024-01-08 Method, device, computer equipment and storage medium for generating countermeasure information

Publications (2)

Publication Number Publication Date
CN117521674A CN117521674A (en) 2024-02-06
CN117521674B true CN117521674B (en) 2024-04-09

Family

ID=89742446

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202410023557.0A Active CN117521674B (en) 2024-01-08 2024-01-08 Method, device, computer equipment and storage medium for generating countermeasure information

Country Status (1)

Country Link
CN (1) CN117521674B (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2020228376A1 (en) * 2019-05-16 2020-11-19 华为技术有限公司 Text processing method and model training method and apparatus
CN112861601A (en) * 2020-12-02 2021-05-28 腾讯科技(深圳)有限公司 Method for generating confrontation sample and related equipment
CN113053516A (en) * 2021-03-26 2021-06-29 安徽科大讯飞医疗信息技术有限公司 Countermeasure sample generation method, device, equipment and storage medium
CN114444476A (en) * 2022-01-25 2022-05-06 腾讯科技(深圳)有限公司 Information processing method, apparatus and computer readable storage medium

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US11886815B2 (en) * 2021-05-28 2024-01-30 Adobe Inc. Self-supervised document representation learning

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2020228376A1 (en) * 2019-05-16 2020-11-19 华为技术有限公司 Text processing method and model training method and apparatus
CN112861601A (en) * 2020-12-02 2021-05-28 腾讯科技(深圳)有限公司 Method for generating confrontation sample and related equipment
CN113053516A (en) * 2021-03-26 2021-06-29 安徽科大讯飞医疗信息技术有限公司 Countermeasure sample generation method, device, equipment and storage medium
CN114444476A (en) * 2022-01-25 2022-05-06 腾讯科技(深圳)有限公司 Information processing method, apparatus and computer readable storage medium

Also Published As

Publication number Publication date
CN117521674A (en) 2024-02-06

Similar Documents

Publication Publication Date Title
CN110309283B (en) Answer determination method and device for intelligent question answering
CN108536679B (en) Named entity recognition method, device, equipment and computer readable storage medium
WO2020228376A1 (en) Text processing method and model training method and apparatus
CN110737801B (en) Content classification method, apparatus, computer device, and storage medium
WO2022037256A1 (en) Text sentence processing method and device, computer device and storage medium
CN111444340B (en) Text classification method, device, equipment and storage medium
CN109101537B (en) Multi-turn dialogue data classification method and device based on deep learning and electronic equipment
CN111597830A (en) Multi-modal machine learning-based translation method, device, equipment and storage medium
JP2023539532A (en) Text classification model training method, text classification method, device, equipment, storage medium and computer program
CN110234018B (en) Multimedia content description generation method, training method, device, equipment and medium
CN111401077A (en) Language model processing method and device and computer equipment
CN116720004B (en) Recommendation reason generation method, device, equipment and storage medium
CN113065358B (en) Text-to-semantic matching method based on multi-granularity alignment for bank consultation service
CN113127624B (en) Question-answer model training method and device
CN111914067A (en) Chinese text matching method and system
CN110795944A (en) Recommended content processing method and device, and emotion attribute determining method and device
CN113704460A (en) Text classification method and device, electronic equipment and storage medium
CN113627447A (en) Label identification method, label identification device, computer equipment, storage medium and program product
CN111666400A (en) Message acquisition method and device, computer equipment and storage medium
CN110597968A (en) Reply selection method and device
Hsueh et al. A Task-oriented Chatbot Based on LSTM and Reinforcement Learning
CN117132923A (en) Video classification method, device, electronic equipment and storage medium
Ermatita et al. Sentiment Analysis of COVID-19 using Multimodal Fusion Neural Networks.
CN116975199A (en) Text prediction method, device, equipment and storage medium
CN116258147A (en) Multimode comment emotion analysis method and system based on heterogram convolution

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant