# The Construction of Machine Translation Model and Its Application in English Grammar Error Detection

Authors: Fei Long
Journal: Security and Communication Networks
 (2021)

---

## Abstract

In order to solve the problems of low accuracy, recall rate, andF1 value of traditional English grammar error detection methods, a new machine translation model is constructed and applied to English grammar error detection. In the encoder-decoder framework, the machine translation model is constructed through the steps of word vector generation, encoder language model construction, decoder language model construction, word alignment, output module, and so on. On this basis, the machine translation model is trained to detect English grammatical errors through dependency analysis and alternative word generation. Experimental results show that the accuracy, recall rate, and F1 value of the proposed method are higher than those of the experimental comparison method for detecting English grammatical errors such as articles, prepositions, nouns, verbs, and subject-verb agreement, indicating that the proposed method is of high practical value.


---

## Body

## 1. Introduction

As the most basic, direct, and convenient expression tool of human thoughts and feelings, natural language is always filled in every corner of human society. From the first cry after birth, people try to use language to express their feelings and intentions. With the advent of the information age, the forms of communication and communication in which people use natural language increasingly reflect its diversity, flexibility and universality [1]. In the era of globalization, as countries and nations are increasingly connected, translation between different languages has naturally become an urgent need. From basic overseas travel, literature translation to international business such as global e-commerce, financial services, international trade, etc., it is inevitable to encounter a problem of cross-language translation. Therefore, efficient translation between different languages in different fields has become a common demand of contemporary people. Translation is the most direct and effective way to solve communication barriers between natural languages [2]. Traditional translation work is done by professional translators, who can translate natural languages to each other through linguistic knowledge to help people realize information communication. With the maturity of computer technology and the continuous progress of natural language processing technology, it has become an inevitable trend to use machine translation system to help people get foreign information quickly instead of human translation. In this case, the large amount of data to be translated drives people to turn to machine translation systems for efficient translation. In addition, there are a lot of grammatical errors in the translation results due to the flood of machine translation software and backward technology at the present stage. Therefore, it is necessary to build an excellent machine translation model and detect its English grammatical errors so as to promote the further development of English translation [3].To solve this problem, reference [4] proposed a syntax error detection method based on deep learning. According to the characteristics of grammar error diagnosis and the problems of existing grammar error diagnosis methods, a model combining BI-LSM-ATT and CRF based on attention mechanism is proposed to study grammar error diagnosis. The model uses jieba word segmentation technology to preprocess data such as word segmentation and part of speech tagging and uses skip-Gram model to obtain word vector representation, which is used as the word embedding layer of the BI-LSTM-ATT model. The long-distance information in two directions is provided to the CRF model for sequence tagging, so as to obtain grammar error detection results. Reference [5] proposed a syntax error detection method based on data augmentation and replication. A copy mechanism is introduced into the self-attention model, and a new C-Transformer model is constructed. A text syntax error correction model from incorrect text sequence is constructed to correct text sequence. On the basis of public dataset, we use sequence to sequence learning to learn different forms of incorrect text from correct text and design a method of error text filtering based on smoothness, semantic and syntactic measures to obtain the result of grammar error detection. Reference [6] proposed a corpus-based English grammar error detection method. Compile corpus, and preprocess data, eliminate data noise, so as to obtain high-quality data. The preprocessed data are automatically segmented and marked with part of speech, and then the N-gram model is established to detect English grammar errors.However, the above methods have low accuracy, recall rate, andF1 value. In order to solve these problems, this paper constructed a new machine translation model and applied it to English grammar error detection. The practical application effect of the model was verified through experiments.Nowadays, the cross-language text processing mainly focuses on two directions, obtaining bilingual related links from parallel corpora or introducing feature information related to downstream tasks to strengthen the performance of text processing. The former needs a lot of annotation data, while the latter is suitable for specific downstream tasks, such as news topic classification and event detection, but cannot be extended to general tasks.In this paper, we proposed a novel machine translation model. The organization of the paper is introduced as follows. In section2, we give a detail introduction of the model, method, and technologies used in the model. In Section 3, we illustrate the English grammar error detection method proposed by us in detail. Section 4 shows the experiment of the paper and the corresponding results and we give the conclusion in Section 5.


## 2. Machine Translation Model Construction

In the framework of encoder and decoder, encoder, word alignment, and decoder are introduced, respectively. Decoders and encoders correspond to the processing process of source language and target language, respectively, and word alignment establishes the corresponding relationship between source language and target language [7]. For decoder and encoder, the common word vector generation and language model are introduced, respectively. And also in our model, we use the attention mechanism to implement the capture the corresponding attention weight relationship between multiple languages. However, unlike the encoder, the decoder ultimately needs to generate translation output, so an output module is added. The frame structure of the whole model is shown in Figure 1.Figure 1
Overall architecture of the translation model.The whole process is implemented under a large encoder-decoder framework. The word alignment module establishes the connection between them. The encoder has two parts: word vector generation and language model. Besides, the decoder also has an output module. The entire translation process starts from the encoder side, the encoder word vector generation module inputs the vector sequence and generates the corresponding source language words, and then the language model encoder generates the language model sequence. Finally, the output of the source-side language model is synthesized. The word vector module is the link between the encoder and the decoder. Before the decoder conducts operations to generate outputs, the word alignment calculates the correlation degree of each output step and each input of the encoder and carries out weighted sum, so as to further serve the language model part of the decoder [8]. Once the word alignment calculation is complete, the decoder side operation can be performed to generate the translation output. The decoder calculates the current moment language model according to the output of the word alignment module, the previous moment language model, and the word vector generation module and further calculates the translation result of the current moment based on this output. Finally, the model operation of word vector generation is carried out on the obtained translation output [9] to prepare for the output at the next moment, and English machine translation is realized through the output model.


### 2.1. Encoder-Decoder Framework

Since 2013, end-to-end framework pattern has gradually emerged in the field of neural machine translation, which realizes direct conversion from source language sequence to target language sequence. End-to-end neural machine translation completely eliminates the process of manual translation process design. For example, there are no separate processing processes such as word alignment and syntax tree, but a joint neural network is established to complete the processing of natural language tasks under the framework of encoder-decoder [10, 11]. The framework maps a given source language sentence to a dense and continuous vector through an encoder, and then a target language sentence from the source language vector through a decoder. This is a very bold new structure. It replaces the linear model in machine translation with nonlinear model, and there is no hidden structure pipeline, but a single complex neural network. Time series network models can also capture historical information without site. Figure 2 is the architecture of the encoder-decoder framework, and Figure 3 is the encoder-decoder frame diagram.Figure 2
The architecture of encoder-decoder.Figure 3
Frame diagram of encoder-decoder.As show in Figure2, there are 3 different parts in the model: the encoder, the intermediate (encoder) vector, and decoder. For the encoder, it is a stack of several recurrent units (LSTM or GRU cells for better performance) where each accepts a single element of the input sequence, collects information for that element, and propagates it forward. The hidden states depend not only on the previous hidden state, but also on the input vector of the previous layer. For the encode vector, it is the final hidden state produced from the encoder part of the model. This vector aims to encapsulate the information for all input elements in order to help the decoder make accurate predictions and it also acts as the initial hidden state of the decoder part of the model. For the decoder, it is a stack of several recurrent units where each unit predicts an output at a special time step. Each recurrent unit accepts a hidden state from the previous unit and produces and output as well as its own hidden state.As shown in Figure3, assuming that a Chinese source statement “today weather very good” is input, the model first generates word vectors for each word and then generates sentence vectors in sequence through the time series network model. The last symbol represents the sentence terminator. The part of the source language side that generates a vector representation of a dense and continuous sentence from the input corresponds to an encoder bias [12]. The target language end corresponds to the source language end, which has a similar structure with the encoder end and adopts the same RNN series network, but the purpose of the decoder end is to generate translation output. After the output statement “The weather today is good
,” the decoding part is complete. Since the model is sequential, the output of the current moment depends on the output information of the previous moment.


### 2.2. Word Vector Generation

