Text generation method and device, electronic equipment and storage medium

By judging whether there is a target text unit in the first prediction sentence in the text generation method to decide whether to perform loop generation processing, the problem of low accuracy of long text generation in the prior art is solved and higher accuracy of text generation is achieved.

CN118734800APending Publication Date: 2024-10-01SHENZHEN INTELLIFUSION TECHNOLOGIES CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202410718155.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-04
Publication Date
2024-10-01

AI Technical Summary

Technical Problem

Existing text generation methods have low accuracy when generating long texts and cannot effectively adapt to the needs of long texts.

Method used

Determine whether to perform text loop generation processing by judging whether the target text unit exists in the first prediction sentence. If it exists, perform loop generation to obtain a higher probability second prediction sentence. If it does not exist, directly splice the first prediction sentence until Generate final text generation results that meet preset conditions.

Benefits of technology

It improves the accuracy of text generation, can better adapt to the generation needs of long text, and ensures the accuracy of the final generated results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118734800A_ABST
    Figure CN118734800A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a text generation method, which comprises the following steps of: inputting a target prompt text into a large text generation model to obtain at least one first prediction statement; for each first prediction statement, when it is detected that a target text unit exists in the first prediction statement, performing text loop generation processing based on the first prediction statement to obtain a second prediction statement, and splicing the second prediction statement into a text generation result; when it is detected that the target text unit does not exist in the first prediction statement, splicing the first prediction statement into a text generation result; and when the terminator exists in the spliced text generation result, determining the spliced text generation result as a final text generation result. Whether the target text unit exists in the first prediction statement or not is used as a condition for judging whether active text loop generation processing needs to be carried out or not, so that the generation requirement of a long text can be well met, and a text generation result with higher accuracy is obtained after the text is generated.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of text processing, and in particular to a text generation method, device, electronic device and storage medium. Background Art

[0002] As the application of large models becomes more and more popular, their use in the field of text generation is also increasing. However, when large models generate long texts, they often have the problem of generating erroneous content (commonly known as hallucination). Existing methods add a retrieval step to the text generation process to enhance the accuracy of the text. However, these methods either only perform a retrieval once before generation or perform retrieval at fixed intervals during the generation process. They cannot adapt well to the needs of long text generation, and the content accuracy of the long text generated in the end is still insufficient. Therefore, how to provide a text generation method that solves the low accuracy of existing text generation when generating long texts has become an urgent problem to be solved. Summary of the invention

[0003] The embodiment of the present invention provides a text generation method, which aims to solve the problem of low accuracy of existing text generation when generating long text. By using whether the target text unit exists in the first prediction sentence as a condition for judging whether it is necessary to actively perform text loop generation processing, when it is not necessary to enter the text loop generation processing, the first prediction sentence can be directly spliced ​​into the text generation result, and when it is necessary, the text loop generation processing can be performed to obtain a second prediction sentence with a higher generation probability, which can well meet the generation needs of long texts, so as to obtain a final text generation result with higher accuracy after text generation.

[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] Inputting the target prompt text into the text generation model to obtain at least one first prediction sentence;

[0006] For each of the first prediction sentences, when it is detected that the target text unit exists in the first prediction sentence, a text loop generation process is performed based on the first prediction sentence to obtain a second prediction sentence, and the second prediction sentence is spliced ​​into the text generation result, and the second prediction sentence satisfies a preset condition, wherein the preset condition is that the second prediction sentence does not include the target text unit and / or the number of loops reaches a preset number, and the generation probability of the target text unit is less than a generation probability threshold;

[0007] When it is detected that the first predicted sentence does not have a target text unit, splicing the first predicted sentence into the text generation result;

[0008] When there is a terminator in the concatenated text generation result, the concatenated text generation result is determined as a final text generation result, wherein the concatenated text generation result includes the second predicted sentence and the first predicted sentence without the target text unit.

[0009] Optionally, performing text loop generation processing based on the first prediction sentence to obtain a second prediction sentence includes:

[0010] Preprocessing the first prediction sentence to obtain an assembly prompt text;

[0011] Inputting the assembly prompt text into the text generation model to generate text, and obtaining a third prediction sentence;

[0012] In a case where the third prediction statement does not satisfy the preset condition, the third prediction statement is determined as the first prediction statement; and the above steps are repeated until, in a case where the third prediction statement satisfies the preset condition, the third prediction statement is determined as the second prediction statement.

[0013] Optionally, preprocessing the first prediction sentence to obtain an assembly prompt text includes:

[0014] Performing text preprocessing on the first predicted sentence to obtain a sentence to be retrieved;

[0015] Performing a search process on the sentence to be searched in the knowledge base to obtain the knowledge text corresponding to the sentence to be searched;

[0016] The sentence to be searched and the knowledge text are assembled to obtain an assembled prompt text.

[0017] Optionally, performing text preprocessing on the first predicted sentence to obtain a sentence to be retrieved includes:

[0018] Determining a text position of the target text unit in the first predicted sentence;

[0019] Based on the text position, the target text unit in the first predicted sentence is updated to a preset marker to obtain the sentence to be retrieved.

[0020] Optionally, the assembling of the sentence to be searched and the knowledge text to obtain an assembled prompt text includes:

[0021] Get the preset prompt template;

[0022] The sentence to be searched and the knowledge text are added to the preset prompt template to obtain the assembled prompt text.

[0023] Optionally, the knowledge base is a knowledge vector base, and the step of performing a search process on the sentence to be searched in the knowledge base to obtain the knowledge text corresponding to the sentence to be searched includes:

[0024] Converting the sentence to be retrieved into a vector to be retrieved;

[0025] Performing a search process on the vector to be searched in the knowledge vector library to obtain a knowledge vector related to the vector to be searched;

[0026] Sorting the knowledge vectors based on the text relevance between the vector to be retrieved and the knowledge vectors to obtain a knowledge vector sorting table;

[0027] The knowledge vectors in the knowledge vector ranking table whose text relevance is higher than a preset relevance threshold are converted into knowledge texts corresponding to the sentence to be retrieved.

[0028] Optionally, before inputting the target prompt text into the text generation model to obtain at least one first prediction sentence, the method further includes:

[0029] Get the text input content entered by the user;

[0030] Performing a sensitive content check on the text input content based on a preset verification model to obtain a first content verification result;

[0031] If the first content verification result is that there is no sensitive content, searching the text input content in the knowledge base to obtain the knowledge text corresponding to the text input content;

