A Chinese text grammatical error location method, system, device and medium

By adopting the dynamic word vector representation method in locating grammatical errors in Chinese text, using BERT and BiLSTM layers to extract features, and constructing a grammatical error database, the problems of low accuracy and inaccurate word vector representation in the existing technology are solved, and high accuracy is achieved Degree of grammatical error location and correction.

CN114896966BActive Publication Date: 2024-09-06XI AN JIAOTONG UNIV
View PDF 8 Cites 0 Cited by

Patent Information

Application Number
CN202210536619.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-05-17
Publication Date
2024-09-06
Estimated Expiration
2042-05-17

AI Technical Summary

Technical Problem

The existing technology has low accuracy in locating and correcting grammatical errors in Chinese texts, and Chinese word vectors are inaccurate in representing sentences with grammatical errors, resulting in high system complexity and difficulty in global optimization.

Method used

A Chinese text grammatical error localization method based on dynamic word vector representation is used, using the pre-trained BERT layer and BiLSTM layer, combined with a large-scale Chinese character pre-training model, to dynamically extract the features of the sentence, output the location of the grammatical error, and build a grammatical error database to Improve accuracy.

Benefits of technology

It has significantly improved the accuracy of locating grammatical errors in Chinese texts, and can accurately identify and locate grammatical errors in sentences, reducing the cost and complexity of manual review.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114896966B
    Figure CN114896966B
Patent Text Reader

Abstract

The present invention discloses a method, system, device and medium for locating grammatical errors in Chinese text, wherein the locating method comprises the following steps: obtaining a Chinese text to be located for grammatical errors and processing it to obtain a Chinese text that meets a preset length requirement; based on the Chinese text that meets the preset length requirement, grammatical errors are located using a pre-trained text grammatical error location model, and a grammatical error location result matrix is ​​output; wherein the text grammatical error location model comprises: an input layer, a BERT layer, a BiLSTM layer, a fully connected layer and an output layer. The Chinese text grammatical error location method provided by the present invention is specifically a Chinese text grammatical error location method based on dynamic word vector representation, which can point out the location of grammatical errors in Chinese sentences; compared with the GEC task, the accuracy rate can be significantly improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of natural language processing sequence annotation, and in particular relates to a method, system, device and medium for locating grammatical errors in Chinese text. Background Art

[0002] With the popularization and development of Internet technology, electronic text data has increased dramatically. Due to the users' randomness in using text input methods and voice input methods, and the lack of subsequent review, grammatical errors are easily generated. In recent years, with the boom of self-media, everyone is a producer of information. The exponential growth of text has caused a decline in text quality, resulting in inaccurate meanings conveyed by sentences, and even misunderstandings. An analysis shows that the grammatical error rate of Chinese online news titles and texts exceeds 1%. These incoherent texts have greatly affected the user experience.

[0003] According to statistics, common types of grammatical errors in Chinese sentences include: repetition, inappropriate words, inappropriate collocation, incomplete components and typos; taking the input "Life is like the ocean, only those with strong will can reach the other side" as an example, the possible error types are shown in Table 1.

[0004] Table 1. Syntax error types

[0005]

[0006] The traditional manual review method for screening grammatically incorrect sentences not only consumes a lot of manpower and time costs, but also has great subjectivity and inaccuracy. Therefore, it is unrealistic to conduct manual review and evaluation. In order to solve the problem of grammatical errors in Chinese sentences, the research on using computers to locate grammatical errors in sentences has emerged. Compared with manual feedback, using computers to judge grammatically incorrect sentences has the advantages of being more objective and timely.

[0007] In the early days, the use of computers to judge grammatically incorrect sentences was mainly based on rules and statistics. In the recognition of grammatically incorrect sentences based on rules, the human language rules formulated by linguists are first analyzed (for example, declarative sentences in Chinese sentences are composed of subject, predicate and object, and attributive modifiers need to be added in front of nouns, etc.) After formulating a series of rules, the natural language processing technology is used to analyze the various components of the sentence, and then match the rule template; if the sentence to be judged is not within the listed rules, the sentence is judged to be a grammatically incorrect sentence. However, the rule-based grammatical error judgment method requires summarizing language rules, and it is difficult to establish perfect language rules. There is also a lack of relevant linguistic knowledge, and there are problems such as too simple judgment mechanism, unsatisfactory results, and inability to find the specific location of grammatical errors in sentences. In the recognition of grammatically incorrect sentences based on statistics, the N-gram language model is mostly used; the language model takes a sequence that conforms to the language rules as input, and the model uses features such as the relationship between sequences to output a probability distribution over all words; the more a sentence conforms to the natural language rules of humans, the greater the output probability will be. This output probability can be used to judge whether a sentence has grammatical errors. Since the N-gram statistical language model is based on the Markov hypothesis and uses limited historical information, it is highly efficient. However, the N-gram model cannot reflect text similarity and cannot associate with earlier text information. Therefore, it is limited in its ability to determine whether a sentence has grammatical errors and has an accuracy bottleneck. In addition, it is also unable to find the specific location of the grammatical error in the sentence.

[0008] In recent years, with the development of deep learning, there are many methods that use deep learning to analyze Chinese grammatical errors, and the research on grammatical error correction (GEC) has emerged; GEC can automatically detect errors in grammatical incoherence in sentences, and then correct the detected errors, thereby reducing the cost of manual verification. The method of GEC task is generally a pipeline method, including: error detection, candidate recall and candidate sorting; first, the long short-term memory network (Long Short-Term Memory, LSTM) and conditional random field (Conditional Random Field, CRF) are used to detect the error position and error type in the sentence, and then the correct segment candidates are recalled for the detected error position, and finally based on the morphology, morphology, semantics or user behavior, combined with the current error point context representation, error correction sorting is performed. With the outstanding effect of neural network machine translation methods such as seq2seq on text generation, the academic community has adopted more end-to-end methods to generate correct sentences, using generative models to directly use incorrect text to generate correct text.