Most of the distributed representation-based methods are word-level. Of course, the mainstream natural language processing first uses various word dividers to divide a sentence into words. However, this topic also involves a training method of character data. In order to optimize the training of such data, a word vector generation method based on recursive neural network (RNN) is proposed.RNN computes a variable length input vectorx to obtain hidden layer h and y vectors for alternative outputs. Every time t passes, the hidden layer ht of RNN will be updated iteratively according to the following formula [13]:(1)ht=fht−1,xt,where f represents an activation function, usually nonlinear, which can be a simple SigmoID function [14] or a complex long short-term memory network (LSTM) unit. Then, after repeated training of the next possible symbol in the sequence, RNN can automatically learn the corresponding probability distribution [15]. In this way, the output at t will be a conditional distribution pxt|xt−1,…,x1, as in formula (2), a one-hot polynomial distribution can use Softmax as the activation function.(2)pxt|xt−1,…,x1=expwjht∑j′=1Kexpwj′ht,where wjj=1,…,K is a row in the weight matrix W. By combining these probabilities, we can calculate the probability of the occurrence of a sequence x using the following formula:(3)px=∏t=1Tpxt|xt−1,x1.Then, the task of obtaining word vector can also be completed by extending the basic idea of RNN.hT, the hidden layer of the last step, at time T, is already a real vector, but it is not a word vector, and it is a vector representation of a sentence. If we save an additional download of ht of each time t and clear it as input for the next hidden layer, we get a chronological sequence of word vectors h1,…,hT. Of course, on closer inspection, this is equivalent to ht=fxt; in other words, a nonlinear transformation based on the one-Hot code. However, the general idea of this scheme is feasible. RNN is mainly used to generate vector representations, but it is only necessary to design how to selectively set ht to zero at the appropriate time.From a natural language perspective, clear zero can be understood as a cut word, which happens to be required for a model that takes character data as input. Then, a switch can be added to the neural network to output the segmented word vector and clear the information of the last word in time. The word vector generating unit at each timet, which is specific to an input sequence, will be expanded in the direction of the chronological order. Among them, h is the hidden layer unit of recursive neural network [16], and its basic recursion mode is the same as that of RNN. w is the switch used to control word segmentation, e is the output of word vector, and it is also subject to switch w, and this switch w will only and must clear h or e at the same time.The switch layerwt should also be related to fht−1,wi−1,xt, and the corresponding word vector generation method is shown as follows:(4)hi=tanhWhxi+Uhhi−1,(5)w¯i=σWwxi+Uwhi−1+Vwwi−1,(6)wi=0,ifwi,1≥wi,2,1,ifwi,1<wi,2,(7)eyi−1=wihi,(8)hi=1−wihi,where x=x1,…,xT,xt∈RKx, Kx is the dictionary size of the source language, and Tx is the sentence length of the source language and is generally not equal to different sentences, σ is the sigmoid activation function, Wh∈Rm×Kx, Uh∈Rm×m, Ww∈R2×K, Uw∈R2×m are the weight matrix, and m is the short vector dimension after word embedding. hi in formula (4) is the output of the original hidden layer, and hi=0⟶. wi in formula (5) can be understood as a switch to determine whether hi at time i is output, similar to the effect of dynamic word segmentation. To ensure that ei−1y does not contain information from the previous word, formula (8) is a further update operation for hi.


### 2.3. Encoder Language Model

NNLM was first systematically proposed and studied in depth by Bengio. The purpose of this algorithm is to predict the current word using the firstn − 1 lyrics of the current word. It should be noted that the purpose of splicing n − 1 vectors is to input the first n − 1 words of the current word as a vector. Of course, you can choose whether to do so or not. The advantage of this is that it is simple and straightforward, or you can choose to combine it into a matrix, even with convolutional neural networks and recursive neural networks. The dashed line input layer is directly connected to the output layer, so that the original input and the information of the hidden layer transformed by one layer are simultaneously used as the input of the output layer, which is equivalent to extending the basic features. The language model generation unit is shown in Figure 4.Figure 4
Language model generation unit.As shown in Figure4, when we read a sentence, we process each word accumulating information up to the end of the text. A system accumulating information composed of similar units repeated over time is a recurrent neural network (RNN) in the deep learning field. In general, a text encoder turns text into a numeric representation. This task can be implemented in many different ways but what we mean by encoders are RNN encoders. Here, xi denotes the input sentences and is formulated as a work vector, the hidden state vector hi contains the sequence state before the current block, Wx are the weights between xi and hi, Wh are the weights between hi+1 and hi, Wy are the weights between hi and oi, and oi is the output vector which is not always produced by each block.Although two control gates and one output gate are simply added, RNN does not have this function by comparison. The following is the specific language model generation formula.(9)z⟶i=σW⟶zeix+U⟶zs⟶i−1,(10)r⟶i=σW⟶reix+U⟶rs⟶i−1,(11)g⟶i′=tanhW⟶geix+U⟶gr⟶i∘g⟶i−1,(12)g⟶i=1−z⟶i∘g⟶i−1+z⟶i∘g⟶i,(13)s⟶i=σW⟶seix+U⟶ss⟶i−1∘tanhg⟶i.Among them,eix∈Rm is the m-dimensional word embedding vector embedded into vector module, and W⟶z,W⟶r,W⟶g∈Rn×m weight matrix, and g0=0,S0=0, formula (9) in zi is updated, formula (10) in ri is reset, the former allows each hidden unit to maintain their previous activated state, while the latter controls what information and how much information need to reset from the previous state. si in formula (13) is the output gate, which is an improvement on the GRU model. At different times t, each hidden layer unit has its own reset, update, and output gates that capture dependencies at different time scales. The reset gate is activated frequently when the hidden layer unit attempts to capture short-term memory; the same is true of renewal gates, which tend to capture long-term memories.


### 2.4. Decoder Language Model

Since it is a machine translation system, there are two relative natural languages, in other words, two relatively independent language models. Through the improved bidirectional GRU in the encoder, the hidden layer sequences is obtained. The same decoding module s also has a similar GRU structure. There is no need to add an output gate because this function has been reflected in the output module. But if this is all, there will be no connection between encoder and decoder, and there will be no translation process. Therefore, in the calculation process of decoder module s′, c containing encoding module information is also added. Here, c can be temporarily regarded as all or part of the source language information, and the specific definition of c will be given in the word alignment model. Therefore, the specific generation algorithm of the language model in the decoder is as follows:(14)zi=σWzei−1y+Uzsi−1′+Czci,ri=σWrei−1y+Ursi−1′+Crci,s¯i′=tanhWsei−1y+Usri∘si−1′s′i−1+Csci,si′=1−zi∘si−1′+zi∘si′,where eiy∈Rm is the m-dimensional word embedding vector of the target language, that is, the result generated by the language model; ∘ is the dot product calculation; Wz,Wr,Ws∈Rn×m, Uz,Ur,Us∈Rn×n, and Cz,Cr,Cs∈Rn×n′ are the weight matrix; s0′=tanhVss⟶1, and the decoder part does not need to calculate the bidirectional language model because it further serves the output module, so as to output the translated target language sequence in turn.


### 2.5. Word Alignment Based on Global Information