[0032] Assembling the knowledge text corresponding to the text input content and the text input content to obtain an assembled text;

[0033] Performing word count verification processing on the assembled text to obtain a word count verification result of the assembled text;

[0034] If the word count check result is that the word count check passes, the assembled text is used as the target prompt text.

[0035] In a second aspect, an embodiment of the present invention further provides a text generation device, the text generation device comprising:

[0036] An input module, used for inputting a target prompt text into a text generation model to obtain at least one first prediction sentence;

[0037] a loop module, configured to, for each of the first prediction sentences, when detecting that a target text unit exists in the first prediction sentence, perform text loop generation processing based on the first prediction sentence to obtain a second prediction sentence, and splice the second prediction sentence into the text generation result, wherein the second prediction sentence satisfies a preset condition, wherein the preset condition is that the second prediction sentence does not include the target text unit and / or the number of loops reaches a preset number, and the generation probability of the target text unit is less than a generation probability threshold;

[0038] a splicing module, configured to splice the first prediction sentence into the text generation result when it is detected that the first prediction sentence does not have a target text unit;

[0039] The determination module is used to determine the concatenated text generation result as the final text generation result when there is a terminator in the concatenated text generation result, wherein the concatenated text generation result includes the second prediction sentence and the first prediction sentence without the target text unit.

[0040] 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.

[0041] 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.

[0042] In an embodiment of the present invention, a target prompt text is input into a large text generation model to obtain at least one first prediction sentence; for each of the first prediction sentences, when it is detected that a target text unit exists in the first prediction sentence, a text loop generation process is performed based on the first prediction sentence to obtain a second prediction sentence, and the second prediction sentence is spliced ​​into a text generation result, wherein the second prediction sentence satisfies a preset condition, wherein the preset condition is that the second prediction sentence does not include a target text unit and / or the number of loops reaches a preset number, and the generation probability of the target text unit is less than a generation probability threshold; when it is detected that the first prediction sentence does not have a target text unit, the first prediction sentence is spliced ​​into the text generation result; when there is a terminator in the spliced ​​text generation result, the spliced ​​text generation result is determined as a final text generation result, and the spliced ​​text generation result includes the second prediction sentence and the first prediction sentence without the target text unit. By using whether the target text unit exists in the first prediction sentence as a condition for judging whether it is necessary to actively perform text loop generation processing, when it is not necessary to enter the text loop generation processing, the first prediction sentence can be directly spliced ​​into the text generation result. When necessary, the text loop generation processing can be performed to obtain a second prediction sentence with a higher generation probability. This can well adapt to the generation needs of long texts, thereby obtaining a final text generation result with higher accuracy after text generation. BRIEF DESCRIPTION OF THE DRAWINGS

[0043] 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.

[0044] Figure 1 is a flow chart of a text generation method provided by an embodiment of the present invention;

[0045] Figure 2 is a flow chart of a second text generation method provided by an embodiment of the present invention;

[0046] Figure 3 is a flow chart of a third text generation method provided by an embodiment of the present invention;

[0047] Figure 4 is a processing schematic diagram of text preprocessing provided by an embodiment of the present invention;

[0048] Figure 5 is a schematic diagram of a preset prompt template provided by an embodiment of the present invention;

[0049] Figure 6 is a flowchart of a fourth text generation method provided by an embodiment of the present invention;

[0050] Figure 7 is a structural schematic diagram of a text generation device provided in an embodiment of the present invention;

[0051] Figure 8 It is a structural schematic diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0052] 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.

[0053] like Figure 1 As shown, Figure 1 : is a flowchart of a text generation method provided by an embodiment of the present invention, comprising:

[0054] 101. Input the target prompt text into a text generation model to obtain at least one first prediction sentence.

[0055] In an embodiment of the present invention, the above-mentioned text generation method can be applied to a text processing platform. The above-mentioned text processing 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, data transmission, and data storage. The above-mentioned text processing platform can be equipped with a large text generation model, or the above-mentioned text processing platform can have an application interface, through which data is transmitted with any large text generation model capable of performing text generation processing. After receiving the text input content input from the user end, the above-mentioned text processing platform can perform corresponding text processing according to the above-mentioned text input content to obtain the final text generation result corresponding to the above-mentioned text input content.

[0056] The target prompt text may be obtained by adding the text input content input by the user to a preset prompt template, or the text input content input by the user may be directly used as the target prompt text. The first predicted sentence may be a predicted sentence obtained by the user inputting the target prompt text into a text generation model and then the text generation model performs text generation processing.

[0057] The above-mentioned text generation result includes at least one predicted sentence, each predicted sentence includes at least one text unit, each text unit has a corresponding generation probability, and the above-mentioned text unit can be the smallest single unit of text, for example, it can be a word, letter, punctuation mark, number, space, character, word and other units.

[0058] It should be noted that after the target prompt text is input into the text generation model, the text generation model performs text generation processing according to the target prompt text and outputs a corresponding text generation result. The text generation result may include any number of first prediction sentences (i.e., at least one first prediction sentence).

[0059] 102. For each first prediction sentence, when it is detected that a target text unit exists in the first prediction sentence, a text loop generation process is performed based on the first prediction sentence to obtain a second prediction sentence, and the second prediction sentence is spliced ​​into the text generation result.

[0060] In an embodiment of the present invention, the second prediction statement satisfies a preset condition, which is that the second prediction statement does not include the target text unit and / or the number of loops reaches a preset number, and the generation probability of the target text unit is less than a generation probability threshold.

[0061] The above-mentioned generation probability threshold can be set according to the type of the above-mentioned target prompt text. The type of the above-mentioned target prompt text may be an answer query type or a spiritual enlightenment type, etc. If the type of the above-mentioned target prompt text is an answer query type, since the answer query type often has a definite answer, the above-mentioned preset text probability threshold can be relatively set to be relatively high. If the type of the above-mentioned target prompt text is a spiritual enlightenment type, since the spiritual enlightenment type often requires confession and obtaining corresponding enlightenment, and there is no definite fixed answer, the above-mentioned preset text probability threshold can be relatively set to be relatively low.

[0062] The above-mentioned text loop generation processing may include preprocessing and text generation processing. The above-mentioned preprocessing may include clearing processing, retrieval processing and assembly processing. The above-mentioned clearing processing may be to clear the target text unit in the above-mentioned first prediction sentence. The above-mentioned retrieval processing may be to use the first prediction sentence with the target text unit cleared as a retrieval condition to search in the knowledge base. The above-mentioned assembly processing may be to assemble the above-mentioned first prediction sentence and the knowledge text retrieved from the above-mentioned knowledge base.

