Vietnamese grammatical error correction method and device integrating multi-granularity features

By integrating multi-granularity features into the Vietnamese grammar error correction method, combining mBERT and N-gram language models, and using large-scale corpus and feature dictionaries, the problems of generation instability and insufficient feature utilization in Vietnamese text grammar correction are solved. Achieve high-accuracy grammatical error identification and correction.

CN114707492BActive Publication Date: 2024-08-23KUNMING UNIV OF SCI & TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210284610.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-03-22
Publication Date
2024-08-23
Estimated Expiration
2042-03-22

AI Technical Summary

Technical Problem

The existing Seq2Seq method has the problem of unstable sentence generation and inability to effectively utilize Vietnamese language features in Vietnamese text grammar error correction, resulting in low error correction accuracy and recognition accuracy.

Method used

Using a Vietnamese grammatical error correction method that integrates multi-granularity features, through the mBERT mask language model and N-gram language model, combined with character, syllable and sentence features, grammatical error detection and correction are performed, using the crawled large-scale Vietnamese corpus Perform data preprocessing and error data generation, build a part-of-speech dictionary and a syllable confusion set dictionary to achieve accurate identification and correction of grammatical errors.

Benefits of technology

Significantly improve the error correction accuracy, recall rate and F value, effectively identify and correct word order errors, syllable confusion errors and function word misuse errors in Vietnamese, avoid the exposure bias of the sequence generation model, and improve the accuracy of grammatical errors. Identification and correction accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114707492B
    Figure CN114707492B
Patent Text Reader

Abstract

The present invention relates to a Vietnamese grammatical error correction method and device integrating multi-granularity features, and belongs to the field of natural language processing. The present invention incorporates additional Vietnamese characters, syllables, and sentence feature embeddings at the model encoding end, and then uses a sequence annotation network to predict the error position of the input sentence, and then uses the masked language model of the multilingual BERT to re-predict the words at the error position to obtain several corrected candidate sentences, and finally uses the N-gram language model to score the candidate sentences, and selects the sentence with the highest score as the corrected sentence output. This method avoids directly generating sentences, but instead modifies the input sentences according to the error detection results, and does not change the basic grammatical structure of the input sentences. Experimental results show that the present invention is F-rated compared to the baseline method based on the Transformer model. 0.5 The value and F1 value increased by 16.69% and 17.84% respectively, and the grammatical error correction effect was significantly better than the sequence-to-sequence generation model.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to a Vietnamese grammatical error correction method and device integrating multi-granularity features, and belongs to the technical field of natural language processing. Background Art

[0002] The application scenarios of text error correction technology are very broad. In addition to being designed as an automatic online error correction learning tool for foreign language learners, it can also play an important role in other fields. For example, embedding an error correction module in office software can automatically check and prompt errors when the author is writing, thereby reducing errors caused by negligence; embedding a text error correction module in a speech recognition system can automatically correct typos in the process of speech recognition to text, making the overall product experience better; the news media industry can use it for editing and proofreading, and automatically correct typos in news articles, thereby saving a lot of labor costs.

[0003] Text grammatical error correction usually uses a sequence-to-sequence text generation model to generate grammatically correct sentences. However, the existing Seq2Seq method has the following problems: (1) The sequence generation model has an exposure bias problem, which leads to unstable generated sentences. The generated sentences have a large difference in grammatical structure from the input sentences, resulting in low error correction accuracy. (2) The existing method cannot effectively utilize the language characteristics of Vietnamese, making it difficult to identify grammatical errors and the accuracy of grammatical error detection is low.

[0004] In summary, it is necessary to provide a method and system that can effectively utilize the language features of Vietnamese and can accurately identify error positions and correctly correct words in the error positions. Summary of the invention

[0005] To solve the above problems, the present invention provides a Vietnamese grammatical error correction method and device integrating multi-granularity features. The present invention performs better than the baseline model in terms of error correction accuracy, recall rate, F-value and other indicators, and the error correction accuracy is greatly improved.

[0006] The technical solution of the present invention is: in the first aspect, the present invention provides a Vietnamese grammatical error correction method integrating multi-granularity features, and the specific steps of the method are as follows:

[0007] Step 1, obtain Vietnamese text data and preprocess it;

[0008] Step 2: embed the input Vietnamese sentence into words and fuse additional feature vectors; perform grammatical error detection on the input Vietnamese sentence;

[0009] Step 3: According to the detection results, use the mBERT masked language model to correct the words in the wrong position to obtain several candidate sentences; use the N-gram language model to score the candidate sentences and select the corrected candidate sentence with the highest score for output.

[0010] As a further solution of the present invention, the specific steps of Step 1 are as follows:

[0011] Step 1.1, use crawler programs to crawl text data from Wikipedia entries (http: / / www.wikipedia.org) and major news websites in Vietnam (http: / / www.vnexpress.net, https: / / thanhnien.vn), and obtain a large amount of original Vietnamese corpus, with a size of about 1.5GB;

[0012] Step 1.2: Clean the crawled corpus. First, segment the text to get 1.52 million sentences. Then delete the sentences containing special characters and non-Vietnamese characters. Then filter out the sentences with a length of no more than 40 syllables and a syllable repetition rate of less than 90%. Finally, get 1.08 million grammatically correct sentences.

[0013] Step 1.3: Use the open source tool Underthesea (https: / / github.com / undertheseanlp / underthesea) to segment and tag the sentences preprocessed in Step 1.2, build a Vietnamese part-of-speech dictionary based on the segmentation and part-of-speech tagging results, and build a syllable confusion set dictionary based on Vietnamese spelling and pronunciation rules;

[0014] Step 1.4, design and implement an error data generation algorithm based on different error types, use this algorithm and the syllable confusion set dictionary obtained in Step 1.3 to make errors in grammatically correct sentences, manually construct a scale of 208,000 "error-correction" parallel sentence pairs, mark the error positions, and obtain the labels corresponding to each word in the error sentences;

[0015] As a further solution of the present invention, the specific steps of Step 2 are as follows:

[0016] Step 2.1, for the sentence X containing grammatical errors, 1 ,...,x i ,...,x n ), using the multilingual BERT model (mBERT) for each syllable x of the input sentence i Initialize the word embedding and get the encoded hidden state representation:

[0017]

[0018] in, represents the hidden state output of the last layer of the mBERT encoder, and L represents the number of hidden network layers.

[0019] Step 2.2, for each syllable x input i To embed character features, first i (c 1 ,c 2 ,....,c M ) to split the characters and get each character c of the current syllable j , then for each character c j Perform one-hot encoding to get syllable x i The corresponding character feature vector C i :

[0020]

[0021] Where M represents the total number of characters in a syllable, and D C Indicates the size of the character feature dimension, f k (x) represents the one-hot encoding of the kth dimension.

[0022] Step 2.3, for each syllable x input i Embed syllable features. Syllable features include the part of speech corresponding to each syllable and its tone. First, determine the part of speech tag p of the input syllable. i Tone Tag i , and then perform One-hot encoding according to the part-of-speech and tone tags to obtain the part-of-speech feature vector P i Harmony tone feature vector T i Finally, P i and T i Perform concatenation operation to obtain syllable feature vector S i :

[0023]

[0024] S i =Concat(P i ,T i )

[0025] Among them, f k (x) represents the one-hot encoding of the kth dimension, D P represents the part-of-speech feature dimension, D T Represents the tone feature dimension.

[0026] Step 2.4, for each syllable x inputi Sentence features are embedded. Sentence features include phrase component features and adjacent syllable matching features. A matrix is ​​used represents the phrase component feature matrix corresponding to the i-th syllable, where d s represents the size of the component annotation set, d m Represents the feature dimension of phrase components, and the weight parameter of the kth dimension is a function of The number of samples is d. m ;

[0027] Step 2.5, use Adjacent Syllable Matching (ASM) to indicate the grammatical correctness between two adjacent syllables in the input sentence. First, use Pointwise Mutual Information (PMI) to indicate the correlation between adjacent syllables:

[0028]

[0029] Among them, P(s 1 ,s 2 ) means two syllables 1 and 2 The probability of co-occurrence in the corpus, P(s) represents the probability of a syllable s appearing alone in the corpus.

[0030] Step 2.6, use a matrix represents the adjacent syllable matching feature of the i-th syllable, where d m Represents the feature dimension, and each weight parameter in the matrix is ​​initialized with the adjacent syllable matching degree (ASM):

[0031]

[0032] Step 2.7: The phrase component feature vector of the i-th syllable and adjacent syllable matching feature vector Concatenate and get the sentence feature vector G i Then the character feature vector C i , syllable feature vector S i and sentence feature vector G i Pad according to the maximum dimension and then concatenate to get syllable x i The corresponding eigenvector F(x i ):

[0033]

[0034] F(x i )=Pad_Concat(C i ,S i ,G i )

[0035] Step 2.8, get each syllable x i The feature embedding F(x i ), and then output it and the last hidden state of the mBERT encoder Concatenate to get the final hidden state representation X i , and then send it to a softmax layer to calculate each syllable x i The predicted label probability l i :

[0036]

[0037] l i =softmax(W O X i +b O )

[0038] Among them, W O is the matrix weight parameter of the softmax layer, b O is the bias weight parameter.

