Sequence labeling method, device, equipment and storage medium in natural language processing

The sequence annotation model is trained by encoding text sequence samples in multiple encoding modes, and the encoding mode is automatically selected during the annotation process, which solves the problem of poor universality of the latent variable conditional random field model and improves the effect of sequence annotation.

CN109885702BActive Publication Date: 2024-08-23HARBIN INST OF TECH SHENZHEN GRADUATE SCHOOL +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN201910146893.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Priority Date
2019-01-17
Filing Date
2019-02-27
Publication Date
2024-08-23
Estimated Expiration
2039-02-27

AI Technical Summary

Technical Problem

Due to differences in coding modes during sequence labeling, the latent variable conditional random field model has poor universality and affects the labeling effect.

Method used

Encode text sequence samples through multiple encoding modes, train to obtain a sequence annotation model, automatically select the best encoding mode during the annotation process, and output labels corresponding to multiple encoding modes.

Benefits of technology

The universality and annotation effect of the sequence annotation model for different input text sequences are improved, so that the annotation is not limited to a single encoding mode.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN109885702B_ABST
    Figure CN109885702B_ABST
Patent Text Reader

Abstract

The present application is about a sequence labeling method in natural language processing, which includes: obtaining a text sequence, inputting the text sequence into a sequence labeling model, obtaining a target path, each node in the target path is a label in a preset label set, and the preset label set contains labels corresponding to m encoding modes; arranging the nodes in the target path in order from first to last in the target path, and obtaining a labeling sequence corresponding to the text sequence. The present application trains the results of encoding text sequence samples according to multiple encoding modes to obtain a sequence labeling model, and processes the input text sequence through the sequence model label, and outputs the labeling sequence corresponding to the text sequence, so that the labeling of the text sequence is not limited to a single encoding mode, thereby improving the universality of the sequence labeling model for different inputs and improving the effect of sequence labeling.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of natural language processing, and in particular to a sequence labeling method, apparatus, device and storage medium in natural language processing. Background Art

[0002] Sequence labeling is one of the basic problems often encountered when solving natural language processing problems. The latent variable conditional random field model is a commonly used model for sequence labeling.

[0003] In the related art, the latent variable conditional random field model uses a certain encoding pattern as a latent variable. When performing sequence labeling on the input text sequence, the latent variable conditional random field model assigns each label of the corresponding encoding pattern to each text element in the input text sequence, thereby realizing the labeling of the text elements in the text sequence.

[0004] However, when the latent variable conditional random field model is used to label text sequences, different encoding modes have different labeling effects on different text sequences. For example, a certain encoding mode has a better labeling effect on text sequence 1, but may have a poorer labeling effect on text sequence 2, which leads to poor universality of the latent variable conditional random field model and affects the labeling effect. Summary of the invention

[0005] The embodiment of the present application provides a sequence labeling method, apparatus, device and storage medium in natural language processing, which can improve the accuracy of labeling text sequences through a latent variable conditional random field model. The technical solution is as follows:

[0006] On the one hand, a sequence tagging method in natural language processing is provided, the method comprising:

[0007] Obtain a text sequence, wherein the text sequence includes n text elements, where n is an integer greater than or equal to 2;

[0008] Input the text sequence into a sequence labeling model to obtain a target path output by the sequence labeling model, wherein the sequence labeling model is obtained by training based on text sequence samples and labeling sequence samples, wherein the labeling sequence samples are labeling sequences obtained by encoding the text sequence samples according to m encoding modes, where m is an integer greater than or equal to 2; each node in the target path is a label in a preset label set, and the preset label set contains labels corresponding to the m encoding modes;

[0009] Arrange the nodes in the target path in order from first to last in the target path to obtain a label sequence corresponding to the text sequence.

[0010] On the other hand, a sequence labeling model training method is provided, the method comprising:

[0011] Get text sequence samples;

[0012] Encode the text sequence samples according to m encoding modes to obtain a label sequence sample, where m is an integer greater than or equal to 2;

[0013] Training is performed based on the text sequence samples and the annotation sequence samples to obtain a sequence annotation model, wherein the sequence annotation model is used to output a target path based on the input text sequence, wherein each node in the target path is a label in a preset label set, and the preset label set contains labels corresponding to the m encoding modes.

[0014] On the other hand, a sequence tagging device in natural language processing is provided, the device comprising:

[0015] A text sequence acquisition module, used to acquire a text sequence, wherein the text sequence includes n text elements, where n is an integer greater than or equal to 2;

[0016] A path acquisition module is used to input the text sequence into a sequence labeling model to obtain a target path output by the sequence labeling model, wherein the sequence labeling model is obtained by training based on text sequence samples and labeling sequence samples, wherein the labeling sequence samples are labeling sequences obtained by encoding the text sequence samples according to m encoding modes, where m is an integer greater than or equal to 2; each node in the target path is a label in a preset label set, and the preset label set contains labels corresponding to the m encoding modes;

[0017] The annotation sequence obtaining module is used to arrange the nodes in the target path in order from first to last in the target path to obtain the annotation sequence corresponding to the text sequence.

[0018] Optionally, the path acquisition module is specifically used to:

[0019] Inputting the text sequence into a sequence labeling model to obtain a probability value of each candidate label path output by the sequence labeling model, wherein the probability value indicates the probability that the actual label path of the text sequence is the corresponding candidate label path;

[0020] The path with the largest probability value among the candidate label paths is obtained as the target path.

[0021] Optionally, any one of the alternative label paths starts from a label in the first column of the first label matrix and passes through a label in each column of the first label matrix in sequence; the first label matrix contains n columns of labels, and each column of the n columns of labels contains each label corresponding to the m encoding modes.

[0022] Optionally, the device further comprises:

[0023] A first sample acquisition module is used to acquire each first subsequence sample of the labeled sequence sample before the path acquisition module inputs the text sequence into the sequence labeling model to obtain the target path output by the sequence labeling model, wherein the first label in the first subsequence sample is any label among the m labels corresponding to the first text element; the first label is any label in the first subsequence sample, the first text element is the text element in the text sequence sample corresponding to the first label, and the m labels corresponding to the first text element are labels corresponding to the first text element when it is encoded according to the m encoding modes respectively;

[0024] The first training module is used to perform training according to the text sequence samples and the first subsequence samples to obtain the sequence labeling model.

[0025] Optionally, any one of the alternative label paths is a path starting from a label in the first column of the second label matrix and passing through a label in each column of the second label matrix in sequence; the second label matrix is ​​one of m label sub-matrices corresponding one-to-one to the m coding modes, the label sub-matrix contains n columns of labels, and each column of the n columns of labels contains each label of a corresponding coding mode.

[0026] Optionally, the device further comprises:

[0027] A second sample acquisition module is used to acquire m second subsequence samples of the labeled sequence sample before the path acquisition module inputs the text sequence into the sequence labeling model to obtain the target path output by the sequence labeling model, each of which is a labeled sequence obtained by encoding the text sequence sample according to one of the m encoding modes;

[0028] The second training module is used to perform training according to the text sequence samples and the m second subsequence samples to obtain the sequence labeling model.

[0029] Optionally, the m encoding modes include a BIO encoding mode and a BILOU encoding mode.

[0030] Optionally, the sequence labeling model is a latent variable conditional random field model.

[0031] On the other hand, a sequence labeling model training device is provided, characterized in that the device comprises:

[0032] A text sequence sample acquisition module is used to acquire text sequence samples;

[0033] A label sequence sample acquisition module, used to encode the text sequence samples according to m encoding modes to obtain label sequence samples, where m is an integer greater than or equal to 2;

[0034] A training module is used to perform training based on the text sequence samples and the annotation sequence samples to obtain a sequence annotation model, wherein the sequence annotation model is used to output a target path based on an input text sequence, wherein each node in the target path is a label in a preset label set, and the preset label set contains labels corresponding to the m encoding modes.

[0035] Optionally, the labeled sequence sample acquisition module is specifically used to:

[0036] Obtaining each first subsequence sample of the labeled sequence sample, wherein the first label in the first subsequence sample is any label among the m labels corresponding to the first text element; the first label is any label in the first subsequence sample, the first text element is a text element in the text sequence sample corresponding to the first label, and the m labels corresponding to the first text element are labels corresponding to the first text element when it is encoded according to the m encoding modes respectively;