[0063] When it is detected that the above-mentioned target text unit exists in the first prediction sentence, the above-mentioned first prediction sentence can be preprocessed, and the preprocessed first prediction sentence can be input into the above-mentioned text generation model to obtain a third prediction sentence. When the target unit does not exist in the third prediction sentence, the third prediction sentence can be determined as the second prediction sentence, and the second prediction sentence can be spliced ​​into the text generation result. When the target unit exists in the third prediction sentence, the third prediction sentence can be used as the first prediction sentence to re-perform the above-mentioned preprocessing and text generation processing, until the number of times the above-mentioned preprocessing and text generation processing are re-performed (i.e., the number of loops) meets the preset number, the above-mentioned text loop generation processing is stopped, and the third prediction sentence obtained in the last loop is determined as the second prediction sentence.

[0064] Specifically, the above text loop generation process can be performed as follows: Figure 2 The flowchart of the second text generation method shown is used to illustrate.

[0065] Figure 2 The first step is included: after the large model (i.e. the text generation large model) receives the prompt (i.e. the target prompt text) input from the user, it generates a sentence as a predicted sentence (i.e. the first predicted sentence) according to the target prompt text.

[0066] Step 2: Determine whether the first predicted sentence contains a low-probability token (i.e., the target text unit).

[0067] Step 3: If there is a low-probability token in the first prediction sentence, the low-probability token in the first prediction sentence is cleared to obtain the preprocessed first prediction sentence (ie, the sentence to be retrieved).

[0068] Step 4: Use the first predicted sentence (i.e., the sentence to be retrieved) after the above preprocessing as a parameter to search the above knowledge base.

[0069] Step 5: Recall the documents (i.e., knowledge text) retrieved in step 4.

[0070] Step 6: Assemble the knowledge text with the first prediction sentence (i.e., the sentence to be retrieved) after the above preprocessing, and re-input it into the large model (i.e., the text generation large model) for text generation processing to obtain the second prediction sentence.

[0071] Step 7: If there is no low-probability token in the first prediction sentence, directly splice the first prediction sentence into the text generation result; if there is no low-probability token in the second prediction sentence obtained in the sixth step, splice the second prediction sentence into the text generation result; if there is still a low-probability token in the second prediction sentence, repeat the second to sixth steps until there is no low-probability token in the second prediction sentence generated by the large model or the number of loops reaches the preset number of loops, and then splice the second prediction sentence obtained in the last loop into the text generation result.

[0072] Step 8: Determine whether to stop generating text based on whether there is a terminator in the generated text.

[0073] Step 9: If there is no terminator in the text generation result, continue the text generation process.

[0074] Step 10: If there is a terminator in the text generation result, stop text generation and obtain the final text generation result.

[0075] It can be seen that in the figure, the third to sixth steps are the steps that need to be executed for the above-mentioned text loop generation processing, the second step is a judgment step for determining whether it is necessary to start the above-mentioned loop generation unit, and the seventh step is a judgment step for determining whether it is necessary to stop the above-mentioned loop generation unit. It should be noted that the above-mentioned sixth step can be a loop generation large model calling the application interface of the above-mentioned large model to re-input the assembly prompt text into the above-mentioned large model.

[0076] 103. When it is detected that the first predicted sentence does not have a target text unit, the first predicted sentence is spliced ​​into the text generation result.

[0077] In the embodiment of the present invention, the above text generation result can be understood as a result of an intermediate process. When the first prediction sentence and the second prediction sentence are not spliced ​​to the above text generation result (i.e., the initial state of the text generation result), the above text generation result is empty. If it is understood in terms of the concept of generation steps, then in the nth generation step, the prediction sentence obtained in the nth generation step needs to be spliced ​​with the text generation result obtained in the n-1th generation step to obtain the text generation result of the nth generation step. Alternatively, the text generation result of the nth generation step can also be understood as the splicing of the prediction sentence obtained in the 1st generation step to the prediction sentence obtained in the nth generation step. Each of the above generation steps can obtain a first prediction sentence without a target text unit or a second prediction sentence that meets the above preset conditions.

[0078] 104. When there is a terminator in the concatenated text generation result, the concatenated text generation result is determined as the final text generation result.

[0079] The text generation result after splicing includes the second predicted sentence and the first predicted sentence without the target text unit. The above terminator can be obtained by the output of the above text generation large model. When the above text generation large model inputs the last predicted sentence according to the corresponding prompt text, the corresponding terminator will be added to the above predicted sentence. When the above last predicted sentence is spliced ​​into the text generation result, the above terminator will exist in the spliced ​​text generation result. At this time, the above spliced ​​text generation result can be determined as the above final text generation result. The above terminator can be a period, an asterisk, a tilde, etc., which can be set according to actual needs. The above splicing can be to splice the head and tail strings of different prediction sentences.

[0080] More specifically, in the above process, the text generation result is obtained, and the process of finally obtaining the above final text generation result can be performed as follows: Figure 3 The flowchart of the third text generation method is shown in FIG.

[0081] Figure 3 In , prompt (i.e., the text input content entered by the user) is input into the knowledge base for retrieval processing, and document 1 (i.e., the first knowledge text), document 2 (i.e., the second knowledge text), and document 3 (i.e., the third knowledge text) are obtained. According to document 1, document 2, document 3 and the text input content entered by the user (i.e., introducing Labor Day), the first first prediction sentence (i.e., prediction sentence 1) "Labor Day is May 1st of each year. This day is a holiday to commemorate the working people all over the world" is obtained. The first first prediction sentence does not contain a text unit (i.e., the target text unit) whose generation probability is less than the generation probability threshold. Therefore, the first first prediction sentence can be used as the splicable prediction sentence (i.e., result 1) obtained in the first generation step and spliced ​​into the text generation result. Since it is the first first prediction sentence, other prediction sentences are not spliced ​​into the text generation result in the first prediction sentence, so the text generation result is empty, so the above-mentioned first first prediction sentence can be directly used as the above-mentioned text generation result.

