Method and device for detecting text typos
Through the combination of word segmentation model and minimum editing distance algorithm, the problem of low accuracy of text typo detection is solved, and automatic error correction and efficient text editing are achieved.
Patent Information
- Application Number
- CN202111627033.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-28
- Publication Date
- 2025-08-26
- Estimated Expiration
- 2041-12-28
AI Technical Summary
The accuracy of text typo detection methods in the prior art is low, resulting in the detection results that do not match the actual situation.
The word segmentation model and the minimum editing distance algorithm are used to output word items through the word segmentation model and search and match words in the text library. The distance matrix is constructed using the minimum editing distance algorithm to calculate the operation cost and correct typos.
It improves the accuracy of text typo detection, realizes automatic error correction, simplifies user operations, and improves text editing efficiency.
Smart Images

Figure CN115759076B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of data processing, and in particular relates to a method and device for detecting typos in text. Background Art
[0002] During text generation, typos may occur due to input errors. A typo is an incorrect character used in a specific context or vocabulary. A typo has a corresponding correct character. To obtain accurate information from text, ensuring its accuracy is crucial. Typos can affect the structure of the text and the information it represents. Therefore, before processing, typos must be detected and corrected.
[0003] In the prior art, the main method for detecting typos in text is as follows: after receiving text input by a user, the text input by the user is processed in a certain manner, and then the probability of the processed text is calculated and compared with a preset probability threshold. Finally, based on the comparison result, it is determined whether the text input by the user is a typo. When the calculated probability of the text is less than the preset probability threshold, the text input by the user is determined to be a typo. When the calculated probability of the text is not less than the preset probability threshold, the text input by the user is determined to be a correct word. However, the typo detection results obtained by the above method may not match the actual situation, and the detection accuracy is low. Summary of the Invention
[0004] The purpose of the present invention is to provide a method and device for detecting typos in text, so as to solve at least one technical problem in the prior art.
[0005] In order to achieve the above object, the present invention adopts the following technical solutions:
[0006] In a first aspect, the present invention provides a method for detecting typos in text, comprising:
[0007] Reading a target text, inputting the target text into a pre-trained word segmentation model, and outputting a word segmentation result, wherein the word segmentation result includes a plurality of words;
[0008] Perform word search and matching on each word in the text library to detect whether the current word is a wrong word;
[0009] If so, multiple distance matrices between the incorrect term and multiple target terms are constructed based on the minimum edit distance algorithm model, the operation cost between each target term and the incorrect term is calculated according to each distance matrix, and the incorrect term is corrected according to the operation cost.
[0010] In one possible design, the training process of the word segmentation model includes:
[0011] Using a sufficient amount of sample data to construct a text library, and establishing a term vector table for the text library, wherein the term vector table includes term indexes and term vectors in the text library, and the term indexes and the term vectors correspond one to one;
[0012] Setting hyperparameters based on the LSTM model and the CRF model to build a word segmentation model, and inputting training data to train the word segmentation model, wherein the training data is provided with a term index and a first term label index;
[0013] Obtaining a corresponding term vector from the term vector table according to the term index of the training data, and generating a second term label index according to the obtained term vector;
[0014] The second term label index is compared with the first term label index, and parameters of the word segmentation model are optimized according to the comparison result until the word segmentation model training is completed.
[0015] In one possible design, after outputting the word segmentation result, the method further includes:
[0016] Search for a specific word in the word segmentation result, regroup or further split the specific word to obtain a new word segmentation result.
[0017] In one possible design, after outputting the word segmentation result, the method further includes:
[0018] The word segmentation result is subjected to sentence splitting according to punctuation marks in the target text.
[0019] In one possible design, each word is searched and matched in the text library to detect whether the current word is a wrong word, including:
[0020] Each term is grouped with its forward term and backward term respectively, to generate a first forward phrase group and a first backward phrase group respectively;
[0021] A search is performed in a text library to determine whether there is a phrase matching the first forward phrase and the first backward phrase. If both the first forward phrase and the first backward phrase exist in the text library, the current term is a non-misspelled term. If either the first forward phrase or the first backward phrase exists in the text library, the current term is a suspected misspelled term. If neither the first forward phrase nor the first backward phrase exists in the text library, the current term is a misspelled term.
[0022] In one possible design, if the current term is a suspected erroneous term, the method further includes:
[0023] Returns a prompt message to the user front end indicating that the current word is a suspected typo, prompting the user to confirm the input of the current word.
[0024] In one possible design, multiple distance matrices between the incorrect term and multiple target terms are constructed based on a minimum edit distance algorithm model, an operation cost between each target term and the incorrect term is calculated based on each distance matrix, and the incorrect term is corrected based on the operation cost, including:
[0025] Based on the minimum edit distance algorithm, distance matrices between the misspelled terms and multiple target terms are constructed. The calculation formula of the distance matrix is as follows:
[0026]
[0027] Among them, Mat[i,j] represents the distance matrix of the i-th row and j-th column, Mat[i-1,j] represents the distance matrix of the i-1-th row and j-th column, D_cost represents the cost of deletion operation, Mat[i,j-1] represents the distance matrix of the i-th row and j-1-th column, I_cost represents the cost of insertion operation, Mat[i-1,j-1] represents the distance matrix of the i-1-th row and j-1-th column, r_cost represents the cost of replacement operation, T[i] represents the character data of the incorrect word in the i-th row, and t[j] represents the character data of a target word in the j-th column;
[0028] In order of operation cost from low to high, each target term is grouped with the forward term and the backward term of the incorrect term to obtain a second forward phrase group and a second backward phrase group, until a second forward phrase group and a corresponding second backward phrase group exist simultaneously in the text library, and the correct term of the incorrect term is obtained.
[0029] In a second aspect, the present invention provides a device for detecting typos in text, comprising:
[0030] A word segmentation module is used to read a target text, input the target text into a pre-trained word segmentation model, and output a word segmentation result, wherein the word segmentation result includes multiple words;
[0031] The typo detection module is used to search and match each word in the text library to detect whether the current word is a typo;
[0032] The wrong word correction module, if so, constructs multiple distance matrices between the wrong word and multiple target words based on the minimum edit distance algorithm model, calculates the operation cost between each target word and the wrong word according to each distance matrix, and corrects the wrong word according to the operation cost.
[0033] In one possible design, the word segmentation model includes:
[0034] a text library construction unit, configured to construct a text library using a sufficient amount of sample data and establish a term vector table for the text library, wherein the term vector table includes term indices and term vectors within the text library, and the term indices and the term vectors correspond one to one;
[0035] A model training unit, configured to set hyperparameters based on the LSTM model and the CRF model to construct a word segmentation model, and input training data to train the word segmentation model, wherein the training data includes a term index and a first term label index;
[0036] a label index generating unit, configured to obtain a corresponding term vector from the term vector table according to the term index of the training data, and generate a second term label index according to the obtained term vector;
[0037] A model parameter optimization unit is used to compare the second term label index with the first term label index, and optimize the parameters of the word segmentation model according to the comparison result until the word segmentation model training is completed.
[0038] In one possible design, the device further includes:
[0039] The word segmentation result updating module is used to search for a specific word in the word segmentation result, and to regroup or further split the specific word to obtain a new word segmentation result.
[0040] In one possible design, the device further includes:
[0041] The sentence splitting module is used to perform sentence splitting on the word segmentation result according to punctuation marks in the target text.
[0042] In one possible design, the typo detection module includes:
[0043] A first phrase generating unit is configured to group each term with its forward term and backward term, and generate a first forward phrase and a first backward phrase respectively;
[0044] The term judgment unit is used to search in a text library whether there is a phrase that matches the first forward phrase and the first backward phrase. If the first forward phrase and the first backward phrase both exist in the text library, the current term is a non-misspelled term. If the first forward phrase or the first backward phrase exists in the text library, the current term is a suspected misspelled term. If neither the first forward phrase nor the first backward phrase exists in the text library, the current term is a misspelled term.
[0045] In one possible design, if the current term is a suspected erroneous term, the apparatus further includes:
[0046] The prompt information return module is used to return prompt information to the user front end that the current word is a suspected typo, so as to prompt the user to confirm the input of the current word.
[0047] In one possible design, the error word correction module includes:
[0048] The distance matrix calculation unit is used to construct distance matrices between the misspelled terms and multiple target terms based on the minimum edit distance algorithm. The calculation formula of the distance matrix is as follows:
[0049]
[0050] Among them, Mat[i,j] represents the distance matrix of the i-th row and j-th column, Mat[i-1,j] represents the distance matrix of the i-1-th row and j-th column, D_cost represents the cost of deletion operation, Mat[i,j-1] represents the distance matrix of the i-th row and j-1-th column, I_cost represents the cost of insertion operation, Mat[i-1,j-1] represents the distance matrix of the i-1-th row and j-1-th column, r_cost represents the cost of replacement operation, T[i] represents the character data of the incorrect word in the i-th row, and t[j] represents the character data of a target word in the j-th column;
[0051] The error correction unit is used to group each target term with the forward term and the backward term of the incorrect term in order of operation cost from low to high, to obtain a second forward phrase group and a second backward phrase group, until a second forward phrase group and a corresponding second backward phrase group exist simultaneously in the text library, thereby obtaining a correct term group of the incorrect term.
[0052] In a third aspect, the present invention provides a computer device comprising a memory, a processor and a transceiver communicatively connected in sequence, wherein the memory is used to store a computer program, the transceiver is used to send and receive messages, and the processor is used to read the computer program and execute the text typo detection method as described in any possible design of the first aspect.
[0053] In a fourth aspect, the present invention provides a computer-readable storage medium having instructions stored thereon. When the instructions are run on a computer, the method for detecting typos in text as described in any possible design of the first aspect is executed.
[0054] In a fifth aspect, the present invention provides a computer program product comprising instructions, which, when executed on a computer, causes the computer to execute the text typo detection method as described in any possible design of the first aspect.
[0055] Beneficial effects:
[0056] The present invention inputs the target text into a pre-trained word segmentation model and outputs a word segmentation result, which includes multiple terms; then each term is searched and matched in the text library to detect whether the current term is a wrong term; if so, multiple distance matrices between the wrong term and multiple target terms are constructed based on the minimum edit distance algorithm model, the operation cost between each target term and the wrong term is calculated according to each distance matrix, and the wrong term is corrected according to the operation cost. The present invention can automatically detect typos in the target text, such as spelling errors or grammatical errors, and automatically correct the wrong term after detecting the wrong term. The whole process is simple to operate, and the user does not need to manually detect errors in the target text, thereby improving text editing efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0057] Figure 1 Flowchart of the method for detecting typos in text in this embodiment. DETAILED DESCRIPTION
[0058] To make the objectives, technical solutions, and advantages of the embodiments of this specification more clear, the technical solutions in the embodiments of this specification will be clearly and completely described below in conjunction with the drawings in the embodiments of this specification. Obviously, the embodiments described are part of the embodiments of this specification, not all of the embodiments. Based on the embodiments in this specification, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this invention.
[0059] Example
[0060] like Figure 1 As shown, in the first aspect, this embodiment provides a method for detecting typos in text, including but not limited to steps S101 to S103:
[0061] Step S101: Read the target text, input the target text into a pre-trained word segmentation model, and output a word segmentation result, which includes multiple words;
[0062] In a specific implementation of step S101, the training process of the word segmentation model includes:
[0063] Step a. constructing a text library using a sufficient amount of sample data and establishing a term vector table for the text library, wherein the term vector table includes term indexes and term vectors in the text library, and the term indexes and the term vectors correspond one to one;
[0064] It should be noted that after obtaining a sufficient amount of labeled sample data, the labeled sample data is sorted and a text library is generated. Each term vector in the text library has a corresponding term index, which can be an Arabic numeral or an English letter number, etc., which is not limited here.
[0065] Step b. Setting hyperparameters based on the LSTM model and the CRF model to construct a word segmentation model, inputting training data to train the word segmentation model, wherein the training data is provided with a term index and a first term label index;
[0066] It should be noted that the LSTM model refers to a Long Short-Term Memory (LSTM) network model, which can integrate the contextual information of each term and obtain a term vector containing the contextual information for each term. The CRF model refers to a Conditional Random Field (CRF) model, which is used to label and analyze vectors.
[0067] Step c. obtaining a corresponding term vector from the term vector table according to the term index of the training data, and generating a second term label index according to the obtained term vector;
[0068] It should be noted that after the training data is input into the word segmentation model, the corresponding term vector in the term vector table can be obtained according to the term index of the training data, and a second label index can be generated according to the obtained term vector. The second label index is the word segmentation label automatically obtained using the CRF model.
[0069] Step d. Compare the second term tag index with the first term tag index, and optimize the parameters of the word segmentation model according to the comparison result until the word segmentation model training is completed.
[0070] Based on the above disclosed content, since a word segmentation model is constructed using an LSTM model that considers contextual information and a CRF model that can automatically label and analyze term vectors, the word segmentation model can obtain word segmentation results with higher accuracy.
[0071] In a specific implementation manner of step S101, after outputting the word segmentation result, the method further includes:
[0072] Search for specific terms in the word segmentation result, re-group or further split the specific terms to obtain a new word segmentation result.
[0073] Among them, it should be noted that the specific terms may be personal names that are difficult for the word segmentation model to recognize. For single-word terms that may be personal names, they can be re-grouped. For example, for "Zhang San", when outputting the word segmentation result, it may still be "Zhang San", then it can be re-grouped into "Zhang" and "San" respectively; the specific terms may also be phrases with more than four characters. If this phrase is composed of several non-single-word phrases, it can be further split. For example, for the four-character phrase "sunny and bright", it can be further split into "sunshine" and "bright".
[0074] In a specific implementation manner of step S101, after outputting the word segmentation result, the method further includes:
[0075] According to the punctuation marks in the target text, split the word segmentation result into sentences, and the target text is split into multiple sentences, and each sentence includes multiple terms.
[0076] Step S102. Search for and match each term in the text library for word grouping to detect whether the current term is a misspelled term;
[0077] In a specific implementation manner of step S102, searching for and matching each term in the text library for word grouping to detect whether the current term is a misspelled term includes:
[0078] Step S1021. Group each term with its forward term and backward term respectively to generate a first forward phrase and a first backward phrase;
[0079] Among them, it should be noted that in a sentence, the forward term refers to the term at least one position before the current term, and the backward term refers to the term at least one position after the current term; among them, it should be noted that when forming phrases forward or backward, if consecutive single characters are encountered, continue to form phrases forward and then backward until a pause word is encountered. Among them, the pause word can be a particle such as "de". For example, if the word segmentation result of a sentence is "There is an enterprise in Zhumadian, Henan", group the current term "ma" forward and backward, then the forward phrase is "Henan Zhuma", and the backward phrase is "Madian".
[0080] Step S1022. Search in the text library to find if there is a phrase that matches the first forward phrase and the first backward phrase. If both the first forward phrase and the first backward phrase exist in the text library, the current word item is a non-incorrect word item. If either the first forward phrase or the first backward phrase exists in the text library, the current word item is a suspected incorrect word item. If neither the first forward phrase nor the first backward phrase exists in the text library, the current word item is an incorrect word item.
[0081] For example, if neither the above forward phrase "河南驻吗" nor the backward phrase "吗店" exists in the text library, the current word item "吗" is an incorrect word item.
[0082] In a specific implementation, if the current word item is a suspected incorrect word item, the method further includes:
[0083] Return a prompt message to the user front-end indicating that the current word item is a suspected incorrect word item, so as to prompt the user to confirm the input of the current word item, thereby avoiding misjudgment of the current word item by the system and improving the accuracy of misspelled word detection.
[0084] Step S103. If so, respectively construct multiple distance matrices between the incorrect word item and multiple target word items based on the minimum edit distance algorithm model, calculate the operation cost between each target word item and the incorrect word item according to each distance matrix, and correct the incorrect word item according to the operation cost.
[0085] It should be noted that the target word items refer to multiple target word items whose character sequences are the same as or similar to the incorrect word item. For example, the character sequence of "吗" is "ma", and the target word items with the same character sequence can be "码", "马", "嘛", etc.; the character sequences similar to it can be "mao", "me", etc. <管理类
[0086] It should be noted that the operation cost refers to the operation cost that the user needs to perform on the device during the process of converting the incorrect word item into a certain target word item when performing text input operations. For example, when converting "吗" to "码", the user does not need to re-enter the character sequence, but needs to select the character "码". For example, if the incorrect word item is "么" and the target word item is "码", the operation cost that the user needs from "么" to "码" is to delete the letter "e", edit the letter "a", and select the target word item "码". This embodiment can define the operation cost for the cases of same-sequence replacement, sequence insertion, sequence deletion, different-sequence replacement, etc.
[0087] In a specific implementation manner of step S103, multiple distance matrices are respectively constructed between the misspelled term and multiple target terms based on the minimum edit distance algorithm model. The operation cost between each target term and the misspelled term is calculated according to each distance matrix, and the misspelled term is corrected according to the operation cost, including:
[0088] Step S1031. Distance matrices are respectively constructed between the misspelled term and multiple target terms based on the minimum edit distance algorithm. The calculation formula of the distance matrix is as follows:
[0089]
[0090] Where Mat[i,j] represents the distance matrix of the i-th row and j-th column, Mat[i-1,j] represents the distance matrix of the (i-1)-th row and j-th column, D_cost represents the deletion operation cost, Mat[i,j-1] represents the distance matrix of the i-th row and (j-1)-th column, I_cost represents the insertion operation cost, Mat[i-1,j-1] represents the distance matrix of the (i-1)-th row and (j-1)-th column, r_cost represents the replacement operation cost, T[i] represents the character data of the misspelled term in the i-th row, and t[j] represents the character data of a certain target term in the j-th column;
[0091] It should be noted that in this embodiment, by obtaining the distance matrix between the target term and the misspelled term, the operation cost between the misspelled term and the target term can be obtained. For example: the operation cost from the character '吗' to the character '码' belongs to the replacement of the same sequence, and the operation cost is defined as 1. The operation cost from the character '毛' to the character '码' is the replacement of the input sequence deletion, and the operation cost is 2. The operation cost from the character '么' to the character '码' belongs to the replacement of different sequences, and the operation cost is defined as 3. Among them, the operation cost of different sequence replacements can be defined respectively according to the number of different characters.
[0092] Step S1032. In the order of increasing operation cost, each target term is respectively combined with the forward term and backward term of the misspelled term to obtain the second forward phrase and the second backward phrase. When a certain second forward phrase and the corresponding second backward phrase exist simultaneously in the text library, the correct term of the misspelled term is obtained.
[0093] It should be noted that when the operation costs of multiple target terms are the same, there is no need to sort, and each target term is respectively combined with the forward term and backward term of the misspelled term; when there are multiple target terms '码', '毛' and '么', and the operation cost of '码' is 1, the operation cost of '毛' is '2', and the operation cost of '么' is 3, then the forward and backward combinations are performed using '码', '毛' and '么' in sequence.
[0094] Based on the above disclosed content, the present invention inputs the target text into a pre-trained word segmentation model and outputs a word segmentation result, wherein the word segmentation result includes multiple terms; each term is then searched and matched in the text library to detect whether the current term is a wrong term; if so, multiple distance matrices between the wrong term and multiple target terms are constructed based on the minimum edit distance algorithm model, the operation cost between each target term and the wrong term is calculated according to each distance matrix, and the wrong term is corrected according to the operation cost. The present invention can automatically detect typos in the target text, such as spelling errors or grammatical errors, and automatically correct the wrong term after detecting the wrong term. The whole process is simple to operate, and the user does not need to manually detect errors in the target text, thereby improving text editing efficiency.
[0095] In a second aspect, the present invention provides a device for detecting typos in text, comprising:
[0096] A word segmentation module is used to read a target text, input the target text into a pre-trained word segmentation model, and output a word segmentation result, wherein the word segmentation result includes multiple words;
[0097] The typo detection module is used to search and match each word in the text library to detect whether the current word is a typo;
[0098] The wrong word correction module, if so, constructs multiple distance matrices between the wrong word and multiple target words based on the minimum edit distance algorithm model, calculates the operation cost between each target word and the wrong word according to each distance matrix, and corrects the wrong word according to the operation cost.
[0099] In one possible design, the word segmentation model includes:
[0100] a text library construction unit, configured to construct a text library using a sufficient amount of sample data and establish a term vector table for the text library, wherein the term vector table includes term indices and term vectors within the text library, and the term indices and the term vectors correspond one to one;
[0101] A model training unit, configured to set hyperparameters based on the LSTM model and the CRF model to construct a word segmentation model, and input training data to train the word segmentation model, wherein the training data includes a term index and a first term label index;
[0102] a label index generating unit, configured to obtain a corresponding term vector from the term vector table according to the term index of the training data, and generate a second term label index according to the obtained term vector;
[0103] A model parameter optimization unit is used to compare the second term label index with the first term label index, and optimize the parameters of the word segmentation model according to the comparison result until the word segmentation model training is completed.
[0104] In one possible design, the device further includes:
[0105] The word segmentation result updating module is used to search for a specific word in the word segmentation result, and to regroup or further split the specific word to obtain a new word segmentation result.
[0106] In one possible design, the device further includes:
[0107] The sentence splitting module is used to perform sentence splitting on the word segmentation result according to punctuation marks in the target text.
[0108] In one possible design, the typo detection module includes:
[0109] A first phrase generating unit is configured to group each term with its forward term and backward term, and generate a first forward phrase and a first backward phrase respectively;
[0110] The term judgment unit is used to search in a text library whether there is a phrase that matches the first forward phrase and the first backward phrase. If the first forward phrase and the first backward phrase both exist in the text library, the current term is a non-misspelled term. If the first forward phrase or the first backward phrase exists in the text library, the current term is a suspected misspelled term. If neither the first forward phrase nor the first backward phrase exists in the text library, the current term is a misspelled term.
[0111] In one possible design, if the current term is a suspected erroneous term, the apparatus further includes:
[0112] The prompt information return module is used to return prompt information to the user front end that the current word is a suspected typo, so as to prompt the user to confirm the input of the current word.
[0113] In one possible design, the device further includes:
[0114] The target term search module is used to obtain the incorrect term and search for multiple target terms similar to the incorrect term in the text library.
[0115] In one possible design, the error word correction module includes:
[0116] The distance matrix calculation unit is used to construct distance matrices between the misspelled terms and multiple target terms based on the minimum edit distance algorithm. The calculation formula of the distance matrix is as follows:
[0117]
[0118] Where, Mat[i-1,j] represents the distance matrix of the i-1th row and j-th column, D_cost represents the cost of deletion operation, Mat[i,j-1] represents the distance matrix of the i-th row and j-1th column, I_cost represents the cost of insertion operation, Mat[i-1,j-1] represents the distance matrix of the i-1th row and j-1th column, r_cost represents the cost of replacement operation, T[i] represents the character data of the incorrect word in the i-th row, and t[j] represents the character data of a target word in the j-th column;
[0119] The error correction unit is used to group each target term with the forward term and the backward term of the incorrect term in order of operation cost from low to high, to obtain a second forward phrase group and a second backward phrase group, until a second forward phrase group and a corresponding second backward phrase group exist simultaneously in the text library, thereby obtaining a correct term group of the incorrect term.
[0120] In a third aspect, the present invention provides a computer device comprising a memory, a processor and a transceiver communicatively connected in sequence, wherein the memory is used to store a computer program, the transceiver is used to send and receive messages, and the processor is used to read the computer program and execute the text typo detection method as described in any possible design of the first aspect.
[0121] In a fourth aspect, the present invention provides a computer-readable storage medium having instructions stored thereon. When the instructions are run on a computer, the method for detecting typos in text as described in any possible design of the first aspect is executed.
[0122] In a fifth aspect, the present invention provides a computer program product comprising instructions, which, when executed on a computer, causes the computer to execute the text typo detection method as described in any possible design of the first aspect.
[0123] Finally, it should be noted that the above description is only a preferred embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention shall be included in the scope of protection of the present invention.
Claims
1. A method for detecting typos in text, characterized in that: include: Reading a target text, inputting the target text into a pre-trained word segmentation model, and outputting a word segmentation result, wherein the word segmentation result includes a plurality of words; Perform a word search and match on each word in the text library to detect whether the current word is a wrong word, including: Each term is grouped with its forward term and backward term respectively, to generate a first forward phrase group and a first backward phrase group respectively; Searching a text library to see whether there is a phrase matching the first forward phrase and the first backward phrase; if both the first forward phrase and the first backward phrase exist in the text library, the current term is a non-misspelled term; if either the first forward phrase or the first backward phrase exists in the text library, the current term is a suspected misspelled term; and if neither the first forward phrase nor the first backward phrase exists in the text library, the current term is a misspelled term. If yes, constructing multiple distance matrices between the incorrect term and multiple target terms based on a minimum edit distance algorithm model, calculating an operation cost between each target term and the incorrect term according to each distance matrix, and correcting the incorrect term according to the operation cost, including: Based on the minimum edit distance algorithm, distance matrices between the misspelled terms and multiple target terms are constructed. The calculation formula of the distance matrix is as follows: in, represents the distance matrix of row i and column j, represents the distance matrix of row i-1 and column j, represents the cost of the delete operation, represents the distance matrix of row i and column j-1, represents the cost of the insert operation, represents the distance matrix of row i-1 and column j-1, represents the cost of the replacement operation, Represents the character data of the incorrect word in row i, Represents the character data of a target term in column j; In order of operation cost from low to high, each target term is grouped with the forward term and the backward term of the incorrect term to obtain a second forward phrase group and a second backward phrase group, until a second forward phrase group and a corresponding second backward phrase group exist simultaneously in the text library, and the correct term of the incorrect term is obtained.
2. The method for detecting typos in text according to claim 1, wherein: The training process of the word segmentation model includes: Using a sufficient amount of sample data to construct a text library, and establishing a term vector table for the text library, wherein the term vector table includes term indexes and term vectors in the text library, and the term indexes and the term vectors correspond one to one; Setting hyperparameters based on the LSTM model and the CRF model to build a word segmentation model, and inputting training data to train the word segmentation model, wherein the training data is provided with a term index and a first term label index; Obtaining a corresponding term vector from the term vector table according to the term index of the training data, and generating a second term label index according to the obtained term vector; The second term label index is compared with the first term label index, and parameters of the word segmentation model are optimized according to the comparison result until the word segmentation model training is completed.
3. The method for detecting typos in text according to claim 1, wherein: After outputting the word segmentation result, the method further includes: Search for a specific word in the word segmentation result, regroup or further split the specific word to obtain a new word segmentation result, wherein the specific word is a name or a phrase of more than four characters.
4. The method for detecting typos in text according to claim 1, wherein: After outputting the word segmentation result, the method further includes: The word segmentation result is subjected to sentence splitting according to punctuation marks in the target text.
5. The method for detecting typos in text according to claim 1, wherein: If the current term is a suspected erroneous term, the method further includes: Returns a prompt message to the user front end indicating that the current word is a suspected typo, prompting the user to confirm the input of the current word.
6. A computer device, characterized in that: The method comprises a memory, a processor and a transceiver which are communicatively connected in sequence, wherein the memory is used to store a computer program, the transceiver is used to send and receive messages, and the processor is used to read the computer program and execute the method for detecting typos in text according to any one of claims 1 to 5.
Citation Information
Patent Citations
Chinese proofreading and error-correction method and system based on Chinese word segmentation
CN108717412A
Word segmentation method and device based on BiLSTM network model and CRF model, computer device and computer storage medium
CN112036183A
Text error correction method, electronic equipment and computer readable storage medium
CN113743094A