[0039] As a further solution of the present invention, the specific steps of Step 3 are as follows:

[0040] A method for grammatical error correction using the mBERT masked language model and the N-gram language model;

[0041] Step 3.1, according to the predicted label sequence L obtained in Step 2 = (l 1 ,l 2 ,...,l n ) to correct grammatical errors, first traverse each label l in the detection result label sequence i , if l i If it is "O" (no error mark), the syllable at the corresponding position in the corrected sentence remains unchanged, otherwise the syllable at the corresponding position is replaced by the "MASK" mark;

[0042] Step 3.2: Use the mBERT Masked Language Model to re-predict the word at the “MASK” tag position and give 5 candidate correction items {a 1 ,a 2 ,a 3 ,a 4 ,a 5};

[0043] Step 3.3, replace the "MASK" mark of the original input sentence X with 5 correction candidates respectively, and get the corresponding 5 correction candidate sentences {Y 1 ,Y 2 ,Y 3 ,Y 4 ,Y 5};

[0044] Step 3.4, use the N-gram language model to score the 5 corrected candidate sentences:

[0045]

[0046]

[0047] Among them, S represents the input candidate sentence, and P(x) represents the probability of a syllable x appearing in the corpus calculated using the N-gram language model.

[0048] Step 3.5, select the sentence with the highest score among the five candidate sentences as the final corrected sentence output:

[0049] Y out =max{score(Y 1 ),score(Y 2 ),score(Y 3 ),score(Y 4 ),score(Y 5 )}

[0050] In a second aspect, an embodiment of the present invention further provides a Vietnamese grammatical error correction device integrating multi-granularity features, wherein the device includes a module for executing the method of the first aspect.

[0051] Specifically, a Vietnamese grammatical error correction device based on the "error detection-error correction" pipeline mode is provided, which includes the following modules:

[0052] Word embedding module: used to embed the input Vietnamese sentence sequence X = (x 1 ,x 2 ,...,x n ) is converted into a word vector. The weight parameters of the word vector are initialized for each syllable using the encoder of the mBERT model. The encoder consists of multiple Transformer encoders. After mBERT encoding, the hidden state representation vector corresponding to each syllable can be obtained. The vector is calculated according to Step 2.1.

[0053] Feature embedding module: used to perform multi-granular feature representation on the input sentence X. These features mainly include three granularities: character granularity, syllable granularity, and sentence granularity. Character feature refers to further encoding and representing each character of the input syllable. Syllable feature refers to further encoding and representing the part of speech and tone of the input syllable. Sentence feature refers to further encoding and representing the phrase structure information and adjacent syllable matching degree of the input sentence X. The calculation steps of the entire feature embedding are as follows:

[0054] 1. Calculate the character feature vector of each syllable according to Step 2.2;

[0055] 2. Calculate the part-of-speech feature vector and tone feature vector of each syllable according to Step 2.3;

[0056] 3. Calculate the adjacent syllable matching feature vector of the input sentence according to Step 2.5 and Step 2.6;

[0057] 4. Calculate the feature vector corresponding to each syllable according to Step 2.7;

[0058] Grammatical error detection module: It is used to predict the label of each syllable of the input sentence X using the mBERT-based sequence labeling model. The latent state representation vector obtained by the word embedding module and the feature vector obtained by the feature embedding module are concatenated and sent to a softmax layer to calculate the probability of predicting the label of each syllable. The prediction probability is calculated according to Step 2.8.

[0059] The grammatical error correction module is used to obtain the predicted label sequence L corresponding to the input sentence X according to the predicted probability calculated by the grammatical error detection module. 1 ,l 2 ,...,l n ). Traverse the label sequence L. If there is no wrong token in L, it means that the input sentence X is grammatically correct and X is output as is. If there is an wrong token in L, it means that X has a grammatical error. Replace the label at the wrong position with the "MASK" token, and then use the mBERT masked language model to re-predict the word at the "MASK" token to get 5 corrected candidate words. Use these 5 candidate words to replace the original words at the wrong position, and get 5 corrected candidate sentences. Finally, use the N-gram language model and Step 3.4 and Step 3.5 to calculate and select the candidate sentence Y with the highest sentence score as the corrected sentence output.

[0060] The word embedding module, the feature embedding module, the grammatical error detection module and the grammatical error correction module are connected in cascade mode to form a Vietnamese grammatical error correction device in an "error detection-error correction" pipeline mode.

[0061] The beneficial effects of the present invention are:

[0062] The present invention regards the grammatical error correction task as two subtasks: grammatical error detection and grammatical error correction. An additional Vietnamese feature vector is incorporated into the encoding end of the grammatical error detection network, including different features of character, syllable and sentence granularity, which can effectively identify Vietnamese grammatical errors that cannot be recognized by traditional sequence labeling models; the input sentence is modified according to the output result of the grammatical error detection instead of directly using the sequence generation model to generate the result. This method will not make a large number of modifications to the overall grammatical structure of the input sentence, effectively avoiding the exposure bias problem of the sequence generation model.

[0063] The method and device structure proposed in the present invention have a good correction effect on word order errors, syllable confusion errors and function word misuse errors in Vietnamese, and the recognition accuracy rate and grammatical error correction accuracy rate of grammatical errors are better than those of the baseline model. BRIEF DESCRIPTION OF THE DRAWINGS

[0064] Figure 1 A schematic diagram for constructing a grammatical error correction model in the present invention;

[0065] Figure 2 It is a schematic diagram of the feature fusion process in the present invention;

[0066] Figure 3 A schematic diagram of the error data generation algorithm flow in the present invention;

[0067] Figure 4 It is a schematic diagram of the structure of the device in the present invention;

[0068] Figure 5 It is a schematic diagram of the process of the present invention. DETAILED DESCRIPTION

[0069] Example 1: Figure 1-Figure 5 As shown, a Vietnamese grammatical error correction method integrating multi-granularity features comprises: preprocessing Vietnamese text data; representing input Vietnamese sentences by word embedding and integrating additional feature vectors; detecting grammatical errors in the input Vietnamese sentences; correcting words in wrong positions by using the mBERT masked language model according to the detection results to obtain several candidate sentences; scoring the candidate sentences by using the N-gram language model, and selecting the corrected candidate sentence with the highest score for output.

[0070] The specific steps are:

[0071] Step 1. Use a crawler to crawl about 1.5GB of raw corpus from the Wikipedia entry directory (http: / / www.wikipedia.org) and major news websites in Vietnam (http: / / www.vnexpress.net, https: / / thanhnien.vn). Use the open source tool Underthesea (https: / / github.com / undertheseanlp / underthesea) to clean the crawled corpus. First, segment the text data to obtain 1.52 million sentences, then filter out sentences containing special characters, and then filter out sentences with a length of no more than 40 syllables and a syllable repetition rate of less than 90%, and finally obtain 1.08 million grammatically correct sentences. Use the open source tool Underthesea to segment and tag these sentences, build a Vietnamese part-of-speech dictionary based on the segmentation and part-of-speech tagging results, and build a syllable confusion set dictionary based on Vietnamese spelling and pronunciation rules.

[0072] We used 1.08 million grammatically correct sentences as seed corpus and designed an error data generation algorithm based on five error types in Vietnamese, including conjunction errors, preposition errors, conjunction errors, word order errors, and syllable confusion errors. The algorithm flow is as follows: Figure 3 As shown. First, the grammatically correct seed corpus Cs is divided into sentences to obtain a sentence set {S}, and each sentence S is traversed. Then, according to the probability Pe, it is determined whether S is erroneous, and according to the probabilities Pu, Pm, and Ps, it is determined whether to introduce substitution errors (preposition, conjunction, and associative word errors), word order errors, and syllable confusion errors into S. Among them, syllable confusion errors are replaced according to the options in the confusion set dictionary. The probabilities Pe, Pu, Pm, and Ps are all manually set parameters, which are set to 0.5, 0.25, 0.25, and 0.25 respectively in the present invention. Examples of sentences containing grammatical errors obtained according to the error data generation algorithm are shown in Table 1.

[0073] Table 1 Examples of types of Vietnamese grammatical errors

[0074]

[0075] The present invention mainly performs grammatical correction on the five types of errors in Table 1, uses an error data generation algorithm to create errors in the seed corpus, takes the erroneous sentences as the source end, and the correct sentences as the target end, and manually constructs 208,000 "error-correction" parallel sentence pairs. Then the sentences containing grammatical errors are annotated, and the BIO annotation scheme is adopted. The "B-" prefix indicates the starting position of the grammatical error, the "I-" prefix indicates the middle and ending parts of the grammatical error part, and the "O" mark indicates the part without grammatical errors. Six different labels are used to represent conjunction errors, preposition errors, conjunction errors, word order errors and syllable confusion errors. The detailed annotation scheme is shown in Table 2.

[0076] Table 2. Error correction corpus annotation scheme

[0077]

[0078] According to the annotation scheme in Table 2, 208,000 manually constructed "error-correction" parallel sentence pairs were annotated to obtain data that can be used for grammatical error detection model training and prediction, as well as parallel sentence pairs for subsequent grammatical error correction model training.