[0082] It can be understood that the retrieval processing and corresponding text generation processing performed when the above-mentioned text input content is input into the above-mentioned large model can be understood as passive processing, that is, a retrieval processing is required before the text loop generation processing is performed, and after obtaining at least one first prediction sentence, whether the above-mentioned first prediction sentence can be spliced ​​into the text generation result depends on whether the above-mentioned first prediction sentence exists in the above-mentioned first prediction sentence. If it exists, it is necessary to enter the above-mentioned text loop generation processing. If not, the above-mentioned first prediction sentence can be directly spliced ​​into the text generation result.

[0083] According to the text input content of Document 1, Document 2, Document 3 and the user, it is obtained that the second first prediction sentence (i.e., prediction sentence 2) contains text units (i.e., target text units, "Birmingham, United Kingdom" and "Freedom") whose text generation probability values ​​are less than the text generation probability threshold. Therefore, the second first prediction sentence can be preprocessed to obtain an assembled prompt text; the assembled prompt text is input into the text generation model for text generation to obtain a third prediction sentence, until there is no text unit (i.e., target text unit) whose text generation probability value is less than the text generation probability threshold in the third prediction sentence, or when the number of loops reaches a preset number, the loop is stopped, and the third prediction sentence obtained in the last loop or the third prediction sentence without the target text unit is used as the second prediction sentence (i.e., result 2, the second prediction sentence that meets the above preset conditions), and the above result 2 is spliced ​​into the text generation result (i.e., spliced ​​with result 1).

[0084] Figure 3 The third first prediction statement is also included. The processing steps of the third first prediction statement are consistent with those of the first first prediction statement or the second first prediction statement and have the same effect. To avoid repetition and redundancy, they will not be repeated here.

[0085] After obtaining the third second prediction sentence that meets the preset conditions, there is a terminator in the third second prediction sentence that meets the preset conditions. After splicing the third second prediction sentence that meets the preset conditions into the text generation result, there is a terminator in the text generation result. At this time, the spliced ​​text generation result can be used as the final text generation result.

[0086] The final text generated by the above can be "Labor Day is May 1st of each year. This day is a holiday to commemorate working people all over the world. It originated from the labor movement in Chicago, the United States in 1886, when workers went on strike and demonstrated for an eight-hour workday. To commemorate this movement, the Second International decided in July 1889 to designate May 1st of each year as International Labor Day."

[0087] In an embodiment of the present invention, a target prompt text is input into a large text generation model to obtain at least one first prediction sentence; for each of the first prediction sentences, when it is detected that a target text unit exists in the first prediction sentence, a text loop generation process is performed based on the first prediction sentence to obtain a second prediction sentence, and the second prediction sentence is spliced ​​into a text generation result, wherein the second prediction sentence satisfies a preset condition, wherein the preset condition is that the second prediction sentence does not include a target text unit and / or the number of loops reaches a preset number, and the generation probability of the target text unit is less than a generation probability threshold; when it is detected that the first prediction sentence does not have a target text unit, the first prediction sentence is spliced ​​into the text generation result; when there is a terminator in the spliced ​​text generation result, the spliced ​​text generation result is determined as a final text generation result, and the spliced ​​text generation result includes the second prediction sentence and the first prediction sentence without the target text unit. By using whether the target text unit exists in the first prediction sentence as a condition for judging whether it is necessary to actively perform text loop generation processing, when it is not necessary to enter the text loop generation processing, the first prediction sentence can be directly spliced ​​into the text generation result. When necessary, the text loop generation processing can be performed to obtain a second prediction sentence with a higher generation probability. This can well adapt to the generation needs of long texts, thereby obtaining a final text generation result with higher accuracy after text generation.

[0088] It is understandable that in the specific implementation of this application, related data such as knowledge texts, text input content entered by users, etc., when the embodiments in this application are applied to specific products or technologies, user permission or consent is required, and the collection, use and processing of relevant data, the construction, use and processing of large models and knowledge bases need to comply with relevant laws, regulations and standards of relevant countries and regions.

[0089] Optionally, in the step of performing text loop generation processing based on the first prediction sentence to obtain the second prediction sentence, the first prediction sentence can also be preprocessed to obtain an assembly prompt text; the assembly prompt text is input into the text generation model for text generation to obtain a third prediction sentence; if the third prediction sentence does not meet the preset conditions, the third prediction sentence is determined as the first prediction sentence; the above steps are repeated until the third prediction sentence meets the preset conditions, and the third prediction sentence is determined as the second prediction sentence.

[0090] In an embodiment of the present invention, the above-mentioned preprocessing may include text preprocessing, retrieval processing and assembly processing. The above-mentioned text preprocessing may be to update the marker to the source of the target text unit in the above-mentioned first predicted sentence to obtain the sentence to be retrieved, to perform retrieval processing in the knowledge base using the above-mentioned sentence to be retrieved as a retrieval condition to obtain the knowledge text corresponding to the sentence to be retrieved, and to assemble the above-mentioned sentence to be retrieved and the above-mentioned knowledge text to obtain the above-mentioned assembled prompt text. The above-mentioned knowledge base may be a vector library storing many document texts.

[0091] Specifically, when the third prediction statement does not meet the preset conditions, the third prediction statement can be used as the first prediction statement, and the preprocessing can be performed again to obtain the assembly prompt text. The assembly prompt text can be input into the text generation model again for text generation, until the third prediction statement obtained by the text generation meets the preset conditions, and the third prediction statement is determined as the second prediction statement.

[0092] It can be understood that one of the above-mentioned preset conditions is that the above-mentioned target text unit does not exist in the third prediction sentence. If the target text unit does not exist in the third prediction sentence, the third prediction sentence is determined as the second prediction sentence, and the text generation result obtained by splicing is more accurate. One of the above-mentioned preset conditions is that when the number of loops reaches the preset number, the third prediction sentence obtained in the last loop is used as the second prediction sentence and spliced. This is to avoid too many loops, resulting in the efficiency of text generation being unable to meet actual usage requirements. Therefore, when the number of loops reaches the preset number, it is possible to ignore whether the target text unit exists in the third prediction sentence and determine the third prediction sentence obtained in the last loop as the second prediction sentence. Alternatively, when the third prediction sentence satisfies the above-mentioned two prediction conditions at the same time, the third prediction sentence can be determined as the second prediction sentence.

[0093] Optionally, in the step of preprocessing the first predicted sentence to obtain an assembled prompt text, the first predicted sentence can also be text preprocessed to obtain a sentence to be retrieved; the sentence to be retrieved is retrieved in the knowledge base to obtain a knowledge text corresponding to the sentence to be retrieved; the sentence to be retrieved and the knowledge text are assembled to obtain an assembled prompt text.