[0037] Each of the first subsequence samples is obtained as a label sequence sample corresponding to the text sequence sample.

[0038] Optionally, the labeled sequence sample acquisition module is specifically used to:

[0039] Obtain m second subsequence samples of the marked sequence sample, each of the second subsequence samples being a marked sequence obtained by encoding the text sequence sample according to one of the m encoding modes;

[0040] Each of the second subsequence samples is obtained as one of the labeled sequence samples corresponding to the text sequence sample.

[0041] On the other hand, a computer device is provided, which includes a processor and a memory, wherein the memory stores at least one instruction, at least one program, a code set or an instruction set, and the at least one instruction, the at least one program, the code set or the instruction set is loaded and executed by the processor to implement the above-mentioned sequence labeling method or sequence labeling model training method in natural language processing.

[0042] On the other hand, a computer-readable storage medium is provided, wherein at least one instruction, at least one program, a code set or an instruction set is stored in the storage medium, and the at least one instruction, the at least one program, the code set or the instruction set is loaded and executed by a processor to implement the above-mentioned sequence labeling method or sequence labeling model training method in natural language processing.

[0043] The technical solution provided by this application may have the following beneficial effects:

[0044] A sequence labeling model is obtained by training the results of encoding text sequence samples according to multiple encoding modes, and the input text sequence is processed through the sequence model label to output a labeling sequence corresponding to the text sequence. Each label in the labeling sequence can be one of the labels corresponding to multiple encoding modes, so that the labeling of the text sequence is not limited to a single encoding mode. In other words, the sequence labeling model can automatically select the encoding mode for the input text sequence during the labeling process, thereby improving the universality of the sequence labeling model for different inputs and improving the effect of sequence labeling.

[0045] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS

[0046] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

[0047] Figure 1 It is a coding schematic diagram of two coding modes involved in this application;

[0048] Figure 2 is a flowchart of a sequence labeling method in natural language processing according to an exemplary embodiment;

[0049] Figure 3 yes Figure 2 A schematic diagram of the model training and labeling process involved in the illustrated embodiment;

[0050] Figure 4 is a flowchart of a sequence labeling model training method according to an exemplary embodiment;

[0051] Figure 5 is a flowchart of a sequence labeling method in natural language processing according to an exemplary embodiment;

[0052] Figure 6 yes Figure 5 A schematic diagram of a conditional random field involved in the illustrated embodiment;

[0053] Figure 7 yes Figure 5 A schematic diagram of a model training involved in the illustrated embodiment;

[0054] Figure 8 is a flowchart of a sequence labeling method in natural language processing according to an exemplary embodiment;

[0055] Fig. 9 yes Figure 8 A schematic diagram of a conditional random field involved in the illustrated embodiment;

[0056] Fig.10 is a structural block diagram of a sequence tagging apparatus in natural language processing according to an exemplary embodiment;

[0057] Fig.11 is a structural block diagram of a sequence labeling model training device according to an exemplary embodiment;

[0058] Fig.12 The present invention is a structural block diagram of a computer device according to an exemplary embodiment. DETAILED DESCRIPTION

[0059] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.

[0060] Natural language processing technology is a general term for a class of technical methods used to process speech and text data. Among them, sequence labeling is an important part of natural language processing technology, and the effect of sequence labeling will directly affect the accuracy of natural language processing. This application proposes a sequence labeling method that can effectively improve the effect of sequence labeling.

[0061] Before describing the various embodiments shown in this application, several concepts involved in this application are first introduced:

[0062] 1) Sequence labeling

[0063] In this application, sequence labeling refers to the task of assigning a preset semantic label to each text element in an input text sequence during natural language processing.

[0064] According to the specific task of natural language processing, the above text element can be a phrase or a character. For example, when the specific task of natural language processing is to segment a text sequence, each text element in the above text sequence can be a letter or a Chinese character; when the specific task of natural language processing is to extract information from a text sequence, each text element in the above text sequence can be an English word or a Chinese character phrase.

[0065] 2) Conditional Random Field

[0066] The conditional random field (CRF) algorithm was proposed by Lafferty et al. in 2001 and is a type of statistical modeling method that is often used for sequence prediction problems. The CRF algorithm provides multiple advantages over hidden Markov models and maximum entropy models for these tasks, including reducing the strong conditional independence assumptions in these models. The CRF algorithm also avoids the basic limitations of the maximum entropy Markov model based on directed graph models and other undirected Markov models (in both graph models, decoding is more biased towards hidden states with few successor states). Parameter estimation in the CRF is usually achieved through the forward-backward algorithm, while probability prediction in the CRF is often achieved through the Viterbi algorithm.

[0067] In related technologies, a large number of studies on sequence prediction are based on conditional random fields.

[0068] For example, a Chinese word segmentation system based on a conditional random field model is proposed in the related art. The model of this system uses a conditional random field model to capture language features such as character recognition, morphology, and character overlap features.

[0069] In addition, a semi-Markov conditional random field (semi-CRF) model is proposed in the related art, in which the input sequence x is segmented by the semi-Markov conditional random field output x, where labels are assigned to sequences of fragments (i.e., subsequences) of the input sequence x, rather than to individual units (i.e., characters or words) of the input sequence x. The features of the semi-Markov conditional random field can capture features on the fragments, and the features within the fragments can be non-Markov. While having this additional representation capability, the exact learning and inference algorithms of the semi-Markov conditional random field are polynomial time. Experiments have shown that semi-Markov conditional random fields are generally superior to traditional conditional random fields.

[0070] In addition, the related art proposes a hybrid model that can represent the characteristics of conditional random fields and semi-Markov conditional random fields, describes effective algorithms for training and inference, and proves that the proposed hybrid model reduces the error of Chinese word segmentation tasks by 18% and 25% compared with the standard first-order conditional random fields and semi-Markov conditional random fields. In addition, the related art also proposes a powerful feature applied to semi-Markov conditional random fields: that is, according to the generative model, the logarithmic conditional probability of a given state sequence constituting a block can effectively reduce the error by 13%.

[0071] In addition, related technologies have proposed techniques for applying semi-Markov conditional random fields to named entity recognition tasks, which have low computational costs. Among them, in order to reduce the computational cost, two techniques are proposed in related technologies: the first is to use feature forests, which enables the model to package feature-equivalent states, and the second is to introduce a filtering process, which greatly reduces the number of candidate states. This framework is able to use rich feature information extracted from fragment-based feature representations while maintaining a tolerable running time. A simple trick is also introduced in the related technology, which is to transmit information about remote entities by embedding label information into non-entity labels.

[0072] 3) Hidden variable conditional random field model

[0073] The latent variable conditional random field model uses the encoding mode as a latent variable, automatically capturing useful information from it to improve the performance of the sequence labeling model. In the study of related technologies, it was found that different encoding modes will directly affect the performance of the sequence labeling model.

[0074] For example, the encoding modes that are currently widely used include the BIO encoding mode and the BILOU encoding mode. Among them, for the BIO encoding mode, it includes three labels, namely label B, label I and label O, wherein label B represents the beginning of the segment (Begin), label I represents the interior of the segment (Intermediate), including the end, and label O represents a word that does not belong to any segment (i.e. Other). For the BILOU encoding mode, it includes five labels, namely label B', label I', label L', label O' and label U', wherein label B' represents the beginning of the segment (Begin), label I' represents the interior of the segment (Inside), excluding the end word, label L' represents the last word of the segment (Last), label O' represents that the corresponding word does not belong to any segment (Outside), and label U' represents the unit character (Unit).

[0075] For example, see Figure 1 , which shows a schematic diagram of the encoding of the two encoding modes involved in this application. Figure 1As shown in part (a), the text sequence "Michelle Jordan will choose Bush" is annotated by the BIO encoding mode. The text sequence contains five text elements: "Michelle", "Jordan", "will", "choose" and "Bush". Assuming that the current natural language processing task is an information extraction task, and the object to be extracted is a person's name (expressed in PER), the results of annotating the five text elements "Michelle", "Jordan", "will", "choose" and "Bush" according to the BIO encoding mode are B-PER, I-PER, O, O and B-PER respectively. Figure 1 As shown in part (b), taking the labeling of the text sequence "Michelle Jordan will choose Bush" using the BILOU encoding mode as an example, assuming that the current natural language processing task is an information extraction task and the object to be extracted is a person's name, the results of labeling the five text elements "Michelle", "Jordan", "will", "choose" and "Bush" according to the BILOU encoding mode are B'-PER, L'-PER, O', O' and U'-PER respectively.

