Sentence identification method and device, storage medium and processor
Through the shared encoder and decoder, combined with the cross entropy loss function and the backpropagation algorithm, the model parameters are adjusted, and the poor performance problems caused by the annotation data of different tasks are solved, and the efficient processing of syntax error detection and error correction tasks are realized.
Patent Information
- Application Number
- CN201910390785.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-05-10
- Publication Date
- 2024-12-10
- Estimated Expiration
- 2039-05-10
AI Technical Summary
Due to the different annotation data of different tasks, the syntax error detection and error correction system processing tasks are poor, and there is currently no effective solution.
Through the shared encoder and decoder, the semantic representation of the pending statement is obtained, and the model parameters are adjusted using the cross entropy loss function and the backpropagation algorithm, and the weight value of the syntax error detection and error correction tasks are combined to realize syntax error detection and error correction. Shared training of tasks.
Improve system performance, enable heterogeneous annotated data to obtain information from each other, and improve the overall performance of syntax error detection and error correction tasks.
Smart Images

Figure CN111914540B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of information processing technology, and in particular to a sentence identification method and device, a storage medium and a processor. Background Art
[0002] In the past, due to the different task division and specific needs, the annotated data had certain differences in the grammatical error detection and correction tasks. In the grammatical error detection scenario, similar to the spell check in Word, it is only necessary to discover and identify the errors in the user's input and give prompts. Based on this requirement, the error positions and types in some data are annotated. For example, the sentence "I like to eat pingguo" is annotated as the fourth word "pingguo" error. In another grammatical error correction scenario, the user's input needs to be corrected. Based on this requirement, the grammatically correct form of another batch of data is annotated, such as the sentence "I like to eat pingguo" and its correct form "I like to eat apples". These two types of annotated data are not the same and cannot be directly mixed and used, so they are called heterogeneous annotated data. However, the detection and correction of grammatical errors in these two data are interrelated. Due to the different annotated data of different tasks, it is difficult to directly mix and use them, resulting in poor performance of the system in processing tasks.
[0003] To address the above-mentioned problems, no effective solution has been proposed yet. Summary of the invention
[0004] The embodiments of the present invention provide a sentence identification method and device, a storage medium and a processor to at least solve the technical problem that the system has poor performance in processing tasks because different annotation data of different tasks are difficult to directly mix and use.
[0005] According to one aspect of an embodiment of the present invention, there is provided a sentence identification method, comprising: obtaining a sentence to be processed; inputting the sentence to be processed into a target encoder, and processing to obtain a semantic representation of the sentence to be processed, wherein the target encoder is an encoder shared by a grammatical error detection task and a grammatical error correction task; inputting the semantic representation of the sentence to be processed into a processing model, and obtaining a processing result, wherein the processing result comprises one of the following: a grammatical error detection result, a grammatical error correction result.
[0006] Furthermore, the method further includes: before inputting the to-be-processed sentence into the target encoder and processing to obtain the semantic representation of the to-be-processed sentence, obtaining a plurality of annotated sentences, wherein the plurality of annotated sentences include: a first category of sentences with annotated grammatical errors and a second category of sentences with corrected grammatical errors; inputting the first category of sentences into the target encoder and processing to obtain the semantic representation of the first category of sentences, inputting the second category of sentences into the target encoder and processing to obtain the semantic representation of the second category of sentences, inputting the semantic representation of the first category of sentences into a grammatical error detection submodel to obtain grammatical error detection results of the first category of sentences, inputting the semantic representation of the second category of sentences into a target decoder to obtain grammatical error correction results of the second category of sentences; comparing the grammatical error detection results of the first category of sentences with the annotated grammatical errors to obtain a first comparison result, comparing the grammatical error correction results of the second category of sentences with the corrected grammatical errors to obtain a second comparison result; and adjusting the parameters of the target encoder according to the first comparison result and the second comparison result.
[0007] Furthermore, the method further includes: adjusting parameters of the grammatical error detection sub-model according to the first comparison result; and adjusting parameters of the target decoder according to the second comparison result.
[0008] Furthermore, according to the first comparison result and the second comparison result, adjusting the parameters of the target encoder includes: calculating a first loss value according to the first comparison result and a cross entropy loss function; calculating a second loss value according to the second comparison result and the cross entropy loss function; calculating a first parameter to be adjusted by using a back propagation algorithm for the first loss value, and calculating a second parameter to be adjusted by using the back propagation algorithm for the second loss value; and adjusting the parameters of the target encoder according to the first parameter and the second parameter.
[0009] Furthermore, according to the first parameter and the second parameter, adjusting the parameters of the target encoder includes: determining a first weight value of the grammatical error detection task and a second weight value of the grammatical error correction task; and adjusting the parameters of the target encoder according to the first parameter, the first weight value, the second parameter and the second weight value.
[0010] Furthermore, the target encoder is a multi-layer Bi-LSTM encoder, and the target decoder is a multi-layer Bi-LSTM decoder.
[0011] Furthermore, if the sentence to be processed is a sentence to be subjected to grammatical error detection, the processing model is a grammatical error detection sub-model; if the sentence to be processed is a sentence to be subjected to grammatical error correction, the processing model is a multi-layer Bi-LSTM decoder.
[0012] According to another aspect of an embodiment of the present invention, a sentence identification device is also provided, including: a first acquisition unit, used to acquire a sentence to be processed; a first processing unit, used to input the sentence to be processed into a target encoder, and process it to obtain a semantic representation of the sentence to be processed, wherein the target encoder is an encoder shared by a grammatical error detection task and a grammatical error correction task; a second processing unit, used to input the semantic representation of the sentence to be processed into a processing model, and obtain a processing result, wherein the processing result includes one of the following: a grammatical error detection result, a grammatical error correction result.
[0013] Furthermore, the device further comprises: a second acquisition unit, used for acquiring a plurality of annotated statements before inputting the to-be-processed statements into the target encoder and processing to obtain the semantic representation of the to-be-processed statements, wherein the plurality of annotated statements include: a first category of statements with annotated grammatical errors and a second category of statements with corrected grammatical errors; a third processing unit, used for inputting the first category of statements into the target encoder and processing to obtain the semantic representation of the first category of statements, inputting the second category of statements into the target encoder and processing to obtain the semantic representation of the second category of statements, the third acquisition unit, used for inputting the semantic representation of the first category of statements into the grammatical error detection submodel to obtain the grammatical error detection results of the first category of statements, inputting the semantic representation of the second category of statements into the target decoder to obtain the grammatical error correction results of the second category of statements; a comparison unit, used for comparing the grammatical error detection results of the first category of statements with the annotated grammatical errors to obtain a first comparison result, and comparing the grammatical error correction results of the second category of statements with the corrected grammatical errors to obtain a second comparison result; a first adjustment unit, used for adjusting the parameters of the target encoder according to the first comparison result and the second comparison result.
[0014] Furthermore, the device also includes: a second adjustment unit, used to adjust the parameters of the grammatical error detection sub-model according to the first comparison result; and a third adjustment unit, used to adjust the parameters of the target decoder according to the second comparison result.
[0015] Furthermore, the first adjustment unit includes: a first calculation module, used to calculate a first loss value according to the first comparison result and the cross entropy loss function, and to calculate a second loss value according to the second comparison result and the cross entropy loss function; a second calculation module, used to calculate a first parameter to be adjusted by using a back propagation algorithm for the first loss value, and to calculate a second parameter to be adjusted by using the back propagation algorithm for the second loss value; an adjustment module, used to adjust the parameters of the target encoder according to the first parameter and the second parameter.
[0016] Furthermore, the adjustment module includes: a determination submodule, used to determine a first weight value of the grammatical error detection task and a second weight value of the grammatical error correction task; an adjustment submodule, used to adjust the parameters of the target encoder according to the first parameter, the first weight value, the second parameter and the second weight value.
[0017] According to another aspect of an embodiment of the present invention, a storage medium is provided, characterized in that the storage medium includes a stored program, wherein when the program is executed, the device where the storage medium is located is controlled to execute any one of the statement identification methods described above.
[0018] According to another aspect of an embodiment of the present invention, a processor is provided, wherein the processor is used to run a program, wherein the program executes any one of the statement identification methods described above when the program is run.
[0019] In an embodiment of the present invention, a sentence to be processed is obtained; the sentence to be processed is input into a target encoder to obtain a semantic representation of the sentence to be processed, wherein the target encoder is an encoder shared by a grammatical error detection task and a grammatical error correction task; the semantic representation of the sentence to be processed is input into a processing model to obtain a processing result, wherein the processing result includes one of the following: a grammatical error detection result and a grammatical error correction result, thereby achieving the technical effect of improving system performance by using an encoder shared by a grammatical error detection task and a grammatical error correction task, so that heterogeneous data can obtain information from each other, thereby achieving the technical effect of improving system performance, and further solving the technical problem of poor performance of system processing tasks due to the difficulty in directly mixing different labeled data of different tasks. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of this application. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:
[0021] Figure 1 is a hardware structure block diagram of a computer terminal provided according to an embodiment of the present invention;
[0022] Figure 2 is a flow chart of a statement identification method provided according to an embodiment of the present invention;
[0023] Figure 3 is a schematic diagram of a sentence identification method provided according to an embodiment of the present invention;
[0024] Figure 4 is a schematic diagram of a sentence identification device provided according to an embodiment of the present invention; and
[0025] Figure 5 is a structural block diagram of an optional computer terminal according to an embodiment of the present invention. DETAILED DESCRIPTION
[0026] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.
[0027] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0028] First, some nouns or terms that appear in the description of the embodiments of the present application are subject to the following explanations:
[0029] Heterogeneous annotated data refers to data that is annotated for the same or related tasks, but the data itself is annotated with different contents. For example, in grammar correction, one set of data annotates some sentences and their corresponding grammatically correct forms, and another set of data annotates the sentences and the locations of their grammatical errors. These two sets of data are heterogeneous annotated data for grammar correction.
[0030] Grammatical error detection: refers to the detection of grammatical errors in sentences.
[0031] Grammatical error correction: refers to correcting grammatical errors in sentences.
[0032] Example 1
[0033] According to an embodiment of the present invention, a method embodiment of statement identification is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0034] The method embodiment provided in the first embodiment of the present application can be executed in a mobile terminal, a computer terminal or a similar computing device. Figure 1 FIG. 1 shows a hardware structure block diagram of a computer terminal (or mobile device) for implementing a sentence identification method. Figure 1 As shown, the computer terminal 10 (or mobile device 10) may include one or more (102a, 102b, ..., 102n are used to illustrate) processors 102 (the processor 102 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA), a memory 104 for storing data, and a transmission device for communication functions. In addition, it may also include: a display, an input / output interface (I / O interface), a universal serial bus (USB) port (which may be included as one of the ports of the I / O interface), a network interface, a power supply and / or a camera. It can be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the above electronic device. Figure 1 More or fewer components as shown, or with Figure 1 Different configurations are shown.
[0035] It should be noted that the one or more processors 102 and / or other data processing circuits described above may generally be referred to herein as "data processing circuits". The data processing circuits may be embodied in whole or in part as software, hardware, firmware, or any other combination thereof. In addition, the data processing circuit may be a single independent processing module, or may be incorporated in whole or in part into any of the other components in the computer terminal 10 (or mobile device). As described in the embodiments of the present application, the data processing circuit acts as a processor control (e.g., selection of a variable resistor terminal path connected to an interface).
[0036] The memory 104 can be used to store software programs and modules of application software, such as the program instructions / data storage device corresponding to the statement identification method in the embodiment of the present invention. The processor 102 executes various functional applications and data processing by running the software programs and modules stored in the memory 104, that is, the statement identification method of the above-mentioned application program is realized. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to the computer terminal 10 via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0037] The transmission device 106 is used to receive or send data via a network. The specific example of the above network may include a wireless network provided by a communication provider of the computer terminal 10. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0038] The display may be, for example, a touch screen liquid crystal display (LCD) that enables a user to interact with a user interface of the computer terminal 10 (or mobile device).
[0039] Under the above operating environment, this application provides Figure 2 The statement identification method shown. Figure 2 4 is a flow chart of a sentence identification method according to the first embodiment of the present invention.
[0040] Step S201, obtaining statements to be processed.
[0041] For example, the sentence to be processed is: I like to eat apples.
[0042] Step S202, inputting the sentence to be processed into a target encoder, and processing to obtain a semantic representation of the sentence to be processed, wherein the target encoder is an encoder shared by the grammatical error detection task and the grammatical error correction task.
[0043] The above-mentioned sentences to be processed can be sentences of grammatical error detection or correction data, which are passed through a shared target decoder (for example, a multi-layer Bi-LSTM encoder) to obtain the semantic representation of each word in the sentence. The multi-layer Bi-LSTM encoder contains: 1) The words of the sentence are mapped to vector representations through the word vector matrix to obtain the word vector sequence of the sentence; 2) The word vector sequence is passed through the multi-layer Bi-LSTM network to obtain the semantic representation of each word.
[0044] That is, the sentence to be processed is input into the target encoder, and the semantic representation is obtained as a matrix of N*D dimensions, where N and D are natural numbers. For example, the sentence to be processed is "I like to eat apples", which includes four words: I, like, eat, apples, and its semantic representation is a matrix of 4*100 dimensions.
[0045] Optionally, in the sentence identification method provided by the embodiment of the present invention, the method further includes: before inputting the sentence to be processed into the target encoder and processing to obtain the semantic representation of the sentence to be processed, obtaining a plurality of annotated sentences, wherein the plurality of annotated sentences include: a first category of sentences with annotated grammatical errors and a second category of sentences with corrected grammatical errors; inputting the first category of sentences into the target encoder and processing to obtain the semantic representation of the first category of sentences, inputting the second category of sentences into the target encoder and processing to obtain the semantic representation of the second category of sentences, inputting the semantic representation of the first category of sentences into a grammatical error detection submodel to obtain grammatical error detection results of the first category of sentences, inputting the semantic representation of the second category of sentences into the target decoder to obtain grammatical error correction results of the second category of sentences; comparing the grammatical error detection results of the first category of sentences with the annotated grammatical errors to obtain a first comparison result, comparing the grammatical error correction results of the second category of sentences with the corrected grammatical errors to obtain a second comparison result; and adjusting the parameters of the target encoder according to the first comparison result and the second comparison result.
[0046] The above-mentioned multiple marked sentences include the first category of sentences with marked grammatical errors and the second category of sentences with corrected grammatical errors. For example, the multiple marked sentences include: sentence one "Today's weather is really Qinlang", the grammatical error is marked as the error of the 4th word "Qinlang", and the grammatical error is corrected as "Today's weather is really sunny"; sentence two "Poor signal caused the call to be short", the grammatical error is marked as the error of the 5th word "short", and the grammatical error is corrected as "Poor signal caused the call to be interrupted". The sentence "The weather is really good in Qinlang today" which has been marked as an error in grammar as the fourth word "Qinlang" is input into the target encoder, and processed to obtain the semantic representation one of the sentence one. The sentence "The weather is really good in Qinlang today" which has been corrected as "The weather is really good today" is input into the target encoder, and processed to obtain the semantic representation two of the sentence one. The semantic representation one of the sentence one is input into the grammatical error detection sub-model to obtain the grammatical error detection result of the sentence one. The semantic representation two of the sentence one is input into the target decoder to obtain the grammatical error correction result of the sentence one. The grammatical error detection result of the sentence one is compared with the marked grammatical errors to obtain a first comparison result. The grammatical error correction result of the sentence one is compared with the corrected grammatical errors to obtain a second comparison result. The parameters of the target encoder are adjusted according to the first comparison result and the second comparison result.
[0047] Through the above scheme, the parameters of the target encoder are adjusted according to the first comparison result of sentence one and the second comparison result of sentence one, the parameters of the target encoder are adjusted according to the first comparison result of sentence two and the second comparison result of sentence two, and ... the parameters of the target encoder are adjusted according to the first comparison result of sentence N and the second comparison result of sentence one. The cross entropy loss function is calculated according to the first comparison result and the second comparison result, and the parameters of the target encoder are updated by reverse gradient propagation.
[0048] like Figure 3 As shown in the figure, this method uses a shared multi-layer Bi-LSTM encoder to extract the semantic representation of the sentence on the data of grammatical error detection and grammatical error correction, and trains the encoder with heterogeneous data, so that the encoder can be fully learned and can extract error detection and correction information at the same time. The independent grammatical error detection sub-model and multi-layer Bi-LSTM decoder of different data ensure the difference of different data output. At the same time, the two grammatical error detection tasks and grammatical error correction tasks of this scheme have no cascade relationship, and will not cause error accumulation. Different data can be trained jointly, so that heterogeneous data can obtain information from each other, and finally improve system performance.
[0049] Step S203, inputting the semantic representation of the sentence to be processed into the processing model to obtain a processing result, wherein the processing result includes one of the following: a grammatical error detection result, a grammatical error correction result.
[0050] In the sentence identification method provided in an embodiment of the present invention, if the sentence to be processed is a sentence to be detected for grammatical errors, the processing model is a grammatical error detection sub-model; if the sentence to be processed is a sentence to be corrected for grammatical errors, the processing model is a multi-layer Bi-LSTM decoder.
[0051] If the sentence to be processed "I like to eat apples" is represented by a 4*100-dimensional matrix and input into the grammatical error detection sub-model, the grammatical error detection result of the sentence to be processed "I like to eat apples" is that the fourth word "apple" is marked as an error. If the sentence to be processed "I like to eat apples" is represented by a 4*100-dimensional matrix and input into the multi-layer Bi-LSTM decoder, the grammatical error correction result of the sentence to be processed "I like to eat apples" is "I like to eat apples".
[0052] In summary, the sentence identification method provided by the embodiment of the present invention obtains the sentence to be processed; inputs the sentence to be processed into the target encoder, and processes to obtain the semantic representation of the sentence to be processed, wherein the target encoder is an encoder shared by the grammatical error detection task and the grammatical error correction task; inputs the semantic representation of the sentence to be processed into the processing model, and obtains the processing result, wherein the processing result includes one of the following: a grammatical error detection result, a grammatical error correction result, and achieves the technical effect of improving the system performance by using the encoder shared by the grammatical error detection task and the grammatical error correction task, thereby solving the technical problem of poor performance of the system processing task due to the difficulty in directly mixing the different labeled data of different tasks.
[0053] Optionally, in the sentence identification method provided by the embodiment of the present invention, the method further includes: adjusting parameters of the grammatical error detection sub-model according to the first comparison result; and adjusting parameters of the target decoder according to the second comparison result.
[0054] In the above scheme, by adjusting the parameters of the grammatical error detection submodel according to the first comparison result and adjusting the parameters of the target decoder according to the second comparison result, the parameters of the grammatical error detection submodel and the target decoder are continuously updated, thereby ensuring the accuracy of the output results of the grammatical error detection submodel and the target decoder.
[0055] Optionally, in the sentence identification method provided in an embodiment of the present invention, adjusting the parameters of the target encoder according to the first comparison result and the second comparison result includes: calculating a first loss value according to the first comparison result and a cross-entropy loss function; calculating a second loss value according to the second comparison result and the cross-entropy loss function; calculating a first parameter to be adjusted using a back-propagation algorithm for the first loss value, and calculating a second parameter to be adjusted using a back-propagation algorithm for the second loss value; and adjusting the parameters of the target encoder according to the first parameter and the second parameter.
[0056] In the above scheme, the first parameter to be adjusted and the second parameter to be adjusted include the parameter to be adjusted and the value to be updated. By determining the first parameter to be adjusted and the second parameter to be adjusted, the parameters of the target encoder are adjusted, thereby playing the role of jointly training the target encoder.
[0057] Optionally, in the sentence identification method provided in an embodiment of the present invention, adjusting the parameters of the target encoder according to the first parameter and the second parameter includes: determining a first weight value for the grammatical error detection task and a second weight value for the grammatical error correction task; adjusting the parameters of the target encoder according to the first parameter, the first weight value, the second parameter and the second weight value.
[0058] For example, the first weight value of the grammatical error detection task is 0.5, and the second weight value of the grammatical error correction task is 1.0. The first parameter to be adjusted * 0.5 + the second parameter to be adjusted * 1.0 is used to obtain the parameters of the final adjusted target encoder. By presetting the weight values of different tasks, the training of the trained target encoder is more targeted, ensuring the accuracy of the output results of the target encoder at the training site.
[0059] It should be noted that, for the above-mentioned method embodiments, for the sake of simplicity, they are all described as a series of action combinations, but those skilled in the art should know that the present invention is not limited by the described action sequence, because according to the present invention, certain steps can be performed in other sequences or simultaneously. Secondly, those skilled in the art should also know that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present invention.
[0060] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, a magnetic disk, or an optical disk), and includes a number of instructions for enabling a terminal device (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present invention.
[0061] Example 2
[0062] According to an embodiment of the present invention, a device for implementing the above-mentioned sentence identification method is also provided. Figure 4 As shown, the device comprises:
[0063] A first acquisition unit 401 is used to acquire a statement to be processed;
[0064] A first processing unit 402 is used to input the sentence to be processed into a target encoder to process and obtain a semantic representation of the sentence to be processed, wherein the target encoder is an encoder shared by a grammatical error detection task and a grammatical error correction task;
[0065] The second processing unit 403 is used to input the semantic representation of the sentence to be processed into the processing model to obtain a processing result, wherein the processing result includes one of the following: a grammatical error detection result and a grammatical error correction result.
[0066] In summary, the sentence identification method provided by the embodiment of the present invention obtains the sentence to be processed through the first acquisition unit 401; the first processing unit 402 inputs the sentence to be processed into the target encoder, and processes to obtain the semantic representation of the sentence to be processed, wherein the target encoder is an encoder shared by the grammatical error detection task and the grammatical error correction task; the second processing unit 403 inputs the semantic representation of the sentence to be processed into the processing model to obtain a processing result, wherein the processing result includes one of the following: a grammatical error detection result, a grammatical error correction result, and achieves the goal of using an encoder shared by the grammatical error detection task and the grammatical error correction task so that heterogeneous data can obtain information from each other, thereby achieving the technical effect of improving system performance, and further solving the technical problem of poor performance of system processing tasks due to the difficulty in directly mixing different annotated data of different tasks.
[0067] Optionally, in the sentence identification device provided in the embodiment of the present invention, the device further includes: a second acquisition unit, used to acquire a plurality of annotated sentences before inputting the sentence to be processed into the target encoder and processing to obtain the semantic representation of the sentence to be processed, wherein the plurality of annotated sentences include: a first category of sentences with annotated grammatical errors and a second category of sentences with grammatical errors corrected; a third processing unit, used to input the first category of sentences into the target encoder and process to obtain the semantic representation of the first category of sentences, input the second category of sentences into the target encoder and process to obtain the semantic representation of the second category of sentences, and the third acquisition unit, used to input the first category of sentences into the target encoder and process to obtain the semantic representation of the second category of sentences. A unit is used to input the semantic representation of the first category of sentences into a grammatical error detection submodel to obtain grammatical error detection results of the first category of sentences, and input the semantic representation of the second category of sentences into a target decoder to obtain grammatical error correction results of the second category of sentences; a comparison unit is used to compare the grammatical error detection results of the first category of sentences with the marked grammatical errors to obtain a first comparison result, and compare the grammatical error correction results of the second category of sentences with the corrected grammatical errors to obtain a second comparison result; a first adjustment unit is used to adjust the parameters of the target encoder according to the first comparison result and the second comparison result.
[0068] Optionally, in the sentence identification device provided in an embodiment of the present invention, the device also includes: a second adjustment unit, used to adjust the parameters of the grammatical error detection sub-model according to the first comparison result; and a third adjustment unit, used to adjust the parameters of the target decoder according to the second comparison result.
[0069] Optionally, in the sentence identification device provided by an embodiment of the present invention, the first adjustment unit includes: a first calculation module, used to calculate a first loss value based on the first comparison result and the cross entropy loss function, and to calculate a second loss value based on the second comparison result and the cross entropy loss function; a second calculation module, used to calculate a first parameter to be adjusted by using a back propagation algorithm for the first loss value, and to calculate a second parameter to be adjusted by using the back propagation algorithm for the second loss value; an adjustment module, used to adjust the parameters of the target encoder according to the first parameter and the second parameter.
[0070] Optionally, in the sentence identification device provided in an embodiment of the present invention, the adjustment module includes: a determination submodule, used to determine a first weight value of the grammatical error detection task and a second weight value of the grammatical error correction task; an adjustment submodule, used to adjust the parameters of the target encoder according to the first parameter, the first weight value, the second parameter and the second weight value.
[0071] Optionally, in the sentence identification device provided by an embodiment of the present invention, the target encoder is a multi-layer Bi-LSTM encoder, and the target decoder is a multi-layer Bi-LSTM decoder.
[0072] Optionally, in the sentence identification device provided in an embodiment of the present invention, if the sentence to be processed is a sentence to be subjected to grammatical error detection, the processing model is a grammatical error detection sub-model; if the sentence to be processed is a sentence to be subjected to grammatical error correction, the processing model is a multi-layer Bi-LSTM decoder.
[0073] It should be noted that the first acquisition unit 401, the first processing unit 402 and the second processing unit 403 described above correspond to step S201, step S202 to step S203 in Example 1, and the examples and application scenarios implemented by the two modules and the corresponding steps are the same, but are not limited to the contents disclosed in the above-mentioned Example 1. It should be noted that the above-mentioned modules as part of the device can be run in the computer terminal 10 provided in Example 1.
[0074] Example 3
[0075] The embodiment of the present invention can provide a computer terminal, which can be any computer terminal device in a computer terminal group. Optionally, in this embodiment, the computer terminal can also be replaced by a terminal device such as a mobile terminal.
[0076] Optionally, in this embodiment, the computer terminal may be located in at least one network device among a plurality of network devices of the computer network.
[0077] In this embodiment, the above-mentioned computer terminal can execute the program code of the following steps in the sentence identification method of the application: obtaining the sentence to be processed; inputting the sentence to be processed into the target encoder, and processing to obtain the semantic representation of the sentence to be processed, wherein the target encoder is an encoder shared by the grammatical error detection task and the grammatical error correction task; inputting the semantic representation of the sentence to be processed into the processing model to obtain the processing result, wherein the processing result includes one of the following: grammatical error detection result, grammatical error correction result.
[0078] The above-mentioned computer terminal can also execute the program code of the following steps in the sentence identification method of the application: the method also includes: before inputting the sentence to be processed into the target encoder and processing to obtain the semantic representation of the sentence to be processed, obtaining multiple annotated sentences, wherein the multiple annotated sentences include: a first category of sentences with annotated grammatical errors and a second category of sentences with corrected grammatical errors; inputting the first category of sentences into the target encoder and processing to obtain the semantic representation of the first category of sentences, inputting the second category of sentences into the target encoder and processing to obtain the semantic representation of the second category of sentences, inputting the semantic representation of the first category of sentences into the grammatical error detection submodel to obtain the grammatical error detection results of the first category of sentences, inputting the semantic representation of the second category of sentences into the target decoder to obtain the grammatical error correction results of the second category of sentences; comparing the grammatical error detection results of the first category of sentences with the annotated grammatical errors to obtain a first comparison result, comparing the grammatical error correction results of the second category of sentences with the corrected grammatical errors to obtain a second comparison result; adjusting the parameters of the target encoder according to the first comparison result and the second comparison result.
[0079] The above-mentioned computer terminal can also execute the program code of the following steps in the sentence identification method of the application: the method also includes: adjusting the parameters of the grammatical error detection sub-model according to the first comparison result; adjusting the parameters of the target decoder according to the second comparison result.
[0080] The above-mentioned computer terminal can also execute the program code of the following steps in the statement identification method of the application: adjusting the parameters of the target encoder according to the first comparison result and the second comparison result includes: calculating the first loss value according to the first comparison result and the cross entropy loss function; calculating the second loss value according to the second comparison result and the cross entropy loss function; calculating the first parameter to be adjusted by the first loss value through the back propagation algorithm, and calculating the second parameter to be adjusted by the second loss value through the back propagation algorithm; adjusting the parameters of the target encoder according to the first parameter and the second parameter.
[0081] The above-mentioned computer terminal can also execute the program code of the following steps in the sentence identification method of the application: adjusting the parameters of the target encoder according to the first parameter and the second parameter includes: determining the first weight value of the grammatical error detection task and the second weight value of the grammatical error correction task; adjusting the parameters of the target encoder according to the first parameter, the first weight value, the second parameter and the second weight value.
[0082] The computer terminal can also execute the program code of the following steps in the statement identification method of the application: the target encoder is a multi-layer Bi-LSTM encoder, and the target decoder is a multi-layer Bi-LSTM decoder.
[0083] The above-mentioned computer terminal can also execute the program code of the following steps in the sentence identification method of the application: if the sentence to be processed is a sentence to be detected for grammatical errors, the processing model is a grammatical error detection sub-model; if the sentence to be processed is a sentence to be corrected for grammatical errors, the processing model is a multi-layer Bi-LSTM decoder.
[0084] Optionally, Figure 5 is a structural block diagram of a computer terminal according to an embodiment of the present invention. Figure 5 As shown, the computer terminal A may include: one or more (only one is shown in the figure) processors and a memory.
[0085] Among them, the memory can be used to store software programs and modules, such as program instructions / modules corresponding to the sentence identification method and device in the embodiment of the present invention. The processor executes various functional applications and data processing by running the software programs and modules stored in the memory, that is, realizing the above-mentioned sentence identification method. The memory may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory may further include a memory remotely arranged relative to the processor, and these remote memories can be connected to the terminal A via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0086] The processor can call the information and application stored in the memory through the transmission device to perform the following steps: obtain the sentence to be processed; input the sentence to be processed into the target encoder, and process it to obtain the semantic representation of the sentence to be processed, wherein the target encoder is an encoder shared by the grammatical error detection task and the grammatical error correction task; input the semantic representation of the sentence to be processed into the processing model to obtain the processing result, wherein the processing result includes one of the following: grammatical error detection result, grammatical error correction result.
[0087] Optionally, the processor may also execute the program code of the following steps: the method also includes: before inputting the sentence to be processed into the target encoder and processing to obtain the semantic representation of the sentence to be processed, obtaining a plurality of annotated sentences, wherein the plurality of annotated sentences include: a first category of sentences with annotated grammatical errors and a second category of sentences with corrected grammatical errors; inputting the first category of sentences into the target encoder and processing to obtain the semantic representation of the first category of sentences, inputting the second category of sentences into the target encoder and processing to obtain the semantic representation of the second category of sentences, inputting the semantic representation of the first category of sentences into the grammatical error detection submodel to obtain the grammatical error detection results of the first category of sentences, inputting the semantic representation of the second category of sentences into the target decoder to obtain the grammatical error correction results of the second category of sentences; comparing the grammatical error detection results of the first category of sentences with the annotated grammatical errors to obtain a first comparison result, comparing the grammatical error correction results of the second category of sentences with the corrected grammatical errors to obtain a second comparison result; adjusting the parameters of the target encoder according to the first comparison result and the second comparison result.
[0088] Optionally, the processor may also execute program code of the following steps: the method further includes: adjusting parameters of a grammatical error detection sub-model according to the first comparison result; and adjusting parameters of a target decoder according to the second comparison result.
[0089] Optionally, the processor may also execute the following steps of program code: adjusting the parameters of the target encoder according to the first comparison result and the second comparison result includes: calculating a first loss value according to the first comparison result and the cross entropy loss function; calculating a second loss value according to the second comparison result and the cross entropy loss function; calculating a first parameter to be adjusted using a back propagation algorithm for the first loss value, and calculating a second parameter to be adjusted using a back propagation algorithm for the second loss value; adjusting the parameters of the target encoder according to the first parameter and the second parameter.
[0090] Optionally, the processor may also execute the program code of the following steps: adjusting the parameters of the target encoder according to the first parameter and the second parameter, including: determining a first weight value for the grammatical error detection task and a second weight value for the grammatical error correction task; adjusting the parameters of the target encoder according to the first parameter, the first weight value, the second parameter and the second weight value.
[0091] Optionally, the processor may also execute program code of the following steps: the target encoder is a multi-layer Bi-LSTM encoder, and the target decoder is a multi-layer Bi-LSTM decoder.
[0092] Optionally, the processor may also execute the following program code: if the statement to be processed is a statement to be subjected to grammatical error detection, the processing model is a grammatical error detection sub-model; if the statement to be processed is a statement to be subjected to grammatical error correction, the processing model is a multi-layer Bi-LSTM decoder.
[0093] By adopting the embodiment of the present invention, a solution for sentence identification is provided, which includes obtaining a sentence to be processed; inputting the sentence to be processed into a target encoder, and processing to obtain a semantic representation of the sentence to be processed, wherein the target encoder is an encoder shared by a grammatical error detection task and a grammatical error correction task; inputting the semantic representation of the sentence to be processed into a processing model, and obtaining a processing result, wherein the processing result includes one of the following: a grammatical error detection result, and a grammatical error correction result, so that the encoder shared by the grammatical error detection task and the grammatical error correction task enables heterogeneous data to obtain information from each other, thereby achieving the technical effect of improving system performance, and further solving the technical problem of poor performance of system processing tasks due to the difficulty in directly mixing different annotated data of different tasks.
[0094] It can be understood by those skilled in the art that Figure 5 The structure shown is for illustration only, and the computer terminal may also be a smart phone (such as an Android phone, an iOS phone, etc.), a tablet computer, a handheld computer, a mobile Internet device (Mobile Internet Devices, MID), a PAD, and other terminal devices. Figure 5 The structure of the electronic device is not limited. For example, the computer terminal 10 may also include Figure 5 More or fewer components (such as network interfaces, display devices, etc.) shown in, or having Figure 5 Different configurations are shown.
[0095] A person of ordinary skill in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing the hardware related to the terminal device through a program, and the program can be stored in a computer-readable storage medium, and the storage medium may include: a flash drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.
[0096] Example 4
[0097] The embodiment of the present invention further provides a storage medium. Optionally, in this embodiment, the storage medium can be used to store the program code executed by the statement identification method provided in the first embodiment.
[0098] Optionally, in this embodiment, the above storage medium may be located in any computer terminal in a computer terminal group in a computer network, or in any mobile terminal in a mobile terminal group.
[0099] Optionally, in this embodiment, the storage medium is configured to store program code for executing the following steps: obtaining a sentence to be processed; inputting the sentence to be processed into a target encoder, and processing to obtain a semantic representation of the sentence to be processed, wherein the target encoder is an encoder shared by a grammatical error detection task and a grammatical error correction task; inputting the semantic representation of the sentence to be processed into a processing model, and obtaining a processing result, wherein the processing result includes one of the following: a grammatical error detection result, a grammatical error correction result.
[0100] Optionally, in this embodiment, the storage medium is configured to store program code for executing the following steps: the method also includes: before inputting the sentence to be processed into the target encoder and processing to obtain the semantic representation of the sentence to be processed, obtaining a plurality of annotated sentences, wherein the plurality of annotated sentences include: a first category of sentences with annotated grammatical errors and a second category of sentences with corrected grammatical errors; inputting the first category of sentences into the target encoder and processing to obtain the semantic representation of the first category of sentences, inputting the second category of sentences into the target encoder and processing to obtain the semantic representation of the second category of sentences, inputting the semantic representation of the first category of sentences into the grammatical error detection submodel to obtain grammatical error detection results of the first category of sentences, inputting the semantic representation of the second category of sentences into the target decoder to obtain grammatical error correction results of the second category of sentences; comparing the grammatical error detection results of the first category of sentences with the annotated grammatical errors to obtain a first comparison result, comparing the grammatical error correction results of the second category of sentences with the corrected grammatical errors to obtain a second comparison result; adjusting the parameters of the target encoder according to the first comparison result and the second comparison result.
[0101] Optionally, in this embodiment, the storage medium is configured to store program codes for executing the following steps: the method further includes: adjusting parameters of a grammatical error detection submodel according to the first comparison result; and adjusting parameters of a target decoder according to the second comparison result.
[0102] Optionally, in this embodiment, the storage medium is configured to store program code for performing the following steps: adjusting the parameters of the target encoder according to the first comparison result and the second comparison result includes: calculating a first loss value according to the first comparison result and the cross entropy loss function; calculating a second loss value according to the second comparison result and the cross entropy loss function; calculating a first parameter to be adjusted by using a back propagation algorithm for the first loss value, and calculating a second parameter to be adjusted by using a back propagation algorithm for the second loss value; adjusting the parameters of the target encoder according to the first parameter and the second parameter.
[0103] Optionally, in this embodiment, the storage medium is configured to store program code for performing the following steps: adjusting the parameters of the target encoder according to the first parameter and the second parameter includes: determining a first weight value for the grammatical error detection task and a second weight value for the grammatical error correction task; adjusting the parameters of the target encoder according to the first parameter, the first weight value, the second parameter and the second weight value.
[0104] Optionally, in this embodiment, the storage medium is configured to store program codes for executing the following steps: the target encoder is a multi-layer Bi-LSTM encoder, and the target decoder is a multi-layer Bi-LSTM decoder.
[0105] Optionally, in this embodiment, the storage medium is configured to store program code for executing the following steps: if the statement to be processed is a statement to be subjected to grammatical error detection, the processing model is a grammatical error detection sub-model; if the statement to be processed is a statement to be subjected to grammatical error correction, the processing model is a multi-layer Bi-LSTM decoder.
[0106] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.
[0107] In the above embodiments of the present invention, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0108] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.
[0109] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0110] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0111] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, magnetic disk or optical disk and other media that can store program codes.
[0112] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principle of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.
Claims
1. A sentence identification method, characterized in that: include: Get pending statements; Inputting the sentence to be processed into a target encoder to process and obtain a semantic representation of the sentence to be processed, wherein the target encoder is an encoder shared by a grammatical error detection task and a grammatical error correction task; Inputting the semantic representation of the sentence to be processed into the processing model to obtain a processing result, wherein the processing result includes one of the following: a grammatical error detection result and a grammatical error correction result; The target encoder is obtained by adjusting the parameters of the target encoder according to a plurality of annotated sentences, a grammatical error detection submodel and a target decoder, wherein the plurality of annotated sentences include: a first category of sentences with annotated grammatical errors and a second category of sentences with corrected grammatical errors, and the parameters of the target encoder are adjusted by calculating a cross entropy loss function according to a first comparison result corresponding to the first category of sentences output by the grammatical error detection submodel and a second comparison result corresponding to the second category of sentences output by the target decoder, and updating the parameters of the target encoder by reverse gradient propagation; The processing model is one of the following: the syntax error detection sub-model, the target decoder.
2. The method according to claim 1, characterized in that: The method further comprises: Before inputting the sentence to be processed into the target encoder to process and obtain the semantic representation of the sentence to be processed, obtaining a plurality of annotated sentences; Inputting the first category of sentences into the target encoder to process and obtain semantic representations of the first category of sentences, inputting the second category of sentences into the target encoder to process and obtain semantic representations of the second category of sentences, Inputting the semantic representation of the first type of sentences into a grammatical error detection sub-model to obtain grammatical error detection results of the first type of sentences, and inputting the semantic representation of the second type of sentences into a target decoder to obtain grammatical error correction results of the second type of sentences; Compare the grammatical error detection results of the first type of sentences with the marked grammatical errors to obtain a first comparison result, and compare the grammatical error correction results of the second type of sentences with the corrected grammatical errors to obtain a second comparison result; Adjust parameters of the target encoder according to the first comparison result and the second comparison result.
3. The method according to claim 2, characterized in that The method further comprises: adjusting the parameters of the grammatical error detection sub-model according to the first comparison result; The parameters of the target decoder are adjusted according to the second comparison result.
4. The method according to claim 2, characterized in that: According to the first comparison result and the second comparison result, adjusting the parameters of the target encoder includes: Calculate a first loss value according to the first comparison result and the cross entropy loss function; Calculate a second loss value according to the second comparison result and the cross entropy loss function; The first loss value is used to calculate a first parameter to be adjusted through a back propagation algorithm, and the second loss value is used to calculate a second parameter to be adjusted through the back propagation algorithm; According to the first parameter and the second parameter, the parameters of the target encoder are adjusted.
5. The method according to claim 4, characterized in that According to the first parameter and the second parameter, adjusting the parameter of the target encoder includes: Determining a first weight value of the grammatical error detection task and a second weight value of the grammatical error correction task; Adjust parameters of the target encoder according to the first parameter, the first weight value, the second parameter and the second weight value.
6. The method according to claim 2, characterized in that The target encoder is a multi-layer Bi-LSTM encoder, and the target decoder is a multi-layer Bi-LSTM decoder.
7. The method according to claim 6, characterized in that If the sentence to be processed is a sentence to be subjected to grammatical error detection, the processing model is a grammatical error detection sub-model; if the sentence to be processed is a sentence to be subjected to grammatical error correction, the processing model is a multi-layer Bi-LSTM decoder.
8. A sentence identification device, characterized in that: include: A first acquisition unit, used for acquiring a statement to be processed; A first processing unit is used to input the sentence to be processed into a target encoder to process and obtain a semantic representation of the sentence to be processed, wherein the target encoder is an encoder shared by a grammatical error detection task and a grammatical error correction task; A second processing unit, configured to input the semantic representation of the sentence to be processed into a processing model to obtain a processing result, wherein the processing result includes one of the following: a grammatical error detection result and a grammatical error correction result; The target encoder is obtained by adjusting the parameters of the target encoder according to a plurality of annotated sentences, a grammatical error detection submodel and a target decoder, wherein the plurality of annotated sentences include: a first category of sentences with annotated grammatical errors and a second category of sentences with corrected grammatical errors, and the parameters of the target encoder are adjusted by calculating a cross entropy loss function according to a first comparison result corresponding to the first category of sentences output by the grammatical error detection submodel and a second comparison result corresponding to the second category of sentences output by the target decoder, and updating the parameters of the target encoder by reverse gradient propagation; The processing model is one of the following: the syntax error detection sub-model, the target decoder.
9. The device according to claim 8, characterized in that The device also includes: A second acquisition unit is used to acquire a plurality of annotated sentences before inputting the sentence to be processed into a target encoder to process and obtain a semantic representation of the sentence to be processed; a third processing unit, configured to input the first category of sentences into the target encoder to process and obtain semantic representations of the first category of sentences, input the second category of sentences into the target encoder to process and obtain semantic representations of the second category of sentences, a third acquisition unit, configured to input the semantic representation of the first type of sentences into a grammatical error detection submodel to obtain grammatical error detection results of the first type of sentences, and input the semantic representation of the second type of sentences into a target decoder to obtain grammatical error correction results of the second type of sentences; A comparison unit, configured to compare the grammatical error detection result of the first type of sentence with the marked grammatical errors to obtain a first comparison result, and to compare the grammatical error correction result of the second type of sentence with the corrected grammatical errors to obtain a second comparison result; The first adjustment unit is used to adjust the parameters of the target encoder according to the first comparison result and the second comparison result.
10. The device according to claim 9, characterized in that The device also includes: a second adjustment unit, configured to adjust parameters of the grammatical error detection sub-model according to the first comparison result; A third adjustment unit is used to adjust the parameters of the target decoder according to the second comparison result.
11. The device according to claim 9, characterized in that The first adjustment unit comprises: A first calculation module, used to calculate a first loss value according to the first comparison result and a cross entropy loss function, and calculate a second loss value according to the second comparison result and the cross entropy loss function; A second calculation module, used to calculate a first parameter to be adjusted by using a back propagation algorithm for the first loss value, and to calculate a second parameter to be adjusted by using the back propagation algorithm for the second loss value; An adjustment module is used to adjust the parameters of the target encoder according to the first parameter and the second parameter.
12. The device according to claim 11, characterized in that The adjustment module comprises: A determination submodule, used to determine a first weight value of the grammatical error detection task and a second weight value of the grammatical error correction task; An adjustment submodule is used to adjust the parameters of the target encoder according to the first parameter, the first weight value, the second parameter and the second weight value.
13. A storage medium, characterized in that: The storage medium includes a stored program, wherein when the program is executed, the device where the storage medium is located is controlled to execute the statement identification method according to any one of claims 1 to 7.
14. A processor, characterized in that: The processor is used to run a program, wherein the program executes the statement identification method described in any one of claims 1 to 7 when running.