[0094] In an embodiment of the present invention, the text preprocessing may be to update the marker to the target text unit in the first predicted sentence. Specifically, the target unit in the first predicted sentence may be deleted and then the marker is added to the text position where the target unit is located.

[0095] The above-mentioned retrieval processing can be performed based on the text similarity between texts. The above-mentioned text similarity can be obtained by a cosine similarity calculation method or a Euclidean distance calculation method. The above-mentioned first prediction sentence is used as a retrieval condition to perform a search in the above-mentioned knowledge base. The sentence with the highest text similarity can be used as the knowledge text corresponding to the above-mentioned first prediction sentence, or the above-mentioned knowledge text can be sorted according to the above-mentioned text similarity, and the knowledge text with a higher sorting can be used as the knowledge text corresponding to the above-mentioned first prediction sentence.

[0096] The above-mentioned assembly processing can be constructed by any kind of programming language to obtain an assembly project, and the above-mentioned assembly processing can be implemented through the above-mentioned assembly project to obtain the above-mentioned assembly prompt text, and the above-mentioned assembly prompt text can be input into the above-mentioned text generation model for text generation processing to obtain the above-mentioned second prediction sentence.

[0097] Optionally, in the step of performing text preprocessing on the first predicted sentence or the second predicted sentence to obtain the sentence to be retrieved, the text position of the target text unit can also be determined in the first predicted sentence; based on the text position, the target text unit in the first predicted sentence is updated to a preset marker to obtain the sentence to be retrieved.

[0098] In an embodiment of the present invention, the above-mentioned text preprocessing can determine the text position of the target text unit in the first predicted sentence, and the above-mentioned update can be understood as including two steps of deletion and insertion, that is, deleting the text unit in the above-mentioned predicted sentence whose text generation probability value is lower than the above-mentioned text generation probability threshold, and inserting the marker into the text position of the above-mentioned predicted sentence according to the text position of the above-mentioned target text unit to obtain the above-mentioned sentence to be retrieved. The above-mentioned marker can be any symbol that can mark the text position but does not affect the semantics of the original text, for example, it can be any bracket, "()", "{}" "[]" or it can also be any symbol that can be used for marking, such as double quotes, single quotes, tilde, pound sign, etc.

[0099] Specifically, the above text preprocessing can be illustrated by a processing diagram of text preprocessing as shown in FIG4 . Figure 4 The "low probability token" can be understood as the target text unit mentioned above, among which "it originated from the labor movement in Birmingham, England in 1886, when workers went on strike and demonstrated for freedom" is the first predicted sentence mentioned above, and "it originated from the labor movement in {} in 1886, when workers went on strike and demonstrated for {}" is the sentence to be searched. The dark part in the figure (i.e. Birmingham, England and freedom) is the target text unit mentioned above. After removing the above "Birmingham, England" and "freedom" and inserting the marker {} at the position where the above "Birmingham, England" and "freedom" are in the original text, the above sentence to be searched is obtained.

[0100] It is understandable that after performing the above preprocessing, when performing the above retrieval processing, knowledge texts with higher text similarity can be retrieved, thereby improving the retrieval accuracy of the above retrieval processing.

[0101] Optionally, in the step of assembling the sentence to be retrieved and the knowledge text to obtain the assembled prompt text, a preset prompt template can also be obtained; the sentence to be retrieved and the knowledge text are added to the preset prompt template to obtain the assembled prompt text.

[0102] In the embodiment of the present invention, the preset prompt template can be Figure 5 The schematic diagram of the preset prompt template shown is used for explanation. Figure 5 The instruction text "Please answer the user's question based on the given reference content. The reference content is as follows:" The above "Document 1" can be the first knowledge text or can also be the string concatenation of the first knowledge text and the first sentence to be searched, the above "Document 2" can be the second knowledge text or can also be the string concatenation of the second knowledge text and the second sentence to be searched, and the above "Document 3" can be the third knowledge text or can also be the string concatenation of the third knowledge text and the third sentence to be searched. The above "User input is:..." can be the text input content entered by the user (i.e. the question entered by the user) or can also be the above target prompt text. The above sentence to be searched and the corresponding knowledge text are added to the above preset prompt template to obtain the above assembled prompt text. It should be noted that the above sentence to be searched corresponds to at least one knowledge text. If there are multiple sentences to be searched and multiple, each sentence to be searched corresponds to at least one knowledge text retrieved according to the above sentence to be searched. After the above sentence to be searched is concatenated with at least one of the above knowledge texts, they are filled into the above prompt template to obtain the above assembled prompt text.

[0103] In a possible embodiment, an assembly project can also be constructed through a programming language, and the above-mentioned prediction statement and knowledge text can be assembled through the above-mentioned assembly project. The above-mentioned programming language can be a Java programming language or a Python programming language. The above-mentioned assembly project is constructed based on the above-mentioned Java programming language or the above-mentioned Python programming language. The above-mentioned assembly project is used for text assembly processing, and the above-mentioned first prediction statement and the knowledge text corresponding to the above-mentioned first prediction statement are simultaneously input into the above-mentioned assembly project for assembly processing, and the above-mentioned assembly prompt text is output by the above-mentioned assembly project.

[0104] Optionally, in the step of performing a search process on the search sentence in the knowledge base to obtain the knowledge text corresponding to the search sentence, the search sentence can also be converted into a search vector; the search vector is searched in the knowledge vector library to obtain a knowledge vector related to the search vector; each knowledge vector is sorted based on the text relevance between the search vector and the knowledge vector to obtain a knowledge vector sorting table; and the knowledge vector in the knowledge vector sorting table whose text relevance is higher than a preset relevance threshold is converted into the knowledge text corresponding to the search sentence.

[0105] In an embodiment of the present invention, the above-mentioned text relevance can be understood as the text relevance between the above-mentioned knowledge vector and the above-mentioned vector to be retrieved. The above-mentioned sentence to be retrieved can be converted into the above-mentioned vector to be retrieved through word embeddings (Word Embeddings), bag of words (Bag of Words, BoW) or TF-IDF (Term Frequency-Inverse Document Frequency) and the like. The above-mentioned knowledge vector library can be any vector database such as FAISS library, Annoy library, Milvus library, etc.