[0079] Step 2. Next, we build a grammatical error detection model. First, we embed the input sentence into words and directly use the pre-trained word embedding weight parameters of the multilingual BERT (mBERT) model to initialize each syllable of the input sentence. The mBERT model comes from the Transformers code library provided by Hugging Face. The BERT download address is: https: / / cdn.huggingface.co / bert-base-multilingual-cased-pytorch_model.bin. For the input sentence X containing grammatical errors, 1 ,x 2 ,...,x n ), using the mBERT model for each syllable x of the input sentence i Initialize the word embedding and get the encoded hidden state representation:

[0080]

[0081] in, represents the hidden state output of the last layer of the mBERT encoder, and L represents the number of hidden network layers.

[0082] Then, feature embedding is performed on each syllable of the input sentence to obtain a feature vector and integrate the feature vector into the encoding end of the mBERT model. The feature fusion process is as follows: Figure 2These features include character features, syllable features, and sentence features. The feature embedding process of each granularity is as follows:

[0083] 1. Character feature embedding, first x i (c 1 ,c 2 ,....,c M ) to split the characters and get each character c of the current syllable j , then for each character c j Perform one-hot encoding to get x i The corresponding character feature vector C i :

[0084]

[0085] Where M represents the total number of characters in a syllable, and D C Indicates the size of the character feature dimension, f k (x) represents the one-hot encoding of the kth dimension.

[0086] 2. Syllable feature embedding. Syllable features include the part of speech corresponding to each syllable and its tone. First, determine the part of speech tag p of the input syllable i Tone Tag i , and then perform One-hot encoding according to the part-of-speech and tone tags to obtain the part-of-speech feature vector P i Harmony tone feature vector T i Finally, P i and T i Perform concatenation operation to obtain syllable feature vector S i :

[0087]

[0088] S i =Concat(P i ,T i ) (4)

[0089] Among them, D P represents the part-of-speech feature dimension, D T Represents the tone feature dimension. The part-of-speech tags are obtained by annotating the input sentences using the open source tool Underthesea mentioned above. There are 10 types in total. The tone tags are determined by the syllable's added characters. Each syllable has only one tone, including 6 tones: horizontal tone, mysterious tone, sharp tone, question tone, falling tone, and heavy tone.

[0090] 3. Sentence feature embedding. Sentence features include the phrase component features of the input sentence and the matching degree of adjacent syllables. A matrix is ​​used Indicates syllable xi The corresponding phrase component feature matrix, where d s represents the size of the component annotation set, d m Represents the feature dimension of phrase components, and the weight parameter of the kth dimension is a function of The number of samples is d. m ; Then use a matrix Indicates syllable x i The adjacent syllable matching feature, where d m Represents the feature dimension, and each weight parameter in the matrix is ​​initialized with Adjacent Syllable Matching (ASM):

[0091]

[0092]

[0093] Among them, P(s 1 ,s 2 ) means two syllables 1 and 2 The probability of co-occurrence in the corpus, P(s) represents the probability of a syllable s appearing alone in the corpus.

[0094] 4. Change the syllable x i The corresponding phrase component feature vector and adjacent syllable matching feature vector Concatenate and get the sentence feature vector G i Then the character feature vector C i , syllable feature vector S i and sentence feature vector G i Pad according to the maximum dimension and then concatenate to get syllable x i The corresponding eigenvector F(x i ):

[0095]

[0096] F(x i )=Pad_Concat(C i ,S i ,G i ) (8)

[0097] Get each syllable x i The feature embedding F(x i ), and then output it and the last hidden state of the mBERT encoder Concatenate to get the final hidden state representation X i , and then send it to a softmax layer to calculate each syllable x i The predicted label probability l i :

[0098]

[0099] l i =softmax(W o X i +b o ) (10)

[0100] Among them, W o is the matrix weight parameter of the softmax layer, b o is the bias weight parameter. The grammatical error detection model uses the cross entropy loss shown in formula (11) to optimize the detection model during the training phase:

[0101]

[0102] Among them, y represents the softmax input of the correct category, C represents the number of label categories, and Y j Indicates the predicted probability of the jth label. In the model inference stage, the final softmax output layer directly outputs the predicted label sequence L corresponding to the Vietnamese sentence X = (l 1 ,l 2 ,...,l n ).

[0103] Step 3. Finally, according to the detection label sequence L, use the mBERT masked language model and N-gram language model to perform grammatical error correction. First, traverse each label l in the detection result label sequence i , if l i If the word is "O" (no error mark), the syllable at the corresponding position in the corrected sentence remains unchanged, otherwise the syllable at the corresponding position is replaced with the "MASK" mark; the mBERT Masked Language Model is used to re-predict the word at the "MASK" mark position, and 5 candidate correction items are given {a 1 ,a 2 ,a 3 ,a 4 ,a 5}; The “MASK” mark of the original input sentence X is replaced with 5 correction candidates respectively, and the corresponding 5 correction candidate sentences {Y 1 ,Y 2 ,Y 3 ,Y 4 ,Y5}; Use the N-gram language model to score the 5 corrected candidate sentences:

[0104]

[0105]

[0106] Where S represents the candidate sentence input, and P(x) represents the probability of a syllable x appearing in the corpus calculated using the N-gram language model. The Vietnamese N-gram language model is trained using the open source tool KenLM and large-scale Vietnamese text data. The KenLM address is: https: / / github.com / kpu / kenlm. In the present invention, a 5-gram language model is trained using KenLM, and the mBERT masked language model uses the BertForMaskedLM model parameters provided in the Transformers code library. Finally, the candidate sentence with the highest score is selected as the output:

[0107] Y out =max{score(Y 1 ),score(Y 2 ),score(Y 3 ),score(Y 4 ),score(Y 5 )} (14)

[0108] The entire grammatical error correction network model needs to train the grammatical error detection network part. The training data must contain the five error types shown in Table 1. The present invention uses the annotated "error-correction" parallel sentence pairs artificially constructed in the data preprocessing part as the training and verification data of the model. The specific data statistical information is shown in Table 3. The detection network adopts the sequence annotation model based on mBERT, and the parameter settings of the model are shown in Table 4.

[0109] Table 3 Detailed statistical information of the dataset

[0110]

[0111] Table 4 Model parameter settings

[0112]

[0113] In terms of the evaluation indicators of the model, M 2 The Scorer tool (https: / / github.com / nusnlp / m2scorer) calculates the error correction accuracy, recall rate, and F value. The details are as follows:

[0114] The grammatical error correction model is evaluated using M 2 Evaluation index, which measures the overall performance of the system by calculating the degree of match between the edit set of the grammatical error correction system output and the reference corrected edit set. The evaluation index calculation of this tool still uses the precision rate P, recall rate R and F value, but the calculation method is slightly different from the general classification task. For n sentences output by the error correction system, the calculation method of P, R and F values ​​is as follows:

[0115]

[0116]

[0117]

[0118] Among them, |g i ∩e i | represents the intersection between the edit set of the i-th sentence output by the grammatical error correction system and the reference edit set, M 2 The evaluation index strictly requires that each modified string is the same to be considered as an intersection, e i and g i They represent the edit set of the i-th sentence output by the error correction system and the edit set of the reference correction of the i-th sentence respectively.

[0119] In order to verify the effectiveness of the present invention, the following model is compared with the model proposed by the present invention:

[0120] (1) LSTM-Seq2Seq: A sequence-to-sequence model based on the LSTM structure. The experiment compares the effects of using word2vec monosyllabic word vectors and GloVe monosyllabic word vectors.

[0121] (2) Bi-LSTM with Attention: A sequence generation model based on a bidirectional LSTM network with an attention mechanism, using monosyllabic word vectors pre-trained with GloVe.

[0122] (3) Transformer: A classic encoder-decoder model based on the self-attention mechanism, which can adapt to various sequence generation tasks, including grammatical error correction.

[0123] Table 5 Comparison of the effects of different methods on the test set (unit: %)

[0124]

[0125] Table 5 shows the evaluation results of different methods on the test set. The results show that compared with the baseline method, the method proposed in this paper has the highest accuracy and recall rate on the test set, which are 42.53% and 42.82% respectively; among the baseline methods, the Transformer model is the best model in the baseline method, which is much higher than the traditional Seq2Seq model based on LSTM network in terms of accuracy and recall rate. Compared with the Transformer model, the method in this chapter has the highest accuracy, recall rate, F 0.5 Value and F 1 The values ​​are 15.86%, 19.59%, 16.69% and 17.84% higher respectively, indicating that the method using the "error detection-error correction" pipeline is better than the direct end-to-end sequence generation method.

[0126] Table 6 Examples of Vietnamese grammatical correction

[0127]

[0128] Table 6 shows two specific examples of Vietnamese grammatical error correction. As can be seen from Table 6, the overall effect of the grammatical error correction model proposed in the present invention is better than the Transformer sequence generation model. In the first example, there is a syllable confusion error in the input sentence. The wrong syllable is The correct syllable is The correct phrase is (all)", although the Transformer model corrected the phrase, it changed the following part that should not be changed Modified, the model proposed by the present invention corrected the entire sentence. In the second example, there are two errors in total, which the Transformer model did not modify, while the proposed model only corrected one error.

