CN116227474A - Method and device for generating countermeasure text, storage medium and electronic equipment - Google Patents

Method and device for generating countermeasure text, storage medium and electronic equipment Download PDF

Info

Publication number
CN116227474A
CN116227474A CN202310514835.8A CN202310514835A CN116227474A CN 116227474 A CN116227474 A CN 116227474A CN 202310514835 A CN202310514835 A CN 202310514835A CN 116227474 A CN116227474 A CN 116227474A
Authority
CN
China
Prior art keywords
text
representative
determining
original
countermeasure
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.)
Granted
Application number
CN202310514835.8A
Other languages
Chinese (zh)
Other versions
CN116227474B (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.)
Zhejiang Lab
Original Assignee
Zhejiang Lab
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 Zhejiang Lab filed Critical Zhejiang Lab
Priority to CN202310514835.8A priority Critical patent/CN116227474B/en
Publication of CN116227474A publication Critical patent/CN116227474A/en
Application granted granted Critical
Publication of CN116227474B publication Critical patent/CN116227474B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/20Natural language analysis
    • G06F40/237Lexical tools
    • G06F40/247Thesauruses; Synonyms
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N20/00Machine learning

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Artificial Intelligence (AREA)
  • Software Systems (AREA)
  • General Physics & Mathematics (AREA)
  • Physics & Mathematics (AREA)
  • Computational Linguistics (AREA)
  • General Health & Medical Sciences (AREA)
  • Health & Medical Sciences (AREA)
  • Computer Vision & Pattern Recognition (AREA)
  • Data Mining & Analysis (AREA)
  • Evolutionary Computation (AREA)
  • Medical Informatics (AREA)
  • Audiology, Speech & Language Pathology (AREA)
  • Computing Systems (AREA)
  • Mathematical Physics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
  • Machine Translation (AREA)

Abstract

The specification discloses a method, a device, a storage medium and an electronic device for generating a countermeasure text, comprising: and acquiring each original text used for generating the countermeasure text, determining the feature vector of each original text according to a pre-trained first language model, and clustering each original text to obtain a specified number of text clusters. Then, the representative text is determined from each text cluster, and then the initial countermeasure text corresponding to each representative text is determined. And then, determining a target thinking chain prompt template from preset thinking chain prompt templates according to the determined difference between the original keywords representing the text and the initial countermeasure keywords. And then, generating a thinking chain prompt text by adopting a target thinking chain prompt template according to the representative text and the initial countermeasure text of the representative text. And inputting the thinking chain prompt text into a pre-trained second language model to obtain the target countermeasure text. The countermeasure text can be generated more flexibly, and the generation cost of the countermeasure text is reduced.

Description