[0009] Based on the above statements, we can see that treating grammatically incorrect sentences as GEC tasks can not only identify whether the sentences have grammatical errors, but also obtain correct sentences after correction; however, there are still many shortcomings in using the GEC method to analyze grammatical errors in Chinese sentences, mainly manifested in:

[0010] (1) The accuracy of text grammatical error correction tasks is not high; the task of text grammatical error correction is interpretative and requires taking into account three tasks: grammatical error judgment, grammatical error location, and grammatical error correction, which makes the task difficult;

[0011] (2) Using Chinese word vectors on grammatically incorrect sentences will lead to inaccurate sentence representation. Explanatory wise, Chinese word vectors are first segmented into "words" units, but the Chinese word segmentation system and word vector training are all trained on clean corpus. Using grammatically incorrect sentences will lead to many incorrect segmentations, and the resulting errors will be more difficult to handle. At the same time, word-based models usually utilize many sub-modules and need to process many special examples, which leads to high system complexity and difficulty in global optimization. Summary of the invention

[0012] The purpose of the present invention is to provide a method, system, device and medium for locating grammatical errors in Chinese text to solve one or more of the above-mentioned technical problems. The method for locating grammatical errors in Chinese text provided by the present invention is specifically a method for locating grammatical errors in Chinese text based on dynamic word vector representation, which can point out the location of grammatical errors in Chinese sentences; compared with the GEC task, it can significantly improve the accuracy.

[0013] In order to achieve the above object, the present invention adopts the following technical solutions:

[0014] A first aspect of the present invention provides a method for locating grammatical errors in Chinese text, comprising the following steps:

[0015] Acquire and process the Chinese text to be located for grammatical errors to obtain a Chinese text that meets a preset length requirement;

[0016] Based on the Chinese text that meets the preset length requirement, grammatical error location is performed using a pre-trained text grammatical error location model, and a grammatical error location result matrix is ​​output;

[0017] Wherein, the text grammatical error location model includes:

[0018] The input layer is used to input Chinese text that meets the preset length requirement, convert each character in the Chinese text into a sequence matrix and output it;

[0019] The BERT layer is used to input the sequence matrix output by the input layer, convert it into a word vector matrix and output it;

[0020] A BiLSTM layer, used for inputting the word vector matrix and performing feature extraction, and outputting a text context feature vector;

[0021] A fully connected layer, used to input the text context feature vector, perform matrix operations and rounding, and output a positioning result vector;

[0022] The output layer is used to input the positioning result vector and output the syntax error positioning result matrix.

[0023] A further improvement of the method of the present invention is that the step of obtaining the pre-trained text grammatical error location model comprises:

[0024] Acquire a training sample set; each training sample in the training sample set includes a Chinese text sample that meets a preset length requirement and a corresponding grammatical error location result matrix;

[0025] During training update, Chinese text samples that meet the preset length requirements in the selected training samples are input into the text grammatical error localization model to obtain a grammatical error localization result prediction matrix; the difference between the grammatical error localization result prediction matrix and the grammatical error localization result matrix in the selected training samples is calculated, and the loss is calculated using the mean square error loss function and the parameters of the text grammatical error localization model are updated to achieve the preset convergence conditions and obtain the pre-trained text grammatical error localization model.

[0026] A further improvement of the method of the present invention is that the step of obtaining a training sample set specifically includes:

[0027] Based on the preset Chinese sentence grammatical error types and combined with the NLPCC 2018 Chinese grammatical error correction shared task training set, a grammatical error sentence database is constructed using a rule-based method; wherein the preset Chinese sentence grammatical error types include one or more of repetition and redundancy, inappropriate wording, inappropriate collocation, incomplete components and the presence of typos.

[0028] A further improvement of the method of the present invention is that the grammatical errors in the grammatical error sentence database include one or more of reduplication of characters, reduplication of words, reduplication of pronunciations, extra characters, fewer characters, fewer words, confusion, wrong characters, wrong homophones, wrong homophones and incorrect spelling in pinyin.

[0029] A second aspect of the present invention provides a Chinese text grammatical error location system, comprising:

[0030] A text acquisition module is used to acquire and process the Chinese text to be located for grammatical errors, and obtain the Chinese text that meets the preset length requirement;

[0031] A result acquisition module is used to perform grammatical error location based on the Chinese text that meets the preset length requirement using a pre-trained text grammatical error location model, and output a grammatical error location result matrix;

[0032] Wherein, the text grammatical error location model includes:

[0033] The input layer is used to input Chinese text that meets the preset length requirement, convert each character in the Chinese text into a sequence matrix and output it;

[0034] The BERT layer is used to input the sequence matrix output by the input layer, convert it into a word vector matrix and output it;

[0035] A BiLSTM layer, used for inputting the word vector matrix and performing feature extraction, and outputting a text context feature vector;

[0036] A fully connected layer, used to input the text context feature vector, perform matrix operations and rounding, and output a positioning result vector;

[0037] The output layer is used to input the positioning result vector and output the syntax error positioning result matrix.

[0038] A further improvement of the system of the present invention is that the step of obtaining the pre-trained text grammatical error location model includes:

[0039] Acquire a training sample set; each training sample in the training sample set includes a Chinese text sample that meets a preset length requirement and a corresponding grammatical error location result matrix;

[0040] During training update, Chinese text samples that meet the preset length requirements in the selected training samples are input into the text grammatical error localization model to obtain a grammatical error localization result prediction matrix; the difference between the grammatical error localization result prediction matrix and the grammatical error localization result matrix in the selected training samples is calculated, and the loss is calculated using the mean square error loss function and the parameters of the text grammatical error localization model are updated to achieve the preset convergence conditions and obtain the pre-trained text grammatical error localization model.

[0041] A further improvement of the system of the present invention is that the step of obtaining a training sample set specifically includes:

[0042] Based on the preset Chinese sentence grammatical error types and combined with the NLPCC 2018 Chinese grammatical error correction shared task training set, a grammatical error sentence database is constructed using a rule-based method; wherein the preset Chinese sentence grammatical error types include one or more of repetition and redundancy, inappropriate wording, inappropriate collocation, incomplete components and the presence of typos.

[0043] A further improvement of the system of the present invention is that the grammatical errors in the grammatical error sentence database include one or more of reduplication of characters, reduplication of words, reduplication of pronunciations, extra characters, fewer characters, fewer words, confusion, wrong characters, wrong homophones, wrong homophones and incorrect writing in pinyin.

[0044] A third aspect of the present invention provides an electronic device, comprising:

[0045] at least one processor; and,

[0046] a memory communicatively connected to the at least one processor; wherein,

[0047] 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 any of the above-mentioned methods for locating grammatical errors in Chinese texts according to the present invention.

[0048] A fourth aspect of the present invention provides a computer-readable storage medium storing a computer program, wherein the computer program, when executed by a processor, implements any one of the above-mentioned methods for locating grammatical errors in Chinese texts of the present invention.

[0049] Compared with the prior art, the present invention has the following beneficial effects:

[0050] The Chinese text grammatical error location method provided by the present invention is specifically a Chinese text grammatical error location method based on dynamic word vector representation, which can point out the location of grammatical errors in Chinese sentences; compared with the GEC task, the accuracy rate can be significantly improved. Specifically, in order to solve the problem that using Chinese word vectors on grammatically incorrect sentences will lead to inaccurate sentence representation, the text grammatical error location model proposed by the present invention is provided with a BERT layer and a BiLSTM layer, a model training method of dynamic word vectors is introduced, and a large-scale Chinese character pre-training model is used in the training process. A bidirectional long short-term memory network is connected after the pre-training model, and the context information of the characters is used to extract the features of the sentence, and finally the location of the grammatical error of the sentence is output.

[0051] According to the types of grammatical errors in Chinese sentences, the present invention constructs a database of grammatically incorrect sentences, which includes correct sentences, grammatically incorrect sentences, the positions of grammatical errors in sentences, and the types of grammatical errors. Specifically to address the problem of low accuracy in text grammatical error correction tasks, the present invention proposes a recognition method for locating text grammatical errors, which can ultimately achieve the goal of inputting a grammatically incorrect sentence and outputting the position of the grammatical error in the sentence. Compared with the GEC task, the accuracy has been further significantly improved. BRIEF DESCRIPTION OF THE DRAWINGS

[0052] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art; obviously, the drawings described below are some embodiments of the present invention, and for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0053] Figure 1 It is a flowchart of a method for locating grammatical errors in Chinese text according to an embodiment of the present invention;

[0054] Figure 2 1 is a schematic diagram of a neural network structure of a Chinese text grammatical error location model based on dynamic word vector representation in an embodiment of the present invention;

[0055] Figure 3 1 is a schematic diagram of the structure of a BERT model in an embodiment of the present invention;

[0056] Figure 4 Schematic diagram of the unit structure of the hidden layer of the bidirectional long-short cycle memory network in an embodiment of the present invention. DETAILED DESCRIPTION

[0057] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.

[0058] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0059] The present invention is further described in detail below in conjunction with the accompanying drawings:

[0060] See also Figure 1A Chinese text grammatical error location method according to an embodiment of the present invention, specifically a Chinese text grammatical error location method based on dynamic word vector representation, is designed to provide a Chinese text grammatical error location model, which can input a Chinese sentence and finally give the location of the grammatical error in the sentence; illustratively, if the sentence has no grammatical error, the output position is 0.

[0061] The syntax error location process implemented by the present invention is as follows: Figure 1 As shown, it includes the pre-training process of the model and the location prediction process of the sentence grammatical error position, which specifically includes:

[0062] First, according to the common types of grammatical errors in Chinese sentences, combined with the NLPCC 2018 Chinese grammatical error correction shared task training set, a grammatical error sentence database is constructed using a rule-based method. The database contains correct sentences, grammatical error sentences, the location of grammatical errors in sentences, and the types of grammatical errors, which can be used for deep neural network model training. In the training process of the text grammatical error location model, the sentence database is first preprocessed, and then the BERT (Bidirectional Encoder Representation from Transformers) layer converts each word in the processed text into a one-dimensional vector by querying the word vector as the model input. In addition, the model input also includes text vectors and position vectors. The output of the BERT layer is the vector representation of the input word corresponding to the fusion of the full-text semantic information; the trained word vector is then input into the bidirectional long short-term memory network layer for feature extraction. At the end of the model, a fully connected layer is used to map the outputs of multiple neurons to a (0, 1) interval of the same length as the input sequence for sequence labeling, and then the Sigmoid activation function is used and rounding is performed. If the output position is marked as 1, it means there is a grammatical error at that position. If the output position is marked as 0, it means there is no grammatical error at that position. Finally, the structure and parameters of the trained word vector model, feature extraction network model and sequence labeling linear layer model are saved for model prediction.