[0076] In addition to the above-mentioned BIO encoding mode and BILOU encoding mode, some latent variable conditional random field models currently use other types of encoding modes, such as BIEOS encoding mode, BIEO encoding mode, SBME encoding mode, etc. Among them, in the BIEOS encoding mode, label B indicates the beginning of the segment, label I indicates the middle of the segment, label E indicates the end of the segment (End), label S indicates a single element (Single), and label O indicates an element that is not related to the tag. In the BIEO encoding mode, label B indicates the beginning of the segment, label I indicates the middle of the segment, label E indicates the end of the segment, and label O indicates an element that is not related to the tag. In the SBME encoding mode, label S indicates a single element, label B indicates the beginning of the segment, label M indicates the middle of the segment (Middle), and label E indicates the end of the segment.

[0077] Experiments show that compared with the conditional random field model without using any encoding pattern as a latent variable, the conditional random field model using the encoding pattern as a latent variable can capture more boundary word features, thus having a positive impact on the model performance.

[0078] At present, the annotation effects of different text sequences in the conditional random field models based on different encoding modes as latent variables are also different. For example, the annotation effect of the conditional random field model based on encoding mode A as latent variable on text sequence 1 is better than that of the conditional random field model based on encoding mode B as latent variable on text sequence 1, and the annotation effect of the conditional random field model based on encoding mode A as latent variable on text sequence 2 may also be worse than that of the conditional random field model based on encoding mode B as latent variable on text sequence 2. Therefore, the conditional random field model based on a single encoding mode as latent variable has poor universality and cannot achieve good annotation effects for all text sequences.

[0079] In response to the above problems, this application proposes a method of using multiple encoding modes as latent variables of a single conditional random field model to automatically select a better encoding mode for the input text sequence.

[0080] Figure 2 The flowchart of a sequence labeling method in natural language processing according to an exemplary embodiment is shown. The sequence labeling method in natural language processing can be used in a computer device with a natural language processing function. For example, the computer device can be a traditional computer device such as a fixed personal computer, a portable personal computer, a workstation, a server, or the like. Alternatively, the computer device can also be an intelligent mobile terminal such as a smart phone, a tablet computer, an e-book reader, etc. Figure 2 As shown, the sequence labeling method in natural language processing may include the following steps:

[0081] Step 21: Obtain a text sequence, where the text sequence contains n text elements, where n is an integer greater than or equal to 2.

[0082] Step 22, input the text sequence into a sequence labeling model to obtain a target path output by the sequence labeling model, the sequence labeling model is trained based on text sequence samples and labeling sequence samples, the labeling sequence samples are labeling sequences obtained by encoding the text sequence samples according to m encoding modes, m is an integer greater than or equal to 2; each node in the target path is a label in a preset label set, and the preset label set contains each label corresponding to the m encoding modes.

[0083] Step 23, arranging the nodes in the target path in order from first to last in the target path, and obtaining a label sequence corresponding to the text sequence.

[0084] The scheme shown in the embodiment of the present application can be divided into a model training process and a labeling process. In the model training process, the result of labeling a text sequence sample through multiple encoding modes is used as a labeling sequence sample for model training to obtain a sequence labeling model containing multiple encoding modes. In the labeling process, the sequence labeling model trained by the model training process labels the input text sequence to obtain a labeling sequence.

[0085] Please refer to Figure 3 , which shows a schematic diagram of the model training and labeling process involved in the embodiment of the present application. Figure 3 As shown, taking m encoding modes including encoding mode A and encoding mode B as an example, during the model training process, for a text sequence sample, the model training device encodes through two encoding modes to obtain the encoding result of the text sequence sample (S31), that is, to obtain the labeled sequence sample corresponding to the text sequence sample. The model training device performs model training according to the text sequence sample and the labeled sequence sample to obtain a sequence labeling model (S32). During the labeling process, for an input text sequence containing n elements, the sequence labeling device inputs the text sequence into the sequence labeling model (S33), and the sequence labeling model outputs a target path containing n labels (S34), and each label in the target path can be one of the labels of encoding mode A and encoding mode B.

[0086] Among them, the above-mentioned model training device and sequence labeling device can be the same computer device, that is, after the computer device obtains the sequence labeling model through training in the above-mentioned steps S31 and S32, the sequence labeling model is subsequently used to perform sequence labeling according to steps S33 and S34.

[0087] Alternatively, the model training device and the sequence labeling device may be different computer devices. That is, after a computer device A obtains a sequence labeling model through training in the above steps S31 and S32, the trained sequence labeling model is provided to another computer device B, and the computer device B uses the sequence labeling model to perform sequence labeling according to steps S33 and S34.

[0088] Among them, after the sequence labeling device obtains the labeling sequence corresponding to the input text sequence through the above-mentioned sequence labeling model, it can perform subsequent processing related to natural language processing on the text sequence according to the labeling sequence, for example, performing word segmentation, information extraction, part-of-speech tagging, named entity recognition, and word meaning role tagging on the above-mentioned text sequence according to the labeling sequence.

[0089] In an embodiment of the present application, a sequence labeling model is obtained by training the results of encoding text sequence samples according to a plurality of encoding modes, and the input text sequence is processed by means of the sequence model label, and a labeling sequence corresponding to the text sequence is output, wherein each label in the labeling sequence may be one of the labels corresponding to a plurality of encoding modes, so that the labeling of the text sequence is not limited to a single encoding mode, that is, the sequence labeling model may automatically select an encoding mode for the input text sequence during the labeling process, thereby improving the universality of the sequence labeling model to different inputs and improving the effect of sequence labeling.

[0090] Among them, the above Figure 3 In the scheme shown, the training process of the sequence labeling model can be as follows Figure 4 As shown. Among them, Figure 4 is a flowchart of a sequence labeling model training method according to an exemplary embodiment. The sequence labeling model training method can be implemented in a computer device, for example, the computer device can be a traditional computer device such as a fixed personal computer, a portable personal computer, a workstation, a server, etc. Figure 4 As shown, the sequence labeling model training method may include the following steps:

[0091] Step 41, obtaining text sequence samples.

[0092] Step 42: Encode the text sequence sample according to m encoding modes to obtain a labeled sequence sample, where m is an integer greater than or equal to 2.

[0093] Step 43: training is performed according to the text sequence sample and the annotation sequence sample to obtain a sequence annotation model.

[0094] Wherein, the above steps 41 to 43 can be performed by a model training device. After the model training device trains the above sequence labeling model, the sequence labeling model can be provided to the sequence labeling device for outputting a target path according to the input text sequence, where each node in the target path is a label in a preset label set, and the preset label set contains the labels corresponding to the m encoding modes.

[0095] In the above Figure 4 In the illustrated embodiment, there are at least m annotation sequence samples corresponding to one text sequence sample.

[0096] In the above Figure 4In a possible embodiment of the scheme shown, the model training device encodes the text sequence sample according to m encoding modes. When obtaining the labeled sequence sample, each first subsequence sample of the labeled sequence sample can be obtained, and the first label in the first subsequence sample is any label among the m labels corresponding to the first text element; the first label is any label in the first subsequence sample, the first text element is the text element corresponding to the first label in the text sequence sample, and the m labels corresponding to the first text element are the labels corresponding to the first text element when encoded according to the m encoding modes respectively; and each of the first subsequence samples is obtained as a labeled sequence sample corresponding to the text sequence sample.

[0097] That is to say, for a text sequence sample, the annotation sequence sample of the text sequence sample is m annotation sequences obtained by encoding the text sequence sample according to the above m encoding modes respectively.

[0098] For example, assuming that the above m encoding modes are three encoding modes, the annotation sequences obtained after a certain text sequence sample is encoded according to these three encoding modes are the following three sequences:

[0099] Sequence a: {a1, a2, a3, a4, a5};

[0100] Sequence b: {b1, b2, b3, b4, b5};

[0101] Sequence c: {c1, c2, c3, c4, c5}.

[0102] Then the above sequence a, sequence b and sequence c are respectively a labeled sequence sample of the text sequence sample.

[0103] In the above Figure 4 In a possible embodiment of the scheme shown, the model training device encodes the text sequence sample according to m encoding modes. When obtaining the labeled sequence sample, m second subsequence samples of the labeled sequence sample can be obtained, and each of the second subsequence samples is a labeled sequence obtained by encoding the text sequence sample according to one of the m encoding modes; each of the second subsequence samples is obtained as a labeled sequence sample corresponding to the text sequence sample.

[0104] That is to say, for a text sequence sample, the tag sequence sample of the text sequence sample can also be m tag sequences obtained by encoding the text sequence sample according to the above m encoding modes, and tag sequences obtained by hybrid expansion based on the m tag sequences. Among them, for any sequence among the above m tag sequences, the hybrid expansion can include but is not limited to replacing the label at any position in the sequence with the label corresponding to the same position in other sequences among the m tag sequences.

[0105] For example, assuming that the above m encoding modes are three encoding modes, the annotation sequences obtained after a certain text sequence sample is encoded according to these three encoding modes are the following three sequences:

[0106] Sequence a: {a1, a2, a3, a4, a5};

[0107] Sequence b: {b1, b2, b3, b4, b5};

[0108] Sequence c: {c1, c2, c3, c4, c5}.

[0109] When expanding based on sequence a, sequence b, and sequence c, any label in one sequence can be replaced with the label at the same position in the other sequence. For example, the first label a1 in sequence a can be replaced with the first label in sequence b or sequence c (i.e., b1 or c1), and the new sequence {b1 / c1, a2, a3, a4, a5} obtained after replacement is also used as a labeled sequence sample.

[0110] In the training process of the above-mentioned sequence labeling model, when the text sequence samples are encoded according to m encoding modes, if each text element in the text sequence samples is encoded according to all the labels corresponding to the m encoding modes, that is, in a labeled sequence sample, the label corresponding to each text element is any one of all the labels corresponding to the m encoding modes, then correspondingly, in the subsequent sequence labeling process, each label in the target path output by the sequence labeling model can be any one of all the labels corresponding to the m encoding modes.

[0111] Figure 5 The flowchart of a sequence labeling method in natural language processing according to an exemplary embodiment is shown. The sequence labeling method in natural language processing can be used in a computer device with a natural language processing function. For example, the computer device can be a traditional computer device such as a fixed personal computer, a portable personal computer, a workstation, a server, or the like. Alternatively, the computer device can also be an intelligent mobile terminal such as a smart phone, a tablet computer, an e-book reader, etc. Figure 5As shown, the sequence labeling method in natural language processing may include the following steps:

[0112] Step 501: Obtain each first subsequence sample of the annotation sequence sample corresponding to the text sequence sample, wherein the first label in the first subsequence sample is any label among the m labels corresponding to the first text element.

[0113] Among them, m is an integer greater than or equal to 2; the first label is any label in the first subsequence sample, the first text element is the text element corresponding to the first label in the text sequence sample, and the m labels corresponding to the first text element are the labels corresponding to the first text element when it is encoded according to the m encoding modes.

[0114] Among them, the above-mentioned m encoding modes include at least two of the BIO encoding mode, the BILOU encoding mode, the BIEOS encoding mode, the BIEO encoding mode and the SBME encoding mode.

[0115] For example, assuming that the above m encoding modes are three encoding modes, the annotation sequences obtained after a certain text sequence sample is encoded according to these three encoding modes are the following three sequences:

[0116] Sequence a: {a1, a2, a3, a4, a5};

[0117] Sequence b: {b1, b2, b3, b4, b5};

[0118] Sequence c: {c1, c2, c3, c4, c5}.

[0119] The first label in the first subsequence sample can be any one of {a1, b1, c1}, and correspondingly, the second label in the first subsequence sample can be any one of {a2, b2, c2}, and so on.

[0120] For example, take m encoding modes including BIO encoding mode and BILOU encoding mode, and take the text sequence sample "Michelle Jordan will choose Bush" as an example, where the text sequence sample contains five text elements, "Michelle", "Jordan", "will", "choose" and "Bush". Assume that the natural language processing task corresponding to the sequence annotation model to be trained is an information extraction task, and the object to be extracted is a person's name (expressed as PER). For the text element "Michelle", the label corresponding to the BIO encoding mode is B-PER, and the corresponding BILOU encoding mode is B'-PER; correspondingly, for the text element "Jordan", the label corresponding to the BIO encoding mode is I-PER, and the corresponding BILOU encoding mode is B'-PER. The BILOU coding mode should be L'-PER; for the text element "will", the label corresponding to the BIO coding mode is O, and the corresponding BILOU coding mode is O'; for the text element "select", the label corresponding to the BIO coding mode is O, and the corresponding BILOU coding mode is O'; for the text element "Bush", the label corresponding to the BIO coding mode is B-PER, and the corresponding BILOU coding mode is U'-PER; by encoding the above-mentioned text sequence samples, multiple first subsequence samples can be obtained, and for one of the first subsequence samples, each label in the first subsequence sample can be one of the labels of the text element at the corresponding position under two different coding modes. For example, the first label in a first subsequence sample (corresponding to the text element "Michelle") can be B-PER or B'-PER, and the second label in the first subsequence sample (corresponding to the text element "Jordan") can be I-PER or L'-PER. That is to say, in an embodiment of the present application, labels at different positions in a first subsequence sample can come from different coding modes.

[0121] Step 502: Perform training based on the text sequence sample and each of the first subsequence samples to obtain the sequence labeling model.

[0122] For example, please refer to Figure 6 , which shows a schematic diagram of a conditional random field involved in an embodiment of the present application. Figure 6 As shown, taking m encoding modes including BIO encoding mode and BILOU encoding mode, and labeling the text sequence sample "Michelle Jordan will choose Bush" as an example, the model training device constructs a label matrix when training according to the text sequence sample and the first subsequence samples. The label matrix contains 8 rows and 5 columns of nodes, each node corresponds to a label, and the label matrix constitutes a complete conditional random field. Figure 6In the figure, the complete conditional random field structure diagram includes two subgraphs, the upper part corresponds to the conditional random field subgraph with the BIO coding mode, which is called the BIO conditional random field subgraph (also referred to as the BIO subgraph) in this application, and the lower part is a conditional random field subgraph with the BILOU coding mode, which is called the BILOU conditional random field subgraph (also referred to as the BILOU subgraph) in this application.

[0123] During the model training and application process, the model training device / sequence labeling device can be combined with the above Figure 6 The conditional random field creation model shown. In the embodiment of the present application, the process of creating the model can be represented by the following pseudo code:

[0124] Input: maximum sentence length L, tag set N, annotated path storage set T

[0125] Create leaf nodes

[0126] for n=1to L do

[0127] foreach n k ∈N do

[0128] 1) Create Bn in the BIO subgraph k Node, In k Node and O Node

[0129] 2) Create Bn in the BILOU subgraph k Node, In k Node, Un k Node and O Node

[0130] 3) Connect the above nodes according to the node connection relationship

[0131] 4) Record the marked path into the set T

[0132] end

[0133] end

[0134] Referring to the above pseudo code, in the embodiment of the present application, for each time step t, it is necessary to traverse all possible labels n k , for each label n k Create corresponding nodes in the BIO subgraph and the BILOU subgraph respectively. Create B, I and O nodes in the BIO subgraph, and create B', I', L', O' and U' nodes in the BILOU subgraph. Then connect the nodes according to the above connection relationship, and finally record the annotation path (i.e. Figure 6The path indicated by the black arrow in the figure) completes the establishment of the structural diagram of the conditional random field. Afterwards, the above model is trained by the standard forward-backward algorithm, and in the model prediction stage, the model is decoded using the Viterbi algorithm. In the decoding step, the trained model selects a subset of black arrows through the Viterbi algorithm. In an embodiment of the present application, the restriction that the path of the maximum likelihood probability output by the model can only uniquely belong to the BIO coding mode or the BILOU coding mode is not cancelled, that is, the model can jump between the BILOU coding mode and the BIO coding mode. At this time, the path with the maximum likelihood probability can use the BIO coding mode and the BILOU coding mode at the same time, so that a suitable coding mode can be selected for each word or phrase, thereby making the conditional likelihood probability of the entire path solved by the Viterbi algorithm optimal.

