Text error correction method, device and electronic equipment
By using the pre-trained large language model and the low-rank adapter method LoRA, the official document data set is fine-tuned to generate a text error correction model, which solves the problems of low text error correction accuracy and poor generalization ability in the existing technology, and achieves Efficient processing of complex text errors and improvement of generalization capabilities.
Patent Information
- Application Number
- CN202410193183.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-02-21
- Publication Date
- 2024-08-27
- Estimated Expiration
- 2044-02-21
AI Technical Summary
Existing rule-based text error correction methods have low accuracy and poor generalization ability when dealing with text errors caused by complex grammatical structures and semantic relationships. They also need to rely on the manual knowledge of domain experts or linguists, which increases production costs, and Rules need to be adjusted frequently when processing text data in different domains.
It uses a pre-trained large language model combined with the low-rank adapter method LoRA to fine-tune the official document data set and generate a text error correction model. It handles various types of errors such as grammar and semantics through a generative model, and uses a proper noun library and punctuation The symbol library is used for correction to ensure that the corrected text is standardized.
It improves the accuracy and generalization ability of text error correction, can effectively handle different levels of text errors, reduces hardware requirements and production costs, and maintains the natural smoothness and coherence of the corrected text.
Smart Images

Figure CN117744633B
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of large model technology, and in particular to a text error correction method, device and electronic device. Background Art
[0002] A large language model is a deep learning model that contains hundreds of billions or more parameters, which are obtained through training with a large amount of text data. Based on the Transformer architecture, the large language model can process a large amount of natural language text, learn knowledge and language rules from it, and improve the ability to understand and generate natural language. Therefore, the large language model can achieve some tasks that are difficult to achieve with traditional methods, such as text generation, reading comprehension, common sense reasoning, etc.
[0003] The rule-based text error correction method detects and repairs spelling errors, grammatical errors, punctuation errors, etc. in the text by pre-defining a series of rules. The core idea of this method is to establish rules based on predefined error patterns, identify errors and make corresponding corrections by matching the rules on the text. Each rule usually includes steps such as error pattern definition, rule design, context consideration, and error correction operation.
[0004] However, for text errors caused by complex grammatical structures and semantic relationships, predefined rules often cannot cover all error patterns. In addition, the design of rules needs to rely on the manual knowledge of domain experts or linguists, which will increase production costs. Moreover, for text data in different fields, rule-based text correction methods have poor generalization ability when dealing with different types of errors in new fields or specific fields, and the rules need to be adjusted frequently. Summary of the invention
[0005] The embodiments of the present application provide a text error correction method, device and electronic device, which can solve the problem of low accuracy and poor generalization ability of the text error correction method.
[0006] In a first aspect, an embodiment of the present application provides a text error correction method, the method comprising:
[0007] Get a pre-trained large model;
[0008] Acquire an official document data set, wherein the official document data set includes normal text data and error text data, wherein the text in the error text data includes grammatical errors, semantic errors, and typos;
[0009] Segmenting the official document data set according to punctuation marks to obtain a segmented official document data set;
[0010] Using the segmented official document dataset, the pre-trained large model is fine-tuned based on the low-rank adapter method LoRA to obtain a text error correction model;
[0011] Inputting the text to be corrected into the text correction model to obtain the corrected text;
[0012] Compare the corrected text with the text to be corrected to obtain the correction position and the erroneous text;
[0013] Correct the error-corrected text and output the target text.
[0014] In one possible design, it also includes:
[0015] Adding a first low-rank matrix and a second low-rank matrix to the pre-trained large model;
[0016] Use the segmented text data to train the first low-rank matrix and the second low-rank matrix;
[0017] The first low-rank matrix and the second low-rank matrix are fine-tuned and the parameters are updated.
[0018] In one possible design, it also includes:
[0019] The first low-rank matrix is Gaussian initialized.
[0020] In one possible design, it also includes:
[0021] The second low-rank matrix is initialized to zero.
[0022] In one possible design, it also includes:
[0023] Correct proper nouns and punctuation marks in the corrected text.
[0024] In one possible design, it also includes:
[0025] Processing the normal text data to obtain a proper noun library and a punctuation mark library;
[0026] The corrected text is matched according to the proper noun library and the punctuation mark library to ensure the standardization of the output text.
[0027] In one possible design, it also includes:
[0028] The pre-trained large model adopts a generative model.
[0029] In a second aspect, an embodiment of the present application provides a device, the device comprising:
[0030] An acquisition module is used to acquire a pre-trained large model; acquire an official document data set, wherein the official document data set includes normal text data and error text data, and the text in the error text data includes grammatical errors, semantic errors, and typos;
[0031] The processing module is used to segment the official document data set according to punctuation marks to obtain a segmented official document data set; use the segmented official document data set to fine-tune the pre-trained large model based on the low-rank adapter method LoRA to obtain a text correction model; input the text to be corrected into the text correction model to obtain a corrected text; compare the corrected text with the text to be corrected to obtain a correction position and an erroneous text; correct the corrected text and output a target text.
[0032] In a third aspect, an embodiment of the present application provides an electronic device, comprising a memory and one or more processors; wherein the memory is used to store computer program code, and the computer program code comprises computer instructions; when the computer instructions are executed by the processor, the electronic device executes part or all of the steps of the method in the first aspect or various possible implementations of the first aspect.
[0033] In a fourth aspect, an embodiment of the present application provides a computer storage medium, which stores instructions. When the instructions are executed on a computer, the computer executes part or all of the steps of the method in the first aspect or various possible implementations of the first aspect.
[0034] The present application provides a text error correction method, the method comprising: obtaining a pre-trained large model; obtaining an official document data set, the official document data set comprising normal text data and error text data, the text in the error text data comprising grammatical errors, semantic errors, and typos; segmenting the official document data set according to punctuation marks to obtain a segmented official document data set; using the segmented official document data set to fine-tune the pre-trained large model based on the low-rank adapter method LoRA to obtain a text error correction model; inputting the text to be corrected into the text error correction model to obtain the corrected text; correcting the corrected text and outputting the target text. The low-rank adapter method LoRA can reduce memory usage, simplify computing requirements, accelerate the training and fine-tuning process of the large model, and have low hardware requirements. In addition, based on the generative large model, error correction can be performed according to contextual information, and various types of errors such as grammar and semantics can be handled, and the structure and meaning of the sentence can be comprehensively considered, so as to better correct errors at different levels. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] In order to more clearly illustrate the technical solution of the present application, the following is a brief introduction to the drawings required for use in the embodiments. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0036] Figure 1 A flowchart of a text error correction method provided in an embodiment of the present application;
[0037] Figure 2 A schematic diagram of an exemplary composition of a text error correction device 200 provided in an embodiment of the present application;
[0038] Figure 3 This is a schematic diagram of an exemplary structure of an electronic device 300 provided in an embodiment of the present application. DETAILED DESCRIPTION
[0039] The technical solution of the embodiment of the present application will be described below in conjunction with the drawings in the embodiment of the present application.
[0040] The terms used in the following embodiments of the present application are only for the purpose of describing specific embodiments, and are not intended to be used as limitations on the present application. As used in the specification and the appended claims of the present application, the singular expressions "one", "a kind", "said", "above", "the" and "this" are intended to also include plural expressions, unless there is a clear contrary indication in the context. It should also be understood that although the terms first, second, etc. may be used to describe a certain class of objects in the following embodiments, the objects should not be limited to these terms. These terms are only used to distinguish specific objects of this class of objects. For example, the terms first, second, etc. may be used to describe low-rank matrices in the following embodiments, but low-rank matrices should not be limited to these terms. These terms are only used to distinguish different low-rank matrices. The same is true for other classes of objects that may be described by the terms first, second, etc. in the following embodiments, which will not be repeated here.
[0041] The embodiments of the present application provide a text correction method, device and electronic device. The text correction method uses an official document text library, a proper noun library and a punctuation library as a knowledge base, and uses publicly available correction texts and common grammatical errors as model parameter adjustment data sets. A generative official document text correction model is implemented by using a low-rank adapter method (Low-Rank Adaptation, LoRA) as a local parameter adjustment method.
[0042] The text error correction method involved in the embodiments of the present application is introduced below through several implementation methods.
[0043] like Figure 1 As shown, Figure 1A text error correction method 100 (hereinafter referred to as method 100) is illustrated, and the method 100 includes the following steps:
[0044] Step S101, obtaining a pre-trained large model.
[0045] Step S102, obtaining an official document data set, wherein the official document data set includes normal text data and error text data, and the text in the error text data includes grammatical errors, semantic errors, and typos.
[0046] In this embodiment, the erroneous text data in the official document data set includes some common simple errors such as typos and word order errors, as well as more complex errors such as grammatical errors and semantic errors. At the same time, each erroneous official document text has a corresponding correct official document text as a comparison.
[0047] Step S103, segmenting the official document data set according to punctuation marks to obtain a segmented official document data set.
[0048] In this embodiment, the document data set is preprocessed so that the processed text meets the input format requirements of the model. Specifically, the document text can be segmented according to paragraphs, or segmented according to length, or segmented according to punctuation marks, etc. This application does not limit this.
[0049] Step S104, using the segmented official document dataset to fine-tune the pre-trained large model based on the low-rank adapter method LoRA to obtain a text error correction model.
[0050] In this embodiment, fine-tuning through the low-rank adapter method can enable the pre-trained large model to quickly complete a large amount of text training with minimal hardware requirements, thereby realizing a generative text correction service.
[0051] Step S105, inputting the text to be corrected into the text correction model to obtain the corrected text.
[0052] Step S106, comparing the corrected text with the text to be corrected to obtain the correction position and the erroneous text.
[0053] Step S107, correcting the error-corrected text and outputting a target text.
[0054] In this embodiment, the user can upload the text to be corrected through the front end, or directly enter the text to be corrected in the text box. After receiving the text to be corrected, the text correction model will perform correction processing, and then correct the proper nouns and punctuation marks of the corrected text to ensure that the format specification and content of the target text outputted by the red are accurate. In addition, the error text can be obtained based on the comparison result between the corrected text and the text to be corrected, and then training can be performed based on the error text to optimize the text correction model.
[0055] In an optional implementation, the method further includes:
[0056] Adding a first low-rank matrix and a second low-rank matrix to the pre-trained large model;
[0057] Use the segmented text data to train the first low-rank matrix and the second low-rank matrix;
[0058] The first low-rank matrix and the second low-rank matrix are fine-tuned and the parameters are updated.
[0059] In this embodiment, the low-rank adapter method introduces adapter parameters into the pre-trained large model to perform local parameter adjustment without destroying the overall structure of the model. Specifically, the first low-rank matrix and the second low-rank matrix are added to the weight matrix of the pre-trained large model, and the segmented official document text data is used for training, and only the first low-rank matrix and the second low-rank matrix are updated to keep the weight of the pre-trained model fixed. This allows the pre-trained large model to effectively learn new content in the field of official documents. In an optional implementation, it also includes:
[0060] The first low-rank matrix is Gaussian initialized.
[0061] In an optional implementation, the method further includes:
[0062] The second low-rank matrix is initialized to zero.
[0063] In this embodiment, the first low-rank matrix is called low-rank matrix A, and the second low-rank matrix is called low-rank matrix B, where: , , usually r is selected to be much smaller than d. At this time, the amount of fine-tuning parameters is reduced from the original d*d to 2*r*d. It can be seen that the low-rank adapter method reduces memory requirements by reducing the number of parameters to be updated, accelerates the pre-trained large model to adapt to new tasks, and accelerates the training and fine-tuning of large models for text generation capabilities by simplifying computing requirements, thereby reducing hardware configuration requirements.
[0064] In an optional implementation, the method further includes:
[0065] Correct proper nouns and punctuation marks in the corrected text.
[0066] In an optional implementation, the method further includes:
[0067] Processing the normal text data to obtain a proper noun library and a punctuation mark library;
[0068] The corrected text is matched according to the proper noun library and the punctuation mark library to ensure the standardization of the output text.
[0069] In this embodiment, after obtaining the official document data set, proper nouns and specific structures in the official document field are extracted from it to form a proper noun library and a punctuation library. By calculating the cosine similarity, the proper nouns and punctuation in the corrected text are identified to prevent the text correction model from making irregular modifications to these specific elements.
[0070] In an optional implementation, the method further includes:
[0071] The pre-trained large model adopts a generative model.
[0072] In this embodiment, the generative model can capture contextual information and understand the overall text structure, not just individual words or phrases. This helps to better understand the context in the text, so that error correction can be performed based on a wider language context. In addition, the generative model can handle not only spelling errors, but also grammatical errors, semantic errors and other types of errors.
[0073] In summary, the text error correction method of the embodiment of the present application can effectively solve text errors that appear in the context by adopting a generative large model, and has a strong generalization ability. In addition, the present application can also correct the complex grammatical structure and professional terminology of special texts such as official documents, ensuring that the coherence of the entire document is maintained when generating the error correction text, and the corrected text is natural and fluent.
[0074] correspond Figure 1 The method described above, and an embodiment of the present application also provides a device for executing the above method.
[0075] like Figure 2 As shown, Figure 2 A text error correction device 200 is shown, the device comprising:
[0076] The acquisition module 201 is used to acquire a pre-trained large model; acquire an official document data set, wherein the official document data set includes normal text data and error text data, and the text in the error text data includes grammatical errors, semantic errors, and typos;
[0077] The processing module 202 is used to segment the official document data set according to punctuation marks to obtain a segmented official document data set; use the segmented official document data set to fine-tune the pre-trained large model based on the low-rank adapter method LoRA to obtain a text correction model; input the text to be corrected into the text correction model to obtain a corrected text; compare the corrected text with the text to be corrected to obtain a correction position and an erroneous text; correct the corrected text and output a target text.
[0078] It can be understood that the division of the above modules / units is only a division of logical functions. In actual implementation, the functions of the above modules can be integrated into the hardware entity implementation. For example, the function of the processing module can be integrated into the processor implementation, and the function of the acquisition module can be integrated into the transceiver implementation. The programs and instructions for implementing the functions of the above modules can be maintained in the memory. For example, Figure B provides an electronic device 300, which may include a processor 301, a transceiver 302 and a memory 303. Among them, the transceiver 302 is used to execute the transmission and reception of various data and signals in the method 100. The memory 303 can be used to store the programs / codes required for the processor 301 to execute the method 100, etc.
[0079] In a specific implementation, corresponding to the aforementioned electronic device 300, the embodiment of the present application further provides a computer storage medium, wherein the computer storage medium provided in the electronic device 300 may store a program, and when the program is executed, some or all of the steps in each embodiment including method 100 to method 300 may be implemented. The storage medium may be a magnetic disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM), etc.
[0080] Those skilled in the art will appreciate that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above may refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0081] In the several embodiments provided in the present application, it should be understood that the disclosed methods, devices and systems can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0082] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, and may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0083] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0084] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions to enable a computer device (which can be a personal computer, a cloud game control device, or a network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk, etc., and other media that can store program codes.
[0085] Although the optional embodiments of the present application have been described, those skilled in the art, once informed of the basic creative concept, may make additional changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including the preferred embodiment and all changes and modifications falling within the scope of the present application.
[0086] The specific implementation methods described above further illustrate the purpose, technical solutions and beneficial effects of the present application in detail. It should be understood that the above description is only the specific implementation method of the present application and is not intended to limit the scope of protection of the present application. Any modifications, equivalent substitutions, improvements, etc. made on the basis of the technical solutions of the present application should be included in the scope of protection of the present invention.
Claims
1. A text error correction method, It is characterized in that The method comprises: Obtain a pre-trained large model, wherein the pre-trained large model adopts a generative model; Acquire an official document data set, wherein the official document data set includes normal text data and error text data, wherein the text in the error text data includes grammatical errors, semantic errors, and typos; Segmenting the official document data set according to punctuation marks to obtain a segmented official document data set; Using the segmented official document dataset, the pre-trained large model is fine-tuned based on the low-rank adapter method LoRA to obtain a text error correction model; Adding a first low-rank matrix and a second low-rank matrix to the pre-trained large model; Use the segmented text data to train the first low-rank matrix and the second low-rank matrix; Fine-tune the first low-rank matrix and the second low-rank matrix to update parameters; Performing Gaussian initialization on the first low-rank matrix; Initializing the second low-rank matrix to zero; Inputting the text to be corrected into the text correction model to obtain the corrected text; Compare the corrected text with the text to be corrected to obtain the correction position and the erroneous text; Correcting the error-corrected text and outputting a target text includes: Correct the proper nouns and punctuation marks in the corrected text by calculating the cosine similarity; Specifically, the normal text data is processed to obtain a proper noun library and a punctuation mark library; the corrected text is matched according to the proper noun library and the punctuation mark library to ensure the standardization of the output text; It further includes: obtaining the erroneous text according to the comparison result between the corrected text and the text to be corrected, and then training based on the erroneous text to optimize the text correction model.
2. A text error correction device, It is characterized in that The device is used to implement the text error correction method according to claim 1, and the device comprises: An acquisition module is used to acquire a pre-trained large model, wherein the pre-trained large model adopts a generative model; acquire an official document data set, wherein the official document data set includes normal text data and error text data, wherein the text in the error text data includes grammatical errors, semantic errors, and typos; The processing module is used to segment the official document data set according to punctuation marks to obtain a segmented official document data set; use the segmented official document data set to fine-tune the pre-trained large model based on the low-rank adapter method LoRA to obtain a text correction model; input the text to be corrected into the text correction model to obtain a corrected text; compare the corrected text with the text to be corrected to obtain a correction position and an erroneous text; correct the corrected text and output a target text, including: correcting proper nouns and punctuation marks in the corrected text by calculating cosine similarity.
3. An electronic device, It is characterized in that The electronic device comprises a memory and one or more processors; wherein, The memory is used to store computer program codes, wherein the computer program codes include computer instructions; when the computer instructions are executed by the processor, the electronic device executes the method as claimed in claim 1.
4. A computer-readable storage medium, It is characterized in that The invention comprises a computer program which, when being run on a computer, causes the computer to execute the method as claimed in claim 1.