Word alignment is the most fundamental problem in neural machine translation. Most neural machine translation problems are based on encoder-decoder framework, encoding and decoding corresponding to the source language and target language, respectively. But if the two parts are clearly separated in this way, then the source language and the target language will no longer have any connection, and there will be no translation problem. Word alignment is to establish the connection between the source language end and the target language end, learn the corresponding relationship between the source language and the target language from the parallel corpus, and further learn the translation rules on this basis, so as to complete the training of neural machine translation model. Therefore, word alignment plays an important role in the final result of neural machine translation system. Based on the attention mechanism, this paper uses a global word alignment method by integrating historical information.Because the two-way loop network is used in the language model design, language translation is uncertain. The words each decoder outputs now depend on a weighted combination of all the input states, not just the last state. Weights determine how much each input state contributes to the output state. Therefore, if the weight is large, it means that the decoder will pay more attention to the corresponding part in the original sentence when generating the current word of the translation. The result of the weight sum is usually normalized to 1 (which is a distribution of the input states).Weights are usually calculated from the output of the language model on the source side and the information of the hidden layer at the last moment on the target side. However, the weight is relative, so its calculation should not only be affected by the above two factors, but also related to the historical information of the weight. The corresponding calculation methods are shown in formulas (15) to (20).(15)eij=VaTtanhWasi−1y+Uasjx,where Va, Wa, and Ua represent the weight matrix; si−1y represents the output of the language model at the target language side at the previous moment; and sjx represents the output of the source language-side language model:(16)bijh=∑i=1t−1expeij,(17)bij=expeijbijh,(18)αij=bij∑k=1Tkbik,(19)αij=bij∑k=1Tkbik,(20)ci=∑j=1Txαijsj,(21)ρX,Y=covX,YσXσY=EX−μXY−μYσXσY=EXY−EXEYN∑X2−∑X2N∑Y2−∑Y2.In the calculation of attention, it is necessary to calculate the degree of correlation between each source language word and each target language word.During the training phase, the model’s parameter, such as the weights and the basis, is initialized according to a standard Gaussian distribution, which means that the mean value of the weights is 0 and the standard deviation of the weights is 1. The basis of the model is initialized to be all zeros.


### 2.6. Output Module

As for decoders, we introduced the common word vector generation and language model of encoder-decoders in the previous part. Decoders differ from encoders in that a final output is necessary for the decoder to achieve supervised learning. However, the previous section alone does not produce translation output. Therefore, the model finally adds an output module for supervised learning, so that effective translation results can be obtained in the end.In order to obtain the translation result, the resultei−1y of the word vector module at the decoder side, the result eiy generated by the language model, and the source language information ci generated by word alignment should be fused at every moment before the generation of terminators. The calculation method of the output module is shown in formulas (21) to (23).(22)t¯i=σWiei−1y+Uisiy+Cici,(23)ti=maxtt,2j−1,tt,2j,j=1,2,…,l,(24)pyi|ei−1y,siy,ci=yiTsoftmaxVpti,where Wt, Ut, Ct, and Vp represent the weight matrix, and the dimensions are 2l∗m, 2l∗n, 2l∗n′, and ky∗l, respectively. max represents nonlinear activation function; soft max represents the activation function.


### 2.7. Attention Mechanism

Attention mechanism is a mechanism used in encoder-decoder structure [17]. Now it has been used in a variety of tasks, including machine translation, image description, and text summarization. It is no longer limited to encoder-decoder structure [18]. A variety of variant attention structures are applied in various tasks. In general, the application of attention mechanism includes the following:(1)
Allowing the decoder to pay attention to the information it needs in multiple vectors in the sequence is the use of the traditional attention mechanism. Because the encoder multistep output is used instead of a single certain length vector of the corresponding step, more information is retained.(2)
Acting on the encoder to solve the representation problem (for example, encoding vector is used as the input of other models), self-attention [19] is generally used.


## 2.1. Encoder-Decoder Framework

Since 2013, end-to-end framework pattern has gradually emerged in the field of neural machine translation, which realizes direct conversion from source language sequence to target language sequence. End-to-end neural machine translation completely eliminates the process of manual translation process design. For example, there are no separate processing processes such as word alignment and syntax tree, but a joint neural network is established to complete the processing of natural language tasks under the framework of encoder-decoder [10, 11]. The framework maps a given source language sentence to a dense and continuous vector through an encoder, and then a target language sentence from the source language vector through a decoder. This is a very bold new structure. It replaces the linear model in machine translation with nonlinear model, and there is no hidden structure pipeline, but a single complex neural network. Time series network models can also capture historical information without site. Figure 2 is the architecture of the encoder-decoder framework, and Figure 3 is the encoder-decoder frame diagram.Figure 2
The architecture of encoder-decoder.Figure 3
Frame diagram of encoder-decoder.As show in Figure2, there are 3 different parts in the model: the encoder, the intermediate (encoder) vector, and decoder. For the encoder, it is a stack of several recurrent units (LSTM or GRU cells for better performance) where each accepts a single element of the input sequence, collects information for that element, and propagates it forward. The hidden states depend not only on the previous hidden state, but also on the input vector of the previous layer. For the encode vector, it is the final hidden state produced from the encoder part of the model. This vector aims to encapsulate the information for all input elements in order to help the decoder make accurate predictions and it also acts as the initial hidden state of the decoder part of the model. For the decoder, it is a stack of several recurrent units where each unit predicts an output at a special time step. Each recurrent unit accepts a hidden state from the previous unit and produces and output as well as its own hidden state.As shown in Figure3, assuming that a Chinese source statement “today weather very good” is input, the model first generates word vectors for each word and then generates sentence vectors in sequence through the time series network model. The last symbol represents the sentence terminator. The part of the source language side that generates a vector representation of a dense and continuous sentence from the input corresponds to an encoder bias [12]. The target language end corresponds to the source language end, which has a similar structure with the encoder end and adopts the same RNN series network, but the purpose of the decoder end is to generate translation output. After the output statement “The weather today is good
,” the decoding part is complete. Since the model is sequential, the output of the current moment depends on the output information of the previous moment.


## 2.2. Word Vector Generation

Most of the distributed representation-based methods are word-level. Of course, the mainstream natural language processing first uses various word dividers to divide a sentence into words. However, this topic also involves a training method of character data. In order to optimize the training of such data, a word vector generation method based on recursive neural network (RNN) is proposed.RNN computes a variable length input vectorx to obtain hidden layer h and y vectors for alternative outputs. Every time t passes, the hidden layer ht of RNN will be updated iteratively according to the following formula [13]:(1)ht=fht−1,xt,where f represents an activation function, usually nonlinear, which can be a simple SigmoID function [14] or a complex long short-term memory network (LSTM) unit. Then, after repeated training of the next possible symbol in the sequence, RNN can automatically learn the corresponding probability distribution [15]. In this way, the output at t will be a conditional distribution pxt|xt−1,…,x1, as in formula (2), a one-hot polynomial distribution can use Softmax as the activation function.(2)pxt|xt−1,…,x1=expwjht∑j′=1Kexpwj′ht,where wjj=1,…,K is a row in the weight matrix W. By combining these probabilities, we can calculate the probability of the occurrence of a sequence x using the following formula:(3)px=∏t=1Tpxt|xt−1,x1.Then, the task of obtaining word vector can also be completed by extending the basic idea of RNN.hT, the hidden layer of the last step, at time T, is already a real vector, but it is not a word vector, and it is a vector representation of a sentence. If we save an additional download of ht of each time t and clear it as input for the next hidden layer, we get a chronological sequence of word vectors h1,…,hT. Of course, on closer inspection, this is equivalent to ht=fxt; in other words, a nonlinear transformation based on the one-Hot code. However, the general idea of this scheme is feasible. RNN is mainly used to generate vector representations, but it is only necessary to design how to selectively set ht to zero at the appropriate time.From a natural language perspective, clear zero can be understood as a cut word, which happens to be required for a model that takes character data as input. Then, a switch can be added to the neural network to output the segmented word vector and clear the information of the last word in time. The word vector generating unit at each timet, which is specific to an input sequence, will be expanded in the direction of the chronological order. Among them, h is the hidden layer unit of recursive neural network [16], and its basic recursion mode is the same as that of RNN. w is the switch used to control word segmentation, e is the output of word vector, and it is also subject to switch w, and this switch w will only and must clear h or e at the same time.The switch layerwt should also be related to fht−1,wi−1,xt, and the corresponding word vector generation method is shown as follows:(4)hi=tanhWhxi+Uhhi−1,(5)w¯i=σWwxi+Uwhi−1+Vwwi−1,(6)wi=0,ifwi,1≥wi,2,1,ifwi,1<wi,2,(7)eyi−1=wihi,(8)hi=1−wihi,where x=x1,…,xT,xt∈RKx, Kx is the dictionary size of the source language, and Tx is the sentence length of the source language and is generally not equal to different sentences, σ is the sigmoid activation function, Wh∈Rm×Kx, Uh∈Rm×m, Ww∈R2×K, Uw∈R2×m are the weight matrix, and m is the short vector dimension after word embedding. hi in formula (4) is the output of the original hidden layer, and hi=0⟶. wi in formula (5) can be understood as a switch to determine whether hi at time i is output, similar to the effect of dynamic word segmentation. To ensure that ei−1y does not contain information from the previous word, formula (8) is a further update operation for hi.