[0135] In the embodiments of the present application, Figure 6 As shown, during the model training process, for a given text sequence sample "Michelle Jordan will choose Bush", according to the annotation method of step 401, the annotation sequence sample corresponding to the text sequence sample can be any path starting from the left leaf node along the order indicated by the solid arrows in the complete conditional random field to the root node. In other words, each path starting from the left leaf node along the order indicated by the solid arrows in the complete conditional random field to the root node is a first subsequence sample in the annotation sequence sample.

[0136] In this step, the model training device can use the text sequence sample and each first subsequence sample as one piece of training data for model training. That is, the training data corresponding to each first subsequence sample can be obtained through one text sequence sample, and the model training device can perform model training according to the multiple pieces of training data corresponding to this text sequence sample.

[0137] For example, please refer to Figure 7 , which shows a schematic diagram of a model training involved in an embodiment of the present application. Figure 7 As shown, the model training device obtains training data consisting of a text sequence sample and each first subsequence sample, for example, Figure 7 In the example, the text sequence sample and the first subsequence sample 1 form one set of training data, the text sequence sample and the first subsequence sample 2 form another set of training data, and so on. The model training device performs model training according to each set of training data, for example, inputs each set of training data into the model for training in turn, and obtains a sequence labeling model used for subsequent sequence labeling.

[0138] Step 503: Obtain a text sequence, where the text sequence contains n text elements, where n is an integer greater than or equal to 2.

[0139] The text sequence may be a text sequence that needs to be sequence labeled during natural language processing.

[0140] Step 504: input the text sequence into a sequence labeling model to obtain a probability value of each candidate label path output by the sequence labeling model, wherein the probability value indicates the probability that the actual label path of the text sequence is the corresponding candidate label path.

[0141] Among them, any path among the alternative label paths starts from a label in the first column of the first label matrix and passes through a label in each column of the first label matrix in sequence; the first label matrix contains n columns of labels, and each column of the n columns of labels contains each label corresponding to the m encoding modes.

[0142] For example, the first label matrix is Figure 6 As an example, the complete conditional random field shown in Figure 6 As shown, in the BIO conditional random field, there are B nodes, I nodes, and O nodes. These nodes can be connected to the nodes in the bottom BILOU conditional random field. For a given B node, it can be connected to the B nodes, I nodes, and O nodes in the BIO conditional random field, and the B' nodes, I' nodes, L' nodes, O' nodes, and U' nodes in the BILOOU conditional random field. For a given I node, it can be connected to the B nodes, I nodes, and O nodes in the BIO conditional random field, and the B' nodes, I' nodes, L' nodes, O' nodes, and U' nodes in the BILOU conditional random field. For a given O node, it can be connected to the B nodes and O nodes in the BIO conditional random field, and the B' nodes, O' nodes, and U' nodes in the BILOU conditional random field. And in the BILOU conditional random field, there are B' nodes, I' nodes, L' nodes, O' nodes, and U' nodes. For a given B' node, it can be connected to the I node in the BIO conditional random field, and the I' node and L' nodes in the BILOU conditional random field. For a given I' node, it can be connected to the I node in the BIO conditional random field, the I' node and the L' node in the BILOU conditional random field. For a given L' node, it can be connected to the B node and the O node in the BIO conditional random field, and the U' node, the B' node, and the O' node in the BILOU conditional random field. For a given O' node, it can be connected to the B node and the O node in the BIO conditional random field, and the B' node, the U' node, and the O' node in the BILOU conditional random field. For a given U' node, it can be connected to the B node and the O node in the BIO conditional random field, and the B' node, the U' node, and the O' node in the BILOU conditional random field. According to the above connection method, Figure 6In the complete random field shown, there are several possible paths from the leaf node to the root node, and these several possible paths are the above-mentioned candidate label paths. In the sequence labeling process, for the input text sequence, the sequence labeling model will output the probability value corresponding to each possible candidate label path.

[0143] Step 505: The path with the largest probability value among the candidate label paths is obtained as the target path.

[0144] For example, in the sequence labeling process, assuming that the input text sequence is "Wang Xiaoming will choose Xiaohong", the corresponding text elements are "Wang", "Xiaoming", "will", "select", "Xiaohong", and if the sequence labeling model is trained accurately enough, the probability value corresponding to each possible candidate label path outputted should be the one along Figure 6 The solid arrow shown indicates one of the paths.

[0145] Step 506: Arrange the nodes in the target path in order from first to last in the target path to obtain a label sequence corresponding to the text sequence.

[0146] Or Figure 6 In the complete conditional random field shown, the input text sequence is "Wang Xiaoming will choose Xiaohong" as an example. The target path that the sequence annotation model may output is the path with the highest probability value among the paths obtained by encoding in multiple encoding modes. That is to say, for a given input sentence, the sequence annotation model can output a label path, which is a mixture of labels of multiple encoding modes. This allows each text element in the input text sequence to be labeled with a different encoding mode. For example, "Michelle" can be labeled with the B node in the BIO encoding mode, and "Jordan" can be labeled with the l' node LAI in the BILOU encoding mode. In other words, the model shown in the embodiment of the present application selects the best encoding mode for each text element in the input text sequence.

[0147] To summarize, in an embodiment of the present application, a sequence labeling model is obtained by training the results of mixed encoding of text sequence samples according to a plurality of encoding modes, and the input text sequence is processed by the sequence model label, and a labeling sequence corresponding to the text sequence is output, wherein each label in the labeling sequence may be one of the labels corresponding to a plurality of encoding modes, so that the labeling of the text sequence is not limited to a single encoding mode, that is, the sequence labeling model can automatically select an encoding mode for the input text sequence during the labeling process, thereby improving the universality of the sequence labeling model for different inputs and improving the effect of sequence labeling.

[0148] In another possible implementation, during the training process of the above-mentioned sequence labeling model, when encoding the text sequence samples according to m encoding modes, if each text element in the text sequence sample is separately encoded according to the labels corresponding to the m encoding modes, that is, in a labeled sequence sample, the label corresponding to each text element is any one of the labels corresponding to one encoding mode, then accordingly, in the subsequent sequence labeling process, each label in the target path output by the sequence labeling model can be any one of all the labels corresponding to the same encoding mode.

[0149] Figure 8 The flowchart of a sequence labeling method in natural language processing according to an exemplary embodiment is shown. The sequence labeling method in natural language processing can be used in a computer device with a natural language processing function. For example, the computer device can be a traditional computer device such as a fixed personal computer, a portable personal computer, a workstation, a server, or the like. Alternatively, the computer device can also be an intelligent mobile terminal such as a smart phone, a tablet computer, an e-book reader, etc. Figure 8 As shown, the sequence labeling method in natural language processing may include the following steps:

[0150] Step 801: obtain m second subsequence samples of the marked sequence sample, each second subsequence sample is a marked sequence obtained by encoding the text sequence sample according to one of the m encoding modes.

[0151] Here, m is an integer greater than or equal to 2.

[0152] For example, take m encoding modes including BIO encoding mode and BILOU encoding mode, and take the text sequence sample "Michelle Jordan will choose Bush" for annotation as an example, wherein the text sequence sample contains five text elements "Michelle", "Jordan", "will", "select" and "Bush". Assuming that the natural language processing task corresponding to the sequence annotation model to be trained is an information extraction task, and the object to be extracted is a person's name (expressed as PER), by encoding the above text sequence sample, two second subsequence samples can be obtained, wherein the second subsequence sample corresponding to the BIO encoding mode is {B-PER, I-PER, O, O and B-PER}, and the second subsequence sample corresponding to the BILOU encoding mode is {B'-PER, L'-PER, O', O' and U'-PER}. That is to say, in an embodiment of the present application, the labels at different positions in a second subsequence sample come from the same encoding mode.

[0153] Step 802: Perform training based on the text sequence sample and the m second subsequence samples to obtain the sequence labeling model.

[0154] For example, please refer to Fig. 9 , which shows a schematic diagram of a conditional random field involved in an embodiment of the present application. Fig. 9 As shown, taking m encoding modes including BIO encoding mode and BILOU encoding mode, and labeling the text sequence sample "Michelle Jordan will choose Bush" as an example, the model training device constructs a label matrix when training according to the text sequence sample and the first subsequence samples. The label matrix contains 8 rows and 5 columns of nodes, each node corresponds to a label, and the label matrix constitutes a complete conditional random field. Fig. 9 In the figure, the complete conditional random field structure diagram includes two subgraphs, the upper part corresponds to the conditional random field subgraph with the BIO coding mode, which is called the BIO conditional random field subgraph (also referred to as the BIO subgraph) in this application, and the lower part is a conditional random field subgraph with the BILOU coding mode, which is called the BILOU conditional random field subgraph (also referred to as the BILOU subgraph) in this application.

[0155] refer to Figure 5 In the pseudo code of the embodiment shown in the figure, in the embodiment of the present application, for each time step t, it is necessary to traverse all possible labels n k , for each label n k Create corresponding nodes in the BIO subgraph and the BILOU subgraph respectively. Create B, I and O nodes in the BIO subgraph, and create B', I', L', O' and U' nodes in the BILOU subgraph. Then connect the nodes according to the above connection relationship and record the annotation path (i.e. Fig. 9 The path indicated by the black arrow in the figure completes the establishment of the structural diagram of the conditional random field. After that, the above model is trained by the standard forward-backward algorithm, and in the model prediction stage, the model is decoded using the Viterbi algorithm. Under the Viterbi algorithm, the model can only output the path with the maximum likelihood probability as the only output. At this time, the path either belongs to the BIO coding mode or the BILOU coding mode. That is, under the Viterbi algorithm, the model can automatically select a suitable coding mode as the output for the input sentence. This coding mode is the path with the maximum likelihood probability among all paths, that is, the best coding mode.

[0156] In the embodiments of the present application, Fig. 9As shown, during the model training process, for a given text sequence sample "Michelle Jordan will choose Bush", according to the annotation method of step 801, the annotation sequence sample corresponding to the text sequence sample can be any path starting from the left leaf node along the order indicated by the solid arrows in the BIO conditional random field or the BILOU conditional random field to the root node. In other words, each path starting from the left leaf node along the order indicated by the solid arrows in the BIO conditional random field or the BILOU conditional random field to the root node is a second subsequence sample in the annotation sequence sample.

[0157] Step 803: Obtain a text sequence, where the text sequence includes n text elements, where n is an integer greater than or equal to 2.

[0158] Step 804: input the text sequence into a sequence labeling model to obtain a probability value of each candidate label path output by the sequence labeling model, wherein the probability value indicates the probability that the actual label path of the text sequence is the corresponding candidate label path.

[0159] Among them, any path among the various alternative label paths starts from a label in the first column of the second label matrix and passes through a label in each column of the second label matrix in sequence; the second label matrix is ​​one of m label sub-matrices corresponding one-to-one to the m coding modes, the label sub-matrix contains n columns of labels, and each column of the n columns of labels contains each label of a corresponding coding mode.

[0160] For example, the second label matrix is Fig. 9 As an example, the complete conditional random field shown in Fig. 9As shown, the matrix composed of the upper BIO conditional random field is the label sub-matrix corresponding to the BIO coding mode, and the label sub-matrix has B nodes, I nodes and O nodes. B nodes can be connected to I nodes, O nodes and B nodes. I nodes can be connected to I nodes, O nodes and B nodes. O nodes can be connected to B nodes and O nodes, but cannot be connected to an I node because the start of a segment must be marked as a B node. The matrix composed of the BILOU conditional random field in the lower part is the label sub-sequence corresponding to the BILOU coding mode, and the label sub-sequence has B' nodes, I' nodes, L' nodes, O' nodes, and U' nodes. For a given B' node, it indicates the beginning of the segment. For a given I' node, it indicates the inside of the segment. For a given L' node, it indicates the end of the segment. For a given U' node, it indicates a segment with unit length. The O' node represents a node that does not belong to any label. The connection relationships are as follows: The B' node can be connected to the I' node and the L' node, but cannot be connected to the B' node, the O' node, and the U' node, because the segment with unit length should be marked as U'. The I' node can only be connected to the I' node and the L' node, and since it represents the inside of the segment, it cannot be connected to the B' node, the U' node, and the O' node that represent the start of a new segment. The L' node can be connected to the B' node, the U' node, and the O' node, but cannot be connected to the L' node and the I' node, because it represents the end of the segment. The U' node can be connected to the B' node, the O' node, and the U' node, but cannot be connected to the I' node and the L' node, because there should be a B' node that represents the start of a segment before them. The O' node can be connected to the B' node and the O' node as well as the U' node, but cannot be connected to the I' node and the L' node, because there should be a B' node before them.

[0161] According to the above connection method, Fig. 9 In the complete random field shown, there are several possible paths from the leaf node to the root node between the BIO encoding mode random field or the BILOU encoding mode random field, and these several possible paths are the above-mentioned candidate label paths. In the sequence labeling process, for the input text sequence, the sequence labeling model will output the probability value corresponding to each possible candidate label path.

[0162] Step 805: The path with the largest probability value among the candidate label paths is obtained as the target path.

[0163] For example, in the sequence labeling process, assuming that the input text sequence is "Wang Xiaoming will choose Xiaohong", the corresponding text elements are "Wang", "Xiaoming", "will", "select", "Xiaohong", and if the sequence labeling model is trained accurately enough, the probability value corresponding to each possible candidate label path outputted should be the one along Fig. 9The two solid arrows shown indicate one of the paths.

[0164] Step 806: Arrange the nodes in the target path in order from first to last in the target path to obtain a labeling sequence corresponding to the text sequence.

[0165] Or Fig. 9 Taking the complete conditional random field shown in the figure as an input text sequence of "Wang Xiaoming will choose Xiaohong" as an example, the target path that the sequence annotation model may output is the path with the highest probability value among the paths obtained by encoding in multiple encoding modes. That is to say, for a given input sentence, the sequence annotation model can output a label path, which is one of the paths corresponding to multiple encoding modes. This allows the input text sequence to be labeled with one of multiple encoding modes. In other words, the model shown in the embodiment of the present application selects the best encoding mode for the entire input text sequence.

[0166] To summarize, in an embodiment of the present application, a sequence labeling model is obtained by training the encoding results of text sequence samples according to a plurality of encoding modes, and the input text sequence is processed by the sequence model label, and a labeling sequence corresponding to the text sequence is output, wherein each label in the labeling sequence may be one of the labels corresponding to one of the plurality of encoding modes, so that the labeling of the text sequence is not limited to a single encoding mode, that is, the sequence labeling model can automatically select an encoding mode for the input text sequence during the labeling process, thereby improving the universality of the sequence labeling model for different inputs and improving the effect of sequence labeling.

[0167] Through the scheme shown in this application, the sequence labeling device can Figure 5 The sequence labeling model in the embodiment shown performs sequence labeling on the input text sequence, or the sequence labeling device can also perform sequence labeling on the input text sequence. Figure 8 The sequence labeling model in the illustrated embodiment performs sequence labeling on an input text sequence.

[0168] Optionally, the sequence labeling device can also be set Figure 5 The sequence labeling model in the illustrated embodiment and Figure 8 In the sequence labeling model in the illustrated embodiment, when performing sequence labeling on a text sequence, the sequence labeling device can independently determine which sequence labeling model to use to label the text sequence.

[0169] For example, the sequence annotation device may obtain the demand characteristics of the text sequence to be annotated, and the demand characteristics may include the amount of data of the text sequence and at least one of the business requirements corresponding to the text sequence (wherein the business requirements may include high efficiency or high accuracy). The sequence annotation device selects a sequence annotation model corresponding to the demand characteristics according to the demand characteristics of the text sequence, and then, according to the selected sequence annotation model, performs the following steps: Figure 5 or Figure 8 The marking method in the illustrated embodiment marks the text sequence.

[0170] For example, suppose Figure 5 The sequence labeling model in the illustrated embodiment is model A. Figure 8 The sequence annotation model in the illustrated embodiment is model B. The annotation accuracy of model A is higher than that of model B, but the structure of model A is more complex than that of model B, and the speed of outputting the annotation results is slower, that is, the annotation efficiency of model B is lower than that of model A. When the sequence annotation device annotates the text sequence, it can first obtain the required features of the text sequence, and select model A or model B for annotation according to the required features.

[0171] For example, when the demand feature contains a small amount of data of the text sequence, and the data amount is small (for example, less than a preset data amount threshold), the sequence labeling device selects model A to label the text sequence to obtain more accurate labeling accuracy; conversely, when the demand feature contains a large amount of data of the text sequence, and the data amount is large (for example, not less than a preset data amount threshold), the sequence labeling device selects model B to label the text sequence to obtain a faster labeling speed.

[0172] Alternatively, when the demand characteristics include a business requirement for a text sequence, and the business requirement is high accuracy, the sequence labeling device selects model A to label the text sequence to obtain a more accurate labeling accuracy; conversely, when the demand characteristics include a business requirement for a text sequence, and the business requirement is high efficiency, the sequence labeling device selects model B to label the text sequence to obtain a faster labeling speed.

[0173] Fig.10 The present invention is a block diagram of a sequence tagging device in natural language processing according to an exemplary embodiment. The sequence tagging device in natural language processing is used in a computer device with a natural language processing function. For example, the computer device can be a traditional computer device such as a fixed personal computer, a portable personal computer, a workstation, a server, or the like. Alternatively, the computer device can also be a smart mobile terminal such as a smart phone, a tablet computer, an e-book reader, etc., to perform Figure 2 , Figure 5 or Figure 8All or part of the steps in the method provided in the illustrated embodiment. The sequence tagging device in natural language processing may include:

[0174] A text sequence acquisition module 1001 is used to acquire a text sequence, wherein the text sequence includes n text elements, where n is an integer greater than or equal to 2;

[0175] The path acquisition module 1002 is used to input the text sequence into a sequence labeling model to obtain a target path output by the sequence labeling model, wherein the sequence labeling model is obtained by training based on text sequence samples and labeling sequence samples, wherein the labeling sequence samples are labeling sequences obtained by encoding the text sequence samples according to m encoding modes, where m is an integer greater than or equal to 2; each node in the target path is a label in a preset label set, and the preset label set contains labels corresponding to the m encoding modes;

[0176] The annotation sequence obtaining module 1003 is used to arrange the nodes in the target path in order from the first to the last in the target path, so as to obtain the annotation sequence corresponding to the text sequence.

[0177] Optionally, the path obtaining module 1002 is specifically configured to:

[0178] Inputting the text sequence into a sequence labeling model to obtain a probability value of each candidate label path output by the sequence labeling model, wherein the probability value indicates the probability that the actual label path of the text sequence is the corresponding candidate label path;

[0179] The path with the largest probability value among the candidate label paths is obtained as the target path.

[0180] Optionally, any one of the alternative label paths starts from a label in the first column of the first label matrix and passes through a label in each column of the first label matrix in sequence; the first label matrix contains n columns of labels, and each column of the n columns of labels contains each label corresponding to the m encoding modes.

[0181] Optionally, the device further comprises:

[0182] A first sample acquisition module is used to acquire each first subsequence sample of the labeled sequence sample before the path acquisition module inputs the text sequence into the sequence labeling model to obtain the target path output by the sequence labeling model, wherein the first label in the first subsequence sample is any label among the m labels corresponding to the first text element; the first label is any label in the first subsequence sample, the first text element is the text element in the text sequence sample corresponding to the first label, and the m labels corresponding to the first text element are labels corresponding to the first text element when it is encoded according to the m encoding modes respectively;

[0183] The first training module is used to perform training according to the text sequence samples and the first subsequence samples to obtain the sequence labeling model.

[0184] Optionally, any one of the alternative label paths is a path starting from a label in the first column of the second label matrix and passing through a label in each column of the second label matrix in sequence; the second label matrix is ​​one of m label sub-matrices corresponding one-to-one to the m coding modes, the label sub-matrix contains n columns of labels, and each column of the n columns of labels contains each label of a corresponding coding mode.

[0185] Optionally, the device further comprises:

[0186] A second sample acquisition module is used to acquire m second subsequence samples of the labeled sequence sample before the path acquisition module inputs the text sequence into the sequence labeling model to obtain the target path output by the sequence labeling model, each of which is a labeled sequence obtained by encoding the text sequence sample according to one of the m encoding modes;

[0187] The second training module is used to perform training according to the text sequence samples and the m second subsequence samples to obtain the sequence labeling model.

[0188] Optionally, the m encoding modes include a BIO encoding mode and a BILOU encoding mode.

[0189] Optionally, the sequence labeling model is a latent variable conditional random field model.

[0190] Fig.11 is a structural block diagram of a sequence labeling model training device according to an exemplary embodiment. The sequence labeling model training device is used in a computer device, for example, the computer device can be a traditional computer device such as a fixed personal computer, a portable personal computer, a workstation, a server, etc., to perform Figure 3 , Figure 5 or Figure 8 In the method provided in the illustrated embodiment, all or part of the steps are performed by a model training device. The sequence labeling model training device may include:

[0191] A text sequence sample acquisition module 1101 is used to acquire text sequence samples;

[0192] The label sequence sample acquisition module 1102 is used to encode the text sequence samples according to m encoding modes to obtain label sequence samples, where m is an integer greater than or equal to 2;

[0193] The training module 1103 is used to perform training based on the text sequence samples and the annotation sequence samples to obtain a sequence annotation model, wherein the sequence annotation model is used to output a target path based on the input text sequence, wherein each node in the target path is a label in a preset label set, and the preset label set contains the labels corresponding to the m encoding modes.

[0194] Optionally, the labeled sequence sample acquisition module 1102 is specifically configured to:

[0195] Obtaining each first subsequence sample of the labeled sequence sample, wherein the first label in the first subsequence sample is any label among the m labels corresponding to the first text element; the first label is any label in the first subsequence sample, the first text element is a text element in the text sequence sample corresponding to the first label, and the m labels corresponding to the first text element are labels corresponding to the first text element when it is encoded according to the m encoding modes respectively;

[0196] Each of the first subsequence samples is obtained as a label sequence sample corresponding to the text sequence sample.

[0197] Optionally, the labeled sequence sample acquisition module 1102 is specifically configured to:

[0198] Obtain m second subsequence samples of the marked sequence sample, each of the second subsequence samples being a marked sequence obtained by encoding the text sequence sample according to one of the m encoding modes;

[0199] Each of the second subsequence samples is obtained as one of the labeled sequence samples corresponding to the text sequence sample.

[0200] Fig.121 is a schematic diagram of a computer device according to an exemplary embodiment. The computer device 1200 includes a central processing unit (CPU) 1201, a system memory 1204 including a random access memory (RAM) 1202 and a read-only memory (ROM) 1203, and a system bus 1205 connecting the system memory 1204 and the central processing unit 1201. The computer device 1200 also includes a basic input / output system (I / O system) 1206 that helps transmit information between various components in the computer, and a large-capacity storage device 1207 for storing an operating system 1213, application programs 1214, and other program modules 1215.

[0201] The basic input / output system 1206 includes a display 1208 for displaying information and an input device 1209 such as a mouse and a keyboard for user inputting information. The display 1208 and the input device 1209 are connected to the central processing unit 1201 through an input / output controller 1210 connected to the system bus 1205. The basic input / output system 1206 may also include an input / output controller 1210 for receiving and processing inputs from a plurality of other devices such as a keyboard, a mouse, or an electronic stylus. Similarly, the input / output controller 1210 also provides output to a display screen, a printer, or other types of output devices.

[0202] The mass storage device 1207 is connected to the central processing unit 1201 through a mass storage controller (not shown) connected to the system bus 1205. The mass storage device 1207 and its associated computer readable media provide non-volatile storage for the computer device 1200. That is, the mass storage device 1207 may include a computer readable medium (not shown) such as a hard disk or a CD-ROM drive.