[0063] In the process of locating grammatical errors in Chinese text, that is, the model prediction process, the Chinese text to be located is first preprocessed, and then the word vector model saved in the training process is used to represent the input sentence with a word vector. The word vector of the text is input into the trained model for feature extraction, and the last layer of the model outputs the incoherent position of the sentence.

[0064] In an exemplary embodiment of the present invention, the construction of a data set, the training of a model and the prediction process specifically include:

[0065] (1) Construction of a grammatically incorrect text dataset, including:

[0066] According to the common types of grammatical errors in Chinese sentences, the present invention combines the NLPCC 2018 Chinese grammatical error correction shared task training set, and uses a rule-based method to construct a grammatical error sentence database. Among them, the types of common grammatical errors in Chinese sentences include: repetition and redundancy, inappropriate wording, inappropriate collocation, incomplete components, and the presence of typos. Therefore, the present invention constructs 11 grammatical errors, including reduplication, reduplication, reduplication, multiple common characters, few characters, few words, confusion, wrong common characters, wrong homophones, wrong homophones, and wrong writing in pinyin. Taking the input "He wants to go to Beijing to visit his grandmother tomorrow" as an example, the constructed grammatical error sentence types and ratios are shown in Table 2.

[0067] Table 2. Types and proportions of grammatically incorrect sentences in the database

[0068]

[0069] In Table 2, the error type indicates the type of grammatical error in the Chinese sentence; the selection probability indicates the proportion of grammatical error sentences of this type; the error position uses a one-dimensional matrix to mark the position of the grammatical error in the sentence, 1 indicates that there is a grammatical error at this position, and 0 indicates that there is no grammatical error at this position. The label indicates whether the sentence has a grammatical error.

[0070] The construction process of repeated words and missing words is as follows: use the random() function in the python library to randomly select a word in the sentence, and then repeatedly add this word (repeated word) or delete the selected word (missing word) after the selected word.

[0071] The construction process of reduplicated words and fewer words is as follows: use the functions in the jieba library to segment the sentence, then use the random() function to randomly select a word in the sentence, and repeat adding this word (reduplicated words) or deleting the selected word (few words) after the selected word.

[0072] The construction process of the chaos error type is: use the function in the jieba library to segment the sentence, then use the random() function to randomly select two words in the sentence and swap the positions of the two words in the sentence.

[0073] The construction process of the wrong type written in pinyin is: use the random() function in the python library to randomly select a word in the sentence, convert the selected Chinese character into pinyin using the function in the Pinyin2Hanzi library, and then replace the Chinese characters in the original sentence with pinyin. The construction process of sentences with reduplicated sounds, wrong homophones, and wrong homophones is: use the random() function to randomly select a word (reduplicated sounds, wrong homophones) in the sentence or select a word (wrong homophone) after jieba word segmentation, first use the function in the Pinyin2Hanzi library to convert the word or word into pinyin, then convert the pinyin into Chinese characters different from the original sentence, and finally modify the sentence according to the rules.

[0074] The construction process of sentences with multiple common characters and incorrect common characters is as follows: first count the 1000 Chinese characters that appear most frequently in all sentences, use these Chinese characters as the common character list, and then randomly select a Chinese character from the common character list to add to a random position in the original sentence (multiple common characters) or replace a Chinese character in a random position in the original sentence (incorrect common characters).

[0075] The grammatically correct sentences used to construct the database come from the NLPCC 2018 Chinese grammatical error correction shared task dataset and the primary school students' excellent composition dataset. Each dataset takes 200,000 grammatically correct sentences, totaling 400,000. According to the above method, noise is added to the 400,000 grammatically correct sentences to construct a grammatically incorrect sentence database. There are 24,199 examples of reduplication, 11,875 examples of reduplication, 23,641 sentences of reduplication, 24,041 sentences of many common characters, 35,935 sentences with few characters, 36,028 sentences with few words, 48,071 chaotic sentences, 47,767 sentences with wrong common characters, 47,506 sentences with wrong homophones, 23,072 sentences with wrong homophones, and 35,956 sentences written in pinyin.

[0076] (2) Construction of grammatical error location model, including:

[0077] The model structure for locating text grammatical errors is as follows: Figure 2As shown. The BERT (Bidirectional Encoder Representation from Transformers) layer based on dynamic word vectors is used to convert each word in the text into a one-dimensional vector as the input of the model. At the same time, the input of the model also includes two parts: text vector and position vector. In order to adapt to the input length limit of the BERT model, each sentence is padded by analyzing the maximum length of the sentence in the database, that is, if the length of the sentence M is less than N, 0 is added after the sentence, and if the length of the sentence M is greater than N, the sentence is divided into shorter sentences. The output of the BERT model is the vector representation of the semantic information of the whole text corresponding to each input word. The output of BERT is connected to the bidirectional long short-term memory (BiLSTM) network to extract the features of Chinese sentences. The output of the BiLSTM neuron is connected to the fully connected layer and mapped to the (0, 1) interval of the same length as the input sequence for sequence labeling. Then the Sigmoid activation function is used and rounding is performed. If the output position is marked as 1, it means that there is a grammatical error at that position. If the output position is marked as 0, it means that there is no grammatical error at that position.