Method and device for generating countermeasure text, storage medium and electronic equipment
Technical Field
The present disclosure relates to the field of computer technologies, and in particular, to a method and apparatus for generating an countermeasure text, a storage medium, and an electronic device.
Background
With the continuous development of technology, language models are increasingly widely applied. The language model is an important research direction in the field of natural language processing, and is a model for building the structure and knowledge of a language by learning language data.
To evaluate the robustness of the language model, the language model may be subjected to a text challenge. The text challenge attack refers to adding disturbance to the input text of the language model, and misleading the language model to output an inaccurate prediction result. Wherein the text after adding disturbance to the input text of the language model is the countermeasure text. It can be seen that it is very important to combat text when evaluating the robustness of a language model.
Based on this, the present specification provides a method of generating a countermeasure text.
Disclosure of Invention
The present disclosure provides a method, an apparatus, a storage medium, and an electronic device for generating a countermeasure text, so as to partially solve the foregoing problems in the prior art.
The technical scheme adopted in the specification is as follows:
the specification provides a method for generating a countermeasure text, which comprises the following steps:
Acquiring an original text of a countermeasure text to be generated;
determining the feature vectors corresponding to the original texts respectively according to a first language model trained in advance;
clustering the original texts according to the feature vectors corresponding to the original texts respectively to obtain a specified number of text clusters;
selecting an original text from each text cluster as a representative text;
determining initial countermeasure texts corresponding to the representative texts respectively;
for each representative text, determining a keyword of the representative text as an original keyword, and determining a keyword of an initial countermeasure text corresponding to the representative text as an initial countermeasure keyword;
determining the difference between the original keywords of the representative text and the initial countermeasure keywords corresponding to the representative text, and determining a target thinking chain prompt template from preset thinking chain prompt templates according to the difference;
generating a corresponding thinking chain prompt text of the representative text by adopting the target thinking chain prompt template according to the representative text and the initial countermeasure text of the representative text;
and inputting the thinking chain prompt text into a pre-trained second language model to obtain the target countermeasure text corresponding to the representative text.
Optionally, according to the difference, determining a target thinking chain prompt template from preset thinking chain prompt templates, which specifically includes:
transmitting the difference to a user;
and responding to the selection operation of the user, and determining a target thinking chain prompt template corresponding to the selected difference from preset thinking chain prompt templates by the user.
Optionally, the thought chain prompt template includes at least a business requirement and a thought text, wherein the thought text is a text representing how different an original keyword of the representative text is from an original keyword of an initial countermeasure text corresponding to the representative text.
Optionally, for each text cluster, selecting an original text from the text clusters as a representative text, and specifically including:
determining a clustering center of each text cluster and determining the distance from each original text contained in the text cluster to the clustering center;
and determining the original text closest to the clustering center as a representative text according to the determined distances.
Optionally, pre-training the second language model specifically includes:
determining a pre-trained second language pre-training model;
Randomly sampling from a preset text library, and taking the text obtained by sampling as a training text;
inputting the training text into the second language pre-training model to obtain an output result;
inputting the output result into a pre-trained evaluation model to obtain an evaluation result of the output result;
and determining the loss of the training text according to the evaluation result, training the second language pre-training model by taking the minimum loss as a training target, and taking the trained second language pre-training model as a second language model, wherein the loss and the evaluation result are inversely related.
Optionally, pre-training the evaluation model specifically includes:
sequencing the output results according to a preset evaluation standard to obtain a standard sequence;
inputting the output result into an evaluation model to be trained aiming at each output result to obtain an evaluation result corresponding to the output result, and sequencing the output results according to each evaluation result to obtain a prediction sequence;
and training the evaluation model to be trained by taking the minimum difference between the standard sequence and the predicted sequence as a training target.
Optionally, for each text cluster, selecting an original text from the text clusters as a representative text, and specifically including:
for each text cluster, randomly selecting an original text from the text clusters as a representative text.
Optionally, determining the initial countermeasure text corresponding to each representative text specifically includes:
aiming at each representative text, carrying out word segmentation processing on the representative text to obtain each word element of the representative text;
determining the corresponding hyponyms of each word element of the representative text according to a preset hyponym library;
for each word element, determining the priority of the word element according to a first language model trained in advance, and determining the priority of each hyponym corresponding to the word element;
determining target lemmas and target hyponyms according to the priorities of the lemmas and the priorities of the hyponyms corresponding to the lemmas;
and generating initial countermeasure text corresponding to the representative text according to the target word element and the target paraphrasing.
The present specification provides a device for generating a countermeasure text, including:
the acquisition module is used for acquiring each original text used for generating the countermeasure text;
the first determining module is used for determining the feature vector corresponding to each original text according to a pre-trained first language model;
The clustering module is used for clustering the original texts according to the feature vectors corresponding to the original texts to obtain a specified number of text clusters;
the selecting module is used for selecting an original text from each text cluster as a representative text;
the second determining module is used for determining initial countermeasure texts corresponding to the representative texts respectively;
a third determining module, configured to determine, for each representative text, a keyword of the representative text as an original keyword, and determine, as an initial countermeasure keyword, a keyword of an initial countermeasure text corresponding to the representative text;
a fourth determining module, configured to determine a difference between an original keyword of the representative text and an initial countermeasure keyword corresponding to the representative text, and determine a target thinking chain prompt template from preset thinking chain prompt templates according to the difference;
the prompt text generation module is used for generating a corresponding thinking chain prompt text of the representative text by adopting the target thinking chain prompt template according to the representative text and the initial countermeasure text of the representative text;
and the countermeasure text generation module is used for inputting the thinking chain prompt text into a pre-trained second language model to obtain a target countermeasure text corresponding to the representative text.
Optionally, the fourth determining module is specifically configured to send the difference to a user; and responding to the selection operation of the user, and determining a target thinking chain prompt template corresponding to the selected difference from preset thinking chain prompt templates by the user.
Optionally, the thought chain prompt template includes at least a business requirement and a thought text, wherein the thought text is a text representing how different an original keyword of the representative text is from an original keyword of an initial countermeasure text corresponding to the representative text.
Optionally, the selecting module is specifically configured to determine, for each text cluster, a cluster center of the text cluster, and determine a distance from the cluster center to each original text included in the text cluster; and determining the original text closest to the clustering center as a representative text according to the determined distances.
Optionally, the apparatus further comprises:
the first training module is used for determining a pre-trained second language pre-training model; randomly sampling from a preset text library, and taking the text obtained by sampling as a training text; inputting the training text into the second language pre-training model to obtain an output result; inputting the output result into a pre-trained evaluation model to obtain an evaluation result of the output result; and determining the loss of the training text according to the evaluation result, training the second language pre-training model by taking the minimum loss as a training target, and taking the trained second language pre-training model as a second language model, wherein the loss and the evaluation result are inversely related.
Optionally, the apparatus further comprises:
the second training module is used for sequencing the output results according to a preset evaluation standard to obtain a standard sequence; inputting the output result into an evaluation model to be trained aiming at each output result to obtain an evaluation result corresponding to the output result, and sequencing the output results according to each evaluation result to obtain a prediction sequence; and training the evaluation model to be trained by taking the minimum difference between the standard sequence and the predicted sequence as a training target.
Optionally, the selecting module is specifically configured to, for each text cluster, randomly select an original text from the text clusters as the representative text.
Optionally, the second determining module is specifically configured to perform word segmentation processing on each representative text to obtain each word element of the representative text; determining the corresponding hyponyms of each word element of the representative text according to a preset hyponym library; for each word element, determining the priority of the word element according to a first language model trained in advance, and determining the priority of each hyponym corresponding to the word element; determining target lemmas and target hyponyms according to the priorities of the lemmas and the priorities of the hyponyms corresponding to the lemmas; and generating initial countermeasure text corresponding to the representative text according to the target word element and the target paraphrasing.
The present specification provides a computer-readable storage medium storing a computer program which, when executed by a processor, implements the above-described method of generating countermeasure text.
The present specification provides an electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the above method of generating challenge text when executing the program.
The above-mentioned at least one technical scheme that this specification adopted can reach following beneficial effect:
according to the method for generating the countermeasure text, the original text of the countermeasure text to be generated is obtained, the feature vectors corresponding to the original text are determined according to the first language model trained in advance, and the original text is clustered according to the feature vectors corresponding to the original text, so that the text clusters with the specified number are obtained. Then, for each text cluster, selecting an original text from the text clusters as a representative text, and determining an initial countermeasure text corresponding to each representative text. Then, for each representative text, determining a keyword of the representative text as an original keyword, determining a keyword of an initial countermeasure text corresponding to the representative text as an initial countermeasure keyword, determining a difference between the original keyword and the initial countermeasure keyword, and determining a target thinking chain prompt template from preset thinking chain prompt templates according to the difference. And then, generating the thinking chain prompt text corresponding to the representative text by adopting a target thinking chain prompt template according to the representative text and the initial countermeasure text corresponding to the representative text. And inputting the thinking chain prompt text into a pre-trained second language model to obtain the target countermeasure text corresponding to the representative text.
According to the method, when the countermeasure text is generated, the obtained original texts are clustered according to the first language model trained in advance, and the text clusters with the specified number are obtained. Then, a substitution table text is selected from each text cluster, and an initial countermeasure text corresponding to each representative text is determined. And determining a target thinking chain prompt template from preset thinking prompt templates according to the difference between the original keywords of the representative text and the initial countermeasure keywords of the initial countermeasure text corresponding to the representative text. And then, generating the corresponding thinking chain prompt text of the representative text by adopting a target thinking chain prompt template. The thought chain prompt text is input into a pre-trained second language model, and the target countermeasure text of the representative text is obtained. The method for generating the countermeasure text of the original text by prompting the text according to the thinking chain can generate the countermeasure text more flexibly, enrich the attack field of the countermeasure text and reduce the generation cost of the countermeasure text.
Drawings
The accompanying drawings, which are included to provide a further understanding of the specification, illustrate and explain the exemplary embodiments of the present specification and their description, are not intended to limit the specification unduly. In the drawings:
FIG. 1 is a flow chart of a method for generating a countermeasure text provided in the present specification;
FIG. 2 is a schematic diagram of a text of a mental chain prompt provided in the present specification;
FIG. 3 is a flowchart of a training method of a second language model provided in the present specification;
FIG. 4 is a schematic diagram of a device for generating a countermeasure text provided in the present specification;
FIG. 5 is a schematic diagram of another countermeasure text generation apparatus provided in the present specification;
fig. 6 is a schematic structural diagram of an electronic device corresponding to fig. 1 provided in the present specification.
Detailed Description
For the purposes of making the objects, technical solutions and advantages of the present specification more apparent, the technical solutions of the present specification will be clearly and completely described below with reference to specific embodiments of the present specification and corresponding drawings. It will be apparent that the described embodiments are only some, but not all, of the embodiments of the present specification. All other embodiments, which can be made by one of ordinary skill in the art without undue burden from the present disclosure, are intended to be within the scope of the present disclosure.
The following describes in detail the technical solutions provided by the embodiments of the present specification with reference to the accompanying drawings.
Fig. 1 is a flow chart of a method for generating a countermeasure text provided in the present specification, including the following steps:
s100: each original text used to generate the countermeasure text is acquired.
In this specification, the apparatus for generating the countermeasure text acquires each original text for generating the countermeasure text, wherein the apparatus for generating the countermeasure text may be a server or an electronic apparatus such as a desktop computer, a notebook computer, or the like. For convenience of description, the method for generating the countermeasure text provided in the present specification will be described below with only the server as the execution subject. The original text can be any language text, such as "today's movies are really interesting, and the episodes are in relief. "such as" The cake was baked to perfection ". The original text may be a pre-stored text for generating the countermeasure text, or may be a text for generating the countermeasure text acquired by the server in response to an input operation by the user.
S102: and determining the feature vectors corresponding to the original texts respectively according to a pre-trained first language model.
The server may determine feature vectors corresponding to the respective original texts according to a first language model trained in advance. The first language model may be a pre-trained language model, or may be any existing language model, which is not specifically limited in this specification. The first language model may be composed of a text encoder composed of a bi-directional coded self-attention network, which may be a BERT (Bidirectional Encoder Representation from Transformers) structured encoder, and a number of classification heads composed of a full connection layer.
Specifically, for each original text, the server may input the original text into a pre-trained first language model, so as to obtain a feature vector of the original text output by a text encoder of the first language model, where the feature vector may be represented by the following formula:
Figure SMS_1
wherein, the liquid crystal display device comprises a liquid crystal display device,
Figure SMS_2
representing the i-th original text,/->
Figure SMS_3
The feature vector representing the i-th original text, BERT is a text encoder constructed from a bi-directionally encoded self-attention network.
S104: and clustering the original texts according to the feature vectors corresponding to the original texts respectively to obtain a specified number of text clusters.
The server can cluster each original text according to the feature vectors corresponding to the original texts respectively to obtain a specified number of text clusters. When clustering each original text, the server may use a K-means algorithm to cluster each original text to obtain a specified number of text clusters, or may use any existing means to cluster each original text to obtain a specified number of text clusters, which is not specifically limited in the specification. The number is arbitrarily specified, and k text clusters are used as examples in the specification for convenience of description.
When clustering original texts by adopting a K-means algorithm to obtain a specified number of text clusters, the server can firstly select K original texts as clustering centers and classify each original text to the closest clustering center to obtain K text clusters. And then, recalculating the clustering center of each text cluster, and reclassifying each original text to a new clustering center closest to the original text until the clustering center is not changed any more, so as to obtain k clustered text clusters. When the distance between the original text and the clustering center is calculated, the Euclidean distance between the original text and the clustering center can be calculated by adopting the following formula:
Figure SMS_4
wherein, the liquid crystal display device comprises a liquid crystal display device,
Figure SMS_5
values representing the ith dimension of the feature vector of the jth original text, +.>
Figure SMS_6
The value of the ith dimension of the feature vector representing the cluster center. d represents the distance between the jth original text and the cluster center.
S106: for each text cluster, selecting an original text from the text clusters as a representative text.
The server may select, for each text cluster, one original text from the text cluster as the representative text. Specifically, the server may randomly select, for each text cluster, one original text from the text clusters as the representative text.
Further, to enable the determined representative text to better represent the text clusters, the server may determine, for each text cluster, a cluster center of the text cluster, and determine a distance from the cluster center of each original text contained in the text cluster. Then, according to the determined distances, the original text closest to the clustering center is determined as the representative text. When determining the distance between each original text in the text cluster and the clustering center of the text cluster, the formula in step S104 may be used for calculation and determination.
When determining the representative text, the server may sort the original texts in the text cluster according to the determined distance from the clustering center from the near to the far, that is, from the small to the large according to the distance value, so as to obtain the text sequence of the text cluster, which may be represented by the following formula:
Figure SMS_7
wherein, the liquid crystal display device comprises a liquid crystal display device,
Figure SMS_8
text sequence representing the ith text cluster, < +.>
Figure SMS_9
Representing the original text which is in the ith text cluster and is closest to the clustering center of the ith text cluster.
Then, based on the determined distances, the original text nearest to the clustering center is determined as the representative text, i.e. the text is to be
Figure SMS_10
The corresponding original text is taken as the representative text of the ith text cluster. Thus, the k representative texts obtained are
Figure SMS_11
S108: initial challenge text corresponding to each representative text is determined.
The server may determine initial challenge text corresponding to each representative text based on a pre-trained first language model. Specifically, the server may perform word segmentation processing on each representative text to obtain each word element of the representative text, and then determine, according to a preset hyponym library, a hyponym corresponding to each word element of the representative text. Then, for each word element, determining the priority of the word element according to a pre-trained first language model, and determining the priority of each hyponym corresponding to the word element. And then, determining target words and target near-meaning words according to the priorities of the words and the priorities of the near-meaning words corresponding to the words, and generating initial countermeasure text corresponding to the representative text according to the target words and the target near-meaning words. When the representative text is subjected to word segmentation, the server can adopt a pre-trained word segmentation device to perform word segmentation on the representative text, or can adopt any existing means to perform word segmentation on the representative text, and the specification is not limited specifically. The paraphrasing library is a collection of words with the same meaning or similar meaning of various words in advance, such as fun, fun and the like.
For example, assume that the representative text is "today's movies are really interesting, and the episodes are fluctuating. After the server performs word segmentation processing on the representative text, 7 words are obtained, namely, today, movie, true, interesting, plot and fall fluctuation. Then, according to the preset hyponym library, determining the hyponym corresponding to each word element, and assuming that each word element has 3 corresponding hyponyms, for example, the hyponym corresponding to the word element 1 'today' can have the hyponym 1 'present day', the hyponym 2 'today' and the hyponym 3 'this day', determining the hyponyms corresponding to other word elements according to the mode, which is not repeated here.
Then, for each word element, determining the priority of the word element according to a pre-trained first language model, and determining the priority of each hyponym corresponding to the word element. Let us assume that the priorities of the lemmas are, from high to low, lemma 5 "interesting", lemma 7 "fall and rise", lemma 4 "true", lemma 6 "scenario" lemma 3 "movie", lemma 1 "today" and lemma 2 ". The priorities of the hyponyms of the word elements 5 'interesting' are assumed to be similar to those of the hyponyms 1 'different interests', the hyponyms 2 'fun' and the hyponyms 3 'fun' from high to low, and the priorities of the hyponyms of other word elements are not repeated here. And then, determining a target word and a target near meaning word according to the priority of each word and the priority of each near meaning word corresponding to each word, and assuming that the target word is the word 5 'interesting' and the target near meaning word is the near meaning word 1 'abnormal', and then 'really interesting and falling and fluctuation of the scenario of the movie today'. If the "interesting" of the word element 5 is replaced by the "abnormal" of the paraphrasing 1, the initial countermeasure text is the "true abnormal of the movie today, and the situation is fluctuant. ".
When determining the priority of each word element according to the pre-trained first language model, the server can input the representative text into the pre-trained first language model to obtain a prediction result of the representative text as an initial result. Then, for each word element in turn, the word element is deleted from the representative text, and a text which does not contain the word element is obtained as a first text. And inputting the first text into the first language model to obtain a prediction result of the first text as a first result. And determining a difference between the initial result and the first result as a first difference. And determining the priority of the word element according to the first difference value. The first difference may be calculated according to the following formula:
Figure SMS_12
wherein, the liquid crystal display device comprises a liquid crystal display device,
Figure SMS_13
representing the difference between the first result and the initial result of the first text with the ith lemma deleted,/v>
Figure SMS_14
The ith word element representing the text T is deleted, T representing the text,/-, and>
Figure SMS_15
representing the original annotation representing the text T +.>
Figure SMS_16
Representing the first text from which the i-th lemma was deleted.
The prediction result of the language model is a prediction probability. The priority of the word represents the importance degree of the word in the text, the initial result and the first result are obtained by respectively inputting the text (namely the first text) deleted from the representative text and the representative text into the first language model, the priority of the word is determined according to the difference between the initial result and the first result, and the larger the difference is, the larger the importance degree of the represented word is, and the higher the priority is. Therefore, when determining the priority of the word according to the first difference value, the first difference value can be directly used as the priority of the word. And sorting the first difference values according to the first difference values corresponding to the words from big to small, and determining the priority of the words according to the sorting result.
Continuing with the above example, assume that the text "today's movies are truly interesting, and the episodes fall and fluctuate. The initial result obtained by inputting the first language model is 0.9, for the word element 1 'today', the word element 1 'today' is deleted from the original text, and the movie of the first text is interesting, and the plot is fluctuant. By inputting the first text into the first language model, the first result is 0.85, the first difference between the initial result and the first result is 0.05, and the priority of the word element 1 'today' is determined to be 0.05. Similarly, other terms may be prioritized according to the method of this example, and will not be described herein.
Meanwhile, when determining the priority of each hyponym corresponding to the word element, the server can replace the word element with each hyponym of the word element in turn to obtain a replaced text as a second text. And inputting the second text into the first language model to obtain a predicted result of the second text as a second result. Then, a difference between the initial result and the second result is determined as a second difference, and the priority of the paraphrasing is determined based on the second difference. The determining method of the priority of the near-meaning word is similar to the determining method of the priority of the word element, and is not repeated and illustrated herein.
In addition, when determining the target word and the target hyponym according to the priority of each word and the priority of each hyponym corresponding to each word, the server may directly use the word with the highest priority as the target word and then use the hyponym with the highest priority as the target hyponym in the hyponym corresponding to the target word. The server may also determine, for each of the tokens in turn, a combination of the token and the hyponym to which the token corresponds. The method comprises the steps of determining the combination priority of each combination, taking a word element in the combination with the highest combination priority as a target word element, and taking a near meaning word in the combination with the highest combination priority as a target near meaning word. The combined priority may be a product of the priority of the lemma and the priority of the paraphrasing, for example, the priority of the lemma 5 "interesting" is 0.8, the priority of the paraphrasing 1 "different interest" corresponding to the lemma 5 "interesting" is 0.8, and the combined priority of the lemma 5 "interesting" and the paraphrasing 1 "different interest" is 0.64, which can be calculated by the following formula:
Figure SMS_17
wherein, the liquid crystal display device comprises a liquid crystal display device,
Figure SMS_18
indicating the priority of the ith token,/-, and>
Figure SMS_19
indicating the priority at which the ith lemma is replaced with the jth hyponym. />
Figure SMS_20
A combination priority indicating a combination of the i-th term and the j-th hyponym.
When generating the initial countermeasure text corresponding to the representative text according to the target word element and the target paraphrasing, the target word element in the representative text can be replaced by the target paraphrasing, and the replaced text is used as the initial countermeasure text corresponding to the representative text.
S110: for each representative text, determining a keyword of the representative text as an original keyword, and determining a keyword of an initial countermeasure text corresponding to the representative text as an initial countermeasure keyword.
For each representative text, the server may determine a keyword of the representative text as an original keyword and determine a keyword of an initial countermeasure text corresponding to the representative text as an initial countermeasure keyword. Specifically, for each representative text, the server may determine, as an original keyword of the representative text, a term that is inconsistent with each term of the initial countermeasure text among the terms of the representative text. And determining the word elements which are inconsistent with the word elements of the representative text in the word elements of the initial countermeasure text corresponding to the representative text as initial countermeasure keywords of the initial countermeasure text corresponding to the representative text.
Continuing with the above example, the representative text is "today's movies are really interesting, the episodes fall and fluctuate. The initial countermeasure text corresponding to the representative text is' real and different interests of the movie today, and the scenes fall and fall. The term "representing the text is" interesting "because it is inconsistent with the term of the initial countermeasure text corresponding to the representing text, and the term representing the initial countermeasure text corresponding to the representing text is" abnormal "because it is inconsistent with the term of the representing text, and the initial countermeasure keyword is" abnormal ".
The server may also use the target term in the above process as an original keyword representing the text, and use the target paraphrasing as an initial countermeasure keyword representing an initial countermeasure text corresponding to the text.
S112: and determining the difference between the original keywords of the representative text and the initial countermeasure keywords corresponding to the representative text, and determining a target thinking chain prompt template from preset thinking chain prompt templates according to the difference.
S114: and generating a corresponding thinking chain prompt text of the representative text by adopting the target thinking chain prompt template according to the representative text and the initial countermeasure text of the representative text.
The server can determine the difference between the original keywords of the representative text and the initial countermeasure keywords corresponding to the representative text, and determine a target thinking chain prompt template from preset thinking chain prompt templates according to the difference. And then, generating a corresponding mental chain prompt text of the representative text by adopting a target mental chain prompt template according to the representative text and the initial countermeasure text of the representative text. The difference may be a word sense difference between the original keyword and the original countermeasure keyword, such as close or opposite. The thought chain prompt template at least comprises a service requirement and a prompt text of the thought text, wherein the service requirement can be a text representing the purpose of the target countermeasure text corresponding to the representative text, for example, the service requirement can be 'robustness of a plurality of countermeasure texts which are needed to be generated by me', the service requirement can also be designed according to the requirement of a subsequently executed service, and the specification is not particularly limited. The thought text is a text representing how the original keyword of the representative text is different from the original keyword of the initial countermeasure text corresponding to the representative text, and includes the original text (i.e., the representative text), the countermeasure text (i.e., the initial countermeasure text corresponding to the representative text), and the explanatory text. The explanatory text is a text explaining what difference the representative text has with the initial countermeasure text corresponding to the representative text.
The differences between the different original keywords and the initial challenge keywords correspond to different mindset cue templates. If the word senses of the original keywords are similar to those of the initial countermeasure keywords, the server can determine the corresponding thinking chain prompt template with the similar word senses from the preset thinking chain prompt templates as a target thinking chain prompt template. If the word senses of the original keywords are opposite to those of the initial countermeasure keywords, the server can determine the thinking chain prompt template corresponding to the opposite word senses from the preset thinking chain prompt templates as a target thinking chain prompt template.
Continuing to use the above example, the original keyword is "interesting", the initial countermeasure keyword is "abnormal", the original keyword and the initial countermeasure keyword are words with similar senses, and the server can determine the corresponding sense-chain prompting template with similar senses from the preset sense-chain prompting templates as the target sense-chain prompting template. According to the representative text 'today's movies are really interesting, the episodes fall and fluctuate. "initial countermeasure text corresponding to representative text" is true and different for movies today, and the episodes fall and fluctuate. The target thinking chain prompt template is adopted to generate a representative text of ' today's movies are really interesting, and the scenes fall and fluctuate '. "corresponding mental chain prompt text".
The thinking chain prompts the text to test the robustness of the language model with the generated several countermeasure texts, and the representative text is' the movie of today is really interesting, and the situation is fluctuant. "the movie today is really interesting, and the episodes fall and fluctuate. In this sentence, the term "interesting" is a powerful indicator of positive emotion. Replacing "fun" with "Exception" changes the emotion of the text because "Exception" implies that the movie is somewhat different from other movies. Such subtle changes in connotation may make the predictions of the model less accurate. Thus, the countermeasure text is 'today' movie true fun, the situation is fluctuant. ".
S116: and inputting the thinking chain prompt text into a pre-trained second language model to obtain the target countermeasure text corresponding to the representative text.
The server may input the thought chain prompt text into a pre-trained second language model to obtain the target countermeasure text corresponding to the representative text, where the second language model may be a pre-trained model, or may be any existing language model, and the description is not specifically limited.
Specifically, the server may input the thought chain prompt text and the original text into a pre-trained second language model to obtain the target countermeasure text corresponding to the representative text. And continuously using the previous example, and inputting the thinking chain prompt text and the representative text obtained in the previous example into a pre-trained second language model to obtain the target countermeasure text corresponding to the representative text. The input text to the second language model is the content of [ i need to test the robustness of the language model with several countermeasure texts generated, representing that the text is "today's movie is really interesting, the plot is in a fluctuation". "the movie today is really interesting, and the episodes fall and fluctuate. In this sentence, the term "interesting" is a powerful indicator of positive emotion. Replacing "fun" with "Exception" changes the emotion of the text because "Exception" implies that the movie is somewhat different from other movies. Such subtle changes in connotation may make the predictions of the model less accurate. Thus, the countermeasure text is 'today' movie true fun, the situation is fluctuant. ". Then, "today's movies are really interesting, and the episodes fall and fluctuate. "fight text" is given.
If it is desired to generate a countermeasure text other than the representative text, the thought chain prompt text and the other text may be directly input into the second language model, and a target countermeasure text corresponding to the other text may be obtained. For example, [ I need to test the robustness of the language model with several countermeasure texts generated, the original text is "today's movies are really interesting, the episodes are going downed. "the movie today is really interesting, and the episodes fall and fluctuate. In this sentence, the term "interesting" is a powerful indicator of positive emotion. Replacing "fun" with "Exception" changes the emotion of the text because "Exception" implies that the movie is somewhat different from other movies. Such subtle changes in connotation may make the predictions of the model less accurate. Thus, the countermeasure text is 'today' movie true fun, the situation is fluctuant. ". Then, the countermeasure text of "the soundtrack of the movie is true and audible, the feeling of the human heart is a" above "[ what is" is an input text to the second language model ".
According to the method, when the countermeasure text is generated, the original text of the countermeasure text to be generated is obtained, the feature vector of each original text is determined according to the first language model trained in advance, and the original texts are clustered to obtain the text clusters with the specified number. Then, the representative text is determined from each text cluster, and then the initial countermeasure text corresponding to each representative text is determined. Then, a target thinking chain prompt template is determined from preset thinking chain prompt templates according to the determined difference between the original keywords representing the text and the initial countermeasure keywords and according to the difference. And then, according to the representative text and the initial countermeasure text corresponding to the representative text, adopting a target thinking chain prompt template to generate the thinking chain prompt text corresponding to the original text. The original texts are clustered to obtain each text cluster, then the table text is selected from each text cluster, the thinking chain prompt text corresponding to the representative text can be directly generated based on the representative text in the subsequent process, the generation speed of the thinking chain prompt text can be increased, and the target countermeasure text can be rapidly generated in the subsequent process. And inputting the thinking chain prompt text and the representative text into a pre-trained second language model to obtain the target countermeasure text corresponding to the representative text. The method can directly utilize the internal knowledge of the second language model, prompt the text based on the thinking chain, directly position the word elements with higher priority, and perform implicit replacement, so that the countermeasure text can be generated more flexibly, the attack field of the countermeasure text is enriched, and the generation cost of the countermeasure text is reduced.
In order to avoid obtaining the countermeasure text which makes the prediction result of the original text inaccurate by replacing the word element of the original text with the anti-ambiguous word of the word element, a limiting text can be added in the mind-chain prompt text, so the mind-chain prompt template also comprises the limiting text, and the limiting text is used for limiting the generation mode of the countermeasure text, for example, the limiting text is that the generated countermeasure text cannot be subjected to simple anti-ambiguous word replacement, and the word replacement is as hidden as possible. ". Therefore, the structure of the mind-chain prompt text in the above step S114 may be as shown in fig. 2, and fig. 2 is a schematic diagram of the structure of one of the mind-chain prompt texts provided in the present specification. The thought chain prompt text in fig. 2 includes business needs, thought text, and constraint text, and the thought text includes original text, explanatory text, and countermeasure text.
Continuing with the above example, [ I need to test the language model's robustness with several countermeasure texts generated, representing the text as "today's movie is really interesting, the scenario is downed and fluctuant". "the movie today is really interesting, and the episodes fall and fluctuate. In this sentence, the term "interesting" is a powerful indicator of positive emotion. Replacing "fun" with "Exception" changes the emotion of the text because "Exception" implies that the movie is somewhat different from other movies. Such subtle changes in connotation may make the predictions of the model less accurate. Thus, the countermeasure text is 'today' movie true fun, the situation is fluctuant. ". At the same time, I want the subsequent generated countermeasure text not to be able to make simple anti-meaning word replacement, and word replacement is hidden as much as possible. Then, "today's movies are really interesting, and the episodes fall and fluctuate. The countermeasure text of the above is the thinking chain prompt text.
In the step S112, when determining the target mind-chain prompting templates from the preset mind-chain prompting templates according to the differences, the server may send the differences to the user, and then, in response to the selection operation of the user, determine the target mind-chain prompting templates corresponding to the selected differences from the preset mind-chain prompting templates. Specifically, the server may send the difference to the terminal and display it. And the user selects the thinking chain prompt template corresponding to the difference according to the difference displayed by the terminal and the preset thinking chain prompt template. And the terminal responds to the selection operation of the user, determines a thinking chain prompt template selected by the user and sends the thinking chain prompt template to the server. The server receives the information sent by the terminal and takes the thinking chain prompt template selected by the user as a target thinking chain prompt template.
In the step S116, the server may further input, into the second language model, the thought chain prompt text corresponding to the representative text and any original text in the text cluster in which the representative text is located, to obtain the target countermeasure text of the input original text.
In this specification, when determining the minlink prompt text of the representative text, the server may transmit the representative text and the initial countermeasure text corresponding to the representative text to the user, and determine the minlink prompt text of the representative text in response to an input operation of the user. Specifically, the server sends the representative text and the initial countermeasure text corresponding to the representative text to the terminal, and displays the initial countermeasure text. And the user inputs the thinking chain prompt text of the representative text according to the representative text displayed by the terminal and the initial countermeasure text corresponding to the representative text. The terminal determines a thought chain prompt text representing the text in response to an input operation of the user, and transmits the text to the server.
In the present specification, the first language model and the second language model are different in model structure, that is, the model parameters of the two models are different, the depth of the network layer is also different, the data size of the training set used by the first language model and the second language model is also different, the first language model is a model trained based on a training set with a smaller data size, and the second language model is a model trained based on a large training set.
When the first language model is trained, the first language model to be trained can be pre-trained with a word mask prediction task and a sentence sequence prediction task. Specifically, the word segmentation machine may be trained based on the original sample dataset first, creating a vocabulary corresponding to the dataset. And processing the original sample according to the pre-training task to obtain a training sample for training and labels corresponding to the training sample. Based on the obtained training samples and labels corresponding to the training samples, pre-training of a word mask prediction task and a sentence sequence prediction task is carried out on a first language model to be trained.
If the pre-training task is a word mask prediction task, it is assumed that the original sample may be "today's movie is really interesting, and the scenario is fluctuated. The word element of interest can be masked according to the requirement of word MASK prediction, so that a training sample of' movie true [ MASK ] today and scene fluctuation can be obtained. "and training sample labels" fun ".
If the pre-training task is a sentence sequential prediction task, the original sample is assumed to be' the movie of today is really interesting, and the next time is seen; i feel so much that "can be processed according to the requirements of sentence sequential prediction tasks" the training data "today's movies are really interesting, see next that [ SEP ] is, I feel so much", and the training tag "1" indicates that the following sentence has a logical connection with the preceding sentence.
After the first language model to be trained is pre-trained, fine tuning is performed on the first language model to be trained according to the original sample dataset. The original sample data set may be a Stanford emotion tree library (The Stanford Sentiment Treebank, SST-2 for short), which contains sentences and emotion labels in movie comments.
In this specification, the second language model may be obtained by further training on the basis of a pre-trained second language pre-training model, and the specific process is shown in fig. 3, and fig. 3 is a schematic flow chart of a training method of the second language model provided in this specification, which includes the following steps:
s200: a pre-trained second language pre-training model is determined.
S202: randomly sampling from a preset text library, and taking the sampled text as training text.
S204: and inputting the training text into the second language pre-training model to obtain an output result, training the second language pre-training model by taking the smallest difference between the output result and the labels corresponding to the training samples as a training target, and taking the trained second language pre-training model as a second language model.
The training process of the second language pre-training model is similar to the pre-training process of the first language model, and the pre-training process is not repeated here. The preset text library is various types of texts collected in advance, for example, the texts can be "graceful language describing mountain peaks" and the labels of training samples can be labeled in advance by users, or can be collected in advance, for example, "graceful language describing mountain peaks" and the labels of the training samples can be "the mountain groups of green, overlapping and overlapping, as if the seas were fluctuant, the seas were fluctuant and the male majors. ".
The server may also determine a pre-trained second language pre-training model, randomly sample from a preset text library, and use the sampled text as training text. And then, inputting the training text into a second language and training model to obtain an output result. And inputting the output result into a pre-trained evaluation model to obtain an evaluation result of the output result, determining the loss of the training sample according to the evaluation result, taking the minimum loss as a training target, training the second language pre-training model, and taking the trained second language pre-training model as the second language model. Wherein, the evaluation result characterizes the quality of the output result and can be a score. The higher the score of the output result, the higher the quality of the output result, the closer the output result is to the label of the training sample, and the smaller the loss, so the loss is inversely related to the evaluation result. Based on the evaluation model, training the second language pre-training model to obtain a second language model, so that the second language model can output an output result with high score, namely an output result with high quality.
When the evaluation model is trained in advance, the server can sort the output results according to a preset evaluation standard to obtain a standard sequence. And inputting the output result into an evaluation model to be trained aiming at each output result to obtain an evaluation result corresponding to the output result, and sequencing the output results according to each evaluation result to obtain a prediction sequence. And then, training the evaluation model to be trained by taking the minimum difference between the standard sequence and the predicted sequence as a training target. The evaluation criteria may be preset evaluation rules, and the server may sort the output results according to the preset evaluation criteria. Each output result is a plurality of output results obtained by inputting the training sample into the second language model for a plurality of times.
When the output results are ranked according to the preset evaluation criteria to obtain the standard sequence, the server can send the output results to the user so that the user ranks the output results. And determining a standard sequence obtained by sequencing all output results by the user in response to the input operation of the user.
In addition, in order to be able to quickly determine the standard sequence of each output result, the server may combine each output result two by two, and send the combination to the user for each combination in turn, so that the user determines which output result in the combination has a high score. In response to a user selection operation, a standard sequence of each output result is determined.
When the output results are ranked according to the evaluation results to obtain the predicted sequence, the server can rank the output results according to the evaluation results from high score to low score to obtain the predicted sequence.
In the step S108, the server may input the original text into the first language model to obtain an initial result of the original text, determine the first text, and input the first text into the first language model to obtain a first result of the first text. The first text can be determined first, the first text is input into the first language model to obtain a first result of the first text, and then the original text is input into the first language model to obtain an initial result of the original text.
Based on the above method for generating the countermeasure text, in the present specification, after acquiring each original text for generating the countermeasure text, the server may determine an initial countermeasure text corresponding to each original text according to a first language model trained in advance. Then, for each original text, determining an original keyword of the original text and an initial countermeasure keyword of an initial countermeasure text corresponding to the original text, determining a difference between the original keyword and the initial countermeasure keyword, and determining a target thinking chain prompt template according to the difference. And then, generating the thinking chain prompt text of the original text by adopting a target thinking chain prompt template. And inputting the thinking chain prompt text into a pre-trained second language model to obtain the target countermeasure text of the original text. The specific process of each step is similar to that of the above method for generating the countermeasure text, and will not be described herein.
The foregoing is a method implemented by one or more embodiments of the present specification, and based on the same concept, the present specification further provides a corresponding device for generating the countermeasure text, as shown in fig. 4.
Fig. 4 is a schematic diagram of a device for generating a countermeasure text provided in the present specification, including:
an acquisition module 300 for acquiring original texts for generating a countermeasure text;
a first determining module 302, configured to determine feature vectors corresponding to the original texts according to a first language model that is trained in advance;
the clustering module 304 is configured to cluster each original text according to the feature vector corresponding to each original text, to obtain a specified number of text clusters;
a selecting module 306, configured to select, for each text cluster, an original text from the text clusters as a representative text;
a second determining module 308, configured to determine initial countermeasure texts corresponding to the representative texts respectively;
a third determining module 310, configured to determine, for each representative text, a keyword of the representative text as an original keyword, and determine, as an initial countermeasure keyword, a keyword of an initial countermeasure text corresponding to the representative text;
a fourth determining module 312, configured to determine a difference between the original keyword of the representative text and the initial countermeasure keyword corresponding to the representative text, and determine a target mind-chain prompting template from preset mind-chain prompting templates according to the difference;
The prompt text generation module 314 is configured to generate, according to the representative text and the initial countermeasure text of the representative text, a prompt text of a chain of thought corresponding to the representative text by using the target chain of thought prompt template;
and the countermeasure text generation module 316 is configured to input the mind chain prompt text into a pre-trained second language model, and obtain a target countermeasure text corresponding to the representative text.
Optionally, the fourth determining module 312 is specifically configured to send the difference to a user; and responding to the selection operation of the user, and determining a target thinking chain prompt template corresponding to the selected difference from preset thinking chain prompt templates by the user.
Optionally, the thought chain prompt template includes at least a business requirement and a thought text, wherein the thought text is a text representing how different an original keyword of the representative text is from an original keyword of an initial countermeasure text corresponding to the representative text.
Optionally, the selecting module 306 is specifically configured to determine, for each text cluster, a cluster center of the text cluster, and determine a distance from the cluster center of each original text included in the text cluster; and determining the original text closest to the clustering center as a representative text according to the determined distances.
Optionally, the apparatus further comprises:
a first training module 318 for determining a pre-trained second language pre-training model; randomly sampling from a preset text library, and taking the text obtained by sampling as a training text; inputting the training text into the second language pre-training model to obtain an output result; inputting the output result into a pre-trained evaluation model to obtain an evaluation result of the output result; and determining the loss of the training text according to the evaluation result, training the second language pre-training model by taking the minimum loss as a training target, and taking the trained second language pre-training model as a second language model, wherein the loss and the evaluation result are inversely related.
Optionally, the apparatus further comprises:
the second training module 320 is configured to sort the output results according to a preset evaluation criterion, so as to obtain a standard sequence; inputting the output result into an evaluation model to be trained aiming at each output result to obtain an evaluation result corresponding to the output result, and sequencing the output results according to each evaluation result to obtain a prediction sequence; and training the evaluation model to be trained by taking the minimum difference between the standard sequence and the predicted sequence as a training target.
Optionally, the selecting module 306 is specifically configured to, for each text cluster, randomly select an original text from the text clusters as the representative text.
Optionally, the second determining module 308 is specifically configured to, for each representative text, perform word segmentation on the representative text to obtain each term of the representative text; determining the corresponding hyponyms of each word element of the representative text according to a preset hyponym library; for each word element, determining the priority of the word element according to a first language model trained in advance, and determining the priority of each hyponym corresponding to the word element; determining target lemmas and target hyponyms according to the priorities of the lemmas and the priorities of the hyponyms corresponding to the lemmas; and generating initial countermeasure text corresponding to the representative text according to the target word element and the target paraphrasing.
The present disclosure also provides a schematic diagram of an apparatus for generating a countermeasure text, as shown in fig. 5, and fig. 5 is a schematic diagram of another apparatus for generating a countermeasure text provided in the present disclosure. The device for generating the countermeasure text further includes the first training module 318 and the second training module 320.
The present specification also provides a computer-readable storage medium storing a computer program operable to perform a method of generating a countermeasure text as provided in fig. 1 above.
The present specification also provides a schematic structural diagram of an electronic device corresponding to fig. 1 shown in fig. 6. At the hardware level, as shown in fig. 6, the electronic device includes a processor, an internal bus, a network interface, a memory, and a nonvolatile storage, and may of course include hardware required by other services. The processor reads the corresponding computer program from the nonvolatile memory into the memory and then runs the computer program to implement the method for generating the countermeasure text described in fig. 1.
Of course, other implementations, such as logic devices or combinations of hardware and software, are not excluded from the present description, that is, the execution subject of the following processing flows is not limited to each logic unit, but may be hardware or logic devices.
In the 90 s of the 20 th century, improvements to one technology could clearly be distinguished as improvements in hardware (e.g., improvements to circuit structures such as diodes, transistors, switches, etc.) or software (improvements to the process flow). However, with the development of technology, many improvements of the current method flows can be regarded as direct improvements of hardware circuit structures. Designers almost always obtain corresponding hardware circuit structures by programming improved method flows into hardware circuits. Therefore, an improvement of a method flow cannot be said to be realized by a hardware entity module. For example, a programmable logic device (Programmable Logic Device, PLD) (e.g., field programmable gate array (Field Programmable Gate Array, FPGA)) is an integrated circuit whose logic function is determined by the programming of the device by a user. A designer programs to "integrate" a digital system onto a PLD without requiring the chip manufacturer to design and fabricate application-specific integrated circuit chips. Moreover, nowadays, instead of manually manufacturing integrated circuit chips, such programming is mostly implemented by using "logic compiler" software, which is similar to the software compiler used in program development and writing, and the original code before the compiling is also written in a specific programming language, which is called hardware description language (Hardware Description Language, HDL), but not just one of the hdds, but a plurality of kinds, such as ABEL (Advanced Boolean Expression Language), AHDL (Altera Hardware Description Language), confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), lava, lola, myHDL, PALASM, RHDL (Ruby Hardware Description Language), etc., VHDL (Very-High-Speed Integrated Circuit Hardware Description Language) and Verilog are currently most commonly used. It will also be apparent to those skilled in the art that a hardware circuit implementing the logic method flow can be readily obtained by merely slightly programming the method flow into an integrated circuit using several of the hardware description languages described above.
The controller may be implemented in any suitable manner, for example, the controller may take the form of, for example, a microprocessor or processor and a computer readable medium storing computer readable program code (e.g., software or firmware) executable by the (micro) processor, logic gates, switches, application specific integrated circuits (Application Specific Integrated Circuit, ASIC), programmable logic controllers, and embedded microcontrollers, examples of which include, but are not limited to, the following microcontrollers: ARC 625D, atmel AT91SAM, microchip PIC18F26K20, and Silicone Labs C8051F320, the memory controller may also be implemented as part of the control logic of the memory. Those skilled in the art will also appreciate that, in addition to implementing the controller in a pure computer readable program code, it is well possible to implement the same functionality by logically programming the method steps such that the controller is in the form of logic gates, switches, application specific integrated circuits, programmable logic controllers, embedded microcontrollers, etc. Such a controller may thus be regarded as a kind of hardware component, and means for performing various functions included therein may also be regarded as structures within the hardware component. Or even means for achieving the various functions may be regarded as either software modules implementing the methods or structures within hardware components.
The system, apparatus, module or unit set forth in the above embodiments may be implemented in particular by a computer chip or entity, or by a product having a certain function. One typical implementation is a computer. In particular, the computer may be, for example, a personal computer, a laptop computer, a cellular telephone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.
For convenience of description, the above devices are described as being functionally divided into various units, respectively. Of course, the functions of each element may be implemented in one or more software and/or hardware elements when implemented in the present specification.
It will be appreciated by those skilled in the art that embodiments of the present description may be provided as a method, system, or computer program product. Accordingly, the present specification may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present description can take the form of a computer program product on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) having computer-usable program code embodied therein.
The present description is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems) and computer program products according to embodiments of the specification. It will be understood that each flow and/or block of the flowchart illustrations and/or block diagrams, and combinations of flows and/or blocks in the flowchart illustrations and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
In one typical configuration, a computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
The memory may include volatile memory in a computer-readable medium, random Access Memory (RAM) and/or nonvolatile memory, such as Read Only Memory (ROM) or flash memory (flash RAM). Memory is an example of computer-readable media.
Computer readable media, including both non-transitory and non-transitory, removable and non-removable media, may implement information storage by any method or technology. The information may be computer readable instructions, data structures, modules of a program, or other data. Examples of storage media for a computer include, but are not limited to, phase change memory (PRAM), static Random Access Memory (SRAM), dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), read Only Memory (ROM), electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), digital Versatile Discs (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices, or any other non-transmission medium, which can be used to store information that can be accessed by a computing device. Computer-readable media, as defined herein, does not include transitory computer-readable media (transmission media), such as modulated data signals and carrier waves.
It should also be noted that the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article or apparatus that comprises the element.
It will be appreciated by those skilled in the art that embodiments of the present description may be provided as a method, system, or computer program product. Accordingly, the present specification may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present description can take the form of a computer program product on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) having computer-usable program code embodied therein.
The description may be described in the general context of computer-executable instructions, such as program modules, being executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform particular tasks or implement particular abstract data types. The specification may also be practiced in distributed computing environments where tasks are performed by remote processing devices that are linked through a communications network. In a distributed computing environment, program modules may be located in both local and remote computer storage media including memory storage devices.
In this specification, each embodiment is described in a progressive manner, and identical and similar parts of each embodiment are all referred to each other, and each embodiment mainly describes differences from other embodiments. In particular, for system embodiments, since they are substantially similar to method embodiments, the description is relatively simple, as relevant to see a section of the description of method embodiments.
The foregoing is merely exemplary of the present disclosure and is not intended to limit the disclosure. Various modifications and alterations to this specification will become apparent to those skilled in the art. Any modifications, equivalent substitutions, improvements, or the like, which are within the spirit and principles of the present description, are intended to be included within the scope of the claims of the present description.

Claims (18)

1. A method of generating a countermeasure text, comprising:
acquiring original texts for generating countermeasure texts;
determining the feature vectors corresponding to the original texts respectively according to a first language model trained in advance;
clustering the original texts according to the feature vectors corresponding to the original texts respectively to obtain a specified number of text clusters;
selecting an original text from each text cluster as a representative text;
determining initial countermeasure texts corresponding to the representative texts;
for each representative text, determining a keyword of the representative text as an original keyword, and determining a keyword of an initial countermeasure text corresponding to the representative text as an initial countermeasure keyword;
determining the difference between the original keywords of the representative text and the initial countermeasure keywords corresponding to the representative text, and determining a target thinking chain prompt template from preset thinking chain prompt templates according to the difference;
generating a corresponding thinking chain prompt text of the representative text by adopting the target thinking chain prompt template according to the representative text and the initial countermeasure text of the representative text;
And inputting the thinking chain prompt text into a pre-trained second language model to obtain the target countermeasure text corresponding to the representative text.
2. The method according to claim 1, wherein determining a target mental chain prompting template from preset mental chain prompting templates according to the difference, specifically comprises:
transmitting the difference to a user;
and responding to the selection operation of the user, and determining a target thinking chain prompt template corresponding to the selected difference from preset thinking chain prompt templates by the user.
3. The method of claim 1, wherein the thought-chain prompting template includes at least business requirements and thought text, the thought text being text that characterizes how different an original keyword of the representative text is from an original keyword of an initial countermeasure text corresponding to the representative text.
4. The method of claim 1, wherein, for each text cluster, selecting an original text from the text cluster as a representative text, specifically comprises:
determining a clustering center of each text cluster and determining the distance from each original text contained in the text cluster to the clustering center;
And determining the original text closest to the clustering center as a representative text according to the determined distances.
5. The method of claim 1, wherein pre-training the second language model, in particular, comprises:
determining a pre-trained second language pre-training model;
randomly sampling from a preset text library, and taking the text obtained by sampling as a training text;
inputting the training text into the second language pre-training model to obtain an output result;
inputting the output result into a pre-trained evaluation model to obtain an evaluation result of the output result;
and determining the loss of the training text according to the evaluation result, training the second language pre-training model by taking the minimum loss as a training target, and taking the trained second language pre-training model as a second language model, wherein the loss and the evaluation result are inversely related.
6. The method of claim 5, wherein pre-training the assessment model, in particular, comprises:
sequencing the output results according to a preset evaluation standard to obtain a standard sequence;
inputting the output result into an evaluation model to be trained aiming at each output result to obtain an evaluation result corresponding to the output result, and sequencing the output results according to each evaluation result to obtain a prediction sequence;
And training the evaluation model to be trained by taking the minimum difference between the standard sequence and the predicted sequence as a training target.
7. The method of claim 1, wherein, for each text cluster, selecting an original text from the text cluster as a representative text, specifically comprises:
for each text cluster, randomly selecting an original text from the text clusters as a representative text.
8. The method of claim 1, wherein determining the initial challenge text corresponding to each representative text comprises:
aiming at each representative text, carrying out word segmentation processing on the representative text to obtain each word element of the representative text;
determining the corresponding hyponyms of each word element of the representative text according to a preset hyponym library;
for each word element, determining the priority of the word element according to a first language model trained in advance, and determining the priority of each hyponym corresponding to the word element;
determining target lemmas and target hyponyms according to the priorities of the lemmas and the priorities of the hyponyms corresponding to the lemmas;
and generating initial countermeasure text corresponding to the representative text according to the target word element and the target paraphrasing.
9. A device for generating a countermeasure text, comprising:
the acquisition module is used for acquiring each original text used for generating the countermeasure text;
the first determining module is used for determining the feature vector corresponding to each original text according to a pre-trained first language model;
the clustering module is used for clustering the original texts according to the feature vectors corresponding to the original texts to obtain a specified number of text clusters;
the selecting module is used for selecting an original text from each text cluster as a representative text;
the second determining module is used for determining initial countermeasure texts corresponding to the representative texts;
a third determining module, configured to determine, for each representative text, a keyword of the representative text as an original keyword, and determine, as an initial countermeasure keyword, a keyword of an initial countermeasure text corresponding to the representative text;
a fourth determining module, configured to determine a difference between an original keyword of the representative text and an initial countermeasure keyword corresponding to the representative text, and determine a target thinking chain prompt template from preset thinking chain prompt templates according to the difference;
The prompt text generation module is used for generating a corresponding thinking chain prompt text of the representative text by adopting the target thinking chain prompt template according to the representative text and the initial countermeasure text of the representative text;
and the countermeasure text generation module is used for inputting the thinking chain prompt text into a pre-trained second language model to obtain a target countermeasure text corresponding to the representative text.
10. The apparatus of claim 9, wherein the fourth determination module is specifically configured to send the difference to a user; and responding to the selection operation of the user, and determining a target thinking chain prompt template corresponding to the selected difference from preset thinking chain prompt templates by the user.
11. The apparatus of claim 9, wherein the thought-chain prompting template includes at least business requirements and thought text, the thought text being text that characterizes how different an original keyword of the representative text is from an original keyword of an initial countermeasure text corresponding to the representative text.
12. The apparatus of claim 9, wherein the selection module is specifically configured to, for each text cluster, determine a cluster center of the text cluster, and determine a distance from the cluster center of each original text contained in the text cluster; and determining the original text closest to the clustering center as a representative text according to the determined distances.
13. The apparatus of claim 9, wherein the apparatus further comprises:
the first training module is used for determining a pre-trained second language pre-training model; randomly sampling from a preset text library, and taking the text obtained by sampling as a training text; inputting the training text into the second language pre-training model to obtain an output result; inputting the output result into a pre-trained evaluation model to obtain an evaluation result of the output result; and determining the loss of the training text according to the evaluation result, training the second language pre-training model by taking the minimum loss as a training target, and taking the trained second language pre-training model as a second language model, wherein the loss and the evaluation result are inversely related.
14. The apparatus of claim 13, wherein the apparatus further comprises:
the second training module is used for sequencing the output results according to a preset evaluation standard to obtain a standard sequence; inputting the output result into an evaluation model to be trained aiming at each output result to obtain an evaluation result corresponding to the output result, and sequencing the output results according to each evaluation result to obtain a prediction sequence; and training the evaluation model to be trained by taking the minimum difference between the standard sequence and the predicted sequence as a training target.
15. The apparatus of claim 9, wherein the selection module is specifically configured to, for each text cluster, randomly select one original text from the text cluster as the representative text.
16. The apparatus of claim 9, wherein the second determining module is specifically configured to, for each representative text, perform word segmentation on the representative text to obtain each word element of the representative text; determining the corresponding hyponyms of each word element of the representative text according to a preset hyponym library; for each word element, determining the priority of the word element according to a first language model trained in advance, and determining the priority of each hyponym corresponding to the word element; determining target lemmas and target hyponyms according to the priorities of the lemmas and the priorities of the hyponyms corresponding to the lemmas; and generating initial countermeasure text corresponding to the representative text according to the target word element and the target paraphrasing.
17. A computer readable storage medium, characterized in that the storage medium stores a computer program which, when executed by a processor, implements the method of any of the preceding claims 1-8.
18. An electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, characterized in that the processor implements the method of any of the preceding claims 1-8 when executing the program.
CN202310514835.8A 2023-05-09 2023-05-09 Method and device for generating countermeasure text, storage medium and electronic equipment Active CN116227474B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310514835.8A CN116227474B (en) 2023-05-09 2023-05-09 Method and device for generating countermeasure text, storage medium and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310514835.8A CN116227474B (en) 2023-05-09 2023-05-09 Method and device for generating countermeasure text, storage medium and electronic equipment

