Model generation method and device, text generation method and device, medium, equipment and product
By constructing an error generation model and optimizing the reward function, diverse error text sample data is automatically generated, solving the problems of high cost and long cycle of manual annotation and improving the training efficiency of text error correction models.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-23
- Publication Date
- 2026-03-10
AI Technical Summary
In existing technologies, the annotation of training data for text correction models relies on manual methods, resulting in high annotation thresholds, high costs, and low efficiency, which affects the training efficiency and iteration cycle of the model.
By constructing an error generation model, standard sample text is used as input to generate error text sample data, and a text error correction model is trained based on this data. The error generation model is optimized using a reward function to generate text that conforms to the specified error type. The second preset model is trained by combining standard sample text and error sample text.
It enables the automated and large-scale generation of diverse error text sample data, significantly reducing the cost of manual annotation and improving the training efficiency and data coverage of text error correction models.
Smart Images

Figure CN121638221A_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of computer technology, and more specifically, to a model generation method, a text generation method, an apparatus, a medium, a device, and a product. Background Technology
[0002] In existing technologies, deep learning models are typically trained by manually annotating a large amount of sample text data to obtain text correction models. However, the annotation of training data for text correction models involves multiple levels, including syntax, semantics, and pragmatics. The annotation rules are complex and must be completed by professionals with linguistic backgrounds, resulting in high annotation thresholds and costs. Furthermore, this strong reliance on manual annotation directly affects the training efficiency and iteration cycle of the model. Summary of the Invention
[0003] The purpose of this disclosure is to provide a model generation method, a text generation method, an apparatus, a medium, a device, and a product.
[0004] According to a first aspect of the present disclosure, a model generation method is provided, the method comprising: Obtain standard sample text and error sample text, wherein the error sample text includes multiple first error texts and the correct text corresponding to each first error text; the standard sample text includes text without text errors. The first preset model is trained based on the erroneous sample text to obtain the error generation model; The standard sample text is used as input to the error generation model to obtain error text sample data corresponding to the standard sample text output by the error generation model. The error text sample data includes at least one second error text. The second preset model is trained based on the standard sample text, the error text sample data, and the error sample text to obtain a text correction model, which is used to correct text errors in the input target text.
[0005] Optionally, training the first preset model based on the erroneous sample text to obtain the error generation model includes: Using the correct text as input and the first incorrect text as the supervision target, the first preset model is trained to obtain a candidate error generation model; The candidate error generation model is optimized based on the reward function to obtain the error generation model. The reward function is used to guide the candidate error generation model to generate a first error text that corresponds to the correct text and conforms to a specified error type. The correct text and the first error text maintain semantic consistency and have minimal text modification.
[0006] Optionally, the reward function can be determined in the following way: The target error level corresponding to the first erroneous text is determined based on a preset grammatical error classification model; Determine the edit distance between the first erroneous text and the correct text; Determine the semantic similarity between the first erroneous text and the correct text; The reward function is determined based on the target error level, the edit distance, and the semantic similarity.
[0007] Optionally, determining the target error level corresponding to the first erroneous text based on a preset syntax error classification model includes: The feature vector of the first erroneous text is input into the syntax error classification model to obtain the error probability of the first erroneous text at each error level output by the syntax error classification model. The error level corresponding to the largest of multiple error probabilities is taken as the target error level.
[0008] Optionally, the error sample text may further include first error type annotation data corresponding to the first error text; Accordingly, the error text sample data also includes the second error type annotation data corresponding to the second error text.
[0009] Optionally, the step of training the second preset model based on the standard sample text, the erroneous text sample data, and the erroneous sample text to obtain a text correction model includes: The second preset model is trained based on a predefined reward model, the standard sample text, the error text sample data, and the error sample text to obtain the text correction model.
[0010] According to a second aspect of the present disclosure, a text generation method is provided, the method comprising: Receive the target text input by the user; The target text is used as input to a pre-generated text correction model to obtain the target correct text output by the text correction model; the text correction model is generated according to the model generation method described in the first aspect.
[0011] According to a third aspect of the present disclosure, a model generation apparatus is provided, the apparatus comprising: The acquisition module is configured to acquire standard sample text and error sample text, wherein the error sample text includes multiple first error texts and the correct text corresponding to each first error text; the standard sample text includes texts without text errors. The training module is configured to train a first preset model based on the error sample text to obtain an error generation model; An error generation module is configured to take the standard sample text as input to the error generation model and obtain error text sample data corresponding to the standard sample text output by the error generation model, wherein the error text sample data includes at least one second error text. The error correction module is configured to train a second preset model based on the standard sample text, the error text sample data, and the error sample text to obtain a text error correction model, which is used to correct text errors in the input target text.
[0012] Optionally, the training module is further configured to: Using the correct text as input and the first incorrect text as the supervision target, the first preset model is trained to obtain a candidate error generation model; The candidate error generation model is optimized based on the reward function to obtain the error generation model. The reward function is used to guide the candidate error generation model to generate a first error text that corresponds to the correct text and conforms to a specified error type. The correct text and the first error text maintain semantic consistency and have minimal text modification.
[0013] Optionally, the reward function can be determined in the following way: The target error level corresponding to the first erroneous text is determined based on a preset grammatical error classification model; Determine the edit distance between the first erroneous text and the correct text; Determine the semantic similarity between the first erroneous text and the correct text; The reward function is determined based on the target error level, the edit distance, and the semantic similarity.
[0014] Optionally, the training module is further configured to: The feature vector of the first erroneous text is input into the syntax error classification model to obtain the error probability of the first erroneous text at each error level output by the syntax error classification model. The error level corresponding to the largest of multiple error probabilities is taken as the target error level.
[0015] Optionally, the acquisition module is further configured to: The error sample text also includes the first error type annotation data corresponding to the first error text; Accordingly, the error text sample data also includes the second error type annotation data corresponding to the second error text.
[0016] Optionally, the error correction module is further configured to: The second preset model is trained based on a predefined reward model, the standard sample text, the error text sample data, and the error sample text to obtain the text correction model.
[0017] According to a fourth aspect of the present disclosure, a text generation apparatus is provided, the apparatus comprising: The receiving module is configured to receive target text input by the user. The generation module is configured to take the target text as input to a pre-generated text correction model and obtain the target correct text corresponding to the target text output by the text correction model; the text correction model is generated according to the model generation method described in the first aspect of this disclosure.
[0018] According to a fifth aspect of the present disclosure, a computer-readable storage medium is provided having computer program instructions stored thereon, which, when executed by a processor, implement the steps of the methods provided in the first and / or second aspects of the present disclosure.
[0019] According to a sixth aspect of the present disclosure, an electronic device is provided, comprising: A memory on which computer programs are stored; A processor is configured to execute the computer program in the memory to implement the steps of the methods described in the first and / or second aspects of the embodiments of this disclosure.
[0020] According to a seventh aspect of the present disclosure, a computer program product is provided, including a computer program that, when executed by a processor, implements the steps of the methods described in the first and / or second aspects.
[0021] The above technical solution obtains standard sample text and error sample text. The error sample text includes multiple first error texts and the correct text corresponding to each first error text. The standard sample text includes text without errors. A first preset model is trained based on the error sample text to obtain an error generation model. The standard sample text is used as input to the error generation model to obtain error text sample data corresponding to the standard sample text output by the error generation model. The error text sample data includes at least one second error text. A second preset model is trained based on the standard sample text, the error text sample data, and the error sample text to obtain a text correction model. The text correction model is used to correct text errors in the input target text. In this way, by constructing the error generation model and using the standard sample text as input to obtain the error text sample data corresponding to the standard sample text output by the error generation model, diverse error text sample data can be generated automatically and on a large scale, solving the problems of high cost and long cycle of manual annotation. Furthermore, by training the second preset model based on the standard sample text, the error text sample data, and the error sample text, a text correction model can be obtained, which can further improve the training efficiency of the text correction model.
[0022] Other features and advantages of this disclosure will be described in detail in the following detailed description section. Attached Figure Description
[0023] The accompanying drawings are provided to further illustrate the present disclosure and form part of the specification. They are used together with the following detailed description to explain the present disclosure, but do not constitute a limitation thereof. In the drawings: Figure 1 This is a flowchart illustrating a model generation method according to an exemplary embodiment; Figure 2 according to Figure 1 The illustrated embodiment shows a flowchart of a model generation method; Figure 3 A flowchart illustrating a text generation method according to an exemplary embodiment; Figure 4 It is based on Figure 3 The illustrated embodiment presents a schematic diagram of a candidate error generation model. Figure 5 It is based on Figure 3 The illustrated embodiment presents a flowchart for determining a reward function; Figure 6 This is a flowchart illustrating a training error generation model according to an exemplary embodiment; Figure 7This is a flowchart illustrating an example of training a text error correction model; Figure 8 A flowchart illustrating a text generation method according to an exemplary embodiment; Figure 9 It is based on Figure 8 The illustrated embodiment shows a flowchart of a text generation method; Figure 10 This is a block diagram illustrating a model generation apparatus according to an exemplary embodiment; Figure 11 This is a block diagram illustrating a text generation apparatus according to an exemplary embodiment; Figure 12 This is a block diagram illustrating an electronic device according to an exemplary embodiment. Detailed Implementation
[0024] The specific embodiments of this disclosure will be described in detail below with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are for illustration and explanation only and are not intended to limit this disclosure.
[0025] Before detailing the specific implementation methods of this disclosure, the application scenarios of this disclosure are first described below. This disclosure can be applied to application scenarios involving the generation of text error correction models. In the prior art, In the process of generating text correction models, high-quality training data is a crucial foundation for improving the performance of these models. Current technologies typically rely on manually collecting a large number of real essay samples from primary and secondary school students or foreign language learners to build large corpora for training these models. These samples are then meticulously annotated by professionals with language teaching backgrounds to identify grammatical errors, inappropriate word choice, unclear logic, and incomplete structure. This annotation work requires not only solid linguistic knowledge and rich teaching experience from the annotators but also an accurate understanding of the scoring criteria, thus placing extremely high demands on the professionalism of human resources. A more significant problem is that to ensure the sufficiency and generalization ability of the model training, the required amount of annotated data often reaches the millions, which puts enormous cost pressure on the entire data preparation process. The collection, cleaning, classification, and sentence-by-sentence annotation of each essay consumes a significant amount of manpower and time, resulting in a lengthy annotation cycle and high costs. Furthermore, due to the subjective differences inherent in manual annotation, inconsistent annotation results may arise between different annotators, requiring multiple rounds of verification and arbitration, further exacerbating resource consumption. Therefore, relying entirely on manual methods to collect and annotate large-scale essay data to generate text correction models is not only costly but also inefficient.
[0026] To address the aforementioned issues, the solution in this application constructs an error generation model. Standard sample text is used as input to this model, resulting in error text sample data corresponding to the standard sample text output by the model. This enables automated and scalable generation of diverse error text sample data, resolving the problems of high cost and long processing times associated with manual annotation. Furthermore, a second preset model is trained based on the standard sample text, the error text sample data, and the error sample text to obtain a text correction model, further improving the training efficiency of the text correction model.
[0027] Figure 1 This is a flowchart illustrating a model generation method according to an exemplary embodiment, such as... Figure 1 As shown, the model generation method may include: Step 101: Obtain standard sample text and error sample text.
[0028] The error sample text includes multiple first error texts, the correct text corresponding to each first error text, and first error type annotation data corresponding to each first error text. The standard sample text includes texts without errors.
[0029] For example, we can collect first-error texts from students' actual writing in Chinese, containing errors in grammar, vocabulary, logic, and structure, either from the internet or real teaching scenarios. After obtaining these first-error texts, we can use a third-party commercial model (such as GPT-4o) to correct the grammatical errors in the erroneous paragraphs, resulting in the corrected text. The standard text can be sample essays or model compositions obtained from the internet.
[0030] Step 102: Train the first preset model based on the erroneous sample text to obtain the erroneous generation model.
[0031] The first preset model can be a 0.5B (0.5 Billion-parameter model, 500 million parameters model) / 1.5B (1.5 Billion-parameter model, 150 million parameters model) / 7B (7 Billion-parameter model, 700 million parameters model) model.
[0032] In this step, Figure 2 This is a flowchart illustrating a model generation method according to an exemplary embodiment, such as... Figure 2 As shown, it may include the following steps.
[0033] Step 201: Obtain the actual K9 Chinese language essay with errors.
[0034] Among them, the real K9 Chinese language error essays can include the original essays with typical Chinese language errors produced by students in the compulsory education stage (grades 1 to 3 of junior high school, corresponding to the K9 education system), and can be the first error text.
[0035] Step 202: Identify the incorrect paragraphs in the essay.
[0036] In this step, the real K9 Chinese erroneous essay can be segmented according to the segmentation boundaries (e.g., punctuation marks) to obtain the erroneous essay paragraphs corresponding to the real K9 Chinese erroneous essay.
[0037] Step 203: Input the erroneous essay paragraph into a third-party large model.
[0038] Step 204: Obtain the correct essay paragraphs output by the third-party large model.
[0039] Step 205: Identify the incorrect paragraph and the correct paragraph pair (Se, Sc).
[0040] The third-party large model can be any third-party commercial / open-source interface, such as GPT-4o (Generative Pre-trained Transformer4 Omni). It should be noted that the third-party large model can output multiple alternative correct paragraphs, and the correct paragraph needs to be sampled from these multiple alternative correct paragraphs.
[0041] In this step, the erroneous essay paragraph can be input into a preset third-party large model to correct grammatical errors in the erroneous essay paragraph, so as to obtain the correct paragraph after correction, and obtain the erroneous paragraph and correct paragraph pair (Se, Sc), where Se represents the erroneous paragraph and Sc represents the correct paragraph.
[0042] Step 206: Input the erroneous paragraph and the correct paragraph pair into a third-party large model using prompt words to obtain a syntax error vector.
[0043] In this step, the erroneous and correct paragraph pairs can be input into a third-party large-scale model via prompt words for grammatical error analysis and statistics to obtain error type data. This error type data can be a 12-dimensional grammatical error vector. ,in, , ∈[1,12] represents the number of each type of grammatical error. The 12-dimensional grammatical errors include: expression errors, spelling errors, punctuation errors, redundant components, mismatched collocations, ambiguity, structural confusion, incorrect word order, missing components, illogicality, inappropriate word choice, and other error types. An example of a prompt word is shown below: Now we need to analyze the types and number of grammatical errors in the erroneous paragraph. Please process the following: Erroneous paragraph: {first erroneous text}; Correct paragraph: {correct text}, and compare the differences between the two. Strictly follow the following error types for statistical analysis: 1. Expression errors 2. Spelling errors 3. Punctuation errors 4. Redundant components 5. Mismatched collocations 6. Ambiguous meaning 7. Structural confusion 8. Incorrect word order 9. Missing components 10. Illogicality 11. Inappropriate word choice 12. Other (if there are any uncovered types, they are included here but must be explained), and output a 12-dimensional error vector, which includes the number of errors corresponding to each error type. The results can be returned in a clear list or vector format, for example: (Incorrect expression): 0, (Spelling error): 2,... (Other): 0. It can also be in a compact vector format: [0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0], but the dimensional correspondences must be explicitly labeled. It can be in pairs of incorrect and correct paragraphs (Se, Sc) and a 12-dimensional vector of grammatical errors. Given a dataset, train the first preset model to obtain an incorrectly generated model.
[0044] Step 103: Use the standard sample text as input to the error generation model to obtain the error text sample data corresponding to the standard sample text output by the error generation model.
[0045] The error text sample data includes at least one second error text.
[0046] Step 104: Train the second preset model based on the standard sample text, the error text sample data, and the error sample text to obtain a text correction model.
[0047] The text correction model is used to determine text errors in the input target text. The second preset model can be a model based on a recurrent neural network model, a long short-term memory network model, a gated recurrent unit model, or a Transformer architecture.
[0048] In this step, the standard sample text, the second erroneous text, the second error type annotation data, the first erroneous text, the correct text, and the first error type annotation data can be used to train the second preset model to obtain the text correction model.
[0049] The above technical solution, by constructing the error generation model and using the standard sample text as input, obtains error text sample data corresponding to the standard sample text output by the error generation model. This enables the automated and scalable generation of diverse error text sample data, solving the problems of high cost and long cycle of manual annotation. Furthermore, by training a second preset model based on the standard sample text, the error text sample data, and the error sample text, a text correction model is obtained, which can further effectively improve the training efficiency of the text correction model.
[0050] Figure 3 according to Figure 1 The illustrated embodiment shows a flowchart of a model generation method, such as... Figure 3 As shown, Figure 1 Step 102, which involves training the first preset model based on the erroneous sample text to obtain an error generation model, may include: Step 301: Using the correct text as input and the first incorrect text as the supervision target, train the first preset model to obtain a candidate error generation model.
[0051] The first preset model can be a model with different parameters such as 0.5B / 1.5B / 7B, and the model size is not limited.
[0052] In this step, the correct text can be divided into multiple correct paragraphs based on its length and natural segmentation boundaries (e.g., punctuation marks), and the first incorrect text can be divided into multiple incorrect paragraphs based on its length and natural segmentation boundaries (e.g., punctuation marks). Using the correct paragraphs from the correct text as input and the incorrect paragraphs from the first incorrect text as the supervised target, supervised fine-tuning training is performed on a model with parameters such as 0.5B / 1.5B / 7B (model parameters are not limited) to obtain a candidate error generation model.
[0053] For example, Figure 4 It is based on Figure 3 The illustrated embodiment presents a schematic diagram of determining the candidate error generation model, as shown below. Figure 4As shown, determining the candidate error generation model (error behavior cloning training) may include: inputting the correct paragraph from the correct text into a pre-trained model such as 0.5B / 1.5B / 7B to obtain the error paragraph corresponding to the first error text output by the pre-trained model such as 0.5B / 1.5B / 7B, to perform supervised fine-tuning training on the pre-trained model such as 0.5B / 1.5B / 7B, optimizing the pre-trained model such as 0.5B / 1.5B / 7B, and using the pre-trained model such as 0.5B / 1.5B / 7B as the candidate error generation model after the model converges. First, error-prone essay writing data can be collected, and the error-prone essay writing data can be divided into multiple unused error paragraphs according to the length and natural paragraph boundaries (e.g., punctuation marks). Then, an open-source / closed-source large model is used to correct the grammatical errors of the unused error paragraphs to obtain the correct error paragraphs corresponding to the unused error paragraphs, and a correct error paragraph pair is obtained, which is represented as: ,in, Indicates the correct paragraph to be used. This represents the potential error segment. The potential correct error segment can be used to perform supervised training on pre-trained models such as 0.5B / 1.5B / 7B. The loss function can be the cross-entropy loss function. Using the potential correct segment as the input to the 0.5B / 1.5B / 7B pre-trained model and the potential error segment as the supervised target, supervised fine-tuning training is performed on the 0.5B / 1.5B / 7B pre-trained model to optimize it. After the 0.5B / 1.5B / 7B pre-trained model converges, the model parameters from the 0.5B / 1.5B / 7B pre-trained model are used as the model parameters of the candidate error generation model.
[0054] Step 302: Optimize the candidate error generation model based on the reward function to obtain the error generation model.
[0055] The reward function is used to guide the candidate error generation model to generate a first error text that corresponds to the correct text and conforms to a specified error type. The correct text and the first error text maintain semantic consistency and have minimal text modification.
[0056] In this step, the reward function can be determined as follows: determining the target error level corresponding to the first erroneous text based on a preset syntax error classification model, determining the edit distance between the first erroneous text and the correct text, determining the semantic similarity between the first erroneous text and the correct text, and determining the reward function based on the target error level, the edit distance, and the semantic similarity. Specifically, determining the target error level corresponding to the first erroneous text based on the preset syntax error classification model can include: inputting the feature vector of the first erroneous text into the syntax error classification model to obtain the error probability of the first erroneous text at each error level output by the syntax error classification model; and using the error level corresponding to the largest of multiple error probabilities as the target error level. Alternatively, the feature vector of the first erroneous text can be input into the syntax error classification model to obtain the cumulative probability of the first erroneous text at each error level output by the syntax error classification model, and the error probability corresponding to each error level can be determined by difference calculation. Or, the error level corresponding to the largest of multiple error probabilities can be used as the target error level.
[0057] Figure 5 It is based on Figure 3 The illustrated embodiment presents a flowchart for determining a reward function, as shown below. Figure 5 As shown, it may include the following steps.
[0058] Step 501: Sample the erroneous and correctly grammatically correct paragraphs.
[0059] In this step, incorrect and correct grammatical paragraphs are sampled to obtain target error-correct paragraph pairs. These target error-correct paragraph pairs include both incorrect and correct paragraphs.
[0060] Step 502: Input the target error-correct paragraph pair into the 0.5B / 1.5B / 7B small model.
[0061] In this step, the target error-corrected paragraph can be input into a 0.5B / 1.5B / 7B small model, and the 0.5B / 1.5B / 7B small model can be fine-tuned using a multi-dimensional syntax error model to obtain a 12-dimensional syntax error vector. .
[0062] Step 503: Calculate grammatical error rewards for erroneous paragraphs.
[0063] Step 504: Calculate the editing distance reward for the target incorrect and correct paragraph pairs.
[0064] Step 505: Calculate the semantic similarity reward for the target incorrect and correct paragraph pairs.
[0065] In this step, error-correct paragraph pairs in the dataset can be sampled to obtain target error-correct paragraph pairs. These target error-correct paragraph pairs are then input into 0.5B / 1.5B / 7B small models and analyzed based on the 12-dimensional syntax error vector. A grammatical error reward calculation is performed on the erroneous paragraphs to determine the corresponding grammatical error level score. Edit distance rewards are calculated for the target error-correct paragraph pair to obtain the edit distance score between the correct and error paragraphs. Semantic similarity rewards are calculated for the target incorrect and correct paragraph pairs to obtain semantic similarity scores between the correct and incorrect paragraphs. The reward function is determined by weighting and summing the syntax error score, the edit distance score, and the semantic similarity score. .
[0066] For example, the edit distance score can be determined using an edit distance determination formula, which is shown below: , ; in, The absolute value of the edited paragraph indicates whether it is a correct or incorrect paragraph. Indicates the text length of the correct paragraph. This represents the ratio between the absolute value of the correct and incorrect paragraphs and the text length of the correct paragraph.
[0067] The semantic similarity score between the erroneous paragraph corresponding to the first erroneous text and the correct paragraph corresponding to the correct text can be determined using the cosine distance of the paragraph embedding vectors. The formula for determining the semantic similarity score is as follows: ; in, This indicates the semantic similarity between correct and incorrect paragraphs.
[0068] The reward function can be determined. .
[0069] It should be noted that the grammar error level score This can be determined in the following way: the 12-dimensional syntax error vector corresponding to the first erroneous text can be used. As syntax error observation vectors, and using these syntax error observation vectors as the syntax error observation vector dataset. From the syntax error observation vector dataset Multiple (e.g., 1000) target error paragraphs corresponding to typical grammatical error observation vectors with balanced error distribution are manually selected. These target error paragraphs are then manually labeled with error severity scores, focusing on the importance of different error types; generally, more errors result in higher scores. Paragraphs without errors receive a score of 0. For example, 0 points represent no errors; 1-3 points represent minor errors (1-2 errors, not affecting comprehension); 4-6 points represent moderate errors (3-5 errors, difficult to understand); 7-9 points represent serious errors (more than 5 errors, semantic confusion); and 10 points represent completely unreadable. Errors are graded, with up to 10 error levels, mapping error scores to 10 discrete levels (ordered classification). The input can be "prompt words + paragraphs containing grammatical errors," and the output labels can be the 12-dimensional grammatical error levels. The LoRa supervised fine-tuning method is used to fine-tune small models of 0.5B / 1.5B / 7B to obtain the grammatical error classification model.
[0070] Determining the grammatical error grade score corresponding to the erroneous paragraph includes: quantifying the difference between the correct and erroneous paragraphs using a predefined loss function. The target error grade score corresponding to the erroneous paragraph is then determined based on the loss function. The expression for the loss function is as follows:
[0071] in, Indicates the error level. Represents the syntax error observation vector. The threshold parameter for the i-th category (satisfying) < <...< ); This represents the coefficient vector of the independent variable.
[0072] In one implementation, the parameters in the loss function can be estimated using the maximum likelihood estimation method. and For each observation data point in each error segment ( The log-likelihood function is defined according to the model. Numerical optimization methods, such as gradient descent, Newton's method, or quasi-Newton methods, can be used to maximize the log-likelihood function. In this application, for an ordered classification model, the log-likelihood function can be expressed as:
[0073] in, This indicates an indicator function that takes the value 1 when the condition is true and 0 otherwise.
[0074] Determining the target error level score corresponding to the erroneous paragraph based on the loss function includes: determining the error feature vector corresponding to the erroneous paragraph based on the loss function. The cumulative distribution function value for each error level is determined by the following formula:
[0075] The error probability corresponding to each error level is determined by difference calculation based on the cumulative distribution function value. The formula for determining the error probability corresponding to each error level is as follows:
[0076] in, ; ; The error level corresponding to the highest of multiple error probabilities can be used as the target error level score. The formula for determining the target error level score is as follows: .
[0077] Figure 6 This is a flowchart illustrating a method for training the error generation model according to an exemplary embodiment, such as... Figure 6 As shown, it may include the following steps.
[0078] Step 601, select the correct paragraph from K9 ({ Input the 0.5B / 1.5B / 7B error behavior clone into the trained model.
[0079] In this step, you can select the correct paragraph from K9 ({ Input the model into the 0.5B / 1.5B / 7B error behavior clone training model to output multiple error paragraphs.
[0080] Step 602: Sample the erroneous paragraphs to obtain erroneous sentence 1, erroneous sentence 2, ..., erroneous sentence G.
[0081] Step 603: Input the G erroneous sentences into the reference model.
[0082] In this step, after inputting G erroneous sentences into the reference model, the model is updated by cloning and training the 0.5B / 1.5B / 7B erroneous behaviors.
[0083] Step 604: Input the G erroneous sentences into the reward model.
[0084] Step 605: Calculate the reward function for the G erroneous sentences to obtain reward 1, reward 2, ..., reward G.
[0085] Step 606: Perform intra-group reward normalization calculation on the G rewards.
[0086] Step 607: Calculate the advantage function for the normalized in-group reward.
[0087] In this step, the advantage function is calculated for the normalized in-group reward, and the policy is updated for the model trained with 0.5B / 1.5B / 7B error behavior clones.
[0088] Among them, the model trained with 0.5B / 1.5B / 7B error behavior clones can be candidate error generation models, and the updated model trained with 0.5B / 1.5B / 7B error behavior clones can be error generation models.
[0089] In this step, the correct paragraph in K9 ({ The input is fed into the candidate error generation model, generating multiple erroneous sentences according to the current strategy. After sampling, G erroneous sentences (erroneous sentence 1, erroneous sentence 2, ..., erroneous sentence G) are obtained. A comprehensive reward is calculated for each erroneous sentence based on the reward function, taking into account grammatical error severity, semantic fidelity, and editing rationality. The advantage value of each erroneous sentence is determined based on the comprehensive reward and the paragraph penalty value, by subtracting the average reward within the group. A paragraph penalty value is determined for each erroneous paragraph based on the reference model, used to prevent the candidate error generation model from deviating too far from its initial behavior. The strategy of the candidate error model is updated to obtain the error generation model. The reference model is used to calculate the strategy ratio but does not participate in strategy updates. Every few rounds, the current strategy is synchronized to the reference model. After the error generation model converges, multiple correct paragraphs can be input into the error generation model for model inference to obtain the erroneous-to-correct paragraph pairs. .in, This can expand the number of wireless connections.
[0090] The above technical solution, using the correct text as input and the first erroneous text as the supervised target, trains the first preset model to obtain a candidate error generation model. The candidate error generation model is then optimized based on a reward function to obtain the final error generation model. This approach can automatically and scalably generate diverse error samples, significantly alleviating the problems of high cost and long cycle of manual annotation. Furthermore, by controlling the types of error generation, the coverage and controllability of the training data can be improved. The generated error samples possess high linguistic naturalness and error typicality, constituting high-quality training data.
[0091] Optionally, training a second preset model based on the standard sample text, the erroneous text sample data, and the erroneous sample text to obtain a text correction model may include: The second preset model is trained based on the predefined reward model, the standard sample text, the error text sample data, and the error sample text to obtain the text correction model.
[0092] In this step, the second preset model can be trained using a reinforcement learning strategy to obtain the text correction model. The reward model in the text correction model can be designed based on the principle of minimizing changes to erroneous paragraphs while ensuring the correctness of the corrections, and ensuring that the output conforms to a predefined correction format. The reward model is defined based on the semantic consistency, editing rationality, and format compliance between the model output and the target correct paragraph. The output of the text correction model must meet the preset correction format, for example, including two parts: "thinking and reasoning" and "correction result," with the corrected part being the final correction result.
[0093] The design of the reward model is as follows: ; in, Indicates the reward value; This indicates an incorrect paragraph in the input; Indicates the predicted paragraph of the output; This indicates the correct paragraph to be output; This indicates the edit distance between the predicted paragraph and the correct paragraph; This indicates the edit distance between the incorrect paragraph and the predicted paragraph; This indicates the edit distance between the incorrect and correct paragraphs; This represents the penalty term in an N-gram language model. This indicates the formatting penalty for predicted paragraphs.
[0094] Figure 7 This is a flowchart illustrating an example of training the text correction model, such as... Figure 7 As shown, it may include the following steps.
[0095] Step 701, remove the incorrect sentence ({ Input into the supervised training model with 0.5B / 1.5B / 7B grading capabilities.
[0096] In this step, the incorrect sentence ({ The input is fed into a model trained under supervised instruction with 0.5B / 1.5B / 7B correction capabilities to output corrected sentences.
[0097] Step 702: Sample the corrected sentences to obtain correct sentence 1, correct sentence 2, ..., correct sentence G.
[0098] Step 703: Input the G correct sentences into the reference model.
[0099] In this step, G correct sentences can be input into the reference model, and the model can be updated after supervised training with 0.5B / 1.5B / 7B grading capabilities.
[0100] Step 704: Input the G correct sentences into the reward model.
[0101] In this step, the correct sentence 1, correct sentence 2, ..., correct sentence G can be input into the reward model.
[0102] Step 705: Calculate the reward function for the G correct sentences to obtain reward 1, reward 2, ..., reward G.
[0103] Step 706: Perform intra-group reward normalization calculation on the G rewards.
[0104] Step 707: Calculate the advantage function for the normalized in-group reward.
[0105] In this step, the advantage function is calculated for the normalized in-group reward, and the policy is updated for the model trained with 0.5B / 1.5B / 7B grading ability supervision.
[0106] Among them, the incorrect sentence ({ The}) can be a K9 essay with erroneous paragraphs. The model trained with 0.5B / 1.5B / 7B correction ability supervision can be the initial text correction model, and the updated model trained with 0.5B / 1.5B / 7B correction ability supervision can be a text correction model.
[0107] In this step, erroneous paragraphs are input into the initial text correction model, which generates multiple correct sentences according to the current strategy. After sampling, G correct sentences are obtained. A comprehensive reward is calculated for each correct sentence based on the reward model. The advantage value of each correct sentence is determined by subtracting the average reward within the group from the comprehensive reward. The initial text correction model is then updated according to the objective function of the GRPO model to obtain the final text correction model.
[0108]
[0109] in, This represents the objective function of the GRPO model. This represents the number of candidate corrected sentences generated by sampling. Indicates the first One generated sample, Indicates the dominance value. This represents the reward for the i-th generated sentence. This represents the average reward within the group. clip(·, 1-∈, 1+∈) means limiting the policy ratio to the interval (1-∈, 1+∈) to prevent excessive policy updates. ] represents the KL divergence, used to constrain the current policy. Reference Strategy The degree of deviation between them. This represents the KL divergence regularization coefficient, used to control the penalty intensity.
[0110] After completing the reinforcement learning fine-tuning, the text error correction model is fine-tuned again (SFT) using the original supervised training data to recover the degradation of basic error correction capabilities that may have been caused by RL training and to enhance the alignment of the model with the standard data distribution.
[0111] It should be noted that since the text correction model learns to output intermediate processes such as thinking and reasoning during the reinforcement learning stage, during supervised training, any content containing thinking and reasoning in the model output should be pruned (deleted) when calculating the cross-entropy loss function, retaining only the corrected formal error correction result and the target correct paragraph.
[0112] The above technical solution, within the framework of reinforcement learning, trains the second preset model based on a predefined reward model, the standard sample text, the error text sample data, and the error sample text. This ensures that the correct text and the first error text maintain semantic consistency with minimal text modification, thereby effectively improving the correction quality of the target correct text generated by the text correction model.
[0113] Figure 8 A flowchart illustrating a text generation method according to an exemplary embodiment is shown, such as... Figure 8 As shown, the method may include: Step 801: Receive the target text input by the user.
[0114] In this step, users can upload the target text by handwriting on an electronic device screen, inputting the text using an electronic device's input method, or handwriting it on paper.
[0115] Step 802: Use the target text as input to a pre-generated text correction model to obtain the target correct text output by the text correction model.
[0116] The text correction model is based on Figures 1-7 The model was generated by the aforementioned model generation method.
[0117] For example, Figure 9 It is based on Figure 8 The illustrated embodiment shows a flowchart of a text generation method, such as... Figure 9 As shown, it may include the following steps.
[0118] Step 901: Obtain a paper copy of the handwritten essay.
[0119] Step 902: Obtain the handwritten essay from the screen of the electronic device.
[0120] Step 903: Obtain the input of the essay using the electronic device's input method.
[0121] Step 904: Conduct an essay test on the handwritten paper essays.
[0122] In this step, the handwritten essays uploaded via photo taken by the device can be checked.
[0123] Step 905: Perform optical character recognition on the essay area.
[0124] In this step, optical character recognition can be performed on the writing area in handwritten essays on paper and the writing area in handwritten essays on electronic device screens to obtain the initial text.
[0125] Step 906: Perform text straightening on the primary text.
[0126] In this step, you can input your essay using an electronic device's input method as the initial text, and then perform text shaping operations on the initial text.
[0127] Step 907: Perform text segmentation on the text after text normalization.
[0128] In this step, the text after it has been formatted is segmented to obtain multiple paragraphs containing errors. .
[0129] Step 908: Input the incorrect paragraph into the 0.5B / 1.5B / 7B K9 Chinese composition correction model to obtain the corrected paragraph. .
[0130] Among them, the 0.5B / 1.5B / 7B K9 Chinese composition correction model can be a text error correction model.
[0131] In this step, if the source of the essay being graded is determined to be a handwritten paper essay, the essay can be photographed using a device. An image processing algorithm can then be used to define the valid writing area within the image, and optical character recognition (OCR) can be performed on this defined area to obtain the initial text. If the source of the essay being graded is determined to be a handwritten essay on an electronic device screen, the valid writing area can be directly defined from the device screen, and OCR can be performed on this defined area to obtain the initial text. If the source of the essay being graded is determined to be essay content entered using an electronic device's input method, this content can be directly used as the initial text. After obtaining the initial recognized text, the following standardization operations can be performed: Punctuation format can be standardized, such as converting full-width punctuation to half-width punctuation and removing unnecessary spaces to ensure proper text formatting. Characters in the initial recognized text can also be standardized to standard Unicode encoding to avoid problems caused by encoding inconsistencies. Punctuation marks (such as periods, exclamation marks, and question marks) can be used as separators to divide the initial recognized text into multiple sentences. The text is further subdivided by incorporating existing line breaks. Each paragraph is length-checked; if it exceeds a preset maximum length, it is truncated to ensure appropriate paragraph length and identify the specified erroneous paragraphs. These erroneous paragraphs are then input into a text correction model, which analyzes and corrects them, outputting a reference correct paragraph.
[0132] The above technical solution, by using the target text as input to a pre-generated text correction model, can obtain the target correct text corresponding to the target text output by the text correction model.
[0133] Figure 10 This is a block diagram illustrating a model generation apparatus 1000 according to an exemplary embodiment, such as... Figure 10 As shown, the model generation device 1000 includes: The acquisition module 1001 is configured to acquire standard sample text and error sample text, wherein the error sample text includes a plurality of first error texts and the correct text corresponding to each first error text; the standard sample text includes texts without text errors. Training module 1002 is configured to train a first preset model based on the error sample text to obtain an error generation model; Error generation module 1003 is configured to take the standard sample text as input to the error generation model and obtain error text sample data corresponding to the standard sample text output by the error generation model, wherein the error text sample data includes at least one second error text. The error correction module 1004 is configured to train a second preset model based on the standard sample text, the error text sample data, and the error sample text to obtain a text error correction model, which is used to correct text errors in the input target text.
[0134] Optionally, the training module 1002 is further configured to: Using the correct text as input and the first incorrect text as the supervision target, the first preset model is trained to obtain a candidate error generation model; The candidate error generation model is optimized based on the reward function to obtain the error generation model. The reward function is used to guide the candidate error generation model to generate a first error text that corresponds to the correct text and conforms to a specified error type. The correct text and the first error text maintain semantic consistency and have minimal text modification.
[0135] Optionally, the reward function can be determined in the following way: The target error level corresponding to the first erroneous text is determined based on a preset grammatical error classification model; Determine the edit distance between the first erroneous text and the correct text; Determine the semantic similarity between the first erroneous text and the correct text; The reward function is determined based on the target error level, the edit distance, and the semantic similarity.
[0136] Optionally, the training module 1002 is further configured to: The feature vector of the first erroneous text is input into the syntax error classification model to obtain the error probability of the first erroneous text at each error level output by the syntax error classification model. The error level corresponding to the largest of multiple error probabilities is taken as the target error level.
[0137] Optionally, the acquisition module 1001 is further configured to: The error sample text also includes the first error type annotation data corresponding to the first error text; Accordingly, the error text sample data also includes the second error type annotation data corresponding to the second error text.
[0138] Optionally, the error correction module 1004 is further configured to: The second preset model is trained based on a predefined reward model, the standard sample text, the error text sample data, and the error sample text to obtain the text correction model.
[0139] Figure 11 This is a block diagram illustrating a text generation apparatus 1100 according to an exemplary embodiment, such as... Figure 11 As shown, the text generation device 1100 includes: The receiving module 1101 is configured to receive target text input by the user; The generation module 1102 is configured to take the target text as input to a pre-generated text correction model to obtain the target correct text corresponding to the target text output by the text correction model; the text correction model is based on this disclosure. Figures 1-7 The model was generated by the aforementioned model generation method.
[0140] Regarding the apparatus in the above embodiments, the specific manner in which each module performs its operation has been described in detail in the embodiments related to the method, and will not be elaborated upon here.
[0141] Figure 12 This is a block diagram illustrating an electronic device 1200 according to an exemplary embodiment. For example... Figure 12 As shown, the electronic device 1200 may include: a processor 1201 and a memory 1202. The electronic device 1200 may also include one or more of a multimedia component 1203, an input / output (I / O) interface 1204, and a communication component 1205.
[0142] The processor 1201 controls the overall operation of the electronic device 1200 to complete all or part of the steps in the model generation method and / or text generation method described above. The memory 1202 stores various types of data to support the operation of the electronic device 1200. This data may include, for example, instructions for any application or method operating on the electronic device 1200, and application-related data such as contact data, sent and received messages, images, audio, video, etc. The memory 1202 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as Static Random Access Memory (SRAM), Electrically Erasable Programmable Read-Only Memory (EEPROM), Erasable Programmable Read-Only Memory (EPROM), Programmable Read-Only Memory (PROM), Read-Only Memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk. Multimedia component 1203 may include a screen and an audio component. The screen may be, for example, a touchscreen, and the audio component is used to output and / or input audio signals. For example, the audio component may include a microphone for receiving external audio signals. The received audio signals may be further stored in memory 1202 or transmitted via communication component 1205. The audio component also includes at least one speaker for outputting audio signals. I / O interface 1204 provides an interface between processor 1201 and other interface modules, such as a keyboard, mouse, buttons, etc. These buttons may be virtual or physical buttons. Communication component 1205 is used for wired or wireless communication between the electronic device 1200 and other devices. Wireless communication may include Wi-Fi, Bluetooth, Near Field Communication (NFC), 2G, 3G, or 4G, or a combination of these. Therefore, the corresponding communication component 1205 may include a Wi-Fi module, a Bluetooth module, or an NFC module.
[0143] In an exemplary embodiment, the electronic device 1200 may be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field-programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic components to perform the model generation method and / or text generation method described above.
[0144] In another exemplary embodiment, a computer-readable storage medium including program instructions is also provided, which, when executed by a processor, implement the steps of the model generation method and / or text generation method described above. For example, the computer-readable storage medium may be the memory 1202 including the program instructions described above, which may be executed by the processor 1201 of the electronic device 1200 to complete the model generation method and / or text generation method described above.
[0145] In another exemplary embodiment, a computer program product is also provided, which includes a computer program executable by a processor, which, when executed by the processor, implements the steps of the model generation method and / or text generation method described above.
[0146] In another exemplary embodiment, a computer program product is also provided, which includes a computer program executable by a processor, which, when executed by the processor, implements the steps of the model generation method and / or text generation method described above.
[0147] The preferred embodiments of this disclosure have been described in detail above with reference to the accompanying drawings. However, this disclosure is not limited to the specific details of the above embodiments. Within the scope of the technical concept of this disclosure, various simple modifications can be made to the technical solutions of this disclosure, and these simple modifications all fall within the protection scope of this disclosure.
[0148] It should also be noted that the various specific technical features described in the above specific embodiments can be combined in any suitable manner without contradiction. In order to avoid unnecessary repetition, this disclosure will not describe the various possible combinations separately.
[0149] Furthermore, various different embodiments of this disclosure can be combined in any way, as long as they do not violate the spirit of this disclosure, they should also be regarded as the content disclosed in this disclosure.
Claims
1. A model generation method characterized by comprising: The method comprises: obtaining standard sample text and error sample text, the error sample text comprising a plurality of first error texts and correct texts corresponding to each first error text; the standard sample text comprising text without text errors; training a first preset model according to the error sample text to obtain an error generation model; taking the standard sample text as input of the error generation model to obtain error text sample data corresponding to the standard sample text output by the error generation model, the error text sample data comprising at least one second error text; training a second preset model based on the standard sample text, the error text sample data and the error sample text to obtain a text error correction model, the text error correction model being used for correcting text errors in an input target text.
2. The model generation method according to claim 1, characterized by, The training of the first preset model according to the error sample text to obtain an error generation model comprises: training the first preset model with the correct text as input and the first error text as supervision target to obtain a candidate error generation model; optimizing the candidate error generation model based on a reward function to obtain the error generation model, the reward function being used for guiding the candidate error generation model to generate a first error text corresponding to the correct text and conforming to a specified error type, wherein the correct text and the first error text maintain semantic consistency and have minimal text changes.
3. The model generation method according to claim 2, characterized by, The reward function can be determined in the following manner: determining a target error level corresponding to the first error text according to a preset syntax error classification model; determining an edit distance between the first error text and the correct text; determining a semantic similarity between the first error text and the correct text; performing weighted summation on the target error level, the edit distance and the semantic similarity to determine the reward function.
4. The model generation method according to claim 3, characterized by, The determination of the target error level corresponding to the first error text according to the preset syntax error classification model comprises: determining a loss function in the syntax error classification model based on a maximum likelihood estimation method, the loss function being used for quantifying differences between correct paragraphs and error paragraphs; determining a cumulative distribution function value of a feature vector of the first error text at each error level according to the loss function; determining an error probability of the feature vector at each error level based on the cumulative distribution function value through differential calculation; taking an error level corresponding to a maximum error probability in a plurality of error probabilities as the target error level.
5. The model generation method according to claim 4, characterized by, The determination of the loss function in the syntax error classification model based on the maximum likelihood estimation method comprises: defining a log-likelihood function of the loss function based on an ordered classification model; maximizing the log-likelihood function through a numerical optimization method to determine model parameters in the loss function.
6. The model generation method according to claim 1, wherein The error sample text further comprises first error type annotation data corresponding to the first error text; Correspondingly, the error text sample data further comprises second error type annotation data corresponding to the second error text.
7. The model generation method of claim 1, wherein, The second preset model is trained based on the standard sample text, the error text sample data, and the error sample text to obtain a text error correction model. The second preset model is trained based on the pre-defined reward model, the standard sample text, the error text sample data, and the error sample text to obtain the text error correction model.
8. A text generation method characterized by, The method comprises: receiving a target text input by a user; inputting the target text into a pre-generated text error correction model to obtain a target correct text corresponding to the target text output by the text error correction model; the text error correction model is generated by the model generation method in any one of claims 1 to 6.
9. A model generation apparatus characterized by comprising: The apparatus comprises: an obtaining module configured to obtain standard sample text and error sample text, the error sample text comprising a plurality of first error texts and correct text corresponding to each first error text; the standard sample text comprising text without text errors; a training module configured to train a first preset model according to the error sample text to obtain an error generation model; an error generation module configured to input the standard sample text into the error generation model to obtain error text sample data corresponding to the standard sample text output by the error generation model, the error text sample data comprising at least one second error text; a correction module configured to train a second preset model according to the standard sample text, the error text sample data, and the error sample text to obtain a text error correction model, the text error correction model being used to correct text errors in an input target text.
10. A text generating apparatus characterized by comprising: The apparatus comprises: a receiving module configured to receive a target text input by a user; a generating module configured to input the target text into a pre-generated text error correction model to obtain a target correct text corresponding to the target text output by the text error correction model; the text error correction model being generated by the model generation method in any one of claims 1 to 6.
11. A computer readable storage medium having stored thereon a computer program, characterized in that The program is executed by the processor to implement the steps of the method in any one of claims 1 to 8.
12. An electronic device, comprising: comprises: a memory having a computer program stored thereon; a processor configured to execute the computer program in the memory to implement the steps of the method in any one of claims 1 to 7.
13. A computer program product comprising a computer program, characterized in that, The computer program is executed by the processor to implement the steps of the method in any one of claims 1 to 8. comprises: a memory having a computer program stored thereon; a processor configured to execute the computer program in the memory to implement the steps of the method in any one of claims 1 to 7. The computer program is executed by the processor to implement the steps of the method in any one of claims 1 to 8.