[0203] Without loss of generality, the computer-readable medium may include computer storage media and communication media. Computer storage media include volatile and non-volatile, removable and non-removable media implemented by any method or technology for storing information such as computer-readable instructions, data structures, program modules or other data. Computer storage media include RAM, ROM, EPROM, EEPROM, flash memory or other solid-state storage technologies, CD-ROM, DVD or other optical storage, cassettes, magnetic tapes, disk storage or other magnetic storage devices. Of course, those skilled in the art will appreciate that the computer storage media is not limited to the above. The above-mentioned system memory 1204 and mass storage device 1207 can be collectively referred to as memory.

[0204] The computer device 1200 can be connected to the Internet or other network devices through a network interface unit 1211 connected to the system bus 1205 .

[0205] The memory also includes one or more programs, which are stored in the memory. The CPU 1201 implements the Figure 2 , 3 , 5 or Figure 8 All or part of the steps of the method shown.

[0206] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory including a computer program (instructions), and the above program (instructions) can be executed by a processor of a computer device to complete the method shown in each embodiment of the present application, and the method performed by the computer device. For example, the non-transitory computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, and an optical data storage device, etc.

[0207] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the invention disclosed herein. The present application is intended to cover any modification, use or adaptation of the present application, which follows the general principles of the present application and includes common knowledge or customary techniques in the art that are not disclosed in the present application. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present application are indicated by the following claims.

[0208] It should be understood that the present application is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.

Claims

1. A sequence tagging method in natural language processing, characterized in that: The method comprises: Obtain a text sequence, wherein the text sequence includes n text elements, where n is an integer greater than or equal to 2; The text sequence is input into a sequence labeling model to obtain the probability value of each candidate label path output by the sequence labeling model, wherein the probability value indicates the probability that the actual label path of the text sequence is the corresponding candidate label path; the path with the largest probability value among the candidate label paths is obtained as the target path; the sequence labeling model is obtained by training based on text sequence samples and labeling sequence samples, the sequence labeling model is a single latent variable conditional random field model with multiple encoding modes as latent variables, the labeling sequence sample is a labeling sequence obtained by encoding the text sequence sample according to m encoding modes, and m is an integer greater than or equal to 2; each node in the target path is a label in a preset label set, and the preset label set contains each label corresponding to the m encoding modes; any path in each candidate label path is a path starting from a label in the first column of the first label matrix and passing through a label in each column of the first label matrix in sequence; the first label matrix contains n columns of labels, and each column of the n columns of labels contains each label corresponding to the m encoding modes; Arrange the nodes in the target path in order from first to last in the target path to obtain a label sequence corresponding to the text sequence.

2. The method according to claim 1, characterized in that Before inputting the text sequence into a sequence labeling model and obtaining a target path output by the sequence labeling model, the method further includes: Obtaining each first subsequence sample of the labeled sequence sample, wherein the first label in the first subsequence sample is any label among the m labels corresponding to the first text element; the first label is any label in the first subsequence sample, the first text element is a text element in the text sequence sample corresponding to the first label, and the m labels corresponding to the first text element are labels corresponding to the first text element when it is encoded according to the m encoding modes respectively; The sequence labeling model is obtained by training according to the text sequence samples and the first subsequence samples.

3. The method according to claim 1 or 2, characterized in that: The m encoding modes include at least two of a BIO encoding mode, a BILOU encoding mode, a BIEOS encoding mode, a BIEO encoding mode and a SBME encoding mode.

4. A sequence labeling model training method, characterized in that: The method comprises: Get text sequence samples; Encode the text sequence samples according to m encoding modes to obtain a label sequence sample, where m is an integer greater than or equal to 2; Training is performed according to the text sequence samples and the annotation sequence samples to obtain a sequence annotation model, wherein the sequence annotation model is a single latent variable conditional random field model with multiple encoding modes as latent variables, and the sequence annotation model is used to output probability values ​​of various candidate label paths according to the input text sequence, so as to obtain the path with the largest probability value among the various candidate label paths as the target path, and arrange the various nodes in the target path in the order from first to last in the target path to obtain the annotation sequence corresponding to the text sequence; the probability value represents the probability that the actual label path of the text sequence is the corresponding candidate label path; each node in the target path is a label in a preset label set, and the preset label set contains various labels corresponding to the m encoding modes; any path in the various candidate label paths is a path starting from a label in the first column of the first label matrix and passing through a label in each column of the first label matrix in sequence; the first label matrix contains n columns of labels, and each column of the n columns of labels contains various labels corresponding to the m encoding modes.

5. The method according to claim 4, characterized in that The step of encoding the text sequence samples according to m encoding modes to obtain the labeled sequence samples includes: Obtaining each first subsequence sample of the labeled sequence sample, wherein the first label in the first subsequence sample is any label among the m labels corresponding to the first text element; the first label is any label in the first subsequence sample, the first text element is a text element in the text sequence sample corresponding to the first label, and the m labels corresponding to the first text element are labels corresponding to the first text element when it is encoded according to the m encoding modes respectively; Each of the first subsequence samples is obtained as a label sequence sample corresponding to the text sequence sample.

6. A sequence tagging device in natural language processing, characterized in that: The device comprises: A text sequence acquisition module, used to acquire a text sequence, wherein the text sequence includes n text elements, where n is an integer greater than or equal to 2; A path acquisition module is used to input the text sequence into a sequence annotation model, obtain the probability value of each candidate label path output by the sequence annotation model, and the probability value indicates the probability that the actual label path of the text sequence is the corresponding candidate label path; the path with the largest probability value among the candidate label paths is obtained as the target path; the sequence annotation model is obtained by training based on text sequence samples and annotation sequence samples, the sequence annotation model is a single latent variable conditional random field model with multiple encoding modes as latent variables, the annotation sequence sample is a annotation sequence obtained by encoding the text sequence sample according to m encoding modes, and m is an integer greater than or equal to 2; each node in the target path is a label in a preset label set, and the preset label set contains each label corresponding to the m encoding modes; any path in each candidate label path is a path starting from a label in the first column of the first label matrix and passing through a label in each column of the first label matrix in sequence; the first label matrix contains n columns of labels, and each column of the n columns of labels contains each label corresponding to the m encoding modes; The annotation sequence obtaining module is used to arrange the nodes in the target path in order from first to last in the target path to obtain the annotation sequence corresponding to the text sequence.

7. A sequence labeling model training device, characterized in that: The device comprises: A text sequence sample acquisition module is used to acquire text sequence samples; A label sequence sample acquisition module, used to encode the text sequence samples according to m encoding modes to obtain label sequence samples, where m is an integer greater than or equal to 2; A training module is used to perform training according to the text sequence samples and the annotation sequence samples to obtain a sequence annotation model, wherein the sequence annotation model is a single latent variable conditional random field model with multiple encoding modes as latent variables, and the sequence annotation model is used to output probability values ​​of various candidate label paths according to the input text sequence, so as to obtain the path with the largest probability value among the various candidate label paths as the target path, and arrange the various nodes in the target path in the order from first to last in the target path to obtain the annotation sequence corresponding to the text sequence; the probability value represents the probability that the actual label path of the text sequence is the corresponding candidate label path; each node in the target path is a label in a preset label set, and the preset label set contains various labels corresponding to the m encoding modes; any path in the various candidate label paths is a path starting from a label in the first column of a first label matrix and passing through a label in each column of the first label matrix in sequence; the first label matrix contains n columns of labels, and each column of the n columns of labels contains various labels corresponding to the m encoding modes.

8. A computer device, characterized in that: The computer device includes a processor and a memory, wherein the memory stores at least one instruction, at least one program, a code set or an instruction set, and the at least one instruction, the at least one program, the code set or the instruction set is loaded and executed by the processor to implement the sequence labeling method in natural language processing as described in any one of claims 1 to 3; or, to implement the sequence labeling model training method as described in claim 4 or 5.

9. A computer-readable storage medium, characterized in that: The storage medium stores at least one instruction, at least one program, a code set or an instruction set, and the at least one instruction, the at least one program, the code set or the instruction set is loaded and executed by the processor to implement the sequence labeling method in natural language processing as described in any one of claims 1 to 3; or, to implement the sequence labeling model training method as described in claim 4 or 5.