## 2.3. Encoder Language Model

NNLM was first systematically proposed and studied in depth by Bengio. The purpose of this algorithm is to predict the current word using the firstn − 1 lyrics of the current word. It should be noted that the purpose of splicing n − 1 vectors is to input the first n − 1 words of the current word as a vector. Of course, you can choose whether to do so or not. The advantage of this is that it is simple and straightforward, or you can choose to combine it into a matrix, even with convolutional neural networks and recursive neural networks. The dashed line input layer is directly connected to the output layer, so that the original input and the information of the hidden layer transformed by one layer are simultaneously used as the input of the output layer, which is equivalent to extending the basic features. The language model generation unit is shown in Figure 4.Figure 4
Language model generation unit.As shown in Figure4, when we read a sentence, we process each word accumulating information up to the end of the text. A system accumulating information composed of similar units repeated over time is a recurrent neural network (RNN) in the deep learning field. In general, a text encoder turns text into a numeric representation. This task can be implemented in many different ways but what we mean by encoders are RNN encoders. Here, xi denotes the input sentences and is formulated as a work vector, the hidden state vector hi contains the sequence state before the current block, Wx are the weights between xi and hi, Wh are the weights between hi+1 and hi, Wy are the weights between hi and oi, and oi is the output vector which is not always produced by each block.Although two control gates and one output gate are simply added, RNN does not have this function by comparison. The following is the specific language model generation formula.(9)z⟶i=σW⟶zeix+U⟶zs⟶i−1,(10)r⟶i=σW⟶reix+U⟶rs⟶i−1,(11)g⟶i′=tanhW⟶geix+U⟶gr⟶i∘g⟶i−1,(12)g⟶i=1−z⟶i∘g⟶i−1+z⟶i∘g⟶i,(13)s⟶i=σW⟶seix+U⟶ss⟶i−1∘tanhg⟶i.Among them,eix∈Rm is the m-dimensional word embedding vector embedded into vector module, and W⟶z,W⟶r,W⟶g∈Rn×m weight matrix, and g0=0,S0=0, formula (9) in zi is updated, formula (10) in ri is reset, the former allows each hidden unit to maintain their previous activated state, while the latter controls what information and how much information need to reset from the previous state. si in formula (13) is the output gate, which is an improvement on the GRU model. At different times t, each hidden layer unit has its own reset, update, and output gates that capture dependencies at different time scales. The reset gate is activated frequently when the hidden layer unit attempts to capture short-term memory; the same is true of renewal gates, which tend to capture long-term memories.


## 2.4. Decoder Language Model

Since it is a machine translation system, there are two relative natural languages, in other words, two relatively independent language models. Through the improved bidirectional GRU in the encoder, the hidden layer sequences is obtained. The same decoding module s also has a similar GRU structure. There is no need to add an output gate because this function has been reflected in the output module. But if this is all, there will be no connection between encoder and decoder, and there will be no translation process. Therefore, in the calculation process of decoder module s′, c containing encoding module information is also added. Here, c can be temporarily regarded as all or part of the source language information, and the specific definition of c will be given in the word alignment model. Therefore, the specific generation algorithm of the language model in the decoder is as follows:(14)zi=σWzei−1y+Uzsi−1′+Czci,ri=σWrei−1y+Ursi−1′+Crci,s¯i′=tanhWsei−1y+Usri∘si−1′s′i−1+Csci,si′=1−zi∘si−1′+zi∘si′,where eiy∈Rm is the m-dimensional word embedding vector of the target language, that is, the result generated by the language model; ∘ is the dot product calculation; Wz,Wr,Ws∈Rn×m, Uz,Ur,Us∈Rn×n, and Cz,Cr,Cs∈Rn×n′ are the weight matrix; s0′=tanhVss⟶1, and the decoder part does not need to calculate the bidirectional language model because it further serves the output module, so as to output the translated target language sequence in turn.


## 2.5. Word Alignment Based on Global Information

Word alignment is the most fundamental problem in neural machine translation. Most neural machine translation problems are based on encoder-decoder framework, encoding and decoding corresponding to the source language and target language, respectively. But if the two parts are clearly separated in this way, then the source language and the target language will no longer have any connection, and there will be no translation problem. Word alignment is to establish the connection between the source language end and the target language end, learn the corresponding relationship between the source language and the target language from the parallel corpus, and further learn the translation rules on this basis, so as to complete the training of neural machine translation model. Therefore, word alignment plays an important role in the final result of neural machine translation system. Based on the attention mechanism, this paper uses a global word alignment method by integrating historical information.Because the two-way loop network is used in the language model design, language translation is uncertain. The words each decoder outputs now depend on a weighted combination of all the input states, not just the last state. Weights determine how much each input state contributes to the output state. Therefore, if the weight is large, it means that the decoder will pay more attention to the corresponding part in the original sentence when generating the current word of the translation. The result of the weight sum is usually normalized to 1 (which is a distribution of the input states).Weights are usually calculated from the output of the language model on the source side and the information of the hidden layer at the last moment on the target side. However, the weight is relative, so its calculation should not only be affected by the above two factors, but also related to the historical information of the weight. The corresponding calculation methods are shown in formulas (15) to (20).(15)eij=VaTtanhWasi−1y+Uasjx,where Va, Wa, and Ua represent the weight matrix; si−1y represents the output of the language model at the target language side at the previous moment; and sjx represents the output of the source language-side language model:(16)bijh=∑i=1t−1expeij,(17)bij=expeijbijh,(18)αij=bij∑k=1Tkbik,(19)αij=bij∑k=1Tkbik,(20)ci=∑j=1Txαijsj,(21)ρX,Y=covX,YσXσY=EX−μXY−μYσXσY=EXY−EXEYN∑X2−∑X2N∑Y2−∑Y2.In the calculation of attention, it is necessary to calculate the degree of correlation between each source language word and each target language word.During the training phase, the model’s parameter, such as the weights and the basis, is initialized according to a standard Gaussian distribution, which means that the mean value of the weights is 0 and the standard deviation of the weights is 1. The basis of the model is initialized to be all zeros.


## 2.6. Output Module

As for decoders, we introduced the common word vector generation and language model of encoder-decoders in the previous part. Decoders differ from encoders in that a final output is necessary for the decoder to achieve supervised learning. However, the previous section alone does not produce translation output. Therefore, the model finally adds an output module for supervised learning, so that effective translation results can be obtained in the end.In order to obtain the translation result, the resultei−1y of the word vector module at the decoder side, the result eiy generated by the language model, and the source language information ci generated by word alignment should be fused at every moment before the generation of terminators. The calculation method of the output module is shown in formulas (21) to (23).(22)t¯i=σWiei−1y+Uisiy+Cici,(23)ti=maxtt,2j−1,tt,2j,j=1,2,…,l,(24)pyi|ei−1y,siy,ci=yiTsoftmaxVpti,where Wt, Ut, Ct, and Vp represent the weight matrix, and the dimensions are 2l∗m, 2l∗n, 2l∗n′, and ky∗l, respectively. max represents nonlinear activation function; soft max represents the activation function.


## 2.7. Attention Mechanism

Attention mechanism is a mechanism used in encoder-decoder structure [17]. Now it has been used in a variety of tasks, including machine translation, image description, and text summarization. It is no longer limited to encoder-decoder structure [18]. A variety of variant attention structures are applied in various tasks. In general, the application of attention mechanism includes the following:(1)
Allowing the decoder to pay attention to the information it needs in multiple vectors in the sequence is the use of the traditional attention mechanism. Because the encoder multistep output is used instead of a single certain length vector of the corresponding step, more information is retained.(2)
Acting on the encoder to solve the representation problem (for example, encoding vector is used as the input of other models), self-attention [19] is generally used.


