Named entity recognition method, device, storage medium and terminal device

By optimizing the encoder through comparative learning and combining it with active learning, it solves the high-cost problem caused by insufficient training data for named entity recognition in the existing technology, achieves efficient named entity recognition, and reduces the dependence on manual annotation.

CN113901823BActive Publication Date: 2024-10-29PING AN TECH (SHENZHEN) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111233302.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-10-22
Publication Date
2024-10-29
Estimated Expiration
2041-10-22

AI Technical Summary

Technical Problem

Existing named entity recognition methods consume a lot of money when there is insufficient training data, and require a large amount of manual annotation of data to improve recognition accuracy, resulting in high costs of time and money.

Method used

The preset twin network is used for pre-training, the encoder is optimized using contrastive learning methods, and active learning is combined with active learning to continuously iteratively train the model through a small amount of manually labeled data to reduce reliance on manual labeling.

Benefits of technology

It effectively reduces the time and money costs, improves the efficiency of named entity recognition, and only requires a small amount of manual annotation to achieve high recognition accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113901823B_ABST
    Figure CN113901823B_ABST
Patent Text Reader

Abstract

The present invention belongs to the field of artificial intelligence technology, and in particular, relates to a method, device, computer-readable storage medium and terminal device for named entity recognition. The method comprises: pre-training an encoder in a twin network, using it as an encoder of a named entity recognition model, and training the model using annotated text data to obtain an annotated trained model; using the annotated trained model to predict unannotated text data to obtain first and second category text data; obtaining manually annotated second category text data, and using the first category text data annotated by the model and the manually annotated second category text data as newly annotated text data; adjusting the annotated trained model using the newly annotated text data to obtain an adjusted model; obtaining target text data to be identified, and using the adjusted model to process the target text data to obtain the entity category of each named entity in the target text data.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of artificial intelligence technology, and in particular relates to a named entity recognition method, device, computer-readable storage medium and terminal device. Background Art

[0002] Named Entity Recognition (NER), also known as entity recognition, entity chunking or entity extraction, is a subtask of information extraction that aims to locate and classify named entities in unstructured text into predefined categories, such as names, organizations, locations, medical codes, time expressions, quantities, monetary values, percentages, etc. The existing methods usually use the IOB tagging scheme to convert it into a sequence tagging problem, among which the bidirectional long short-term memory network combined with the conditional random field is a typical model. The great success of these methods is due to a large amount of correctly manually annotated data. However, in the actual scenario of named entity recognition, even if only a few thousand or tens of thousands of training data are manually annotated, the time and money consumed are huge. In order to obtain a higher recognition accuracy, more annotated data is required, which will also cause greater cost consumption. Summary of the invention

[0003] In view of this, embodiments of the present invention provide a method, apparatus, computer-readable storage medium, and terminal device for named entity recognition to solve the problem of high cost consumption of existing named entity recognition methods.

[0004] A first aspect of an embodiment of the present invention provides a method for named entity recognition, which may include:

[0005] Use text data in a preset text data set to pre-train an encoder in a preset twin network to obtain a pre-trained encoder;

[0006] Using the pre-trained encoder as an encoder of a preset named entity recognition model, and using the annotated text data in the text data set to train the named entity recognition model to obtain a named entity recognition model after annotated training;

[0007] Use the named entity recognition model trained by the annotation to predict the unlabeled text data in the text data set to obtain the first category of text data labeled by the model and the second category of text data to be manually labeled;

[0008] Acquire the manually annotated second-category text data, and use the model-annotated first-category text data and the manually annotated second-category text data as newly annotated text data;

[0009] Using the newly added annotated text data to adjust the annotated trained named entity recognition model to obtain an adjusted named entity recognition model;

[0010] The target text data to be recognized is acquired, and the target text data is processed using the adjusted named entity recognition model to obtain the entity category of each named entity in the target text data.

[0011] In a specific implementation of the first aspect, the pre-training of an encoder in a preset twin network using text data in a preset text data set to obtain a pre-trained encoder may include:

[0012] Performing data enhancement on the text data in the text data set to obtain a preset number of enhanced text data pairs; wherein any one of the enhanced text data pairs includes two different enhanced text data obtained by performing data enhancement on the same text data;

[0013] Using the twin network to process the enhanced text data pair, respectively obtaining a first feature vector and a second feature vector;

[0014] Calculate a first loss function according to the first eigenvector and the second eigenvector;

[0015] The encoder in the twin network is pre-trained with the goal of minimizing the first loss function to obtain a pre-trained encoder.

[0016] In a specific implementation of the first aspect, calculating the first loss function according to the first feature vector and the second feature vector may include:

[0017] The first loss function is calculated according to the following formula:

[0018]

[0019] Wherein, p1 is the first eigenvector, z2 is the second eigenvector, ||p1||2 is the modulus of the first eigenvector, ||z2||2 is the modulus of the second eigenvector, is the first loss function.

[0020] In a specific implementation of the first aspect, the training of the named entity recognition model using the annotated text data in the text dataset to obtain the annotated and trained named entity recognition model may include:

[0021] Encode the annotated text data in the text data set using the encoder of the named entity recognition model to obtain an encoded feature vector;

[0022] Processing the encoded feature vector using a multilayer perceptron of the named entity recognition model to obtain a probability distribution of entity categories;

[0023] Calculate a second loss function according to the probability distribution;

[0024] The named entity recognition model is trained with the goal of minimizing the second loss function to obtain a labeled trained named entity recognition model.

[0025] In a specific implementation of the first aspect, the processing of the encoded feature vector using the multilayer perceptron of the named entity recognition model to obtain a probability distribution of entity categories may include:

[0026] The probability distribution of entity categories is calculated according to the following formula:

[0027] p i =Softmax(U tanh(Vh i ))

[0028] Where i is the serial number of the annotated text data in the text dataset, h i is the encoded feature vector corresponding to the i-th annotated text data in the text data set, U and V are both preset model parameters, Softmax is the preset activation function, and p i is the probability distribution of the entity category corresponding to the i-th annotated text data in the text dataset.

[0029] In a specific implementation of the first aspect, calculating the second loss function according to the probability distribution may include:

[0030] The second loss function is calculated according to the following formula:

[0031]

[0032] Where n is the number of annotated text data in the text dataset, z i is the entity category label corresponding to the i-th annotated text data in the text dataset, and loss is the second loss function.

[0033] In a specific implementation of the first aspect, the using the annotated trained named entity recognition model to predict the unannotated text data in the text data set to obtain the first category of text data annotated by the model and the second category of text data to be manually annotated may include:

[0034] Using the labeled trained named entity recognition model to predict the unlabeled text data in the text dataset, and calculating the confidence of the prediction result;

[0035] The unlabeled text data whose confidence level of the prediction result is greater than or equal to a preset confidence level threshold is used as the first category of text data;

[0036] The unlabeled text data whose confidence level of the prediction result is less than the confidence level threshold is taken as the second category of text data.

[0037] A second aspect of an embodiment of the present invention provides a named entity recognition device, which may include:

[0038] An encoder pre-training module, used to pre-train an encoder in a preset twin network using text data in a preset text data set to obtain a pre-trained encoder;

[0039] A model training module, used to use the pre-trained encoder as an encoder of a preset named entity recognition model, and train the named entity recognition model using the annotated text data in the text data set to obtain a named entity recognition model after annotated training;

[0040] A model prediction module, used to use the named entity recognition model after the annotation training to predict the unannotated text data in the text data set, and obtain the first category of text data annotated by the model and the second category of text data to be manually annotated;

[0041] A module for adding annotated text data, used to obtain the second type of text data after manual annotation, and use the first type of text data after the model annotation and the second type of text data after manual annotation as newly added annotated text data;

[0042] A model adjustment module, used to adjust the annotated trained named entity recognition model using the newly added annotated text data to obtain an adjusted named entity recognition model;

[0043] The named entity recognition module is used to obtain target text data to be recognized, and use the adjusted named entity recognition model to process the target text data to obtain the entity category of each named entity in the target text data.

[0044] In a specific implementation of the second aspect, the encoder pre-training module may include:

[0045] A data enhancement unit, configured to perform data enhancement on the text data in the text data set to obtain a preset number of enhanced text data pairs; wherein any one of the enhanced text data pairs includes two different enhanced text data obtained by performing data enhancement on the same text data;

[0046] A twin network processing unit, used to process the enhanced text data pair using the twin network to obtain a first feature vector and a second feature vector respectively;

[0047] A first loss function calculation unit, used for calculating a first loss function according to the first eigenvector and the second eigenvector;

[0048] A pre-training unit is used to pre-train the encoder in the twin network with the goal of minimizing the first loss function to obtain a pre-trained encoder.

[0049] In a specific implementation of the second aspect, the first loss function calculation unit may be specifically configured to calculate the first loss function according to the following formula:

[0050]

[0051] Wherein, p1 is the first eigenvector, z2 is the second eigenvector, ||p1||2 is the modulus of the first eigenvector, ||z2||2 is the modulus of the second eigenvector, is the first loss function.