[0106] The above-mentioned text relevance can be understood as the above-mentioned text similarity. In addition to the cosine similarity calculation method and the Euclidean distance calculation method, the above-mentioned text similarity can also be calculated by the Manhattan distance, Jaccard similarity and Pearson Correlation Coefficient and other methods to obtain the text relevance between the above-mentioned vector to be retrieved and the knowledge vector. And based on the above-mentioned text relevance, the various knowledge vectors are sorted in a descending order of text relevance to obtain the above-mentioned knowledge vector sorting table, and the knowledge vectors in the above-mentioned knowledge vector sorting table whose text relevance is higher than the preset relevance threshold are converted into the knowledge text corresponding to the sentence to be retrieved. The above-mentioned preset relevance threshold can be set according to the historical text generation experience.

[0107] Optionally, before inputting the target prompt text into the text generation model to obtain at least one first prediction sentence, the text input content input by the user can also be obtained; the text input content is checked for sensitive content based on a preset verification model to obtain a first content verification result; if the first content verification result is that there is no sensitive content, the text input content is searched in the knowledge base to obtain the knowledge text corresponding to the text input content; the knowledge text corresponding to the text input content and the text input content are assembled to obtain an assembled text; the assembled text is checked for word count to obtain a word count verification result of the assembled text; if the word count verification result is that the word count verification passes, the assembled text is used as the target prompt text.

[0108] In an embodiment of the present invention, the text input content input by the above-mentioned user may be the content of the user's question, that is, when the user needs to generate text, the content of the above-mentioned text generation large model input. The above-mentioned preset verification model may be a BERT verification model, a DistilBERT verification model, a TinyBERT verification model, a TextCNN verification model, a FastText verification model or any other model that can verify sensitive content. The above-mentioned sensitive content may be any content that violates morality, the rule of law or human values. If the above-mentioned first content verification result is that sensitive content exists, text generation processing is not performed, and the preset default answer is directly output to the user end. For example, the above-mentioned preset default answer may be "I haven't learned how to answer this question yet. You can ask me some other questions and I will try my best to help you solve them."

[0109] The above-mentioned assembly processing can also be implemented through the above-mentioned preset prompt template or the above-mentioned assembly project. It can be understood that under normal circumstances, the number of words that the large model can process simultaneously is limited, so it is necessary to perform word count verification processing on the above-mentioned assembled text. If the number of words in the above-mentioned assembled text exceeds the above-mentioned text generation large model, the above-mentioned word count verification result is that the word count verification fails, otherwise the above-mentioned word count verification result is that the word count verification passes. When the word count verification result of the above-mentioned assembled text is that the word count verification fails, the above-mentioned preset default answer can be output to the above-mentioned user terminal. When the word count verification result of the above-mentioned assembled text is that the word count verification passes, the above-mentioned assembled text can be used as the above-mentioned target prompt text, and the above-mentioned target prompt text can be input into the above-mentioned text generation large model for text generation processing to obtain the above-mentioned first prediction sentence.

[0110] In a possible embodiment, after the step of obtaining the final text generation result, the final text generation result can also be input into a preset verification model for sensitive content verification processing to obtain a second content verification result of the final text generation result; if the second content verification result of the final text generation result is that there is no sensitive content, the final text generation result is output to the user end; if the second content verification result of the final text generation result is that there is sensitive content, the preset default answer is output to the user end.

[0111] Specifically, when there is a terminator in the text generation result after splicing, the final text generation result is obtained, and the above final text generation result needs to be returned to the user end for the user to view. Therefore, before returning to the user end, sensitive content verification is required to avoid the presence of sensitive content, affecting the user's experience, or causing other adverse effects.

[0112] The above sensitive content verification can be implemented by the above preset verification model, and when the preset verification model outputs the second content verification result. If the second content verification result is that there is no sensitive content, the above final text generation result can be returned to the user end. Otherwise, the above preset default answer can be output to the user end. The above preset default answer can be "I haven't learned how to answer this question yet, you can ask me some other questions, and I will try my best to help you solve them."

[0113] like Figure 6 As shown, the embodiment of the present invention also provides a flowchart of a fourth text generation method, comprising the following steps:

[0114] Step 1: Perform sensitive content verification on the question / dialogue input by the user (i.e. the text input content mentioned above).

[0115] Step 2: Determine whether there is sensitive content based on the first verification result obtained from the sensitive content verification process.

[0116] Step 2: If the question / conversation entered by the user contains sensitive content, a fallback answer (i.e. the default answer preset above) will be output.

[0117] Step 4: If the question / conversation input by the user does not contain sensitive content, the question / conversation input by the user is used as a search condition to perform search processing in the knowledge base.

[0118] Step 5: Recall the knowledge text obtained through the retrieval process in step 4.

[0119] Step 6: Assemble the above knowledge text with the original question (i.e. the question / dialogue input by the user) to obtain an assembled text.

[0120] Step 7: Check the word count of the above assembled text.

[0121] Step 8: Determine whether the above-mentioned assembled text has passed the verification based on the verification result obtained from the word count verification processing in the seventh step. If it fails, output a fallback answer. Otherwise, input the above-mentioned assembled text as the above-mentioned target prompt text into the large model to generate a prediction sentence.

[0122] Step 9: Determine whether text loop generation processing is required (i.e. the above-mentioned text preprocessing, retrieval processing, assembly processing and text generation processing, i.e. the retrieval enhancement generation module) based on the prediction sentence generated by the large model.

[0123] Step 10: If text loop generation processing is required (i.e., starting the retrieval enhancement generation module), enter the loop processing process until the third prediction sentence output by the large model meets the preset conditions, then stop the loop, and use the third prediction sentence that meets the preset conditions as the second prediction sentence mentioned above. Determine whether to stop text generation based on the terminator output by the large model. If there is no terminator, continue to the next generation step. If there is a terminator, stop text generation to obtain the final text generation result.

[0124] Step 11: If text loop generation processing is not required (i.e., starting the retrieval enhancement generation module), the first prediction statement of the current generation step is spliced ​​into the text generation result, and the next generation step is entered. After all generation steps are completed, determine whether to stop text generation based on the terminator output by the large model. If there is no terminator, continue to the next generation step. If there is a terminator, stop the text generation processing to obtain the final text generation result.

[0125] Step 12: Perform sensitive content verification on the result content (i.e. the final text generation result).

[0126] Step 13: If there is no sensitive content in the result content, output the answer.

[0127] Step 14: If the result contains sensitive content, output a fallback answer.

[0128] like Figure 7 As shown, the embodiment of the present invention also provides a text generation device, including:

[0129] An input module 701, used to input a target prompt text into a text generation model to obtain at least one first prediction sentence;