[0078] In the embodiment of the present invention, the BERT layer is introduced as a pre-trained model to represent text word vectors in order to solve the problem that using Chinese word vectors on grammatically incorrect sentences will lead to inaccurate sentence representation. Because Chinese word vectors are segmented in units of "words", word vectors are trained on clean corpus. Using grammatically incorrect sentences will lead to many incorrect segmentations, and the resulting errors will be more difficult to handle. The network architecture of BERT uses a multi-layer Transformer structure. The overall structure is as follows: Figure 3 As shown in the figure, BERT mainly uses the Transformer Encoder instead of the Decoder. Multiple Transformer Encoders are stacked together to form BERT.

[0079] The biggest feature of BERT is that it abandons the traditional recurrent neural network (RNN) and convolutional neural network (CNN), and converts the distance between two words at any position into an attention matrix through the Attention mechanism, effectively solving the thorny long-term dependency problem in natural language processing. As a large-scale pre-training model, BERT is not related to specific natural language processing tasks. Its goal is to learn what the language itself should be like. The pre-training process of BERT is to gradually adjust the model parameters so that the text semantic representation output by the model can depict the essence of the language, which is convenient for subsequent fine-tuning for specific natural language processing tasks. In order to better use text context information, BERT also uses the multi-task training objectives of Mask Language Model and Next Sentence Prediction for network training.

[0080] The BERT layer converts each word in the padded text into a one-dimensional vector by querying the word vector table as the model input; the model output is the vector representation of each word after integrating the semantic information of the entire text. In addition, in addition to the word vector, the model input also includes two parts: the text vector and the position vector. The value of the text vector is automatically learned during the model training process, and is used to characterize the global semantic information of the text and integrate it with the semantic information of a single word. Since the semantic information carried by words appearing at different positions in the text is different, the BERT layer attaches a different vector to the words at different positions to distinguish them. Finally, the BERT layer uses the sum of the word vector, text vector, and position vector as the model input.

[0081] In the embodiment of the present invention, BiLSTM is a typical structure in a recurrent neural network (RNN). Simple RNN can theoretically establish dependencies between states at long time intervals, but due to the gradient explosion or vanishing problem, it can actually only learn short-term dependencies, while LSTM can well alleviate the gradient vanishing and gradient explosion problems. However, LSTM can only predict the output of the next moment based on the time series information of the previous moment, while BiLSTM uses the information before the input sequence and after the input sequence, and extracts the feature indicators of the composition in combination with the contextual information of the words, which can better mine the dependency relationship of the text.

[0082] like Figure 4 The figure shows the structure of a single BiLSTM unit. The BiLSTM network uses twice the number of hidden layer units compared to LSTM to process data bidirectionally. A single BiLSTM hidden layer contains three gates: Γ u ,Γ f,Γ o , respectively update gate, forget gate and output gate. The corresponding expression is,

[0083]

[0084] Among them, W c ,W f ,W u ,W o ,b c ,b f ,b u ,b o are the parameters to be learned, σ represents the sigmoid activation function, tanh represents the hyperbolic tangent function, and * represents the product of the corresponding elements of the matrix or vector. The forget gate determines what information to discard from the neuron state. It looks at a <t-1>< / t-1> (previous hidden state) and x <t>< / t> (current input), and is state c <t-1>< / t-1> Each number in outputs a number between 0 and 1; the Sigmoid layer of the input gate determines which values ​​will be updated; then, a Tanh layer creates the candidate vector c <t>< / t> , this vector will be added to the state of the neuron; combining these two vectors, the value of the forget gate and the input gate determines how much new and old information to remember: the previous state value c <t-1>< / t-1> Multiply by Γ f , which expresses the part you want to forget. Add the obtained value to Γ u Multiply Get the new state value. Finally, the output gate decides what to output, and the final output state a <t>< / t> After the Softmax function, we can get the output y <t>< / t> .

[0085] In the embodiment of the present invention, a Dense layer is introduced to implement sequence labeling, and finally the incoherent positions in the text sentence are output. Connect to the Dense layer, the number of input neurons in the Dense layer is 2N, and the number of output neurons is M. Among them, N represents the number of neurons in the forward or backward long short cycle memory network in the BiLSTM network; M represents the length of the input text, and the output value of each position is converted to a value in the [0,1] interval through the Sigmoid activation function and rounded. In the result, 0 represents no grammatical error at the position, and 1 represents a grammatical error at the position.

[0086] In the embodiment of the present invention, the optimization algorithm and the evaluation index include: the optimization algorithm refers to a method for adjusting the model parameters in the process of learning the model. For the neural network model, the optimization method currently used is mainly based on the gradient descent method, mainly including stochastic gradient descent (SGD), momentum method (Momentum), adaptive gradient descent algorithm (AdaGrad), AdaDelta method and adaptive momentum method (Adaptive Moments, Adam) and the like. Adam is an adaptive learning method, which uses the first-order moment estimation and second-order moment estimation of the gradient to dynamically adjust the learning rate of each parameter. The present invention adopts the Adam algorithm. The evaluation index refers to an index for evaluating the quality of the model. The present invention uses the accuracy rate (a_accuracy) to measure the accuracy of the model in locating grammatical errors in Chinese text. When the grammatical error position predicted by the model is exactly the same as the sample position in the training set, it is considered to be predicted correctly. At the same time, considering that the task of locating grammatical errors in Chinese sentences has high requirements for local features, the accurate position determined by using sequence annotation is usually offset, and there is a situation where the position of a grammatical error in a sentence is uncertain. Therefore, in addition to defining the above absolute accuracy (a_accuracy), the relative accuracy is also used to judge the model, that is, a convolution operation is added after the output of the model. When evaluating the model, as long as the incoherent position falls into a certain window, it is considered to be accurate. The window sizes used are 3, 5, and 9, respectively, and the corresponding accuracy rates are recorded as b_accuracy, c_accuracy, and d_accuracy, respectively. Table 3 shows an example of the evaluation results of grammatically incorrect statements when the window size is 3.