Publications (2)

Publication Number Publication Date
CN116227474A true CN116227474A (en) 2023-06-06
CN116227474B CN116227474B (en) 2023-08-25

Family

ID=86575406

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310514835.8A Active CN116227474B (en) 2023-05-09 2023-05-09 Method and device for generating countermeasure text, storage medium and electronic equipment

Country Status (1)

Country Link
CN (1) CN116227474B (en)

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116663530A (en) * 2023-08-01 2023-08-29 北京高德云信科技有限公司 Data generation method, device, electronic equipment and storage medium
CN117272941A (en) * 2023-09-21 2023-12-22 北京百度网讯科技有限公司 Data processing method, apparatus, device, computer readable storage medium and product
CN117273868A (en) * 2023-11-20 2023-12-22 浙江口碑网络技术有限公司 Shop recommendation method and device, electronic equipment and storage medium
CN117369783A (en) * 2023-12-06 2024-01-09 之江实验室 Training method and device for security code generation model
CN117592483A (en) * 2023-11-21 2024-02-23 合肥工业大学 Implicit emotion analysis method and device based on thinking tree
CN117807961A (en) * 2024-03-01 2024-04-02 之江实验室 Training method and device of text generation model, medium and electronic equipment
CN117892818A (en) * 2024-03-18 2024-04-16 浙江大学 Large language model rational content generation method based on implicit thinking chain

Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111241287A (en) * 2020-01-16 2020-06-05 支付宝(杭州)信息技术有限公司 Training method and device for generating generation model of confrontation text
CN111753503A (en) * 2020-06-19 2020-10-09 兰州大学 Blind person oriented mathematical formula editing method and device
CN114022687A (en) * 2021-09-24 2022-02-08 之江实验室 Image description countermeasure generation method based on reinforcement learning
CN114528827A (en) * 2022-01-02 2022-05-24 西安电子科技大学 Text-oriented confrontation sample generation method, system, equipment and terminal
CN115176224A (en) * 2020-04-14 2022-10-11 Oppo广东移动通信有限公司 Text input method, mobile device, head-mounted display device, and storage medium
CN115661703A (en) * 2022-10-14 2023-01-31 辽宁工程技术大学 Method for extracting shop signboard information based on deep learning
WO2023032577A1 (en) * 2021-08-30 2023-03-09 株式会社デンソー Switching power supply device
CN115935991A (en) * 2022-11-04 2023-04-07 招联消费金融有限公司 Multitask model generation method and device, computer equipment and storage medium