[0129] In a second aspect, an embodiment of the present invention further provides a Vietnamese grammatical error correction device integrating multi-granularity features, wherein the device includes a module for executing the method of the first aspect.

[0130] Specifically, a Vietnamese grammatical error correction device based on the "error detection-error correction" pipeline mode can be provided, such as Figure 4 As shown, it includes the following modules:

[0131] Word embedding module: used to embed the input Vietnamese sentence sequence X = (x 1 ,x 2 ,...,x n) is converted into a word vector. The weight parameters of the word vector are initialized for each syllable using the encoder of the mBERT model. After mBERT encoding, the word embedding vector corresponding to each syllable can be obtained. The vector is calculated according to formula (1).

[0132] Feature embedding module: used to represent the input sentence X with multi-granularity features. These features mainly include three granularities: character granularity, syllable granularity, and sentence granularity. Character features include the encoding of each character that makes up the input syllable. The character feature vector is calculated according to formula (2); syllable features include the part of speech and tone of the input syllable. The part of speech feature vector and the syllable feature vector are calculated according to formula (3). The part of speech feature vector and the syllable feature vector are concatenated to obtain the syllable feature vector of the input syllable; sentence features include the phrase component features and the adjacent syllable matching degree of the input sentence. The representation method of the phrase component feature vector is the same as the feature embedding process introduced above. The adjacent syllable matching degree feature vector is calculated according to formula (4). The two are concatenated to obtain the sentence feature vector. Finally, the character feature vector, syllable feature vector, and sentence feature vector are padded, aligned, and concatenated to obtain the feature vector corresponding to the input syllable.

[0133] Grammatical error detection module: It is used to predict the label of each syllable of the input sentence X using the mBERT-based sequence labeling model. The word embedding vector obtained by the word embedding module and the feature vector obtained by the feature embedding module are concatenated and sent to a softmax layer to calculate the probability of predicting the label of each syllable. The predicted probability is calculated according to formula (10).

[0134] The grammatical error correction module is used to obtain the predicted label sequence L corresponding to the input sentence X according to the predicted probability calculated by the grammatical error detection module. 1 ,l 2 ,...,l n ). Traverse the label sequence L. If there is no wrong token in L, it means that the input sentence X is grammatically correct and X is output as is. If there is an wrong token in L, it means that X contains a grammatical error. Use the "MASK" token to replace the label at the wrong position, and then use the mBERT masked language model to re-predict the word at the "MASK" token to obtain 5 corrected candidate words. Use these 5 candidate words to replace the original words at the wrong position, and obtain 5 corrected candidate sentences. Finally, use the N-gram language model and formula (12-13) to calculate the score of each candidate sentence, and select the candidate sentence Y with the highest sentence score as the corrected sentence output.

[0135] The word embedding module, feature embedding module, grammatical error detection module and grammatical error correction module are connected in cascade mode to realize the function of grammatical error detection and correction of input Vietnamese sentences, thus forming a Vietnamese grammatical error correction device based on the "error detection-error correction" pipeline mode.

[0136] The specific implementation modes of the present invention are described in detail above in conjunction with the accompanying drawings, but the present invention is not limited to the above implementation modes, and various changes can be made within the knowledge scope of ordinary technicians in this field without departing from the purpose of the present invention.

Claims