[0052] In a specific implementation of the second aspect, the model training module may include:

[0053] An encoding unit, used to encode the annotated text data in the text data set using an encoder of the named entity recognition model to obtain an encoded feature vector;

[0054] A multi-layer perception unit, used to process the encoded feature vector using the multi-layer perceptron of the named entity recognition model to obtain a probability distribution of entity categories;

[0055] A second loss function calculation unit, used to calculate a second loss function according to the probability distribution;

[0056] The model training unit is used to train the named entity recognition model with the goal of minimizing the second loss function to obtain a named entity recognition model after annotation training.

[0057] In a specific implementation of the second aspect, the multi-layer perception unit may be specifically used to calculate the probability distribution of entity categories according to the following formula:

[0058] pi =Softmax(U tanh(Vh i ))

[0059] Where i is the serial number of the annotated text data in the text dataset, h i is the encoded feature vector corresponding to the i-th annotated text data in the text data set, U and V are both preset model parameters, Softmax is the preset activation function, and p i is the probability distribution of the entity category corresponding to the i-th annotated text data in the text dataset.

[0060] In a specific implementation of the second aspect, the second loss function calculation unit may be specifically configured to calculate the second loss function according to the following formula:

[0061]

[0062] Where n is the number of annotated text data in the text dataset, z i is the entity category label corresponding to the i-th annotated text data in the text dataset, and loss is the second loss function.

[0063] In a specific implementation of the second aspect, the model prediction module may include:

[0064] A prediction unit, used to predict the unlabeled text data in the text data set using the labeled trained named entity recognition model, and calculate the confidence of the prediction result;

[0065] A first-category text data determination unit, configured to use unlabeled text data whose prediction result confidence is greater than or equal to a preset confidence threshold as the first-category text data;

[0066] The second-category text data determining unit is used to take the unlabeled text data whose prediction result confidence is less than the confidence threshold as the second-category text data.

[0067] A third aspect of an embodiment of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of any one of the above-mentioned named entity recognition methods are implemented.

[0068] A fourth aspect of an embodiment of the present invention provides a terminal device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of any one of the above-mentioned named entity recognition methods when executing the computer program.

[0069] A fifth aspect of an embodiment of the present invention provides a computer program product. When the computer program product is run on a terminal device, the terminal device executes the steps of any one of the above-mentioned named entity recognition methods.

[0070] Compared with the prior art, the embodiments of the present invention have the following beneficial effects: the embodiments of the present invention use text data in a preset text data set to pre-train an encoder in a preset twin network to obtain a pre-trained encoder; the pre-trained encoder is used as an encoder of a preset named entity recognition model, and the annotated text data in the text data set is used to train the named entity recognition model to obtain an annotated trained named entity recognition model; the annotated trained named entity recognition model is used to predict the unannotated text data in the text data set to obtain the first category of text data annotated by the model and the second category of text data to be manually annotated; the manually annotated second category of text data is obtained, and the first category of text data annotated by the model and the manually annotated second category of text data are used as newly annotated text data; the newly annotated text data is used to adjust the annotated trained named entity recognition model to obtain an adjusted named entity recognition model; the target text data to be recognized is obtained, and the adjusted named entity recognition model is used to process the target text data to obtain the entity category of each named entity in the target text data. Through the embodiments of the present invention, active learning and contrastive learning are integrated. First, the encoder is pre-trained using the contrastive learning method and used for the training of the named entity recognition model. In the subsequent active learning process, the model continuously performs self-iterative training and optimization through the feedback received. The entire process only requires a small amount of manual labeling, which effectively reduces the consumption of time and money costs. BRIEF DESCRIPTION OF THE DRAWINGS

[0071] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.

[0072] Figure 1 A flowchart of a method for named entity recognition in an embodiment of the present invention;

[0073] Figure 2 A schematic flowchart for pre-training an encoder in a preset twin network using text data in a preset text dataset;

[0074] Figure 3A schematic flowchart for training a named entity recognition model using annotated text data in a text dataset;

[0075] Figure 4 A schematic diagram of a named entity recognition model;

[0076] Figure 5 A structural diagram of an embodiment of a named entity recognition device in an embodiment of the present invention;

[0077] Figure 6 The present invention is a schematic block diagram of a terminal device in an embodiment of the present invention. DETAILED DESCRIPTION

[0078] In order to make the purpose, features and advantages of the present invention more obvious and easy to understand, the technical solutions 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 embodiments described below 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 are within the scope of protection of the present invention.

[0079] The embodiments of the present invention can acquire and process relevant data based on artificial intelligence technology. Artificial Intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.

