Method, device, equipment and medium for optimizing prompt words

By generating text content and extracting topic information, the similarity of prompt words is optimized, and the problem of low correlation between prompt words and generated content in the generative large language model is solved, and high-quality prompt word generation is achieved to reflect user intentions.

CN118733758BActive Publication Date: 2024-12-17SHENZHEN DIBO ENTERPRISE RISK MANAGEMENT TECH CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202411231811.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-09-04
Publication Date
2024-12-17
Estimated Expiration
2044-09-04

AI Technical Summary

Technical Problem

In the prior art, the process of processing prompt words in the generative large language model lacks in-depth semantic analysis and consistency verification, resulting in low correlation between prompt words and generated content, easy to deviate from the topic, and reduce application efficiency and user experience.

Method used

By obtaining the original prompt words, generating text content, extracting topic information and related information, generating candidate prompt words, and semantic optimization according to the similarity of prompt words, adjusting or fusing the original prompt words to improve consistency, the language model of the Transformer architecture is used for deal with.

Benefits of technology

Improve the correlation between prompt words and the content generated by the model, so that the generated target prompt words have high-quality expression and can accurately reflect the user's initial intention.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118733758B_ABST
    Figure CN118733758B_ABST
Patent Text Reader

Abstract

The present application relates to the technical field of natural language processing, and discloses a method, device, equipment and medium for optimizing prompt words. The method includes: obtaining original prompt words; generating text content based on the original prompt words to obtain generated text; extracting subject information and subject-related information from the generated text to obtain subject text and subject-related text; generating prompt words based on the subject text and subject-related text to obtain candidate prompt words; calculating the similarity between the original prompt words and the candidate prompt words to obtain prompt word similarity; using a consistency analysis method to semantically optimize the original prompt words based on the similarity between the candidate prompt words and the prompt words to obtain the target prompt words. The embodiment of the present application can improve the correlation between the prompt words and the generated content of the model.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of natural language processing, and in particular to a method, device, equipment and medium for optimizing prompt words. Background Art

[0002] Prompts are the core of interacting with generative large language models. They can be text that asks questions or provides instructions to the model. A good prompt word can ensure that the model gives the expected answer, while a bad prompt word may cause the model to deviate from the topic.

[0003] In the related art, the process of processing prompt words by generative large language models usually relies on manual intervention, lacks deep semantic analysis and consistency verification between prompt words and generated content, and easily generates prompt words that deviate from the topic or are irrelevant, reducing the actual efficiency of the application and user experience. Summary of the invention

[0004] The purpose of the present application is to provide a method, device, equipment and medium for optimizing prompt words, which can improve the relevance between prompt words and generated content of a model.

[0005] The present application provides a method for optimizing prompt words, including:

[0006] Get the original prompt word;

[0007] Generating text content based on the original prompt word to obtain generated text;

[0008] Extracting subject information and subject-related information from the generated text to obtain subject text and subject-related text;

[0009] Generate prompt words according to the subject text and the subject-related text to obtain candidate prompt words;

[0010] Calculating the similarity between the original prompt word and the candidate prompt word to obtain the prompt word similarity;

[0011] A consistency analysis method is adopted to semantically optimize the original prompt word according to the similarity between the candidate prompt word and the prompt word to obtain a target prompt word.

[0012] In some embodiments, the generating text content based on the original prompt word to obtain the generated text includes:

[0013] Performing vector embedding on the original prompt word to obtain a word vector sequence of the original prompt word;

[0014] Position encoding is performed on the word vector sequence of the original prompt word to obtain a position embedded word vector sequence;

[0015] Performing a linear transformation process on the position embedded word vector sequence, performing an attention weight operation on the word vector after the linear transformation process, and obtaining the text features of the original prompt word;

[0016] According to the text features of the original prompt word, continuous context prediction is performed on the original prompt word to obtain the generated text.

[0017] In some embodiments, extracting the subject information and subject-related information from the generated text to obtain the subject text and subject-related text includes:

[0018] Performing vector embedding on the generated text to obtain a word vector sequence of the generated text;

[0019] Performing linear transformation processing on the word vector sequence of the generated text, performing attention weight operation on the word vector after the linear transformation processing, and obtaining the text features of the generated text;

[0020] Counting the frequency distribution of characteristic words corresponding to the text characteristics of the generated text, and outputting corresponding characteristic words according to the frequency distribution of the characteristic words to obtain the subject text;

[0021] The similarity between the characteristic words in the subject text and the generated text is calculated, and the corresponding characteristic words are extracted from the generated text according to the similarity calculation result to obtain the subject-related text.

[0022] In some embodiments, generating prompt words according to the subject text and the subject-related text to obtain candidate prompt words includes:

[0023] Performing vector embedding on the subject text and the subject-related text to obtain a word vector sequence of the subject text and a word vector sequence of the subject-related text;