## 3. English Grammar Error Detection

### 3.1. Model Training

When training the model, first parse each sentence in the corpus, generate short sentences according to the method of generating clauses in the machine translation model constructed above, and save all clauses at all levels into a new corpus. This parsed corpus is then processed by a machine translation model generation tool to generate statistical information. Finally, the machine translation model is stored in a database for searching.The training process of machine translation model is as follows. Firstly, every sentence in the corpus is analyzed, and hierarchical clauses are generated and put into hierarchical clause set. The probability information of the clause set, namely, the tuple probability table, is generated by the machine translation model tuple probability generation tool and stored in the database for query. The corpus used in this paper is the whole corpus of Yahoo N-gram corpus, the corpus dependency analysis tool uses Stanford Parser, the machine translation model tuple probability generation tool uses Berkeley LM, and the smoothing method uses Kneser–Ney smoothing. The machine translation model has a high requirement for memory during the training process. Low memory settings will take a long time and are prone to error, so more memory will be allocated in general. In this article, the machine translation model training tool uses Berkeley LM to generate ternary models.


### 3.2. Dependency Analysis and Generation of Alternative Words

Since the machine translation model in this paper is a language model generated by dependency analysis, a sentence to be corrected needs to go through dependency analysis to generate hierarchical structure and then use statistical information generated by the corpus to correct grammatical errors. Errors in the use of words can generally be divided into two types: spelling errors and correct spelling but not in accordance with the context of the true word errors. Spelling errors can be searched using Lucene’s SpellChecker dictionary feature. That is, typing in a word returns a set of edit-close words in a preprepared dictionary, which can consist of tuples of words from the Yahoo N-gram corpus that Berkeley LM has trained.True word errors need to be considered separately. In the determiner errors, this paper deals with the use of “the,” “a,” and “an” separately. When these three words appear, they are alternatives to each other. The alternative of prepositions is similar. This paper only deals with the most common prepositions, that is, “in,” “on,” “to,” “of,” and “for” are alternatives to each other.For obtaining other alternative words, this article uses the functions provided in Freeling. Freeling can perform word state analysis on a given word and extract related words with the same stem as generated words. These related words are used as alternatives in this paper. Such errors as verb morphology and noun singular and plural and subject-verb consistency can be provided by this method for English grammatical error detection.


### 3.3. Error Correction Decoding Algorithm

Consider sentences with only two levels of nodes. Let the sentence length be n, i.e., only dominant words) and 33 subordinate words, and there are no subordinate words under these n−1, n−1 subordinate words. There is only one hierarchical clause in this sentence after dependency analysis, and the order of the words in the hierarchical clause is consistent with the original sentence. Using the ternary language model in this paper, the probability calculation method of sentences is as follows:(25)ps=∏i=1npwi|wi−1,wi−2.Here, we use formula (25) to calculate the probability of the sentence s, which depends on the previous weights’ information of the model, and the probability of the sentence is also assumed conditionally independent requirements.Assuming that the root of the hierarchical clause is a certain word, but there are multiple alternative leaves, the decoding sequence with the highest probability can be obtained through the Viterbi algorithm. The maximum probability of defining this decoding sequence is the score of the hierarchical clause with the root ofn, that is, subScoren.To unify the process, more generally the leaf is also defined as the root of a tree, and if this leaf is set tow, the trees that define its alternatives all score subScore.Generally speaking, a sentence may have multiple levels after parsing, so the score defining this tree can be recursively defined as: the score of the first-level clause multiplied by the score of each subtree formed by nonroot nodes in the first-level clause. Let the word order of the first-level subtree be listed assubSeq=c1,…,ckrck−1,…,cn−1, where r is the root of the whole sentence and c is the other n−1 nodes dependent on the head node, namely,(26)ps=subScorer=psubSeq∏i=1n−1subScoreci.Combined with the above analysis results, the English grammar error detection process is mainly composed of three processes: dependency analysis to generate hierarchical clauses, generation of alternative words, and finally language model decoding to generate English grammar error detection results. The overall process is shown in Figure5.Figure 5
Flowchart of English grammar error detection.The program starts by reading a statement from the text, dividing the statement into words, then obtaining the dependencies of each word, and recombining to generate hierarchical clauses. Then the candidate word tool is used to obtain the candidate word for each word, and the decoding process of the machine translation model begins. The decoding process starts with the topmost clause and, using the probabilities calculated by the machine translation model, computes and retains the maximum probability path for a series of words in their current position. Because each word may have a modification part, this process needs to carry out recursive calculation, according to the result of recursive calculation to achieve English grammar error detection.


## 3.1. Model Training

When training the model, first parse each sentence in the corpus, generate short sentences according to the method of generating clauses in the machine translation model constructed above, and save all clauses at all levels into a new corpus. This parsed corpus is then processed by a machine translation model generation tool to generate statistical information. Finally, the machine translation model is stored in a database for searching.The training process of machine translation model is as follows. Firstly, every sentence in the corpus is analyzed, and hierarchical clauses are generated and put into hierarchical clause set. The probability information of the clause set, namely, the tuple probability table, is generated by the machine translation model tuple probability generation tool and stored in the database for query. The corpus used in this paper is the whole corpus of Yahoo N-gram corpus, the corpus dependency analysis tool uses Stanford Parser, the machine translation model tuple probability generation tool uses Berkeley LM, and the smoothing method uses Kneser–Ney smoothing. The machine translation model has a high requirement for memory during the training process. Low memory settings will take a long time and are prone to error, so more memory will be allocated in general. In this article, the machine translation model training tool uses Berkeley LM to generate ternary models.


## 3.2. Dependency Analysis and Generation of Alternative Words

Since the machine translation model in this paper is a language model generated by dependency analysis, a sentence to be corrected needs to go through dependency analysis to generate hierarchical structure and then use statistical information generated by the corpus to correct grammatical errors. Errors in the use of words can generally be divided into two types: spelling errors and correct spelling but not in accordance with the context of the true word errors. Spelling errors can be searched using Lucene’s SpellChecker dictionary feature. That is, typing in a word returns a set of edit-close words in a preprepared dictionary, which can consist of tuples of words from the Yahoo N-gram corpus that Berkeley LM has trained.True word errors need to be considered separately. In the determiner errors, this paper deals with the use of “the,” “a,” and “an” separately. When these three words appear, they are alternatives to each other. The alternative of prepositions is similar. This paper only deals with the most common prepositions, that is, “in,” “on,” “to,” “of,” and “for” are alternatives to each other.For obtaining other alternative words, this article uses the functions provided in Freeling. Freeling can perform word state analysis on a given word and extract related words with the same stem as generated words. These related words are used as alternatives in this paper. Such errors as verb morphology and noun singular and plural and subject-verb consistency can be provided by this method for English grammatical error detection.


## 3.3. Error Correction Decoding Algorithm