[0080] AI basic technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, mechatronics, etc. AI software technologies mainly include computer vision technology, robotics technology, biometrics technology, speech processing technology, natural language processing technology, and machine learning / deep learning.

[0081] The execution subject of the embodiment of the present invention may be an artificial intelligence-based terminal device, which is used to execute the named entity recognition method in the embodiment of the present invention.

[0082] See also Figure 1 , an embodiment of a method for named entity recognition in an embodiment of the present invention may include:

[0083] Step S101: Use text data in a preset text data set to pre-train an encoder in a preset twin network to obtain a pre-trained encoder.

[0084] like Figure 2As shown, step S101 may specifically include the following process:

[0085] Step S1011: perform data enhancement on the text data in the text data set to obtain a preset number of enhanced text data pairs.

[0086] The text data set may include annotated text data and unannotated text data. Any of the enhanced text data pairs includes two different enhanced text data obtained by performing data enhancement on the same text data.

[0087] In an embodiment of the present invention, by performing data enhancement on the same sample, a series of self-similar text data pairs can be obtained as positive examples. The specific data enhancement method can be set according to the actual situation. For example, in one implementation, a dropout method can be used for data enhancement, that is, a dropout operation is performed on the text data by randomly sampling a dropout mask. The same text data is subjected to two consecutive dropout operations, and two different enhanced text data can be obtained respectively, thereby forming an enhanced text data pair.

[0088] It should be noted that the above is only an example and not a limitation of the data enhancement method. In practical applications, other data enhancement methods in the prior art can be adopted according to specific circumstances, and the embodiments of the present invention do not make specific limitations on this.

[0089] Step S1012: Use the twin network to process the enhanced text data pair to obtain a first feature vector and a second feature vector, respectively.

[0090] The twin network can be a SimSiam network, which includes two processing branches (respectively recorded as branch 1 and branch 2), which process the two enhanced text data in the enhanced text data pair (respectively recorded as text data 1 and text data 2), wherein the encoder in branch 1 encodes text data 1 to obtain a first feature vector; the encoder in branch 2 encodes text data 2, and the encoding result is then subjected to a nonlinear change of the predictor to obtain a second feature vector. It should be noted that the encoder in branch 1 and the encoder in branch 2 share the same parameters and can be considered to be the same encoder.

[0091] Step S1013: Calculate a first loss function according to the first eigenvector and the second eigenvector.

[0092] Specifically, the first loss function can be calculated according to the following formula:

[0093]

[0094] Wherein, p1 is the first eigenvector, z2 is the second eigenvector, ||p1||2 is the modulus of the first eigenvector, ||z2||2 is the modulus of the second eigenvector, is the first loss function.

[0095] Step S1014: pre-train the encoder in the twin network with the goal of minimizing the first loss function to obtain a pre-trained encoder.

[0096] After the first loss function is calculated, the model parameters of the twin network can be adjusted according to the first loss function. In an embodiment of the present invention, assuming that the model parameter of the twin network is W1, the first loss function is back-propagated to modify the model parameter W1 of the twin network to obtain the modified model parameter W2. After modifying the parameters, continue to execute the next training process. In this training process, recalculate the first loss function, back-propagate the first loss function to modify the model parameter W2 of the twin network, and obtain the modified model parameter W3, ..., and so on. Repeat the above process continuously. Each training process can modify the model parameters of the twin network until the preset training conditions are met. The training condition can be that the number of training times reaches a preset number threshold. The number threshold can be set according to the actual situation. For example, it can be set to thousands, tens of thousands, hundreds of thousands or even larger values; the training condition can also be the convergence of the twin network; because the number of training times may not reach the number threshold, but the twin network has converged, it may cause unnecessary repetition of work; or the twin network cannot converge all the time, which may lead to an infinite loop and the training process cannot be ended. Based on the above two situations, the training condition can also be that the number of training times reaches the number threshold or the twin network converges. When the training conditions are met, the pre-trained twin network can be obtained, and the encoder at this time is the pre-trained encoder.

[0097] Through the comparative learning method in the embodiment of the present invention, the parameters of the encoder have been optimized and can be used for the subsequent named entity recognition process.

[0098] Step S102: using the pre-trained encoder as an encoder of a preset named entity recognition model, and using the annotated text data in the text data set to train the named entity recognition model to obtain a named entity recognition model after annotated training.

[0099] like Figure 3 As shown, step S102 may specifically include the following process:

[0100] Step S1021: Use the encoder of the named entity recognition model to encode the annotated text data in the text data set to obtain an encoded feature vector.