[0024] Performing linear transformation processing on the word vector sequence of the subject text and the word vector sequence of the subject-related text, performing attention weight operation on the word vectors after the linear transformation processing, and obtaining text features of the subject text and text features of the subject-related text;

[0025] Splicing the text features of the subject text and the text features of the subject-related text to obtain a splicing result of a target length;

[0026] According to the splicing processing result, prompt word prediction is performed to obtain the prompt word distribution corresponding to the topic text and the topic-related text, and the candidate prompt word is determined according to the prompt word distribution.

[0027] In some embodiments, the calculating the similarity between the original prompt word and the candidate prompt word to obtain the prompt word similarity includes:

[0028] The angular distance, cosine distance, Euclidean distance or Manhattan distance between the word vector sequence of the original prompt word and the word vector of the candidate prompt word is calculated as the prompt word similarity.

[0029] In some embodiments, the using of a consistency analysis method to semantically optimize the original prompt word according to the similarity between the candidate prompt word and the prompt word to obtain a target prompt word includes:

[0030] When the prompt word similarity is in a first similarity interval, adjusting punctuation marks in the original prompt word and / or replacing non-keywords in the original prompt word to obtain the target prompt word;

[0031] When the prompt word similarity is in a second similarity interval, based on the semantics of the original prompt word, the original prompt word and the candidate prompt word are merged to obtain the target prompt word;

[0032] When the similarity of the prompt word is in a third similarity interval, the original prompt word and the candidate prompt word are fused based on the semantics of the candidate prompt word to obtain the target prompt word.

[0033] In some embodiments, the generating of text content for the original prompt word, the extracting of topic information and topic-related information for the generated text, the generating of prompt words based on the topic text and the topic-related text, and the rewriting of the original prompt word based on the candidate prompt word and the evaluation result are all performed by calling a preset natural language processing model, wherein the natural language processing model is obtained by training a language model based on a Transformer architecture using sample original prompt words and sample target prompt words.

[0034] The embodiment of the present application also provides a device for optimizing prompt words, including:

[0035] The first module is used to obtain the original prompt words;

[0036] The second module is used to generate text content based on the original prompt word to obtain a generated text;

[0037] The third module is used to extract the subject information and subject-related information from the generated text to obtain the subject text and the subject-related text;

[0038] The fourth module is used to generate prompt words according to the subject text and the subject-related text to obtain candidate prompt words;

[0039] The fifth module is used to calculate the similarity between the original prompt word and the candidate prompt word to obtain the prompt word similarity;

[0040] The sixth module is used to adopt a consistency analysis method to perform semantic optimization on the original prompt word according to the similarity between the candidate prompt word and the prompt word to obtain a target prompt word.

[0041] An embodiment of the present application further provides an electronic device, the electronic device comprising a memory and a processor, the memory storing a computer program, and the processor implementing the above-mentioned method for optimizing prompt words when executing the computer program.

[0042] The embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method for optimizing prompt words is implemented.

[0043] The beneficial effects of the present application are as follows: by extracting the subject information and subject-related information from the generated text generated by the original prompt word to obtain the subject text and subject-related text, generating candidate prompt words based on the subject text and subject-related text, and using the consistency analysis method based on the similarity between the original prompt word and the candidate prompt word to semantically optimize the original prompt word using the candidate prompt word to generate the corresponding target prompt word. Since the subject text and subject-related text are extracted from the generated text generated by the original prompt word, and then the candidate prompt word is generated based on the subject text and subject-related text, and then the original prompt word is semantically optimized using the candidate prompt word, the correlation between the prompt word and the generated content of the model can be improved, so that the generated target prompt word has both high-quality expression and can reflect the user's initial intention. BRIEF DESCRIPTION OF THE DRAWINGS

[0044] Figure 1 It is a flow chart of a method for optimizing prompt words provided in an embodiment of the present application.

[0045] Figure 2 It is a flowchart of the specific method of step S102 provided in an embodiment of the present application.

[0046] Figure 3 It is a flowchart of the specific method of step S103 provided in an embodiment of the present application.

[0047] Figure 4 It is a flowchart of the specific method of step S104 provided in an embodiment of the present application.

[0048] Figure 5 It is a structural diagram of a device for optimizing prompt words provided in an embodiment of the present application.

[0049] Figure 6 It is a schematic diagram of the hardware structure of the electronic device provided in the embodiment of the present application. DETAILED DESCRIPTION

[0050] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0051] It should be noted that, although the functional modules are divided in the device schematic diagram and the logical order is shown in the flowchart, in some cases, the steps shown can be performed in a different order than the module division in the device or the order in the flowchart. The terms "first", "second" and the like in the specification, claims and drawings are used to distinguish similar objects, and are not used to describe a specific order or sequence.

[0052] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.

[0053] See also Figure 1 , Figure 1 is a flow chart of a method for optimizing prompt words provided in an embodiment of the present application. In some embodiments of the present application, Figure 1 The method includes but is not limited to steps S101 to S106. Figure 1 These six steps are introduced in detail.