[0130] A loop module 702 is used for, for each of the first prediction sentences, when it is detected that the first prediction sentence contains a target text unit, performing text loop generation processing based on the first prediction sentence to obtain a second prediction sentence, and splicing the second prediction sentence into the text generation result, wherein the second prediction sentence satisfies a preset condition, wherein the preset condition is that the second prediction sentence does not contain the target text unit and / or the number of loops reaches a preset number, and the generation probability of the target text unit is less than a generation probability threshold;

[0131] A splicing module 703, configured to splice the first predicted sentence into the text generation result when it is detected that the first predicted sentence does not have a target text unit;

[0132] The determination module 704 is used to determine the concatenated text generation result as the final text generation result when there is a terminator in the concatenated text generation result, wherein the concatenated text generation result includes the second predicted sentence and the first predicted sentence without the target text unit.

[0133] Optionally, the circulation module 702 includes:

[0134] A preprocessing submodule, used for preprocessing the first prediction sentence to obtain an assembly prompt text;

[0135] A text generation submodule, used for inputting the assembly prompt text into the text generation model to generate text and obtain a third prediction sentence;

[0136] The first determination submodule is used to determine the third prediction statement as the first prediction statement when the third prediction statement does not meet the preset condition; repeat the above steps until the third prediction statement is determined as the second prediction statement when the third prediction statement meets the preset condition.

[0137] Optionally, the preprocessing submodule includes:

[0138] A text preprocessing unit, used for performing text preprocessing on the first predicted sentence to obtain a sentence to be retrieved;

[0139] A retrieval unit, used to perform retrieval processing on the sentence to be retrieved in the knowledge base to obtain the knowledge text corresponding to the sentence to be retrieved;

[0140] The assembling unit is used to assemble the sentence to be searched and the knowledge text to obtain an assembled prompt text.

[0141] Optionally, the text preprocessing unit includes:

[0142] A first determination subunit, configured to determine a text position of the target text unit in the first predicted sentence;

[0143] An updating subunit is used to update the target text unit in the first predicted sentence to a preset marker based on the text position to obtain the sentence to be retrieved.

[0144] Optionally, the assembly unit comprises:

[0145] An acquisition subunit is used to acquire a preset prompt template;

[0146] The adding subunit is used to add the sentence to be searched and the knowledge text to the preset prompt template to obtain the assembled prompt text.

[0147] Optionally, the knowledge base is a knowledge vector base, and the retrieval unit includes:

[0148] A first conversion subunit, used for converting the sentence to be searched into a vector to be searched;

[0149] A retrieval subunit, configured to perform retrieval processing on the vector to be retrieved in the knowledge vector library to obtain a knowledge vector related to the vector to be retrieved;

[0150] A sorting subunit, used to sort the knowledge vectors based on the text relevance between the vectors to be searched and the knowledge vectors, to obtain a knowledge vector sorting table;

[0151] The second conversion subunit is used to convert the knowledge vectors in the knowledge vector ranking table whose text relevance is higher than a preset relevance threshold into the knowledge text corresponding to the sentence to be retrieved.

[0152] Optionally, the text generation processing device further includes:

[0153] The acquisition module is used to obtain the text input content entered by the user;

[0154] A first verification module, configured to perform sensitive content verification on the text input content based on a preset verification model to obtain a first content verification result;

[0155] A retrieval module, configured to retrieve the text input content in a knowledge base to obtain a knowledge text corresponding to the text input content if the first content verification result is that no sensitive content exists;

[0156] An assembling module, used for assembling the knowledge text corresponding to the text input content and the text input content to obtain an assembled text;

[0157] A second verification module is used to perform word count verification processing on the assembled text to obtain a word count verification result of the assembled text;

[0158] A passing module is used to use the assembled text as the target prompt text if the word count verification result is that the word count verification is passed.

[0159] like Figure 8 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.

[0160] Specifically, it includes a processor 801 and a memory 802, and a computer program for executing the text generation method which is stored in the memory 802 and can be run on the processor 801, wherein:

[0161] The processor 801 runs the computer program of the text generation method stored in the memory 802 to perform the following steps:

[0162] Inputting the target prompt text into the text generation model to obtain at least one first prediction sentence;

[0163] For each of the first prediction sentences, when it is detected that the target text unit exists in the first prediction sentence, a text loop generation process is performed based on the first prediction sentence to obtain a second prediction sentence, and the second prediction sentence is spliced ​​into the text generation result, and the second prediction sentence satisfies a preset condition, wherein the preset condition is that the second prediction sentence does not include the target text unit and / or the number of loops reaches a preset number, and the generation probability of the target text unit is less than a generation probability threshold;

[0164] When it is detected that the first predicted sentence does not have a target text unit, splicing the first predicted sentence into the text generation result;

[0165] When there is a terminator in the concatenated text generation result, the concatenated text generation result is determined as a final text generation result, wherein the concatenated text generation result includes the second predicted sentence and the first predicted sentence without the target text unit.

[0166] Optionally, the processor 801 performs text loop generation processing based on the first prediction sentence to obtain a second prediction sentence, including:

[0167] Preprocessing the first prediction sentence to obtain an assembly prompt text;

[0168] Inputting the assembly prompt text into the text generation model to generate text, and obtaining a third prediction sentence;

[0169] In a case where the third prediction statement does not satisfy the preset condition, the third prediction statement is determined as the first prediction statement; and the above steps are repeated until, in a case where the third prediction statement satisfies the preset condition, the third prediction statement is determined as the second prediction statement.

[0170] Optionally, the preprocessing of the first prediction sentence to obtain the assembly prompt text performed by the processor 801 includes:

[0171] Performing text preprocessing on the first predicted sentence to obtain a sentence to be retrieved;

[0172] Performing a search process on the sentence to be searched in the knowledge base to obtain the knowledge text corresponding to the sentence to be searched;

[0173] The sentence to be searched and the knowledge text are assembled to obtain an assembled prompt text.

[0174] Optionally, the processor 801 performs text preprocessing on the first predicted sentence to obtain a sentence to be retrieved, including:

[0175] Determining a text position of the target text unit in the first predicted sentence;

[0176] Based on the text position, the target text unit in the first predicted sentence is updated to a preset marker to obtain the sentence to be retrieved.

[0177] Optionally, the processor 801 performs the assembling process of the sentence to be searched and the knowledge text to obtain an assembled prompt text, including:

[0178] Get the preset prompt template;

