Text model error correction method and device and electronic equipment
By adjusting the output probability of candidate characters based on the compliance prediction model during the text model output character process, the problem of uncontrollability of the text model generation results is solved, the compliance of the generated content is improved, and the information received by users is ensured to be safe and compliant.
Patent Information
- Application Number
- CN202410372103.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-29
- Publication Date
- 2024-11-26
AI Technical Summary
The results of the text model generation are uncontrollable, and content that does not comply with laws and regulations or violates ethics may be output, resulting in users receiving improper information.
During the character output process of text model, the compliance probability of at least two candidate characters is output based on the character string to be detected and the compliance prediction model is determined, and the character output probability is adjusted according to the compliance probability of each candidate character to reduce the incompatibility The output probability of the standard characters is increased to the output probability of the standard characters.
Improve the security and compliance of the results generated by text models, avoid users from receiving improper information, and ensure the legal compliance and ethical nature of the generated content.
Smart Images

Figure CN119026595A_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of artificial intelligence technology, and specifically relates to a text model error correction method, device and electronic device. Background Art
[0002] At present, text models have shown excellent performance in semantic understanding, content generation, and logical reasoning. People can interact with text models through dialogue and chat. However, due to the uncontrollability of model generation results, the content generated by text models may not comply with laws and regulations or violate ethics, which may cause users to receive inappropriate information. Summary of the invention
[0003] The purpose of the embodiments of the present application is to provide a text model error correction method, device and electronic device, which can reduce the output probability of non-compliant characters and increase the output probability of compliant characters during the process of text model outputting characters, thereby improving the security compliance of the text model generation results and preventing users from receiving inappropriate information.
[0004] In a first aspect, an embodiment of the present application provides a text model error correction method, the method comprising: in a case where a character string to be detected is non-compliant, based on the character string to be detected and a compliance prediction model, outputting compliance probabilities of at least two candidate characters, the candidate characters being generated based on text information input into the text model during the process of generating the character string to be detected; and adjusting the character output probability of each candidate character according to the compliance probability of each candidate character among the at least two candidate characters.
[0005] In the second aspect, an embodiment of the present application provides a text model error correction device, which includes: a processing module, which is used to output the compliance probability of at least two candidate characters based on the character string to be detected and the compliance prediction model when the character string to be detected is not compliant, and the candidate characters are generated according to the text information input into the text model during the process of generating the character string to be detected; the processing module is also used to adjust the character output probability of each candidate character according to the compliance probability of each candidate character in the at least two candidate characters.
[0006] In a third aspect, an embodiment of the present application provides an electronic device, which includes a processor and a memory, wherein the memory stores programs or instructions that can be run on the processor, and when the programs or instructions are executed by the processor, the steps of the text model error correction method of the first aspect are implemented.
[0007] In a fourth aspect, an embodiment of the present application provides a readable storage medium having a program or instruction stored thereon, which, when executed by a processor, implements the steps of the text model error correction method of the first aspect.
[0008] In a fifth aspect, an embodiment of the present application provides a chip, which includes a processor and a communication interface, wherein the communication interface and the processor are coupled, and the processor is used to run programs or instructions to implement the steps of the text model error correction method of the first aspect.
[0009] In a sixth aspect, an embodiment of the present application provides a computer program product, which is stored in a storage medium and is executed by at least one processor to implement the steps of the text model error correction method of the first aspect.
[0010] In the text model error correction method provided in the embodiment of the present application, when the character string to be detected is not compliant, based on the character string to be detected and the compliance prediction model, the compliance probabilities of at least two candidate characters are output, and the candidate characters are generated according to the text information input into the text model in the process of generating the character string to be detected; according to the compliance probability of each candidate character in the at least two candidate characters, the character output probability of each candidate character is adjusted. Through the above-mentioned text model error correction method, when the generated content of the text model is not compliant, the text model is controlled to regenerate new content, and in the process of generating new content, the compliance probability of each candidate character regenerated by the text model is calculated by the compliance prediction model, and the character output probability of each candidate character output by the text model is corrected according to the compliance probability of each candidate character. In this way, in the process of outputting characters by the text model, the output probability of non-compliant characters can be reduced, the output probability of compliant characters can be increased, and the security compliance of the text model generation result is improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0011] Figure 1 A flowchart of a text model error correction method provided for some embodiments of the present application;
[0012] Figure 2 A schematic diagram of a text model error correction method provided for some embodiments of the present application;
[0013] Figure 3 A schematic diagram of a text model error correction method provided for some embodiments of the present application;
[0014] Figure 4 A schematic diagram of a text model error correction method provided for some embodiments of the present application;
[0015] Figure 5 A schematic diagram of a text model error correction method provided for some embodiments of the present application;
[0016] Figure 6 A schematic diagram of an operation interface of a text model error correction method provided in some embodiments of the present application;
[0017] Figure 7A schematic diagram of a text model error correction method provided for some embodiments of the present application;
[0018] Figure 8 A flowchart of a text model error correction method provided for some embodiments of the present application;
[0019] Fig. 9 A structural block diagram of a text model error correction device provided for some embodiments of the present application;
[0020] Fig.10 A structural block diagram of an electronic device provided for some embodiments of the present application;
[0021] Fig.11 A schematic diagram of the hardware structure of an electronic device provided for some embodiments of the present application. DETAILED DESCRIPTION
[0022] The following will be combined with the drawings in the embodiments of the present application to clearly describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, rather than all the embodiments. All other embodiments obtained by ordinary technicians in this field based on the embodiments in the present application belong to the scope of protection of this application.
[0023] The terms "first", "second", etc. in the specification and claims of the present application are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the terms used in this way are interchangeable where appropriate, so that the embodiments of the present application can be implemented in an order other than those illustrated or described herein, and the objects distinguished by "first", "second", etc. are generally of one type, and the number of objects is not limited. For example, the first object can be one or more. In addition, "and / or" in the specification and claims represents at least one of the connected objects, and the character " / " generally indicates that the objects associated with each other are in an "or" relationship.
[0024] The text model error correction method provided in the embodiment of the present application is described in detail below through specific embodiments and their application scenarios in conjunction with the accompanying drawings.
[0025] like Figure 1 As shown, the embodiment of the present application provides a text model error correction method, which may include the following steps 102 and 104:
[0026] Step 102: When the character string to be detected is not compliant, based on the character string to be detected and the compliance prediction model, output compliance probabilities of at least two candidate characters.
[0027] The text model error correction method proposed in the embodiments of this application is executed by an electronic device, which can specifically be intelligent electronic devices such as smartphones, tablets, laptops, and smart watches, without specific limitations here.
[0028] Among them, the candidate characters are generated according to the text information input into the text model during the process of generating the string to be detected, and the text information input into the text model during the process of generating the string to be detected is the above-mentioned information of the string to be detected.
[0029] Among them, the above-mentioned text model can specifically be a GPT (Generative Pre-trained Transformers) model. The GPT model uses a one-way, autoregressive method to predict and generate the next character. For example, when the sentence "What do you like to do?" is input into the GPT model, the GPT model will use "What do you like to do?" as the input for reply and generate the first character "I". Further, the GPT model will use "What do you like to do? I" as the input for reply and generate the second character "like". Then, the GPT model will use "What do you like to do? I like" as the input to generate the third character "to", and so on, continuously looping until the generation ends and the final output "I like watching movies" is obtained as the reply.
[0030] Specifically, when the GPT model generates a response, the GPT model can predict the probability of generating the next character based on the input information. That is, after inputting information into the GPT model, GPT can predict the next most likely character, that is, predict the character output probability of each candidate character. For example, using the above example, when the input information of the GPT model is "What do you like to do?", the response may be "I like to listen to music" or "watch movies", "listen to music", etc. in addition to "I like to watch movies", and the possibility of replying "OK" is small. Therefore, when the GPT model generates the first character "I", the GPT model will first output a table containing all candidate characters and their character output probabilities, such as {I: 0.4, watch: 0.2, listen: 0.2, eat: 0.1, good: 0.00002, yes: 0.00001...}. For another example, when the input information of the GPT model is "What fruit do you like to eat?", the reply may be "I like to eat apples", "I like to eat bananas" or "watermelons", etc., and the possibility of replying "Hello" is relatively small. At this time, when the GPT model generates the first character, it will first output a table containing all candidate characters and their character output probabilities: {I: 0.6, Apple: 0.1, West: 0.1, Peach: 0.1, Good: 0.00002, You: 0.00001, Yes: 0.00001...}. On this basis, based on the sampling strategy and the character output probability of each candidate character, the current output character result is sampled.
[0031] The character sampling strategy is the process of selecting the final output character based on the character output probability of each candidate character after obtaining the character output probability of all candidate characters, such as selecting the candidate character with the highest character output probability as the final output character. In actual application, common sampling strategies may include:
[0032] (1) Topk sampling: Select the top k characters with the highest probability of character output from at least two candidate characters, and then select them according to the probability distribution. Sample the selected k characters, where i and j represent the order numbers of the selected candidate characters, wi represents the i-th selected candidate character, k represents the number of selected candidate characters, and p wi represents the sampling probability of the i-th candidate character selected, x i represents the character output probability of the i-th candidate character selected, x j Indicates the character output probability of the jth candidate character selected. For example, using the above example of inputting "What do you like to do?" into the GPT model, when k is 3, select "I", "see" and "listen" from at least two candidate characters, and then based on the above probability distribution, calculate the sampling probabilities of the three characters respectively: On this basis, the GPT model can select the candidate character "I" with the highest sampling probability as the final output character.
[0033] (2) Topm sampling: The character output probabilities of the candidate characters are accumulated in descending order until the accumulated value exceeds m, and then the candidate characters corresponding to the accumulated value are sampled according to the above probability distribution. For example, using the above example of inputting "What do you like to do?" into the GPT model, when m is 0.85, when the four candidate characters "I", "see", "listen" and "eat" are selected, the accumulated value of the character output probability of the four candidate characters is 0.4+0.2+0.2+0.1=0.9, 0.9>0.85. On this basis, according to the above probability distribution, the sampling probabilities of the four characters are calculated as follows: Furthermore, the GPT model can select the candidate character "I" with the highest sampling probability as the final output character.
[0034] (3) Temperature sampling: according to probability distribution All candidate characters are sampled. T is the temperature coefficient. The smaller the value of T, the more concentrated the sampling probability is towards the head, and the more stable the output result is. The larger the value of T, the more evenly distributed the sampling probability is, and the more diverse the output result is. i and j represent the order of the candidate characters, wi represents the i-th candidate character, M represents the total number of candidate characters, and p represents the total number of candidate characters. wi represents the sampling probability of the i-th candidate character, x i represents the character output probability of the i-th candidate character, x j Represents the character output probability of the jth candidate character.
[0035] Furthermore, in the text model error correction method provided in the embodiment of the present application, compliance detection is performed on the generated content of the text model in real time, and the above-mentioned character string to be detected is the character string that is newly generated by the text model and can constitute a complete sentence.
[0036] Furthermore, the purpose of the above-mentioned compliance detection is to review and determine whether the string to be detected contains characters that pose security compliance risks, that is, to review and determine whether the string to be detected contains characters that are not in compliance with laws and regulations or violate ethical morals, such as reviewing and determining whether the string to be detected contains swear words, insults, and other characters.
[0037] Furthermore, the compliance prediction model is used to predict the compliance of each candidate character and output the compliance probability of each candidate character.
[0038] In actual application, Figure 3As shown, the compliance prediction model may specifically include a BERT (Bidirectional Encoder Representation from Transformers) model and a fully connected layer. In the process of the compliance prediction model predicting the compliance of each candidate character, the BERT model is used to predict the input information such as w 1 、w 2 、w 3 、w k and w k-1 The BERT model is used to encode the characters, and the encoded information obtained by the BERT model is input into the fully connected layer, and then the compliance probability of the candidate characters is obtained through the softmax function. Among them, the number of parameters of the text model is much larger than that of the compliance prediction model. Therefore, the amount of calculation of the compliance prediction model in actual use is negligible compared with the text model.
[0039] Furthermore, the compliance probability is used to indicate the possibility that each candidate character is compliant. The greater the compliance probability, the greater the possibility that the corresponding candidate character is compliant. The smaller the compliance probability, the smaller the possibility that the corresponding candidate character is compliant.
[0040] Specifically, in the text model error correction method provided in the embodiment of the present application, when the character string to be detected generated by the text model is non-compliant, the text model is controlled to regenerate new content to modify the non-compliant character string to be detected, and at least two candidate characters generated by the text model according to the above information of the character string to be detected are input into the trained compliance prediction model, so as to predict the compliance of each candidate character through the trained compliance prediction model to obtain the compliance probability of each candidate character.
[0041] Step 104: According to the compliance probability of each candidate character in the at least two candidate characters, the character output probability of each candidate character is adjusted.
[0042] Among them, the character output probability is the probability of the text model outputting each candidate character.
[0043] It is understandable that in the process of text generation by the text model, the text model will output the character output probability of the next character based on the currently generated text, taking into account the semantic information and fluency of the above text. In the actual application process, the character output probability can be specifically a list containing all possible candidate characters and the corresponding character output probabilities. For example, if the text model wants to output the next character of "He doesn't like to eat broccoli, but I like to eat broccoli", the character output probability of the next character can be specifically shown in Table 1 below, where Table 1 is an example table of the character output probability of the next character of "He doesn't like to eat broccoli, but I like to eat broccoli".
[0044] Table 1
[0045]
[0046]
[0047] Furthermore, when the compliance probability of the candidate character is relatively large, the character output probability of the candidate character is increased, and when the compliance probability of the candidate character is relatively small, the character output probability of the candidate character is reduced.
[0048] Specifically, in the text model error correction method provided in the embodiment of the present application, after obtaining the compliance probability of each candidate character, for each candidate character, the character output probability of the candidate character output by the text model is adjusted according to the compliance probability of the candidate character to reduce the character output probability of non-compliant characters and increase the character output probability of compliant characters, so that compliant characters can be sampled in the subsequent output results, thereby achieving security processing of the output results of the text model and ensuring the security compliance of the generated results of the text model. In this way, in the process of the text model outputting characters, the generated content of the text model is checked for compliance, and in the case that the generated content of the text model is non-compliant, by regenerating candidate characters, calculating the compliance probability of candidate characters and correcting the character output probability of the text model for the candidate characters, the character output probability of non-compliant characters is reduced, and the character output probability of compliant characters is increased, thereby performing security processing on the output results of the text model and ensuring the security compliance of the generated results of the text model.
[0049] In addition, it is understandable that the traditional text model generation response solution generally uses the audit model to audit the generation results of the text model after the text model generates the response to determine whether the generation results contain content with security compliance risks. If it is determined that the generation results of the text model contain content with security compliance issues, the question sentence is rewritten or a fixed response template is used to respond. In this way, using a fixed response template to respond will make the response result stiff, and rewriting the question sentence will cause problems such as incoherent and unsmooth context semantics after the rewrite, which reduces the response quality of the traditional text model generation response solution.
[0050] In the text model error correction method provided in the embodiment of the present application, when the text model generates a character string to be detected that has security compliance issues, new candidate characters are generated based on the above information of the character string to be detected, and then the character output probability of each candidate character is corrected based on the compliance probability of each candidate character. In this way, the problematic character string is rewritten in combination with the context semantics, and while making the generation result of the text model compliant, the generation result of the text model is made coherent with the context semantics, ensuring the quality of the overall generation result of the text model.
[0051] The above-mentioned text model error correction method provided by the embodiment of the present application, when the character string to be detected is not compliant, based on the character string to be detected and the compliance prediction model, outputs the compliance probability of at least two candidate characters, the candidate characters are generated according to the text information input into the text model in the process of generating the character string to be detected; according to the compliance probability of each candidate character in the at least two candidate characters, adjust the character output probability of each candidate character. Through the above-mentioned text model error correction method, when the generated content of the text model is not compliant, the text model is controlled to regenerate new content, and, in the process of generating new content, the compliance probability of each candidate character regenerated by the text model is calculated by the compliance prediction model, and the character output probability of each candidate character output by the text model is corrected according to the compliance probability of each candidate character. In this way, in the process of outputting characters by the text model, the output probability of non-compliant characters can be reduced, and the output probability of compliant characters can be increased, thereby improving the security compliance of the text model generation result and preventing users from receiving inappropriate information.
[0052] In the embodiment of the present application, the above text model error correction method may further include the following steps 106 to 112:
[0053] Step 106: according to the order in which the text model generates the characters, the character type of each character generated by the text model is detected in turn.
[0054] Specifically, when the text model generates a piece of text, it generates it character by character in sequence. In the text model error correction method provided in the embodiment of the present application, in the process of generating characters through the text model, each character generated by the text model in real time will be compared with the characters in the sentence character set in turn according to the order in which the text model generates the characters, so as to detect the character type of each character generated by the text model in turn, and determine whether the characters generated by the text model in real time are sentence characters, that is, determine whether the text model has generated a complete sentence.
[0055] Among them, the character type of the characters in the sentence character set is a sentence character.
[0056] In actual application, the sentence character set may specifically include sentence characters such as a period ".", a semicolon ";", an exclamation mark "!", and an ellipsis "...", which are not specifically limited here.
[0057] Step 108: When the sentence character is detected for the first time, all characters generated by the text model are determined as the character string to be detected.
[0058] Specifically, in the text model error correction method provided in the embodiment of the present application, in the process of detecting the character type of each character generated by the text model in turn, when the text model is detected for the first time to generate a sentence character, that is, when the character generated by the text model is detected for the first time to be within the above-mentioned sentence character set, all characters generated by the text model are determined as the character string to be detected.
[0059] Step 110: When a sentence character is detected for the Nth time, a character string consisting of all characters between the sentence character detected for the N-1th time and the sentence character detected for the Nth time is determined as the character string to be detected.
[0060] Wherein, N is a positive integer greater than 1.
[0061] Specifically, in the text model error correction method provided in the embodiment of the present application, in the process of detecting the character type of each character generated by the text model in turn, when the text model is detected to generate a sentence character for the Nth time, that is, when the character generated by the text model is detected for the Nth time and is within the above-mentioned sentence character set, the character string composed of all characters between the sentence character detected for the N-1th time and the sentence character detected for the Nth time is determined as the character string to be detected.
[0062] Step 112: Perform compliance check on the character string to be checked by using the detection model.
[0063] Among them, the detection model is used to classify the input text to determine whether the input text is safe and compliant.
[0064] In actual application, the above detection models include but are not limited to fastText model, TextCNN (Text Convolitional Neural Networks) model, TextRNN (Text Recurrent Neural Networks) model and BERT model, etc. Technical personnel in this field can select the specific type of detection model according to actual conditions, and no specific limitation is made here.
[0065] Specifically, in the text model error correction method provided in the embodiment of the present application, the character type of each character generated by the text model is detected in turn according to the order in which the text model generates characters. When the characters generated by the text model in real time are not in the above-mentioned sentence character set, the text model is controlled to continue to generate characters. When the characters generated by the text model are detected for the first time in the above-mentioned sentence character set, that is, when the text model generates sentence characters for the first time, all characters generated by the text model are determined as the string to be detected. When the characters generated by the text model are detected for the Nth time in the above-mentioned sentence character set, that is, when the text model generates sentence characters for the Nth time, the string composed of all characters between the sentence characters detected for the N-1th time and the sentence characters detected for the Nth time is determined as the string to be detected. On this basis, after each determination of the string to be detected, the detection model is called, and the string to be detected is classified by the detection model to perform compliance detection on the string to be detected, and it is determined whether the string to be detected is safe and compliant. In this way, when the text model generates a reply, after detecting that the text model generates an irregular sentence, the irregular sentence is immediately corrected and rewritten, avoiding rewriting the problem segment after the text model generates a large reply, improving the efficiency and real-time performance of error correction of the text model's generation results and saving computing power. In addition, by directly correcting errors in the link where the text model outputs characters, the text model can reply to questions more quickly and efficiently, shortening the user's waiting time.
[0066] Exemplarily, "What kind of fruit do you like to eat?" is input into the text model, and the text model takes "What kind of fruit do you like to eat." as the above information, and outputs the character "I". Further, the text model takes "What kind of fruit do you like to eat. I" as the above information, and outputs the character "Xi". Further, the text model takes "What kind of fruit do you like to eat. I like" as the above information, and outputs the character "Huan". Further, the text model takes "What kind of fruit do you like to eat. I like" as the above information, and outputs the character "Eat". Further, the text model takes "What kind of fruit do you like to eat. I like to eat" as the above information, and outputs the character "Apple". Further, the text model takes "What kind of fruit do you like to eat. I like to eat Apple" as the above information, and outputs the character "Fruit". By analogy, the text model outputs the reply information of "What kind of fruit do you like to eat." word by word, until a complete reply "I like to eat apples. He likes to eat grapes. She likes to eat bananas" is generated. In the process of the text model outputting the reply information word by word, the text model detects the character type of each character it outputs. When the sentence character, i.e., the first period in "I like to eat apples. He likes to eat grapes. She likes to eat bananas," is detected for the first time, all characters generated by the text model, i.e., "I like to eat apples." are determined as the string to be detected, and the detection model performs a compliance check on "I like to eat apples."; when the sentence character, i.e., the second period in "I like to eat apples. He likes to eat grapes. She likes to eat bananas," is detected for the second time, the string composed of all characters between the sentence character detected for the second time and the sentence character detected for the first time, i.e., "He likes to eat grapes." is determined as the string to be detected, and the detection model performs a compliance check on "He likes to eat grapes."; when the sentence character, i.e., the third period in "I like to eat apples. He likes to eat grapes. She likes to eat bananas," is detected for the third time, the string composed of all characters between the sentence character detected for the third time and the sentence character detected for the second time, i.e., "She likes to eat bananas." is determined as the string to be detected, and the detection model performs a compliance check on "She likes to eat bananas.".
[0067] Exemplarily, the input text model is fed with "Please recite 'Sympathy for the Peasants'". Taking "Please recite 'Sympathy for the Peasants'" as the above context information, the text model outputs the character 'hoe'. Further, taking "Please recite 'Sympathy for the Peasants' hoe" as the above context information, the text model outputs the character 'grain'. Further, taking "Please recite 'Sympathy for the Peasants' hoe grain" as the above context information, the text model outputs the character'sun'. Further, taking "Please recite 'Sympathy for the Peasants' hoe grain sun" as the above context information, the text model outputs the character 'when'. Further, taking "Please recite 'Sympathy for the Peasants' hoe grain sun when" as the above context information, the text model outputs the character 'noon'. And so on, the text model outputs the reply information for "Please recite 'Sympathy for the Peasants'" character by character until the complete reply "Hoeing the crops under the midday sun, sweat dripping onto the soil below. Who knows that every grain in the bowl is the fruit of hard toil." is generated. Among them, during the process of the text model outputting the reply information character by character, the text model detects the character type of each character it outputs. When the first punctuation mark in the sentence-ending character, i.e., the first full stop in "Hoeing the crops under the midday sun, sweat dripping onto the soil below. Who knows that every grain in the bowl is the fruit of hard toil.", is detected for the first time, all the characters generated by the text model, i.e., "Hoeing the crops under the midday sun, sweat dripping onto the soil below.", are determined as the string to be detected, and the string "Hoeing the crops under the midday sun, sweat dripping onto the soil below." is subjected to compliance detection through the detection model; when the second punctuation mark in the sentence-ending character, i.e., the second full stop in "Hoeing the crops under the midday sun, sweat dripping onto the soil below. Who knows that every grain in the bowl is the fruit of hard toil.", is detected for the second time, the string composed of all the characters between the second detected sentence-ending character and the first detected sentence-ending character, i.e., "Who knows that every grain in the bowl is the fruit of hard toil.", is determined as the string to be detected, and the string "Who knows that every grain in the bowl is the fruit of hard toil." is subjected to compliance detection through the detection model.
[0068] In the above embodiments provided by the present application, according to the order in which the text model generates characters, the character type of each character generated by the text model is detected in sequence; when the first sentence-ending character is detected, all the characters generated by the text model are determined as the string to be detected; when the Nth sentence-ending character is detected, the string composed of all the characters between the (N - 1)th detected sentence-ending character and the Nth detected sentence-ending character is determined as the string to be detected, where N is a positive integer greater than 1; through the detection model, the string to be detected is subjected to compliance detection. In this way, after detecting that the text model generates a non-compliant sentence, the non-compliant sentence is immediately corrected and rewritten, improving the efficiency and real-time performance of error correction for the generation result of the text model and saving computing power. Moreover, error correction is performed at the link where the text model outputs characters, making the text model reply to questions more quickly and efficiently, and shortening the waiting time of users.
[0069] In the embodiments of the present application, the step of outputting the compliance probabilities of at least two candidate characters based on the string to be detected and the compliance prediction model may specifically include the following steps 114 to 118:
[0070] Step 114: Re-input the text information input into the text model during the process of generating the string to be detected into the text model, and output at least two candidate characters.
[0071] Specifically, in the text model error correction method provided in the embodiments of the present application, when the string to be detected is non-compliant, the text information input into the text model during the process of generating the string to be detected is re-input into the text model, that is, the above-text information of the string to be detected is re-input into the text model, so that the text model regenerates a new string to be detected according to the above-text information and outputs at least two candidate characters.
[0072] Step 116: Determine the input information corresponding to each candidate character according to the text information.
[0073] Wherein, the input information is obtained by splicing each candidate character and the text information.
[0074] For example, when the above text information is "You are like a little", if the candidate character is "child", the input information corresponding to the candidate character is "You are like a little child", if the candidate character is "ugly", the input information corresponding to the candidate character is "You are like a little clown", if the candidate character is "fart", the input information corresponding to the candidate character is "You are like a little fart", and if the candidate character is "sky", the input information corresponding to the candidate character is "You are like a little sky".
[0075] In addition, it should be noted that in the actual application process, when the candidate character is not the candidate character of the first character in the regenerated string to be detected, the input information corresponding to the candidate character is obtained by splicing the candidate character and its above-text information, and the above-text information of the candidate character is the text information input into the text model during the process of generating the candidate character.
[0076] Step 118: Input the input information corresponding to each candidate character into the compliance prediction model, and output the compliance probability of each candidate character.
[0077] Specifically, in the text model error correction method provided in the embodiments of the present application, the character output probability of the candidate characters generated by the text model is corrected in the character generation link. At this time, most of the input to the compliance prediction model is incomplete text, which is difficult to classify. Therefore, in the text model error correction method provided in the embodiments of the present application, for each candidate character, the input information corresponding to each candidate character is determined by combining each candidate character and its above-text information, and then it is determined whether the input information corresponding to each candidate character is compliant through the trained compliance prediction model, and the compliance probability of each candidate character is output. In this way, it is ensured that the compliance of the candidate character is judged by combining the context of the candidate character, ensuring the accuracy of determining the compliance probability of the candidate character.
[0078] Exemplarily, the context information of the string to be detected is the string "I don't like to eat broccoli." When the string to be detected is non-compliant, "I don't like to eat broccoli." is re-input into the text model, and the text model regenerates candidate characters "it", "too", and "one" based on "I don't like to eat broccoli." On this basis, "I don't like to eat broccoli." and "it" are concatenated to obtain the input information "I don't like to eat broccoli. It" corresponding to the candidate character "it", "I don't like to eat broccoli." and "too" are concatenated to obtain the input information "I don't like to eat broccoli. Too" corresponding to the candidate character "too", and "I don't like to eat broccoli." and "one" are concatenated to obtain the input information "I don't like to eat broccoli. One" corresponding to the candidate character "one". Further, "I don't like to eat broccoli. It" is input into the compliance prediction model to output the compliance probability of the candidate character "it", "I don't like to eat broccoli. Too" is input into the compliance prediction model to output the compliance probability of the candidate character "too", and "I don't like to eat broccoli. One" is input into the compliance prediction model to output the compliance probability of the candidate character "one".
[0079] Exemplarily, the context information of the string to be detected is the string "Math is too difficult." When the string to be detected is non-compliant, "Math is too difficult." is re-input into the text model, and the text model regenerates candidate characters "simple", "boring", and "true" based on "Math is too difficult." On this basis, "Math is too difficult." and "simple" are concatenated to obtain the input information "Math is too difficult. Simple" corresponding to the candidate character "simple", "Math is too difficult." and "boring" are concatenated to obtain the input information "Math is too difficult. Boring" corresponding to the candidate character "boring", and "Math is too difficult." and "true" are concatenated to obtain the input information "Math is too difficult. True" corresponding to the candidate character "true". Further, "Math is too difficult. Simple" is input into the compliance prediction model to output the compliance probability of the candidate character "simple", "Math is too difficult. Boring" is input into the compliance prediction model to output the compliance probability of the candidate character "boring", and "Math is too difficult. True" is input into the compliance prediction model to output the compliance probability of the candidate character "true".
[0080] In the above embodiments provided by the present application, in the process of outputting the compliance probabilities of at least two candidate characters based on the string to be detected and the compliance prediction model, the text information input into the text model during the generation of the string to be detected is input into the text model again to output at least two candidate characters; according to the text information, the input information corresponding to each candidate character is determined, and the input information is obtained by concatenating each candidate character with the text information; the input information corresponding to each candidate character is input into the compliance prediction model to output the compliance probability of each candidate character. In this way, by combining the context of the candidate characters to determine whether the candidate characters are compliant, the accuracy of determining the compliance probability of the candidate characters is ensured.
[0081] In the embodiment of the present application, the above text model error correction method may further include the following steps 120 to 124:
[0082] Step 120: Input the training samples into the text model, and output the character output probability of each candidate character corresponding to each training sample.
[0083] The training sample corresponds to the above input information, and the last character in the training sample is equivalent to the candidate character in the above input information.
[0084] It is understandable that, unlike the traditional classification model, which inputs complete sentences or paragraphs, the compliance prediction model of the embodiment of the present application mostly inputs incomplete texts that are still in the process of being generated. Therefore, the training samples and training methods of the compliance prediction model of the embodiment of the present application are also different from the traditional classification model. The training samples of the traditional classification model are complete sentences, and the category to which the training samples belong can be directly determined. For example, "You are like a clown" is not compliant, while "You are like a child" is compliant. However, the training samples of the compliance prediction model of the embodiment of the present application, such as "You are like a child", are incomplete texts, and it is difficult to determine the category to which they belong. It is necessary to combine the following information of the training samples to determine whether the training samples are compliant, and to determine the possibility of the compliance of the training samples.
[0085] On this basis, in the text model error correction method provided in the embodiment of the present application, in the process of training the above-mentioned compliance prediction model, incomplete sentences are selected as training samples, and the training samples are input into the text model as the above information to obtain the output probability of the next character, that is, the candidate character, of each training sample output by the text model.
[0086] Step 122: When the combination information of the training sample and the corresponding candidate characters complies with the requirements, the sum of the character output probabilities of the corresponding candidate characters is determined as the label value of the training sample.
[0087] Among them, the labeled value of the training sample is the compliance probability of the training sample.
[0088] Furthermore, the combined information is obtained by concatenating each candidate character with the training sample.
[0089] Specifically, in the text model error correction method provided in the embodiment of the present application, after obtaining the candidate characters and their character output probabilities of each training sample, for each training sample, the training sample is combined with each of its candidate characters respectively, and it is determined whether the combination information obtained by combining the training sample with each candidate character is compliant. On this basis, when the combination information of the training sample and its candidate characters is compliant, the sum of the character output probabilities of the compliant candidate characters is determined as the annotation value of the training sample, that is, as the compliance probability of the training sample. In this way, the sum of the character output probabilities of the compliant candidate characters of the training sample is determined as the annotation value of the training sample, which improves the accuracy of the annotation value of the obtained training sample, and whether the training sample is compliant is determined in combination with the context of the training sample, which further improves the accuracy of annotating the training sample.
[0090] For example, the training sample is "you look like a little kid". "You look like a little kid" is input into the text model, and the text model generates candidate characters for "you look like a little kid" and their character output probabilities: {child: 0.6, ugly: 0.3, fart: 0.1}. On this basis, the training sample "you look like a little kid" is combined with its candidate characters to obtain the combined information "you look like a kid", "you look like a clown" and "you look like a little fart". Further, it is determined whether each combined information is compliant. If it is determined that "you look like a kid" and "you look like a little fart" are compliant, but "you look like a clown" is not compliant, the annotation value of the training sample "you look like a little kid", that is, the compliance probability, is: 0.6+0.1=0.7.
[0091] For example, the training sample is "You are really big", and "You are really big" is input into the text model. The text model generates candidate characters for "You are really big" and their character output probabilities: {good: 0.2, smart: 0.3, mixed: 0.5}. On this basis, the training sample "You are really big" is combined with its candidate characters to obtain the combined information "You are really good", "You are really smart" and "You are really a big mixed". Further, it is judged whether each combination of information is compliant. If it is determined that "You are really good" and "You are really smart" are compliant, but "You are really a big mixed" is not compliant, the annotation value of the training sample "You are really big", that is, the compliance probability, is: 0.2+0.3=0.5.
[0092] Based on the above labeling method, as shown in the following Table 2, a batch of training samples and their labeling values can be obtained, where Table 2 is an example table of training samples.
[0093] Table 2
[0094] Training samples Annotation value (compliance probability) You're like a child 1 You're like a little brat 1 You look like a clown 0 You are like a little 0.7 You are like a sky 0.9 You are like an angel 1 You are so big 0.5 You are such a nice person. 1 You're such a big asshole 0 …… ……
[0095] Step 124: Train the compliance prediction model according to the target loss function, the labeled value of each training sample, and the predicted value of each training sample to obtain a trained compliance prediction model.
[0096] Specifically, in the text model error correction method provided in the embodiment of the present application, after the training samples are labeled to obtain the labeled value of each training sample, the compliance prediction model is trained according to the target loss function, the labeled value of each training sample and the predicted value of each training sample to obtain the trained compliance prediction model.
[0097] The above objective loss function adopts cross entropy, which can be specifically expressed as the following formula (1):
[0098]
[0099] Among them, loss is the loss value, y is the labeled value of the training sample, is the predicted value of the compliance prediction model for the training sample.
[0100] In the above-mentioned embodiment provided by the present application, the training samples are input into the text model, and the character output probability of each candidate character corresponding to each training sample is output; when the combination information of the training sample and the corresponding candidate character is compliant, the sum of the output probabilities of the corresponding candidate characters is determined as the labeling value of the training sample, and the combination information is obtained by splicing each candidate character with the training sample; according to the target loss function, the labeling value of each training sample and the predicted value of each training sample, the compliance prediction model is trained to obtain the trained compliance prediction model. In this way, the training samples are labeled in combination with the context of the training samples and then the compliance prediction model is trained, which ensures the accuracy of labeling the training samples and then ensures the accuracy of training the compliance prediction model.
[0101] In the embodiment of the present application, the above step 104 may specifically include the following step 104a:
[0102] Step 104a: According to the first formula, the probability value of the character output probability of each candidate character is adjusted according to the compliance probability of each candidate character.
[0103] Among them, the first formula is obtained by normalizing the second formula, and the function value of the second formula is the larger one between zero and the target value, and the target value is determined according to the compliance probability, the character output probability and the threshold parameter.
[0104] Furthermore, the target value can be specifically the result obtained by multiplying the difference between the compliance probability and the threshold parameter by the character output probability, that is, target value = character output probability × (compliance probability - threshold parameter). On this basis, the function value of the second formula is the larger of zero and the target value, that is, when the compliance probability is lower than the threshold parameter, the corrected character output probability is made zero, thereby reducing the output possibility of candidate characters with lower compliance probability and improving the compliance of the text model generation results.
[0105] Among them, the above threshold parameters are adjustable parameters, which are used to control the threshold of the compliance probability. For the specific values of the above threshold parameters, those skilled in the art can set them according to actual conditions, and no specific restrictions are made here.
[0106] Specifically, in the text model error correction method provided in the embodiment of the present application, after obtaining the compliance probability of each candidate character, according to the first formula, the initial character output probability of each candidate character is corrected according to the compliance probability and character output probability of each candidate character to obtain the adjusted character output probability of each candidate character, thereby reducing the possibility of obtaining candidate characters with lower compliance probability in subsequent sampling.
[0107] For example, Figure 5 As shown, when outputting the kth character w k When the text model has output the first k-1 characters, that is, w 1 、w 2 、w 3 and w k-1 Enter the text model with the same characters and get the kth character w k The possible i candidate characters are w k1 、w k2 and w ki And other characters, and get the character output probability of each candidate character, that is, x 1 、x 2 and x i Etc. Further, the first k-1 characters that the text model has output, namely w 1 、w 2 、w 3 and w k-1 The same character as the kth character w k The candidate character is w k1 、w k2 and w ki The trained compliance prediction model is input to obtain the compliance probability of each candidate character, i.e., p s1 to p si On this basis, based on the first formula, according to the character output probability and compliance probability of each candidate character, a new character output probability of each candidate character is obtained.
[0108] The second formula can be specifically shown as the following formula (2):
[0109] F(i)=max{x i (p .i -b),0}, (2)
[0110] Among them, i is the ordinal number of the candidate character, F(i) is the function value corresponding to the i-th candidate character, and x i is the character output probability of the i-th candidate character, p si is the compliance probability of the i-th candidate character, and b is the threshold parameter.
[0111] On this basis, by normalizing the second formula, the first formula can be obtained. The first formula can be specifically shown in the following formula (3):
[0112]
[0113] Among them, X i is the character output probability of the i-th candidate character. In this way, when the compliance probability is lower than the threshold parameter, the corrected character output probability is zero, which reduces the output possibility of the candidate character with a smaller compliance probability.
[0114] For example, when the threshold parameter b is 0.5 and the number of candidate characters is 3, if the character output probabilities of the three candidate characters are 0.38, 0.27 and 0.19 respectively, and the compliance probabilities of the three candidate characters are 0.65, 0.88 and 0.90 respectively, according to the first formula above, the character output probability of the first candidate character can be calculated as:
[0115]
[0116] The character output probability of the second candidate character is:
[0117]
[0118] The character output probability of the third candidate character is:
[0119]
[0120] In the above-mentioned embodiment provided by the present application, in the process of adjusting the character output probability of each candidate character according to the compliance probability of each candidate character in at least two candidate characters, the probability value of the character output probability of each candidate character is adjusted according to the compliance probability of each candidate character according to the first formula; wherein the first formula is obtained by normalizing the second formula, and the second formula is: F(i)=max{x i (p.i -b),0}; where i is the ordinal number of the candidate character, F(i) is the function value corresponding to the i-th candidate character, and x i is the character output probability of the i-th candidate character, p si is the compliance probability of the i-th candidate character, and b is the threshold parameter. In this way, the output probability of candidate characters with a lower compliance probability can be reduced, thereby reducing the possibility of obtaining candidate characters with a lower compliance probability in subsequent sampling, and improving the security compliance of the text model generation results.
[0121] In the embodiment of the present application, the above text model error correction method may further include the following steps 126 and 128:
[0122] Step 126: Determine the sampling probability of each candidate character according to the adjusted character output probability of each candidate character.
[0123] Specifically, in the text model error correction method provided in the embodiment of the present application, after adjusting the probability value of the character output probability of each candidate character, based on the target sampling algorithm, the candidate characters are sampled according to the adjusted character output probability of each candidate character to obtain the sampling probability of each candidate character. In this way, the candidate characters are sampled according to the adjusted character output probability of the candidate characters, which reduces the possibility of sampling to obtain non-compliant characters and improves the compliance of the text model generation result.
[0124] Among them, the target sampling algorithm includes but is not limited to the above-mentioned topk sampling algorithm, Topm sampling algorithm and temperature sampling algorithm. For the specific type of the target sampling algorithm, technical personnel in this field can select it according to actual conditions, and no specific limitation is made here.
[0125] For example, taking the temperature sampling algorithm as an example, the probability distribution of the target sampling algorithm is Where T is the temperature coefficient, i and j represent the order of candidate characters, wi represents the i-th candidate character, M represents the total number of candidate characters, and p wi represents the sampling probability of the i-th candidate character, X i represents the adjusted character output probability of the i-th candidate character, X j represents the adjusted character output probability of the jth candidate character. On this basis, when the temperature coefficient T is 0.1, the number of candidate characters is 3, and e is an approximate value of 2.72, if the adjusted character output probabilities of the three candidate characters are 0.242, 0.435, and 0.323 respectively, according to the above probability distribution, the sampling probability of the first candidate character can be calculated as:
[0126]
[0127] The sampling probability of the second candidate character is:
[0128]
[0129] The sampling probability of the second candidate character is:
[0130]
[0131] Step 128: Determine the character to be output from at least two candidate characters according to the sampling probability of each candidate character.
[0132] Specifically, in the text model error correction method provided in the embodiment of the present application, after sampling at least two candidate characters and obtaining the sampling probability of each candidate character, the character to be output is selected from at least two candidate characters according to the sampling probability of each candidate character as the final character output result of the text model, such as determining the candidate character with the highest sampling probability as the character to be output and outputting it. On this basis, the above information of the character to be output and the character string to be detected is used as new input information of the text model based on the autoregressive method, and the next character is continuously generated in the above manner until the text model generates the end character and obtains a complete response of the text model. In this way, based on the corrected character output probability of each candidate character, the candidate characters are sampled, which reduces the possibility of sampling to obtain candidate characters with a lower compliance probability, and improves the security compliance of the text model generation results.
[0133] In the above embodiment provided by the present application, the sampling probability of each candidate character is determined according to the adjusted character output probability of each candidate character; and the character to be output is determined from at least two candidate characters according to the sampling probability of each candidate character. In this way, based on the corrected character output probability of each candidate character, the candidate characters are sampled, which reduces the possibility of sampling to obtain candidate characters with a lower compliance probability, and improves the security compliance of the text model generation result.
[0134] In summary, the traditional text model generates text in an autoregressive manner one character at a time. When generating each character, the output probability of all possible candidate characters is calculated by the internal parameters of the text model, and then sampling is performed based on the output probability of each candidate character to obtain the final output result. In the text model error correction method provided in the embodiment of the present application, Figure 2As shown, an error correction module 310 is added. In the process of sampling and outputting characters by the text model 308, after the problem content is found, the error correction module 310 will be entered, and the candidate characters generated by the text model 308 based on the above text will be input into the compliance prediction model 312, so as to predict the compliance probability of the candidate characters that may be output at present through the compliance prediction model 312, and then the initial character output probability of the candidate characters will be adjusted based on the compliance probability of the candidate characters, so as to reduce the character output probability of the non-compliant characters and obtain the new character output probability of the candidate characters. On this basis, sampling is performed based on the adjusted character output probability of each candidate character to obtain the final output result. In this way, on the one hand, in the process of generating a reply by the text model, after detecting that the text model generates an non-compliant sentence, the non-compliant sentence is immediately corrected and rewritten, avoiding rewriting the problem segment after the text model generates a large segment of reply, improving the efficiency and real-time performance of error correction of the generated result of the text model, saving computing power, and, by directly correcting the error in the link of outputting characters by the text model, the text model can reply to the problem more quickly and efficiently, shortening the waiting time of the user. On the other hand, since the error correction module reduces the character output probability of non-compliant characters through directionality, after passing through the error correction module, the text model will sample normal characters with a higher character output probability. The text semantics generated after error correction are more coherent and smooth, and the coherence of contextual semantics can be taken into account while generating content that is safe and compliant.
[0135] That is to say, the structural framework of the text model error correction method provided in the embodiment of the present application may specifically include a text model, a detection module and an error correction module, the detection module includes the above detection model, and the error correction module includes the above compliance prediction model. On this basis, Figure 8 As shown, the text model error correction method provided in the embodiment of the present application may specifically include the following steps 402 to 418:
[0136] Step 402: The user inputs a question.
[0137] Step 404: The text model generates characters one by one.
[0138] Step 406: according to the order in which the text model generates the characters, the character type of each character generated by the text model is detected in turn.
[0139] Step 408: When a sentence character is detected for the first time, all characters generated by the text model are determined as the character string to be detected. When a sentence character is detected for the Nth time, the character string consisting of all characters between the sentence character detected for the N-1th time and the sentence character detected for the Nth time is determined as the character string to be detected.
[0140] Step 410: Call the detection model in the detection module to perform compliance detection on the character string to be detected.
[0141] Step 412: Determine: the detection result of the character string to be detected is compliant. If so, execute step 416; if not, execute step 414.
[0142] Step 414: Call the compliance prediction model in the text model and error correction module to rewrite the character string to be detected.
[0143] Step 416: Determine: the text model generation is completed, if yes, execute step 418, if no, execute step 404.
[0144] Step 418: Output the reply result.
[0145] Specifically, in the text model error correction method provided in the embodiment of the present application, in the process of the text model generating a reply, the detection module is used to detect the sentences generated by the text model in real time. When the sentences generated by the text model are judged as non-compliant by the detection module, such as when it is detected that the sentences generated by the text model have security compliance risks, the error correction module is entered to rewrite the non-compliant sentences, and the text model is controlled to continue to generate correct content. In the case where the detection result of the sentence generated by the text model is normal and the text model has not been completed, the sentence generated by the text model is used as the above information to control the text model to continue to generate a reply, and in the case where the detection result of the sentence generated by the text model is normal and the text model is completed, the generation result of the text model is output to the user.
[0146] In actual application, the detection module may further include a character judgment unit and a storage unit. The character judgment unit is used to judge whether the text model has generated a complete sentence and whether the text model has completed the generation of all replies. Furthermore, the storage unit is used to store the content generated by the text model and the classification results of the detection model on the sentences generated by the text model.
[0147] For example, Figure 6 As shown, through the text model error correction method provided by the embodiment of the present application, the user input information 204, i.e., "I met an XX today and I am in a bad mood," entered by the user in the voice assistant interface 202 is replied, and the reply information 206, i.e., "As an AI, I cannot use vulgar language. However, sometimes we are indeed influenced by others," is output to the user. Among them, "XX" refers to the swear words entered by the user in the voice assistant interface 202.
[0148] Among them, Figure 7As shown, during the process of the text model generating a response, the text model generates characters one by one based on an autoregressive manner until the text model generates the first string 302, namely "As an AI, I cannot use vulgar language." After that, when it is detected that the currently generated character by the text model is a clause-separating character, it is determined that the text model has generated a complete sentence, and it enters the detection module. The detection model performs compliance detection on the first string 302 generated by the text model, namely "As an AI, I cannot use vulgar language.", and outputs the detection result as compliant. On this basis, the text model continues to generate the second string 304, namely "However, XXs do cause trouble to people." for this string, and performs compliance detection on the second string 304 again, obtaining a detection result of non-compliance. At this time, it enters the error correction module, takes the first string 302, namely "As an AI, I cannot use vulgar language.", as the input of the text model to rewrite the second string 304, namely "However, XXs do cause trouble to people.", and generates the third string 306, namely "However, sometimes we are indeed influenced by others." This sentence, and displays the generated first string 302 and the third string 306 as the response information to the user.
[0149] Among them, during the process of rewriting "However, XXs do cause trouble to people.", as Figure 4 shown, since the compliance probabilities of the three characters "but", "is", and "," are relatively high, and the output probabilities of these three characters are still relatively high after passing through the error correction module, the first three characters regenerated by the text model are still the three characters "However,". Further, the text model regenerates the fourth character w 4 , the fourth character w 4 's candidate characters and their initial character output probabilities x i are as shown in Table 3 below. Among them, Table 3 is an example table of the initial character output probabilities of each candidate character during the process of generating the fourth character.
[0150] Table 3
[0151] <![CDATA[The fourth character is w 4 (Candidate character)]]> <![CDATA[Initial character output probability x i > mix 0.38 have 0.27 I 0.19
[0152] Among them, i represents the order number of the candidate character, and the value of i can be any integer between 1 and the size of the character table. For the convenience of display and calculation, in Table 3, i is taken as the maximum value of 3 for example.
[0153] Further, as Figure 4 shown, for the content already generated by the text model, "As an AI, I cannot use vulgar language. However," and the fourth character w to be generated 4Combine each candidate character to obtain the input information corresponding to each candidate character, and input the input information corresponding to each candidate character into the compliance prediction model to obtain the compliance probability p of the candidate character "混" s1 = 0.65, the compliance probability p of the candidate character "有" s2 = 0.88, the compliance probability p of the candidate character "我" s3 = 0.90.
[0154] Further, taking the threshold parameter b as 0.5 as an example, according to the above first formula, based on the character output probability and compliance probability of each candidate character, correct the character output probability of each candidate character to obtain the adjusted character output probability of each candidate character, as shown in Table 4 below, where Table 4 is an example table of the adjusted character output probability of each candidate character.
[0155] Table 4
[0156] <![CDATA[The fourth character is w 4 (Candidate character)]]> <![CDATA[Adjusted Character Output Probability X i > mix 0.242 have 0.435 I 0.323
[0157] As shown in Table 3 and Table 4, after passing through the error correction module, the character output probability of the candidate character "混" changes from 0.38 to 0.242, the character output probability of the candidate character "有" changes from 0.27 to 0.435, and the character output probability of the candidate character "我" changes from 0.19 to 0.323. It can be seen that the character output probability of the candidate character "混" with a relatively low compliance probability is reduced, while the character output probabilities of the candidate characters "有" and "我" with relatively high compliance probabilities are increased, reducing the possibility of obtaining the candidate character "混" with a small compliance probability in subsequent sampling.
[0158] Further, taking the temperature coefficient as 0.1 and e taking the approximate value of 2.72 as an example, based on the temperature sampling algorithm, sample the candidate characters according to the adjusted character output probability of each candidate character to obtain the sampling probability p of the candidate character "混" w1 = 0.099, the sampling probability p of the candidate character "有" w2 = 0.680, the sampling probability p of the candidate character "我" w3 = 0.221. On this basis, select the candidate character "有" with the highest sampling probability as the fourth character w 4 , and continue to generate the next character according to the above process until the text model generates the complete sentence "However, sometimes we are indeed influenced by others.", detect that the text model generates the end symbol, determine that the text model generation ends, and display the final generation result of the text model "As an AI, I cannot use vulgar language. However, sometimes we are indeed influenced by others." to the user.
[0159] In addition, it should be noted that the method of adding an error correction module to intervene in the text model output sampling stage proposed in the embodiment of the present application can also be used in other scenarios that require directional adjustment of the text model output results. For example, for a scenario where the text model generates a specific stylized response, a corresponding stylized correction module can be added to increase the sampling probability of text in the corresponding style, so that the text model can better generate text in the corresponding style. Based on personalized needs, those skilled in the art can also flexibly train some small models applied to text output scenarios according to the method of directional adjustment of character output probability proposed in the embodiment of the present application to assist the text model in outputting text that meets the needs and has characteristics such as high efficiency and content semantic coherence.
[0160] The text model error correction method provided in the embodiment of the present application can be executed by a text model error correction device. In the embodiment of the present application, the text model error correction device provided in the embodiment of the present application is described by taking the text model error correction device executing the above text model error correction method as an example.
[0161] like Fig. 9 As shown, an embodiment of the present application provides a text model error correction device 500, which may include the following processing module 502.
[0162] A processing module 502 is used to output compliance probabilities of at least two candidate characters based on the character string to be detected and the compliance prediction model when the character string to be detected is not compliant, where the candidate characters are generated according to text information input into the text model during the process of generating the character string to be detected;
[0163] The processing module 502 is further configured to adjust the character output probability of each candidate character according to the compliance probability of each candidate character in the at least two candidate characters.
[0164] The text model error correction device 500 provided in the embodiment of the present application, when the character string to be detected is not compliant, outputs the compliance probability of at least two candidate characters based on the character string to be detected and the compliance prediction model, the candidate characters are generated according to the text information input into the text model in the process of generating the character string to be detected; according to the compliance probability of each candidate character in the at least two candidate characters, adjust the character output probability of each candidate character. Through the above-mentioned text model error correction device 500, when the generated content of the text model is not compliant, the text model is controlled to regenerate new content, and, in the process of generating new content, the compliance probability of each candidate character generated by the text model is calculated by the compliance prediction model, and the character output probability of each candidate character output by the text model is corrected according to the compliance probability of each candidate character. In this way, in the process of outputting characters by the text model, the output probability of non-compliant characters can be reduced, and the output probability of compliant characters can be increased, thereby improving the security compliance of the text model generation result and preventing users from receiving inappropriate information.
[0165] In an embodiment of the present application, the text model error correction device 500 also includes: a detection module 504, which is used to detect the character type of each character generated by the text model in sequence according to the order in which the text model generates the characters; the processing module 502 is also used to: when a sentence character is detected for the first time, all characters generated by the text model are determined as the string to be detected; when a sentence character is detected for the Nth time, the string composed of all characters between the sentence character detected for the N-1th time and the sentence character detected for the Nth time is determined as the string to be detected, where N is a positive integer greater than 1; the detection module 504 is also used to perform compliance detection on the string to be detected through the detection model.
[0166] The above-mentioned embodiment provided by the present application detects the character type of each character generated by the text model in sequence according to the order in which the text model generates characters; when a sentence character is detected for the first time, all characters generated by the text model are determined as the string to be detected; when a sentence character is detected for the Nth time, the string composed of all characters between the sentence character detected for the N-1th time and the sentence character detected for the Nth time is determined as the string to be detected, where N is a positive integer greater than 1; the string to be detected is subjected to compliance detection through the detection model. In this way, after it is detected that the text model generates an illegal sentence, the illegal sentence is immediately corrected and rewritten, which improves the efficiency and real-time performance of error correction of the generated result of the text model and saves computing power. In addition, error correction is performed at the link of outputting characters by the text model, so that the text model can reply to questions more quickly and efficiently, shortening the waiting time of users.
[0167] In an embodiment of the present application, the processing module 502 is specifically used to: input the text information input into the text model in the process of generating the character string to be detected into the text model again, and output at least two candidate characters; determine the input information corresponding to each candidate character based on the text information, and the input information is obtained by splicing each candidate character with the text information; input the input information corresponding to each candidate character into the compliance prediction model, and output the compliance probability of each candidate character.
[0168] In the above-mentioned embodiment provided by the present application, in the process of outputting the compliance probabilities of at least two candidate characters based on the character string to be detected and the compliance prediction model, the text information input into the text model in the process of generating the character string to be detected is input into the text model again, and at least two candidate characters are output; the input information corresponding to each candidate character is determined based on the text information, and the input information is obtained by splicing each candidate character with the text information; the input information corresponding to each candidate character is input into the compliance prediction model, and the compliance probability of each candidate character is output. In this way, the compliance of the candidate character is determined in combination with the context of the candidate character, which ensures the accuracy of determining the compliance probability of the candidate character.
[0169] In an embodiment of the present application, the processing module 502 is also used to: input the training sample into the text model, and output the character output probability of each candidate character corresponding to each training sample; when the combination information of the training sample and the corresponding candidate character is compliant, the sum of the output probabilities of the corresponding candidate characters is determined as the labeling value of the training sample, and the combination information is the concatenation of each candidate character and the training sample; according to the target loss function, the labeling value of each training sample and the predicted value of each training sample, the compliant prediction model is trained to obtain a trained compliant prediction model.
[0170] In the above-mentioned embodiment provided by the present application, the training samples are input into the text model, and the character output probability of each candidate character corresponding to each training sample is output; when the combination information of the training sample and the corresponding candidate character is compliant, the sum of the output probabilities of the corresponding candidate characters is determined as the labeling value of the training sample, and the combination information is obtained by splicing each candidate character with the training sample; according to the target loss function, the labeling value of each training sample and the predicted value of each training sample, the compliance prediction model is trained to obtain the trained compliance prediction model. In this way, the training samples are labeled in combination with the context of the training samples and then the compliance prediction model is trained, which ensures the accuracy of labeling the training samples and then ensures the accuracy of training the compliance prediction model.
[0171] In the embodiment of the present application, the processing module 502 is specifically used to: according to the first formula, according to the compliance probability of each candidate character, adjust the probability value of the character output probability of each candidate character; wherein the second formula is: F(i)=max{xi (p .i -b),0}; where i is the ordinal number of the candidate character, F(i) is the function value corresponding to the i-th candidate character, and x i is the character output probability of the i-th candidate character, p si is the compliance probability of the i-th candidate character, and b is the threshold parameter.
[0172] In the above-mentioned embodiment provided by the present application, in the process of adjusting the character output probability of each candidate character according to the compliance probability of each candidate character in at least two candidate characters, the probability value of the character output probability of each candidate character is adjusted according to the compliance probability of each candidate character according to the first formula; wherein the first formula is obtained by normalizing the second formula, and the second formula is: F(i)=max{x i (p .i -b),0}; where i is the ordinal number of the candidate character, F(i) is the function value corresponding to the i-th candidate character, and x i is the character output probability of the i-th candidate character, p si is the compliance probability of the i-th candidate character, and b is the threshold parameter. In this way, the output probability of candidate characters with a lower compliance probability can be reduced, thereby reducing the possibility of obtaining candidate characters with a lower compliance probability in subsequent sampling, and improving the security compliance of the text model generation results.
[0173] In the embodiment of the present application, the processing module 502 is further used to: determine the sampling probability of each candidate character according to the adjusted character output probability of each candidate character; and determine the character to be output from at least two candidate characters according to the sampling probability of each candidate character.
[0174] In the above embodiment provided by the present application, the sampling probability of each candidate character is determined according to the adjusted character output probability of each candidate character; and the character to be output is determined from at least two candidate characters according to the sampling probability of each candidate character. In this way, based on the corrected character output probability of each candidate character, the candidate characters are sampled, which reduces the possibility of sampling to obtain candidate characters with a lower compliance probability, and improves the security compliance of the text model generation result.
[0175] The text model error correction device 500 in the embodiment of the present application can be an electronic device, or a component in the electronic device, such as an integrated circuit or a chip. The electronic device can be a terminal, or other devices other than the terminal. Exemplarily, the electronic device can be a mobile phone, a tablet computer, a laptop computer, a palmtop computer, a vehicle-mounted electronic device, a mobile Internet device (Mobile Internet Device, MID), an augmented reality (augmented reality, AR) / virtual reality (virtual reality, VR) device, a robot, a wearable device, an ultra-mobile personal computer (ultra-mobile personal computer, UMPC), a netbook or a personal digital assistant (personal digital assistant, PDA), etc., and can also be a server, a network attached storage (Network Attached Storage, NAS), a personal computer (personal computer, PC), a television (television, TV), a teller machine or a self-service machine, etc., which is not specifically limited in the embodiment of the present application.
[0176] The text model error correction device 500 in the embodiment of the present application may be a device having an operating system. The operating system may be an Android operating system, an iOS operating system, or other possible operating systems, which are not specifically limited in the embodiment of the present application.
[0177] The text model error correction device 500 provided in the embodiment of the present application can achieve Figure 1 and Figure 8 To avoid repetition, the various processes implemented by the method embodiment are not described here.
[0178] Alternatively, if Fig.10 As shown, an embodiment of the present application also provides an electronic device 600, including a processor 602 and a memory 604, wherein the memory 604 stores programs or instructions that can be executed on the processor 602, and when the program or instructions are executed by the processor 602, the various steps of the above-mentioned text model error correction method embodiment are implemented, and the same technical effect can be achieved. To avoid repetition, they are not described here.
[0179] It should be noted that the electronic devices in the embodiments of the present application include the above-mentioned mobile electronic devices and non-mobile electronic devices.
[0180] Fig.11 A schematic diagram of the hardware structure of an electronic device to implement an embodiment of the present application.
[0181] The electronic device 700 includes but is not limited to: a radio frequency unit 701, a network module 702, an audio output unit 703, an input unit 704, a sensor 705, a display unit 706, a user input unit 707, an interface unit 708, a memory 709, a processor 710 and other components.
[0182] Those skilled in the art will appreciate that the electronic device 700 may also include a power source (such as a battery) for supplying power to each component, and the power source may be logically connected to the processor 710 through a power management system, thereby implementing functions such as managing charging, discharging, and power consumption management through the power management system. Fig.11 The electronic device structure shown in the figure does not constitute a limitation on the electronic device. The electronic device may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently, which will not be described in detail here.
[0183] Among them, the processor 710 is used to output the compliance probabilities of at least two candidate characters based on the character string to be detected and the compliance prediction model when the character string to be detected is not compliant. The candidate characters are generated according to the text information input into the text model during the process of generating the character string to be detected.
[0184] The processor 710 is further configured to adjust the character output probability of each candidate character according to the compliance probability of each candidate character in the at least two candidate characters.
[0185] In an embodiment of the present application, when the character string to be detected is not compliant, based on the character string to be detected and the compliance prediction model, the compliance probabilities of at least two candidate characters are output, and the candidate characters are generated according to the text information input into the text model in the process of generating the character string to be detected; according to the compliance probability of each candidate character in the at least two candidate characters, the character output probability of each candidate character is adjusted. In an embodiment of the present application, when the generated content of the text model is not compliant, the text model is controlled to regenerate new content, and in the process of generating new content, the compliance probability of each candidate character generated by the text model is calculated by the compliance prediction model, and the character output probability of each candidate character output by the text model is corrected according to the compliance probability of each candidate character. In this way, in the process of outputting characters by the text model, the output probability of non-compliant characters can be reduced, and the output probability of compliant characters can be increased, thereby improving the security compliance of the text model generation results and preventing users from receiving inappropriate information.
[0186] Optionally, the processor 710 is also used to: detect the character type of each character generated by the text model in sequence in the order in which the text model generates the characters; when a sentence character is detected for the first time, determine all characters generated by the text model as the string to be detected; when a sentence character is detected for the Nth time, determine the string consisting of all characters between the sentence character detected for the N-1th time and the sentence character detected for the Nth time as the string to be detected, where N is a positive integer greater than 1; the detection module 504 is also used to perform compliance detection on the string to be detected through the detection model.
[0187] The above-mentioned embodiment provided by the present application detects the character type of each character generated by the text model in sequence according to the order in which the text model generates characters; when a sentence character is detected for the first time, all characters generated by the text model are determined as the string to be detected, and when a sentence character is detected for the Nth time, the string composed of all characters between the sentence character detected for the N-1th time and the sentence character detected for the Nth time is determined as the string to be detected, where N is a positive integer greater than 1; the detection module 504 is also used to perform compliance detection on the string to be detected through the detection model. In this way, after it is detected that the text model generates an illegal sentence, the illegal sentence is immediately corrected and rewritten, which improves the efficiency and real-time performance of error correction of the generated result of the text model and saves computing power. In addition, error correction is performed at the link of outputting characters by the text model, so that the text model can reply to questions more quickly and efficiently, shortening the waiting time of users.
[0188] Optionally, the processor 710 is specifically used to: input text information input into the text model during the process of generating the character string to be detected into the text model again, and output at least two candidate characters; determine the input information corresponding to each candidate character based on the text information, and the input information is obtained by concatenating each candidate character with the text information; input the input information corresponding to each candidate character into the compliance prediction model, and output the compliance probability of each candidate character.
[0189] In the above-mentioned embodiment provided by the present application, in the process of outputting the compliance probabilities of at least two candidate characters based on the character string to be detected and the compliance prediction model, the text information input into the text model in the process of generating the character string to be detected is input into the text model again, and at least two candidate characters are output; the input information corresponding to each candidate character is determined based on the text information, and the input information is obtained by splicing each candidate character with the text information; the input information corresponding to each candidate character is input into the compliance prediction model, and the compliance probability of each candidate character is output. In this way, the compliance of the candidate character is determined in combination with the context of the candidate character, which ensures the accuracy of determining the compliance probability of the candidate character.
[0190] Optionally, the processor 710 is also used to: input the training sample into the text model, and output the character output probability of each candidate character corresponding to each training sample; when the combination information of the training sample and the corresponding candidate character is compliant, the sum of the output probabilities of the corresponding candidate characters is determined as the labeling value of the training sample, and the combination information is the concatenation of each candidate character and the training sample; according to the target loss function, the labeling value of each training sample and the predicted value of each training sample, the compliant prediction model is trained to obtain a trained compliant prediction model.
[0191] In the above-mentioned embodiment provided by the present application, the training samples are input into the text model, and the character output probability of each candidate character corresponding to each training sample is output; when the combination information of the training sample and the corresponding candidate character is compliant, the sum of the output probabilities of the corresponding candidate characters is determined as the labeling value of the training sample, and the combination information is obtained by splicing each candidate character with the training sample; according to the target loss function, the labeling value of each training sample and the predicted value of each training sample, the compliance prediction model is trained to obtain the trained compliance prediction model. In this way, the training samples are labeled in combination with the context of the training samples and then the compliance prediction model is trained, which ensures the accuracy of labeling the training samples and then ensures the accuracy of training the compliance prediction model.
[0192] Optionally, the processor 710 is specifically configured to: adjust the probability value of the character output probability of each candidate character according to the compliance probability of each candidate character according to the first formula; wherein the second formula is: F(i)=max{x i (p .i -b),0}; where i is the ordinal number of the candidate character, F(i) is the function value corresponding to the i-th candidate character, and x i is the character output probability of the i-th candidate character, p si is the compliance probability of the i-th candidate character, and b is the threshold parameter.
[0193] In the above-mentioned embodiment provided by the present application, in the process of adjusting the character output probability of each candidate character according to the compliance probability of each candidate character in at least two candidate characters, the probability value of the character output probability of each candidate character is adjusted according to the compliance probability of each candidate character according to the first formula; wherein the first formula is obtained by normalizing the second formula, and the second formula is: F(i)=max{x i (p .i -b),0}; where i is the ordinal number of the candidate character, F(i) is the function value corresponding to the i-th candidate character, and x i is the character output probability of the i-th candidate character, p siis the compliance probability of the i-th candidate character, and b is the threshold parameter. In this way, the output probability of candidate characters with a lower compliance probability can be reduced, thereby reducing the possibility of obtaining candidate characters with a lower compliance probability in subsequent sampling, and improving the security compliance of the text model generation results.
[0194] Optionally, the processor 710 is further configured to: determine a sampling probability of each candidate character according to the adjusted character output probability of each candidate character; and determine a character to be output from at least two candidate characters according to the sampling probability of each candidate character.
[0195] In the above embodiment provided by the present application, the sampling probability of each candidate character is determined according to the adjusted character output probability of each candidate character; and the character to be output is determined from at least two candidate characters according to the sampling probability of each candidate character. In this way, based on the corrected character output probability of each candidate character, the candidate characters are sampled, which reduces the possibility of sampling to obtain candidate characters with a lower compliance probability, and improves the security compliance of the text model generation result.
[0196] It should be understood that in the embodiment of the present application, the input unit 704 may include a graphics processor (Graphics Processing Unit, GPU) 7041 and a microphone 7042, and the graphics processor 7041 processes the image data of the static picture or video obtained by the image capture device (such as a camera) in the video capture mode or the image capture mode. The display unit 706 may include a display panel 7061, and the display panel 7061 may be configured in the form of a liquid crystal display, an organic light emitting diode, etc. The user input unit 707 includes a touch panel 7071 and at least one of other input devices 7072. The touch panel 7071 is also called a touch screen. The touch panel 7071 may include two parts: a touch detection device and a touch controller. Other input devices 7072 may include, but are not limited to, a physical keyboard, function keys (such as volume control keys, switch keys, etc.), a trackball, a mouse, and a joystick, which will not be repeated here.
[0197] The memory 709 can be used to store software programs and various data. The memory 709 may mainly include a first storage area for storing programs or instructions and a second storage area for storing data, wherein the first storage area may store an operating system, an application program or instructions required for at least one function (such as a sound playback function, an image playback function, etc.), etc. In addition, the memory 709 may include a volatile memory or a non-volatile memory, or the memory 709 may include both volatile and non-volatile memories. Among them, the non-volatile memory may be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory may be a random access memory (RAM), a static random access memory (SRAM), a dynamic random access memory (DRAM), a synchronous dynamic random access memory (SDRAM), a double data rate synchronous dynamic random access memory (DDRSDRAM), an enhanced synchronous dynamic random access memory (ESDRAM), a synchronous link dynamic random access memory (SLDRAM) and a direct memory bus random access memory (DRRAM). The memory 709 in the embodiment of the present application includes but is not limited to these and any other suitable types of memory.
[0198] The processor 710 may include one or more processing units; optionally, the processor 710 integrates an application processor and a modem processor, wherein the application processor mainly processes operations related to an operating system, a user interface, and application programs, and the modem processor mainly processes wireless communication signals, such as a baseband processor. It is understandable that the modem processor may not be integrated into the processor 710.
[0199] An embodiment of the present application also provides a readable storage medium, on which a program or instruction is stored. When the program or instruction is executed by a processor, each process of the above-mentioned text model error correction method embodiment is implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.
[0200] The processor is the processor in the electronic device in the above embodiment. The readable storage medium includes a computer readable storage medium, such as a computer read-only memory ROM, a random access memory RAM, a magnetic disk or an optical disk.
[0201] An embodiment of the present application further provides a chip, which includes a processor and a communication interface, wherein the communication interface and the processor are coupled, and the processor is used to run programs or instructions to implement the various processes of the above-mentioned text model error correction method embodiment, and can achieve the same technical effect. To avoid repetition, it will not be repeated here.
[0202] It should be understood that the chip mentioned in the embodiments of the present application can also be called a system-level chip, a system chip, a chip system or a system-on-chip chip, etc.
[0203] An embodiment of the present application provides a computer program product, which is stored in a storage medium. The program product is executed by at least one processor to implement the various processes of the above-mentioned text model error correction method embodiment, and can achieve the same technical effect. To avoid repetition, it will not be repeated here.
[0204] It should be noted that, in this article, the terms "comprise", "include" or any other variant thereof are intended to cover non-exclusive inclusion, so that the process, method, article or device including a series of elements includes not only those elements, but also includes other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise one..." do not exclude the presence of other identical elements in the process, method, article or device including the element. In addition, it should be pointed out that the scope of the methods and devices in the embodiments of the present application is not limited to performing functions in the order shown or discussed, and may also include performing functions in a substantially simultaneous manner or in reverse order according to the functions involved, for example, the described method may be performed in an order different from that described, and various steps may also be added, omitted, or combined. In addition, the features described with reference to certain examples may be combined in other examples.
[0205] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a computer software product, which is stored in a storage medium (such as ROM / RAM, a disk, or an optical disk), and includes a number of instructions for a terminal (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods of each embodiment of the present application.
[0206] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of the present application, ordinary technicians in this field can also make many forms without departing from the purpose of the present application and the scope of protection of the claims, all of which are within the protection of the present application.
Claims
1. A text model error correction method, characterized in that: include: In the case where the character string to be detected is not compliant, outputting compliance probabilities of at least two candidate characters based on the character string to be detected and the compliance prediction model, wherein the candidate characters are generated according to text information input into the text model during the process of generating the character string to be detected; According to the compliance probability of each candidate character in the at least two candidate characters, the character output probability of each candidate character is adjusted.
2. The text model error correction method according to claim 1, characterized in that: The step of outputting compliance probabilities of at least two candidate characters based on the character string to be detected and the compliance prediction model includes: Inputting text information input into the text model in the process of generating the character string to be detected into the text model again, and outputting at least two candidate characters; Determine input information corresponding to each candidate character according to the text information, wherein the input information is obtained by concatenating each candidate character with the text information; The input information corresponding to each of the candidate characters is input into the compliance prediction model, and the compliance probability of each of the candidate characters is output.
3. The text model error correction method according to claim 1, characterized in that: The error correction method further comprises: Input the training samples into the text model, and output the character output probability of each candidate character corresponding to each training sample; In the case where the combination information of the training sample and the corresponding candidate character complies with the requirements, the sum of the character output probabilities of the corresponding candidate character is determined as the label value of the training sample, wherein the combination information is obtained by concatenating each candidate character with the training sample; The compliance prediction model is trained according to the target loss function, the labeled value of each training sample and the predicted value of each training sample to obtain a trained compliance prediction model.
4. The text model error correction method according to claim 1, characterized in that: The step of adjusting the character output probability of each candidate character according to the compliance probability of each candidate character in the at least two candidate characters comprises: According to the first formula, the probability value of the character output probability of each candidate character is adjusted according to the compliance probability of each candidate character; The first formula is obtained by normalizing the second formula, and the second formula is: F(i)=max{x i (p si -b),0}; Among them, i is the ordinal number of the candidate character, F(i) is the function value corresponding to the i-th candidate character, and x i is the character output probability of the i-th candidate character, p si is the compliance probability of the i-th candidate character, and b is the threshold parameter.
5. The text model error correction method according to any one of claims 1 to 4, characterized in that: The error correction method further comprises: Determine the sampling probability of each candidate character according to the adjusted character output probability of each candidate character; According to the sampling probability of each candidate character, a character to be output is determined from the at least two candidate characters.
6. The text model error correction method according to any one of claims 1 to 4, characterized in that: The error correction method further comprises: According to the order in which the text model generates the characters, the character type of each character generated by the text model is detected in sequence; When a sentence character is detected for the first time, all characters generated by the text model are determined as the character string to be detected; In the case where a sentence character is detected for the Nth time, a character string consisting of all characters between the sentence character detected for the N-1th time and the sentence character detected for the Nth time is determined as the character string to be detected, where N is a positive integer greater than 1; The character string to be detected is subjected to compliance detection by means of the detection model.
7. A text model error correction device, characterized in that: include: a processing module, configured to output compliance probabilities of at least two candidate characters based on the character string to be detected and a compliance prediction model when the character string to be detected is non-compliant, wherein the candidate characters are generated according to text information input into the text model during the process of generating the character string to be detected; The processing module is further configured to adjust the character output probability of each candidate character according to the compliance probability of each candidate character in the at least two candidate characters.
8. The text model error correction device according to claim 7, characterized in that: The processing module is specifically used for: Inputting text information input into the text model in the process of generating the character string to be detected into the text model again, and outputting at least two candidate characters; Determine input information corresponding to each candidate character according to the text information, wherein the input information is obtained by concatenating each candidate character with the text information; The input information corresponding to each of the candidate characters is input into the compliance prediction model, and the compliance probability of each of the candidate characters is output.
9. The text model error correction device according to claim 7, characterized in that: The processing module is also used for: Inputting training samples into the text model, and outputting the character output probability of each candidate character corresponding to each training sample; In the case where the combination information of the training sample and the corresponding candidate character complies with the requirements, the sum of the character output probabilities of the corresponding candidate character is determined as the label value of the training sample, wherein the combination information is obtained by concatenating each candidate character with the training sample; The compliance prediction model is trained according to the target loss function, the labeled value of each training sample and the predicted value of each training sample to obtain a trained compliance prediction model.
10. The text model error correction device according to claim 7, characterized in that: The processing module is specifically used for: According to the first formula, the probability value of the character output probability of each candidate character is adjusted according to the compliance probability of each candidate character; The first formula is obtained by normalizing the second formula, and the second formula is: F(i)=max{x i (p si -b),0}; Among them, i is the ordinal number of the candidate character, F(i) is the function value corresponding to the i-th candidate character, and x i is the character output probability of the i-th candidate character, p si is the compliance probability of the i-th candidate character, and b is the threshold parameter.
11. The text model error correction device according to any one of claims 7 to 10, characterized in that: The processing module is also used for: Determine the sampling probability of each candidate character according to the adjusted character output probability of each candidate character; According to the sampling probability of each candidate character, a character to be output is determined from the at least two candidate characters.
12. The text model error correction device according to any one of claims 7 to 10, characterized in that: The error correction device also includes: A detection module, used to detect the character type of each character generated by the text model in sequence according to the order in which the text model generates the characters; The processing module is further configured to, when a sentence character is detected for the first time, determine all characters generated by the text model as the character string to be detected, and when a sentence character is detected for the Nth time, determine a character string consisting of all characters between the sentence character detected for the N-1th time and the sentence character detected for the Nth time as the character string to be detected, wherein N is a positive integer greater than 1; The detection module is further used to perform compliance detection on the character string to be detected through a detection model.
13. An electronic device, characterized in that: It comprises a processor and a memory, wherein the memory stores programs or instructions that can be run on the processor, and when the programs or instructions are executed by the processor, the steps of the text model error correction method as described in any one of claims 1 to 6 are implemented.