[0054] Step S101, obtaining the original prompt word.

[0055] The original prompt word can be input into the electronic device by the user, for example, by voice, text, etc.

[0056] After the electronic device obtains the original prompt word, it can process the original prompt word to obtain a text representation corresponding to the original prompt word.

[0057] Step S102, generating text content based on the original prompt word to obtain a generated text.

[0058] In order to accurately optimize the original prompt words, it is necessary to generate text content based on the original prompt words to mine the association between the original prompt words and the generated text obtained by the text content generation.

[0059] In the embodiment of the present application, the generated text can be obtained by generating text content for the original prompt word. In the specific implementation, the text content generation based on the original prompt word is performed by calling the natural language processing model, and the original prompt word obtained in step S101 is input into the natural language processing model, so that the natural language processing model understands the text features of the original prompt word based on the multi-head attention mechanism and the feedforward neural network, and generates a word at each time step based on the original prompt word, and uses the previously generated word as the context to generate the next word, and gradually generates the text content until the required text length is reached or the end symbol is generated, and the generated text is obtained.

[0060] Among them, the natural language processing model is a language model based on the Transformer architecture.

[0061] See also Figure 2 , Figure 2 is a flowchart of a specific method of step S102 provided in an embodiment of the present application. In some embodiments of the present application, step S102 includes but is not limited to steps S201 to S204. Figure 2 These four steps are introduced in detail.

[0062] Step S201, embedding the original prompt word into a vector to obtain a word vector sequence of the original prompt word.

[0063] Step S202, position encoding is performed on the word vector sequence of the original prompt word to obtain a position embedded word vector sequence.

[0064] Step S203, linear transformation is performed on the position embedded word vector sequence, and attention weight operation is performed on the word vector after linear transformation to obtain the text features of the original prompt word.

[0065] Step S204: Perform continuous context prediction on the original prompt word according to the text features of the original prompt word to obtain a generated text.

[0066] In a specific implementation, the text content generation based on the original prompt word is performed by calling a natural language processing model. Optionally, the natural language processing model may include a vector embedding layer, a position encoding layer, an encoder layer, and a decoder layer.

[0067] Step S201 is executed by calling the vector embedding layer in the natural language processing model. In the specific implementation, the word vector sequence of the original prompt word includes the word vector of each characteristic word in the original prompt word. For the original prompt word, after the vector embedding layer performs vector embedding processing on the original prompt word, the original prompt word is mapped into a vector sequence composed of word vectors of multiple characteristic words, that is, the word vector sequence of the original prompt word.

[0068] Step S202 is executed by calling the position encoding layer in the natural language processing model. In the specific implementation, the position embedding word vector sequence includes the position vector of each feature word in the original prompt word, and the word vector sequence of the original prompt word is input into the position encoding layer, and the corresponding position information is embedded in the word vector of each feature word to indicate the position of the corresponding feature word in the original prompt word and the relative position between each feature word. After the position encoding layer performs position encoding on the word vector sequence of the original prompt word, the word vector sequence of the original prompt word is mapped into a vector sequence composed of word vectors of multiple feature words with embedded position information, that is, a position embedding word vector sequence.

[0069] Step S203 is executed by calling the encoder layer in the natural language processing model. After obtaining the position embedding word vector sequence, the word vector of each feature word after the embedded position information in the position embedding word vector sequence is linearly transformed, and each word vector after the linear transformation is subjected to attention weight operation to obtain the text features of the original prompt word. In the specific implementation, the position embedding word vector sequence is input into the encoder layer, and the encoder layer connects the multi-head mechanism and the feedforward layer through the residual network result. The multi-head mechanism performs multiple linear transformations on the input vector to obtain different linear values, and then the attention weight is calculated. The attention weight calculation formula is as follows:

[0070] ,

[0071] ,

[0072] Among them, Q, K and V are the input word vector matrices, , and is a trainable weight matrix, Attention is the attention weight operation, Concat is the concatenation process, is the i-th hyperparameter head, i is an integer greater than or equal to 1 and less than or equal to h. Through the above formula, the word vector of each feature word after embedding position information in the position embedding word vector sequence is linearly transformed, and the principle of attention weight operation is to perform Attention operation on each word vector after linear transformation: Q, K, V are mapped through the corresponding weight matrix, and the calculation results are concatenated after repeating h times to obtain the text features of the original prompt word. The text features of the original prompt word reflect the semantic relationship and grammatical structure of the text to be classified.

[0073] Step S204 is executed by calling the decoder layer in the natural language processing model. After obtaining the text features of the original prompt word, the context information of the original prompt word is understood layer by layer through the text features of the original prompt word, so as to generate text based on the original prompt word output. In the specific implementation, the text features of the original prompt word are input into the decoder layer, and the decoder layer connects the multi-head mechanism and the feedforward layer through the residual network result. The multi-head mechanism performs multiple linear transformations on the input vector to obtain different linear values, and then operates the attention weights to capture the representation of different features obtained by different linear transformations, thereby capturing the global information in the original prompt word, combining the global information in the original prompt word, and generating a vocabulary at each time step based on the original prompt word, and using the previously generated vocabulary as the context to generate the next vocabulary, and gradually generating text content until the required text length is reached or the end symbol is generated to obtain the generated text.

