Text error correction method and device, equipment, storage medium and product
Through the joint training of the graph neural network and the BERT model, a preset text error correction model is formed, which solves the problem of low error correction accuracy in the existing technology and achieves a more efficient text error correction effect.
Patent Information
- Application Number
- CN202410671540.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-27
- Publication Date
- 2024-10-01
AI Technical Summary
Existing text error correction systems are based on lexicon and rules, resulting in low error correction accuracy and inability to effectively handle complex grammatical errors and contextual information.
The graph neural network is used to process the text data, and a feature matrix graph is generated. The BERT model and the graph attention network are combined for joint training to form a preset text error correction model to improve the error correction accuracy.
Through the joint training of the graph neural network and the BERT model, the text error correction model can better understand the relationship between texts, improve the error correction accuracy and efficiency, and overcome the problem of low error correction accuracy in the existing technology.
Smart Images

Figure CN118734834A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of natural language processing technology, and in particular to a text error correction method, apparatus, device, storage medium and computer program product. Background Art
[0002] Text error correction is a very important task in the field of natural language processing. Its purpose is to automatically detect and correct grammatical, spelling, and punctuation errors in input text, generate more accurate and readable text, and help online publishers generate spelled website content more quickly and efficiently to improve customer satisfaction, etc.
[0003] The current text correction system is mainly based on thesaurus and rules. It matches words with text in thesaurus. If the match fails, correction is performed. This method is suitable for some common word errors. Since the number of words in thesaurus is limited and cannot include all words and variant forms, it requires a lot of computing resources to perform correction, and the accuracy of text correction is also low.
[0004] Therefore, how to improve the accuracy of text error correction is a problem that needs to be solved urgently.
[0005] The above contents are only used to assist in understanding the technical solution of the present application and do not constitute an admission that the above contents are prior art. Summary of the invention
[0006] The main purpose of this application is to provide a text correction method, device, equipment, storage medium and computer program product, aiming to solve the technical problem in the related art that text correction is performed based on a vocabulary and rules, resulting in low accuracy of text correction.
[0007] To achieve the above purpose, the present application proposes a text error correction method, which includes:
[0008] Obtaining text data to be corrected;
[0009] The text data is processed by graph construction to obtain a feature matrix diagram, which is used to represent the correlation between various text fragments in the text data;
[0010] Based on a preset text error correction model, the feature matrix graph is corrected to obtain a text error correction result, wherein the preset text error correction model is obtained by joint training based on the BERT model and the graph attention network.
[0011] In one embodiment, based on a preset text error correction model, the feature matrix diagram is subjected to error correction processing, and before obtaining the text error correction result, the method further includes:
[0012] Obtain historical error-corrected text datasets;
[0013] Based on the graph neural network, the error correction text dataset is converted into the first matrix graph;
[0014] Based on the BERT model, the error correction text dataset is converted into first embedded data, and the first matrix graph is converted into an initial feature vector;
[0015] The initial feature vector and the first embedded data are predicted by the graph attention network to obtain a prediction result;
[0016] Compare the predicted results with the actual results corresponding to the error correction text dataset until the preset loss function converges, and then determine the text error correction model.
[0017] In one embodiment, the prediction result is compared with the actual result corresponding to the error correction text data set until the preset loss function converges, and the text error correction model is determined, including:
[0018] Compare the predicted results with the actual results corresponding to the error correction text dataset, and calculate the first loss function of the BERT model and the second loss function of the graph attention network;
[0019] Combining the first loss function with the second loss function to obtain a preset loss function;
[0020] Based on the output value of the preset loss function, the model parameters of the neural network in each iteration round are updated until the preset loss function reaches the minimum value, generating a text error correction model.
[0021] In one embodiment, converting the first matrix graph into an initial eigenvector includes:
[0022] Determine a plurality of first characteristic nodes in the first matrix graph;
[0023] Each first characteristic node is initialized by a zero vector to obtain an initial characteristic vector.
[0024] In one embodiment, the text data is subjected to a graph construction process to obtain a feature matrix graph, including:
[0025] Identify entity tags in text data, including text tags and word tags;
[0026] According to each entity label, generate a second feature node and a feature edge in the feature matrix graph;
[0027] Connect each second feature node and feature edge to obtain a feature matrix graph.
[0028] In one embodiment, based on a preset text error correction model, error correction processing is performed on the feature matrix diagram to obtain a text error correction result, including:
[0029] Based on the preset text error correction model, the feature matrix graph is converted into embedding layer data;
[0030] Perform prediction processing on the embedded layer data on the structure diagram corresponding to the feature matrix diagram to obtain the prediction weight;
[0031] Based on the text type corresponding to the prediction weight, the text correction result is determined.
[0032] In addition, to achieve the above purpose, the present application also proposes a text error correction device, which includes:
[0033] A first acquisition module, used to acquire text data to be corrected;
[0034] A processing module is used to perform a graph construction process on the text data to obtain a feature matrix diagram, and the feature matrix diagram is used to represent the correlation relationship between various text fragments in the text data;
[0035] The error correction processing module is used to perform error correction processing on the feature matrix graph based on a preset text error correction model to obtain a text error correction result, wherein the preset text error correction model is obtained by joint training based on the BERT model and the graph attention network.
[0036] In addition, to achieve the above-mentioned purpose, the present application also proposes a text correction device, which includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the text correction method as described above.
[0037] In addition, to achieve the above-mentioned purpose, the present application also proposes a storage medium, which is a computer-readable storage medium. A computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the text error correction method as described above are implemented.
[0038] In addition, to achieve the above-mentioned purpose, the present application also provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the steps of the text error correction method as described above are implemented.
[0039] The present application proposes a text error correction method, apparatus, device, storage medium and computer program product. The present application obtains text data to be corrected and processes the text data through a graph neural network to obtain a feature matrix diagram. The feature matrix diagram is used to represent the correlation between each text fragment in the text data, so that the text data can be converted into a graph structure based on multiple text types. After integrating multiple levels of semantic feature information, the preset text error correction model input subsequently can better understand the relationship between texts, thereby improving the accuracy of model prediction. Furthermore, the preset text error correction model is obtained by joint training based on the BERT model and the graph attention network, so that the model can understand and learn text data from multiple levels, thereby improving the error correction efficiency and accuracy of the model.
[0040] In summary, the present application processes text data through a graph neural network to obtain a feature matrix diagram, which is used to represent the correlation between various text fragments in the text data, so that the text data can be converted into a graphical structure based on multiple text types. After integrating multiple levels of semantic feature information, the preset text error correction model input subsequently can better understand the relationship between texts, thereby improving the accuracy of model predictions. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0042] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0043] Figure 1 A flowchart of the first embodiment of the text error correction method of the present application is provided;
[0044] Figure 2 A schematic diagram of the overall execution flow provided for the text error correction method of this application;
[0045] Figure 3 A brief flowchart of the third embodiment of the present invention is provided.
[0046] Figure 4 This is a schematic diagram of the module structure of the text error correction device of the embodiment of the present application;
[0047] Figure 5 It is a schematic diagram of the device structure of the hardware operating environment involved in the text error correction method in the embodiment of the present application.
[0048] The purpose, features and advantages of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0049] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application and are not used to limit the present application.
[0050] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.
[0051] The main solution of the embodiment of the present application is: obtaining text data to be corrected;
[0052] The text data is processed by graph construction to obtain a feature matrix diagram, which is used to represent the correlation between various text fragments in the text data;
[0053] Based on a preset text error correction model, the feature matrix graph is corrected to obtain a text error correction result, wherein the preset text error correction model is obtained by joint training based on the BERT model and the graph attention network.
[0054] In this embodiment, for ease of description, the text error correction device is used as the execution subject for explanation below.
[0055] In the prior art, there are mainly three technologies for text error correction:
[0056] 1. Text correction based on vocabulary and rules. The text correction system can correct the text through the built-in vocabulary. This method is a simple and direct way, suitable for handling errors in some common words, such as common names, place names or common words. The correction system uses the vocabulary to match the words in the text to be corrected, and determines whether there is a spelling error based on the matching results. If the word to be corrected successfully matches the word in the vocabulary, it is considered correct and does not need to be corrected; on the contrary, if the word to be corrected cannot find a match in the vocabulary, it is judged as a spelling error and provides correction suggestions. Through the use of the vocabulary, the correction system can quickly and accurately identify and repair common word errors in the text.
[0057] The disadvantages of method 1 are:
[0058] Text error correction using a vocabulary is too dependent on a fixed vocabulary. The number of words and phrases in the vocabulary is limited and may not include all words and variant forms. Therefore, some error correction errors may be missed or errors may be reported for words that are not in the vocabulary. It cannot process contextual information. Vocabulary error correction is usually based only on the frequency statistics of words and phrases, and cannot consider the contextual information of surrounding words. In addition, when the text contains ambiguous or polysemous words, the vocabulary may give wrong suggestions and cannot make more accurate inferences with the help of contextual information. It cannot handle complex grammatical errors. Various grammatical errors in the text, such as subject-verb inconsistency and word order errors, cannot be effectively processed. It is necessary to maintain and update a huge vocabulary, and it takes a lot of computing resources to search for words in the vocabulary and generate candidate error correction results. Therefore, vocabulary error correction may require high computing resources and maintenance costs.
[0059] 2. Text correction based on the BERT (Bidirectional Encoder Representation from Transformers, a pre-trained language representation model) language model. By removing the NSP task, simplifying the input of the BERT model, and removing Segment Embedding, the Masked Language Modeling (MLM) task of the original BERT model can be improved into a text correction task. Through the training or fine-tuning stage, 15% of the tokens in the text can be randomly replaced with incorrect characters, and then the model is required to restore these tokens to correct characters. The specific process is to directly input the original text into the model and let the model predict the correct token at each position to effectively handle different types of errors in the text correction task and provide accurate correction suggestions.
[0060] The disadvantages of method 2 are:
[0061] For the text error correction of the BERT model, each output token is independent of each other, that is, the error correction output in the previous step does not affect the error correction in the current step. For example, in the sentence "Ice is liquid", although the token "ice" at position 0 has been corrected to "water", the correction information is not passed to the token at position 2, so the model will still correct "liquid" to "solid" when predicting the output at position 2, which leads to an error.
[0062] 3. Text correction based on generative models. The specific process is to use the prepared data set to train the GPT model, take the erroneous text as input, and let the model generate the corrected text as output, compare the generated text with the correct correction result, use the appropriate loss function to guide the model to learn to generate the correct correction text, and then use evaluation indicators, such as edit distance or language model perplexity, to select the optimal correction result.
[0063] The disadvantages of method 3 are:
[0064] A generative model is a model that takes a sentence as input and then outputs one or more possible corrected texts. Although it can solve the problem of insufficient contextual information, it still has some disadvantages. It requires a lot of computing resources and time to train. If the text to be corrected is large, it may take a long time to generate the correction results. A large amount of high-quality data is required to train to obtain accurate performance. If the sample quality is not good, the model effect may decline. Before correcting the text, the generative model may replace the wrong words with other wrong words, which may cause bigger problems.
[0065] The present application provides a text correction method, apparatus, device, storage medium and computer program product, which processes text data through a graph neural network to obtain a feature matrix diagram, which is used to represent the correlation between various text fragments in the text data, so that the text data can be converted into a graphical structure based on multiple text types. After integrating multiple levels of semantic feature information, the preset text correction model input subsequently can better understand the relationship between texts, thereby improving the accuracy of model prediction.
[0066] The specific embodiments of the technical solution that can be implemented are described in conjunction with the drawings, as well as the framework and ideas of the corresponding claims. If there are drawings, they will be described in conjunction with the drawings.
[0067] It can be seen from the above embodiments that the present application overcomes the technical problems of error correction accuracy of text data in the prior art by adopting a technical means of converting text data into a graph structure so that the error correction model can better understand the relationship between texts, thereby achieving the technical effect of improving the error correction accuracy of the model for text data.
[0068] It should be noted that the execution subject of this embodiment can be a computing service device with data processing, network communication and program running functions, such as a tablet computer, a personal computer, a mobile phone, etc., or an electronic device capable of realizing the above functions, a text error correction device, etc. The following takes a text error correction device as an example to illustrate this embodiment and the following embodiments.
[0069] Based on this, the present application embodiment provides a text error correction method, referring to Figure 1 , Figure 1 This is a flow chart of the first embodiment of the text error correction method of this application.
[0070] In this embodiment, the text error correction method includes steps S10 to S40:
[0071] Step S10, obtaining text data to be corrected;
[0072] It should be noted that the text data can be paragraphs, short sentences, words, etc., without specific limitation.
[0073] It should be noted that if there are wrong characters or grammatical problems in the text data to be corrected, the text correction process will not only correct the typos in the text, but also adjust the corresponding logic of the text. For example, when the text data to be corrected is "ice is liquid", after the text correction is completed, it will be adjusted to "water is liquid" or "ice is solid".
[0074] Step S20, performing a graph construction process on the text data to obtain a feature matrix diagram, where the feature matrix diagram is used to characterize the association relationship between various text segments in the text data;
[0075] It should be noted that the text dataset is constructed into a structural graph through the graph neural network, thereby obtaining a feature matrix graph.
[0076] It should be noted that the feature matrix diagram includes multiple node feature matrices and adjacency matrices. Each node feature matrix represents a piece of text or a word. The corresponding node is constructed according to the meaning or part of speech corresponding to the text data. The adjacency matrix is the vector adjacent to each node feature matrix.
[0077] It should be noted that the purpose of converting text data into a feature matrix diagram is to better describe the semantic relationship between each text fragment in the text data set, thereby further improving the performance and expressiveness of the model.
[0078] It should be noted that the feature matrix diagram can also be called a heterogeneous graph of the text dataset. Each feature node represents a text fragment, where a text fragment can be a paragraph, a word, a short sentence, etc. Different feature nodes are connected by edges with text attributes. For example, when the text represented by the node is "Person", the attributes of the current node can be "name", "age", etc. After obtaining the feature matrix diagram, each node represents an entity, and each edge represents the relationship between entities. By defining appropriate types, attributes, labels and weights on the nodes and edges, the nodes and edges are connected to generate node feature matrices and adjacency matrices.
[0079] Step S30, based on a preset text error correction model, the feature matrix graph is corrected to obtain a text error correction result, wherein the preset text error correction model is obtained by joint training based on the BERT model and the graph attention network.
[0080] It should be noted that the preset text error correction model is obtained by joint training based on the BERT model and the graph attention network. The preset text error correction model is composed of the BERT encoder and the GAT network structure. The BERT encoder is composed of multiple transformer encoder layers. Each encoder layer contains a multi-head self-attention mechanism and a feedforward neural network, and uses residual connections and layer normalization. The feedforward neural network is a fully connected multi-layer perceptron, which is used to perform nonlinear transformation on the output of the self-attention mechanism. The GAT network structure consists of multiple graph convolutional layers, self-attention mechanisms, node representation updates, multi-head attention, and stacked layers.
[0081] It should be noted that the two models are combined to correct text errors. The language model advantages of the BERT model are used to model the text, and the graph neural network with an attention mechanism is used to learn the representation of text fragments and process the correlation between texts, thereby further improving the model's recognition and error correction capabilities.
[0082] In a feasible implementation, step S30 may include steps S31 to S33:
[0083] Step S31, based on a preset text error correction model, converting the feature matrix graph into embedding layer data;
[0084] It should be noted that after the feature matrix diagram is input into the preset text error correction model, the feature matrix diagram is encoded by the BERT encoder and converted into embedded layer data. The encoding process is an existing technology well known to personnel in this field and will not be elaborated here.
[0085] It should be noted that the embedding layer data is the data output by the encoder, which contains the contextual information of the text data. The Transformer Encoder block in the BERT model obtains the final encoded representation of the input sequence through multiple self-attention and feedforward network operations. The self-attention mechanism realizes the weighted summation of all positions, thereby capturing the contextual information and relationships.
[0086] Step S32, performing prediction processing on the embedded layer data on the structure diagram corresponding to the feature matrix diagram to obtain a prediction weight;
[0087] It should be noted that the prediction process is performed by the graph attention network. Processing the embedding layer data output by the BERT encoder on the structure graph allows the graph attention network to capture the node relationship in the structure graph, thereby forward propagating the corresponding node feature vectors and outputting the prediction weights.
[0088] It can be understood that after the model training is completed, the predicted weights obtained include the weight values of the BERT model and the weight values of the graph attention network. The two are combined to form the final weight output by the text error correction model.
[0089] Specifically, the output model weights obtained by BERT encoder are combined with the output model weights of GAT to obtain the final model weights. The fusion formula is as follows:
[0090] h=[h BERT ;h GAT ]
[0091] Among them, h represents the final model weight; h BERT and h GAT Represent the model weights of BERT encoder and GAT respectively.
[0092] Step S33, determining the text error correction result based on the text type corresponding to the prediction weight.
[0093] It should be noted that the output prediction weight has its corresponding text type, which can be a short sentence, a word, etc. After determining the text type, the current text type is replaced with the text data to be corrected to determine the text correction result.
[0094] The present application proposes a text error correction method, apparatus, device, storage medium and computer program product. The present application obtains text data to be corrected and processes the text data through a graph neural network to obtain a feature matrix diagram. The feature matrix diagram is used to represent the correlation between each text fragment in the text data, so that the text data can be converted into a graph structure based on multiple text types. After integrating multiple levels of semantic feature information, the preset text error correction model input subsequently can better understand the relationship between texts, thereby improving the accuracy of model prediction. Furthermore, the preset text error correction model is obtained by joint training based on the BERT model and the graph attention network, so that the model can understand and learn text data from multiple levels, thereby improving the error correction efficiency and accuracy of the model.
[0095] Based on the first embodiment of the present application, in the second embodiment of the present application, the same or similar contents as those in the above-mentioned embodiment 1 can be referred to the above introduction, and will not be repeated in the following. Figure 2 Before step S30, the text error correction method further includes steps S201 to S205:
[0096] Step S201, obtaining a historical error correction text dataset;
[0097] It should be noted that before generating a text error correction model, the BERT model and the GAT (Graph Attention Network) model need to be jointly trained to obtain a trained text error correction model.
[0098] It should be noted that the historical error-corrected text data set includes the text data to be corrected and the text correction results. When iteratively training the model, the predicted value can be compared with the actual text correction result to confirm the error and gradually optimize the structure or parameters of the model.
[0099] Step S202, based on a graph neural network, converting the error correction text data set into a first matrix graph;
[0100] It should be noted that the first matrix diagram is similar to the feature matrix diagram, and is used to represent the relationship between various text fragments in the text data with nodes, so as to facilitate the understanding and learning of subsequent models.
[0101] Step S203, based on the BERT model, converting the error correction text data set into first embedded data, and converting the first matrix graph into an initial feature vector;
[0102] It should be noted that the error-correcting text data set is converted into first embedded data through the encoder in the BERT model, wherein the first embedded data is the output data of the encoder.
[0103] It should be noted that the first matrix is initialized by a zero vector to obtain an initial eigenvector, wherein the initial eigenvector can be expressed as: W =(0,0,...,0).
[0104] It should be noted that the purpose of converting the first matrix diagram into the initial feature vector is to reduce the calculation steps of the model, because the word node represents the context around the word, and the feature vectors of other nodes connected to it are also obtained by the BERT model. Therefore, there is no need to calculate the feature vector through the BERT model. At the same time, 0 vector initialization will not affect the generalization ability of the model.
[0105] Step S204, performing prediction processing on the initial feature vector and the first embedded data through a graph attention network to obtain a prediction result;
[0106] It should be noted that after obtaining the initial feature vector and the first embedded data, the first embedded data is processed on the basis of the initial feature vector through the graph attention network layer to obtain the corresponding prediction result.
[0107] Specifically, the BERT encoder is used to convert the input text and graph structure into embedding and initialization. GAT processes the embedding (first embedded data) on the graph structure, then compares the predicted result with the actual result, calculates the value of the loss function, and then calculates the gradient through backpropagation, that is, measures the contribution of each parameter in the entire network to the loss function, to update the model parameters.
[0108] Step S205, comparing the predicted result with the actual result corresponding to the error correction text data set until the preset loss function converges, and then determining the text error correction model.
[0109] It should be noted that the predicted results are compared with the actual results, the value of the loss function is calculated, and then the gradient is calculated through back propagation, that is, the contribution of each parameter in the entire network to the loss function is measured to update the model parameters.
[0110] The first matrix diagram is converted into an initial eigenvector, including:
[0111] Determine a plurality of first characteristic nodes in the first matrix graph;
[0112] It should be noted that the first characteristic node is a matrix node in the first matrix diagram used to represent each word or paragraph.
[0113] Specifically, the Transformer Encoder block in the BERT model obtains the final encoded representation of the input sequence through multiple self-attention and feedforward network operations, where the self-attention mechanism implements the weighted summation of all positions to capture contextual information and relationships. Assuming that the BERT model contains L Transformer Encoder blocks and processes the input sequence X, the output of the L-layer Encoder block can be expressed as:
[0114] L=(L 0 , L 1 , ..., L L )
[0115] Among them, L 0 Represents the input sequence X, L 1 Represents the output of the first layer Encoder block, and so on. LRepresents the output of the last layer of Encoder block. Through deep representation learning of the input sequence by multiple layers of Encoder, the BERT model can extract deep grammatical and semantic information from text information.
[0116] Each first characteristic node is initialized by a zero vector to obtain an initial characteristic vector.
[0117] It should be noted that, in this embodiment, the feature vector of the text data is expressed as:
[0118] X i =f(L 0 , L 1 , ..., L L )
[0119] Among them, X j represents the feature vector of the i-th segment node, f is a mapping function that converts the output L of the multi-layer encoder into the feature representation of each node. For each word node, this application uses a 0 vector for initialization, because the word node represents the context around the word, and the feature vectors of other nodes connected to it are also obtained by the BERT model, so there is no need to calculate the feature vector through the BERT model, and the 0 vector initialization will not affect the generalization ability of the model. The initial feature vector is expressed as:
[0120] X W =(0,0,...,0)
[0121] Among them, X W The feature vector representing the word node is composed of a 0 vector. Therefore, this application implements the feature representation of text segment nodes and word nodes based on the BERT model, laying the foundation for subsequent text error correction tasks.
[0122] Among them, the predicted results are compared with the actual results corresponding to the error correction text dataset until the preset loss function converges, and the text error correction model is determined, including:
[0123] Compare the predicted results with the actual results corresponding to the error correction text dataset, and calculate the first loss function of the BERT model and the second loss function of the graph attention network;
[0124] It should be noted that the first loss function is the loss function in the BERT model, and the second loss function is the loss function in the graph attention network. If the two models are to be jointly trained, the loss functions of the two models must be considered separately, and the model parameters must be tuned according to the output results of the two loss functions.
[0125] Combining the first loss function with the second loss function to obtain a preset loss function;
[0126] It should be noted that the process of combining the two functions can be to add the two loss functions through the weight coefficient, wherein the preset loss function can be a multi-task loss function. The loss function calculated by GAT during the training process of the jointly trained text error correction model may not be able to be reversely updated at the BERT layer when the gradient is reversely updated. Therefore, here we use a multi-task loss function, namely:
[0127] L=Weight_BERT*Loss_BERT+Weight_gat*Loss_gat
[0128] Among them, Weight_BERT represents the weight output by the BERT model, and Loss_BERT is the loss function value output by the BERT model. The multiplication of the two results in Weight_BERT*Loss_BERT, which is the first loss function. Similarly, Weight_gat*Loss_gat represents the second loss function. Weight_gat represents the weight output by the gat model, and Loss_gat is the loss function value output by the gat model.
[0129] Based on the output value of the preset loss function, the model parameters of the neural network in each iteration round are updated until the preset loss function reaches the minimum value, generating a text error correction model.
[0130] It should be noted that during BERT transfer learning, the prediction value and target value generated by it are calculated, and then the data of each round is reversely updated. Similarly, the loss of GAT is calculated in parallel, and then reversely updated at the same time as the loss function of the BERT model. This not only solves the gradient update problem that occurs during the joint training of the two network layers, but also helps the accuracy of the model. The parallel reverse update of the two network layers further improves the training speed of the model. By repeating the previous steps many times, the model is gradually optimized and its accuracy and generalization ability are improved; when the preset loss function reaches the minimum value, the output model weight obtained by the BERT encoder is finally combined with the output model weight of the GAT to obtain the final model weight. The fusion formula is expressed as follows:
[0131] h=[h BERT ;h GAT ]
[0132] Among them, h represents the final model weight; h BERT and h GAT Represent the model weights of BERT encoder and GAT respectively. So far, the iterative training of the text error correction model is completed.
[0133] In this embodiment, the BERT model and the GAT model are jointly trained, and a multi-task loss function is used to perform gradient optimization on the feature vector of the weighted fusion of text embedding obtained by the BERT encoder and GAT to improve the accuracy and performance of text embedding.
[0134] Based on the first embodiment and / or the second embodiment of the present application, in the third embodiment of the present application, the same or similar contents as those of the above-mentioned first and second embodiments can refer to the above introduction, and will not be repeated later. Figure 3 , the text error correction method further includes steps S21-S23:
[0135] Step S21, identifying entity tags in text data, where entity tags include text tags and word tags;
[0136] It should be noted that the text tag can be a paragraph, a short sentence, etc., or other types of text, without any specific limitation.
[0137] It should be noted that the defective label represents a single word or a single character.
[0138] It should be noted that after identifying each entity label in the text data, the node feature matrix and adjacency matrix are constructed according to the word meaning and part of speech.
[0139] Step S22, generating a second feature node and a feature edge in the feature matrix diagram according to each entity label;
[0140] It should be noted that the second feature node is a node in the feature matrix diagram used to represent text.
[0141] It should be noted that the feature edges are used to represent the relationship between nodes, and each edge type represents an independent relationship type.
[0142] Specifically, meaningful entities and relationships in text data are identified, and then based on the category and attributes of the entity and the part of speech of the set Chinese characters, different types of nodes are determined. Each node type represents an independent entity category. In this application, there are two types of node types, text document and word. Then, based on the relationship between entities, different types of edges are determined. Each edge type represents an independent relationship type. In this application, there are two types of edge types (edge-type), document-word and word-word, to describe the relationship between text fragments in the data set. After that, node attributes and labels need to be determined. Each node can have some attributes to describe its characteristics. Attributes are in the form of key-value pairs, which can add more information to the node. For example, for the "Person" node, there can be attributes such as "name", "age", etc. Finally, edge attributes and labels are determined. Each edge can also have some attributes to describe the characteristics of the relationship. For example, some edges can have attributes such as "start_date", "end_date", etc., which represent the time range of member relationships.
[0143] Step S23, connecting each second feature node and feature edge to obtain a feature matrix graph.
[0144] It should be noted that the feature matrix graph includes a node feature matrix and an adjacency matrix. After determining each second feature node and feature edge, two matrices need to be constructed before connecting each node. By defining appropriate types, attributes, labels, and weights on the nodes and edges, the nodes and edges are generated into the following two matrices:
[0145] Specifically, the process of constructing the node feature matrix is as follows:
[0146] The node feature matrix contains the feature representation of the word or document in the graph. Each row represents a node, and each column represents a different dimension of the node feature, as shown below:
[0147] Assume there are N nodes, each node has a D-dimensional feature representation, the node feature matrix X can be expressed as: X = [x_1, x_2, ..., x_N]
[0148] Among them, N represents the number of nodes and represents the feature dimension of each node.
[0149] x_i represents the feature vector of the i-th node, which is a D-dimensional column vector.
[0150] This representation indicates that X is an N×D matrix, where each row represents a node and each column represents a different dimension of node features.
[0151] The process of constructing the adjacency matrix is as follows:
[0152] In order to better highlight the word representation, the weights on the edges are defined in the following way:
[0153] The edge-weights of document-word are defined by Word2Vec, and the edge-weights of word-word are defined by word co-occurrence statistics, which calculates the frequency of two words co-occurring in the same context. The weights of the edges can be set according to their co-occurrence times. The more co-occurrence times, the higher the weight. Finally, a node self-loop is added. The self-loop edge-weights on all nodes are 1, and the edge-weights in other cases are 0. The graph constructed in this way by this application can better describe the semantic relationship between text fragments in the text dataset, thereby further improving the performance and expressiveness of the model.
[0154] In this embodiment, by constructing the text data into a structural diagram, the semantic relationship between text fragments in the text data set can be better described, which makes it easier for the model to handle the correlation between texts when it is subsequently input into the model, further improving the model's recognition and error correction capabilities.
[0155] For example, to help understand the implementation process of the text error correction method obtained by combining this embodiment with the above-mentioned embodiment 1, please refer to Figure 2 , Figure 2 A brief flowchart of a text error correction method is provided, specifically: Figure 2 As shown, the text data is first preprocessed through a graph neural network, and a structure graph is constructed based on features such as word meaning and part of speech to generate a node feature matrix and an adjacency matrix. The BERT model is then used to characterize the semantic features of the text fragment to determine the initial feature vector. Then, the text data is predicted and processed based on the text correction model obtained by joint training of the BERT model and the graph neural network. Thus, the output vector of the BERT encoder and the output vector of the graph convolutional layer are jointly used for text correction to obtain the text correction result.
[0156] It should be noted that the above examples are only used to understand the present application and do not constitute a limitation on the text error correction method of the present application. More simple transformations based on this technical concept are all within the scope of protection of the present application.
[0157] This application also provides a text correction device, please refer to Figure 4 , the text error correction device comprises:
[0158] A first acquisition module 10, used to acquire text data to be corrected;
[0159] The processing module 20 is used to perform a graph construction process on the text data to obtain a feature matrix diagram, and the feature matrix diagram is used to represent the association relationship between each text segment in the text data;
[0160] The error correction processing module 30 is used to perform error correction processing on the feature matrix graph based on a preset text error correction model to obtain a text error correction result, wherein the preset text error correction model is obtained by joint training based on the BERT model and the graph attention network.
[0161] Optionally, the text error correction device further includes:
[0162] The second acquisition module is used to acquire a historical error correction text dataset;
[0163] A first conversion module, used to convert the error correction text data set into a first matrix graph based on a graph neural network;
[0164] A second conversion module is used to convert the error correction text dataset into first embedded data based on the BERT model, and convert the first matrix graph into an initial feature vector;
[0165] A prediction processing module, used to perform prediction processing on the initial feature vector and the first embedded data through a graph attention network to obtain a prediction result;
[0166] The determination module is used to compare the predicted results with the actual results corresponding to the error correction text data set until the preset loss function converges, and then determine the text error correction model.
[0167] Optionally, the determination module includes:
[0168] A comparison unit, used to compare the predicted result with the true result corresponding to the error correction text dataset, and calculate the first loss function of the BERT model and the second loss function of the graph attention network;
[0169] A combining unit, used for combining the first loss function with the second loss function to obtain a preset loss function;
[0170] The updating unit is used to update the model parameters of the neural network in each iteration round based on the output value of the preset loss function until the preset loss function reaches a minimum value, thereby generating a text error correction model.
[0171] Optionally, the second conversion module includes:
[0172] A first determining unit, used to determine a plurality of first characteristic nodes in the first matrix diagram;
[0173] The initialization unit is used to initialize each first characteristic node through a zero vector to obtain an initial characteristic vector.
[0174] Optionally, the processing module includes:
[0175] A recognition unit, used to recognize entity tags in text data, where entity tags include text tags and word tags;
[0176] A generating unit, used for generating a second feature node and a feature edge in the feature matrix diagram according to each entity label;
[0177] The connection unit is used to connect each second feature node and feature edge to obtain a feature matrix graph.
[0178] Optionally, the error correction processing module includes:
[0179] A conversion unit, used for converting the feature matrix graph into embedding layer data based on a preset text error correction model;
[0180] A prediction processing unit, used to perform prediction processing on the embedded layer data on the structure diagram corresponding to the feature matrix diagram to obtain a prediction weight;
[0181] The second determination unit is used to determine the text error correction result based on the text type corresponding to the prediction weight.
[0182] The text error correction device provided by the present application adopts the text error correction method in the above embodiment, which can solve the technical problem of text error correction. Compared with the prior art, the beneficial effects of the text error correction device provided by the present application are the same as the beneficial effects of the text error correction method provided by the above embodiment, and other technical features in the text error correction device are the same as the features disclosed in the above embodiment method, which will not be repeated here.
[0183] The present application provides a text correction device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the text correction method in the above-mentioned embodiment 1.
[0184] Reference below Figure 5 , which shows a schematic diagram of the structure of a text error correction device suitable for implementing the embodiment of the present application. The text error correction device in the embodiment of the present application may include but is not limited to mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 5The text error correction device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0185] like Figure 5 As shown, the text error correction device may include a processing device 1001 (e.g., a central processing unit, a graphics processor, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. In RAM1004, various programs and data required for the operation of the text error correction device are also stored. The processing device 1001, ROM1002, and RAM1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Generally, the following systems can be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touch pad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD: Liquid Crystal Display), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 can allow the text correction device to communicate with other devices wirelessly or by wire to exchange data. Although the text correction device with various systems is shown in the figure, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems can be implemented or have alternatively.
[0186] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.
[0187] The text error correction device provided by the present application adopts the text error correction method in the above embodiment to solve the technical problem of text error correction. Compared with the prior art, the beneficial effects of the text error correction device provided by the present application are the same as the beneficial effects of the text error correction method provided by the above embodiment, and the other technical features in the text error correction device are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.
[0188] It should be understood that the various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.
[0189] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
[0190] The present application provides a computer-readable storage medium having computer-readable program instructions (ie, computer programs) stored thereon, wherein the computer-readable program instructions are used to execute the text error correction method in the above-mentioned embodiment.
[0191] The computer-readable storage medium provided in the present application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, systems or devices, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, system or device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination of the above.
[0192] The computer-readable storage medium may be included in the text correction device; or may exist independently without being assembled into the text correction device.
[0193] The computer-readable storage medium carries one or more programs. When the one or more programs are executed by the text correction device, the text correction device can perform text correction.
[0194] Computer program code for performing the operations of the present application may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0195] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0196] The modules involved in the embodiments described in this application may be implemented by software or hardware, wherein the name of the module does not constitute a limitation on the unit itself in some cases.
[0197] The readable storage medium provided by the present application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned text error correction method, and can solve the technical problem of text error correction. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided by the present application are the same as the beneficial effects of the text error correction method provided by the above-mentioned embodiment, and will not be repeated here.
[0198] The present application also provides a computer program product, including a computer program, which implements the steps of the above-mentioned text error correction method when executed by a processor.
[0199] The computer program product provided by the present application can solve the technical problem of text error correction. Compared with the prior art, the beneficial effects of the computer program product provided by the present application are the same as the beneficial effects of the text error correction method provided by the above embodiment, which will not be repeated here.
[0200] The above descriptions are only some embodiments of the present application, and are not intended to limit the patent scope of the present application. All equivalent structural changes made using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect applications in other related technical fields are included in the patent protection scope of the present application.
Claims
1. A text error correction method, characterized in that: The text error correction method comprises: Obtaining text data to be corrected; Performing a graph construction process on the text data to obtain a feature matrix diagram, wherein the feature matrix diagram is used to characterize the association relationship between various text segments in the text data; Based on a preset text error correction model, the feature matrix graph is corrected to obtain a text error correction result, wherein the preset text error correction model is obtained by joint training based on a BERT model and a graph attention network.
2. The method according to claim 1, characterized in that Before the error correction processing is performed on the feature matrix diagram based on the preset text error correction model to obtain the text error correction result, the method further includes: Obtain historical error-corrected text datasets; Based on the graph neural network, converting the error correction text data set into a first matrix graph; Based on the BERT model, converting the error correction text dataset into first embedded data, and converting the first matrix graph into an initial feature vector; Performing prediction processing on the initial feature vector and the first embedded data through the graph attention network to obtain a prediction result; The predicted result is compared with the actual result corresponding to the error correction text data set until the preset loss function converges, and then the text error correction model is determined.
3. The method according to claim 2, characterized in that The step of comparing the predicted result with the actual result corresponding to the error correction text data set until a preset loss function converges, and determining a text error correction model comprises: Compare the predicted result with the true result corresponding to the error correction text dataset, and calculate the first loss function of the BERT model and the second loss function of the graph attention network; Combining the first loss function with the second loss function to obtain a preset loss function; Based on the output value of the preset loss function, the model parameters of the neural network in each iteration round are updated until the preset loss function reaches a minimum value, thereby generating a text error correction model.
4. The method according to claim 2, characterized in that The converting the first matrix graph into an initial eigenvector comprises: Determine a plurality of first characteristic nodes in the first matrix diagram; Each of the first characteristic nodes is initialized by a zero vector to obtain an initial characteristic vector.
5. The method according to claim 1, characterized in that The step of performing a graph construction process on the text data to obtain a feature matrix graph includes: Identify entity tags in the text data, wherein the entity tags include text tags and word tags; According to each of the entity labels, generating a second feature node and a feature edge in a feature matrix graph; The second feature nodes and feature edges are connected to obtain a feature matrix graph.
6. The method according to claim 1, characterized in that The error correction process is performed on the feature matrix diagram based on the preset text error correction model to obtain the text error correction result, including: Based on a preset text error correction model, converting the feature matrix graph into embedding layer data; Performing prediction processing on the embedded layer data on the structure diagram corresponding to the feature matrix diagram to obtain a prediction weight; Based on the text type corresponding to the prediction weight, a text error correction result is determined.
7. A text error correction device, characterized in that: The device comprises: A first acquisition module, used to acquire text data to be corrected; A processing module, used for performing a graph construction process on the text data to obtain a feature matrix diagram, wherein the feature matrix diagram is used to characterize the association relationship between various text segments in the text data; The error correction processing module is used to perform error correction processing on the feature matrix graph based on a preset text error correction model to obtain a text error correction result, wherein the preset text error correction model is obtained by joint training based on the BERT model and the graph attention network.
8. A text error correction device, characterized in that: The device comprises: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the text error correction method according to any one of claims 1 to 6.
9. A storage medium, characterized in that: The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the text error correction method according to any one of claims 1 to 6 are implemented.
10. A computer program product, characterized in that The computer program product comprises a computer program, and when the computer program is executed by a processor, the steps of the text error correction method according to any one of claims 1 to 6 are implemented.
