Text generation method and device, electronic equipment and medium
Through the text repair model, the initial text generated by the language model is solved, and the problem of difficulty in designing a lightweight and efficient text generation control scheme in the prior art is achieved, so that the generated text meets the attribute requirements, while maintaining low resource overhead.
Patent Information
- Application Number
- CN202311645945.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-01
- Publication Date
- 2025-06-03
AI Technical Summary
It is difficult to design a lightweight, efficient text generation control scheme with less impact on language model generation results to ensure that the generated text meets specific attribute requirements.
The text repair model determines whether the initial text generated by the target language model matches the preconfigured attribute requirements. If it does not match, determine the attribute-related fragment in the initial text that causes attribute mismatch, and replace it with the text repair fragment that meets the attribute requirements to repair the initial text.
It realizes effective control over text generated by the language model, ensures that the generated text meets specific attribute requirements, while maintaining the characteristics of lightweight, efficient and low resource overhead.
Smart Images

Figure CN120087336A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of text processing, and in particular, to a text generation method, apparatus, electronic device, and medium. Background Art
[0002] With the remarkable capabilities demonstrated by large-parameter language models such as ChatGPT, more and more companies, institutions, and individuals choose to train or use them for text generation to assist in completing work. A large number of language models on the market today are trained entirely based on training datasets, and the uncertain data quality may cause the language model to generate meaningless or even harmful text, having a bad impact. Text generation control refers to using specific intervention modules or algorithms to help the language model generate text that meets specific attributes. Currently, how to design a lightweight, efficient, and less impactful text generation control scheme on the generation results of the language model remains a challenge. Summary of the Invention
[0003] In view of this, the purpose of the present application is to provide a text generation method, apparatus, electronic device, and medium that can control the attributes of the text generated by the language model, and is lightweight, efficient, has less impact on the distribution of the text generated by the language model, and maintains a low resource overhead.
[0004] In a first aspect, a text generation method provided by an embodiment of the present application includes:
[0005] For the initial text generated by the target language model based on the prompt information, determine whether the attributes of the initial text match the pre-configured attribute requirements through the text repair model;
[0006] If not, determine the attribute-related fragments in the initial text that cause the attribute mismatch based on the attribute requirements; the attribute-related fragments include words and / or sentences;
[0007] Replace the attribute-related fragments in the initial text with text repair fragments that meet the attribute requirements to repair the initial text and generate a target text with matching attributes.
[0008] In a second aspect, an embodiment of the present application provides a text generation apparatus, including:
[0009] A judgment module, configured to determine whether the attributes of the initial text match the pre-configured attribute requirements through the text repair model for the initial text generated by the target language model based on the prompt information;
[0010] A determination module, configured to determine the attribute-related fragments in the initial text that cause the attribute mismatch based on the attribute requirements when the attributes of the initial text do not match the pre-configured attribute requirements; the attribute-related fragments include words and / or sentences;
[0011] A repair module, configured to replace the attribute-related fragments in the initial text with text repair fragments that meet the attribute requirements, so as to repair the initial text and generate a target text that matches the attributes.
[0012] In a third aspect, an embodiment of the present application provides an electronic device, including: a processor, a memory, and a bus. The memory stores machine-readable instructions executable by the processor. When the electronic device runs, the processor communicates with the memory through the bus. When the machine-readable instructions are executed by the processor, the steps of the text generation method are executed.
[0013] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, on which a computer program is stored. When the computer program is run by a processor, the steps of the text generation method are executed.
[0014] An embodiment of the present application provides a text generation method, device, electronic device, and medium. For an initial text generated by a target language model based on prompt information, a text repair model is used to determine whether the attributes of the initial text match pre-configured attribute requirements; if not, the attribute-related fragments in the initial text that cause the attribute mismatch are determined based on the attribute requirements; the attribute-related fragments include words and / or sentences; the attribute-related fragments in the initial text are replaced with text repair fragments that meet the attribute requirements, so as to repair the initial text and generate a target text that matches the attributes. In this way, after the language model generates the initial text, subsequent control processing is performed. For a large number of texts that are normally generated and meet the attribute requirements, the method of the present application hardly incurs additional resource overhead and does not cause great interference to the normal text generation of the model. Therefore, it has little impact on the distribution of the texts generated by the language model, is lightweight and efficient, and also maintains low resource overhead. Description of the Drawings
[0015] To more clearly illustrate the technical solutions of the embodiments of the present application, the following will briefly introduce the drawings required to be used in the embodiments. It should be understood that the following drawings only show some embodiments of the present application, and therefore should not be regarded as limiting the scope. For those of ordinary skill in the art, without creative efforts, other related drawings can also be obtained based on these drawings.
[0016] Figure 1 Shows a flowchart of the text generation method described in the embodiments of the present application;
[0017] Figure 2 Shows a flowchart of another text generation method described in the embodiments of the present application;
[0018] Figure 3The flowchart of the method for determining the attribute-related fragments in the initial text that cause attribute mismatches based on the attribute requirements described in the embodiments of the present application is shown;
[0019] Figure 4 The flowchart of the method for replacing the attribute-related fragments in the initial text with text repair fragments that meet the attribute requirements in the embodiments of the present application is shown;
[0020] Figure 5 The flowchart of another text generation method described in the embodiments of the present application is shown;
[0021] Figure 6 The structural schematic diagram of the text generation device described in the embodiments of the present application is shown;
[0022] Figure 7 The structural schematic diagram of the electronic device described in the embodiments of the present application is shown. Detailed implementation manners
[0023] To make the objectives, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application. It should be understood that the accompanying drawings in the present application are only for the purposes of illustration and description, and are not used to limit the protection scope of the present application. In addition, it should be understood that the schematic drawings are not drawn in actual proportions. The flowcharts used in the present application show the operations implemented according to some embodiments of the present application. It should be understood that the operations in the flowcharts may not be implemented in sequence, and the steps without logical context relationships may be reversed or implemented simultaneously. In addition, those skilled in the art may add one or more other operations to the flowchart or remove one or more operations from the flowchart under the guidance of the content of the present application.
[0024] In addition, the described embodiments are only some embodiments of the present application, rather than all of the embodiments. The components of the embodiments of the present application usually described and illustrated in the accompanying drawings here may be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present application provided in the accompanying drawings is not intended to limit the scope of the present application claimed, but merely represents the selected embodiments of the present application. All other embodiments obtained by those skilled in the art based on the embodiments of the present application without creative efforts fall within the protection scope of the present application.
[0025] It should be noted that the term "including" will be used in the embodiments of the present application to indicate the existence of the features stated thereafter, but does not exclude the addition of other features.
[0026] As language models with a large number of parameters such as ChatGPT have demonstrated extraordinary capabilities, more and more companies, institutions, and individuals choose to train or use them for text generation to assist in completing work. A large number of language models on the market today are trained entirely based on training datasets, and the uncertain data quality may cause language models to generate meaningless or even harmful texts, having a bad impact. Text generation control refers to using specific intervention modules or algorithms to help language models generate texts that meet specific attributes. Currently, how to design a lightweight, efficient, and less impactful text generation control scheme for language model generation results remains a challenge.
[0027] One of the main existing technical solutions is to use the RLHF technique during training and fine-tune the language model using reinforcement learning techniques based on human feedback on the quality of the generated text. RLHF: Reinforcement Learning from Human Feedback is a machine learning method that uses reinforcement learning from human feedback to help fine-tune the model.
[0028] Existing technical solutions also use non-training phase solutions. For example, DExperts will try to fine-tune two targeted expert large models to help the language model determine the output; Self-debiasing will try to use the few-shot learning ability inherent in the large language model to help judge the attributes of the model output; PPLM (Plug and Play Language Model) will use an attribute model to backpropagate and offset the hidden features of the model input to help the model achieve an output that better meets the attribute requirements; FUDGE (Future Discriminators for Generation) uses Bayes' formula to directly train an attribute model to help the model control text generation.
[0029] Although using the RLHF technique for fine-tuning has significantly improved the quality of the text generated by the model, it requires a huge investment in computing resources and human resources, and it still cannot completely solve the problem that the model may generate meaningless or even harmful texts. Solutions such as DExperts and Self-debiasing use large models, and the resource overhead will still increase exponentially during the actual generation process. Although PPLM and FUDGE have a relatively low resource overhead burden, they have a large offset from the original generation distribution of the model, which may reduce the output quality of the model. In addition, the current methods are not transparent enough, making it inconvenient to understand and analyze the results.
[0030] Based on this, embodiments of the present application provide a text generation method, apparatus, electronic device, and medium. For the initial text generated by a target language model based on prompt information, it is determined by a text repair model whether the attributes of the initial text match pre-configured attribute requirements; if not, then based on the attribute requirements, attribute-related fragments that cause the attribute mismatch in the initial text are determined; the attribute-related fragments include words and / or sentences; the attribute-related fragments in the initial text are replaced with text repair fragments that meet the attribute requirements to repair the initial text and generate a target text with matching attributes. In this way, subsequent control processing is only performed after the language model generates the initial text. For a large number of texts that are normally generated to meet the attribute requirements, the technical solution of the present application hardly incurs additional resource overhead and does not cause significant interference to the normal text generation of the model. Therefore, it has a small impact on the distribution of the texts generated by the language model, is lightweight and efficient, and also maintains a low resource overhead.
[0031] Please refer to Figure 1 , Figure 1 which shows a flowchart of the text generation method according to an embodiment of the present application; please refer to Figure 1 , and the method includes the following steps S101 - S103:
[0032] S101. For the initial text generated by a target language model based on prompt information, it is determined by a text repair model whether the attributes of the initial text match pre-configured attribute requirements;
[0033] S102. If not, then based on the attribute requirements, attribute-related fragments that cause the attribute mismatch in the initial text are determined; the attribute-related fragments include words and / or sentences;
[0034] S103. The attribute-related fragments in the initial text are replaced with text repair fragments that meet the attribute requirements to repair the initial text and generate a target text with matching attributes.
[0035] The text generation method according to an embodiment of the present application locates and repairs texts generated by a target language model with non-compliant attributes. On the one hand, for a large number of texts that are normally generated to meet the attribute requirements, the technical solution of the present application hardly incurs additional resource overhead and does not cause significant interference to the normal text generation of the model, has a small impact on the distribution of the texts generated by the language model, is lightweight and efficient, and also maintains a low resource overhead. On the other hand, only the attribute-related words or sentences that cause the attribute mismatch are repaired, and the generated text of the language model is modified to the minimum extent to make it meet the attribute requirements as much as possible, further reducing the impact on the distribution of the texts generated by the language model and reducing the resource overhead.
[0036] In an embodiment of the present application, the text generation method can run on a terminal device or a server; among them, the terminal device can be a local terminal device. When the text generation method runs on the server, the text generation method can be implemented and executed based on a cloud interaction system, where the cloud interaction system at least includes a server and a client device (i.e., the terminal device).
[0037] In step S101, for the initial text generated by the target language model based on the prompt information, the text repair model is used to determine whether the attributes of the initial text match the pre-configured attribute requirements.
[0038] Among them, the target language model can be a general language model such as ChatGPT, or a language model trained by the target user according to their own needs, such as a question-and-answer model for assisting customers in answering questions, a novel generator for assisting in writing, and so on.
[0039] Different language models and different users have different requirements for the attributes of the text. For example, the question-and-answer model requires that the generated text should not contain gender discrimination, regional discrimination, be mild in attitude, and not be sarcastic to customers, etc. The novel generator requires that there should be no novel sensitive words, sensitive fragments, etc.
[0040] The initial text is generated by the target language model based on the prompt information input by the user.
[0041] Specifically, before using the text repair model to determine whether the attributes of the initial text generated by the target language model based on the prompt information match the pre-configured attribute requirements, the method further includes:
[0042] The target language model receives the prompt information input by the user;
[0043] Generates an initial text based on the prompt information.
[0044] When a user inputs a prompt, first, the language model will normally generate text according to the prompt; these texts are generated entirely by the model based on its own results without any other intervention, and may generate text that does not meet the attribute requirements. In the text generation method described in the embodiment of the present application, no additional intervention will be made to the generation process of the language model, but the generated result will be put into the subsequent steps for processing. When the first word x 1 to the i-th word x i are generated, the language model M will predict the distribution P of the next word according to its output y (the specific calculation is as follows).
[0045] P(x i+1 ) = M(y|x 1 ,…,x n )
[0046] Among them, M represents a language model, y represents the output of the language model M, and P(x i+1 ) represents the distribution of the next word x 1 preset by the language model M according to the first word x i to the i-th word x i+1 , and x n represents the last word among n words.
[0047] Since different users have different attribute requirements, therefore, please refer to Figure 2 , in the embodiments of the present application, before determining whether the attribute of the initial text generated by the target language model based on the prompt information matches the pre-configured attribute requirements through the text repair model, the method further includes the following steps S201-S202;
[0048] S201. Determine the attribute requirements for the initial text based on the user requirements;
[0049] S202. Configure the text repair model based on the attribute requirements so that the text repair model processes the initial text with reference to the attribute requirements.
[0050] The text repair model can be an overall model, or a model including multiple modules or sub-models. It can be a model constructed based on regular expressions, etc., or a model constructed based on machine learning, neural networks, etc.
[0051] Configure the text repair model based on the attribute requirements. Through configuration operations and / or selection operations, determine the processing rules and / or sub-models corresponding to the attribute requirements in the text repair model, so that the text repair model processes the initial text through the processing rules and / or sub-models corresponding to the attribute requirements.
[0052] Determine the processing rules and / or sub-models corresponding to the attribute requirements in the text repair model through configuration operations, that is, specifically configure the processing rules according to the attribute requirements, and specifically train the sub-models according to the attribute requirements.
[0053] The processing rules can be regular expressions.
[0054] Train the sub-models according to the attribute requirements, that is, design a sample training set according to the attribute requirements to train the sub-models.
[0055] Based on the selection operation, determine the processing rules and / or sub-models corresponding to the attribute requirements in the text repair model, that is, it is possible to select the processing rules and / or sub-models corresponding to the target attribute requirements from the processing rules corresponding to different attribute requirements pre-configured in the text repair model and the pre-trained sub-models corresponding to different attribute requirements.
[0056] In the embodiments of the present application, the entire text generation process includes four steps: language model generation, text attribute evaluation, attribute-related segment location, and generated text repair. Therefore, the text repair model has the functions in the above three aspects of text attribute evaluation, attribute-related segment location, and generated text repair, which specifically correspond to the functions described in steps S101 - S103 respectively.
[0057] Based on this, in the text generation method described in the embodiments of the present application, the text repair model includes multiple sub-modules, and the sub-modules include: an attribute evaluation sub-module, a contribution degree calculation sub-module, and a text repair sub-module; the sub-modules include processing rules and / or sub-models corresponding to at least one attribute requirement;
[0058] Configuring the text repair model based on the attribute requirement includes:
[0059] In response to the received attribute requirement for the text repair model, configure the processing rules and / or sub-models in at least one sub-module of the text repair model.
[0060] The attribute evaluation sub-module is used to determine whether the attributes of the initial text match the pre-configured attribute requirements;
[0061] The contribution degree calculation sub-module is used to determine the attribute-related segments in the initial text that cause the attribute mismatch based on the attribute requirement;
[0062] The text repair sub-module is used to replace the attribute-related segments in the initial text with text repair segments that meet the attribute requirements to repair the initial text and generate a target text with matching attributes.
[0063] In some embodiments, according to the attribute requirement, through a selection operation, multiple processing rules and / or sub-models corresponding to the attribute requirement in multiple sub-modules can be selected simultaneously to simplify the configuration operation and improve the configuration efficiency.
[0064] In the embodiments of the present application, determining whether the attributes of the initial text match the pre-configured attribute requirements through the text repair model includes:
[0065] Determine whether the attributes of the initial text match each pre-configured attribute requirement through at least one pre-configured target attribute evaluation rule and / or target attribute evaluation sub-model in the text repair model;
[0066] Among them, different types of attribute requirements correspond to different attribute evaluation rules or attribute evaluation sub-models.
[0067] That is to say, the text repair model specifically determines whether the attributes of the initial text match each pre-configured attribute requirement through the target attribute evaluation rule and / or the target attribute evaluation sub-model.
[0068] The attribute requirements can be flexibly set according to user needs, and the specific content is diverse. For example, there should be no gender discrimination, no regional discrimination, a mild attitude, and no sarcasm towards customers.
[0069] Based on this, each attribute requirement can correspond to a target attribute evaluation rule or a target attribute evaluation sub-model. For example, the judgment of no gender discrimination is carried out through the target attribute evaluation rule, while the judgment of a mild attitude is carried out using the target attribute evaluation sub-model.
[0070] That is to say, the attribute evaluation sub-module in the text repair model can be an attribute evaluation rule, an attribute evaluation sub-model, and their combination.
[0071] The target attribute evaluation sub-model can be used to evaluate a single attribute requirement alone or to evaluate multiple attribute requirements simultaneously.
[0072] In the embodiment of the present application, in order to improve the configuration efficiency, in the described text generation method, when the text repair model is used to determine whether the attributes of the initial text match the pre-configured attribute requirements, it further includes:
[0073] Determine the attribute requirements of the initial text based on user needs;
[0074] Select the target attribute evaluation rule and / or the target attribute evaluation sub-model representing the attribute requirements from the pre-configured set of attribute evaluation rules and / or multiple attribute evaluation sub-models.
[0075] For example, the attribute evaluation sub-module in the text repair model has the following four evaluation functions: evaluating whether the text is gender-discriminatory, regionally discriminatory, has a mild attitude, or is sarcastic towards customers; however, the user's attribute requirements are two, namely no gender discrimination and no regional discrimination; then only select the target attribute evaluation rule and / or the target attribute evaluation sub-model for evaluating whether there is gender discrimination and regional discrimination.
[0076] When selecting the target attribute evaluation rule and / or the target attribute evaluation sub-model representing the attribute requirements, specifically, input the user requirements, and based on the attribute descriptions of the attribute evaluation rules and the attribute descriptions of the attribute evaluation sub-models, select the target attribute evaluation rule and / or the target attribute evaluation sub-model that matches the user requirements.
[0077] The attribute description can be the name of the attribute evaluation rule and / or the attribute evaluation sub-model, etc.
[0078] In some embodiments, the attribute evaluation rules can also be specifically configured according to the attribute requirements, or the attribute evaluation sub-model can be trained. For example, configure the attribute evaluation rules for gender discrimination, and train the attribute evaluation sub-model for identifying whether the attitude is gentle.
[0079] The specific content of the attribute evaluation rules corresponding to different attribute requirements is different. For example, the keywords and key phrases to be declared are different.
[0080] When training the evaluation sub-models corresponding to different attribute requirements, the training text data is determined based on the attribute requirements, and the training text data corresponding to different attribute requirements is different.
[0081] Specifically, for the evaluation of the attribute evaluation rules, it is usually presented in the form of a regular expression. For a generated initial text, if it matches a regular expression that does not meet the attribute requirements, it can be evaluated as an initial text that does not meet the attribute requirements.
[0082] It should be noted that for the attribute evaluation sub-model, the model type is not unique, and the training text data used by different types of attribute evaluation sub-models is also different. Therefore, the present application embodiments do not make any limitations on the specific model to which the above attribute evaluation sub-model belongs and the specific data content of the above training text data.
[0083] Specifically, the attribute evaluation sub-model can adopt a classification model. According to actual needs, various classification models are trained. Both traditional models such as support vector machines and deep learning models such as recurrent neural networks and large language classification models can be used. The trained classification model can directly output whether the category of the initial text meets the attribute requirements.
[0084] Alternatively, the classification model is a multi-classification model, which can simultaneously determine whether the initial text meets multiple types of attribute requirements, and directly output whether the category of the initial text meets the attributes of specific categories or does not meet the attributes of specific categories.
[0085] Only as an example, if it is required that the text generated by the model does not show gender discrimination, "All nurses are female" is a text that does not meet the attribute requirements, while "All nurses are angels" meets the attribute requirements. The regular expression ".*nurse.*female.*" can be configured as the regular expression that does not meet the requirements for filtering, or a classification model can be used for judgment.
[0086] In the text generation method described in the embodiments of the present application, determining whether at least one attribute of the initial text meets the pre-configured attribute requirements by using at least one target attribute evaluation rule and / or target attribute evaluation sub-model pre-configured in the text repair model includes:
[0087] Match the initial text with at least one target attribute evaluation rule, and determine whether at least one attribute of the initial text meets the pre-configured attribute requirements according to the matching result;
[0088] And / or,
[0089] Input the initial text into the target attribute evaluation sub-model;
[0090] The target attribute evaluation sub-model classifies the initial text to determine the classification result of the initial text;
[0091] Judge whether at least one attribute of the initial text meets the pre-configured attribute requirements according to the classification result.
[0092] In the step S102, if the attribute of the initial text does not match the pre-configured attribute requirements, determine the attribute-related fragments in the initial text that cause the attribute mismatch based on the attribute requirements; the attribute-related fragments include words and / or sentences.
[0093] In this way, the attribute-related fragments can be called attribute-related words or attribute-related sentences.
[0094] In some embodiments, if the attribute of the initial text matches the pre-configured attribute requirements, determine that the initial text is the target text with matching attributes.
[0095] That is to say, if the attribute of the initial text matches the pre-configured attribute requirements, there are no attribute-related fragments in the initial text that cause the attribute mismatch, and the attribute of the initial text itself meets the requirements and does not need to be repaired, and can be directly used as the target text.
[0096] The embodiments of the present application directly output the text that meets the attribute requirements generated by the language model as the target text, which greatly reduces the resource overhead and reduces the distribution impact on the text generated by the language model.
[0097] Please refer to Figure 3 , Figure 3 shows the method flow chart for determining the attribute-related fragments in the initial text that cause the attribute mismatch based on the attribute requirements in the embodiments of the present application: Specifically, determining the attribute-related fragments in the initial text that cause the attribute mismatch based on the attribute requirements includes the following steps S301-S302:
[0098] S301. Based on the attribute requirements, calculate the contribution degree of the words and / or sentences in the initial text to the attribute mismatch;
[0099] S302. Locate the words and / or sentences whose contribution degree meets the preset contribution degree condition, and determine the attribute-related fragments that cause the attribute mismatch.
[0100] The contribution degree is the degree of influence of the word and / or sentence on whether the text meets the attribute requirements. The higher the contribution degree, the greater the influence of the word and / or sentence on whether the text meets the attribute requirements, and the more likely it is to be the cause of the text attribute mismatch.
[0101] Here, the preset contribution condition may be exceeding a preset contribution threshold, or a preset number of words and / or sentences ranked first in contribution.
[0102] Before calculating the contribution of words and / or sentences of the initial text to the attribute mismatch based on the attribute requirement, the initial text is divided according to word granularity and / or sentence granularity to obtain divided words and / or sentences.
[0103] When the initial text is divided to obtain the divided words and / or sentences, they can be screened out according to rules to screen out words that are meaningless to the attribute requirements, such as function words such as "的".
[0104] In the embodiment of the present application, based on the attribute requirements, the contribution of the words and / or sentences of the initial text to the attribute mismatch is calculated; including:
[0105] Based on the pre-configured attribute requirements, a target contribution calculation sub-model corresponding to the attribute requirements is determined; wherein different types of attribute requirements correspond to different contribution calculation sub-models;
[0106] The target contribution calculation sub-model is used to calculate the contribution of words and / or sentences of the initial text to the attribute mismatch.
[0107] Based on the pre-configured attribute requirements, determine the target contribution calculation sub-model corresponding to the attribute requirements; including:
[0108] Training the target contribution calculation sub-model corresponding to the attribute requirements;
[0109] or,
[0110] A target contribution calculation sub-model corresponding to the attribute requirement is selected from the pre-trained contribution calculation sub-models.
[0111] For the text evaluated as not meeting the requirements in step S101, the text is located at the word granularity and sentence granularity according to the rules to obtain the attribute-related fragments that cause the attribute mismatch. This requires that the positions of important attribute-related words or sentences be clearly defined when formulating regular expression rules.
[0112] For the text evaluated as not meeting the requirements in step S101, due to the black-box nature of the machine learning model, the contribution calculation sub-model can use the feature interpretation method of the model (e.g., SHAP) to interpret the output of the model and locate it at the word granularity and sentence granularity. SHAP is a feature importance analysis method based on the Shapley value. For a piece of text, the Shapley value contribution gi of the i-th word or sentence in it to the result of the final evaluation model can be calculated. Subsequently, by setting a certain threshold t, all the words and sentences in the generated text whose contributions exceed the threshold t can be selected as the positioning results.
[0113] For example, for a text like "All nurses are female", it may be found that the contribution of "nurse" is 0.3, the contribution of "all" is -0.1, and the contribution of "female" is 0.8. Then, for the attribute requirement of no gender discrimination, if the threshold t is set to 0.5, the word "female" can be located as the attribute-related word causing gender discrimination in the text.
[0114] The calculation of the contribution degree is also related to the text attribute. If the attribute requirement is no uncivilized elements, then the same text "All nurses are female" will be judged to meet the attribute requirement. In the embodiments of the present application, when training the contribution calculation sub-model, it can be trained based on the attribute-related words declared in the attribute evaluation rules (usually regular expression rules).
[0115] When the text repair model evaluates whether the attribute of the initial text meets the attribute requirement based on the attribute evaluation sub-model, it determines the contribution degree of different words or sentences to this kind of attribute based on the attribute evaluation sub-model. For example, in a gender discrimination classification model, it can output the weights of different words for classification, and this weight is used to train the contribution calculation sub-model.
[0116] That is to say, based on the attribute evaluation rules corresponding to the attribute requirements and / or the attribute evaluation sub-model in the text repair model, reference information is determined; the reference information represents the influence degree of different words or sentences on not meeting this kind of attribute requirement;
[0117] Training the target contribution calculation sub-model corresponding to the attribute requirement includes:
[0118] Training the target contribution calculation sub-model corresponding to the attribute requirement based on the attribute requirement and the reference information of the attribute requirement.
[0119] In step S103, the attribute-related fragments in the initial text are replaced with text repair fragments that meet the attribute requirements to repair the initial text and generate a target text with attribute matching.
[0120] Please refer to Figure 4 , Figure 4A method flow chart for replacing an attribute-related segment in an initial text with a text repair segment that meets the attribute requirements is shown; replacing the attribute-related segment in the initial text with a text repair segment that meets the attribute requirements to generate a target text that matches the attribute includes the following steps S401 - S402:
[0121] S401. Based on the semantics and attribute requirements of the text obtained by removing the attribute-related segment from the initial text, predict a text repair segment that meets the attribute requirements;
[0122] S402. Use the text repair segment to replace the attribute-related segment in the initial text to generate a target text that matches the attribute.
[0123] Specifically, in the embodiments of the present application, the text repair sub-model corresponding to the attribute requirement in the text repair model predicts a text repair segment that meets the attribute requirements based on the semantics and attribute requirements of the text obtained by removing the attribute-related segment from the initial text.
[0124] In other words, predicting a text repair segment that meets the attribute requirements based on the semantics and attribute requirements of the text obtained by removing the attribute-related segment from the initial text includes:
[0125] Mask the attribute-related segment to be repaired, and input the masked initial text into the text repair sub-model corresponding to the attribute requirement; among them, the text repair sub-models corresponding to different attribute requirements are different;
[0126] The text repair sub-model predicts words or sentences that meet the attribute requirements based on the semantics of the masked initial text to obtain a text repair segment.
[0127] Here, the model type adopted by the text repair sub-model is not limited. The text repair sub-models corresponding to different attribute requirements are obtained based on the training text data corresponding to this type of attribute requirement. The text training data corresponding to different attribute requirements are different.
[0128] The text repair model can be a text repair sub-model trained according to specific attribute requirements; or, there are multiple different text repair sub-models in the text repair model, and based on a selection operation, select the text repair sub-model corresponding to the attribute requirement.
[0129] If it is necessary to repair attribute keywords with multiple unmatched attributes, for example, all nurses are female, especially those in City A; City A is a keyword for regional discrimination, and female is a keyword for gender discrimination. A text repair sub-model that can repair both regional discrimination and gender discrimination can be trained, or text repair sub-models for repairing regional discrimination and gender discrimination can be trained separately. By inputting the masked initial text into the text repair sub-model corresponding to the attribute requirement, text repair segments that meet the requirements of this type of attribute are obtained through different text repair sub-models respectively.
[0130] In the embodiments of the present application, after the attribute-related fragments that do not meet the attribute requirements at the word granularity and sentence granularity are located, a specific repair model is used for controlled repair. The repair model is specifically trained to minimally modify the generated text of the language model for words and sentences so that it can meet the attribute requirements as much as possible.
[0131] Specifically, the words to be repaired can be masked with [MASK], and then a text-to-text model can be used and modules such as PPLM (Plug and Play Language Models) or FUDGE (a controllable text generation method based on future discriminators) can be added to help achieve the repair of the attribute-oriented generated text. The text-to-text model will predict the text content at the [MASK] according to the relevant semantics of the [MASK] context, and at the same time, the PPLM or FUDGE module will also perform a certain offset control on the distribution predicted by the text-to-text model to make it meet the attribute requirements as much as possible.
[0132] Among them, PPLM uses the method of backpropagating and modifying the hidden representation according to the prediction of the attribute model, while FUDGE uses the method of directly correcting the prediction distribution using Bayes' formula.
[0133] When the target text after repair is obtained, it re-enters step S102, and is evaluated by the target attribute evaluation rule and / or the target attribute evaluation sub-model in the text repair model. If the evaluation meets the attribute requirements, it can be output as the target text obtained by the user. If the evaluation still does not meet the requirements, the attribute-related fragments can be located again and repaired.
[0134] Please refer to Figure 5 , in the embodiments of the present application, after repairing the initial text and generating the target text that matches the attributes, the method further includes the following steps S501-S503:
[0135] S501. Secondarily determine whether the attributes of the target text match the pre-configured attribute requirements through the text repair model;
[0136] S502. If so, output the target text;
[0137] S503. If not, repair the target text again.
[0138] The step of secondarily determining whether the attributes of the target text match the pre-configured attribute requirements through the text repair model means inputting the target text into the attribute evaluation sub-module of the text repair model, and secondarily determining whether the attributes of the target text match the pre-configured attribute requirements through the target attribute evaluation rule and / or the target attribute evaluation sub-model of the attribute evaluation sub-module.
[0139] If not, then execute the steps S102 - S103 again, that is, determine the attribute - related fragments in the target text that cause the attribute mismatch based on the attribute requirements; the attribute - related fragments include words and / or sentences; replace the attribute - related fragments in the target text with text repair fragments that meet the attribute requirements to repair the target text again.
[0140] It should be noted that during a new round of repair, hyperparameters (for example: the offset step of the PPLM repair model) can be automatically adjusted so that the result of the newly repaired text is different from that of the previous round of repaired text.
[0141] Specifically, when repairing the initial text through the text repair sub - model in the text repair model, the repairing of the target text again includes:
[0142] Adjust the hyperparameters in the text repair sub - model to obtain an adjusted text repair sub - model;
[0143] Repair the target text again through the adjusted text repair sub - model.
[0144] The content of the target text repaired again is different from that of the previous target text. In this way, after at least one repair, the text with attributes not meeting the requirements is repaired into text with attributes meeting the requirements, and subsequent control processing is only performed after the language model is generated, which has less impact on the distribution of the model - generated text and also maintains a low resource overhead.
[0145] Based on the same inventive concept, the present application also provides a text generation device corresponding to the above - mentioned text generation method of the target object. Since the principle of solving problems by the text generation device in the embodiments of the present application is similar to that of the above - mentioned text generation method in the embodiments of the present application, the implementation of the device can refer to the implementation of the above - mentioned method, and the repeated parts will not be described again.
[0146] Please refer to Figure 6 , Figure 6 shows a schematic structural diagram of the text generation device described in the embodiments of the present application; the text generation device includes:
[0147] A judgment module 601, configured to determine whether the attributes of the initial text generated by the target language model based on the prompt information match the pre - configured attribute requirements through the text repair model;
[0148] A determination module 602, configured to determine, when the attributes of the initial text do not match the pre - configured attribute requirements, the attribute - related fragments in the initial text that cause the attribute mismatch; the attribute - related fragments include words and / or sentences;
[0149] A repair module 603, configured to replace the attribute-related segments in the initial text with text repair segments that meet the attribute requirements, so as to repair the initial text and generate a target text that matches the attributes.
[0150] An embodiment of the present application provides a text generation device. For an initial text generated by a target language model based on prompt information, it is determined whether the attributes of the initial text match the pre-configured attribute requirements through a text repair model; if not, the attribute-related segments in the initial text that cause the attribute mismatch are determined based on the attribute requirements; the attribute-related segments include words and / or sentences; the attribute-related segments in the initial text are replaced with text repair segments that meet the attribute requirements, so as to repair the initial text and generate a target text that matches the attributes. In this way, after the language model generates the initial text, subsequent control processing is performed. For a large number of texts that are normally generated and meet the attribute requirements, the technical solution of the present application hardly incurs additional resource overhead and does not cause significant interference to the normal text generation of the model. Therefore, it has a small impact on the distribution of the texts generated by the language model, is lightweight and efficient, and also maintains a low resource overhead.
[0151] In an alternative embodiment, the text generation device further includes:
[0152] A generation module, configured to receive prompt information input by a user by the target language model before determining whether the attributes of the initial text generated by the target language model based on the prompt information match the pre-configured attribute requirements through the text repair model;
[0153] Generate an initial text based on the prompt information.
[0154] In an alternative embodiment, the determination module in the text generation device is further configured to: if the attributes of the initial text match the pre-configured attribute requirements, determine that the initial text is a target text that matches the attributes.
[0155] In an alternative embodiment, the text generation device further includes:
[0156] A configuration module, configured to determine the attribute requirements for the initial text based on user needs before determining whether the attributes of the initial text generated by the target language model based on the prompt information match the pre-configured attribute requirements through the text repair model;
[0157] Configure the text repair model based on the attribute requirements, so that the text repair model processes the initial text with reference to the attribute requirements.
[0158] In an alternative embodiment, the text repair model in the text generation device includes a plurality of sub-modules, and the sub-modules include: an attribute evaluation sub-module, a contribution degree calculation sub-module, and a text repair sub-module; the sub-modules include processing rules and / or sub-models corresponding to at least one attribute requirement.
[0159] When configuring the text repair model based on the attribute requirement, the configuration module is specifically configured to:
[0160] In response to the received attribute requirement for the text repair model, configure the processing rules and / or sub-models in at least one sub-module of the text repair model.
[0161] In an alternative embodiment, when the judgment module in the text generation device determines whether the attribute of the initial text matches the pre-configured attribute requirement through the text repair model, it is specifically configured to:
[0162] Determine whether the attribute of the initial text matches each pre-configured attribute requirement through at least one pre-configured target attribute evaluation rule and / or target attribute evaluation sub-model in the text repair model;
[0163] Among them, different types of attribute requirements correspond to different attribute evaluation rules or attribute evaluation sub-models.
[0164] In an alternative embodiment, when the judgment module in the text generation device determines whether the attribute of the initial text matches the pre-configured attribute requirement through the text repair model, it is further configured to determine the attribute requirement of the initial text based on the user's needs;
[0165] Select the target attribute evaluation rule and / or target attribute evaluation sub-model representing the attribute requirement from the pre-configured attribute evaluation rule set and / or multiple attribute evaluation sub-models.
[0166] In an alternative embodiment, when the judgment module in the text generation device determines whether at least one attribute of the initial text matches the pre-configured attribute requirement through at least one pre-configured target attribute evaluation rule and / or target attribute evaluation sub-model in the text repair model, it is specifically configured to:
[0167] Match the initial text with at least one target attribute evaluation rule, and determine whether at least one attribute of the initial text matches the pre-configured attribute requirement according to the matching result;
[0168] And / or,
[0169] Input the initial text into the target attribute evaluation sub-model;
[0170] The target attribute evaluation sub-model classifies the initial text to determine the classification result of the initial text;
[0171] Judge whether at least one attribute of the initial text meets the pre-configured attribute requirements according to the classification result.
[0172] In an optional implementation manner, when the determination module in the text generation device determines the attribute-related fragments in the initial text that cause attribute mismatch based on the attribute requirements, it specifically is used for:
[0173] Based on the attribute requirements, calculate the contribution degree of the words and / or sentences in the initial text to the attribute mismatch;
[0174] Locate the words and / or sentences whose contribution degree meets the preset contribution degree condition, and determine the attribute-related fragments that cause the attribute mismatch.
[0175] In an optional implementation manner, when the determination module in the text generation device calculates the contribution degree of the words and / or sentences in the initial text to the attribute mismatch based on the attribute requirements, it specifically is used for:
[0176] Based on the pre-configured attribute requirements, determine the target contribution degree calculation sub-model corresponding to the attribute requirements; where different types of attribute requirements correspond to different contribution degree calculation sub-models;
[0177] Through the target contribution degree calculation sub-model, calculate the contribution degree of the words and / or sentences in the initial text to the attribute mismatch.
[0178] In an optional implementation manner, when the determination module in the text generation device determines the target contribution degree calculation sub-model corresponding to the attribute requirements based on the pre-configured attribute requirements, it specifically is used for:
[0179] Train the target contribution degree calculation sub-model corresponding to the attribute requirements;
[0180] Or,
[0181] Select the target contribution degree calculation sub-model corresponding to the attribute requirements from the pre-trained contribution degree calculation sub-models.
[0182] In an optional implementation manner, when the repair module in the text generation device replaces the attribute-related fragments in the initial text with text repair fragments that meet the attribute requirements to generate a target text with attribute matching, it specifically is used for:
[0183] Based on the semantics and attribute requirements of the text obtained by removing the attribute-related fragments from the initial text, predict the text repair fragments that meet the attribute requirements;
[0184] Generate a target text that matches the attributes by using text repair segments to replace the attribute-related segments in the initial text.
[0185] In an alternative embodiment, when the repair module in the text generation device predicts text repair segments that meet the attribute requirements based on the semantics and attribute requirements of the text after removing the attribute-related segments from the initial text, it is specifically configured to:
[0186] Mask the attribute-related segments that need to be repaired, and input the masked initial text into the text repair sub-model corresponding to the attribute requirements; where the text repair sub-models corresponding to different attribute requirements are different;
[0187] The text repair sub-model predicts words or sentences that meet the attribute requirements based on the semantics of the masked initial text to obtain text repair segments.
[0188] In an alternative embodiment, the text generation device further includes:
[0189] A secondary judgment module, configured to, after repairing the initial text to generate a target text that matches the attributes, secondarily judge whether the attributes of the target text match the pre-configured attribute requirements through the text repair model;
[0190] If so, output the target text;
[0191] If not, repair the target text again.
[0192] In an alternative embodiment, when the secondary judgment module in the text generation device repairs the initial text through the text repair sub-model in the text repair model and repairs the target text again, it is specifically configured to:
[0193] Adjust the hyperparameters in the text repair sub-model to obtain an adjusted text repair sub-model;
[0194] Repair the target text again through the adjusted text repair sub-model.
[0195] Based on the same inventive concept, the present application also provides an electronic device corresponding to the text generation method of the above target object. Since the principle of solving problems by the electronic device in the embodiments of the present application is similar to the above text generation method in the embodiments of the present application, the implementation of the electronic device can refer to the implementation of the above method, and the repeated parts will not be described again.
[0196] Please refer to Figure 7 , Figure 7The structural schematic diagram of the electronic device according to the embodiment of the present application is shown; the electronic device 700 includes: a processor 702, a memory 701, and a bus. The memory 701 stores machine-readable instructions executable by the processor 702. When the electronic device 700 runs, the processor 702 communicates with the memory 701 through the bus. When the machine-readable instructions are executed by the processor 702, the following steps of the text generation method are executed. Specifically:
[0197] For the initial text generated by the target language model based on the prompt information, determine whether the attributes of the initial text match the pre-configured attribute requirements through the text repair model;
[0198] If not, determine the attribute-related fragments in the initial text that cause the attribute mismatch based on the attribute requirements; the attribute-related fragments include words and / or sentences;
[0199] Replace the attribute-related fragments in the initial text with text repair fragments that meet the attribute requirements to repair the initial text and generate a target text with matching attributes.
[0200] In an optional implementation manner, before determining whether the attributes of the initial text generated by the target language model based on the prompt information match the pre-configured attribute requirements through the text repair model, the processor is further configured to:
[0201] The target language model receives the prompt information input by the user;
[0202] Generate an initial text based on the prompt information.
[0203] In an optional implementation manner, the processor is further configured to:
[0204] If the attributes of the initial text match the pre-configured attribute requirements, determine that the initial text is the target text with matching attributes.
[0205] In an optional implementation manner, before determining whether the attributes of the initial text generated by the target language model based on the prompt information match the pre-configured attribute requirements through the text repair model, the processor is further configured to:
[0206] Based on the user requirements, determine the attribute requirements for the initial text;
[0207] Configure the text repair model based on the attribute requirements so that the text repair model processes the initial text with reference to the attribute requirements.
[0208] In an alternative embodiment, the text repair model includes a plurality of sub-modules, and the sub-modules include: an attribute evaluation sub-module, a contribution degree calculation sub-module, and a text repair sub-module; the sub-modules include processing rules and / or sub-models corresponding to at least one attribute requirement;
[0209] When configuring the text repair model based on the attribute requirements, the processor is specifically configured to:
[0210] In response to the received attribute requirements for the text repair model, configure the processing rules and / or sub-models in at least one sub-module of the text repair model.
[0211] In an alternative embodiment, when the processor determines whether the attributes of the initial text match the pre-configured attribute requirements through the text repair model, the processor is specifically configured to:
[0212] Judge whether the attributes of the initial text match each pre-configured attribute requirement through at least one pre-configured target attribute evaluation rule and / or target attribute evaluation sub-model in the text repair model;
[0213] Among them, different types of attribute requirements correspond to different attribute evaluation rules or attribute evaluation sub-models.
[0214] In an alternative embodiment, when the processor determines whether the attributes of the initial text match the pre-configured attribute requirements through the text repair model, the processor is further configured to:
[0215] Determine the attribute requirements of the initial text based on the user's needs;
[0216] Select the target attribute evaluation rule and / or target attribute evaluation sub-model representing the attribute requirements from the pre-configured attribute evaluation rule set and / or multiple attribute evaluation sub-models.
[0217] In an alternative embodiment, when the processor determines whether at least one attribute of the initial text matches the pre-configured attribute requirements through at least one pre-configured target attribute evaluation rule and / or target attribute evaluation sub-model in the text repair model, the processor is specifically configured to:
[0218] Match the initial text with at least one target attribute evaluation rule, and judge whether at least one attribute of the initial text matches the pre-configured attribute requirements according to the matching result;
[0219] and / or,
[0220] Input the initial text into the target attribute evaluation sub-model;
[0221] The target attribute evaluation sub-model classifies the initial text to determine the classification result of the initial text;
[0222] Determine whether at least one attribute of the initial text meets the pre-configured attribute requirements according to the classification result.
[0223] In an alternative embodiment, when determining the attribute-related fragments in the initial text that cause attribute mismatch based on the attribute requirements, the processor is specifically configured to:
[0224] Calculate the contribution degree of the words and / or sentences in the initial text to the attribute mismatch based on the attribute requirements;
[0225] Locate the words and / or sentences whose contribution degree meets the preset contribution degree condition, and determine the attribute-related fragments that cause the attribute mismatch.
[0226] In an alternative embodiment, when calculating the contribution degree of the words and / or sentences in the initial text to the attribute mismatch based on the attribute requirements, the processor is specifically configured to:
[0227] Determine a target contribution degree calculation sub-model corresponding to the attribute requirements based on the pre-configured attribute requirements; where different types of attribute requirements correspond to different contribution degree calculation sub-models;
[0228] Calculate the contribution degree of the words and / or sentences in the initial text to the attribute mismatch through the target contribution degree calculation sub-model.
[0229] In an alternative embodiment, when determining the target contribution degree calculation sub-model corresponding to the attribute requirements based on the pre-configured attribute requirements, the processor is specifically configured to:
[0230] Train the target contribution degree calculation sub-model corresponding to the attribute requirements;
[0231] Or,
[0232] Select the target contribution degree calculation sub-model corresponding to the attribute requirements from the pre-trained contribution degree calculation sub-models.
[0233] In an alternative embodiment, when replacing the attribute-related fragments in the initial text with text repair fragments that meet the attribute requirements to generate a target text with attribute matching, the processor is specifically configured to:
[0234] Predict text repair fragments that meet the attribute requirements based on the semantics and attribute requirements of the text obtained by removing the attribute-related fragments from the initial text;
[0235] Use the text repair fragments to replace the attribute-related fragments in the initial text to generate a target text with attribute matching.
[0236] In an alternative embodiment, when predicting a text repair segment that meets the attribute requirements based on the semantics and attribute requirements of the text with the attribute-related segments removed from the initial text, the processor is specifically configured to:
[0237] Mask the attribute-related segments that need to be repaired, and input the masked initial text into the text repair sub-model corresponding to the attribute requirements; wherein, the text repair sub-models corresponding to different attribute requirements are different;
[0238] Based on the semantics of the masked initial text, the text repair sub-model predicts words or sentences that meet the attribute requirements to obtain a text repair segment.
[0239] In an alternative embodiment, after repairing the initial text to generate a target text that matches the attributes, the processor is further configured to:
[0240] Secondarily determine whether the attributes of the target text match the pre-configured attribute requirements through the text repair model;
[0241] If so, output the target text;
[0242] If not, repair the target text again.
[0243] In an alternative embodiment, when repairing the initial text through the text repair sub-model in the text repair model, when repairing the target text again, the processor is specifically configured to:
[0244] Adjust the hyperparameters in the text repair sub-model to obtain an adjusted text repair sub-model;
[0245] Repair the target text again through the adjusted text repair sub-model.
[0246] Based on the same inventive concept, the present application also provides a computer-readable storage medium corresponding to the above-mentioned text generation method for the target object. Since the principle of solving problems by the computer-readable storage medium in the embodiments of the present application is similar to the above-mentioned text generation method in the embodiments of the present application, the implementation of the computer-readable storage medium can refer to the implementation of the above method, and the repeated parts will not be described again.
[0247] An embodiment of the present application provides a computer-readable storage medium, on which a computer program is stored. When the computer program is run by a processor, the processor executes the following steps of the text generation method:
[0248] For the initial text generated by the target language model based on the prompt information, determine whether the attributes of the initial text match the pre-configured attribute requirements through the text repair model;
[0249] Otherwise, determine the attribute-related fragments in the initial text that cause the attribute mismatch based on the attribute requirements; the attribute-related fragments include words and / or sentences;
[0250] Replace the attribute-related fragments in the initial text with text repair fragments that meet the attribute requirements to repair the initial text and generate a target text with matching attributes.
[0251] In an alternative embodiment, before determining whether the attributes of the initial text match the pre-configured attribute requirements through the text repair model for the initial text generated by the target language model based on the prompt information, the processor is further configured to:
[0252] The target language model receives the prompt information input by the user;
[0253] Generate an initial text based on the prompt information.
[0254] In an alternative embodiment, the processor is further configured to:
[0255] If the attributes of the initial text match the pre-configured attribute requirements, determine that the initial text is the target text with matching attributes.
[0256] In an alternative embodiment, before determining whether the attributes of the initial text match the pre-configured attribute requirements through the text repair model for the initial text generated by the target language model based on the prompt information, the processor is further configured to:
[0257] Determine the attribute requirements for the initial text based on the user's needs;
[0258] Configure the text repair model based on the attribute requirements so that the text repair model processes the initial text with reference to the attribute requirements.
[0259] In an alternative embodiment, the text repair model includes multiple sub-modules, and the sub-modules include: an attribute evaluation sub-module, a contribution degree calculation sub-module, and a text repair sub-module; the sub-modules include processing rules and / or sub-models corresponding to at least one attribute requirement;
[0260] When configuring the text repair model based on the attribute requirements, the processor is specifically configured to:
[0261] In response to the received attribute requirements for the text repair model, configure the processing rules and / or sub-models in at least one sub-module of the text repair model.
[0262] In an alternative embodiment, when determining whether the attributes of the initial text match the pre-configured attribute requirements through the text repair model, the processor is specifically configured to:
[0263] Determine whether the attributes of the initial text match each pre-configured attribute requirement through at least one pre-configured target attribute evaluation rule and / or target attribute evaluation sub-model in the text repair model;
[0264] Among them, different types of attribute requirements correspond to different attribute evaluation rules or attribute evaluation sub-models.
[0265] In an optional implementation manner, when the processor determines whether the attributes of the initial text match the pre-configured attribute requirements through the text repair model, it is further configured to:
[0266] Determine the attribute requirements of the initial text based on user needs;
[0267] Select the target attribute evaluation rule and / or target attribute evaluation sub-model that characterizes the attribute requirements from the pre-configured set of attribute evaluation rules and / or multiple attribute evaluation sub-models.
[0268] In an optional implementation manner, when the processor determines whether at least one attribute of the initial text matches the pre-configured attribute requirements through at least one pre-configured target attribute evaluation rule and / or target attribute evaluation sub-model in the text repair model, it specifically is configured to:
[0269] Match the initial text with at least one target attribute evaluation rule, and determine whether at least one attribute of the initial text matches the pre-configured attribute requirements according to the matching result;
[0270] and / or,
[0271] Input the initial text into the target attribute evaluation sub-model;
[0272] The target attribute evaluation sub-model classifies the initial text to determine the classification result of the initial text;
[0273] Determine whether at least one attribute of the initial text matches the pre-configured attribute requirements according to the classification result.
[0274] In an optional implementation manner, when the processor determines the attribute-related fragments in the initial text that cause attribute mismatch based on the attribute requirements, it specifically is configured to:
[0275] Based on the attribute requirements, calculate the contribution degree of the words and / or sentences in the initial text to the attribute mismatch;
[0276] Locate the words and / or sentences whose contribution degree meets the preset contribution degree condition, and determine the attribute-related fragments that cause the attribute mismatch.
[0277] In an alternative embodiment, when calculating the contribution degree of the word and / or sentence pair attributes mismatch of the initial text based on the attribute requirements, the processor is specifically configured to:
[0278] Determine a target contribution degree calculation sub-model corresponding to the attribute requirements based on the pre-configured attribute requirements; wherein, different types of attribute requirements correspond to different contribution degree calculation sub-models;
[0279] Calculate the contribution degree of the word and / or sentence pair attributes mismatch of the initial text through the target contribution degree calculation sub-model.
[0280] In an alternative embodiment, when determining a target contribution degree calculation sub-model corresponding to the attribute requirements based on the pre-configured attribute requirements, the processor is specifically configured to:
[0281] Train a target contribution degree calculation sub-model corresponding to the attribute requirements;
[0282] Or,
[0283] Select a target contribution degree calculation sub-model corresponding to the attribute requirements from the pre-trained contribution degree calculation sub-models.
[0284] In an alternative embodiment, when replacing the attribute-related fragments in the initial text with text repair fragments that meet the attribute requirements to generate a target text with matching attributes, the processor is specifically configured to:
[0285] Predict text repair fragments that meet the attribute requirements based on the semantics and attribute requirements of the text obtained by removing the attribute-related fragments from the initial text;
[0286] Use the text repair fragments to replace the attribute-related fragments in the initial text to generate a target text with matching attributes.
[0287] In an alternative embodiment, when predicting text repair fragments that meet the attribute requirements based on the semantics and attribute requirements of the text obtained by removing the attribute-related fragments from the initial text, the processor is specifically configured to:
[0288] Mask the attribute-related fragments that need to be repaired, and input the masked initial text into the text repair sub-model corresponding to the attribute requirements; wherein, different text repair sub-models correspond to different attribute requirements;
[0289] The text repair sub-model predicts words or sentences that meet the attribute requirements based on the semantics of the masked initial text to obtain text repair fragments.
[0290] In an alternative embodiment, after repairing the initial text to generate a target text with matching attributes, the processor is further configured to:
[0291] Use the text repair model to secondarily determine whether the attributes of the target text match the pre-configured attribute requirements;
[0292] If so, output the target text;
[0293] If not, repair the target text again.
[0294] In an alternative embodiment, when the processor repairs the initial text through the text repair sub-model in the text repair model and repairs the target text again, it is specifically used for:
[0295] Adjust the hyperparameters in the text repair sub-model to obtain an adjusted text repair sub-model;
[0296] Use the adjusted text repair sub-model to repair the target text again.
[0297] Those skilled in the art can clearly understand that for the convenience and brevity of description, the specific working processes of the systems and devices described above can refer to the corresponding processes in the method embodiments, which will not be elaborated herein. In the several embodiments provided in this application, it should be understood that the disclosed systems, devices, and methods can be implemented in other ways. The device embodiments described above are merely illustrative. For example, the division of the modules is only a logical function division, and there can be other division methods in actual implementation. Also, for example, multiple modules or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed couplings or direct couplings or communication connections to each other can be through some communication interfaces. The indirect couplings or communication connections of the devices or modules can be in electrical, mechanical, or other forms.
[0298] The modules described as separate components may or may not be physically separated, and the components displayed as modules may or may not be physical units, that is, they can be located in one place, or they can be distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0299] In addition, the functional units in each embodiment of this application can be integrated into one processing unit, or each unit can exist physically alone, or two or more units can be integrated into one unit.
[0300] When the above-mentioned functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a non-volatile computer-readable storage medium executable by a processor. Based on such an understanding, the technical solution of the present application, in essence, or the part that contributes to the prior art, or a part of this technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a platform server, or a network device, etc.) to execute all or part of the steps of the methods described in various embodiments of the present application. The aforementioned storage medium includes: various media such as USB flash drives, mobile hard disks, ROM, RAM, magnetic disks, or optical discs that can store program codes.
[0301] The above are only specific implementation manners of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art within the technical scope disclosed by the present application can easily think of changes or substitutions, which should all be covered by the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.
Claims
1. A text generation method, characterized in that, the method includes: For the initial text generated by the target language model based on the prompt information, judge whether the attributes of the initial text match the pre-configured attribute requirements through the text repair model; If not, determine the attribute-related fragments in the initial text that cause the attribute mismatch based on the attribute requirements; the attribute-related fragments include words and / or sentences; Replace the attribute-related fragments in the initial text with text repair fragments that meet the attribute requirements to repair the initial text and generate a target text with matching attributes.
2. The text generation method according to claim 1, characterized in that, Before judging whether the attributes of the initial text match the pre-configured attribute requirements through the text repair model for the initial text generated by the target language model based on the prompt information, the method further includes: Determine the attribute requirements for the initial text based on the user requirements; Configure the text repair model based on the attribute requirements so that the text repair model processes the initial text with reference to the attribute requirements.
3. The text generation method according to claim 2, characterized in that, The text repair model includes multiple sub-modules, and the sub-modules include: an attribute evaluation sub-module, a contribution degree calculation sub-module, and a text repair sub-module; the sub-modules include processing rules and / or sub-models corresponding to at least one type of attribute requirement; The configuring the text repair model based on the attribute requirements includes: In response to the received attribute requirements for the text repair model, configure the processing rules and / or sub-models in at least one sub-module of the text repair model.
4. The text generation method according to claim 1, characterized in that, The judging whether the attributes of the initial text match the pre-configured attribute requirements through the text repair model includes: Judge whether the attributes of the initial text match each pre-configured attribute requirement through at least one pre-configured target attribute evaluation rule and / or target attribute evaluation sub-model in the text repair model; Among them, different types of attribute requirements correspond to different attribute evaluation rules or attribute evaluation sub-models.
5. The text generation method according to claim 4, characterized in that, The judging whether the attributes of the initial text match the pre-configured attribute requirements through the text repair model further includes: Determine the attribute requirements of the initial text based on the user requirements; Select the target attribute evaluation rule and / or target attribute evaluation sub-model representing the attribute requirements from the pre-configured attribute evaluation rule set and / or multiple attribute evaluation sub-models.
6. The text generation method according to claim 4, characterized in that, The judging whether at least one attribute of the initial text meets the pre-configured attribute requirements through at least one pre-configured target attribute evaluation rule and / or target attribute evaluation sub-model in the text repair model includes: Match the initial text with at least one target attribute evaluation rule, and judge whether at least one attribute of the initial text meets the pre-configured attribute requirements according to the matching result; and / or, Input the initial text into the target attribute evaluation sub-model; The target attribute evaluation sub-model classifies the initial text to determine the classification result of the initial text; Based on the classification result, it is determined whether at least one attribute of the initial text meets the pre-configured attribute requirements.
7. The text generation method according to claim 1, characterized in that, Based on the attribute requirements, the attribute-related fragments in the initial text that cause attribute mismatch are determined, including: Based on the attribute requirements, calculate the contribution degree of the words and / or sentences in the initial text to the attribute mismatch; Locate the words and / or sentences whose contribution degree meets the preset contribution degree condition, and determine the attribute-related fragments that cause attribute mismatch.
8. The method according to claim 7, characterized in that, Based on the attribute requirements, calculate the contribution degree of the words and / or sentences in the initial text to the attribute mismatch; including: Based on the pre-configured attribute requirements, determine the target contribution degree calculation sub-model corresponding to the attribute requirements; among them, different types of attribute requirements correspond to different contribution degree calculation sub-models; Through the target contribution degree calculation sub-model, calculate the contribution degree of the words and / or sentences in the initial text to the attribute mismatch.
9. The method according to claim 8, characterized in that, Based on the pre-configured attribute requirements, determine the target contribution degree calculation sub-model corresponding to the attribute requirements; including: Train the target contribution degree calculation sub-model corresponding to the attribute requirements; Or, Select the target contribution degree calculation sub-model corresponding to the attribute requirements from the pre-trained contribution degree calculation sub-models.
10. The text generation method according to claim 1, characterized in that: Replace the attribute-related fragments in the initial text with text repair fragments that meet the attribute requirements to generate a target text with attribute matching, including: Based on the semantics and attribute requirements of the text obtained by removing the attribute-related fragments from the initial text, predict the text repair fragments that meet the attribute requirements; Use the text repair fragments to replace the attribute-related fragments in the initial text to generate a target text with attribute matching.
11. The text generation method according to claim 10, characterized in that: Based on the semantics and attribute requirements of the text obtained by removing the attribute-related fragments from the initial text, predict the text repair fragments that meet the attribute requirements, including: Mask the attribute-related fragments that need to be repaired, and input the masked initial text into the text repair sub-model corresponding to the attribute requirements; among them, the text repair sub-models corresponding to different attribute requirements are different; The text repair sub-model predicts the words or sentences that meet the attribute requirements based on the semantics of the masked initial text to obtain the text repair fragments.
12. The text generation method according to claim 1, characterized in that, After repairing the initial text to generate a target text with attribute matching, the method further includes: Secondarily judge whether the attribute of the target text matches the pre-configured attribute requirements through the text repair model; If so, output the target text; If not, repair the target text again.
13. The method according to claim 12, characterized in that, When repairing the initial text through the text repair sub-model in the text repair model, the step of repairing the target text again includes: Adjust the hyperparameters in the text repair sub-model to obtain an adjusted text repair sub-model; Use the adjusted text repair sub-model to repair the target text again.
14. The text generation method according to claim 1, characterized in that, before determining whether the attributes of the initial text generated by the target language model based on the prompt information match the pre-configured attribute requirements through the text repair model, the method further includes: The target language model receives the prompt information input by the user; Generate an initial text based on the prompt information.
15. The text generation method according to claim 1, characterized in that, the method further includes: If the attributes of the initial text match the pre-configured attribute requirements, determine that the initial text is the target text with matching attributes.
16. A text generation device, characterized in that, the device includes: A judgment module, configured to determine whether the attributes of the initial text generated by the target language model based on the prompt information match the pre-configured attribute requirements through the text repair model; A determination module, configured to determine, when the attributes of the initial text do not match the pre-configured attribute requirements, the attribute-related fragments in the initial text that cause the non-matching of the attributes; the attribute-related fragments include words and / or sentences; A repair module, configured to replace the attribute-related fragments in the initial text with text repair fragments that meet the attribute requirements to repair the initial text and generate a target text with matching attributes.
17. An electronic device, characterized in that, including: A processor, a memory, and a bus, where the memory stores machine-readable instructions executable by the processor. When the electronic device runs, the processor communicates with the memory through the bus. When the machine-readable instructions are executed by the processor, the steps of the text generation method according to any one of claims 1 to 15 are executed.
18. A computer-readable storage medium, characterized in that, A computer program is stored on the computer-readable storage medium, and when the computer program is run by a processor, the steps of the text generation method according to any one of claims 1 to 15 are executed.