[0074] Step S103, extracting the subject information and subject-related information from the generated text to obtain the subject text and subject-related text.

[0075] It can be understood that the subject information refers to an overview of the main content of the generated text, and the subject-related information is the neighborhood key information of the subject information, which is an overview of the main content of the subject information. For example, based on the original prompt words, a generated text about a legal case is generated, and its subject information may include the case type, and the corresponding subject text may be "criminal case", and its subject-related information may include people, time, place and cause, etc., and the corresponding subject-related text is related to the subject text.

[0076] In the embodiment of the present application, the subject text and the subject-related text can be obtained by extracting the subject information and the subject-related information from the generated text. In a specific implementation, the subject information and the subject-related information extraction from the generated text is performed by calling a natural language processing model, the generated text generated in step S102 is input into the natural language processing model, and the text subject extraction process is performed through the text features of the generated text to obtain the subject text, and then the subject-related information extraction process is performed through the text features of the subject text to obtain the subject-related text.

[0077] See also Figure 3 , Figure 3 is a flowchart of a specific method of step S103 provided in an embodiment of the present application. In some embodiments of the present application, step S103 includes but is not limited to steps S301 to S304. Figure 3 These four steps are introduced in detail.

[0078] Step S301, embedding the generated text into a vector to obtain a word vector sequence of the generated text.

[0079] Step S302, linear transformation is performed on the word vector sequence of the generated text, and attention weight operation is performed on the word vector after the linear transformation to obtain the text features of the generated text.

[0080] Step S303, statistically generate the frequency distribution of the characteristic words corresponding to the text features of the text, output the corresponding characteristic words according to the frequency distribution of the characteristic words, and obtain the subject text.

[0081] Step S304, calculating the similarity between the characteristic words in the subject text and the generated text, extracting the corresponding characteristic words from the generated text according to the similarity calculation result, and obtaining the subject-related text.

[0082] In a specific implementation, extracting topic information and topic-related information from the generated text is performed by calling a natural language processing model. Optionally, the natural language processing model may include a vector embedding layer, an encoder layer, a topic extraction layer, and a related information extraction layer.

[0083] Step S301 is executed by calling the vector embedding layer in the natural language processing model. In the specific implementation, the word vector sequence of the generated text includes the word vector of each characteristic word in the generated text. For the generated text, after the vector embedding layer performs vector embedding processing on the generated text, the generated text is mapped into a vector sequence composed of word vectors of multiple characteristic words, that is, the word vector sequence of the generated text.

[0084] Step S302 is executed by calling the encoder layer in the natural language processing model. In the specific implementation, the word vector sequence of the generated text is input into the encoder layer, and the encoder layer connects the multi-head mechanism and the feedforward layer through the residual network result, and performs linear transformation processing on each word vector of the generated text in the word vector sequence of the generated text, and performs attention weight operation on each word vector after the linear transformation processing. The multi-head mechanism performs multiple linear transformation processing on the input vector to obtain different linear values, and then operates the attention weight to obtain the text features of the generated text.

[0085] Step S303 is executed by calling the topic extraction layer in the natural language processing model. In the specific implementation, the text features of the generated text are input into the topic extraction layer, the feature words included in the text features of the generated text are obtained, and each feature word is sampled. When Gibbs sampling is performed, the frequency distribution of the feature words corresponding to the text features of the generated text is counted, and a preset number of feature words with the highest distribution frequency are obtained. The obtained feature words are output to obtain the topic text.

[0086] Step S304 is executed by calling the associated information extraction layer in the natural language processing model. In the specific implementation, the subject text and the generated text are input into the subject extraction layer, and the angle distance, cosine distance, Euclidean distance or Manhattan distance between the word vectors of the characteristic words of the subject text and the generated text are calculated to obtain the similarity calculation result, and according to the similarity calculation result, several characteristic words most similar to the subject text are extracted from the generated text to obtain the subject associated text.

[0087] Step S104, generating prompt words according to the subject text and the subject-related text to obtain candidate prompt words.

[0088] After determining the subject text and subject-related text corresponding to the generated text, prompt words may be generated according to the subject text and subject-related text in step S104 to obtain candidate prompt words.

[0089] In the embodiment of the present application, the candidate prompt words can be generated by prompt words according to the subject text and the subject-related text. In a specific implementation, the prompt words are generated according to the subject text and the subject-related text by calling a natural language processing model, the subject text and the subject-related text generated in step S103 are input into the natural language processing model, the text features of the subject text and the subject-related text are extracted, the text features of the subject text and the text features of the subject-related text are spliced, and the prompt words are predicted according to the splicing processing result, thereby generating candidate prompt words.

[0090] See also Figure 4 , Figure 4 is a flowchart of a specific method of step S104 provided in an embodiment of the present application. In some embodiments of the present application, step S104 includes but is not limited to step S401 to step S404. Figure 4 These four steps are introduced in detail.

[0091] Step S401, embedding the subject text and the subject-related text into vectors to obtain a word vector sequence of the subject text and a word vector sequence of the subject-related text.

[0092] Step S402, linear transformation is performed on the word vector sequence of the topic text and the word vector sequence of the topic-related text, and attention weight operation is performed on the word vectors after the linear transformation to obtain the text features of the topic text and the text features of the topic-related text.

[0093] Step S403, concatenating the text features of the subject text and the text features of the subject-related text to obtain a concatenated result of a target length.

[0094] Step S404: predict prompt words based on the splicing processing result, obtain prompt word distribution corresponding to the topic text and the topic-related text, and determine candidate prompt words based on the prompt word distribution.

[0095] In a specific implementation, the prompt word generation based on the topic text and the topic-related text is performed by calling a natural language processing model. Optionally, the natural language processing model may include a vector embedding layer, an encoder layer, a fully connected layer, and a prompt word extraction layer.

[0096] Step S401 is executed by calling the vector embedding layer in the natural language processing model. In the specific implementation, the word vector sequence of the subject text contains the word vector of each characteristic word in the subject text, and the word vector sequence of the subject-related text contains the word vector of each characteristic word in the subject-related text. After the vector embedding layer performs vector embedding processing on the subject text and the subject-related text, the subject text and the subject-related text are respectively mapped into a vector sequence composed of the word vectors of multiple characteristic words, that is, the word vector sequence of the subject text and the word vector sequence of the subject-related text are generated.

[0097] Step S402 is executed by calling the encoder layer in the natural language processing model. In the specific implementation, the word vector sequence of the topic text and the word vector sequence of the topic-related text are input into the encoder layer, and the encoder layer connects the multi-head mechanism and the feedforward layer through the residual network result, and each word vector of the word vector sequence of the topic text and the word vector sequence of the topic-related text is linearly transformed, and each word vector after the linear transformation is subjected to attention weight operation. The multi-head mechanism performs multiple linear transformations on the input vectors to obtain different linear values, and then the attention weights are operated to obtain the text features of the topic text and the text features of the topic-related text.

[0098] Step S403 is executed by calling the fully connected layer in the natural language processing model. In a specific implementation, the fully connected layer is called to concatenate the text features of the subject text and the text features of the subject-related text to obtain a concatenation result of a target length.

[0099] Step S404 is executed by calling the prompt word extraction layer in the natural language processing model. In the specific implementation, the splicing processing result is input into the prompt word extraction layer, and a classification function is used to perform classification prediction based on the splicing processing result to obtain the prompt word distribution corresponding to the splicing processing result, and the candidate prompt word corresponding to the text to be classified is determined according to the prompt word distribution.

[0100] Step S105, calculating the similarity between the original prompt word and the candidate prompt word to obtain the prompt word similarity.

[0101] After the candidate prompt words are obtained, the prompt word similarity is obtained by calculating the similarity between the original prompt word and the candidate prompt word, so as to determine the difference between the original prompt word and the candidate prompt word.

[0102] In some embodiments, the similarity between the original prompt word and the candidate prompt word can be obtained by calculating the angular distance, cosine distance, Euclidean distance or Manhattan distance between the word vector sequence of the original prompt word and the word vector of the candidate prompt word, and the calculated result is used as the prompt word similarity.

[0103] In the embodiment of the present application, the cosine distance between the word vector sequence of the original prompt word and the word vector of the candidate prompt word is calculated as the prompt word similarity. In the specific implementation, the calculation formula of the cosine distance is:

[0104] ,

[0105] in, is the cosine distance between the word vector sequence of the original prompt word and the word vector of the candidate prompt word, is the word vector sequence of the original prompt word, is the word vector of the candidate prompt word, is the modulus of the word vector sequence of the original prompt word, is the modulus of the word vector of the candidate hint word.

[0106] Step S106: using a consistency analysis method, semantically optimizing the original prompt word according to the similarity between the candidate prompt word and the prompt word, to obtain the target prompt word.

[0107] In the embodiment of the present application, the target prompt word can be obtained by semantically optimizing the original prompt word according to the similarity between the candidate prompt word and the prompt word. In the specific implementation, the consistency analysis method is adopted, and the semantic optimization of the original prompt word according to the similarity between the candidate prompt word and the prompt word is performed by calling the natural language processing model, the original prompt word, the candidate prompt word and the prompt word similarity are input into the natural language processing model, and the original prompt word, the candidate prompt word and the prompt word similarity are used as the context, and through semantic matching and context understanding, the deviation degree between the candidate prompt word and the prompt word is characterized according to the prompt word similarity, and the original prompt word is semantically optimized using the candidate prompt word, so as to obtain the target prompt word, so that the target prompt word finally generated has both high-quality expression and can reflect the user's initial intention.