[0087] Table 3. Example of evaluation results for grammatically incorrect statements when the window size is 3

[0088]

[0089] During the model training process, the sentences in the database are first padded according to the length N. If the length of the sentence M is less than N, 0 is added to the end of the sentence. If the length of the sentence M is greater than N, the sentence is divided into shorter sentences. The model inputs the sentence into the BERT model to convert each word in the sentence into three parts: word vector, text vector and position vector, and outputs it as a word vector matrix. The word vector matrix is ​​then input into the BiLSTM layer for feature extraction, and finally the Dense layer outputs the probability of grammatical errors at each position in the text. The model reduces the loss value of the loss function based on the gradient descent method, and then dynamically adjusts the word vector parameters and model parameters, ultimately achieving the purpose of improving the model's grammatical error location performance indicators.

[0090] In the prediction process of the model, that is, in the process of processing the sentence to be judged, the sentence is first padded and then input into the prediction model. The model automatically passes through the BERT layer, BiLSTM layer, and Dense layer, and finally outputs a sequence of 0 and 1 of the same length as the input. In the sequence, 1 represents a grammatical error at that position, and 0 represents no grammatical error at that position, thus completing the task of locating the grammatical error.

[0091] In the experimental design and result analysis in the embodiment of the present invention, a Chinese text grammatical error location experiment based on dynamic word vector representation was carried out to verify the effectiveness and accuracy of this method in locating and identifying grammatical errors in Chinese text. The experimental environment is: Intel (R) Core (TM) i5-10500 CPU @ 3.10GHz 3.10GHz processor, 16.0GB memory, GPU NVIDIA GeForce GTX 3080Ti, video memory 12.0GB, Windows 10 system 64-bit. The experimental software is JupyterNotebook, the deep learning framework uses TensorFlow2.4.1, the CUDA version is 11.1.0, and the corresponding CUDNN version is 8.0.4. The Python function library and version used in the experiment are shown in Table 4.

[0092] Table 4. Python library names and versions

[0093]

[0094] The selection and processing of the data set include: the data used in the embodiment of the present invention are the NLPCC2018 Chinese grammatical error correction shared task data set and the essays of primary school students from grades one to six, 200,000 of each, and a total of 400,000. According to the rules, noise is added to 400,000 grammatically correct sentences to construct a grammatically incorrect sentence database. There are 24,199 examples of reduplication type, 11,875 examples of reduplication type, 23,641 sentences of reduplication type, 24,041 sentences of multiple common characters type, 35,935 sentences with few characters, 36,028 sentences with few words, 48,071 sentences of confusion type, 47,767 sentences with wrong common characters, 47,506 sentences with wrong homophones, 23,072 sentences with wrong homophones, and 35,956 sentences written in pinyin. Finally, the processed data set is stored in a TXT document.

[0095] The BERT model uses BERT-Chinese-base, which contains 12 Transformer layers, 768 hidden layer units, 12 self-attention heads, and a total of about 110 million parameters. The input sequence length is 36. Through the padding operation, when the sentence length is less than 36, 0 is added to the end of the sentence to make it reach a length of 36. When the sentence length is greater than 36, the sentence is divided into punctuation marks with a length of less than 36, and then padding is performed. The number of single LSTM neurons in the BiLSTM layer is 128, and the entire BiLSTM layer has a total of about 900,000 parameters. The activation function of the Dense layer uses the 'Sigmiod' function, with a total of about 9,000 parameters. The configuration of the Chinese text grammatical error location model is shown in Table 5.

[0096] Table 5. Model structure parameters

[0097]

[0098] According to the above parameters, the network is set up and the text grammatical error location model is constructed. 95% of the data in the data set is used as the training set to train the network. After the model training is completed, 5% of the data in the data set is used as the test set to test the model. The evaluation index values ​​of the model on the test set are shown in Table 6. As can be seen from the table, the Chinese text grammatical error location model based on dynamic word vector representation is used to identify the location of grammatical errors in sentences, and the absolute accuracy can reach 75.96%. Considering that the accurate location is usually offset, and there is a situation where the location of a grammatical error in a sentence is uncertain, the accuracy of the model is evaluated by using window convolution. When the window size is 3, 5, and 9, the accuracy can reach 84.35%, 85.59%, and 87.01% respectively.

[0099] The following conclusions can be drawn from the experimental results of the embodiments of the invention:

[0100] (1) The Chinese text grammatical error localization model based on dynamic word vector representation is used to identify the location of grammatical errors in sentences with high accuracy, especially when the location window is expanded from 1 to 3, the accuracy reaches 84.35%.

[0101] (2) From the optimization of the syntax error location model, it can be seen that as the window size increases, the location accuracy increases. In particular, when the window size increases from 1 to 3, the accuracy rate increases the most, by 8.39%. However, when the window size increases further, the accuracy rate does not increase significantly. This indicates that the location determined by the model does have an offset, but the offset is not large, and most of them are only offset by 1 position.

[0102] Table 6. Model prediction evaluation indicators

[0103]

[0104] It should be noted that the model parameter initialization learning rate in Table 5 has been selected through grid search to select the optimal parameter, and the search range is [1×10 -5 , 1×10 -6 , 1×10 -7 ]. Under the same Chinese text grammatical error localization model based on dynamic word vector representation, the evaluation index values ​​of different parameters on the test set are shown in Table 7. It can be seen from the table that selecting the initialization learning rate as 0.000001 can enable the Chinese text grammatical error localization model based on dynamic word vector representation to achieve the optimal performance.