Patent Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111241287A (en) * 2020-01-16 2020-06-05 支付宝(杭州)信息技术有限公司 Training method and device for generating generation model of confrontation text
CN115176224A (en) * 2020-04-14 2022-10-11 Oppo广东移动通信有限公司 Text input method, mobile device, head-mounted display device, and storage medium
CN111753503A (en) * 2020-06-19 2020-10-09 兰州大学 Blind person oriented mathematical formula editing method and device
WO2023032577A1 (en) * 2021-08-30 2023-03-09 株式会社デンソー Switching power supply device
CN114022687A (en) * 2021-09-24 2022-02-08 之江实验室 Image description countermeasure generation method based on reinforcement learning
CN114528827A (en) * 2022-01-02 2022-05-24 西安电子科技大学 Text-oriented confrontation sample generation method, system, equipment and terminal
CN115661703A (en) * 2022-10-14 2023-01-31 辽宁工程技术大学 Method for extracting shop signboard information based on deep learning
CN115935991A (en) * 2022-11-04 2023-04-07 招联消费金融有限公司 Multitask model generation method and device, computer equipment and storage medium

Non-Patent Citations (4)

* Cited by examiner, † Cited by third party
Title
JASON WEI 等: "Chain-of-Thought Prompting Elicits Reasoning in Large Language Models", ARXIV.ORG, pages 1 - 14 *
RUOCHEN ZHAO等: "Verify-and-Edit: A Knowledge-Enhanced Chain-of-Thought Framework", ARXIV.ORG, pages 1 - 16 *
孙才俊等: "基于指令序列嵌入的安卓恶意应用检测框架", 信息安全研究, vol. 8, no. 8, pages 777 - 785 *
金庚星: "媒介即模型: 人 ChatGPT 共生自主***的智能涌现", 学术界, pages 1 - 8 *

