CN109408813B - Text correction method and device - Google Patents

Text correction method and device Download PDF

Info

Publication number
CN109408813B
CN109408813B CN201811158046.0A CN201811158046A CN109408813B CN 109408813 B CN109408813 B CN 109408813B CN 201811158046 A CN201811158046 A CN 201811158046A CN 109408813 B CN109408813 B CN 109408813B
Authority
CN
China
Prior art keywords
text
sub
corrected
sample
weight
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201811158046.0A
Other languages
Chinese (zh)
Other versions
CN109408813A (en
Inventor
贾亚伟
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Kingsoft Internet Security Software Co Ltd
Original Assignee
Beijing Kingsoft Internet Security Software Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Kingsoft Internet Security Software Co Ltd filed Critical Beijing Kingsoft Internet Security Software Co Ltd
Priority to CN201811158046.0A priority Critical patent/CN109408813B/en
Publication of CN109408813A publication Critical patent/CN109408813A/en
Application granted granted Critical
Publication of CN109408813B publication Critical patent/CN109408813B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/20Natural language analysis
    • G06F40/232Orthographic correction, e.g. spell checking or vowelisation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/08Learning methods
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Abstract

The embodiment of the application provides a text correction method and device. The method comprises the following steps: acquiring an input current text to be corrected; inputting the current text into a neural network, determining semantic vectors and weights of the current text by an encoding layer of the neural network according to first network parameters trained in advance, and inputting the semantic vectors and weights into a decoding layer; the weight is used for indicating the possibility of errors of each sub-text in the current text; the decoding layer of the neural network determines corrected text corresponding to the current text according to the pre-trained second network parameters, the semantic vector and the weight; and acquiring corrected text corresponding to the current text determined by the decoding layer. By applying the scheme provided by the embodiment of the application, the processing efficiency of text correction can be improved.

Description

Text correction method and device
Technical Field
The present disclosure relates to the field of text processing technologies, and in particular, to a text correction method and apparatus.
Background
In order to improve convenience when a user uses an input method, a function of correcting text which has been input by the user is often arranged in an input method client. I.e. based on the current text entered by the user, detecting errors in the current text and outputting text corrected for the errors.
In the related art, the error correction technology for the input text is mainly based on preset rules. The preset rule may be a collocation rule of a main predicate in a sentence. For example, in the english language, a part of speech of a word in the input text may be labeled, and according to a preset rule and the part of speech of the labeled word, a grammar error in the input text is determined, so as to correct the grammar of the input text.
The text correction method can correct the type of the partial grammar errors. However, in practice, the types of errors at the time of user input are very large, and spelling errors, temporal errors, and the like exist in addition to grammar errors. In this case, a corresponding preset rule may be established in advance for each error type. When error correction is performed, the input text is required to be matched with each preset rule one by one, and errors in the input text are determined. When the preset rules are many, the processing efficiency of this text correction method is low.
Disclosure of Invention
An object of the embodiments of the present application is to provide a method and an apparatus for correcting text, so as to improve processing efficiency during text correction. The specific technical scheme is as follows.
In a first aspect, an embodiment of the present application provides a text correction method, including:
Acquiring an input current text to be corrected;
inputting the current text into a neural network; wherein the neural network comprises an encoding layer and a decoding layer;
the encoding layer determines the semantic vector and the weight of the current text according to a first pre-trained network parameter, and inputs the semantic vector and the weight into the decoding layer; the weight is used for indicating the possibility of errors of each sub-text in the current text;
the decoding layer determines corrected text corresponding to the current text according to the pre-trained second network parameters, the semantic vector and the weight;
and acquiring corrected text corresponding to the current text determined by a decoding layer.
Optionally, the semantic vector includes sub-semantic vectors of each sub-text of the current text, and the weight includes a sub-weight of each sub-text of the current text; the step of determining the corrected text corresponding to the current text according to the pre-trained second network parameters, the semantic vector and the weight comprises the following steps:
the Nth corrected sub-text of the corrected text corresponding to the current text is determined in the following manner:
Acquiring an N-1 correction sub-text; wherein, N is a positive integer, and when N is greater than 1, the N-1 th correction sub-text is: determining from a preset text object library according to the N-1 sub-semantic vector, the N-1 sub-weight and the obtained N-2 correction sub-text; the text object library comprises various text objects;
and determining the Nth corrected sub-text from the text object library according to the Nth sub-semantic vector, the Nth sub-weight and the N-1 th corrected sub-text.
Optionally, when the N is 1, the step of obtaining the N-1 th corrected sub-text includes:
the preset text is taken as the N-1 correction sub-text, or the text selected from the preset text library is taken as the N-1 correction sub-text.
Optionally, the step of determining the nth corrected sub-text from the text object library according to the nth sub-semantic vector and the nth sub-weight and the nth-1 corrected sub-text includes:
determining the scores of all text objects in the text object library according to the Nth sub-semantic vector, the Nth sub-weight and the N-1 th corrected sub-text;
and determining an Nth correction sub-text from each text object in the text object library according to each score.
Optionally, the neural network is obtained by adopting the following training mode:
acquiring parallel corpus; the parallel corpus comprises sample texts and corresponding standard corrected texts;
inputting the sample text into an encoding layer of the neural network;
the encoding layer determines sample semantic vectors and sample weights of the sample text according to the first network parameters, and inputs the sample semantic vectors and the sample weights into the decoding layer; the sample weight is used for indicating the possibility of errors of each sample sub-text in the sample text;
the decoding layer determines a sample corrected text corresponding to the sample text according to the second network parameter, the sample semantic vector and the sample weight;
comparing the difference between the sample corrected text and the standard corrected text;
when the difference is greater than a preset threshold, modifying the first network parameter and the second network parameter according to the difference, and returning to execute the step of inputting the sample text into the coding layer of the neural network;
and when the difference is smaller than a preset threshold value, determining that the neural network training is completed.
Optionally, the encoding layer adopts a bidirectional pyramid type cyclic neural network, and/or the decoding layer adopts a bidirectional cyclic neural network.
In a second aspect, an embodiment of the present application provides a text correction apparatus, including:
the first acquisition module is used for acquiring the input current text to be corrected;
the first input module is used for inputting the current text into the neural network; wherein the neural network comprises an encoding layer and a decoding layer; the encoding layer determines the semantic vector and the weight of the current text according to a first pre-trained network parameter, and inputs the semantic vector and the weight into the decoding layer; the weight is used for indicating the possibility of errors of each sub-text in the current text; the decoding layer determines corrected text corresponding to the current text according to the pre-trained second network parameters, the semantic vector and the weight;
and the second acquisition module is used for acquiring corrected text corresponding to the current text determined by the decoding layer.
Optionally, the semantic vector includes sub-semantic vectors of each sub-text of the current text, and the weight includes a sub-weight of each sub-text of the current text; the decoding layer, when determining the corrected text corresponding to the current text according to the pre-trained second network parameter, the semantic vector and the weight, comprises:
The Nth corrected sub-text of the corrected text corresponding to the current text is determined by adopting the following method:
acquiring an N-1 correction sub-text; wherein, N is a positive integer, and when N is greater than 1, the N-1 th correction sub-text is: determining from a preset text object library according to the N-1 sub-semantic vector, the N-1 sub-weight and the obtained N-2 correction sub-text; the text object library comprises various text objects;
and determining the Nth corrected sub-text from the text object library according to the Nth sub-semantic vector, the Nth sub-weight and the N-1 th corrected sub-text.
Optionally, the decoding layer, when obtaining the N-1 th correction sub-text, includes:
and when the N is 1, taking the preset text as an N-1 correction sub-text, or taking the text selected from the preset text library as an N-1 correction sub-text.
Optionally, the decoding layer, when determining the nth corrected sub-text from the text object library according to the nth sub-semantic vector, the nth sub-weight and the nth-1 corrected sub-text, includes:
determining the scores of all text objects in the text object library according to the Nth sub-semantic vector, the Nth sub-weight and the N-1 th corrected sub-text;
And determining an Nth correction sub-text from each text object in the text object library according to each score.
Optionally, the apparatus further includes: the training module is used for obtaining the neural network by adopting the following training operation:
acquiring parallel corpus; the parallel corpus comprises sample texts and corresponding standard corrected texts;
inputting the sample text into an encoding layer of the neural network;
the encoding layer determines sample semantic vectors and sample weights of the sample text according to the first network parameters, and inputs the sample semantic vectors and the sample weights into the decoding layer; the sample weight is used for indicating the possibility of errors of each sample sub-text in the sample text;
the decoding layer determines a sample corrected text corresponding to the sample text according to the second network parameter, the sample semantic vector and the sample weight;
comparing the difference between the sample corrected text and the standard corrected text;
when the difference is greater than a preset threshold, modifying the first network parameter and the second network parameter according to the difference, and returning to execute the step of inputting the sample text into the coding layer of the neural network;
And when the difference is smaller than a preset threshold value, determining that the neural network training is completed.
Optionally, the encoding layer adopts a bidirectional pyramid type cyclic neural network, and/or the decoding layer adopts a bidirectional cyclic neural network.
In a third aspect, an embodiment of the present application provides an electronic device, where the electronic device includes a processor, a communication interface, a memory, and a communication bus, where the processor, the communication interface, and the memory complete communication with each other through the communication bus;
a memory for storing a computer program;
and the processor is used for realizing the text correction method provided by the first aspect when executing the program stored in the memory.
In a fourth aspect, embodiments of the present application provide a computer-readable storage medium having stored therein a computer program which, when executed by a processor, implements the text correction method provided in the first aspect.
According to the text correction method and device, the current text to be corrected can be input into the neural network, the encoding layer determines the semantic vector and the weight of the current text according to the first network parameter, and the decoding layer determines the corrected text corresponding to the current text according to the second network parameter, the semantic vector and the weight. Because the first network parameters and the second network parameters are trained in advance according to a large number of samples, corrected texts corresponding to the current texts can be determined by adopting the neural network, when the large number of samples contain texts with multiple error types, the neural network can correct the texts with multiple error types without matching multiple preset rules one by one, so that the processing efficiency of text correction can be improved. Of course, not all of the above-described advantages need be achieved simultaneously in practicing any one of the products or methods of the present application.
Drawings
In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following description will make a brief introduction to the drawings used in the description of the embodiments or the prior art. It is apparent that the drawings in the following description are only some embodiments of the present application, and that other drawings may be obtained from these drawings without inventive effort for a person of ordinary skill in the art.
Fig. 1 is a schematic flow chart of a text correction method according to an embodiment of the present application;
FIG. 2A is a schematic diagram of a neural network according to an embodiment of the present application when correcting text;
fig. 2B is a schematic structural diagram of a neural network according to an embodiment of the present application;
fig. 3 is a schematic structural diagram of a text correction apparatus according to an embodiment of the present application;
fig. 4 is a schematic structural diagram of an electronic device according to an embodiment of the present application.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application. It will be apparent that the described embodiments are only some, but not all, of the embodiments of the present application. All other embodiments, which can be made by one of ordinary skill in the art without undue burden from the present disclosure, are within the scope of the present application based on the embodiments herein.
In order to improve processing efficiency in text correction, the embodiment of the application provides a text correction method and device. The present application will be described in detail with reference to specific examples.
Fig. 1 is a schematic flow chart of a text correction method according to an embodiment of the present application. The method is applied to the electronic equipment. The electronic device can be a common computer, a server, a tablet personal computer, a smart phone and the like. In particular, the method can be applied to a client in an electronic device. The client may be an input method application installed in the electronic device. The method comprises the following steps:
step S101: and acquiring the input current text to be corrected.
The current text may be a text input by a user. When the client receives the current text input by the user, the user can correct errors of the current text input by the user, so that the use experience of the user is improved.
When the current text is acquired, the client can acquire the current text when the correction condition is met, namely, the text correction is triggered. The correction conditions may include: detecting that the pause time after the user inputs the current text is greater than a preset time threshold; alternatively, when the correction button is triggered after the user inputs the current text; alternatively, when the preset input content is detected, for example, the preset input content may be a space or the like.
In different language types, the current text may include different situations. For example, in the english language, the current text may be a word or a sentence, or a portion of a sentence, such as injury or I hope that, etc. In chinese language, the current text may be a word, or may be a phrase or a complete sentence.
Step S102: the current text is entered into the neural network.
Wherein the neural network includes an encoding layer and a decoding layer. And the encoding layer is used for determining the semantic vector and the weight of the current text according to the pre-trained first network parameters and inputting the semantic vector and the weight into the decoding layer. The weights are used to indicate the likelihood that each sub-text in the current text is erroneous. The semantic vector and the weight may be quantities expressed in a matrix.
And the decoding layer is used for determining corrected text corresponding to the current text according to the pre-trained second network parameters, the semantic vector and the weight.
When the current text is input into the neural network, the current text is directly input into the coding layer of the neural network. The encoding layer inputs the semantic vector and the weight into the decoding layer when determining the semantic vector and the weight of the current text. The decoding layer receives the semantic vector and the weight input by the encoding layer, and determines corrected text corresponding to the current text according to the second network parameter and the semantic vector and the weight.
The first network parameters and the second network parameters are obtained through training according to the sample text and the corresponding standard corrected text in advance.
The neural network may be located in the electronic device or may be located in other devices besides the electronic device.
Step S103: and acquiring corrected text corresponding to the current text determined by the decoding layer.
The output result of the decoding layer may be corrected text corresponding to the current text. The embodiment can directly obtain the output result of the decoding layer.
For example, the current text may be: i dont even know to say what; the corresponding corrected text is: i don't even know what to say. The current text may be: i hope that no people are injured, no building are destructed; the corresponding corrected text is: i hope that no people are injured, no buildings are destroyed. The current text is: she are an goad girl; the corresponding corrected text is: she is a good girl.
The method of the embodiment can correct various errors in sentences, including spelling errors, grammar errors, word errors, punctuation errors and the like.
As can be seen from the foregoing, in this embodiment, the current text to be corrected may be input into the neural network, the encoding layer determines the semantic vector and the weight of the current text according to the first network parameter, and the decoding layer determines the corrected text corresponding to the current text according to the second network parameter and the semantic vector and the weight. Because the first network parameters and the second network parameters are trained in advance according to a large number of samples, corrected texts corresponding to the current texts can be determined by adopting the neural network, when the large number of samples contain texts with multiple error types, the neural network can correct the texts with multiple error types without matching multiple preset rules one by one, so that the processing efficiency of text correction can be improved.
In another embodiment of the present application, based on the embodiment shown in fig. 1, the semantic vector includes sub-semantic vectors of each sub-text of the current text, and the weights include sub-weights of each sub-text of the current text. The semantic vectors and weights may be represented in a matrix. Each row or column in the matrix of semantic vectors represents a sub-semantic vector for each sub-text of the current text. Each row or column in the matrix of weights represents a sub-weight for each sub-text of the current text.
In step S102, the step of determining the corrected text corresponding to the current text according to the pre-trained second network parameter, the semantic vector and the weight includes:
the N-th corrected sub-text of the corrected text corresponding to the current text is determined by adopting the following steps 1a and 2 a:
step 1a: and acquiring the N-1 th correction sub-text.
Wherein N is a positive integer, and can be an integer of 1, 2, 3, 4, etc. When N is greater than 1, the N-1 th syndrome text is: and determining from a preset text object library according to the N-1 sub-semantic vector, the N-1 sub-weight and the acquired N-2 correction sub-text.
When N is 1, the N-1 th syndrome text may be obtained in the following manner: the preset text is taken as the N-1 correction sub-text, or the text selected from the preset text library is taken as the N-1 correction sub-text. The text may be selected randomly when selected from a library of preset texts.
The current text comprises M sub-texts, wherein M is a positive integer greater than or equal to N. The nth sub-text corresponds to the nth correction sub-text. The sequence of each sub-text in the current text corresponds to the sequence of each sub-semantic vector in the semantic vector and the sequence of each sub-weight in the weights respectively.
The preset text object library comprises various text objects, and the text objects can comprise vocabulary, punctuation marks and the like. In language types where there are different variations of a word, such as English language types, the vocabulary may contain a variety of different variations of each vocabulary. For example, tall, taller, drink, apple, apples, etc.; punctuation marks include commas, periods, colon, dashes, and the like.
Step 2a: and determining the Nth corrected sub-text from the text object library according to the Nth sub-semantic vector, the Nth sub-weight and the N-1 th corrected sub-text.
The nth syndrome text may be a word, a punctuation mark, or the like. The text object library comprises punctuation marks, so that correction of the punctuation marks in the current text can be realized.
In summary, according to the embodiment, the corrected text corresponding to the current sub-text can be determined from the text object library according to the previous corrected sub-text and the sub-semantic vector and the weight corresponding to the current sub-text, so that the accuracy of the determined corrected sub-text can be improved.
In another embodiment of the present application, step 2a, i.e. the step of determining the nth corrected sub-text from the text object library according to the nth sub-semantic vector and the nth sub-weight and the nth-1 th corrected sub-text, comprises steps 2a-1 and 2a-2, is based on the embodiment shown in fig. 1.
Step 2a-1: and determining the scores of all the text objects in the text object library according to the Nth sub-semantic vector, the Nth sub-weight and the N-1 th corrected sub-text.
Step 2a-2: and determining an Nth correction sub-text from each text object in the text object library according to each score.
In this step, specifically, the text object with the highest score in the text object library may be determined as the nth correction sub-text. The corrected sub-text of each sub-text of the current text thus obtained is the text object with the highest score. Alternatively, the k text objects with the highest scores in the text object library may be determined as the nth correction sub-text. Thus, when determining the (n+1) -th correction sub-text, determining the (n+1) -th correction sub-text according to the (i is a positive integer less than or equal to k) th correction sub-text, the (n+1) -th sub-semantic vector and the (n+1) -th sub-weight in the k text objects of the (N) -th correction sub-text.
In this embodiment, the decoding layer may employ a recurrent neural network (Recurrent Neural Network, RNN). The embodiment can determine the correction sub-text more accurately from a plurality of text objects in the text object library according to the scores of the text objects in the text object library when determining the correction sub-text.
In another embodiment of the present application, based on the embodiment shown in fig. 1, the training method shown in the following steps 1b-5b is used to obtain the neural network:
step 1b: and obtaining parallel corpus. The parallel corpus comprises sample texts and corresponding standard corrected texts. For example, one sample is she are an goad girl and the corresponding standard corrected text is: she is a good girl.
Step 2b: the sample text is input into the coding layer of the neural network.
And the encoding layer is used for determining sample semantic vectors and sample weights of the sample text according to the first network parameters and inputting the sample semantic vectors and the sample weights into the decoding layer. Wherein the sample weight is used to indicate the possibility of error in each sample sub-text in the sample text.
And determining a sample corrected text corresponding to the sample text according to the second network parameter, the sample semantic vector and the sample weight by the decoding layer of the neural network.
The initial values of the first network parameter and the second network parameter may be preset values.
Step 3b: the difference between the sample corrected text and the standard corrected text is compared.
The differences may include uncorrected erroneous text and error text that corrects the correct text. The differences may be represented using parameterized data.
Step 4b: when the difference is greater than the preset threshold, the first network parameter and the second network parameter are modified according to the difference, and the step of inputting the sample text into the coding layer of the neural network is performed, namely, the step 2b is performed.
The preset threshold may be a parameter value preset empirically. When the difference is larger than a preset threshold, the difference between the corrected text of the sample obtained from the decoding layer and the standard corrected text is considered to be larger, the correction accuracy requirement cannot be met, and the network parameters need to be continuously adjusted.
When modifying the first network parameter and the second network parameter, the first network parameter and the second network parameter may be modified in a direction to reduce the difference based on the difference.
The parallel corpus may include a plurality of sample texts and corresponding standard corrected texts. Various errors may be included in the sample text in the parallel corpus, such as spelling errors, word errors, tense errors, and the like.
After modifying the first network parameter and the second network parameter, a next sample may be selected for input into the neural network.
Step 5b: and when the difference is smaller than a preset threshold value, determining that the neural network training is completed.
When the difference is smaller than a preset threshold, the difference between the corrected text of the sample obtained from the decoding layer and the standard corrected text is considered to be smaller, the correction precision requirement can be met, and the network parameters are trained.
When the difference is equal to the preset threshold, the first network parameter and the second network parameter may be modified according to the difference, and the step 2b may be executed in a return manner, or it may be determined that the neural network training is completed.
In this embodiment, the parallel corpus is used to train the decoding layer and the encoding layer of the neural network, and the network parameters are continuously adjusted until the network parameters of the neural network are adjusted to meet the correction accuracy requirement, so as to determine that the neural network training is completed.
In another embodiment of the present application, the above-described encoding layer employs a cyclic neural network in the form of a bi-directional pyramid, and/or the decoding layer employs a bi-directional cyclic neural network, based on the embodiment shown in fig. 1.
In the embodiment, the coding layer adopts a network structure design in a bidirectional pyramid form, so that parameters of a model can be greatly reduced, and the reasoning time of a neural network is reduced. The decoding layer adopts a cyclic neural network, so that the accuracy in correction can be improved, and the accuracy of the neural network is further improved.
The present application will be described in more detail with reference to specific examples.
Fig. 2A is a schematic diagram of a neural network according to an embodiment of the present application when correcting text. Wherein the left square frame is an encoding layer (encoder), and the right square frame is a decoding layer (decoder). When the current text input into the encoding layer is she are an goad girl, the semantic vector and weight (intent) of the current text can be determined in the encoding layer, and the semantic vector and weight are input into the decoding layer (indicated by the two-dotted arrow). The decoding layer predicts each sub-text according to the inputted semantic vector and weight, and determines corrected text of each sub-text. And the decoding layer is used for determining the current corrected text based on the previous corrected text, the current sub-semantic vector in the semantic vector and the current sub-weight in the weight. Each corrected text may then be determined and combined into a final output, she is a good girl. < S > is a sentence head identifier located at the sentence head of the current text. When the decoding layer detects the sentence head identifier, the preset text may be regarded as the previous corrected text. When there is a greater likelihood of an error in a sub-text in the current text, there is a greater likelihood of correcting the sub-text in the corresponding decoding layer.
Fig. 2B is a schematic structural diagram of a neural network according to an embodiment of the present application. The neural network is a sequence-to-sequence (seq 2 seq) model with attention mechanisms based on the coding layer-decoding layer architecture. The coding layer adopts a bidirectional pyramid type cyclic neural network, and the decoding layer adopts a bidirectional cyclic neural network. The coding layer may include a plurality of sub-layers, for example, j=0 sub-layers, j=1 sub-layers, and the like. The two dashed arrows of the coding layer pointing to the decoding layer represent the semantic vectors and weights that the coding layer inputs to the decoding layer.
In the coding layer, each box represents a network element (Gated Recurrent Unit, GRU). The GRU is also referred to as a door. Each GRU in a horizontal row constitutes a sub-layer of the coding layer. Between each GRU, there are the following forward and backward outputs:
forward direction:
and (3) backward:
the activation function of the hidden layer is:
wherein, the liquid crystal display device comprises a liquid crystal display device,
is a preset parameter matrix. X is x t For the current text of the input coding layer at time t, j is the number of the sub-layer in the coding layer, j=0, 1,2,3, … …. />For the forward output of the jth GRU network element in the jth sublayer, +.>Is the backward output of the tth GRU network unit in the jth sublayer. T is the transposed symbol of the vector.
In the attention mechanism of the coding layer, the weight a t Is a as t =∑ j α tj c j Wherein
Where k is the value in j. Φ (X) is a function of the linear transformation of X, e.g., Φ (X) = wX +z. w and z are preset parameters.
The output of the j-th sublayer of the coding layer isThe coding layer outputs +.>As a semantic vector, a decoding layer is input.
The decoding layer receives the semantic vector input by the encoding layerAnd weight a t At this time, the semantic vector can be +>And weight a t Obtaining a scoring vector of each text object in the text object library through transformation of a linear rectification function (Rectified Linear Unit, reLU), inputting the scoring vector into softmax in a decoding layer, and normalizing the scoring in the scoring vector by the softmax to obtain the scoring of each text object. The decoding layer determines the text object with the highest score from the text object library as corrected text according to the score.
Fig. 3 is a schematic structural diagram of a text correction apparatus according to an embodiment of the present application. The apparatus corresponds to the embodiment of the method shown in fig. 1, and the apparatus is applied to an electronic device. The electronic device can be a common computer, a server, a tablet personal computer, a smart phone and the like. In particular, the apparatus may be applied to a client in an electronic device. The device comprises:
A first obtaining module 301, configured to obtain an input current text to be corrected;
a first input module 302, configured to input the current text into a neural network; wherein the neural network comprises an encoding layer and a decoding layer; the encoding layer determines the semantic vector and the weight of the current text according to a first pre-trained network parameter, and inputs the semantic vector and the weight into the decoding layer; the weight is used for indicating the possibility of errors of each sub-text in the current text; the decoding layer determines corrected text corresponding to the current text according to the pre-trained second network parameters, the semantic vector and the weight;
and the second obtaining module 303 is configured to obtain a corrected text corresponding to the current text determined by the decoding layer.
In another embodiment of the present application, based on the embodiment shown in fig. 3, the semantic vector includes sub-semantic vectors of each sub-text of the current text, and the weights include sub-weights of each sub-text of the current text; the decoding layer, when determining the corrected text corresponding to the current text according to the pre-trained second network parameter, the semantic vector and the weight, comprises the following steps:
The Nth corrected sub-text of the corrected text corresponding to the current text is determined by adopting the following method:
acquiring an N-1 correction sub-text; wherein, N is a positive integer, and when N is greater than 1, the N-1 th correction sub-text is: determining from a preset text object library according to the N-1 sub-semantic vector, the N-1 sub-weight and the obtained N-2 correction sub-text; the text object library comprises various text objects;
and determining the Nth corrected sub-text from the text object library according to the Nth sub-semantic vector, the Nth sub-weight and the N-1 th corrected sub-text.
In another embodiment of the present application, based on the embodiment shown in fig. 3, when the decoding layer obtains the N-1 th correction sub-text, the method includes:
and when the N is 1, taking the preset text as an N-1 correction sub-text, or taking the text selected from the preset text library as an N-1 correction sub-text.
In another embodiment of the present application, based on the embodiment shown in fig. 3, when the decoding layer determines the nth corrected sub-text from the text object library according to the nth sub-semantic vector and the nth sub-weight and the nth-1 corrected sub-text, the decoding layer includes:
Determining the scores of all text objects in the text object library according to the Nth sub-semantic vector, the Nth sub-weight and the N-1 th corrected sub-text;
and determining an Nth correction sub-text from each text object in the text object library according to each score.
In another embodiment of the present application, based on the embodiment shown in fig. 3, the apparatus further includes: a training module (not shown in the figure) for obtaining the neural network by using the following training operations:
acquiring parallel corpus; the parallel corpus comprises sample texts and corresponding standard corrected texts;
inputting the sample text into an encoding layer of the neural network;
the encoding layer determines sample semantic vectors and sample weights of the sample text according to the first network parameters, and inputs the sample semantic vectors and the sample weights into the decoding layer; the sample weight is used for indicating the possibility of errors of each sample sub-text in the sample text;
the decoding layer determines a sample corrected text corresponding to the sample text according to the second network parameter, the sample semantic vector and the sample weight;
comparing the difference between the sample corrected text and the standard corrected text;
When the difference is greater than a preset threshold, modifying the first network parameter and the second network parameter according to the difference, and returning to execute the step of inputting the sample text into the coding layer of the neural network;
and when the difference is smaller than a preset threshold value, determining that the neural network training is completed.
In another embodiment of the present application, the encoding layer may employ a recurrent neural network in the form of a bi-directional pyramid, and/or the decoding layer may employ a bi-directional recurrent neural network, based on the embodiment shown in fig. 3.
Since the above embodiment of the apparatus is obtained based on the embodiment of the method, and has the same technical effects as the method, the technical effects of the embodiment of the apparatus are not described herein. For the device embodiments, since they are substantially similar to the method embodiments, the description is relatively simple, and reference is made to the description of the method embodiments for relevant points.
Fig. 4 is a schematic structural diagram of an electronic device according to an embodiment of the present application. The electronic device comprises a processor 401, a communication interface 402, a memory 403 and a communication bus 404, wherein the processor 401, the communication interface 402 and the memory 403 complete communication with each other through the communication bus 404;
A memory 403 for storing a computer program;
the processor 401 is configured to implement the text correction method provided in the embodiment of the present application when executing the program stored in the memory 403. The method comprises the following steps:
acquiring an input current text to be corrected;
inputting the current text into a neural network; wherein the neural network comprises an encoding layer and a decoding layer;
the encoding layer is used for determining semantic vectors and weights of the current text according to the first network parameters trained in advance, and inputting the semantic vectors and weights into the decoding layer; the weight is used for indicating the possibility of errors of each sub-text in the current text;
the decoding layer is used for determining corrected texts corresponding to the current texts according to the pre-trained second network parameters, the semantic vectors and the weights;
and acquiring corrected text corresponding to the current text determined by the decoding layer.
The communication bus 404 referred to above for the electronic devices may be a peripheral component interconnect standard (Peripheral Component Interconnect, PCI) bus, or an extended industry standard architecture (Extended Industry Standard Architecture, EISA) bus, or the like. The communication bus 404 may be classified as an address bus, a data bus, a control bus, or the like. For ease of illustration, the figures are shown with only one bold line, but not with only one bus or one type of bus.
The communication interface 402 is used for communication between the electronic device and other devices described above.
The Memory 403 may include random access Memory (Random Access Memory, RAM) or may include Non-Volatile Memory (NVM), such as at least one magnetic disk Memory. Optionally, the memory 403 may also be at least one storage device located remotely from the aforementioned processor.
The processor 401 may be a general-purpose processor including a central processing unit (Central Processing Unit, CPU), a network processor (Network Processor, NP), etc.; but also digital signal processors (Digital Signal Processing, DSP), application specific integrated circuits (Application Specific Integrated Circuit, ASIC), field programmable gate arrays (Field-Programmable Gate Array, FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
In summary, the present text to be corrected may be input into the neural network, the encoding layer determines the semantic vector and the weight of the present text according to the first network parameter, and the decoding layer determines the corrected text corresponding to the present text according to the second network parameter and the semantic vector and the weight. Because the first network parameters and the second network parameters are trained in advance according to a large number of samples, corrected texts corresponding to the current texts can be determined by adopting the neural network, when the large number of samples contain texts with multiple error types, the neural network can correct the texts with multiple error types without matching multiple preset rules one by one, so that the processing efficiency of text correction can be improved.
The embodiment of the application also provides a computer readable storage medium, and a computer program is stored in the computer readable storage medium, and when the computer program is executed by a processor, the text correction method provided by the embodiment of the application is realized. The method comprises the following steps:
acquiring an input current text to be corrected;
inputting the current text into a neural network; wherein the neural network comprises an encoding layer and a decoding layer;
the encoding layer is used for determining semantic vectors and weights of the current text according to the first network parameters trained in advance, and inputting the semantic vectors and weights into the decoding layer; the weight is used for indicating the possibility of errors of each sub-text in the current text;
the decoding layer is used for determining corrected texts corresponding to the current texts according to the pre-trained second network parameters, the semantic vectors and the weights;
and acquiring corrected text corresponding to the current text determined by the decoding layer.
In summary, the present text to be corrected may be input into the neural network, the encoding layer determines the semantic vector and the weight of the present text according to the first network parameter, and the decoding layer determines the corrected text corresponding to the present text according to the second network parameter and the semantic vector and the weight. Because the first network parameters and the second network parameters are trained in advance according to a large number of samples, corrected texts corresponding to the current texts can be determined by adopting the neural network, when the large number of samples contain texts with multiple error types, the neural network can correct the texts with multiple error types without matching multiple preset rules one by one, so that the processing efficiency of text correction can be improved.
It is noted that relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
In this specification, each embodiment is described in a related manner, and identical and similar parts of each embodiment are all referred to each other, and each embodiment mainly describes differences from other embodiments.
The foregoing description is only of the preferred embodiments of the present application and is not intended to limit the scope of the present application. Any modifications, equivalent substitutions, improvements, etc. that are within the spirit and principles of the present application are intended to be included within the scope of the present application.

Claims (12)

1. A method of text correction, the method comprising:
acquiring an input current text to be corrected;
inputting the current text into a neural network; wherein the neural network comprises an encoding layer and a decoding layer;
the encoding layer determines the semantic vector and the weight of the current text according to a first pre-trained network parameter, and inputs the semantic vector and the weight into the decoding layer; the weights comprise sub-weights of all the sub-texts of the current text and are used for indicating the possibility of errors of all the sub-texts in the current text;
the decoding layer determines corrected text corresponding to the current text according to a pre-trained second network parameter, the semantic vector and the weight, wherein the first network parameter and the second network parameter are obtained by training the corrected text according to a sample text and a corresponding standard in advance;
acquiring corrected text corresponding to the current text determined by a decoding layer;
the semantic vector comprises sub-semantic vectors of all sub-texts of the current text; the step of determining the corrected text corresponding to the current text according to the pre-trained second network parameters, the semantic vector and the weight comprises the following steps:
The Nth corrected sub-text of the corrected text corresponding to the current text is determined in the following manner:
acquiring an N-1 correction sub-text; wherein, N is a positive integer, and when N is greater than 1, the N-1 th correction sub-text is: determining from a preset text object library according to the N-1 sub-semantic vector, the N-1 sub-weight and the obtained N-2 correction sub-text; the text object library comprises various text objects;
and determining the Nth corrected sub-text from the text object library according to the Nth sub-semantic vector, the Nth sub-weight and the N-1 th corrected sub-text.
2. The method of claim 1, wherein the step of obtaining the N-1 th syndrome text when the N is 1, comprises:
the preset text is taken as the N-1 correction sub-text, or the text selected from the preset text library is taken as the N-1 correction sub-text.
3. The method of claim 1, wherein the step of determining the nth corrected sub-text from the text object library according to the nth sub-semantic vector and the nth sub-weight and the nth-1 corrected sub-text comprises:
determining the scores of all text objects in the text object library according to the Nth sub-semantic vector, the Nth sub-weight and the N-1 th corrected sub-text;
And determining an Nth correction sub-text from each text object in the text object library according to each score.
4. The method according to claim 1, wherein the neural network is obtained using the following training scheme:
acquiring parallel corpus; the parallel corpus comprises sample texts and corresponding standard corrected texts;
inputting the sample text into an encoding layer of the neural network;
the encoding layer determines sample semantic vectors and sample weights of the sample text according to the first network parameters, and inputs the sample semantic vectors and the sample weights into the decoding layer; the sample weight is used for indicating the possibility of errors of each sample sub-text in the sample text;
the decoding layer determines a sample corrected text corresponding to the sample text according to the second network parameter, the sample semantic vector and the sample weight;
comparing the difference between the sample corrected text and the standard corrected text;
when the difference is greater than a preset threshold, modifying the first network parameter and the second network parameter according to the difference, and returning to execute the step of inputting the sample text into the coding layer of the neural network;
And when the difference is smaller than a preset threshold value, determining that the neural network training is completed.
5. The method according to claim 1, wherein the encoding layer employs a recurrent neural network in the form of a bi-directional pyramid and/or the decoding layer employs a bi-directional recurrent neural network.
6. A text correction apparatus, the apparatus comprising:
the first acquisition module is used for acquiring the input current text to be corrected;
the first input module is used for inputting the current text into the neural network; wherein the neural network comprises an encoding layer and a decoding layer; the encoding layer determines the semantic vector and the weight of the current text according to a first pre-trained network parameter, and inputs the semantic vector and the weight into the decoding layer; the weights comprise sub-weights of all the sub-texts of the current text and are used for indicating the possibility of errors of all the sub-texts in the current text; the decoding layer determines corrected text corresponding to the current text according to a pre-trained second network parameter, the semantic vector and the weight, wherein the first network parameter and the second network parameter are obtained by training the corrected text according to a sample text and a corresponding standard in advance;
The second acquisition module is used for acquiring corrected text corresponding to the current text determined by the decoding layer;
the semantic vector comprises sub-semantic vectors of all sub-texts of the current text; the decoding layer, when determining the corrected text corresponding to the current text according to the pre-trained second network parameter, the semantic vector and the weight, comprises:
the Nth corrected sub-text of the corrected text corresponding to the current text is determined by adopting the following method:
acquiring an N-1 correction sub-text; wherein, N is a positive integer, and when N is greater than 1, the N-1 th correction sub-text is: determining from a preset text object library according to the N-1 sub-semantic vector, the N-1 sub-weight and the obtained N-2 correction sub-text; the text object library comprises various text objects;
and determining the Nth corrected sub-text from the text object library according to the Nth sub-semantic vector, the Nth sub-weight and the N-1 th corrected sub-text.
7. The apparatus of claim 6, wherein the decoding layer, when acquiring the N-1 th syndrome text, comprises:
and when the N is 1, taking the preset text as an N-1 correction sub-text, or taking the text selected from the preset text library as an N-1 correction sub-text.
8. The apparatus of claim 6, wherein the decoding layer, when determining the nth corrected sub-text from the text object library based on the nth sub-semantic vector and the nth sub-weight and the nth-1 corrected sub-text, comprises:
determining the scores of all text objects in the text object library according to the Nth sub-semantic vector, the Nth sub-weight and the N-1 th corrected sub-text;
and determining an Nth correction sub-text from each text object in the text object library according to each score.
9. The apparatus of claim 6, wherein the apparatus further comprises: the training module is used for obtaining the neural network by adopting the following training operation:
acquiring parallel corpus; the parallel corpus comprises sample texts and corresponding standard corrected texts;
inputting the sample text into an encoding layer of the neural network;
the encoding layer determines sample semantic vectors and sample weights of the sample text according to the first network parameters, and inputs the sample semantic vectors and the sample weights into the decoding layer; the sample weight is used for indicating the possibility of errors of each sample sub-text in the sample text;
The decoding layer determines a sample corrected text corresponding to the sample text according to the second network parameter, the sample semantic vector and the sample weight;
comparing the difference between the sample corrected text and the standard corrected text;
when the difference is greater than a preset threshold, modifying the first network parameter and the second network parameter according to the difference, and returning to execute the step of inputting the sample text into the coding layer of the neural network;
and when the difference is smaller than a preset threshold value, determining that the neural network training is completed.
10. The apparatus of claim 6, wherein the encoding layer employs a recurrent neural network in the form of a bi-directional pyramid, and/or the decoding layer employs a bi-directional recurrent neural network.
11. The electronic equipment is characterized by comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory are communicated with each other through the communication bus;
a memory for storing a computer program;
a processor for carrying out the method steps of any one of claims 1-5 when executing a program stored on a memory.
12. A computer-readable storage medium, characterized in that the computer-readable storage medium has stored therein a computer program which, when executed by a processor, implements the method steps of any of claims 1-5.
CN201811158046.0A 2018-09-30 2018-09-30 Text correction method and device Active CN109408813B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201811158046.0A CN109408813B (en) 2018-09-30 2018-09-30 Text correction method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201811158046.0A CN109408813B (en) 2018-09-30 2018-09-30 Text correction method and device

Publications (2)

Publication Number Publication Date
CN109408813A CN109408813A (en) 2019-03-01
CN109408813B true CN109408813B (en) 2023-07-21

Family

ID=65466681

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201811158046.0A Active CN109408813B (en) 2018-09-30 2018-09-30 Text correction method and device

Country Status (1)

Country Link
CN (1) CN109408813B (en)

Families Citing this family (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109922371B (en) * 2019-03-11 2021-07-09 海信视像科技股份有限公司 Natural language processing method, apparatus and storage medium
CN110276069B (en) * 2019-05-17 2021-04-02 中国科学院计算技术研究所 Method, system and storage medium for automatically detecting Chinese braille error
CN110232129B (en) * 2019-06-11 2020-09-29 北京百度网讯科技有限公司 Scene error correction method, device, equipment and storage medium
CN110232191A (en) * 2019-06-17 2019-09-13 无码科技(杭州)有限公司 Autotext error-checking method
CN111274785B (en) * 2020-01-21 2023-06-20 北京字节跳动网络技术有限公司 Text error correction method, device, equipment and medium
CN111310447B (en) * 2020-03-18 2024-02-02 河北省讯飞人工智能研究院 Grammar error correction method, grammar error correction device, electronic equipment and storage medium

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103488488A (en) * 2013-09-26 2014-01-01 贝壳网际(北京)安全技术有限公司 Text input check method, device ad mobile terminal
CN107085471A (en) * 2017-04-25 2017-08-22 北京百度网讯科技有限公司 A kind of input method error correction method and device based on user's input speed
CN107357775A (en) * 2017-06-05 2017-11-17 百度在线网络技术(北京)有限公司 The text error correction method and device of Recognition with Recurrent Neural Network based on artificial intelligence
CN107451106A (en) * 2017-07-26 2017-12-08 阿里巴巴集团控股有限公司 Text method and device for correcting, electronic equipment
CN108563634A (en) * 2018-03-29 2018-09-21 广州视源电子科技股份有限公司 Recognition methods, system, computer equipment and the storage medium of word misspelling

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
AU2015201364A1 (en) * 2014-03-17 2015-10-01 Accenture Global Services Limited Generating a semantic network based on semantic connections between subject-verb-object units
US11023680B2 (en) * 2016-02-17 2021-06-01 The King Abdulaziz City For Science And Technology (Kacst) Method and system for detecting semantic errors in a text using artificial neural networks

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103488488A (en) * 2013-09-26 2014-01-01 贝壳网际(北京)安全技术有限公司 Text input check method, device ad mobile terminal
CN107085471A (en) * 2017-04-25 2017-08-22 北京百度网讯科技有限公司 A kind of input method error correction method and device based on user's input speed
CN107357775A (en) * 2017-06-05 2017-11-17 百度在线网络技术(北京)有限公司 The text error correction method and device of Recognition with Recurrent Neural Network based on artificial intelligence
CN107451106A (en) * 2017-07-26 2017-12-08 阿里巴巴集团控股有限公司 Text method and device for correcting, electronic equipment
CN108563634A (en) * 2018-03-29 2018-09-21 广州视源电子科技股份有限公司 Recognition methods, system, computer equipment and the storage medium of word misspelling

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
汉语语音识别声调模型集成中基于决策树的上下文相关权重参数聚类方法;黄浩等;《新疆大学学报(自然科学版)》;20110815(第03期);全文 *

Also Published As

Publication number Publication date
CN109408813A (en) 2019-03-01

Similar Documents

Publication Publication Date Title
CN109408813B (en) Text correction method and device
US11321542B2 (en) Processing text sequences using neural networks
KR102204286B1 (en) Batch normalization layers
Zhao et al. Improving slot filling in spoken language understanding with joint pointer and attention
US11080589B2 (en) Sequence processing using online attention
US11928601B2 (en) Neural network compression
US20180203852A1 (en) Natural language generation through character-based recurrent neural networks with finite-state prior knowledge
US10699073B2 (en) Systems and methods for language detection
US11681872B2 (en) Language sequence labeling method and apparatus, storage medium, and computing device
US11003993B1 (en) Training recurrent neural networks to generate sequences
US11144721B2 (en) System and method for transforming unstructured text into structured form
US20210303786A1 (en) Machine learning based abbreviation expansion
CN112580310B (en) Missing character/word completion method and electronic equipment
Gale et al. Experiments in Character-Level Neural Network Models for Punctuation.
US20230205994A1 (en) Performing machine learning tasks using instruction-tuned neural networks
CN111339775A (en) Named entity identification method, device, terminal equipment and storage medium
US20220230065A1 (en) Semi-supervised training of machine learning models using label guessing
CN114818729A (en) Method, device and medium for training semantic recognition model and searching sentence
US20200104681A1 (en) Neural Networks with Area Attention
CN112509565A (en) Voice recognition method and device, electronic equipment and readable storage medium
Kamath et al. Sarcasm detection approaches survey
EP3519984A1 (en) Systems and methods for language detection
US20240078379A1 (en) Attention neural networks with n-grammer layers
Prasain et al. Nepali Spelling Checker
CN116362231A (en) Spelling error correction method, device and equipment for Indonesia and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant