Prompt language text generation method and device, equipment and medium
By covering and completing the initial prompt text, optimized prompt text that meets the semantic similarity requirements are generated, the problem of being affected by the prompt language characteristics when generating original text content in the prior art is solved, and text quality and user are improved Satisfaction.
Patent Information
- Application Number
- CN202310952612.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-07-31
- Publication Date
- 2025-02-14
AI Technical Summary
Existing language question and answer models are susceptible to the language characteristics of the prompts when generating original text content, resulting in poor use.
By obtaining the initial prompt text, determine the target occlusion rate and target number, and perform text occlusion to generate the prompt text to be completed. Then, the preset target prompt generation model is used to complete the complete prompt text and generate imitation prompt text. Finally, the optimized prompt text that meets the preset semantic similarity requirements with the initial prompt text is determined from the imitation prompt text.
It effectively reduces the impact of the language characteristics of the prompt words on the generated text, and improves the quality and user satisfaction of the original text content.
Smart Images

Figure CN119441500A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of natural language processing, and in particular to a method, device, equipment and medium for generating prompt text. Background Art
[0002] The language question-answering model can generate original text content that answers the prompt requirements based on the given prompt. These original text contents will be similar to the original training samples, but they are not simply copies of the samples.
[0003] When existing language question-answering models generate original text content, the quality of the original text content is closely related to the given prompts.
[0004] However, existing methods are easily affected by the language characteristics of prompts when using language question-answering models to generate original text content, resulting in poor performance. Summary of the invention
[0005] The present application provides a prompt text generation method, device, equipment and medium to solve the problem that the existing method is easily affected by the language characteristics of the prompt when using a language question-answering model to generate original text content, resulting in poor use effect.
[0006] In a first aspect, the present application provides a method for generating a prompt text, the method comprising:
[0007] Get the initial prompt text;
[0008] Based on the number of words in the initial prompt text, determine the target coverage rate and target number. The target coverage rate is the ratio of the number of words covered in the initial prompt text to the total number of words. The target number is the number of prompt texts to be completed after the covering process.
[0009] Based on the target masking rate, the initial prompt text is masked to obtain the prompt text to be completed, wherein the number of prompt texts to be completed matches the number of target quantity representations;
[0010] Based on the prompt text to be completed and the preset target prompt generation model, a first preset number of imitation prompt texts is obtained, where the first preset number is greater than or equal to the number of items represented by the target number;
[0011] An optimized prompt text that meets a preset semantic similarity requirement with the initial prompt text is determined from the imitation prompt text.
[0012] In the embodiment of the present application, the target coverage rate and the target quantity are determined based on the number of words in the initial prompt text, including:
[0013] Determining a preset text word number range based on a first preset text word value and a second preset text word value, wherein the second preset text word value is greater than the first preset text word value;
[0014] Based on the text word range corresponding to the initial prompt text, the target coverage rate and target quantity are determined.
[0015] In the embodiment of the present application, based on the text word count range corresponding to the initial prompt text, the target coverage rate and the target number are determined, including:
[0016] If the text word count range is the first text word count range, determining the target coverage ratio to be the first target coverage ratio corresponding to the first text word count range, the target number to be the first target number corresponding to the first text word count range, and the first text word count range to be a range smaller than the first preset text word value;
[0017] If the text word count range is the second text word count range, determining the target coverage rate to be the second target coverage rate corresponding to the second text word count range, the target number to be the second target number corresponding to the second text word count range, and the second text word count range to be a range greater than the first preset text word value and less than the second preset text word value;
[0018] If the text word count range is the third text word count range, the target coverage rate is determined to be the third target coverage rate corresponding to the third text word count range, and the target quantity is the third target quantity corresponding to the third text word count range, wherein the third text word count range is a range greater than the second preset text word value range, the third target coverage rate is greater than the second target coverage rate, which is greater than the first target coverage rate, and the third target quantity is greater than the second target quantity, which is greater than the first target quantity.
[0019] In the embodiment of the present application, before obtaining a first preset number of imitation prompt texts based on the prompt text to be completed and the target prompt generation model, the method further includes:
[0020] Obtaining a target information sample, where the target information sample is an information sample that meets the input requirements of the language question answering model;
[0021] Based on the language features of the target information sample, the prompt generation model is self-supervised trained to obtain a target prompt generation model, wherein the prompt generation model is used to receive input text, and after processing the input text, provide a prompt text that meets the input requirements to the language question answering model.
[0022] In the embodiment of the present application, based on the prompt text to be completed and the target prompt generation model, a first preset number of imitation prompt texts are obtained, including:
[0023] Based on the prompt text to be completed and the target prompt generation model, an initial imitation prompt text is obtained;
[0024] Determine the output probability of the target prompt generation model outputting the initial imitation prompt text;
[0025] Based on the output probability, the initial imitation prompt texts are sorted to obtain an initial imitation prompt text sequence set;
[0026] comparing the target quantity with a first preset quantity;
[0027] If the target number is less than the first preset number, then based on the preset extraction order, the imitation prompt text is determined from the initial imitation prompt text sequence set, and the number of the imitation prompt text meets the requirement of the second preset number, and the second preset number is obtained according to the first preset number and the target number;
[0028] If the target number is equal to the first preset number, the imitation prompt text with the highest output probability is determined from the initial imitation prompt text sequence set.
[0029] In the embodiment of the present application, determining the output probability of the target prompt generation model outputting the initial imitation prompt text includes:
[0030] Based on the target prompt generation model, determine the similarity probability between the initial imitation prompt text and the target information sample;
[0031] Based on the similarity probability, the output probability of the initial imitation prompt text is determined.
[0032] In the embodiment of the present application, after determining the optimized prompt text that meets the preset semantic similarity requirement with the initial prompt text from the imitation prompt text, the method further includes:
[0033] The optimized prompt text is sent to the language question answering model, so that the language question answering model generates answer text information based on the optimized prompt text.
[0034] In a second aspect, the present application provides a prompt text generation device, the device comprising:
[0035] A text acquisition module is used to acquire the initial prompt text;
[0036] A masking rate and quantity determination module is used to determine a target masking rate and a target quantity based on the number of words in the initial prompt text. The target masking rate is the ratio of the number of words covered in the initial prompt text to the total number of words. The target quantity is the number of prompt texts to be completed after the masking process is performed.
[0037] A text masking module, used for masking the initial prompt text based on the target masking rate to obtain the prompt text to be completed, wherein the number of prompt texts to be completed matches the number of items represented by the target quantity;
[0038] A text obtaining module, used to obtain a first preset number of imitation prompt texts based on the prompt text to be completed and a preset target prompt generation model, where the first preset number is greater than or equal to the number of items represented by the target number;
[0039] The text determination module is used to determine the optimized prompt text that meets the preset semantic similarity requirement with the initial prompt text from the imitation prompt text.
[0040] In a third aspect, the present application provides a device, comprising: a processor, and a memory communicatively connected to the processor;
[0041] Memory stores computer-executable instructions;
[0042] The processor executes the computer-executable instructions stored in the memory to implement the method of the present application.
[0043] In a fourth aspect, the present application provides a computer-readable storage medium, in which computer-executable instructions are stored. When the computer-executable instructions are executed by a processor, they are used to implement the method of the present application.
[0044] The prompt text generation method, device, equipment and medium provided in the present application obtain an initial prompt text; determine a target coverage rate and a target number based on the number of words in the initial prompt text, wherein the target coverage rate is the ratio of the number of words covered in the initial prompt text to the total number of words, and the target number is the number of prompt texts to be completed after the covering process; based on the target coverage rate, the initial prompt text is covered to obtain the prompt text to be completed, wherein the number of prompt texts to be completed matches the number represented by the target number; based on the prompt text to be completed and a preset target prompt generation model, a first preset number of imitation prompt texts is obtained, wherein the first preset number is greater than or equal to the number represented by the target number; and an optimized prompt text that meets a preset semantic similarity requirement with the initial prompt text is determined from the imitation prompt text.
[0045] In this way, the target coverage rate corresponding to the initial prompt text and the target number of prompt texts to be generated can be determined by the number of words in the initial prompt text, and the initial prompt text can be masked by the target coverage rate to obtain the target number of prompt texts to be completed; the masked text in the prompt text to be completed can be completed by the target prompt generation model to generate a first preset number of imitation prompt texts; and the imitation prompt text and the initial prompt text are compared for semantic similarity to determine the optimized prompt text in the imitation prompt text. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0047] Figure 1 A flowchart of a method for generating a prompt text provided in an embodiment of the present application;
[0048] Figure 2 A flowchart of another method for generating prompt text provided in an embodiment of the present application;
[0049] Figure 3 A schematic diagram of the structure of a prompt text generation device provided in an embodiment of the present application;
[0050] Figure 4 This is a structural block diagram of a device for executing a prompt text generation method according to an embodiment of the present application.
[0051] The above-mentioned drawings have shown clear embodiments of the present application, which will be described in more detail below; these drawings and textual descriptions are not intended to limit the scope of the concept of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION
[0052] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.
[0053] In the prior art, the principle of the language question-answering model to generate original text content is to fit the original training set. Therefore, the quality of the original text content generated by it depends on whether the given prompt is close to the language features of the text prompt in the original training set. When the language features of the given prompt are significantly different from the language features of the prompt in the original training set, the original text content generated by it will also deviate significantly from the user requirements contained in the given prompt.
[0054] In order to solve the above problems, an embodiment of the present application provides a prompt text generation method, which can enable a language question and answer model to generate prompts with original text content that meets user requirements, and use the prompt generation model as an original training set for pre-training, thereby ensuring that the target prompt generation model trained by self-supervised learning can learn the language features of the prompts in the original training set, so that when the target prompt generation model completes the prompt texts to be completed and generated after masking based on the target coverage rate and with a target number of prompt texts, the completed imitation prompt text can have the language features of the prompts in the original training set, and in the imitation prompt text, determine the optimized prompt text that meets the preset semantic similarity requirements with the given initial prompt text, thereby optimizing the given initial prompt text, so that the language question and answer model can generate original text content that meets user requirements by optimizing the prompt text.
[0055] The technical solution of the present application and how the technical solution of the present application solves the above-mentioned technical problems are described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below in conjunction with the accompanying drawings.
[0056] This embodiment does not impose any special restrictions on the implementation method of the execution subject, as long as the execution subject can obtain the initial prompt text; based on the number of words in the initial prompt text, determine the target coverage rate and the target number, the target coverage rate is the ratio of the number of words covered in the initial prompt text to the total number of words, and the target number is the number of prompt texts to be completed after the covering process; based on the target coverage rate, the initial prompt text is covered to obtain the prompt text to be completed, wherein the number of prompt texts to be completed matches the number represented by the target number; based on the prompt text to be completed and a preset target prompt generation model, a first preset number of imitation prompt texts is obtained, and the first preset number is greater than or equal to the number represented by the target number; and the optimized prompt text that meets the preset semantic similarity requirement with the initial prompt text is determined from the imitation prompt text.
[0057] Among them, the target prompt generation model can be a text-to-text model, that is, a text is input and a text with the language style of the text in the original training set is output; the model framework of the target prompt generation model can be original or refer to existing models, including but not limited to Generative Pre-Trained Transformer (GPT), Bidirectional Encoder Representation from Transformers (BERT), etc.
[0058] Figure 1 A flowchart of a method for generating a prompt text provided in an embodiment of the present application is shown below. Figure 1 As shown, the prompt text generation method may include the following steps:
[0059] S110, obtaining an initial prompt text.
[0060] The initial prompt text is a given prompt text containing user requirements, which enables the language question-answering model to generate original text information that meets the user requirements based on the prompt text.
[0061] S120. Determine a target coverage rate and a target number based on the number of characters in the initial prompt text. The target coverage rate is the ratio of the number of characters covered in the initial prompt text to the total number of characters. The target number is the number of prompt texts to be completed after the covering process.
[0062] Based on this, by determining the number of text characters contained in a given initial prompt text, the target coverage rate corresponding to the number of text characters and the target number of prompt texts to be completed generated after masking can be determined; wherein, the target coverage rate and target number of items can be set by the user himself or determined by other means, and this embodiment does not impose any restrictions on this.
[0063] In some implementations, determining a target coverage rate and a target quantity based on the number of words in the initial prompt text includes:
[0064] Determining a preset text word number range based on a first preset text word value and a second preset text word value, wherein the second preset text word value is greater than the first preset text word value;
[0065] Based on the text word range corresponding to the initial prompt text, the target coverage rate and target quantity are determined.
[0066] Among them, the first preset text word value and the second preset text word value are pre-set text word value values, which can be used to determine the text word range; the specific values of the first preset text word value and the second preset text word value can be set by the user himself, or can be determined in other forms, and this embodiment also does not limit this.
[0067] Based on this, the text word count range can be determined through the first preset text word value and the second preset text word value, so as to determine the target coverage rate corresponding to the initial prompt text and the target number of items with all prompt texts according to the number of words in the initial prompt text.
[0068] In this implementation, based on the text word count range corresponding to the initial prompt text, the target coverage rate and the target number are determined, including:
[0069] If the text word count range is the first text word count range, determining the target coverage ratio to be the first target coverage ratio corresponding to the first text word count range, the target number to be the first target number corresponding to the first text word count range, and the first text word count range to be a range smaller than the first preset text word value;
[0070] If the text word count range is the second text word count range, determining the target coverage rate to be the second target coverage rate corresponding to the second text word count range, the target number to be the second target number corresponding to the second text word count range, and the second text word count range to be a range greater than the first preset text word value and less than the second preset text word value;
[0071] If the text word count range is the third text word count range, the target coverage rate is determined to be the third target coverage rate corresponding to the third text word count range, and the target quantity is the third target quantity corresponding to the third text word count range, wherein the third text word count range is a range greater than the second preset text word value range, the third target coverage rate is greater than the second target coverage rate, which is greater than the first target coverage rate, and the third target quantity is greater than the second target quantity, which is greater than the first target quantity.
[0072] Among them, the first text word count range, the second text word count range, and the third text word count range are three word count ranges obtained according to the first preset text word value and the second preset text word value. The first text word count range is less than the first preset text word value, the second text word count range is greater than the first preset text word value and less than the second preset text word value, and the third text word count range is greater than the second preset text word value.
[0073] Based on this, the text word count range corresponding to the text word count of the initial prompt text is determined by the text word count of the initial prompt text and the first preset text word value and the second preset text word value, thereby determining the corresponding target coverage rate and the target number of prompt texts to be completed.
[0074] S130. Based on the target covering rate, the initial prompt text is covered to obtain the prompt text to be completed, wherein the number of prompt texts to be completed matches the number of items represented by the target quantity.
[0075] Among them, the masked characters in the prompt text to be completed are not adjacent to each other, that is, when the initial prompt text is masked according to the target masking rate, continuous masking cannot be performed. The masked characters must not be adjacent to each other, and there must be uncovered characters of the initial prompt text to separate them, so as to ensure the accuracy of the subsequent completion of the prompt text to be completed based on the target prompt generation model.
[0076] Based on this, the initial prompt text is randomly masked according to the target masking rate, and a target number of prompt texts to be completed are obtained, in which the masked characters are not adjacent to each other.
[0077] S140: Based on the prompt text to be completed and a preset target prompt generation model, a first preset number of imitation prompt texts is obtained, where the first preset number is greater than or equal to the number of items represented by the target number.
[0078] Among them, the preset target prompt generation model is a pre-set prompt generation model that can complete the prompt text to be completed, which can be understood as a text-to-text model, that is, input a text and output a text with the language style of the text in the original training set; the model framework of the target prompt generation model can be original or refer to existing models, including but not limited to Generative Pre-Trained Transformer (GPT), Bidirectional Encoder Representation from Transformers (BERT based on Transformer), etc.; the target prompt model can be a natural language processing model trained by self-supervised learning.
[0079] The first preset number is a preset value, which represents the number of imitation prompt texts obtained by the target prompt generation model; the first preset number can be set by the user or determined in other forms.
[0080] Based on this, the prompt text to be completed is completed through the preset target prompt generation model to obtain a first preset number of imitation prompt texts, and the first preset number is greater than or equal to the number represented by the target number, that is, the number of imitation prompt texts is not less than the number of prompt texts to be completed, thereby ensuring that for each prompt text to be completed obtained after masking, the target prompt generation model will generate a corresponding imitation prompt text.
[0081] In some implementations, before obtaining a first preset number of imitation prompt texts based on the prompt text to be completed and the target prompt generation model, the method further includes:
[0082] Obtaining a target information sample, where the target information sample is an information sample that meets the input requirements of the language question answering model;
[0083] Based on the language features of the target information sample, the prompt generation model is self-supervised trained to obtain a target prompt generation model, wherein the prompt generation model is used to receive input text, and after processing the input text, provide a prompt text that meets the input requirements to the language question answering model.
[0084] Among them, the target information sample can be understood as an information sample that satisfies the language style of the language question answering model, that is, the language question answering model can generate high-quality original text content that meets user requirements based on the target information sample.
[0085] Based on this, the prompt generation model is self-supervised trained through the target information samples, so that the trained target prompt generation model can learn the language characteristics of the target information samples, and then the imitation prompt text completed by the target prompt generation model can have the language characteristics of the target information samples, so that the optimized prompt text determined from the imitation prompt text can enable the language question and answer model to generate original text content that satisfies the user and improve the accuracy and text quality of the original text content.
[0086] In some other implementations, based on the prompt text to be completed and the target prompt generation model, a first preset number of imitation prompt texts are obtained, including:
[0087] Based on the prompt text to be completed and the target prompt generation model, an initial imitation prompt text is obtained;
[0088] Determine the output probability of the target prompt generation model outputting the initial imitation prompt text;
[0089] Based on the output probability, the initial imitation prompt texts are sorted to obtain an initial imitation prompt text sequence set;
[0090] comparing the target quantity with a first preset quantity;
[0091] If the target number is less than the first preset number, then based on the preset extraction order, the imitation prompt text is determined from the initial imitation prompt text sequence set, and the number of the imitation prompt text meets the requirement of the second preset number, and the second preset number is obtained according to the first preset number and the target number;
[0092] If the target number is equal to the first preset number, the imitation prompt text with the highest output probability is determined from the initial imitation prompt text sequence set.
[0093] Among them, the output probability is the output probability of the target prompt generation model for the initial imitation prompt text obtained by completion, that is, the probability value given by the model for each possible output result. In machine learning, the output of the model is usually a classification or regression result, and the output probability refers to the probability value of the result. The output probability can be used to determine the confidence of the model, that is, the degree of certainty of the model for the output result. Generally speaking, the higher the output probability, the higher the confidence of the model in the result.
[0094] The second preset quantity is the first preset quantity divided by the value corresponding to the target quantity; if the value corresponding to the first preset quantity divided by the target quantity is a non-integer, the nearest smaller integer is taken as the second preset quantity. For example, if the value corresponding to the first preset quantity divided by the target quantity is 5.6, the second preset quantity is determined to be 5.
[0095] Based on this, the initial imitation prompt texts are sorted by output probability to obtain an initial imitation prompt text sequence set; and the target number and the first preset number are compared, so that according to the comparison result, for each prompt text to be completed, the corresponding number of imitation prompt texts will be determined from the initial imitation prompt text sequence set, so as to achieve that for each prompt text to be completed, the number of imitation prompt texts obtained is the same.
[0096] In this implementation, determining the output probability of the target prompt generation model outputting the initial imitation prompt text includes:
[0097] Based on the target prompt generation model, determine the similarity probability between the initial imitation prompt text and the target information sample;
[0098] Based on the similarity probability, the output probability of the initial imitation prompt text is determined.
[0099] Among them, the similarity probability is the semantic similarity probability between the initial imitation prompt text and the target information sample, which is used to determine the output probability of the initial imitation prompt text. That is, if the semantic similarity probability between the initial imitation prompt text and the target information sample is high, the output probability of the initial imitation prompt text is higher.
[0100] Comparing the semantic similarity probability between the initial imitation prompt text and the target information sample can be done by determining the probability of the unmasked text and the masked and completed text adjacent to the text in the initial imitation prompt text appearing in the target information sample, thereby determining the semantic similarity probability between the initial imitation prompt text and the target information sample; in addition, the semantic similarity probability between the initial imitation prompt text and the target information sample can also be determined in other forms, which is not limited in this embodiment.
[0101] S150: Determine, from the imitation prompt text, an optimized prompt text that meets a preset semantic similarity requirement with the initial prompt text.
[0102] Among them, the preset semantic similarity requirement is a pre-set requirement for determining the semantic similarity between texts; if the preset semantic similarity requirement is met between texts, it indicates that the texts have a high semantic similarity; the similarity of the texts can be compared using existing artificial intelligence model comparisons, dictionary matching queries, word vector comparisons and other automatic methods.
[0103] Based on this, by continuing to compare the semantic similarity between the imitation prompt text and the initial prompt text, the optimized prompt text that meets the preset semantic similarity requirements is determined in the imitation prompt text; it can be understood that the optimized prompt text is the prompt text that has the language characteristics of the target information sample and meets the similarity requirements with the initial prompt text, which enables the language question answering model to generate high-quality original text content that meets the user's requirements based on the optimized prompt text. This improves the user's sense of use and satisfaction.
[0104] In some embodiments, after determining the optimized prompt text that meets the preset semantic similarity requirement with the initial prompt text from the imitation prompt text, the method further includes:
[0105] The optimized prompt text is sent to the language question answering model, so that the language question answering model generates answer text information based on the optimized prompt text.
[0106] Among them, the language question and answer model can be a generative artificial intelligence model, which uses various machine learning methods to learn the content text components of an object from training data, and then generates an artificial intelligence model with new and completely original content, and will generate corresponding original content for the input text; the language question and answer model can also be other natural language processing models, as long as it can achieve a certain task requirement given by the user and the model can generate original text content that meets the requirements, this embodiment does not limit this.
[0107] In this embodiment, a given initial prompt text is obtained, and based on a preset text word count range, a text word count range corresponding to the text word count of the initial prompt text, as well as a corresponding target coverage rate and a target number of prompt texts to be completed are determined, and the initial prompt text is covered based on the target coverage rate to obtain a target number of prompt texts to be completed; and the prompt text to be completed is completed by a target prompt generation model obtained by training based on a target information sample to obtain a first preset number of imitation prompt texts, and based on the size relationship between the first preset number and the target number, the number of imitation prompt texts with the highest output probability for each prompt text to be completed is determined, and based on the preset semantic similarity requirement, an optimized prompt text is determined from the imitation prompt texts with the highest output probability, so that the language question answering model generates high-quality original text content that meets user requirements based on the optimized prompt text.
[0108] In this way, optimization is achieved by covering, completing, and comparing the similarity of the initial prompt text given by the user, and an optimized prompt text is obtained. Since the target prompt text generation model is based on the target information sample and is learned through self-supervised learning, the optimized prompt text has the language characteristics of the target information sample. The language question and answer model can generate high-quality original text content that meets the user's requirements based on the optimized prompt text, so that no matter what language characteristics the prompt given by the user has, it can be converted according to the language characteristics of the prompt supported by the language question and answer model, thereby improving the quality of the original content generated by the language question and answer model, meeting the actual needs of users, and effectively improving the use effect of the generative artificial intelligence model.
[0109] Figure 2 A flowchart of another method for generating prompt text provided in an embodiment of the present application.
[0110] like Figure 2 As shown, the prompt text generation method may include the following steps:
[0111] S210. Select the text portion of the original training set of the generative artificial intelligence model as an unlabeled data set for the styled text generation model.
[0112] Among them, the generative artificial intelligence model can be an artificial intelligence model that learns the content text components of an object from training data through various machine learning methods, and then generates new and completely original content. For the input text, the artificial intelligence model will generate corresponding original content.
[0113] The original training set is a prompt text dataset that fully conforms to the language characteristics of the prompts of the generative artificial intelligence model.
[0114] The styled text generation model can be a text-to-text model, that is, a text input will output a text that matches the style. The model framework of the styled text generation model can be original or refer to existing models, including but not limited to T5, GPT, BERT, etc.
[0115] S220. Based on self-supervised learning, a styled text generation model is obtained according to the unlabeled dataset selected in the previous step.
[0116] Based on this, the text generation model is trained through self-supervised learning based on an unlabeled dataset to obtain a styled text generation model.
[0117] S230 , the original prompt input by the user is randomly masked at intervals according to the target masking rate to obtain masked text.
[0118] Among them, the target coverage rate will be adjusted differently according to the different lengths of the original prompt. If the original prompt has only one word, there is no need to mask it and it can be directly input into the generative artificial intelligence model to obtain the result; if the original prompt is short, the target coverage rate must be adjusted to a suitable value; if the original prompt is long enough, a target coverage rate value can be determined, such as 60%.
[0119] The number of masked texts will also vary depending on the length of the original prompt. If the original prompt has only one word, the number is 1; if the original prompt is short, the number is relatively small; if the original prompt is long enough, a value such as 10 can be determined.
[0120] S240: Input the masked texts into the styled text generation model to obtain corresponding styled completed texts.
[0121] The number of completion texts is a fixed value determined in advance. Then, different countermeasures will be taken according to the different lengths of the original prompt. If the original prompt has only one word, it will be directly input into the styled text, and the text with the highest probability of output of the styled text and the corresponding number of completion texts will be taken; if the original prompt is short, that is, the number of covered texts is less than the number of completion texts, then for each input of the styled text, the text with the highest probability of output must be taken, and the number of previous completion texts divided by the number of covered texts, and finally the completion text is formed; if the original prompt is long enough, that is, the number of completion texts is equal to the number of covered texts, then for each input of the styled text, the text with the highest probability of output must be taken as the completion text, and the number of completion texts is formed.
[0122] S250, respectively compare the text similarity between the completed text and the original prompt, and take the style text with the highest similarity as the optimized text.
[0123] In this embodiment, the text similarity comparison method includes but is not limited to automatic methods such as using existing artificial intelligence model comparison, using word vector angle comparison, using dictionary matching query comparison, etc. After each text is compared with the original input to obtain the corresponding similarity, it is sorted and the most similar text is automatically selected.
[0124] S260. Inputting the optimized text into the generative artificial intelligence model can obtain better original content results and return them to the user.
[0125] In this embodiment, no matter what style of prompt the user inputs, it can be converted according to the style supported by the generative artificial intelligence model, thereby improving the quality of the original content generated, meeting the actual needs of the user, and effectively improving the use effect of the generative artificial intelligence model.
[0126] Figure 3 A schematic diagram of the structure of a prompt text generating device 300 provided in an embodiment of the present application is shown in FIG. Figure 3 As shown, the prompt text generating device 300 includes: a text acquisition module 310 , a coverage rate and quantity determination module 320 , a text covering module 330 , a text obtaining module 340 and a text determination module 350 .
[0127] The text acquisition module 310 is used to acquire the initial prompt text;
[0128] The coverage rate and quantity determination module 320 is used to determine the target coverage rate and target quantity based on the number of words in the initial prompt text. The target coverage rate is the ratio of the number of words covered in the initial prompt text to the total number of words. The target quantity is the number of prompt texts to be completed after the covering process.
[0129] A text masking module 330 is used to mask the initial prompt text based on the target masking rate to obtain the prompt text to be completed, wherein the number of prompt texts to be completed matches the number of items represented by the target number;
[0130] A text obtaining module 340 is used to obtain a first preset number of imitation prompt texts based on the prompt text to be completed and a preset target prompt generation model, where the first preset number is greater than or equal to the number of items represented by the target number;
[0131] The text determination module 350 is used to determine, from the imitation prompt text, an optimized prompt text that meets a preset semantic similarity requirement with the initial prompt text.
[0132] In the embodiment of the present application, the coverage rate and quantity determination module 320 may also be specifically used for:
[0133] Determining a preset text word number range based on a first preset text word value and a second preset text word value, wherein the second preset text word value is greater than the first preset text word value;
[0134] Based on the text word range corresponding to the initial prompt text, the target coverage rate and target quantity are determined.
[0135] In the embodiment of the present application, the coverage rate and quantity determination module 320 may also be specifically used for:
[0136] If the text word count range is the first text word count range, determining the target coverage ratio to be the first target coverage ratio corresponding to the first text word count range, the target number to be the first target number corresponding to the first text word count range, and the first text word count range to be a range smaller than the first preset text word value;
[0137] If the text word count range is the second text word count range, determining the target coverage rate to be the second target coverage rate corresponding to the second text word count range, the target number to be the second target number corresponding to the second text word count range, and the second text word count range to be a range greater than the first preset text word value and less than the second preset text word value;
[0138] If the text word count range is the third text word count range, the target coverage rate is determined to be the third target coverage rate corresponding to the third text word count range, and the target quantity is the third target quantity corresponding to the third text word count range, wherein the third text word count range is a range greater than the second preset text word value range, the third target coverage rate is greater than the second target coverage rate, which is greater than the first target coverage rate, and the third target quantity is greater than the second target quantity, which is greater than the first target quantity.
[0139] In the embodiment of the present application, the prompt text generating device 300 can also be specifically used for:
[0140] Obtaining a target information sample, where the target information sample is an information sample that meets the input requirements of the language question answering model;
[0141] Based on the language features of the target information sample, the prompt generation model is self-supervised trained to obtain a target prompt generation model, wherein the prompt generation model is used to receive input text, and after processing the input text, provide a prompt text that meets the input requirements to the language question answering model.
[0142] In the embodiment of the present application, the text obtaining module 340 may also be specifically used for:
[0143] Based on the prompt text to be completed and the target prompt generation model, an initial imitation prompt text is obtained;
[0144] Determine the output probability of the target prompt generation model outputting the initial imitation prompt text;
[0145] Based on the output probability, the initial imitation prompt texts are sorted to obtain an initial imitation prompt text sequence set;
[0146] comparing the target quantity with a first preset quantity;
[0147] If the target number is less than the first preset number, then based on the preset extraction order, the imitation prompt text is determined from the initial imitation prompt text sequence set, and the number of the imitation prompt text meets the requirement of the second preset number, and the second preset number is obtained according to the first preset number and the target number;
[0148] If the target number is equal to the first preset number, the imitation prompt text with the highest output probability is determined from the initial imitation prompt text sequence set.
[0149] In the embodiment of the present application, the text obtaining module 340 may also be specifically used for:
[0150] Based on the target prompt generation model, determine the similarity probability between the initial imitation prompt text and the target information sample;
[0151] Based on the similarity probability, the output probability of the initial imitation prompt text is determined.
[0152] In the embodiment of the present application, the prompt text generating device 300 can also be specifically used for:
[0153] The optimized prompt text is sent to the language question answering model, so that the language question answering model generates answer text information based on the optimized prompt text.
[0154] Figure 4 This is a schematic diagram of the structure of the device provided in the embodiment of the present application. Figure 4 As shown, the device 400 includes:
[0155] The device 400 may include a processor 401 with one or more processing cores, a memory 402 with one or more computer-readable storage media, a communication component 403 and other components. The processor 401 , the memory 402 and the communication component 403 are connected via a bus 404 .
[0156] In a specific implementation process, at least one processor 401 executes the computer execution instructions stored in the memory 402, so that at least one processor 401 executes the above message processing method.
[0157] The specific implementation process of the processor 401 can be found in the above method embodiment, and its implementation principle and technical effect are similar, so this embodiment will not be repeated here.
[0158] In the above Figure 4 In the illustrated embodiment, it should be understood that the processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), etc. A general-purpose processor may be a microprocessor or any conventional processor. The steps of the method disclosed in the present application may be directly implemented as being executed by a hardware processor, or may be executed by a combination of hardware and software modules in the processor.
[0159] The memory may include a high-speed memory (Random Access Memory, RAM), and may also include a non-volatile memory (Non-volatile Memory, NVM), such as at least one disk memory.
[0160] The bus may be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, the bus in the drawings of the present application is not limited to only one bus or one type of bus.
[0161] In some embodiments, a computer program product is also proposed, including a computer program or instructions, which implement the steps in any of the above-mentioned prompt text generation methods when executed by a processor.
[0162] The specific implementation of the above operations can be found in the previous embodiments, which will not be described in detail here.
[0163] A person of ordinary skill in the art will appreciate that all or part of the steps in the various methods of the above embodiments may be completed by instructions, or by controlling related hardware through instructions. The instructions may be stored in a computer-readable storage medium and loaded and executed by a processor.
[0164] To this end, an embodiment of the present application provides a computer-readable storage medium, in which multiple computer execution instructions are stored. The computer execution instructions can be loaded by a processor to execute the steps in any prompt text generation method provided in the embodiment of the present application.
[0165] The storage medium may include: a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.
[0166] According to one aspect of the present application, a computer program product or a computer program is provided. The computer program product or the computer program comprises computer instructions stored in a computer-readable storage medium.
[0167] Since the instructions stored in the storage medium can execute the steps in any prompt text generation method provided in the embodiments of the present application, the beneficial effects that can be achieved by any prompt text generation method provided in the embodiments of the present application can be achieved. Please refer to the previous embodiments for details and will not be repeated here.
[0168] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the invention disclosed herein. The present application is intended to cover any modification, use or adaptation of the present application, which follows the general principles of the present application and includes common knowledge or customary techniques in the art that are not disclosed in the present application. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present application are indicated by the following claims.
[0169] It should be understood that the present application is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.
Claims
1. A method for generating a prompt text, characterized in that: The method comprises: Get the initial prompt text; Based on the number of characters in the initial prompt text, determine a target coverage rate and a target number, wherein the target coverage rate is the ratio of the number of characters covered in the initial prompt text to the total number of characters, and the target number is the number of prompt texts to be completed after the covering process is performed; Based on the target covering rate, the initial prompt text is covered to obtain the prompt text to be completed, wherein the number of the prompt text to be completed matches the number of the target quantity representation; Based on the prompt text to be completed and a preset target prompt generation model, a first preset number of imitation prompt texts is obtained, where the first preset number is greater than or equal to the number of items represented by the target number; An optimized prompt text that meets a preset semantic similarity requirement with the initial prompt text is determined from the imitation prompt text.
2. The method according to claim 1, characterized in that The step of determining a target coverage rate and a target quantity based on the number of characters in the initial prompt text includes: Determining a preset text word number range based on a first preset text word value and a second preset text word value, wherein the second preset text word value is greater than the first preset text word value; The target coverage rate and the target quantity are determined based on the text word number range corresponding to the initial prompt text.
3. The method according to claim 2, characterized in that The determining the target coverage rate and the target quantity based on the text word count range corresponding to the initial prompt text includes: If the text word count range is a first text word count range, determining the target coverage rate to be a first target coverage rate corresponding to the first text word count range, the target number to be a first target number corresponding to the first text word count range, and the first text word count range is a range smaller than the first preset text word value; If the text word count range is a second text word count range, determining the target coverage rate to be a second target coverage rate corresponding to the second text word count range, the target number to be a second target number corresponding to the second text word count range, and the second text word count range is a range greater than the first preset text word value and less than the second preset text word value; If the text word count range is a third text word count range, the target coverage rate is determined to be a third target coverage rate corresponding to the third text word count range, and the target quantity is a third target quantity corresponding to the third text word count range, wherein the third text word count range is a range greater than the second preset text word value range, the third target coverage rate is greater than the second target coverage rate, which is greater than the first target coverage rate, and the third target quantity is greater than the second target quantity, which is greater than the first target quantity.
4. The method according to claim 1, characterized in that Before obtaining a first preset number of imitation prompt texts based on the prompt text to be completed and the target prompt generation model, the method further includes: Acquire a target information sample, where the target information sample is an information sample that meets the input requirements of the language question answering model; Based on the language features of the target information sample, a prompt generation model is self-supervised trained to obtain the target prompt generation model, wherein the prompt generation model is used to receive input text, and after processing the input text, provide the language question-answering model with a prompt text that meets the input requirements.
5. The method according to claim 1, characterized in that The step of obtaining a first preset number of imitation prompt texts based on the prompt text to be completed and the target prompt generation model includes: Based on the prompt text to be completed and the target prompt generation model, an initial imitation prompt text is obtained; Determine the output probability of the target prompt generation model outputting the initial imitation prompt text; Based on the output probability, the initial imitation prompt texts are sorted to obtain an initial imitation prompt text sequence set; comparing the target quantity with the first preset quantity; If the target number is less than the first preset number, then based on a preset extraction order, determine the imitation prompt text from the initial imitation prompt text sequence set, the number of the imitation prompt text meets the requirement of a second preset number, and the second preset number is obtained according to the first preset number and the target number; If the target number is equal to the first preset number, the imitation prompt text with the highest output probability is determined from the initial imitation prompt text sequence set.
6. The method according to claim 5, characterized in that The step of determining the output probability of the target prompt generation model outputting the initial imitation prompt text comprises: Based on the target prompt generation model, determining the similarity probability between the initial imitation prompt text and the target information sample; Based on the similarity probability, the output probability of the initial imitation prompt text is determined.
7. The method according to claim 1, characterized in that After determining the optimized prompt text that meets the preset semantic similarity requirement with the initial prompt text from the imitation prompt text, the method further includes: The optimized prompt text is sent to a language question-answering model, so that the language question-answering model generates answer text information based on the optimized prompt text.
8. A prompt text generation device, characterized in that: The device comprises: A text acquisition module is used to acquire the initial prompt text; A coverage rate and quantity determination module, used to determine a target coverage rate and a target quantity based on the number of words in the initial prompt text, wherein the target coverage rate is the ratio of the number of words covered in the initial prompt text to the total number of words, and the target quantity is the number of prompt texts to be completed after the covering process is performed; A text masking module, configured to mask the initial prompt text based on the target masking rate to obtain the prompt text to be completed, wherein the number of the prompt text to be completed matches the number of the target quantity representation; A text obtaining module, used to obtain a first preset number of imitation prompt texts based on the prompt text to be completed and a preset target prompt generation model, wherein the first preset number is greater than or equal to the number of items represented by the target number; The text determination module is used to determine the optimized prompt text that meets the preset semantic similarity requirement with the initial prompt text from the imitation prompt text.
9. A device, characterized in that: include: one or more processors; Memory; One or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, and the one or more programs are configured to execute the method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions can be called by a processor to execute the method according to any one of claims 1 to 7.