Consider sentences with only two levels of nodes. Let the sentence length be n, i.e., only dominant words) and 33 subordinate words, and there are no subordinate words under these n−1, n−1 subordinate words. There is only one hierarchical clause in this sentence after dependency analysis, and the order of the words in the hierarchical clause is consistent with the original sentence. Using the ternary language model in this paper, the probability calculation method of sentences is as follows:(25)ps=∏i=1npwi|wi−1,wi−2.Here, we use formula (25) to calculate the probability of the sentence s, which depends on the previous weights’ information of the model, and the probability of the sentence is also assumed conditionally independent requirements.Assuming that the root of the hierarchical clause is a certain word, but there are multiple alternative leaves, the decoding sequence with the highest probability can be obtained through the Viterbi algorithm. The maximum probability of defining this decoding sequence is the score of the hierarchical clause with the root ofn, that is, subScoren.To unify the process, more generally the leaf is also defined as the root of a tree, and if this leaf is set tow, the trees that define its alternatives all score subScore.Generally speaking, a sentence may have multiple levels after parsing, so the score defining this tree can be recursively defined as: the score of the first-level clause multiplied by the score of each subtree formed by nonroot nodes in the first-level clause. Let the word order of the first-level subtree be listed assubSeq=c1,…,ckrck−1,…,cn−1, where r is the root of the whole sentence and c is the other n−1 nodes dependent on the head node, namely,(26)ps=subScorer=psubSeq∏i=1n−1subScoreci.Combined with the above analysis results, the English grammar error detection process is mainly composed of three processes: dependency analysis to generate hierarchical clauses, generation of alternative words, and finally language model decoding to generate English grammar error detection results. The overall process is shown in Figure5.Figure 5
Flowchart of English grammar error detection.The program starts by reading a statement from the text, dividing the statement into words, then obtaining the dependencies of each word, and recombining to generate hierarchical clauses. Then the candidate word tool is used to obtain the candidate word for each word, and the decoding process of the machine translation model begins. The decoding process starts with the topmost clause and, using the probabilities calculated by the machine translation model, computes and retains the maximum probability path for a series of words in their current position. Because each word may have a modification part, this process needs to carry out recursive calculation, according to the result of recursive calculation to achieve English grammar error detection.


## 4. Experimental Results and Analysis

### 4.1. Experimental Design

#### 4.1.1. Experimental Data

Experimental data came from GEC evaluation task of CONLL2013. Statistical results of training data and test data are shown in Table1. The test data were divided into two parts with the same number of sentences: long and short.Table 1
Details of training data and test data.
Wrong typeTraining setTest setAmountProportionAmountProportionArticles665814.869019.9Prepositions24045.33129.0Noun37798.439611.4Subject-predicate agreement14533.21223.5Verb forms15273.41243.6Total error data1582135.1164447.4Total data45106—3470—


#### 4.1.2. Corpus

This corpus is from Yahoo N-gram (version 2.0;n = 1, 2, 3, 4, 5). The N-gram corpus is based on news from 12,000 news websites, with 14.6 million articles, 126 million sentences, and 3.4 billion words. This corpus does not contain the original corpus article itself, but only contains N-gram fragments that appear at least twice. Due to the large scale of N-gram language model, in order to improve the retrieval efficiency, this paper uses the open-source search engine Apache Solr to build index and search services for it. The preprocessing procedure is illustrated in Figure 6.Figure 6
The preprocessing procedure of the corpus.


#### 4.1.3. Evaluation Indicators

The evaluation of experimental results was based on CONLL2013 evaluation standard, and accuracyP, recall R, and F1 values were adopted, which were defined as follows:(27)P=NcorrectNpredicted,R=NcorrectNtarget,F1=2⋅P⋅RP+R,where Ncorrect, Npredicted, and Ntarget, respectively, refer to the number of correct corrections, the number of corrected errors, and the number of errors that should have existed.The syntax error detection method based on deep learning, the syntax error detection method based on data augmentation and replication, and the proposed method are used as experimental comparison methods to verify the application effects of different methods by comparing different indicators.


### 4.2. Analysis of Experimental Results

#### 4.2.1. Short Test Set

The English grammar error detection results of the syntax error detection method based on deep learning, the syntax error detection method based on data augmentation and replication, and the method in this paper based on the short test set are shown in Tables2 to 4.Table 2
Comparison results of recall rates.
Wrong typeSyntax error detection method based on deep learningSyntax error detection method based on data augmentation and replicationModel without attention mechanismPaper methodArticles0.31110.26010.30210.3345Prepositions0.05740.04520.06130.0778Noun0.27570.29970.31010.3213Verb0.15990.23020.22580.2704Subject-predicate agreement0.14020.25020.21070.3014Table 3
Comparison results of accuracy rates.
Wrong typeSyntax error detection method based on deep learningSyntax error detection method based on data augmentation and replicationModel without attention mechanismPaper methodArticles0.50320.47320.45120.5103Prepositions0.16790.15100.14230.1677Noun0.52680.40880.51120.5288Verb0.25950.22010.24980.2813Subject-predicate agreement0.22950.24010.27650.3122Table 4
Comparison results ofF1 values.
Wrong typeSyntax error detection method based on deep learningSyntax error detection method based on data augmentation and replicationModel without attention mechanismPaper methodArticles0.39100.33570.37450.4041Prepositions0.08520.07300.10050.1062Noun0.34010.34580.38490.4131Verb0.19850.22500.24510.2757Subject-predicate agreement0.17490.24500.26950.3067For article errors, the accuracy, recall rate, and F1 value of the proposed method are 2.34% and 7.44% higher than those based on deep learning, 0.71% and 3.71% higher than those based on data augments and replication, respectively, and theF1 value is 1.3% and 6.84% higher.For preposition errors, the accuracy andF1 values of the proposed method are both higher than those of deep learning-based grammar error detection method and data augmentation and replication method, which are 3.26% and 2.04%, and 2.1% and 3.32%, respectively, and the recall rate is 0.02% lower than that of deep learning-based grammar error detection method. Syntax error detection method based on data enhancement and replication reached 1.67%.For noun errors, the accuracy, recall rate, andF1 value of the proposed method are 4.56% and 2.16% higher than those based on deep learning, 2% and 12% higher than those based on data enhancement and replication, and 7.3% and 6.73% higher than those based on data enhancement and replication, respectively.For verb errors, the accuracy, recall rate, andF1 value of the proposed method are 11.05% and 4.02%, 2.18% and 6.12%, and 7.72% and 5.07% higher than those based on deep learning and data augments and replication, respectively.For subject-verb-induced errors, the accuracy, recall rate, andF1 values of the proposed method are 16.12% and 5.12% higher than those of the deep learning-based method, 8.27% and 7.21% higher than those of the data augment-based method and replication method, and 13.18% and 6.7% higher than those of the deep learning-based method and data augment-based method, respectively.


#### 4.2.2. Long Test Set

The English grammar error detection results of the syntax error detection method based on deep learning, the syntax error detection method based on data augmentation and replication, and the method in this paper based on the long test set are shown in Tables5 to 7.Table 5
Comparison results of recall rates.
Wrong typeSyntax error detection method based on deep learningSyntax error detection method based on data augmentation and replicationModel without attention mechanismPaper methodArticles0.26970.25970.33210.3415Prepositions0.04720.05070.0520.0781Noun0.23150.33210.29830.3516Verb0.15130.25210.27450.2913Subject-predicate agreement0.11020.27120.290.3219Table 6
Comparison results of accuracy rates.
Wrong typeSyntax error detection method based on deep learningSyntax error detection method based on data augmentation and replicationModel without attention mechanismPaper methodArticles0.47420.47510.50120.5134Prepositions0.15900.16080.16580.1727Noun0.45330.46010.52880.5318Verb0.22010.25950.20320.3123Subject-predicate agreement0.19950.27320.330.3312Table 7
Comparison results ofF1 values.
Wrong typeSyntax error detection method based on deep learningSyntax error detection method based on data augmentation and replicationModel without attention mechanismPaper methodArticles0.34380.33560.40230.4102Prepositions0.07300.08470.1050.1076Noun0.30640.38290.4140.4233Verb0.17980.25530.2980.3014Subject-predicate agreement0.17490.27220.31320.3265As shown in Tables4–7, for article errors, the accuracy, recall rate, and F1 value of the proposed method are 7.18% and 8.18% higher than those of the grammar error detection method based on deep learning and the grammar error detection method based on data augmentation and replication, respectively, and the recall rate is 3.92% and 3.83% higher. F1 values were 6.64 and 7.46% higher.For preposition errors, the accuracy, recall rate, andF1 value of the proposed method are higher than those of deep learning-based grammar error detection method and data augmentation and replication-based grammar error detection method, which are 3.09% and 2.74%, 1.37% and 1.19%, and 3.46% and 2.3%, respectively.For noun errors, the accuracy, recall rate, andF1 value of the proposed method are 12.01% and 1.95% higher than those of the deep learning-based method, 7.85% and 7.17% higher than those of the method based on data augment and replication, and 11.69% and 4.0% higher than those of the method based on data augmentation and replication, respectively.For verb errors, the accuracy, recall rate, andF1 values are higher than those of deep learning-based grammar error detection method and data augmentation and replication-based grammar error detection method, respectively, by 14% and 3.92%, 9.22% and 5.28%, and 12.6% and 4.61%.For subject-predicate agreement errors, the accuracy, recall rate, andF1 value of the proposed method are 22.17% and 5.07%, 13.17% and 5.8%, and 15.16% and 5.43% higher than those based on deep learning and data augmentation and replication, respectively.