[0108] In a specific embodiment, step S106 specifically includes:

[0109] When the prompt word similarity is in the first similarity interval, adjusting punctuation marks in the original prompt word and / or replacing non-keywords in the original prompt word to obtain a target prompt word;

[0110] When the prompt word similarity is in the second similarity interval, based on the semantics of the original prompt word, the original prompt word and the candidate prompt word are fused to obtain the target prompt word;

[0111] When the prompt word similarity is in the third similarity interval, the original prompt word and the candidate prompt word are fused based on the semantics of the candidate prompt word to obtain the target prompt word.

[0112] The lower boundary of the first similarity interval is greater than or equal to the upper boundary of the second similarity interval, and the lower boundary of the second similarity interval is greater than or equal to the upper boundary of the third similarity interval. It can be understood that when the prompt word similarity is in the first similarity interval, the descriptions representing the original prompt word and the candidate prompt word are basically consistent, when the prompt word similarity is in the second similarity interval, there are a small amount of inconsistency between the descriptions representing the original prompt word and the candidate prompt word, and when the prompt word similarity is in the third similarity interval, there are a large amount of inconsistency between the descriptions representing the original prompt word and the candidate prompt word.

[0113] In a specific implementation, a consistency analysis method is used to perform semantic optimization on the original prompt word according to the similarity between the candidate prompt word and the prompt word, which is performed by calling the prompt word optimization layer of the natural language processing model.

[0114] In a specific implementation, the prompt word similarity is input into the prompt word optimization layer. When the prompt word similarity is in a first similarity interval, the prompt word optimization layer is called. According to the punctuation marks and non-keywords of the candidate prompt words, the punctuation marks in the original prompt words are adjusted and / or the non-keywords in the original prompt words are replaced to obtain the target prompt word. When the prompt word similarity is in a second similarity interval, the prompt word optimization layer is called. Based on the semantics of the original prompt word, the original prompt word and the candidate prompt word are merged, the semantics of the original prompt word is retained, and according to the punctuation marks and keywords of the candidate prompt word, the punctuation marks in the original prompt word and / or the keywords in the original prompt word are replaced to obtain the target prompt word. When the prompt word similarity is in a third similarity interval, the prompt word optimization layer is called. Based on the semantics of the candidate prompt word, the original prompt word and the candidate prompt word are merged, and according to the punctuation marks and keywords of the candidate prompt word, the punctuation marks in the original prompt word and / or the keywords in the original prompt word are replaced to obtain the target prompt word.

[0115] See also Figure 5 The embodiment of the present application also provides a device for optimizing prompt words, which can implement the above-mentioned method for optimizing prompt words, and the device includes:

[0116] The first module 501 is used to obtain the original prompt word;

[0117] The second module 502 is used to generate text content based on the original prompt word to obtain a generated text;

[0118] The third module 503 is used to extract the subject information and subject-related information from the generated text to obtain the subject text and the subject-related text;

[0119] The fourth module 504 is used to generate prompt words according to the subject text and the subject-related text to obtain candidate prompt words;

[0120] The fifth module 505 is used to calculate the similarity between the original prompt word and the candidate prompt word to obtain the prompt word similarity;

[0121] The sixth module 506 is used to use a consistency analysis method to perform semantic optimization on the original prompt word according to the similarity between the candidate prompt word and the prompt word to obtain a target prompt word.

[0122] The specific implementation of the device for optimizing prompt words is substantially the same as the specific implementation of the method for optimizing prompt words, and will not be described in detail herein.

[0123] Figure 6 It is a block diagram of an electronic device according to an exemplary embodiment.

[0124] Refer to the following Figure 6 The electronic device 600 according to this embodiment of the present disclosure is described. Figure 6 The electronic device 600 shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.

[0125] like Figure 6 As shown, the electronic device 600 is in the form of a general computing device. The components of the electronic device 600 may include, but are not limited to: at least one processing unit 610, at least one storage unit 620, a bus 630 connecting different system components (including the storage unit 620 and the processing unit 610), a display unit 640, etc.

[0126] The storage unit stores program codes, which can be executed by the processing unit 610, so that the processing unit 610 executes the steps according to various exemplary embodiments of the present disclosure described in the above method part of optimizing prompt words of this specification.

[0127] The storage unit 620 may include a readable medium in the form of a volatile storage unit, such as a random access memory unit (RAM) 6201 and / or a cache memory unit 6202 , and may further include a read-only memory unit (ROM) 6203 .

[0128] The storage unit 620 may also include a program / utility 6204 having a set (at least one) of program modules 6205, such program modules 6205 including but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment.