[0105] Table 7. Prediction evaluation indicators for different model parameters

[0106]

[0107] In order to reflect the superiority of the text grammatical error location model based on dynamic word vector representation, the model is compared with the static word vector. Among them, the word vectors all use BERT-Chinese-base, the parameters of the static word vectors do not change with the model training, and the vectors in the dynamic word vectors in the present invention change with the model training. The evaluation index values ​​of different models on the test set are shown in Table 8. It can be seen from the table that the text grammatical error location method based on dynamic word vector representation can improve the accuracy of grammatical error location.

[0108] Table 8. Dynamic word vector and static word vector model prediction evaluation indicators

[0109]

[0110] In summary, an embodiment of the present invention discloses a method for locating grammatical errors in Chinese text based on dynamic word vector representation, which can input a Chinese sentence and finally locate the position of the grammatical error to assist in manual review of Chinese text errors. The text grammatical error location model is based on BERT, which converts each word in the text into a vector as the input of the model, and dynamically trains the word vector during the training process. The output of BERT is connected to a bidirectional long short-term memory (BiLSTM) network to extract the features of the Chinese sentence, and then connected to a fully connected layer for sequence labeling. If the output position is marked as 1, it means that there is a grammatical error at that position. If the output position is marked as 0, it means that there is no grammatical error at that position. Experiments show that the grammatical error location model based on dynamic word vector representation can dynamically train word vectors, mine the grammatical features of Chinese text, and more accurately identify the location of grammatical errors in Chinese sentences.

[0111] The following are device embodiments of the present invention, which can be used to perform method embodiments of the present invention. For details not disclosed in the device embodiments, please refer to the method embodiments of the present invention.

[0112] In yet another embodiment of the present invention, a Chinese text grammatical error location system is specifically provided, comprising:

[0113] A text acquisition module is used to acquire and process the Chinese text to be located for grammatical errors, and obtain the Chinese text that meets the preset length requirement;

[0114] A result acquisition module is used to perform grammatical error location based on the Chinese text that meets the preset length requirement using a pre-trained text grammatical error location model, and output a grammatical error location result matrix;

[0115] Wherein, the text grammatical error location model includes:

[0116] The input layer is used to input Chinese text that meets the preset length requirement, convert each character in the Chinese text into a sequence matrix and output it;

[0117] The BERT layer is used to input the sequence matrix output by the input layer, convert it into a word vector matrix and output it;

[0118] A BiLSTM layer, used for inputting the word vector matrix and performing feature extraction, and outputting a text context feature vector;

[0119] A fully connected layer, used to input the text context feature vector, perform matrix operations and rounding, and output a positioning result vector;

[0120] The output layer is used to input the positioning result vector and output the syntax error positioning result matrix.

[0121] The embodiment of the present invention provides a Chinese text grammatical error location system based on dynamic word vector representation, which can point out the location of grammatical errors in Chinese sentences. In text generation scenarios, such as in speech recognition systems and text recognition systems, it is possible to identify and locate text sentences that are messy and incoherent due to recognition errors or noise from unknown sources, assist in checking errors, and remind users of error locations. In intelligent education, this method can assist teachers in correcting essays, assist students in improving their writing skills, and reduce the occurrence of sentence errors. The present invention does not require in-depth research on the rules of the Chinese language, nor does it require summarizing the evaluation criteria for the quality of Chinese sentences. It only requires a general understanding, with less manual participation. The system of the present invention can effectively use the Chinese character pre-training model to realize Chinese text grammatical error location: introduce a trained large-scale Chinese character pre-training model, access a bidirectional long short-term memory network after the pre-training model, and use fine-tuning technology to dynamically train the model. The final trained model can more accurately identify the location of grammatical errors in sentences.

[0122] In another embodiment of the present invention, a computer device is provided, the computer device comprising a processor and a memory, the memory being used to store a computer program, the computer program comprising program instructions, and the processor being used to execute the program instructions stored in the computer storage medium. The processor may be a central processing unit (CPU), or may be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc., which are the computing core and control core of the terminal, which are suitable for implementing one or more instructions, and are specifically suitable for loading and executing one or more instructions in a computer storage medium to implement a corresponding method flow or corresponding function; the processor described in the embodiment of the present invention can be used for the operation of the Chinese text grammatical error location method.

[0123] In another embodiment of the present invention, the present invention also provides a storage medium, specifically a computer-readable storage medium (Memory), which is a memory device in a computer device for storing programs and data. It is understandable that the computer-readable storage medium here can include both the built-in storage medium in the computer device and the extended storage medium supported by the computer device. The computer-readable storage medium provides a storage space, which stores the operating system of the terminal. In addition, one or more instructions suitable for being loaded and executed by the processor are also stored in the storage space, and these instructions can be one or more computer programs (including program codes). It should be noted that the computer-readable storage medium here can be a high-speed RAM memory or a non-volatile memory, such as at least one disk memory. The processor can load and execute one or more instructions stored in the computer-readable storage medium to implement the corresponding steps of the method for locating grammatical errors in Chinese text in the above embodiment.

[0124] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.

[0125] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0126] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0127] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0128] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the above embodiments, ordinary technicians in the relevant field should understand that the specific implementation methods of the present invention can still be modified or replaced by equivalents. Any modification or equivalent replacement that does not depart from the spirit and scope of the present invention should be covered within the scope of protection of the claims of the present invention.