## 4.1. Experimental Design

### 4.1.1. Experimental Data

Experimental data came from GEC evaluation task of CONLL2013. Statistical results of training data and test data are shown in Table1. The test data were divided into two parts with the same number of sentences: long and short.Table 1
Details of training data and test data.
Wrong typeTraining setTest setAmountProportionAmountProportionArticles665814.869019.9Prepositions24045.33129.0Noun37798.439611.4Subject-predicate agreement14533.21223.5Verb forms15273.41243.6Total error data1582135.1164447.4Total data45106—3470—


### 4.1.2. Corpus

This corpus is from Yahoo N-gram (version 2.0;n = 1, 2, 3, 4, 5). The N-gram corpus is based on news from 12,000 news websites, with 14.6 million articles, 126 million sentences, and 3.4 billion words. This corpus does not contain the original corpus article itself, but only contains N-gram fragments that appear at least twice. Due to the large scale of N-gram language model, in order to improve the retrieval efficiency, this paper uses the open-source search engine Apache Solr to build index and search services for it. The preprocessing procedure is illustrated in Figure 6.Figure 6
The preprocessing procedure of the corpus.


### 4.1.3. Evaluation Indicators

The evaluation of experimental results was based on CONLL2013 evaluation standard, and accuracyP, recall R, and F1 values were adopted, which were defined as follows:(27)P=NcorrectNpredicted,R=NcorrectNtarget,F1=2⋅P⋅RP+R,where Ncorrect, Npredicted, and Ntarget, respectively, refer to the number of correct corrections, the number of corrected errors, and the number of errors that should have existed.The syntax error detection method based on deep learning, the syntax error detection method based on data augmentation and replication, and the proposed method are used as experimental comparison methods to verify the application effects of different methods by comparing different indicators.


## 4.1.1. Experimental Data

Experimental data came from GEC evaluation task of CONLL2013. Statistical results of training data and test data are shown in Table1. The test data were divided into two parts with the same number of sentences: long and short.Table 1
Details of training data and test data.
Wrong typeTraining setTest setAmountProportionAmountProportionArticles665814.869019.9Prepositions24045.33129.0Noun37798.439611.4Subject-predicate agreement14533.21223.5Verb forms15273.41243.6Total error data1582135.1164447.4Total data45106—3470—


## 4.1.2. Corpus

This corpus is from Yahoo N-gram (version 2.0;n = 1, 2, 3, 4, 5). The N-gram corpus is based on news from 12,000 news websites, with 14.6 million articles, 126 million sentences, and 3.4 billion words. This corpus does not contain the original corpus article itself, but only contains N-gram fragments that appear at least twice. Due to the large scale of N-gram language model, in order to improve the retrieval efficiency, this paper uses the open-source search engine Apache Solr to build index and search services for it. The preprocessing procedure is illustrated in Figure 6.Figure 6
The preprocessing procedure of the corpus.


## 4.1.3. Evaluation Indicators

The evaluation of experimental results was based on CONLL2013 evaluation standard, and accuracyP, recall R, and F1 values were adopted, which were defined as follows:(27)P=NcorrectNpredicted,R=NcorrectNtarget,F1=2⋅P⋅RP+R,where Ncorrect, Npredicted, and Ntarget, respectively, refer to the number of correct corrections, the number of corrected errors, and the number of errors that should have existed.The syntax error detection method based on deep learning, the syntax error detection method based on data augmentation and replication, and the proposed method are used as experimental comparison methods to verify the application effects of different methods by comparing different indicators.


## 4.2. Analysis of Experimental Results

### 4.2.1. Short Test Set

The English grammar error detection results of the syntax error detection method based on deep learning, the syntax error detection method based on data augmentation and replication, and the method in this paper based on the short test set are shown in Tables2 to 4.Table 2
Comparison results of recall rates.
Wrong typeSyntax error detection method based on deep learningSyntax error detection method based on data augmentation and replicationModel without attention mechanismPaper methodArticles0.31110.26010.30210.3345Prepositions0.05740.04520.06130.0778Noun0.27570.29970.31010.3213Verb0.15990.23020.22580.2704Subject-predicate agreement0.14020.25020.21070.3014Table 3
Comparison results of accuracy rates.
Wrong typeSyntax error detection method based on deep learningSyntax error detection method based on data augmentation and replicationModel without attention mechanismPaper methodArticles0.50320.47320.45120.5103Prepositions0.16790.15100.14230.1677Noun0.52680.40880.51120.5288Verb0.25950.22010.24980.2813Subject-predicate agreement0.22950.24010.27650.3122Table 4
Comparison results ofF1 values.
Wrong typeSyntax error detection method based on deep learningSyntax error detection method based on data augmentation and replicationModel without attention mechanismPaper methodArticles0.39100.33570.37450.4041Prepositions0.08520.07300.10050.1062Noun0.34010.34580.38490.4131Verb0.19850.22500.24510.2757Subject-predicate agreement0.17490.24500.26950.3067For article errors, the accuracy, recall rate, and F1 value of the proposed method are 2.34% and 7.44% higher than those based on deep learning, 0.71% and 3.71% higher than those based on data augments and replication, respectively, and theF1 value is 1.3% and 6.84% higher.For preposition errors, the accuracy andF1 values of the proposed method are both higher than those of deep learning-based grammar error detection method and data augmentation and replication method, which are 3.26% and 2.04%, and 2.1% and 3.32%, respectively, and the recall rate is 0.02% lower than that of deep learning-based grammar error detection method. Syntax error detection method based on data enhancement and replication reached 1.67%.For noun errors, the accuracy, recall rate, andF1 value of the proposed method are 4.56% and 2.16% higher than those based on deep learning, 2% and 12% higher than those based on data enhancement and replication, and 7.3% and 6.73% higher than those based on data enhancement and replication, respectively.For verb errors, the accuracy, recall rate, andF1 value of the proposed method are 11.05% and 4.02%, 2.18% and 6.12%, and 7.72% and 5.07% higher than those based on deep learning and data augments and replication, respectively.For subject-verb-induced errors, the accuracy, recall rate, andF1 values of the proposed method are 16.12% and 5.12% higher than those of the deep learning-based method, 8.27% and 7.21% higher than those of the data augment-based method and replication method, and 13.18% and 6.7% higher than those of the deep learning-based method and data augment-based method, respectively.


### 4.2.2. Long Test Set