[0129] Bus 630 may represent one or more of several types of bus structures, including a memory unit bus or memory unit controller, a peripheral bus, an accelerated graphics port, a processing unit, or a local bus using any of a variety of bus architectures.

[0130] The electronic device 600 may also communicate with one or more external devices 600' (e.g., keyboards, pointing devices, Bluetooth devices, etc.), may also communicate with one or more devices that enable a user to interact with the electronic device 600, and / or communicate with any device that enables the electronic device 600 to communicate with one or more other computing devices (e.g., routers, modems, etc.). Such communication may be performed via an input / output (I / O) interface 650. Furthermore, the electronic device 600 may also communicate with one or more networks (e.g., a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) via a network adapter 660. The network adapter 660 may communicate with other modules of the electronic device 600 via a bus 630. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the electronic device 600, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.

[0131] The embodiment of the present application further provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the method for optimizing prompt words is implemented.

[0132] The method, device, equipment and storage medium for optimizing prompt words provided in the embodiments of the present application extract the subject information and subject-related information from the generated text generated by the original prompt word to obtain the subject text and subject-related text, generate candidate prompt words based on the subject text and subject-related text, and use the consistency analysis method based on the similarity between the original prompt word and the candidate prompt word to semantically optimize the original prompt word using the candidate prompt word to generate the corresponding target prompt word. Since the subject text and subject-related text are extracted from the generated text generated by the original prompt word, and the candidate prompt word is generated based on the subject text and subject-related text, and then the original prompt word is semantically optimized using the candidate prompt word, the correlation between the prompt word and the generated content of the model can be improved, so that the generated target prompt word has both high-quality expression and can reflect the user's initial intention.

[0133] Through the description of the above implementation, it is easy for those skilled in the art to understand that the example implementation described here can be implemented by software, or by software combined with necessary hardware. Therefore, the technical solution according to the implementation of the present disclosure can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, including several instructions to enable a computing device (which can be a personal computer, a server, or a network device, etc.) to execute the above method according to the implementation of the present disclosure.

[0134] The program product may use any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of readable storage media (a non-exhaustive list) include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.

[0135] Computer readable storage media may include data signals propagated in baseband or as part of a carrier wave, wherein readable program codes are carried. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. The readable storage medium may also be any readable medium other than a readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, device, or device. The program codes contained on the readable storage medium may be transmitted using any suitable medium, including but not limited to wireless, wired, optical cable, RF, etc., or any suitable combination thereof.

[0136] Program code for performing the operations of the present disclosure may be written in any combination of one or more programming languages, including object-oriented programming languages ​​such as Java, C++, etc., and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server. In cases involving a remote computing device, the remote computing device may be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computing device (e.g., through the Internet using an Internet service provider).

[0137] Those skilled in the art will appreciate that the above modules can be distributed in the device according to the description of the embodiment, or can be changed accordingly and only used in one or more devices different from the embodiment. The modules of the above embodiments can be combined into one module, or further divided into multiple sub-modules.

[0138] The exemplary embodiments of the present disclosure are specifically shown and described above. It should be understood that the present disclosure is not limited to the detailed structures, configurations or implementations described herein; on the contrary, the present disclosure is intended to cover various modifications and equivalent configurations included in the spirit and scope of the appended claims.

Claims

1. A method for optimizing prompt words, characterized in that: include: Get the original prompt word; Generating text content based on the original prompt word to obtain generated text; Extracting subject information and subject-related information from the generated text to obtain subject text and subject-related text; Generate prompt words according to the subject text and the subject-related text to obtain candidate prompt words; Calculating the similarity between the original prompt word and the candidate prompt word to obtain the prompt word similarity; Using a consistency analysis method, semantically optimizing the original prompt word according to the similarity between the candidate prompt word and the prompt word, to obtain a target prompt word; The generating of prompt words according to the subject text and the subject-related text to obtain candidate prompt words includes: Performing vector embedding on the subject text and the subject-related text to obtain a word vector sequence of the subject text and a word vector sequence of the subject-related text; Performing linear transformation processing on the word vector sequence of the subject text and the word vector sequence of the subject-related text, performing attention weight operation on the word vectors after the linear transformation processing, and obtaining text features of the subject text and text features of the subject-related text; Splicing the text features of the subject text and the text features of the subject-related text to obtain a splicing result of a target length; According to the splicing processing result, predict the prompt word to obtain the prompt word distribution corresponding to the subject text and the subject-related text, and determine the candidate prompt word according to the prompt word distribution; The method of using consistency analysis to semantically optimize the original prompt word according to the similarity between the candidate prompt word and the prompt word to obtain the target prompt word includes: When the prompt word similarity is in a first similarity interval, adjusting punctuation marks in the original prompt word and / or replacing non-keywords in the original prompt word to obtain the target prompt word; When the prompt word similarity is in a second similarity interval, based on the semantics of the original prompt word, the original prompt word and the candidate prompt word are merged to obtain the target prompt word; When the similarity of the prompt word is in a third similarity interval, the original prompt word and the candidate prompt word are fused based on the semantics of the candidate prompt word to obtain the target prompt word.

2. The method for optimizing prompt words according to claim 1, characterized in that: The step of generating text content based on the original prompt word to obtain a generated text includes: Performing vector embedding on the original prompt word to obtain a word vector sequence of the original prompt word; Position encoding is performed on the word vector sequence of the original prompt word to obtain a position embedded word vector sequence; Performing a linear transformation process on the position embedded word vector sequence, performing an attention weight operation on the word vector after the linear transformation process, and obtaining the text features of the original prompt word; According to the text features of the original prompt word, continuous context prediction is performed on the original prompt word to obtain the generated text.

3. The method for optimizing prompt words according to claim 1, characterized in that: The extracting of subject information and subject-related information from the generated text to obtain subject text and subject-related text includes: Performing vector embedding on the generated text to obtain a word vector sequence of the generated text; Performing linear transformation processing on the word vector sequence of the generated text, performing attention weight operation on the word vector after the linear transformation processing, and obtaining the text features of the generated text; Counting the frequency distribution of characteristic words corresponding to the text characteristics of the generated text, and outputting corresponding characteristic words according to the frequency distribution of the characteristic words to obtain the subject text; The similarity between the characteristic words in the subject text and the generated text is calculated, and the corresponding characteristic words are extracted from the generated text according to the similarity calculation result to obtain the subject-related text.

4. The method for optimizing prompt words according to claim 1, characterized in that: The calculating the similarity between the original prompt word and the candidate prompt word to obtain the prompt word similarity includes: The angular distance, cosine distance, Euclidean distance or Manhattan distance between the word vector sequence of the original prompt word and the word vector of the candidate prompt word is calculated as the prompt word similarity.

5. The method for optimizing prompt words according to any one of claims 1 to 4, characterized in that: The text content generation of the original prompt word, the extraction of topic information and topic-related information of the generated text, the prompt word generation based on the topic text and the topic-related text, and the rewriting of the original prompt word based on the candidate prompt word and the evaluation result are all executed by calling a preset natural language processing model, and the natural language processing model is obtained by training a language model based on the Transformer architecture using sample original prompt words and sample target prompt words.

6. A device for optimizing prompt words, characterized in that: include: The first module is used to obtain the original prompt words; The second module is used to generate text content based on the original prompt word to obtain a generated text; The third module is used to extract the subject information and subject-related information from the generated text to obtain the subject text and the subject-related text; The fourth module is used to generate prompt words according to the subject text and the subject-related text to obtain candidate prompt words; The fifth module is used to calculate the similarity between the original prompt word and the candidate prompt word to obtain the prompt word similarity; The sixth module is used to use a consistency analysis method to perform semantic optimization on the original prompt word according to the similarity between the candidate prompt word and the prompt word to obtain a target prompt word; The generating of prompt words according to the subject text and the subject-related text to obtain candidate prompt words includes: Performing vector embedding on the subject text and the subject-related text to obtain a word vector sequence of the subject text and a word vector sequence of the subject-related text; Performing linear transformation processing on the word vector sequence of the subject text and the word vector sequence of the subject-related text, performing attention weight operation on the word vectors after the linear transformation processing, and obtaining text features of the subject text and text features of the subject-related text; Splicing the text features of the subject text and the text features of the subject-related text to obtain a splicing result of a target length; According to the splicing processing result, predict the prompt word to obtain the prompt word distribution corresponding to the subject text and the subject-related text, and determine the candidate prompt word according to the prompt word distribution; The method of using consistency analysis to semantically optimize the original prompt word according to the similarity between the candidate prompt word and the prompt word to obtain the target prompt word includes: When the prompt word similarity is in a first similarity interval, adjusting punctuation marks in the original prompt word and / or replacing non-keywords in the original prompt word to obtain the target prompt word; When the prompt word similarity is in a second similarity interval, based on the semantics of the original prompt word, the original prompt word and the candidate prompt word are merged to obtain the target prompt word; When the similarity of the prompt word is in a third similarity interval, the original prompt word and the candidate prompt word are fused based on the semantics of the candidate prompt word to obtain the target prompt word.

7. An electronic device, characterized in that: The electronic device comprises a memory and a processor, the memory stores a computer program, and the processor implements the method for optimizing prompt words according to any one of claims 1 to 5 when executing the computer program.

8. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the method for optimizing prompt words according to any one of claims 1 to 5 is implemented.

Citation Information

Patent Citations

  • Search prompt word generation method and device, electronic equipment and storage medium

    CN117093600A

  • Text generation method and device, electronic equipment and readable medium

    CN117271756A

  • Online question and answer cue word optimization generation method based on large language model

    CN118093836A

  • Text subject term generation method and related equipment

    CN118297056A

  • Address information feature extraction method based on deep neural network model

    US20210012199A1