Cited By (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116663530A (en) * 2023-08-01 2023-08-29 北京高德云信科技有限公司 Data generation method, device, electronic equipment and storage medium
CN116663530B (en) * 2023-08-01 2023-10-20 北京高德云信科技有限公司 Data generation method, device, electronic equipment and storage medium
CN117272941A (en) * 2023-09-21 2023-12-22 北京百度网讯科技有限公司 Data processing method, apparatus, device, computer readable storage medium and product
CN117273868A (en) * 2023-11-20 2023-12-22 浙江口碑网络技术有限公司 Shop recommendation method and device, electronic equipment and storage medium
CN117592483A (en) * 2023-11-21 2024-02-23 合肥工业大学 Implicit emotion analysis method and device based on thinking tree
CN117592483B (en) * 2023-11-21 2024-05-28 合肥工业大学 Implicit emotion analysis method and device based on thinking tree
CN117369783A (en) * 2023-12-06 2024-01-09 之江实验室 Training method and device for security code generation model
CN117369783B (en) * 2023-12-06 2024-02-23 之江实验室 Training method and device for security code generation model
CN117807961A (en) * 2024-03-01 2024-04-02 之江实验室 Training method and device of text generation model, medium and electronic equipment
CN117807961B (en) * 2024-03-01 2024-05-31 之江实验室 Training method and device of text generation model, medium and electronic equipment
CN117892818A (en) * 2024-03-18 2024-04-16 浙江大学 Large language model rational content generation method based on implicit thinking chain
CN117892818B (en) * 2024-03-18 2024-05-28 浙江大学 Large language model rational content generation method based on implicit thinking chain

Also Published As

Publication number Publication date
CN116227474B (en) 2023-08-25

Similar Documents

Publication Publication Date Title
CN116227474B (en) Method and device for generating countermeasure text, storage medium and electronic equipment
CN109992771B (en) Text generation method and device
CN110032730B (en) Text data processing method, device and equipment
CN111401062B (en) Text risk identification method, device and equipment
CN112417093B (en) Model training method and device
CN117076650B (en) Intelligent dialogue method, device, medium and equipment based on large language model
CN114722834A (en) Semantic recognition model training method, equipment and medium based on contrast learning
CN112948449A (en) Information recommendation method and device
CN113887206B (en) Model training and keyword extraction method and device
CN117332282B (en) Knowledge graph-based event matching method and device
CN116127328B (en) Training method, training device, training medium and training equipment for dialogue state recognition model
CN116720124A (en) Educational text classification method and device, storage medium and electronic equipment
CN116824331A (en) Model training and image recognition method, device, equipment and storage medium
CN116662657A (en) Model training and information recommending method, device, storage medium and equipment
CN113887234B (en) Model training and recommending method and device
CN116501852B (en) Controllable dialogue model training method and device, storage medium and electronic equipment
CN117494068B (en) Network public opinion analysis method and device combining deep learning and causal inference
CN117807961B (en) Training method and device of text generation model, medium and electronic equipment
CN115017915B (en) Model training and task execution method and device
CN116108163B (en) Text matching method, device, equipment and storage medium
CN114611517B (en) Named entity recognition method, device, equipment and medium based on deep learning
CN116795972B (en) Model training method and device, storage medium and electronic equipment
CN117033469B (en) Database retrieval method, device and equipment based on table semantic annotation
CN118036668B (en) GPT model-oriented comprehensive evaluation method
CN117271611B (en) Information retrieval method, device and equipment based on large model

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
GR01 Patent grant