[0179] The sentence to be searched and the knowledge text are added to the preset prompt template to obtain the assembled prompt text.

[0180] Optionally, the knowledge base is a knowledge vector base, and the processor 801 performs the retrieval process on the to-be-searched sentence in the knowledge base to obtain the knowledge text corresponding to the to-be-searched sentence, including:

[0181] Converting the sentence to be retrieved into a vector to be retrieved;

[0182] Performing a search process on the vector to be searched in the knowledge vector library to obtain a knowledge vector related to the vector to be searched;

[0183] Sorting the knowledge vectors based on the text relevance between the vector to be retrieved and the knowledge vectors to obtain a knowledge vector sorting table;

[0184] The knowledge vectors in the knowledge vector ranking table whose text relevance is higher than a preset relevance threshold are converted into knowledge texts corresponding to the sentence to be retrieved.

[0185] Optionally, before inputting the target prompt text into the text generation model to obtain at least one first prediction sentence, the method executed by the processor 801 further includes:

[0186] Get the text input content entered by the user;

[0187] Performing a sensitive content check on the text input content based on a preset verification model to obtain a first content verification result;

[0188] If the first content verification result is that there is no sensitive content, searching the text input content in the knowledge base to obtain the knowledge text corresponding to the text input content;

[0189] Assembling the knowledge text corresponding to the text input content and the text input content to obtain an assembled text;

[0190] Performing word count verification processing on the assembled text to obtain a word count verification result of the assembled text;

[0191] If the word count check result is that the word count check passes, the assembled text is used as the target prompt text.

[0192] 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, the computer program implements the various processes of the text generation method or the application-side text generation method provided in the embodiment of the present invention, and can achieve the same technical effect. To avoid repetition, it will not be repeated here.

[0193] 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.

[0194] 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: Inputting the target prompt text into the text generation model to obtain at least one first prediction sentence; For each of the first prediction sentences, when it is detected that the target text unit exists in the first prediction sentence, a text loop generation process is performed based on the first prediction sentence to obtain a second prediction sentence, and the second prediction sentence is spliced ​​into the text generation result, and the second prediction sentence satisfies a preset condition, wherein the preset condition is that the second prediction sentence does not include the target text unit and / or the number of loops reaches a preset number, and the generation probability of the target text unit is less than a generation probability threshold; When it is detected that the first predicted sentence does not have a target text unit, splicing the first predicted sentence into the text generation result; When there is a terminator in the concatenated text generation result, the concatenated text generation result is determined as a final text generation result, and the concatenated text generation result includes the second predicted sentence and the first predicted sentence without the target text unit.

2. The text generation method according to claim 1, characterized in that: The performing text loop generation processing based on the first prediction sentence to obtain a second prediction sentence includes: Preprocessing the first prediction sentence to obtain an assembly prompt text; Inputting the assembly prompt text into the text generation model to generate text, and obtaining a third prediction sentence; In a case where the third prediction statement does not satisfy the preset condition, the third prediction statement is determined as the first prediction statement; and the above steps are repeated until, in a case where the third prediction statement satisfies the preset condition, the third prediction statement is determined as the second prediction statement.

3. The text generation method according to claim 2, characterized in that: The preprocessing of the first prediction sentence to obtain an assembly prompt text includes: Performing text preprocessing on the first predicted sentence to obtain a sentence to be retrieved; Performing a search process on the sentence to be searched in the knowledge base to obtain the knowledge text corresponding to the sentence to be searched; The sentence to be searched and the knowledge text are assembled to obtain an assembled prompt text.

4. The text generation method according to claim 3, characterized in that: The performing text preprocessing on the first predicted sentence to obtain a sentence to be retrieved includes: Determining a text position of the target text unit in the first predicted sentence; Based on the text position, the target text unit in the first predicted sentence is updated to a preset marker to obtain the sentence to be retrieved.

5. The text generation method according to claim 2, characterized in that: The step of assembling the sentence to be searched and the knowledge text to obtain an assembled prompt text includes: Get the preset prompt template; The sentence to be searched and the knowledge text are added to the preset prompt template to obtain the assembled prompt text.

6. The text generation method according to claim 3, characterized in that: The knowledge base is a knowledge vector base, and the step of performing a search process on the sentence to be searched in the knowledge base to obtain the knowledge text corresponding to the sentence to be searched includes: Converting the sentence to be retrieved into a vector to be retrieved; Performing a search process on the vector to be searched in the knowledge vector library to obtain a knowledge vector related to the vector to be searched; Sorting the knowledge vectors based on the text relevance between the vector to be retrieved and the knowledge vectors to obtain a knowledge vector sorting table; The knowledge vectors in the knowledge vector ranking table whose text relevance is higher than a preset relevance threshold are converted into knowledge texts corresponding to the sentence to be retrieved.

7. The text generation method according to any one of claims 1 to 6, characterized in that: Before inputting the target prompt text into the text generation model to obtain at least one first prediction sentence, the method further includes: Get the text input content entered by the user; Performing a sensitive content check on the text input content based on a preset verification model to obtain a first content verification result; If the first content verification result is that there is no sensitive content, searching the text input content in the knowledge base to obtain the knowledge text corresponding to the text input content; Assembling the knowledge text corresponding to the text input content and the text input content to obtain an assembled text; Performing word count verification processing on the assembled text to obtain a word count verification result of the assembled text; If the word count check result is that the word count check passes, the assembled text is used as the target prompt text.

8. A text generation device, characterized in that: The text generating device comprises: An input module, used for inputting a target prompt text into a text generation model to obtain at least one first prediction sentence; a loop module, configured to, for each of the first prediction sentences, when detecting that a target text unit exists in the first prediction sentence, perform text loop generation processing based on the first prediction sentence to obtain a second prediction sentence, and splice the second prediction sentence into the text generation result, wherein the second prediction sentence satisfies a preset condition, wherein the preset condition is that the second prediction sentence does not include the target text unit and / or the number of loops reaches a preset number, and the generation probability of the target text unit is less than a generation probability threshold; a splicing module, configured to splice the first prediction sentence into the text generation result when it is detected that the first prediction sentence does not have a target text unit; The determination module is used to determine the concatenated text generation result as the final text generation result when there is a terminator in the concatenated text generation result, wherein the concatenated text generation result includes the second prediction sentence and the first prediction sentence without the target text unit.

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.

Citation Information

Cited By

  • Enterprise policy recommendation method and device, equipment and medium

    CN120012941A