The English grammar error detection results of the syntax error detection method based on deep learning, the syntax error detection method based on data augmentation and replication, and the method in this paper based on the long test set are shown in Tables5 to 7.Table 5
Comparison results of recall rates.
Wrong typeSyntax error detection method based on deep learningSyntax error detection method based on data augmentation and replicationModel without attention mechanismPaper methodArticles0.26970.25970.33210.3415Prepositions0.04720.05070.0520.0781Noun0.23150.33210.29830.3516Verb0.15130.25210.27450.2913Subject-predicate agreement0.11020.27120.290.3219Table 6
Comparison results of accuracy rates.
Wrong typeSyntax error detection method based on deep learningSyntax error detection method based on data augmentation and replicationModel without attention mechanismPaper methodArticles0.47420.47510.50120.5134Prepositions0.15900.16080.16580.1727Noun0.45330.46010.52880.5318Verb0.22010.25950.20320.3123Subject-predicate agreement0.19950.27320.330.3312Table 7
Comparison results ofF1 values.
Wrong typeSyntax error detection method based on deep learningSyntax error detection method based on data augmentation and replicationModel without attention mechanismPaper methodArticles0.34380.33560.40230.4102Prepositions0.07300.08470.1050.1076Noun0.30640.38290.4140.4233Verb0.17980.25530.2980.3014Subject-predicate agreement0.17490.27220.31320.3265As shown in Tables4–7, for article errors, the accuracy, recall rate, and F1 value of the proposed method are 7.18% and 8.18% higher than those of the grammar error detection method based on deep learning and the grammar error detection method based on data augmentation and replication, respectively, and the recall rate is 3.92% and 3.83% higher. F1 values were 6.64 and 7.46% higher.For preposition errors, the accuracy, recall rate, andF1 value of the proposed method are higher than those of deep learning-based grammar error detection method and data augmentation and replication-based grammar error detection method, which are 3.09% and 2.74%, 1.37% and 1.19%, and 3.46% and 2.3%, respectively.For noun errors, the accuracy, recall rate, andF1 value of the proposed method are 12.01% and 1.95% higher than those of the deep learning-based method, 7.85% and 7.17% higher than those of the method based on data augment and replication, and 11.69% and 4.0% higher than those of the method based on data augmentation and replication, respectively.For verb errors, the accuracy, recall rate, andF1 values are higher than those of deep learning-based grammar error detection method and data augmentation and replication-based grammar error detection method, respectively, by 14% and 3.92%, 9.22% and 5.28%, and 12.6% and 4.61%.For subject-predicate agreement errors, the accuracy, recall rate, andF1 value of the proposed method are 22.17% and 5.07%, 13.17% and 5.8%, and 15.16% and 5.43% higher than those based on deep learning and data augmentation and replication, respectively.


## 4.2.1. Short Test Set

The English grammar error detection results of the syntax error detection method based on deep learning, the syntax error detection method based on data augmentation and replication, and the method in this paper based on the short test set are shown in Tables2 to 4.Table 2
Comparison results of recall rates.
Wrong typeSyntax error detection method based on deep learningSyntax error detection method based on data augmentation and replicationModel without attention mechanismPaper methodArticles0.31110.26010.30210.3345Prepositions0.05740.04520.06130.0778Noun0.27570.29970.31010.3213Verb0.15990.23020.22580.2704Subject-predicate agreement0.14020.25020.21070.3014Table 3
Comparison results of accuracy rates.
Wrong typeSyntax error detection method based on deep learningSyntax error detection method based on data augmentation and replicationModel without attention mechanismPaper methodArticles0.50320.47320.45120.5103Prepositions0.16790.15100.14230.1677Noun0.52680.40880.51120.5288Verb0.25950.22010.24980.2813Subject-predicate agreement0.22950.24010.27650.3122Table 4
Comparison results ofF1 values.
Wrong typeSyntax error detection method based on deep learningSyntax error detection method based on data augmentation and replicationModel without attention mechanismPaper methodArticles0.39100.33570.37450.4041Prepositions0.08520.07300.10050.1062Noun0.34010.34580.38490.4131Verb0.19850.22500.24510.2757Subject-predicate agreement0.17490.24500.26950.3067For article errors, the accuracy, recall rate, and F1 value of the proposed method are 2.34% and 7.44% higher than those based on deep learning, 0.71% and 3.71% higher than those based on data augments and replication, respectively, and theF1 value is 1.3% and 6.84% higher.For preposition errors, the accuracy andF1 values of the proposed method are both higher than those of deep learning-based grammar error detection method and data augmentation and replication method, which are 3.26% and 2.04%, and 2.1% and 3.32%, respectively, and the recall rate is 0.02% lower than that of deep learning-based grammar error detection method. Syntax error detection method based on data enhancement and replication reached 1.67%.For noun errors, the accuracy, recall rate, andF1 value of the proposed method are 4.56% and 2.16% higher than those based on deep learning, 2% and 12% higher than those based on data enhancement and replication, and 7.3% and 6.73% higher than those based on data enhancement and replication, respectively.For verb errors, the accuracy, recall rate, andF1 value of the proposed method are 11.05% and 4.02%, 2.18% and 6.12%, and 7.72% and 5.07% higher than those based on deep learning and data augments and replication, respectively.For subject-verb-induced errors, the accuracy, recall rate, andF1 values of the proposed method are 16.12% and 5.12% higher than those of the deep learning-based method, 8.27% and 7.21% higher than those of the data augment-based method and replication method, and 13.18% and 6.7% higher than those of the deep learning-based method and data augment-based method, respectively.


## 4.2.2. Long Test Set

The English grammar error detection results of the syntax error detection method based on deep learning, the syntax error detection method based on data augmentation and replication, and the method in this paper based on the long test set are shown in Tables5 to 7.Table 5
Comparison results of recall rates.
Wrong typeSyntax error detection method based on deep learningSyntax error detection method based on data augmentation and replicationModel without attention mechanismPaper methodArticles0.26970.25970.33210.3415Prepositions0.04720.05070.0520.0781Noun0.23150.33210.29830.3516Verb0.15130.25210.27450.2913Subject-predicate agreement0.11020.27120.290.3219Table 6
Comparison results of accuracy rates.
Wrong typeSyntax error detection method based on deep learningSyntax error detection method based on data augmentation and replicationModel without attention mechanismPaper methodArticles0.47420.47510.50120.5134Prepositions0.15900.16080.16580.1727Noun0.45330.46010.52880.5318Verb0.22010.25950.20320.3123Subject-predicate agreement0.19950.27320.330.3312Table 7
Comparison results ofF1 values.
Wrong typeSyntax error detection method based on deep learningSyntax error detection method based on data augmentation and replicationModel without attention mechanismPaper methodArticles0.34380.33560.40230.4102Prepositions0.07300.08470.1050.1076Noun0.30640.38290.4140.4233Verb0.17980.25530.2980.3014Subject-predicate agreement0.17490.27220.31320.3265As shown in Tables4–7, for article errors, the accuracy, recall rate, and F1 value of the proposed method are 7.18% and 8.18% higher than those of the grammar error detection method based on deep learning and the grammar error detection method based on data augmentation and replication, respectively, and the recall rate is 3.92% and 3.83% higher. F1 values were 6.64 and 7.46% higher.For preposition errors, the accuracy, recall rate, andF1 value of the proposed method are higher than those of deep learning-based grammar error detection method and data augmentation and replication-based grammar error detection method, which are 3.09% and 2.74%, 1.37% and 1.19%, and 3.46% and 2.3%, respectively.For noun errors, the accuracy, recall rate, andF1 value of the proposed method are 12.01% and 1.95% higher than those of the deep learning-based method, 7.85% and 7.17% higher than those of the method based on data augment and replication, and 11.69% and 4.0% higher than those of the method based on data augmentation and replication, respectively.For verb errors, the accuracy, recall rate, andF1 values are higher than those of deep learning-based grammar error detection method and data augmentation and replication-based grammar error detection method, respectively, by 14% and 3.92%, 9.22% and 5.28%, and 12.6% and 4.61%.For subject-predicate agreement errors, the accuracy, recall rate, andF1 value of the proposed method are 22.17% and 5.07%, 13.17% and 5.8%, and 15.16% and 5.43% higher than those based on deep learning and data augmentation and replication, respectively.


## 5. Conclusion

In the era of globalization, as countries and nations are increasingly connected, translation between different languages has naturally become an urgent need. Although human translation can achieve accurate translation, its corresponding human cost is unaffordable for many needs. Therefore, the importance of machine translation is self-evident. However, machine translation is far from fully automatic and high-quality translation and has a great space for development. Therefore, this paper designs a new machine translation model and applies it to English grammar error detection. Experimental results show that in the short test set and long test set, the accuracy, recall rate, andF1 value of the proposed method are higher than those of the experimental comparison method for detecting English grammatical errors such as articles, prepositions, nouns, verbs, and subject-verb agreement, and error detection results show that the method of English grammar of higher quality has good practical application value.



---

*Source: 2731914-2021-12-18.xml*