1. A Vietnamese grammatical error correction method integrating multi-granularity features, characterized in that: The specific steps of the method are as follows: Step 1, obtain Vietnamese text data and preprocess it; Step 2: embed the input Vietnamese sentence into words and fuse additional feature vectors; perform grammatical error detection on the input Vietnamese sentence; Step 3: According to the detection results, use the mBERT masked language model to correct the words in the wrong position and obtain several candidate sentences; use the N-gram language model to score the candidate sentences and select the corrected candidate sentence with the highest score for output; The specific steps of Step 2 are as follows: Step 2.1, for the input sentence X containing grammatical errors, i ,...,x n ), using the multilingual BERT model mBERT for each syllable x in the input sentence i Initialize the word embedding and get the encoded hidden state representation: in, represents the hidden state output of the last layer of the mBERT encoder, and L represents the number of hidden network layers; Step 2.2, for each syllable x input i To embed character features, first i (c1,c2,....,c M ) to split the characters and get each character c of the current syllable j , then for each character c j Perform one-hot encoding to get syllable x i The corresponding character feature vector C i : Where M represents the total number of characters in a syllable, and D C Indicates the size of the character feature dimension, f k (x) represents the One-hot encoding of the kth dimension; Step 2.3, for each syllable x input i Embed syllable features. Syllable features include the part of speech corresponding to each syllable and its tone. First, determine the part of speech tag p of the input syllable. i Tone Tag i , and then perform One-hot encoding according to the part-of-speech and tone tags to obtain the part-of-speech feature vector P i Harmony tone feature vector T i Finally, P i and T i Perform concatenation operation to obtain syllable feature vector S i : S i =Concat(P i ,T i )(4) Among them, f k (x) represents the one-hot encoding of the kth dimension, D P represents the part-of-speech feature dimension, D T Represents the dimension of tone characteristics; Step 2.4, for each syllable x input i Sentence features are embedded. Sentence features include phrase component features and adjacent syllable matching features. A matrix is ​​used represents the phrase component feature matrix corresponding to the i-th syllable, where d s represents the size of the component annotation set, d m Represents the feature dimension of phrase components, and the weight parameter of the kth dimension is a function of Random sampling is performed from a uniform distribution on the m ; Step 2.5, use the adjacent syllable matching degree ASM to represent the grammatical correctness between two adjacent syllables in the input sentence. First, use the point mutual information PMI to represent the correlation between adjacent syllables: Among them, P(s1,s2) represents the probability of two syllables s1 and s2 appearing simultaneously in the corpus, and P(s) represents the probability of a syllable s appearing alone in the corpus; Step 2.6, use a matrix represents the adjacent syllable matching feature of the i-th syllable, where d m Represents the feature dimension, and each weight parameter in the matrix is ​​initialized with the adjacent syllable matching degree ASM: Step 2.7: The phrase component feature vector of the i-th syllable and adjacent syllable matching feature vector Concatenate and get the sentence feature vector G i Then the character feature vector C i , syllable feature vector S i and sentence feature vector G i After filling according to the maximum dimension and then concatenating, we get syllable x i The corresponding eigenvector F(x i ): F(x i )=Pad_Concat(C i ,S i ,G i )(8) Step 2.8, get each syllable x i The feature embedding F(x i ), and then output it and the last hidden state of the mBERT encoder Concatenate to get the final hidden state representation X i , and then send it to a softmax layer to calculate each syllable x i The predicted label probability l i : l i =softmax(W O X i +b O )(10)W O is the matrix weight parameter of the softmax layer, b O is the bias weight parameter; The specific steps of Step 3 are as follows: Step 3.1, according to the predicted label sequence L obtained in Step 2 = (l1, l2, ..., l n ) to correct grammatical errors, first traverse each label l in the detection result label sequence i , if l i If it is "O", the syllable at the corresponding position in the corrected sentence remains unchanged, otherwise the syllable at the corresponding position is replaced by the "MASK" mark; Step 3.2, use the mBERT masked language model to re-predict the word at the "MASK" mark position and give 5 candidate correction items {a1, a2, a3, a4, a5}; Step 3.3, replace the "MASK" mark of the original input sentence X with 5 correction candidates respectively, and obtain the corresponding 5 correction candidate sentences {Y1, Y2, Y3, Y4, Y5}; Step 3.4, use the N-gram language model to score the 5 corrected candidate sentences: Where S represents the candidate sentence input, and P(x) represents the probability of a syllable x appearing in the corpus calculated using the N-gram language model; Step 3.5, select the sentence with the highest score among the five candidate sentences as the final corrected sentence output: Y out =max{score(Y1),score(Y2),score(Y3),score(Y4),score(Y5)}(13)。 2. The Vietnamese grammatical error correction method integrating multi-granularity features according to claim 1 is characterized in that: The specific steps of Step 1 are as follows: Step 1.1, use the crawler program to crawl text data from the Wikipedia entry directory and major news websites in Vietnam to obtain the original Vietnamese corpus; Step 1.2: Clean the crawled corpus. First, segment the text to get 1.52 million sentences. Then delete the sentences containing special characters and non-Vietnamese characters. Then filter out sentences with a length of no more than 40 syllables and sentences with a syllable repetition rate of less than 90%. Finally, get 1.08 million grammatically correct Vietnamese sentences. Step 1.3, use open source tools to perform word segmentation and part-of-speech tagging on the sentences preprocessed in Step 1.2, build a Vietnamese part-of-speech dictionary based on the word segmentation and part-of-speech tagging results, and build a syllable confusion set dictionary based on Vietnamese spelling and pronunciation rules; Step 1.

4. Design and implement an error data generation algorithm based on different error types. Use this algorithm and the syllable confusion set dictionary obtained in Step 1.3 to make errors in grammatically correct sentences. Manually construct a scale of 208,000 "error-correction" parallel sentence pairs, mark the error positions, and obtain the labels corresponding to each word in the incorrect sentences.

3. A Vietnamese grammatical error correction device integrating multi-granularity features, characterized in that: The method comprises a module for executing the method according to any one of claims 1 to 2.