Text error correction method, device, computer equipment and storage medium
By integrating pinyin features and stroke features in text error correction methods, calculating error probability and filtering information, the problem of low accuracy of text error correction in the prior art is solved, and efficient error correction for Chinese text is achieved.
Patent Information
- Application Number
- CN202210457419.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-27
- Publication Date
- 2024-12-27
- Estimated Expiration
- 2042-04-27
AI Technical Summary
When using Chinese text error correction methods, the use of pinyin features and stroke features is insufficient, resulting in low text error correction accuracy.
By obtaining the feature vector of the target text, calculating its pinyin characteristics and stroke characteristics, performing feature fusion to calculate the probability of homophone error and stroke error, performing information filtering, and finally input the fused features into the target encoding network for error correction.
It improves the accuracy of text error correction, can effectively identify and correct homophones and similar characters in the text, and reduces resource waste.
Smart Images

Figure CN114781359B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of artificial intelligence technology, and in particular, to a text error correction method, device, computer device, and storage medium. Background Art
[0002] During the text recognition process, errors of similar-looking or homophonic characters often occur due to OCR recognition or input methods. For example, "进入" (enter) is written as "进人" (enter a person), "风景" (scenery) is written as "凡景" (ordinary scenery), "哈密瓜" (Hami melon) is written as "哈蜜瓜" (Hami melon), etc. In addition, in the speech recognition scenario, there are also problems where the speech recognition is parsed as similar-looking or homophonic characters. The text error correction task is usually used to detect and correct misspelled characters in the input text, which can greatly reduce the errors of similar-looking and homophonic characters.
[0003] With the development of computer technology, more and more researchers have conducted research on Chinese text error correction. For example, the Soft-mask Bert model, which includes a detection network and a correction network. The detection network mainly uses the GRU network to model the input sentence, and then outputs the probability that each character in the sentence is a misspelled character. Then, the correction network is used to correct the misspelled characters. The PLOME model incorporates position encoding, character encoding, pinyin features, and stroke features into the encoding of the input sentence, and then directly uses the language model of the pre-trained BERT model for correction. The Soft-mask Bert model divides the text error correction task into two modules: detection and correction. Although it can achieve certain results, it only uses the features of the input text and does not add other features. Although the PLOME model adds pinyin features and stroke features, it depends on the effect of the pre-trained Bert model, and directly adding the pinyin features and stroke features to the input character features makes it difficult to utilize the pinyin features and stroke features to the greatest extent. Eventually, it leads to the problem of low text error correction accuracy. Summary of the Invention
[0004] The purpose of the embodiments of this application is to propose a text error correction method, device, computer device, and storage medium to solve the technical problem of low text error correction accuracy.
[0005] To solve the above technical problem, the embodiments of this application provide a text error correction method, which adopts the following technical solutions:
[0006] Obtain a target text, calculate the feature vector of the target text, and calculate the pinyin feature and stroke feature of the target text;
[0007] The feature vector and the pinyin feature are merged to obtain a first target feature, a homophone error probability of the target text is calculated according to the first target feature, and information filtering is performed on the feature vector based on the homophone error probability to obtain a pinyin filter vector;
[0008] The feature vector and the stroke feature are merged to obtain a second target feature, a stroke error probability of the target text is calculated according to the second target feature, and information filtering is performed on the feature vector based on the stroke error probability to obtain a stroke filter vector;
[0009] The feature vector, the pinyin filter vector and the stroke filter vector are subjected to feature fusion to obtain a third target feature, and the third target feature is input into a target coding network to obtain an error-corrected text through encoding.
[0010] Furthermore, the step of calculating the homophone error probability of the target text according to the first target feature includes:
[0011] Acquire a pinyin feature gating network, and map the first target feature based on a first fully connected layer of the pinyin feature gating network to obtain a first mapping feature;
[0012] The first mapping feature is input into the first activation layer of the pinyin feature gating network, and the first mapping feature is calculated based on the activation function of the first activation layer to obtain the homophone error probability.
[0013] Furthermore, the step of calculating the stroke error probability of the target text according to the second target feature includes:
[0014] Acquire a stroke feature gating network, and map the second target feature based on a second fully connected layer of the stroke feature gating network to obtain a second mapping feature;
[0015] The second mapping feature is input into the second activation layer of the stroke feature gating network, and the second mapping feature is calculated based on the activation function of the second activation layer to obtain the stroke error probability.
[0016] Furthermore, the step of filtering the feature vector based on the homophone error probability to obtain a pinyin filter vector includes:
[0017] Calculate a first opposition probability parameter according to the homophone error probability, use the homophone error probability as a first weight value of the first target feature, and use the first opposition probability parameter as a second weight value of the feature vector;
[0018] The pinyin filter vector is calculated based on the first weight value, the second weight value, the first target feature and the feature vector.
[0019] Furthermore, the step of filtering the feature vector based on the stroke error probability to obtain a stroke filter vector includes:
[0020] Calculating a second opposing probability parameter according to the stroke error probability, using the stroke error probability as a third weight value of the second target feature, and using the second opposing probability parameter as a fourth weight value of the feature vector;
[0021] The stroke filter vector is calculated according to the third weight value, the fourth weight value, the second target feature and the feature vector.
[0022] Furthermore, the step of performing feature fusion on the feature vector, the pinyin filter vector and the stroke filter vector to obtain a third target feature includes:
[0023] Performing vector addition on the feature vector, the pinyin filter vector and the stroke filter vector to obtain a fusion feature;
[0024] A third fully connected layer is obtained, and mapping calculation is performed on the fusion feature based on the third fully connected layer to obtain the third target feature.
[0025] Furthermore, the step of inputting the third target feature into the target encoding network and encoding to obtain the error correction text includes:
[0026] The target encoding network includes a multi-head attention layer, a regularization layer and a forward propagation layer. The third target feature is input into the multi-head attention layer, and the error-corrected text is calculated through the regularization layer and the forward propagation layer.
[0027] In order to solve the above technical problems, the embodiment of the present application further provides a text error correction device, which adopts the following technical solution:
[0028] An acquisition module, used to acquire a target text, calculate a feature vector of the target text, and calculate a phonetic feature and a stroke feature of the target text;
[0029] A first fusion module is used to fuse the feature vector and the pinyin feature to obtain a first target feature, calculate the homophone error probability of the target text according to the first target feature, and perform information filtering on the feature vector based on the homophone error probability to obtain a pinyin filter vector;
[0030] A second fusion module is used to fuse the feature vector and the stroke feature to obtain a second target feature, calculate the stroke error probability of the target text according to the second target feature, and filter the feature vector based on the stroke error probability to obtain a stroke filter vector;
[0031] The output module is used to perform feature fusion on the feature vector, the pinyin filter vector and the stroke filter vector to obtain a third target feature, input the third target feature into a target encoding network, and encode to obtain an error-corrected text.
[0032] In order to solve the above technical problems, the embodiment of the present application further provides a computer device, which adopts the following technical solution:
[0033] Acquire a target text, calculate a feature vector of the target text, and calculate phonetic features and stroke features of the target text;
[0034] The feature vector and the pinyin feature are merged to obtain a first target feature, a homophone error probability of the target text is calculated according to the first target feature, and information filtering is performed on the feature vector based on the homophone error probability to obtain a pinyin filter vector;
[0035] The feature vector and the stroke feature are merged to obtain a second target feature, a stroke error probability of the target text is calculated according to the second target feature, and information filtering is performed on the feature vector based on the stroke error probability to obtain a stroke filter vector;
[0036] The feature vector, the pinyin filter vector and the stroke filter vector are subjected to feature fusion to obtain a third target feature, and the third target feature is input into a target coding network to obtain an error-corrected text through encoding.
[0037] In order to solve the above technical problems, the embodiment of the present application further provides a computer-readable storage medium, which adopts the following technical solution:
[0038] Acquire a target text, calculate a feature vector of the target text, and calculate phonetic features and stroke features of the target text;
[0039] The feature vector and the pinyin feature are merged to obtain a first target feature, a homophone error probability of the target text is calculated according to the first target feature, and information filtering is performed on the feature vector based on the homophone error probability to obtain a pinyin filter vector;
[0040] The feature vector and the stroke feature are merged to obtain a second target feature, a stroke error probability of the target text is calculated according to the second target feature, and information filtering is performed on the feature vector based on the stroke error probability to obtain a stroke filter vector;
[0041] The feature vector, the pinyin filter vector and the stroke filter vector are subjected to feature fusion to obtain a third target feature, and the third target feature is input into a target coding network to obtain an error-corrected text through encoding.
[0042] The text error correction method proposed in the present application realizes accurate extraction of the pinyin feature and the stroke feature by acquiring the target text, calculating the feature vector of the target text, and calculating the pinyin feature and the stroke feature of the target text; then, the feature vector and the pinyin feature are fused to obtain the first target feature, the homophonic error probability of the target text is calculated according to the first target feature, and the feature vector is filtered based on the homophonic error probability to obtain the pinyin filter vector, thereby realizing error correction of homophonic characters in the target text; then, the feature vector and the stroke feature are fused to obtain the second target feature, the stroke error probability of the target text is calculated according to the second target feature, and the feature vector is filtered based on the stroke error probability to obtain the stroke filter vector, thereby realizing error correction of characters with similar shapes in the target text; finally, the feature vector, the pinyin filter vector and the stroke filter vector are feature fused to obtain the third target feature, and the third target feature is input into the target encoding network to encode the corrected text, thereby realizing efficient error correction of the text, and being able to timely and effectively identify typos in the text, thereby improving the accuracy of text error correction and avoiding waste of resources due to text errors. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] In order to more clearly illustrate the scheme in the present application, a brief introduction is given below to the drawings required for use in the description of the embodiments of the present application. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0044] Figure 1 is an exemplary system architecture diagram to which the present application may be applied;
[0045] Figure 2 A flowchart of an embodiment of a text error correction method according to the present application;
[0046] Figure 3 is a structural schematic diagram of an embodiment of a text error correction device according to the present application;
[0047] Figure 4It is a structural diagram of an embodiment of a computer device according to the present application.
[0048] Reference numerals: text error correction device 300 , acquisition module 301 , first fusion module 302 , second fusion module 303 , and output module 304 . DETAILED DESCRIPTION
[0049] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by technicians in the technical field of the present application; the terms used in the specification of the application herein are only for the purpose of describing specific embodiments and are not intended to limit the present application; the terms "including" and "having" and any variations thereof in the specification and claims of the present application and the above-mentioned drawings are intended to cover non-exclusive inclusions. The terms "first", "second", etc. in the specification and claims of the present application or the above-mentioned drawings are used to distinguish different objects, not to describe a specific order.
[0050] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0051] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the accompanying drawings.
[0052] like Figure 1 As shown, the system architecture 100 may include terminal devices 101, 102, 103, a network 104 and a server 105. The network 104 is used to provide a medium for communication links between the terminal devices 101, 102, 103 and the server 105. The network 104 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0053] Users can use terminal devices 101, 102, 103 to interact with server 105 through network 104 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 101, 102, 103, such as web browser applications, shopping applications, search applications, instant messaging tools, email clients, social platform software, etc.
[0054] Terminal devices 101, 102, 103 can be various electronic devices with display screens and supporting web browsing, including but not limited to smart phones, tablet computers, e-book readers, MP3 players (Moving Picture Experts Group Audio Layer III), MP4 (Moving Picture Experts Group Audio Layer IV) players, laptop computers, desktop computers, etc.
[0055] The server 105 may be a server that provides various services, such as a background server that provides support for web pages displayed on the terminal devices 101 , 102 , and 103 .
[0056] It should be noted that the text correction method provided in the embodiment of the present application is generally executed by a server / terminal device, and accordingly, the text correction device is generally arranged in the server / terminal device.
[0057] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0058] Continue to refer Figure 2 , shows a flow chart of an embodiment of a text error correction method according to the present application. The text error correction method comprises the following steps:
[0059] Step S201, obtaining a target text, calculating a feature vector of the target text, and calculating a phonetic feature and a stroke feature of the target text.
[0060] In this embodiment, the input target text is obtained, and the target text is input into the pre-trained Chinese BERT model. The target text is calculated by the BERT model to obtain the feature vector corresponding to the target text. The pinyin feature is the pinyin coding feature of the target text. The pinyin text is obtained by performing pinyin conversion on the target text; then, the pinyin text is encoded to obtain the pinyin feature. Specifically, a pinyin list is obtained, and the target text can be converted into the corresponding pinyin text by referring to the pinyin list through the pinyin toolkit. When the pinyin text is obtained, the pinyin text is input into the pinyin coding network, and the pinyin text is encoded based on the pinyin coding network to obtain the pinyin feature. Among them, the pinyin coding network can select LSTM (Long Short-Term Memory, long short-term memory network), and the input pinyin text is feature-encoded by the long short-term memory network to obtain the corresponding pinyin feature.
[0061] The stroke feature is the stroke coding feature corresponding to the target text. By performing stroke conversion on the target text, the corresponding stroke feature sequence is obtained. Specifically, a Chinese character stroke list is obtained, and each stroke in the Chinese character stroke list is numbered; then, the stroke order corresponding to each Chinese character in the target text is determined according to the number, and the number combination corresponding to each Chinese character in the target text is determined according to the stroke order; according to the arrangement order of the Chinese characters in the target text, the number combination is sorted, and the stroke feature sequence corresponding to the target text is obtained. For example, the horizontal line "-" is represented by the number 1, the vertical line "|" is represented by 2, and the corresponding stroke feature list of "Today's weather is very good" is "3445 1134 1134 3115 13243111512212511". When the stroke feature sequence is obtained, the stroke feature sequence is input into the stroke coding network, and the stroke feature sequence is encoded based on the stroke coding network to obtain the stroke feature. The stroke encoding network may also be LSTM (Long Short-Term Memory), which has different parameters from the LSTM selected by the pinyin encoding network. The stroke feature sequence is encoded by the LSTM to obtain the stroke features corresponding to the target text. The vector dimensions of the stroke features and the pinyin features are the same as the vector dimensions of the feature vector.
[0062] Step S202, fusing the feature vector and the pinyin feature to obtain a first target feature, calculating the homophone error probability of the target text according to the first target feature, filtering the feature vector based on the homophone error probability, and obtaining a pinyin filter vector.
[0063] In this embodiment, when the feature vector and the pinyin feature are obtained, the feature vector and the pinyin feature are fused, wherein the fused first target feature can be obtained by vector addition of the feature vector and the pinyin feature. The homophone error probability of the target text is calculated according to the first target feature, and the homophone error probability is the probability that there are homophone errors in the characters in the target text. The homophone error probability can be obtained by calculating the first target feature obtained by the fully connected layer and the activation layer. When the homophone error probability is obtained, the feature vector is filtered based on the homophone error probability to obtain a pinyin filter vector. Among them, information filtering is a process of filtering the feature vector and the first target feature according to the calculated homophone error probability, and filtering out the correct pinyin information therein. Specifically, the homophone error probability is used as the first weight value of the first target feature, and the opposite probability parameter of the homophone error probability is used as the second weight value of the feature vector, and the product of the first weight value and the first target feature, and the product of the second weight value and the feature vector are calculated; the two products are summed to calculate the pinyin filter vector.
[0064] Step S203: fuse the feature vector and the stroke feature to obtain a second target feature, calculate the stroke error probability of the target text according to the second target feature, and filter the feature vector based on the stroke error probability to obtain a stroke filter vector.
[0065] In this embodiment, when the feature vector and the stroke feature are obtained, the feature vector and the stroke feature are fused, wherein the fused second target feature can be obtained by vector addition of the feature vector and the stroke feature. The stroke error probability of the target text is calculated according to the second target feature, and the stroke error probability is the probability that there is a similar error in the character in the target text. The second target feature is calculated by the fully connected layer and the activation layer to obtain the stroke error probability. When the stroke error probability is obtained, the feature vector is filtered based on the stroke error probability to obtain a stroke filter vector. Among them, information filtering is a process of filtering the feature vector and the second target feature according to the calculated stroke error probability, and filtering out the correct stroke information. Specifically, the stroke error probability is used as the third weight value of the second target feature, and the opposite probability parameter of the homophonic error probability is used as the fourth weight value of the feature vector. The product of the third weight value and the second target feature, and the product of the fourth weight value and the feature vector are calculated; the two products are summed to calculate the stroke filter vector.
[0066] Step S204, performing feature fusion on the feature vector, the pinyin filter vector and the stroke filter vector to obtain a third target feature, inputting the third target feature into a target encoding network, and encoding to obtain an error-corrected text.
[0067] In this embodiment, when the feature vector, the pinyin filter vector and the stroke filter vector are obtained, the feature vector, the pinyin filter vector and the stroke filter vector are subjected to feature fusion to obtain a third target feature. The third target feature is input into the target coding network, and the error correction text is obtained based on the target coding network encoding. Specifically, the target coding network can select the encoding network of the transformer model, wherein the transformer model includes an encoding network (encoder) and a decoding network (decoder); the third target feature is encoded and calculated by the encoding network of the transformer model, and the error correction text is obtained as output.
[0068] The text correction method proposed in the present application realizes efficient text correction by integrating the pinyin features and stroke features into the feature vector of the target text respectively, and then filters the characters of the target text by those with similar pronunciations and similar shapes, and finally outputs the correction text after fusion, thereby realizing efficient text correction, being able to timely and effectively identify typos in the text, improving the accuracy of text correction, and avoiding the waste of resources due to text errors.
[0069] In some optional implementations of this embodiment, the step of calculating the homophone error probability of the target text according to the first target feature includes:
[0070] Acquire a pinyin feature gating network, and map the first target feature based on a first fully connected layer of the pinyin feature gating network to obtain a first mapping feature;
[0071] The first mapping feature is input into the first activation layer of the pinyin feature gating network, and the first mapping feature is calculated based on the activation function of the first activation layer to obtain the homophone error probability.
[0072] In this embodiment, a homophone error is an error in which the pinyin corresponding to the two characters is the same but the glyphs are different. In order to determine whether there are homophone errors in the characters in the target text, when the first target feature of the fusion of the feature vector and the pinyin feature is obtained, a pinyin feature gating network is obtained, wherein the pinyin feature gating network is a network composed of gate control units, including a first fully connected layer and a first activation layer. Based on the first fully connected layer of the pinyin feature gating network, the first target feature is mapped and calculated to obtain a first mapping feature; then, the first mapping feature is input into the first activation layer of the pinyin feature gating network for calculation to obtain the probability of homophone errors. The calculation formula for the probability of homophone errors is as follows:
[0073] p1=σ(W1(X_vec+py_vec)+b1)
[0074] Among them, X_vec is the feature vector, py_vec is the pinyin feature, X_vec+py_vec is used to calculate the first target feature, W1 and b1 are the training parameter matrix and bias term of the first fully connected layer, W1(X_vec+py_vec)+b1 is used to calculate the first mapping feature, and σ is the activation function of the first activation layer.
[0075] This embodiment performs mapping calculation and activation calculation on the first target feature through the pinyin feature gating network to obtain the homophone error probability, so that the probability of homophone errors occurring in each word can be accurately represented through the homophone error probability, further realizing the correction of homophone errors in the target text, and improving the efficiency and accuracy of text error correction.
[0076] In some optional implementations of this embodiment, the step of calculating the stroke error probability of the target text according to the second target feature includes:
[0077] Acquire a stroke feature gating network, and map the second target feature based on a second fully connected layer of the stroke feature gating network to obtain a second mapping feature;
[0078] The second mapping feature is input into the second activation layer of the stroke feature gating network, and the second mapping feature is calculated based on the activation function of the second activation layer to obtain the stroke error probability.
[0079] In this embodiment, the stroke error is an error caused by the proximity of two glyphs. In order to determine whether there are stroke errors in the characters in the target text, when the second target feature of the fusion of the feature vector and the stroke feature is obtained, a stroke feature gating network is obtained, wherein the stroke feature gating network is a network composed of gate control units, including a second fully connected layer and a second activation layer. Based on the second fully connected layer of the stroke feature gating network, the second target feature is mapped and calculated to obtain a second mapping feature; then, the second mapping feature is input into the second activation layer of the stroke feature gating network for calculation to obtain the stroke error probability. The calculation formula for the stroke error probability is as follows:
[0080] p2=σ(W2(X_vec+st_vec)+b2)
[0081] Among them, X_vec is the feature vector, st_vec is the pinyin feature, X_vec+st_vec is calculated to obtain the second target feature, W2 and b2 are the training parameter matrix and bias term of the second fully connected layer, W2(X_vec+st_vec)+b2 is calculated to obtain the second mapping feature, and σ is the activation function of the second activation layer.
[0082] This embodiment performs mapping calculations and activation calculations on the second target feature through a stroke feature gating network to obtain a stroke error probability, so that the stroke error probability can accurately represent the probability of similar errors in each character, further realizing the correction of similar errors in the target text and improving the efficiency and accuracy of text error correction.
[0083] In some optional implementations of this embodiment, the step of filtering the feature vector based on the homophone error probability to obtain the pinyin filter vector includes:
[0084] Calculate a first opposition probability parameter according to the homophone error probability, use the homophone error probability as a first weight value of the first target feature, and use the first opposition probability parameter as a second weight value of the feature vector;
[0085] The pinyin filter vector is calculated based on the first weight value, the second weight value, the first target feature and the feature vector.
[0086] In this embodiment, when the homophone error probability is obtained, a first opposing probability parameter is calculated according to the homophone error probability, wherein the first opposing probability parameter is the probability of the opposing event of the homophone error probability, and the first opposing probability parameter is obtained by subtracting the homophone error probability from 1. When the first opposing probability parameter is obtained, the homophone error probability is used as the first weight value of the first target feature, and the first opposing probability parameter is used as the second weight value of the feature vector. The first target feature and the feature vector are filtered based on the first weight value and the second weight value by the gating unit of the pinyin feature gating network to obtain a pinyin filter vector. Specifically, the pinyin feature gating network may further include a gating unit, through which information in the network may be screened, and the formula is as follows:
[0087] X py =p1*pyX_vec+(1-p1)*X_vec
[0088] Among them, pyX_vec is the first target feature, X_vec is the feature vector, p1 is the homophone error probability, and 1-p1 is the opposition probability parameter.
[0089] This embodiment calculates the first opposing probability parameter through the homophone error probability, and then filters the first target feature and feature vector according to the homophone error probability and the first opposing probability parameter, thereby achieving homophone error correction for the target text and further improving the accuracy of text error correction.
[0090] In some optional implementations of this embodiment, the step of filtering the feature vector based on the stroke error probability to obtain the stroke filter vector includes:
[0091] Calculating a second opposing probability parameter according to the stroke error probability, using the stroke error probability as a third weight value of the second target feature, and using the second opposing probability parameter as a fourth weight value of the feature vector;
[0092] The stroke filter vector is calculated according to the third weight value, the fourth weight value, the second target feature and the feature vector.
[0093] In this embodiment, when the stroke error probability is obtained, a second opposing probability parameter is calculated based on the stroke error probability, wherein the second opposing probability parameter is the probability of the opposing event of the stroke error probability, and the second opposing probability parameter is obtained by subtracting the stroke error probability from 1. When the second opposing probability parameter is obtained, the stroke error probability is used as the third weight value of the second target feature, and the second opposing probability parameter of the stroke error probability is used as the fourth weight value of the feature vector. The second target feature and the feature vector are filtered based on the third weight value and the fourth weight value through the gating unit of the stroke feature gating network to obtain a stroke filter vector. Specifically, the product of the third weight value and the second target feature, and the product of the fourth weight value and the feature vector are calculated based on the gating unit; then, the two products are summed to calculate the stroke filter vector. The calculation formula of the stroke filter vector is as follows:
[0094] X st =p2*stX_vec+(1-p2)*X_vec
[0095] Among them, p2 is the stroke error probability, stX_vec is the second target feature, 1-p2 is the opposite probability parameter corresponding to the stroke error probability, and X_vec is the feature vector.
[0096] This embodiment calculates the second opposite probability parameter through the stroke error probability, and then filters the second target feature and feature vector according to the stroke error probability and the second opposite probability parameter, thereby correcting similar characters in the target text and further improving the accuracy of text correction.
[0097] In some optional implementations of this embodiment, the step of performing feature fusion on the feature vector, the pinyin filter vector and the stroke filter vector to obtain the third target feature includes:
[0098] Performing vector addition on the feature vector, the pinyin filter vector and the stroke filter vector to obtain a fusion feature;
[0099] A third fully connected layer is obtained, and mapping calculation is performed on the fusion feature based on the third fully connected layer to obtain the third target feature.
[0100] In this embodiment, when the pinyin filter vector and the stroke filter vector are obtained, the feature vector, the pinyin filter vector and the stroke filter vector are vector-added to obtain a fusion feature; then, a third fully connected layer is obtained, wherein the parameters of the third fully connected layer are different from those of the second fully connected layer and the first fully connected layer, and the feature vector, the pinyin filter vector and the stroke filter vector are mapped to the same parameter space through the third fully connected layer to obtain a third target feature. The calculation formula of the third target feature is as follows:
[0101] X merge =W3(X_vec+X py +X st )+b3
[0102] Among them, X_vec is the feature vector, X py is the pinyin filter vector, X st is the stroke filter vector, W3 and b3 are the training parameter matrix and bias term of the third fully connected layer.
[0103] This embodiment obtains the third target feature by fusing the feature vector, the pinyin filter vector and the stroke filter vector, thereby achieving the fusion of the features after error correction and further improving the efficiency of text error correction.
[0104] In some optional implementations of this embodiment, the step of inputting the third target feature into the target encoding network and encoding to obtain the error correction text includes:
[0105] The target encoding network includes a multi-head attention layer, a regularization layer and a forward propagation layer. The third target feature is input into the multi-head attention layer, and the error-corrected text is calculated through the regularization layer and the forward propagation layer.
[0106] In this embodiment, the third target feature is a feature that integrates the feature vector of the target text, the pinyin filter vector and the stroke filter vector, and the pinyin filter vector and the stroke filter vector are the pinyin feature after error correction and the stroke feature after error correction. Therefore, when the third target feature is obtained, the third target feature is encoded to obtain the final error-corrected text. Specifically, a target coding network is obtained, and the target coding network can adopt the coding network in the transformer model, and the target coding network includes a multi-head attention layer, a regularization layer and a forward propagation layer. The third target feature is input into the multi-head attention layer of the target coding network, and then, after passing through the regularization layer and the forward propagation layer, the error-corrected text corresponding to the target text is encoded.
[0107] This embodiment encodes the third target feature through the target encoding network, realizes efficient fusion and encoding of the features after error correction, and improves the accuracy of text error correction.
[0108] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through computer-readable instructions, and the computer-readable instructions can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the aforementioned storage medium can be a non-volatile storage medium such as a disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM).
[0109] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.
[0110] Further references Figure 3 , as a response to the above Figure 2 The present application provides an embodiment of a text error correction device, and the device embodiment is similar to Figure 2 Corresponding to the method embodiment shown, the device can be specifically applied to various electronic devices.
[0111] like Figure 3 As shown, the text error correction device 300 described in this embodiment includes: an acquisition module 301, a first fusion module 302, a second fusion module 303 and an output module 304. Among them:
[0112] The acquisition module 301 is used to acquire a target text, calculate a feature vector of the target text, and calculate a phonetic feature and a stroke feature of the target text;
[0113] In this embodiment, the input target text is obtained, and the target text is input into the pre-trained Chinese BERT model. The target text is calculated by the BERT model to obtain the feature vector corresponding to the target text. The pinyin feature is the pinyin coding feature of the target text. The pinyin text is obtained by performing pinyin conversion on the target text; then, the pinyin text is encoded to obtain the pinyin feature. Specifically, a pinyin list is obtained, and the target text can be converted into the corresponding pinyin text by referring to the pinyin list through the pinyin toolkit. When the pinyin text is obtained, the pinyin text is input into the pinyin coding network, and the pinyin text is encoded based on the pinyin coding network to obtain the pinyin feature. Among them, the pinyin coding network can select LSTM (Long Short-Term Memory, long short-term memory network), and the input pinyin text is feature-encoded by the long short-term memory network to obtain the corresponding pinyin feature.
[0114] The stroke feature is the stroke coding feature corresponding to the target text. By performing stroke conversion on the target text, the corresponding stroke feature sequence is obtained. Specifically, a Chinese character stroke list is obtained, and each stroke in the Chinese character stroke list is numbered; then, the stroke order corresponding to each Chinese character in the target text is determined according to the number, and the number combination corresponding to each Chinese character in the target text is determined according to the stroke order; according to the arrangement order of the Chinese characters in the target text, the number combination is sorted, and the stroke feature sequence corresponding to the target text is obtained. For example, the horizontal line "-" is represented by the number 1, the vertical line "|" is represented by 2, and the corresponding stroke feature list of "Today's weather is very good" is "3445 1134 1134 3115 13243111512212511". When the stroke feature sequence is obtained, the stroke feature sequence is input into the stroke coding network, and the stroke feature sequence is encoded based on the stroke coding network to obtain the stroke feature. The stroke encoding network may also be LSTM (Long Short-Term Memory), which has different parameters from the LSTM selected by the pinyin encoding network. The stroke feature sequence is encoded by the LSTM to obtain the stroke features corresponding to the target text. The vector dimensions of the stroke features and the pinyin features are the same as the vector dimensions of the feature vector.
[0115] A first fusion module 302 is used to fuse the feature vector and the pinyin feature to obtain a first target feature, calculate the homophone error probability of the target text according to the first target feature, and perform information filtering on the feature vector based on the homophone error probability to obtain a pinyin filter vector;
[0116] In some optional implementations of this embodiment, the first fusion module 302 includes:
[0117] A first mapping unit is used to obtain a pinyin feature gating network, and map the first target feature based on a first fully connected layer of the pinyin feature gating network to obtain a first mapping feature;
[0118] The first calculation unit is used to input the first mapping feature to the first activation layer of the pinyin feature gating network, calculate the first mapping feature based on the activation function of the first activation layer, and obtain the homophone error probability.
[0119] In some optional implementations of this embodiment, the first fusion module 302 further includes:
[0120] a second calculation unit, configured to calculate a first opposition probability parameter according to the homophone error probability, use the homophone error probability as a first weight value of the first target feature, and use the first opposition probability parameter as a second weight value of the feature vector;
[0121] The third calculation unit is used to calculate the pinyin filter vector according to the first weight value, the second weight value, the first target feature and the feature vector.
[0122] In this embodiment, when the feature vector and the pinyin feature are obtained, the feature vector and the pinyin feature are fused, wherein the fused first target feature can be obtained by vector addition of the feature vector and the pinyin feature. The homophone error probability of the target text is calculated according to the first target feature, and the homophone error probability is the probability that there are homophone errors in the characters in the target text. The homophone error probability can be obtained by calculating the first target feature obtained by the fully connected layer and the activation layer. When the homophone error probability is obtained, the feature vector is filtered based on the homophone error probability to obtain a pinyin filter vector. Among them, information filtering is a process of filtering the feature vector and the first target feature according to the calculated homophone error probability, and filtering out the correct pinyin information therein. Specifically, the homophone error probability is used as the first weight value of the first target feature, and the opposite probability parameter of the homophone error probability is used as the second weight value of the feature vector, and the product of the first weight value and the first target feature, and the product of the second weight value and the feature vector are calculated; the two products are summed to calculate the pinyin filter vector.
[0123] A second fusion module 303 is used to fuse the feature vector and the stroke feature to obtain a second target feature, calculate the stroke error probability of the target text according to the second target feature, and filter the feature vector based on the stroke error probability to obtain a stroke filter vector;
[0124] In some optional implementations of this embodiment, the second fusion module 303 includes:
[0125] A second mapping unit is used to obtain a stroke feature gating network, and map the second target feature based on a second fully connected layer of the stroke feature gating network to obtain a second mapping feature;
[0126] The fourth calculation unit is used to input the second mapping feature to the second activation layer of the stroke feature gating network, calculate the second mapping feature based on the activation function of the second activation layer, and obtain the stroke error probability.
[0127] In some optional implementations of this embodiment, the second fusion module 303 further includes:
[0128] a fifth calculation unit, configured to calculate a second opposing probability parameter according to the stroke error probability, use the stroke error probability as a third weight value of the second target feature, and use the second opposing probability parameter as a fourth weight value of the feature vector;
[0129] A sixth calculation unit is used to calculate the stroke filter vector according to the third weight value, the fourth weight value, the second target feature and the feature vector.
[0130] In this embodiment, when the feature vector and the stroke feature are obtained, the feature vector and the stroke feature are fused, wherein the fused second target feature can be obtained by vector addition of the feature vector and the stroke feature. The stroke error probability of the target text is calculated according to the second target feature, and the stroke error probability is the probability that there is a similar error in the character in the target text. The second target feature is calculated by the fully connected layer and the activation layer to obtain the stroke error probability. When the stroke error probability is obtained, the feature vector is filtered based on the stroke error probability to obtain a stroke filter vector. Among them, information filtering is a process of filtering the feature vector and the second target feature according to the calculated stroke error probability, and filtering out the correct stroke information. Specifically, the stroke error probability is used as the third weight value of the second target feature, and the opposite probability parameter of the homophonic error probability is used as the fourth weight value of the feature vector. The product of the third weight value and the second target feature, and the product of the fourth weight value and the feature vector are calculated; the two products are summed to calculate the stroke filter vector.
[0131] The output module 304 is used to perform feature fusion on the feature vector, the pinyin filter vector and the stroke filter vector to obtain a third target feature, input the third target feature into the target encoding network, and encode to obtain the error-corrected text.
[0132] In some optional implementations of this embodiment, the output module 304 includes:
[0133] A fusion unit, used for performing vector addition on the feature vector, the pinyin filter vector and the stroke filter vector to obtain a fusion feature;
[0134] The third mapping unit is used to obtain a third fully connected layer, and perform mapping calculation on the fusion feature based on the third fully connected layer to obtain the third target feature.
[0135] In some optional implementations of this embodiment, the output module 304 further includes:
[0136] The encoding unit, which is used for the target encoding network, includes a multi-head attention layer, a regularization layer and a forward propagation layer. The third target feature is input to the multi-head attention layer, and the error-corrected text is calculated through the regularization layer and the forward propagation layer.
[0137] In this embodiment, when the feature vector, the pinyin filter vector and the stroke filter vector are obtained, the feature vector, the pinyin filter vector and the stroke filter vector are subjected to feature fusion to obtain a third target feature. The third target feature is input into the target coding network, and the error correction text is obtained based on the target coding network encoding. Specifically, the target coding network can select the encoding network of the transformer model, wherein the transformer model includes an encoding network (encoder) and a decoding network (decoder); the third target feature is encoded and calculated by the encoding network of the transformer model, and the error correction text is obtained as output.
[0138] The text correction device proposed in this embodiment realizes efficient error correction of text, and can timely and effectively identify typos in text, thereby improving the accuracy of text correction and avoiding waste of resources due to text errors.
[0139] To solve the above technical problems, the present application also provides a computer device. Figure 4 , Figure 4 This is a basic structural block diagram of the computer device in this embodiment.
[0140] The computer device 6 includes a memory 61, a processor 62, and a network interface 63 that are interconnected through a system bus. It should be noted that the figure only shows a computer device 6 with components 61-63, but it should be understood that it is not required to implement all the components shown, and more or fewer components can be implemented instead. Among them, those skilled in the art can understand that the computer device here is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions, and its hardware includes but is not limited to microprocessors, application specific integrated circuits (Application Specific Integrated Circuit, ASIC), programmable gate arrays (Field-Programmable Gate Array, FPGA), digital processors (Digital Signal Processor, DSP), embedded devices, etc.
[0141] The computer device may be a computing device such as a desktop computer, a notebook, a PDA, a cloud server, etc. The computer device may interact with a user through a keyboard, a mouse, a remote controller, a touch pad, or a voice control device.
[0142] The memory 61 includes at least one type of readable storage medium, and the readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, disk, optical disk, etc. In some embodiments, the memory 61 can be an internal storage unit of the computer device 6, such as a hard disk or memory of the computer device 6. In other embodiments, the memory 61 can also be an external storage device of the computer device 6, such as a plug-in hard disk equipped on the computer device 6, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (FlashCard), etc. Of course, the memory 61 can also include both the internal storage unit of the computer device 6 and its external storage device. In this embodiment, the memory 61 is generally used to store the operating system and various application software installed on the computer device 6, such as computer-readable instructions of a text error correction method, etc. In addition, the memory 61 can also be used to temporarily store various types of data that have been output or are to be output.
[0143] The processor 62 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chips in some embodiments. The processor 62 is generally used to control the overall operation of the computer device 6. In this embodiment, the processor 62 is used to run computer-readable instructions stored in the memory 61 or process data, such as computer-readable instructions for running the text error correction method.
[0144] The network interface 63 may include a wireless network interface or a wired network interface. The network interface 63 is generally used to establish a communication connection between the computer device 6 and other electronic devices.
[0145] The computer device proposed in this embodiment realizes efficient error correction of text and can timely and effectively identify typos in text, thereby improving the accuracy of text error correction and avoiding waste of resources due to text errors.
[0146] The present application also provides another embodiment, namely, providing a computer-readable storage medium, wherein the computer-readable storage medium stores computer-readable instructions, and the computer-readable instructions can be executed by at least one processor to enable the at least one processor to perform the steps of the text correction method as described above.
[0147] The computer-readable storage medium proposed in this embodiment realizes efficient error correction of text and can timely and effectively identify typos in text, thereby improving the accuracy of text error correction and avoiding waste of resources due to text errors.
[0148] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in each embodiment of the present application.
[0149] Obviously, the embodiments described above are only some embodiments of the present application, rather than all embodiments. The preferred embodiments of the present application are given in the accompanying drawings, but they do not limit the patent scope of the present application. The present application can be implemented in many different forms. On the contrary, the purpose of providing these embodiments is to make the understanding of the disclosure of the present application more thorough and comprehensive. Although the present application is described in detail with reference to the aforementioned embodiments, for those skilled in the art, it is still possible to modify the technical solutions recorded in the aforementioned specific implementation methods, or to perform equivalent replacement of some of the technical features therein. Any equivalent structure made using the contents of the specification and drawings of this application, directly or indirectly used in other related technical fields, is similarly within the scope of patent protection of this application.
Claims
1. A text error correction method, characterized in that: The steps include: Acquire a target text, calculate a feature vector of the target text, and calculate phonetic features and stroke features of the target text; The feature vector and the pinyin feature are merged to obtain a first target feature, a homophone error probability of the target text is calculated according to the first target feature, and information filtering is performed on the feature vector based on the homophone error probability to obtain a pinyin filter vector; The feature vector and the stroke feature are merged to obtain a second target feature, a stroke error probability of the target text is calculated according to the second target feature, and information filtering is performed on the feature vector based on the stroke error probability to obtain a stroke filter vector; Performing feature fusion on the feature vector, the pinyin filter vector and the stroke filter vector to obtain a third target feature, inputting the third target feature into a target encoding network, and encoding to obtain an error-corrected text; The step of calculating the homophone error probability of the target text according to the first target feature comprises: Acquire a pinyin feature gating network, and map the first target feature based on a first fully connected layer of the pinyin feature gating network to obtain a first mapping feature; Inputting the first mapping feature to the first activation layer of the pinyin feature gating network, calculating the first mapping feature based on the activation function of the first activation layer, and obtaining the homophone error probability; The step of calculating the stroke error probability of the target text according to the second target feature comprises: Acquire a stroke feature gating network, and map the second target feature based on a second fully connected layer of the stroke feature gating network to obtain a second mapping feature; Inputting the second mapping feature to the second activation layer of the stroke feature gating network, and calculating the second mapping feature based on the activation function of the second activation layer to obtain the stroke error probability; The step of filtering the feature vector based on the homophone error probability to obtain a pinyin filter vector comprises: Calculate a first opposition probability parameter according to the homophone error probability, use the homophone error probability as a first weight value of the first target feature, and use the first opposition probability parameter as a second weight value of the feature vector; Calculate the pinyin filter vector according to the first weight value, the second weight value, the first target feature and the feature vector; The step of filtering the feature vector based on the stroke error probability to obtain a stroke filter vector comprises: Calculating a second opposing probability parameter according to the stroke error probability, using the stroke error probability as a third weight value of the second target feature, and using the second opposing probability parameter as a fourth weight value of the feature vector; The stroke filter vector is calculated according to the third weight value, the fourth weight value, the second target feature and the feature vector.
2. The text error correction method according to claim 1, characterized in that: The step of performing feature fusion on the feature vector, the pinyin filter vector and the stroke filter vector to obtain a third target feature comprises: Performing vector addition on the feature vector, the pinyin filter vector and the stroke filter vector to obtain a fusion feature; A third fully connected layer is obtained, and a mapping calculation is performed on the fusion feature based on the third fully connected layer to obtain the third target feature.
3. The text error correction method according to claim 1, characterized in that: The step of inputting the third target feature into the target encoding network and encoding to obtain the error correction text comprises: The target encoding network includes a multi-head attention layer, a regularization layer and a forward propagation layer. The third target feature is input into the multi-head attention layer, and the error-corrected text is calculated through the regularization layer and the forward propagation layer.
4. A text error correction device, characterized in that: include: An acquisition module, used to acquire a target text, calculate a feature vector of the target text, and calculate a phonetic feature and a stroke feature of the target text; A first fusion module is used to fuse the feature vector and the pinyin feature to obtain a first target feature, calculate the homophone error probability of the target text according to the first target feature, and perform information filtering on the feature vector based on the homophone error probability to obtain a pinyin filter vector; A second fusion module is used to fuse the feature vector and the stroke feature to obtain a second target feature, calculate the stroke error probability of the target text according to the second target feature, and filter the feature vector based on the stroke error probability to obtain a stroke filter vector; An output module, used for performing feature fusion on the feature vector, the pinyin filter vector and the stroke filter vector to obtain a third target feature, inputting the third target feature into a target encoding network, and encoding to obtain an error-corrected text; The first fusion module includes: A first mapping unit is used to obtain a pinyin feature gating network, and map the first target feature based on a first fully connected layer of the pinyin feature gating network to obtain a first mapping feature; A first calculation unit is used to input the first mapping feature to the first activation layer of the pinyin feature gating network, and calculate the first mapping feature based on the activation function of the first activation layer to obtain the homophone error probability; The second fusion module includes: A second mapping unit is used to obtain a stroke feature gating network, and map the second target feature based on a second fully connected layer of the stroke feature gating network to obtain a second mapping feature; a fourth calculation unit, configured to input the second mapping feature into the second activation layer of the stroke feature gating network, and calculate the second mapping feature based on the activation function of the second activation layer to obtain the stroke error probability; The first fusion module also includes: a second calculation unit, configured to calculate a first opposition probability parameter according to the homophone error probability, use the homophone error probability as a first weight value of the first target feature, and use the first opposition probability parameter as a second weight value of the feature vector; A third calculation unit, configured to calculate the pinyin filter vector according to the first weight value, the second weight value, the first target feature and the feature vector; The second fusion module also includes: a fifth calculation unit, configured to calculate a second opposing probability parameter according to the stroke error probability, use the stroke error probability as a third weight value of the second target feature, and use the second opposing probability parameter as a fourth weight value of the feature vector; A sixth calculation unit is used to calculate the stroke filter vector according to the third weight value, the fourth weight value, the second target feature and the feature vector.
5. A computer device, comprising a memory and a processor, wherein the memory stores computer-readable instructions, and the processor implements the steps of the text error correction method as described in any one of claims 1 to 3 when executing the computer-readable instructions.
6. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-readable instructions, and when the computer-readable instructions are executed by a processor, the steps of the text error correction method according to any one of claims 1 to 3 are implemented.
Citation Information
Patent Citations
Text error correction method and device, and related equipment
CN108874174A
Text error correction method and system
CN111310443A