[0101] Figure 4 The figure shows a schematic diagram of the named entity recognition model, which may include an encoder and a multi-layer perceptron. i is the serial number of the annotated text data in the text data set, x is i is the i-th annotated text data in the text data set, 1≤i≤n, n is the number of annotated text data in the text data set, and the encoder of the named entity recognition model is x i Encode and get the same value as x i The corresponding encoded feature vector is denoted as h i .

[0102] Step S1022: Use the multi-layer perceptron of the named entity recognition model to process the encoded feature vector to obtain a probability distribution of entity categories.

[0103] Specifically, the probability distribution of entity categories can be calculated according to the following formula:

[0104] p i =Softmax(U tanh(Vh i ))

[0105] Among them, U and V are preset model parameters, Softmax is the preset activation function, and p i For x i The probability distribution of the corresponding entity category.

[0106] Step S1023: Calculate a second loss function according to the probability distribution.

[0107] Specifically, the second loss function can be calculated according to the following formula:

[0108]

[0109] Among them, z i For x i The corresponding entity category label is the entity category manually labeled in advance, and the loss is the second loss function.

[0110] Step S1024: training the named entity recognition model with the goal of minimizing the second loss function to obtain a named entity recognition model after annotation training.

[0111] After the second loss function is calculated, the model parameters of the named entity recognition model can be adjusted according to the second loss function. In an embodiment of the present invention, assuming that the model parameter of the named entity recognition model is V1, the second loss function is back-propagated to modify the model parameter V1 of the named entity recognition model to obtain the modified model parameter V2. After modifying the parameters, the next training process is continued. In this training process, the second loss function is recalculated, and the second loss function is back-propagated to modify the model parameter V2 of the named entity recognition model to obtain the modified model parameter V3, ..., and so on. The above process is repeated continuously. The model parameters of the named entity recognition model can be modified in each training process until the preset training conditions are met. The training condition can be that the number of training times reaches a preset number threshold. The number threshold can be set according to the actual situation. For example, it can be set to thousands, tens of thousands, hundreds of thousands or even larger values; the training condition can also be that the named entity recognition model converges; because the number of training times may not reach the number threshold, but the named entity recognition model has converged, it may cause unnecessary work to be repeated; or the named entity recognition model cannot converge, which may lead to an infinite loop and the training process cannot be ended. Based on the above two situations, the training condition can also be that the number of training times reaches the number threshold or the named entity recognition model converges. When the training conditions are met, the named entity recognition model after the labeled training can be obtained.

[0112] Step S103: Use the trained named entity recognition model to predict the unlabeled text data in the text data set to obtain the first category of text data labeled by the model and the second category of text data to be manually labeled.

[0113] Specifically, the named entity recognition model after the annotation training can be used to predict the unlabeled text data in the text data set, and the confidence of the prediction result can be calculated. Then, the unlabeled text data whose confidence of the prediction result is greater than or equal to the preset confidence threshold can be regarded as the first category of text data, that is, the text data that is easier to be labeled by the model; the unlabeled text data whose confidence of the prediction result is less than the confidence threshold can be regarded as the second category of text data, that is, the text data that is difficult to be labeled by the model. For example, if "Mary" is labeled, if the probability of the predicted labeling given by the model as the entity category "PER" and "LOC" is relatively close, then its final labeling result cannot be determined, so it can be regarded as the second category of text data, which needs to be screened out for manual labeling. The specific value of the confidence threshold can be set according to the actual situation, and the embodiment of the present application does not make specific restrictions on this.

[0114] Step S104: obtaining the manually annotated second-category text data, and using the model-annotated first-category text data and the manually annotated second-category text data as newly annotated text data.

[0115] In an embodiment of the present invention, experts can be arranged to manually annotate the screened second category of text data. Through such an active learning method, the text data that is easier to annotate through the model is directly annotated using the model, and only the screened text data that is difficult to annotate through the model is manually annotated, which greatly improves the overall efficiency of the model.

[0116] Step S105: Use the newly added annotated text data to adjust the annotated trained named entity recognition model to obtain an adjusted named entity recognition model.

[0117] After the above process, a part of the unlabeled text data is converted into labeled text data. The amount of labeled text data continues to increase in the process. The newly added labeled text data can continue to be used to adjust the named entity recognition model to obtain an adjusted named entity recognition model.

[0118] It should be noted that the adjustment of the model is a continuous iterative process, that is, continuously repeating steps S103 to S105, continuously converting unlabeled text data into labeled text data, and using the newly added labeled text data for a new round of model adjustment until the final named entity recognition model reaches the predetermined recognition accuracy. In subsequent named entity recognition tasks, the model can be used for named entity recognition.

[0119] Step S106: Acquire target text data to be recognized, and use the adjusted named entity recognition model to process the target text data to obtain entity categories of each named entity in the target text data.

[0120] The target text data may be pre-stored in the terminal device, or may be sent to the terminal device by other devices through a preset communication method, or may be input into the terminal device by a user through a preset human-computer interaction interface. When named entity recognition is required, the terminal device can use the adjusted named entity recognition model to process the target text data, thereby obtaining the entity category of each named entity in the target text data. For example, if the target text data is "Xiao Ming goes to school at 8 o'clock in the morning.", then after being processed by the adjusted named entity recognition model, the final recognition result is: (named entity: Xiao Ming, entity category: name); (named entity: 8 o'clock in the morning, entity category: time); (named entity: school, entity category: place).

[0121] In summary, the embodiment of the present invention uses the text data in a preset text data set to pre-train the encoder in the preset twin network to obtain a pre-trained encoder; uses the pre-trained encoder as the encoder of a preset named entity recognition model, and uses the annotated text data in the text data set to train the named entity recognition model to obtain a named entity recognition model after annotated training; uses the annotated trained named entity recognition model to predict the unannotated text data in the text data set to obtain the first category of text data annotated by the model and the second category of text data to be manually annotated; obtains the second category of text data annotated by the model, and uses the first category of text data annotated by the model and the second category of text data annotated by the model as newly annotated text data; uses the newly annotated text data to adjust the annotated trained named entity recognition model to obtain an adjusted named entity recognition model; obtains the target text data to be recognized, and uses the adjusted named entity recognition model to process the target text data to obtain the entity category of each named entity in the target text data. Through the embodiments of the present invention, active learning and contrastive learning are integrated. First, the encoder is pre-trained using the contrastive learning method and used for the training of the named entity recognition model. In the subsequent active learning process, the model continuously performs self-iterative training and optimization through the feedback received. The entire process only requires a small amount of manual labeling, which effectively reduces the consumption of time and money costs.

[0122] It should be understood that the order of execution of the steps in the above embodiment does not necessarily mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present invention.

[0123] Corresponding to a named entity recognition method described in the above embodiment, Figure 5 A structural diagram of an embodiment of a named entity recognition device provided by an embodiment of the present invention is shown.

[0124] In this embodiment, a named entity recognition device may include:

[0125] An encoder pre-training module 501 is used to pre-train an encoder in a preset twin network using text data in a preset text data set to obtain a pre-trained encoder;

[0126] A model training module 502 is used to use the pre-trained encoder as an encoder of a preset named entity recognition model, and use the annotated text data in the text data set to train the named entity recognition model to obtain a named entity recognition model after annotated training;

[0127] A model prediction module 503 is used to predict the unlabeled text data in the text data set using the labeled trained named entity recognition model to obtain the first type of text data labeled by the model and the second type of text data to be manually labeled;

[0128] The annotated text data adding module 504 is used to obtain the second type of text data after manual annotating, and use the first type of text data after the model annotates and the second type of text data after manual annotating as the newly annotated text data;

[0129] A model adjustment module 505 is used to adjust the annotated trained named entity recognition model using the newly added annotated text data to obtain an adjusted named entity recognition model;

[0130] The named entity recognition module 506 is used to obtain target text data to be recognized, and use the adjusted named entity recognition model to process the target text data to obtain the entity category of each named entity in the target text data.

[0131] In a specific implementation of the embodiment of the present invention, the encoder pre-training module may include:

[0132] A data enhancement unit, configured to perform data enhancement on the text data in the text data set to obtain a preset number of enhanced text data pairs; wherein any one of the enhanced text data pairs includes two different enhanced text data obtained by performing data enhancement on the same text data;

[0133] A twin network processing unit, used to process the enhanced text data pair using the twin network to obtain a first feature vector and a second feature vector respectively;

[0134] A first loss function calculation unit, used for calculating a first loss function according to the first eigenvector and the second eigenvector;

[0135] A pre-training unit is used to pre-train the encoder in the twin network with the goal of minimizing the first loss function to obtain a pre-trained encoder.

[0136] In a specific implementation of the embodiment of the present invention, the first loss function calculation unit may be specifically configured to calculate the first loss function according to the following formula:

[0137]

[0138] Wherein, p1 is the first eigenvector, z2 is the second eigenvector, ||p1||2 is the modulus of the first eigenvector, ||z2||2 is the modulus of the second eigenvector, is the first loss function.

[0139] In a specific implementation of the embodiment of the present invention, the model training module may include:

[0140] An encoding unit, used to encode the annotated text data in the text data set using an encoder of the named entity recognition model to obtain an encoded feature vector;

[0141] A multi-layer perception unit, used to process the encoded feature vector using the multi-layer perceptron of the named entity recognition model to obtain a probability distribution of entity categories;

[0142] A second loss function calculation unit, used to calculate a second loss function according to the probability distribution;

[0143] The model training unit is used to train the named entity recognition model with the goal of minimizing the second loss function to obtain a named entity recognition model after annotation training.

[0144] In a specific implementation of the embodiment of the present invention, the multi-layer perception unit can be specifically used to calculate the probability distribution of entity categories according to the following formula:

[0145] p i =Softmax(U tanh(Vh i ))

[0146] Where i is the serial number of the annotated text data in the text dataset, h i is the encoded feature vector corresponding to the i-th annotated text data in the text data set, U and V are both preset model parameters, Softmax is the preset activation function, and p i is the probability distribution of the entity category corresponding to the i-th annotated text data in the text dataset.

[0147] In a specific implementation of the embodiment of the present invention, the second loss function calculation unit may be specifically configured to calculate the second loss function according to the following formula:

[0148]

[0149] Where n is the number of annotated text data in the text dataset, z i is the entity category label corresponding to the i-th annotated text data in the text dataset, and loss is the second loss function.

[0150] In a specific implementation of the embodiment of the present invention, the model prediction module may include:

[0151] A prediction unit, used to predict the unlabeled text data in the text data set using the labeled trained named entity recognition model, and calculate the confidence of the prediction result;

[0152] A first-category text data determination unit, configured to use unlabeled text data whose prediction result confidence is greater than or equal to a preset confidence threshold as the first-category text data;

[0153] The second-category text data determining unit is used to take the unlabeled text data whose prediction result confidence is less than the confidence threshold as the second-category text data.

[0154] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the above-described devices, modules and units can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0155] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0156] Figure 6 A schematic block diagram of a terminal device provided by an embodiment of the present invention is shown. For ease of explanation, only the parts related to the embodiment of the present invention are shown.

[0157] In this embodiment, the terminal device 6 may be a computing device such as a desktop computer, a notebook, or a palm computer. The terminal device 6 may include: a processor 60, a memory 61, and a computer-readable instruction 62 stored in the memory 61 and executable on the processor 60, such as a computer-readable instruction for executing the above-mentioned named entity recognition method. When the processor 60 executes the computer-readable instruction 62, the steps in the above-mentioned named entity recognition method embodiments are implemented, such as Figure 1 Alternatively, when the processor 60 executes the computer-readable instructions 62, the functions of each module / unit in the above-mentioned device embodiments are realized, for example, Figure 5 Functions of modules 501 to 506 are shown.

[0158] Exemplarily, the computer-readable instructions 62 may be divided into one or more modules / units, which are stored in the memory 61 and executed by the processor 60 to implement the present invention. The one or more modules / units may be a series of computer-readable instruction segments capable of implementing specific functions, which are used to describe the execution process of the computer-readable instructions 62 in the terminal device 6.

[0159] The processor 60 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.

[0160] The memory 61 may be an internal storage unit of the terminal device 6, such as a hard disk or memory of the terminal device 6. The memory 61 may also be an external storage device of the terminal device 6, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the terminal device 6. Further, the memory 61 may also include both an internal storage unit of the terminal device 6 and an external storage device. The memory 61 is used to store the computer-readable instructions and other instructions and text data required by the terminal device 6. The memory 61 may also be used to temporarily store text data that has been output or is to be output.

[0161] 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 integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0162] 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 computer-readable instructions to enable 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, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc. Various media that can store computer-readable instructions.

[0163] The embodiments described above are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A method for named entity recognition, characterized in that: include: Data enhancement is performed on text data in a preset text data set to obtain a preset number of enhanced text data pairs; wherein any of the enhanced text data pairs includes two different enhanced text data obtained by data enhancement of the same text data; the enhanced text data pairs are processed using a preset twin network to obtain a first feature vector and a second feature vector, respectively; a first loss function is calculated based on the first feature vector and the second feature vector; an encoder in the twin network is pre-trained with the goal of minimizing the first loss function to obtain a pre-trained encoder; Using the pre-trained encoder as an encoder of a preset named entity recognition model, and using the annotated text data in the text data set to train the named entity recognition model to obtain a named entity recognition model after annotated training; The unlabeled text data in the text data set is predicted using the named entity recognition model after the annotation training, and the confidence of the prediction result is calculated; the unlabeled text data whose confidence of the prediction result is greater than or equal to a preset confidence threshold is used as the first category of text data after the model annotation; the unlabeled text data whose confidence of the prediction result is less than the confidence threshold is used as the second category of text data to be manually annotated; Acquire the manually annotated second-category text data, and use the model-annotated first-category text data and the manually annotated second-category text data as newly annotated text data; Using the newly added annotated text data to adjust the annotated trained named entity recognition model to obtain an adjusted named entity recognition model; The target text data to be recognized is acquired, and the target text data is processed using the adjusted named entity recognition model to obtain the entity category of each named entity in the target text data.

2. The method for named entity recognition according to claim 1, characterized in that: The calculating a first loss function according to the first eigenvector and the second eigenvector includes: The first loss function is calculated according to the following formula: Wherein, p1 is the first eigenvector, z2 is the second eigenvector, ∥p1∥2 is the modulus of the first eigenvector, ∥z2∥2 is the modulus of the second eigenvector, is the first loss function.

3. The method for named entity recognition according to claim 1, characterized in that: The method of training the named entity recognition model using the annotated text data in the text data set to obtain the annotated and trained named entity recognition model includes: Encode the annotated text data in the text data set using the encoder of the named entity recognition model to obtain an encoded feature vector; Processing the encoded feature vector using a multilayer perceptron of the named entity recognition model to obtain a probability distribution of entity categories; Calculate a second loss function according to the probability distribution; The named entity recognition model is trained with the goal of minimizing the second loss function to obtain a labeled trained named entity recognition model.

4. The method for named entity recognition according to claim 3, characterized in that: The multi-layer perceptron using the named entity recognition model processes the encoded feature vector to obtain a probability distribution of entity categories, including: The probability distribution of entity categories is calculated according to the following formula: p i =Softmax(U tanh(Vh i )) Where i is the serial number of the annotated text data in the text dataset, h i is the encoded feature vector corresponding to the i-th annotated text data in the text data set, U and V are both preset model parameters, Softmax is the preset activation function, and p i is the probability distribution of the entity category corresponding to the i-th annotated text data in the text dataset.

5. The method for named entity recognition according to claim 4, characterized in that: The calculating a second loss function according to the probability distribution comprises: The second loss function is calculated according to the following formula: Where n is the number of annotated text data in the text dataset, z i is the entity category label corresponding to the i-th annotated text data in the text dataset, and loss is the second loss function.

6. A named entity recognition device, characterized in that: include: An encoder pre-training module is used to perform data enhancement on text data in a preset text data set to obtain a preset number of enhanced text data pairs; wherein any of the enhanced text data pairs includes two different enhanced text data obtained by data enhancement of the same text data; the enhanced text data pairs are processed using a preset twin network to obtain a first feature vector and a second feature vector respectively; a first loss function is calculated based on the first feature vector and the second feature vector; an encoder in the twin network is pre-trained with the goal of minimizing the first loss function to obtain a pre-trained encoder; A model training module, used to use the pre-trained encoder as an encoder of a preset named entity recognition model, and train the named entity recognition model using the annotated text data in the text data set to obtain a named entity recognition model after annotated training; A model prediction module is used to use the named entity recognition model after the annotation training to predict the unannotated text data in the text data set, and calculate the confidence of the prediction result; the unannotated text data whose confidence of the prediction result is greater than or equal to a preset confidence threshold is used as the first category of text data after model annotation; the unannotated text data whose confidence of the prediction result is less than the confidence threshold is used as the second category of text data to be manually annotated; A module for adding annotated text data, used to obtain the second type of text data after manual annotation, and use the first type of text data after the model annotation and the second type of text data after manual annotation as newly added annotated text data; A model adjustment module, used to adjust the annotated trained named entity recognition model using the newly added annotated text data to obtain an adjusted named entity recognition model; The named entity recognition module is used to obtain target text data to be recognized, and use the adjusted named entity recognition model to process the target text data to obtain the entity category of each named entity in the target text data.

7. A computer-readable storage medium storing computer-readable instructions, characterized in that: When the computer-readable instructions are executed by a processor, the steps of the named entity recognition method according to any one of claims 1 to 5 are implemented.

8. A terminal device, comprising a memory, a processor, and computer-readable instructions stored in the memory and executable on the processor, characterized in that: When the processor executes the computer-readable instructions, the steps of the named entity recognition method according to any one of claims 1 to 5 are implemented.

Citation Information

Patent Citations

  • Semi-supervised Chinese named entity recognition method based on deep learning

    CN108959252A

  • Text emotion recognition method and device, terminal equipment and storage medium

    CN112101042A