Text generation method and device, electronic equipment and storage medium
By searching and integrating the first text and the second text obtained through its expansion, the problem of insufficient interpretation of the search result set association in the prior art is solved, and the accuracy of text generation is improved.
Patent Information
- Application Number
- CN202410925154.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-10
- Publication Date
- 2024-12-13
AI Technical Summary
Existing text generation methods cannot effectively interpret and express the association between the search result sets, resulting in low accuracy of knowledge text, which in turn affects the accuracy of model output.
By obtaining the first text and the second text obtained through its expansion, the first search result set and the second search result set are obtained, and the first search result set are fused to generate the target result set, and provided to the text to generate a big model to generate more Accurate text.
By fusion processing of the search result set, the comprehensiveness and accuracy of the content of the knowledge text are improved, thereby improving the accuracy of model output.
Smart Images

Figure CN119129533A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of natural language processing, and in particular to a text generation method, device, electronic device and storage medium. Background Art
[0002] At present, the application of big models is increasing. In the field of text generation, big models can generate natural language texts, such as articles and conversations. However, when generating text or answering questions, big text generation models will create some unreal information (i.e., hallucinations) that are inconsistent with the facts of the real world. The current way to solve hallucinations is often to search for corresponding search results in the knowledge base based on the first text input by the user, and merge the numerous search results to obtain knowledge text. Finally, the knowledge text and the first text are provided to the text generation big model at the same time to avoid hallucinations. However, the existing text generation methods cannot explain and express the relationship between each search result set, resulting in low accuracy of the final knowledge text, which ultimately leads to a decrease in the accuracy of the model output content. Summary of the invention
[0003] The embodiment of the present invention provides a text generation method, which aims to solve the problem that the knowledge text obtained by fusion during the existing text generation is of low accuracy, which ultimately leads to a decrease in the accuracy of the model output content. By performing retrieval processing on a first text and a second text obtained by expanding the first text, a first retrieval result set and a second retrieval result set are obtained. After the first retrieval result set and the second retrieval result set are fused, a more comprehensive target result set can be obtained, and then when the target result set and the first text are provided to a large text generation model, a more accurate target text can be generated.
[0004] In a first aspect, an embodiment of the present invention provides a text generation method, characterized in that the method comprises the following steps:
[0005] Acquire a search text, wherein the search text includes a first text and a second text, wherein the second text is obtained by expanding the first text through a text generation macro model;
[0006] Performing search processing on the search text to obtain a first search result set and a second search result set, wherein the first search result set corresponds to the first text and the second search result set corresponds to the second text;
[0007] Merging the first search result set and the second search result set to obtain a target result set;
[0008] The target result set and the first text are provided to the text generation model so that the text generation model generates the target text.
[0009] Optionally, performing search processing on the search text to obtain a first search result set and a second search result set includes:
[0010] Using the search text as a search condition to perform search processing in a preset knowledge base, obtaining a first search result corresponding to the first text, a relevance between the first search result and the corresponding first text, and a second search result corresponding to the second text, and a relevance between the second search result and the corresponding second text;
[0011] Based on the relevance between each first search result and the corresponding first text, adding each first search result to the search result set corresponding to the first text in a preset order to obtain the first search result set;
[0012] Based on the relevance between each second search result and the corresponding second text, each second search result is added to the search result set corresponding to the second text in a preset order to obtain the second search result set.
[0013] Optionally, the second text includes at least one text unit, each of the text units corresponds to a text generation probability value, and the first search result set and the second search result set are fused to obtain a target result set, including:
[0014] Determining a text weight of the second text based on a text generation probability value of a text unit in the second text;
[0015] Determining a text weight of the first text based on the text weight of the second text and a preset weight coefficient;
[0016] Based on the text weight of the second text and the text weight of the first text, the first search result set and the second search result set are fused to obtain a target result set.
[0017] Optionally, determining the text weight of the second text based on the text generation probability value of the text unit in the second text includes:
[0018] Adding text generation probability values of the respective text units in the second text to obtain an initial weight of the second text;
[0019] The initial weight of the second text is normalized to obtain a text weight of the second text.
[0020] Optionally, normalizing the initial weight of the second text to obtain the text weight of the second text includes:
[0021] Add up the initial weights of all second texts to obtain the initial weight sum;
[0022] Based on the initial weight and normalizing the initial weight of the second text, a text weight of the second text is obtained.
[0023] Optionally, the first search result set includes first search results sorted according to relevance to the first text, the second search result set includes second search results sorted according to relevance to the second text, and the first search result set and the second search result set are fused based on the text weight of the second text and the text weight of the first text to obtain a target result set, including:
[0024] Calculating a fusion score for each of the first search results based on a text weight of the first text and a rank of each of the first search results in the first search result set;
[0025] Calculating a fusion score of each second search result based on a text weight of the second text and a rank of each second search result in the second search result set;
[0026] Based on the fusion score of each of the first search results and the fusion score of each of the second search results, the first search result set and the second search result set are fused to obtain the target result set.
[0027] Optionally, providing the target result set and the first text to the text generation model so that the text generation model generates a target text includes:
[0028] Based on the fusion score, extracting search results that meet preset conditions from the target result set;
[0029] Adding the search results satisfying the preset conditions and the first text to a preset prompt template to obtain a target prompt text;
[0030] The target prompt text is provided to the text generation model so that the text generation model generates the target text.
[0031] In a second aspect, an embodiment of the present invention further provides a text generation device, the text generation device comprising:
[0032] An acquisition module, used for acquiring a search text, wherein the search text includes a first text and a second text, wherein the second text is obtained by expanding the first text through a text generation macro model;
[0033] A retrieval module, used to perform retrieval processing on the search text to obtain a first search result set and a second search result set, wherein the first search result set corresponds to the first text and the second search result set corresponds to the second text;
[0034] A fusion module, used for fusing the first search result set and the second search result set to obtain a target result set;
[0035] A generation module is used to provide the target result set and the first text to the text generation model so that the text generation model generates the target text.
[0036] In a third aspect, an embodiment of the present invention provides an electronic device, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps in the text generation method provided in the embodiment of the present invention when executing the computer program.
[0037] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps in the text generation method provided in the embodiment of the invention are implemented.
[0038] In an embodiment of the present invention, a search text is obtained, the search text includes a first text and a second text, the second text is obtained by expanding the first text through a text generation model; the search text is searched to obtain a first search result set and a second search result set, the first search result set corresponds to the first text, and the second search result set corresponds to the second text; the first search result set and the second search result set are fused to obtain a target result set; the target result set and the first text are provided to the text generation model so that the text generation model generates the target text. The text weight determined by the text generation probability value and the search result set obtained by relevance sorting can well reflect the association between the various search result sets, so that after the search result set is fused by taking the order of relevance sorting and the text weight as the basis for fusion, a target result set with higher accuracy can be obtained, and then a target text with higher accuracy can be obtained after text generation processing is performed based on the target result set and the first text. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0040] Figure 1 is a flow chart of a text generation method provided by an embodiment of the present invention;
[0041] Figure 2 is a structural schematic diagram of a prompt template provided by an embodiment of the present invention;
[0042] Figure 3 is an example diagram of a fusion score calculation method provided by an embodiment of the present invention;
[0043] Figure 4 is a flow chart of another text generation method provided by an embodiment of the present invention;
[0044] Figure 5 is a flow chart of another text generation method provided by an embodiment of the present invention;
[0045] Figure 6 is a structural schematic diagram of a text generation device provided in an embodiment of the present invention;
[0046] Figure 7 It is a structural schematic diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0047] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0048] like Figure 1 As shown, Figure 1 : is a flow chart of a text generation method provided by an embodiment of the present invention. The text generation method is applied to the management of specific personnel in a specific area and includes:
[0049] 101. Get the search text.
[0050] In an embodiment of the present invention, the above-mentioned text generation method can be applied to a text generation platform. The above-mentioned text generation platform can be constructed by a server or a server cluster. The above-mentioned server or server cluster can be any electronic device with functions such as text recognition, text processing, text generation, data storage, and data transmission. The above-mentioned text generation large model can be deployed in the above-mentioned text generation platform, or the above-mentioned text generation platform can have an application interface of any one of the text generation large models. The above-mentioned text generation platform can realize the application of the above-mentioned text generation large model by calling the above-mentioned application interface.
[0051] The above-mentioned text generation big model can be any big model that can perform text generation processing, for example, it can be the Wenxin Yiyan big model, the Xinghuo big model, the Pangu big model, the Hunyuan big model, New Bing, GPT-4, GPT-3, GPT-2 and other big models.
[0052] The above-mentioned search text includes a first text and a second text. The above-mentioned second text is obtained by expanding the first text through a text generation model. The above-mentioned first text can be a query or question type text input by a user. The above-mentioned user can input the text required for query or inquiry through any user terminal and upload the above-mentioned text to the above-mentioned text generation platform.
[0053] When the text generation platform receives the first text, it can combine the first text with the preset prompt template and input it into the text generation model, so that the text generation model can expand the first text according to the preset prompt template to obtain at least one second text. The number of the second texts can be obtained according to the preset prompt template. The number of output results (i.e., second texts) of the text generation model can be set in the prompt template. Or, when the number of the second texts is not set, the number of the second texts is generated and output by the text generation model itself.
[0054] Specifically, the above preset prompt template can be used as follows: Figure 2 The structural schematic diagram of a prompt template shown is further explained. Figure 2In the example, "Please generate 4 new query statements with different questions but similar meanings based on the query provided below." can be the above-mentioned prompt template, which is used to prompt the above-mentioned text generation model to perform corresponding expansion processing. It should be noted that the above-mentioned "4 new query statements (i.e., the number of the above-mentioned output results)" is not fixed, and the number of new query statements can be any number, which can be set according to user needs. For example, when the user needs a more accurate answer (i.e., the target text, or it can be understood as the reply made by the text generation model to the query or inquiry raised by the first text), the number of the above-mentioned query statements can be set to a larger number to provide a second text with sufficient data volume, so that when searching based on the second text with sufficient data volume, more search results can be retrieved, thereby improving the accuracy of text generation. When the user needs faster text generation efficiency, the number of the above-mentioned query statements can be set to a smaller number to reduce the number of second texts (to a minimum of one), thereby improving the efficiency of text generation.
[0055] In a possible embodiment, the first text may be expanded according to the semantics of the first text to obtain a text with semantics similar to the first text, and the text with semantics similar to the first text may be used as the second text.
[0056] Each of the above-mentioned second texts includes at least one text unit, and each text unit corresponds to a text generation probability value. The above-mentioned text unit can be the smallest unit in the text (i.e., token). For example, it can be a character, word, phrase, punctuation mark or other unit in the text. When the above-mentioned text generation model outputs the above-mentioned second text, it will synchronously output the text generation probability value of each text unit in the above-mentioned second text. The above-mentioned text generation probability value can be understood as the confidence of the above-mentioned text unit.
[0057] 102. Perform search processing on the search text to obtain a first search result set and a second search result set.
[0058] In an embodiment of the present invention, the first search result set corresponds to the first text, and the second search result set corresponds to the second text. The first text and the second text can be used as search conditions to perform search processing in a preset knowledge base to obtain the first search result set and the second search result set. It should be noted that when performing the search processing, the search processing can be a parallel search or a serial search, which can be set according to actual needs. The embodiment of the present invention can give priority to parallel search to improve the search efficiency.
[0059] At least one first search result corresponding to the first text retrieved according to the search text is sorted according to the relevance between the first search result and the first text, and the at least one first search result is stored in the result set corresponding to the first text to obtain a first search result set. For each second text, at least one second search result corresponding to the second text retrieved according to the search text is sorted according to the relevance between the second search result and the second text, and the at least one second search result is stored in the result set corresponding to the second text to obtain a second search result set. The above relevance can be understood as text similarity, and the above relevance can be calculated by any text similarity algorithm, for example, it can be cosine similarity or Jaccard similarity.
[0060] 103. The first search result set and the second search result set are merged to obtain a target result set.
[0061] In an embodiment of the present invention, the first search result set includes first search results sorted according to the relevance to the first text, and the second search result set includes second search results sorted according to the relevance to the second text. When the text generation model generates the second text according to the first text, it can simultaneously output the text generation probability value of each text unit in the second text. Therefore, the text weight of the second text can be calculated according to the text generation probability value, and the text weight of the first text can be calculated based on the text weight of the second text and the preset weight coefficient.
[0062] Based on the text weight of the above-mentioned first text and the rank of the above-mentioned first search result in the first search result set, the fusion score of each of the above-mentioned first search results is calculated; based on the text weight of the above-mentioned second text and the rank of the above-mentioned second search result in the second search result set, the fusion score of each of the above-mentioned second search results is calculated; and according to the fusion score of each first search result and the fusion score of each second search result, the first search result or the second search result is added to the preset empty set in descending order of the fusion score, so as to obtain the above-mentioned target result set.
[0063] It is understandable that the second search result set may contain a second search result with the same text content as the first search result. The rank of the first search result with the same text content may be the same as or different from the rank of the second search result with the same text content. Since the text content is the same, the fusion score of the search results with the same text content can be calculated based on the rank of the search results with the same text content (the first search result and the second search result, or when there are multiple second search result sets, the second search results in different second search result sets) in different search result sets and the corresponding text weights. Therefore, when adding, the search results with the same text content can be added to the target result set as an addition unit based on the fusion score of the search results with the same text content.
[0064] 104. Provide the target result set and the first text to a text generation model so that the text generation model generates the target text.
[0065] In an embodiment of the present invention, the search results in the target result set correspond to the fusion score. According to the fusion score, a preset number of search results with higher fusion scores can be extracted from the target result set, and the search results and the first text are assembled to obtain a target prompt text. The target prompt text is provided to the text generation model so that the text generation model generates the target text. It can be understood that the target text is the reply of the text generation model to the first text. After the target text is generated, the target text can be transmitted to the user display interface of the user terminal used by the user through the data transmission function for the user to view.
[0066] The above-mentioned assembly processing can be an assembly project constructed based on Java programming language or Python programming language, and the above-mentioned search results and the above-mentioned first text are input into the above-mentioned assembly project to realize the above-mentioned assembly processing, or the above-mentioned search results and the above-mentioned first text can be string-concatenated by any method that can perform string concatenation, for example, it can be a preset target prompt template, and the above-mentioned search results and the above-mentioned first text are spliced into the above-mentioned preset target prompt template to obtain the above-mentioned target prompt text.
[0067] In an embodiment of the present invention, a search text is obtained, the search text includes a first text and a second text, the second text is obtained by expanding the first text through a text generation model; the search text is searched to obtain a first search result set and a second search result set, the first search result set corresponds to the first text, and the second search result set corresponds to the second text; the first search result set and the second search result set are fused to obtain a target result set; the target result set and the first text are provided to the text generation model so that the text generation model generates the target text. The text weight determined by the text generation probability value and the search result set obtained by relevance sorting can well reflect the association between the various search result sets, so that after the search result set is fused by taking the order of relevance sorting and the text weight as the basis for fusion, a target result set with higher accuracy can be obtained, and then a target text with higher accuracy can be obtained after text generation processing is performed based on the target result set and the first text.
[0068] It is understandable that in the specific implementation of the present application, it involves the first text input by the user, the knowledge base and other related data. When the embodiments in the present application are applied to specific products or technologies, the user's permission or consent is required, and the collection, use and processing of relevant data and the construction, use and processing of large models need to comply with the relevant laws, regulations and standards of relevant countries and regions.
[0069] Optionally, in the step of performing a search process on the search text to obtain a first search result set and a second search result set, the search text can also be used as a search condition to perform a search process in a preset knowledge base to obtain a first search result corresponding to the first text, the correlation between the first search result and the corresponding first text, and a second search result corresponding to the second text, and the correlation between the second search result and the corresponding second text; based on the correlation between each first search result and the corresponding first text, each first search result is added to the search result set corresponding to the first text in a preset order to obtain a first search result set; based on the correlation between each second search result and the corresponding second text, each second search result is added to the search result set corresponding to the second text in a preset order to obtain a second search result set.
[0070] In the embodiment of the present invention, the above-mentioned preset knowledge base may be a knowledge vector library, for example, it may be any vector database such as a FAISS library, an Annoy library, a Milvus library, etc.
[0071] Specifically, the search may be performed by converting the search text into a corresponding search vector, and calculating the relevance (i.e., text similarity) between the knowledge vector in the knowledge vector library and the search vector by using the search vector as a search condition. After the search, the knowledge vector corresponding to each search vector is obtained, and the knowledge vector is converted into a text form to obtain the first search result and the second search result.
[0072] It can be understood that each knowledge vector corresponds to a search result (the first search result or the second search result), and each search vector corresponds to a search text (the first text or the second text). The above vectors and texts are essentially the same, and only the expression method (or understood as the form of existence, one is a vector form and the other is a text form) is different. Therefore, the correlation between the above knowledge vector and the above search vector is equivalent to the correlation between the corresponding search result and the search text. Therefore, after the search is completed, the search result corresponding to each search text and the correlation between each search result and the corresponding search text can be obtained. The above preset order can be a descending order, so based on the correlation between the above first search result and the corresponding first text, the above first search result can be added to the search result set corresponding to the first text one by one in the order of correlation from large to small, and the first search result set is obtained. At the same time, based on the correlation between the above second search result and the corresponding second text, the above second search result can be added to the search result set corresponding to the second text one by one in the order of correlation from large to small, and the second search result set is obtained.
[0073] It should be noted that, in the first search result set, the higher the rank of the first search result, the higher the correlation between the first search result and the corresponding first text, and vice versa, the lower the correlation between the first search result and the corresponding first text. Similarly, in the second search result set, the higher the rank of the second search result, the higher the correlation between the second search result and the corresponding second text, and vice versa, the lower the correlation between the second search result and the second text.
[0074] The above-mentioned empty set of search results can be understood as a preset empty set. The first text corresponds to an empty set of search results, and each second text corresponds to an empty set of search results. After all the search results (first search results and second search results) corresponding to the search texts (first text and second text) are added to the corresponding empty sets of search results, the above-mentioned first search result set and second search result set can be obtained.
[0075] Optionally, in the step of fusing the first search result set and the second search result set to obtain a target result set, the text weight of the second text can be determined based on the text generation probability value of the text unit in the second text; the text weight of the first text can be determined based on the text weight of the second text and a preset weight coefficient; and the first search result set and the second search result set can be fused based on the text weight of the second text and the text weight of the first text to obtain the target result set.
[0076] In an embodiment of the present invention, the above-mentioned second text includes at least one text unit, and each of the above-mentioned text unit corresponds to a text generation probability value. It should be noted that since the above-mentioned text generation probability value is obtained through the output of the above-mentioned text generation large model, each text unit in the above-mentioned second text has a corresponding text generation probability value.
[0077] Specifically, the text generation probability value of each text unit in the second text may be added to obtain the initial weight of the second text, and the initial weight of each second text may be normalized to obtain the text weight of each second text.
[0078] It is understandable that, since the first text is not the output of the large text generation model, but only serves as the input of the large text generation model, the first text does not have a corresponding text generation probability value. However, the first text is input by the user and is often closer to the user's real thoughts. Therefore, a preset weight coefficient can be set, and the text weight of the first text can be calculated based on the text weight of the second text and the weight coefficient. The weight coefficient can be a number greater than or equal to 1, such as 1.1 (or 110%), 1.2 (or 120%), 1.3 (or 130%), etc. The weight coefficient can be obtained based on historical text generation experience or through a limited number of experiments.
[0079] It should be noted that there may be multiple second texts. When there are multiple second texts, the text weight of each second text can also be calculated based on the text generation probability value of the text unit in each second text, and the text weight of the first text can be selected from the multiple text weights of the second texts as the basis for calculating the text weight of the first text. The text weight of the second text with the highest text weight and the weight coefficient are multiplied together to obtain the text weight of the first text.
[0080] In a possible embodiment, when the first text is first audio data collected by the user through an audio collection device of a terminal device and converted into the first text, the audio data may be analyzed and processed to obtain the speech speed and tone when the first text is input. The text weight of the first text is set according to the speech speed and tone.
[0081] Specifically, the speech rate can be calculated by VAD and syllable count, and the tone can be extracted from the audio data by Mel-Frequency Cepstral Coefficients (MFCC), Formant Analysis or Spectrogram Analysis. The type of tone can be divided into a firm tone or an unfirm tone. The firm tone can include a confident tone, a commanding tone, a decisive tone, etc., and the unfirm tone can include a hesitant tone, a confused tone, a nervous tone, etc.
[0082] When the speech speed in the audio data is in the normal speech speed range and the tone is a firm tone, it means that the user is very clear about what he needs to ask or what he needs to query, so the weight coefficient can be set relatively large. On the contrary, when the speech speed in the audio data is not in the normal speech speed range (for example, faster or slower) and the tone is an undetermined tone, it means that the user is not very clear about what he needs to ask or what he needs to query, so the weight coefficient can be set relatively small.
[0083] After obtaining the text weight of the above-mentioned first text, the fusion score of each first retrieval result in the first retrieval result set can be calculated according to the text weight of the above-mentioned first text, and the fusion score of each second retrieval result in the second retrieval result set can be calculated according to the text weight of the above-mentioned second text. According to the fusion score of each of the above-mentioned first retrieval results and the fusion score of each of the above-mentioned second retrieval results, the above-mentioned first retrieval results and the second retrieval results can be added one by one to the preset retrieval result empty set in descending order of the fusion score to obtain the above-mentioned target retrieval result set.
[0084] Optionally, in the step of determining the text weight of the second text based on the text generation probability values of the text units in the second text, the text generation probability values of the various text units in the second text can also be added to obtain the initial weight of the second text; and the initial weight of the second text can be normalized to obtain the text weight of the second text.
[0085] In an embodiment of the present invention, when the above-mentioned search text is the second text, the text generation probability values of each text unit in the second text can also be added to obtain the initial weight of the second text, and the above-mentioned initial weight can be normalized by any normalization method to obtain the text weight of the above-mentioned second text. The above-mentioned any normalization method can be Min-Max Normalization, Z-Score Normalization or Decimal ScalingNormalization, etc.
[0086] Optionally, in the step of normalizing the initial weights of the second text to obtain the text weights of the second texts, the initial weights of all the second texts can be added together to obtain the sum of the initial weights; and the initial weights of the second texts can be normalized based on the sum of the initial weights to obtain the text weights of the second texts.
[0087] In an embodiment of the present invention, when there are multiple second texts, the initial weights of all the second texts can be added together to obtain the sum of the initial weights corresponding to all the initial weights. The sum of the initial weights can be used as a divisor, the initial weight can be used as a dividend, and the calculated quotient can be used as the text weight of the second text.
[0088] More specifically, the text weight of the second text can be further described by the following formula:
[0089]
[0090] Among them, the above S represents the Sth second text, the above W′(S) represents the text weight of the Sth second text, the above W(S) represents the initial weight of the Sth second text, and W(S′) represents the above initial weight sum.
[0091] It should be noted that, when the number of the second text is only one, the second text can be directly normalized by using the Min-MaxNormalization, Z-Score Normalization, Decimal Scaling Normalization or other methods.
[0092] Optionally, the first search result set includes first search results sorted according to relevance to the first text, and the second search result set includes second search results sorted according to relevance to the second text. In the step of fusing the first search result set and the second search result set based on the text weight of the second text and the text weight of the first text to obtain the target result set, the fusion score of each first search result can be calculated based on the text weight of the first text and the rank of each first search result in the first search result set; the fusion score of each second search result can be calculated based on the text weight of the second text and the rank of each second search result in the second search result set; and the first search result set and the second search result set are fused based on the fusion score of each first search result and the fusion score of each second search result to obtain the target result set.
[0093] In an embodiment of the present invention, the above-mentioned first text is only one, and the above-mentioned second text can be one or more, so there is only one first search result set corresponding to the first text, and the second search result set corresponding to the second text can be one or more, and there may be search results with the same text content in different search result sets (the first search result set and the second search result set, or multiple second search result sets) (i.e., the first search result and the second search result with the same text content, or the second search results with the same text content in different second search result sets), and the order of the search results with the same text content in their corresponding different search result sets may be the same or different. When there are search results with the same text content, the fusion score of the same text content can be calculated based on the order of the search results with the same text content in the corresponding different search result sets, and the corresponding text weight.
[0094] Specifically, the above fusion score can be further explained by the following formula:
[0095]
[0096] Among them, the above Fscore represents the fusion score of the d-th search result (i.e., the first search result or the second search result) after the fusion of all search result sets, the above D represents all search result sets (including the first search result and the second search result set), S represents all search texts (including the first text and the second text), s represents the search text corresponding to the d-th search result (i.e., the first text or the second text), R represents a group of (1…|D|) relevance rankings (i.e., a relevance ranking represents the rank of each search result in a search result set, and a group of relevance rankings may include the rank of each search result in multiple search result sets), the above r∈R represents that the r-th search result set is one of all search result sets, r(d) represents the rank of the d-th search result in the r-th search result set, the above W′(s) represents the text weight of the s-th search text (i.e., the first text or the second text), and the above Expressed as a fusion constant. The above fusion constant can be set according to actual needs. Substituting the text weight of the above first text and the rank of the first search result into the above formula for calculation, the fusion score of the first search result can be obtained. Substituting the text weight of the above second text and the rank of the second search result into the above formula for calculation, the fusion score of the second search result can be obtained.
[0097] Specifically, the above fusion constants can be analyzed through the following examples and set accordingly.
[0098] Assume that all W′(s) are equal (i.e., the text weights of all second texts are equal), and the above Set it to a constant of 3. Then we can have the following formula:
[0099] A: For search results with the same text content, one second search result ranked first is equivalent to two second search results ranked fifth.
[0100] B: For search results with the same text content, one second search result ranked second is equivalent to two second search results ranked seventh.
[0101] Assume that all W′(s) are equal (i.e., the text weights of all second texts are equal), and the above Set it to a constant of 50. Then we can have the following formula:
[0102] C: For search results with the same text content, one second search result ranked first is equivalent to two second search results ranked fifty-second.
[0103] D: For search results with the same text content, one second search result ranked 2nd is equivalent to two second search results ranked 54th.
[0104] The above formula can be used to obtain the analytical results: when the constant When the value is larger, the more times it appears in the search result set, the higher the fusion score of the search results at the lower position will be. For example, if there is a constant with a large value and a small constant Based on large constants Calculates the combined score of two second search results with the same text content and ranked 50th, a constant with a decimal value Calculate the fusion score of two second search results with the same text content and ranked 50th, a large constant The calculated fusion score will be smaller than the constant value The calculated fusion score is higher, and the constant with a large value Constants with decimal values The greater the difference between them, the greater the difference in the calculated fusion score. Therefore, based on the above analysis results, the above constants can be set according to actual needs.
[0105] Furthermore, the above fusion points can also be Figure 3 An example diagram of a fusion score calculation method is shown for illustration.
[0106] Figure 3 In the above example, result set 1 is represented as the first search result set (it can be the first search result set or the second search result set), result set 2 is represented as the second search result set (i.e. the second search result set), and result set 3 is represented as the third search result set (i.e. the second search result set). There are four search results A, B, C, and D in all search result sets. Assume that the text weight of the search text corresponding to result set 1 is 0.4, the text weight of the search text corresponding to result set 2 is 0.3, and the text weight of the search text corresponding to result set 3 is 0.3, and the fusion constant is set to 3.
[0107] Then the fusion score of retrieval result A is
[0108] The fusion score of retrieval result B is
[0109] The fusion score of the retrieval result C is
[0110] The fusion score of the retrieval result D is
[0111] After obtaining the above fusion score, the above fusion score and the corresponding search results can be added to the above preset empty set to obtain the above target result set. It should be noted that in result sets 1 to 3, there are documents with the same text content, for example, there is a search result A. When adding, it is not necessary to repeatedly add the search result A multiple times. The search result A with the same text content can be added as a unit to the target result set.
[0112] In another embodiment, after obtaining the fusion score of each search result, it can be added one by one to the above preset empty set in descending order according to the fusion score to obtain a target result set with an arrangement order.
[0113] Optionally, in the step of providing the target result set and the first text to the text generation model so that the text generation model generates the target text, the retrieval results that meet the preset conditions can be extracted from the target result set based on the fusion score; the retrieval results that meet the preset conditions and the first text are added to a preset prompt template to obtain the target prompt text; and the target prompt text is provided to the text generation model so that the text generation model generates the target text.
[0114] In an embodiment of the present invention, the preset condition may be to extract search results with a fusion score higher than a preset fusion score threshold, or to extract a preset number of search results with top fusion scores, or to extract search results with the highest fusion scores. The embodiment of the present invention may preferably extract a preset number of search results with top fusion scores, so as to ensure that a moderate number of search results are used as the basis for the text generation model to reply to the first text, thereby improving the text generation accuracy of the text generation model.
[0115] The preset prompt template can be obtained based on historical text generation experience or a limited number of experiments. The target prompt text can be obtained by adding the search results and the first text that meet the preset conditions to the preset prompt template. The target prompt text is provided to the text generation model, and the text generation model can generate a corresponding answer based on the content given in the target prompt text as the target text.
[0116] In a possible embodiment, the above-mentioned preset prompt template may include prompt text, knowledge text (i.e., retrieval results that meet preset conditions) and the first text entered by the user. The above-mentioned prompt text may be "Please answer the following first text entered by the user, and use the following knowledge text provided as the basis for the answer."
[0117] like Figure 4 As shown, the embodiment of the present invention also provides a flowchart of another text generation method. Figure 4The following steps are included:
[0118] The first step is to add the user query (i.e., the first text) to a pre-made prompt (i.e., a preset prompt template) to obtain an extended prompt text, and provide the extended prompt text to a text generation model to generate a new query (i.e., the second text).
[0119] In the second step, the first text and the second text are determined as search texts, and the text weight of each search text (including the text weight of the first text and the text weight of the second text) is calculated according to the text generation probability value of each text unit in the second text.
[0120] The third step is to use the search text as a search condition to perform search processing in the search knowledge base, and recall the search results corresponding to each search text to obtain the result set corresponding to each search text (ie, the first search result set and the second search result set).
[0121] In the fourth to seventh steps, the fusion scores of the search results in the result set are calculated, and all the result sets are fused according to the fusion scores to obtain a single result set (ie, the target result set).
[0122] Step 8, subsequent process (i.e. extracting the search results that meet the preset conditions from the single result set, and generating the target text through the text generation model based on the search results that meet the preset conditions and the first text).
[0123] like Figure 5 As shown, the embodiment of the present invention also provides a flowchart of another text generation method. Figure 5 The following steps are included:
[0124] Step 1: For each query (i.e., second text) generated by the model, the text weight of each second text can be represented by the weighted sum of the text generation probability of each second text. The weight of the original query (i.e., first text) can be 110% of the highest weight in the second text.
[0125] Specifically, the weighted sum can be obtained by adding the text generation probability values of each text unit in the second text to obtain the initial weight of each second text, and calculating the initial weight sum of all initial weights based on the initial weight of each second text, and taking the quotient of the initial weight and the initial weight sum as the text weight of the second text.
[0126] The second step is to determine the first text and the second text as search texts, and use the search texts as search conditions to search and recall the search results corresponding to each search text in the search knowledge base.
[0127] In the third and fourth steps, according to the text similarity between the search text and its corresponding search results, the search results corresponding to each search text are sorted and added to the empty set one by one to obtain the search result set that each search text can correspond to.
[0128] Step 5: In step 6, all search result sets are merged according to the fusion rearrangement algorithm (ie, the formula used to calculate Fscore in the above embodiment) to obtain a single result set (ie, the target result set).
[0129] like Figure 6 As shown, the embodiment of the present invention also provides a text generation device, including:
[0130] An acquisition module 601 is used to acquire a search text, wherein the search text includes a first text and a second text, wherein the second text is obtained by expanding the first text through a text generation model;
[0131] A retrieval module 602, configured to perform retrieval processing on the search text to obtain a first search result set and a second search result set, wherein the first search result set corresponds to the first text and the second search result set corresponds to the second text;
[0132] A fusion module 603 is used to fuse the first search result set and the second search result set to obtain a target result set;
[0133] The generation module 604 is used to provide the target result set and the first text to the text generation model so that the text generation model generates the target text.
[0134] Optionally, the retrieval module 602 includes:
[0135] A first search submodule is used to perform a search process in a preset knowledge base using the search text as a search condition, and obtain a first search result corresponding to the first text, a correlation between the first search result and the corresponding first text, and a second search result corresponding to the second text, and a correlation between the second search result and the corresponding second text;
[0136] A first adding submodule, configured to add each first search result to a search result set corresponding to the first text in a preset order based on the relevance between each first search result and the corresponding first text, to obtain the first search result set;
[0137] The second adding submodule is used to add each second search result to the search result set corresponding to the second text in a preset order based on the relevance between each second search result and the corresponding second text, so as to obtain the second search result set.
[0138] Optionally, the second text includes at least one text unit, each of the text units corresponds to a text generation probability value, and the fusion module 603 includes:
[0139] A first determination submodule, configured to determine a text weight of the second text based on a text generation probability value of a text unit in the second text;
[0140] A second determination submodule, configured to determine a text weight of the first text based on a text weight of the second text and a preset weight coefficient;
[0141] The first fusion submodule is used to fuse the first search result set and the second search result set based on the text weight of the second text and the text weight of the first text to obtain a target result set.
[0142] Optionally, the first determining submodule includes:
[0143] A first calculation unit, configured to add text generation probability values of the respective text units in the second text to obtain an initial weight of the second text;
[0144] The normalization unit is used to normalize the initial weight of the second text to obtain the text weight of the second text.
[0145] Optionally, the normalization unit includes:
[0146] A first calculation subunit, used for adding the initial weights of all second texts to obtain an initial weight sum;
[0147] A normalization subunit is used to perform normalization processing on the initial weight of the second text based on the initial weight to obtain the text weight of the second text.
[0148] Optionally, the first search result set includes first search results sorted according to relevance to the first text, the second search result set includes second search results sorted according to relevance to the second text, and the first fusion submodule includes:
[0149] a second calculation unit, configured to calculate a fusion score of each of the first search results based on a text weight of the first text and a rank of each of the first search results in the first search result set;
[0150] a third calculation unit, configured to calculate a fusion score of each second search result based on a text weight of the second text and a rank of each second search result in the second search result set;
[0151] The first fusion unit is used to fuse the first retrieval result set and the second retrieval result set based on the fusion score of each first retrieval result and the fusion score of each second retrieval result to obtain the target result set.
[0152] Optionally, the generating module 604 includes:
[0153] A first extraction submodule, configured to extract search results that meet preset conditions from the target result set based on the fusion score;
[0154] A third adding submodule, used for adding the search result satisfying the preset condition and the first text to a preset prompt template to obtain a target prompt text;
[0155] The first generation submodule is used to provide the target prompt text to the text generation model so that the text generation model generates the target text.
[0156] like Figure 7 As shown, an embodiment of the present invention further provides an electronic device, characterized in that it includes a processor, and the processor can execute any one of the above-mentioned text generation methods.
[0157] Specifically, it includes a processor 701 and a memory 702, and a computer program for executing the text generation method which is stored in the memory 702 and can be run on the processor 701, wherein:
[0158] The processor 701 runs the computer program of the text generation method stored in the memory 702 to perform the following steps:
[0159] Acquire a search text, wherein the search text includes a first text and a second text, wherein the second text is obtained by expanding the first text through a text generation macro model;
[0160] Performing search processing on the search text to obtain a first search result set and a second search result set, wherein the first search result set corresponds to the first text and the second search result set corresponds to the second text;
[0161] Merging the first search result set and the second search result set to obtain a target result set;
[0162] The target result set and the first text are provided to the text generation model so that the text generation model generates the target text.
[0163] Optionally, the processor 701 performs search processing on the search text to obtain a first search result set and a second search result set, including:
[0164] Using the search text as a search condition to perform search processing in a preset knowledge base, obtaining a first search result corresponding to the first text, a correlation between the first search result and the corresponding first text, and a second search result corresponding to the second text, and a correlation between the second search result and the corresponding second text;
[0165] Based on the relevance between each first search result and the corresponding first text, adding each first search result to the search result set corresponding to the first text in a preset order to obtain the first search result set;
[0166] Based on the relevance between each second search result and the corresponding second text, each second search result is added to the search result set corresponding to the second text in a preset order to obtain the second search result set.
[0167] Optionally, the second text includes at least one text unit, each of the text units corresponds to a text generation probability value, and the processor 701 performs the fusion processing of the first search result set and the second search result set to obtain the target result set, including:
[0168] Determining a text weight of the second text based on a text generation probability value of a text unit in the second text;
[0169] Determining a text weight of the first text based on the text weight of the second text and a preset weight coefficient;
[0170] Based on the text weight of the second text and the text weight of the first text, the first search result set and the second search result set are fused to obtain a target result set.
[0171] Optionally, the determining of the text weight of the second text based on the text generation probability value of the text unit in the second text performed by the processor 701 includes:
[0172] Adding text generation probability values of the respective text units in the second text to obtain an initial weight of the second text;
[0173] The initial weight of the second text is normalized to obtain a text weight of the second text.
[0174] Optionally, the processor 701 performs normalization processing on the initial weight of the second text to obtain the text weight of the second text, including:
[0175] Add up the initial weights of all second texts to obtain the initial weight sum;
[0176] Based on the initial weight and normalizing the initial weight of the second text, a text weight of the second text is obtained.
[0177] Optionally, the first search result set includes first search results sorted according to relevance to the first text, and the second search result set includes second search results sorted according to relevance to the second text. The processor 701 performs fusion processing on the first search result set and the second search result set based on the text weight of the second text and the text weight of the first text to obtain a target result set, including:
[0178] Calculating a fusion score for each of the first search results based on a text weight of the first text and a rank of each of the first search results in the first search result set;
[0179] Calculating a fusion score of each second search result based on a text weight of the second text and a rank of each second search result in the second search result set;
[0180] Based on the fusion score of each of the first search results and the fusion score of each of the second search results, the first search result set and the second search result set are fused to obtain the target result set.
[0181] Optionally, the processor 701 performs the step of providing the target result set and the first text to the text generation model so that the text generation model generates the target text, including:
[0182] Based on the fusion score, extracting search results that meet preset conditions from the target result set;
[0183] Adding the search results satisfying the preset conditions and the first text to a preset prompt template to obtain a target prompt text;
[0184] The target prompt text is provided to the text generation model so that the text generation model generates the target text.
[0185] An embodiment of the present invention also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, each process of the text generation method or the application-side text generation method provided in the embodiment of the present invention is implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.
[0186] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program, and the above-mentioned computer program can be stored in a computer-readable storage medium, and when the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the above-mentioned computer-readable storage medium can be a disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM), etc.
[0187] The above disclosure is only the preferred embodiment of the present invention, which certainly cannot be used to limit the scope of the present invention. Therefore, equivalent changes made according to the claims of the present invention are still within the scope of the present invention.
Claims
1. A text generation method, characterized in that: The method comprises the following steps: Acquire a search text, wherein the search text includes a first text and a second text, wherein the second text is obtained by expanding the first text through a text generation macro model; Performing search processing on the search text to obtain a first search result set and a second search result set, wherein the first search result set corresponds to the first text and the second search result set corresponds to the second text; Merging the first search result set and the second search result set to obtain a target result set; The target result set and the first text are provided to the text generation model so that the text generation model generates the target text.
2. The text generation method according to claim 1, characterized in that: The retrieval processing of the retrieval text to obtain a first retrieval result set and a second retrieval result set includes: Using the search text as a search condition to perform a search process in a preset knowledge base, obtaining a first search result corresponding to the first text, a relevance between the first search result and the corresponding first text, a second search result corresponding to the second text, and a relevance between the second search result and the corresponding second text; Based on the relevance between each first search result and the corresponding first text, adding each first search result to the search result set corresponding to the first text in a preset order to obtain the first search result set; Based on the relevance between each second search result and the corresponding second text, each second search result is added to the search result set corresponding to the second text in a preset order to obtain the second search result set.
3. The text generation method according to claim 1, characterized in that: The second text includes at least one text unit, each of the text units corresponds to a text generation probability value, and the first search result set and the second search result set are fused to obtain a target result set, including: Determining a text weight of the second text based on a text generation probability value of a text unit in the second text; Determining a text weight of the first text based on the text weight of the second text and a preset weight coefficient; Based on the text weight of the second text and the text weight of the first text, the first search result set and the second search result set are fused to obtain a target result set.
4. The text generation method according to claim 3, characterized in that: The determining the text weight of the second text based on the text generation probability value of the text unit in the second text includes: Adding text generation probability values of the respective text units in the second text to obtain an initial weight of the second text; The initial weight of the second text is normalized to obtain a text weight of the second text.
5. The text generation method according to claim 4, characterized in that: The step of normalizing the initial weight of the second text to obtain the text weight of the second text includes: Add up the initial weights of all second texts to obtain the initial weight sum; Based on the initial weight and normalizing the initial weight of the second text, a text weight of the second text is obtained.
6. The text generation method according to claim 3, characterized in that: The first search result set includes first search results sorted according to relevance to the first text, the second search result set includes second search results sorted according to relevance to the second text, and the first search result set and the second search result set are fused based on the text weight of the second text and the text weight of the first text to obtain a target result set, including: Calculating a fusion score for each of the first search results based on a text weight of the first text and a rank of each of the first search results in the first search result set; Calculating a fusion score of each second search result based on a text weight of the second text and a rank of each second search result in the second search result set; Based on the fusion score of each of the first search results and the fusion score of each of the second search results, the first search result set and the second search result set are fused to obtain the target result set.
7. The text generation method according to claim 6, characterized in that: Providing the target result set and the first text to the text generation model so that the text generation model generates the target text includes: Based on the fusion score, extracting search results that meet preset conditions from the target result set; Adding the search results satisfying the preset conditions and the first text to a preset prompt template to obtain a target prompt text; The target prompt text is provided to the text generation model so that the text generation model generates the target text.
8. A text generation device, characterized in that: The text generating device comprises: An acquisition module, used for acquiring a search text, wherein the search text includes a first text and a second text, wherein the second text is obtained by expanding the first text through a text generation macro model; A retrieval module, configured to perform retrieval processing on the retrieval text to obtain a first retrieval result set and a second retrieval result set, wherein the first retrieval result set corresponds to the first text and the second retrieval result set corresponds to the second text; A fusion module, used for fusing the first search result set and the second search result set to obtain a target result set; A generation module is used to provide the target result set and the first text to the text generation model so that the text generation model generates the target text.
9. An electronic device, characterized in that: include: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps in the text generation method according to any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in the text generation method according to any one of claims 1 to 7 are implemented.