Claims

1. A method for locating grammatical errors in Chinese text, characterized in that: The following steps are involved: Acquire and process the Chinese text to be located for grammatical errors to obtain a Chinese text that meets a preset length requirement; Based on the Chinese text that meets the preset length requirement, grammatical error location is performed using a pre-trained text grammatical error location model, and a grammatical error location result matrix is ​​output; Wherein, the text grammatical error location model includes: The input layer is used to input Chinese text that meets the preset length requirement, convert each character in the Chinese text into a sequence matrix and output it; The BERT layer is used to input the sequence matrix output by the input layer, convert it into a word vector matrix and output it; A BiLSTM layer, used for inputting the word vector matrix and performing feature extraction, and outputting a text context feature vector; A fully connected layer, used to input the text context feature vector, perform matrix operations and rounding, and output a positioning result vector; The output layer is used to input the positioning result vector and output the syntax error positioning result matrix.

2. A Chinese text grammatical error location method according to claim 1, characterized in that: The step of obtaining the pre-trained text grammatical error location model includes: Acquire a training sample set; each training sample in the training sample set includes a Chinese text sample that meets a preset length requirement and a corresponding grammatical error location result matrix; During training update, Chinese text samples that meet the preset length requirements in the selected training samples are input into the text grammatical error localization model to obtain a grammatical error localization result prediction matrix; the difference between the grammatical error localization result prediction matrix and the grammatical error localization result matrix in the selected training samples is calculated, and the loss is calculated using the mean square error loss function and the parameters of the text grammatical error localization model are updated to achieve the preset convergence conditions and obtain the pre-trained text grammatical error localization model.

3. A method for locating grammatical errors in Chinese text according to claim 2, characterized in that: The step of obtaining a training sample set specifically includes: Based on the preset Chinese sentence grammatical error types and combined with the NLPCC 2018 Chinese grammatical error correction shared task training set, a grammatical error sentence database is constructed using a rule-based method; wherein the preset Chinese sentence grammatical error types include one or more of repetition and redundancy, inappropriate wording, inappropriate collocation, incomplete components and the presence of typos.

4. A method for locating grammatical errors in Chinese text according to claim 3, characterized in that: The grammatical errors in the grammatical error sentence database include one or more of reduplication of characters, reduplication of words, reduplication of pronunciations, extra characters, missing characters, missing words, confusion, wrong characters, wrong homophones, wrong homophones and wrong spelling in pinyin.

5. A Chinese text grammatical error location system, characterized in that: include: A text acquisition module is used to acquire and process the Chinese text to be located for grammatical errors, and obtain the Chinese text that meets the preset length requirement; A result acquisition module is used to perform grammatical error location based on the Chinese text that meets the preset length requirement using a pre-trained text grammatical error location model, and output a grammatical error location result matrix; Wherein, the text grammatical error location model includes: The input layer is used to input Chinese text that meets the preset length requirement, convert each character in the Chinese text into a sequence matrix and output it; The BERT layer is used to input the sequence matrix output by the input layer, convert it into a word vector matrix and output it; A BiLSTM layer, used for inputting the word vector matrix and performing feature extraction, and outputting a text context feature vector; A fully connected layer, used to input the text context feature vector, perform matrix operations and rounding, and output a positioning result vector; The output layer is used to input the positioning result vector and output the syntax error positioning result matrix.

6. A Chinese text grammatical error location system according to claim 5, characterized in that: The step of obtaining the pre-trained text grammatical error location model includes: Acquire a training sample set; each training sample in the training sample set includes a Chinese text sample that meets a preset length requirement and a corresponding grammatical error location result matrix; During training update, Chinese text samples that meet the preset length requirements in the selected training samples are input into the text grammatical error localization model to obtain a grammatical error localization result prediction matrix; the difference between the grammatical error localization result prediction matrix and the grammatical error localization result matrix in the selected training samples is calculated, and the loss is calculated using the mean square error loss function and the parameters of the text grammatical error localization model are updated to achieve the preset convergence conditions and obtain the pre-trained text grammatical error localization model.

7. A Chinese text grammatical error location system according to claim 6, characterized in that: The step of obtaining a training sample set specifically includes: Based on the preset Chinese sentence grammatical error types and combined with the NLPCC 2018 Chinese grammatical error correction shared task training set, a grammatical error sentence database is constructed using a rule-based method; wherein the preset Chinese sentence grammatical error types include one or more of repetition and redundancy, inappropriate wording, inappropriate collocation, incomplete components and the presence of typos.

8. A Chinese text grammatical error location system according to claim 7, characterized in that: The grammatical errors in the grammatical error sentence database include one or more of reduplication of characters, reduplication of words, reduplication of pronunciations, extra characters, missing characters, missing words, confusion, wrong characters, wrong homophones, wrong homophones and wrong spelling in pinyin.

9. An electronic device, characterized in that: include: at least one processor; as well as, 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 to enable the at least one processor to execute the Chinese text grammatical error locating method according to any one of claims 1 to 4.

10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the method for locating grammatical errors in Chinese text according to any one of claims 1 to 4 is implemented.

Citation Information

Patent Citations

  • A Chinese grammatical error detection method based on a word vector with text information added

    CN108984525A

  • An LSTM-based Chinese text grammar error correction model method

    CN109948152A

  • Chinese grammar error detection method and system based on hierarchical multi-task learning

    CN112364631A

  • Error correction method and device for Chinese text, and computer equipment

    CN112395861A

  • Chinese grammar error correction method and device based on data enhancement

    CN113822054A