Method for training a named entity recognition model and method for named entity recognition
By utilizing the BERT-CRF model and labeled samples from similar domains for training, the problem of named entity recognition model training relying on large-scale labeled corpora has been solved, realizing the development and application of a low-cost and efficient named entity recognition model.
Patent Information
- Application Number
- CN202110349239.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-03-31
- Publication Date
- 2025-12-23
- Estimated Expiration
- 2041-03-31
AI Technical Summary
In existing technologies, supervised learning named entity recognition models rely on large-scale labeled corpora for training, resulting in high labeling costs and low development efficiency.
The BERT-CRF model is adopted and trained using labeled samples from similar domains in the target domain. Multiple batches of meta-training data are obtained from the training set, including the training support set and the query set. The emission score and transition score are calculated using BERT layers and CRF layers to adjust the model parameters. In the testing phase, a very small number of labeled samples from the target domain are used to test the training effect.
It reduces the cost of manually labeled samples, improves the development efficiency of named entity recognition models, and enables high-accuracy named entity recognition in the target domain.
Smart Images

Figure CN113177411B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of natural language processing, in particular to a named entity recognition model training method and a named entity recognition method. BACKGROUND
[0002] A named entity refers to an entity word with specific meaning or strong representation in a certain field, such as an event name, a place name, a person name, etc. in the news field. Named entity recognition (NER) refers to recognizing entities with specific meaning in a text, mainly including a person name, a place name, an organization name, a proper noun, etc. At present, named entity recognition is mainly converted into a supervised learning problem in machine learning, a statistical learning model or a deep learning model is established and trained, and finally a named entity recognition result is obtained. The training of the named entity recognition model in supervised learning depends on large-scale annotated corpus. The annotated corpus is usually obtained by active labeling by humans, and the cost of obtaining the annotated corpus is high. A large amount of annotated corpus is required to train a usable named entity recognition model. Before a large amount of annotated corpus is obtained, work cannot be carried out, which is equivalent to transferring the development cost to the labeling of the corpus, and the overall development efficiency is low.
[0003] At present, there is no effective solution to the problem that the training of the named entity recognition model in supervised learning in the related art depends on large-scale annotated corpus, resulting in high labeling cost and low development efficiency. SUMMARY
[0004] Embodiments of the present application provide a named entity recognition model training method and a named entity recognition method to at least solve the problem that the training of the named entity recognition model in supervised learning in the related art depends on large-scale annotated corpus, resulting in high labeling cost and low development efficiency.
[0005] In a first aspect, an embodiment of the present application provides a named entity recognition model training method, the named entity recognition model comprising a BERT-CRF model, and the training method comprising:
[0006] obtaining a training set, the training set comprising multiple batches of meta training data, each batch of meta training data comprising a training support set and a training query set, wherein the training set is annotated samples of a target field and a similar field;
[0007] training the named entity recognition model with each batch of the meta training data, each round of training comprising: inputting the training query set and the training support set into a BERT layer of a BERT-CRF model in the named entity recognition model, obtaining emission scores and transition scores of the training query set samples, inputting the emission scores and the transition scores of the training query set samples into a CRF layer of the BERT-CRF model in the named entity recognition model, obtaining a loss function of the named entity recognition model, and adjusting parameters of the named entity recognition model according to the loss function of the named entity recognition model.
[0008] In some embodiments, the training method further comprises, in each round of training:
[0009] obtaining a test set comprising a test support set and a test query set, wherein the test set is a labeled sample of the target domain;
[0010] inputting the test support set and the test query set into the BERT layer of the BERT-CRF model in the named entity recognition model, and obtaining emission scores and transition scores of the test query set samples;
[0011] inputting the emission scores and the transition scores of the test query set samples into the CRF layer of the BERT-CRF model in the named entity recognition model, and obtaining test category labels of the test query set samples;
[0012] judging an accuracy of the test set according to the test category labels of the test query set samples and real category labels, and if the accuracy of the test set is greater than or equal to a preset value, stopping the training, and if the accuracy of the test set is less than the preset value, continuing to train the named entity recognition model with a next batch of the meta training data.
[0013] In some embodiments, inputting the training query set and the training support set into the BERT layer of the BERT-CRF model in the named entity recognition model to obtain the emission scores of the training query set samples comprises:
[0014] inputting the training query set and the training support set into the BERT layer of the BERT-CRF model in the named entity recognition model to obtain feature representation vectors of the training support set samples and feature representation vectors of the training query set samples;
[0015] obtaining predefined anchor category feature representation vectors, wherein the anchor category feature representation vectors are represented by loss backpropagation adjustment vectors, and the number of the anchor category feature representation vectors is greater than or equal to the sum of the number of categories in the source domain and the number of categories in the target domain;
[0016] According to the feature representation vectors of the training support set samples, obtain the feature representation vector of each class label in the training support set, and perform singular value decomposition on the difference vector between the feature representation vector of each class label in the training support set and the anchor class feature representation vector to obtain a feature mapping function.
[0017] According to the feature mapping function, calculate the similarity between the feature representation vector of the training query set sample and the anchor class feature representation vector to obtain the emission score of the training query set sample.
[0018] In some embodiments, according to the feature representation vectors of the training support set samples, obtaining the feature representation vector of each class label in the training support set comprises:
[0019] According to the class label of each word in the training support set sample, obtain the feature representation vector of the corresponding word in each training support set sample, and calculate the average value of the feature representation vectors of all words under each class as the feature representation vector of each class label in the training support set.
[0020] In some embodiments, inputting the training query set and the training support set into the BERT layer of the BERT-CRF model of the named entity recognition model to obtain the transition score of the training query set sample comprises:
[0021] According to the label class in the training query set sample, obtain a label class transition matrix, adjust the label class transition matrix according to the loss back propagation in training, and obtain the transition score of the training query set sample according to the label class transition matrix.
[0022] In some embodiments, before obtaining the training set and the test set, the training method further comprises:
[0023] According to the target domain, obtain a plurality of source domains of the target domain, and the annotation data set of a single domain is a batch of meta-training data, so that the number of each type of label contained in each batch of meta-training data is balanced, wherein the annotation data sets of a plurality of source domains are training sets, and the annotation data set of the target domain is a test set.
[0024] In some embodiments, after balancing the number of each type of label contained in each batch of meta-training data, the training method further comprises:
[0025] Each word or subword corresponds to a sequence number in a model vocabulary, and each word or subword corresponds to a sequence number in all labels in the field. The sequence number of each sample in the meta-training data in the field data is saved in the meta data sequence number. Each batch of the meta-training data is loaded through the field data and the meta data sequence number. Each batch of the meta-training data includes a plurality of samples, each sample includes a plurality of words or subwords, and each word or subword has a label.
[0026] In a second aspect, the embodiments of the present application provide a named entity recognition method, which uses the named entity recognition model obtained by the named entity recognition model training method to perform named entity recognition. The method comprises the following steps:
[0027] Obtain a prediction support set and a prediction query set of a target field, wherein the prediction support set is a labeled data set, and the prediction query set is an unlabeled data set.
[0028] Input the prediction support set and the prediction query set into the named entity recognition model to obtain the prediction class label of the prediction query set sample.
[0029] In a third aspect, the embodiments of the present application provide an electronic device, which comprises a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the training method of the named entity recognition model and the named entity recognition method are realized.
[0030] In a fourth aspect, the embodiments of the present application provide a storage medium, which stores a computer program. When the processor executes the computer program, the training method of the named entity recognition model and the named entity recognition method are realized.
[0031] Compared with the related art, the training method of the named entity recognition model provided in the embodiments of the present application includes a BERT-CRF model, the training set is obtained, the training set includes multiple batches of meta training data, each batch of meta training data includes a training support set and a training query set, wherein the training set is a labeled sample of a target field and a similar field; each batch of meta training data is used to train the named entity recognition model, each round of training includes: inputting the training query set and the training support set into the BERT layer of the BERT-CRF model in the named entity recognition model, obtaining the emission score and the transition score of the training query set sample, inputting the emission score and the transition score of the training query set sample into the CRF layer of the BERT-CRF model in the named entity recognition model, obtaining the loss of the named entity recognition model, and adjusting the parameters of the named entity recognition model according to the loss of the named entity recognition model. When the target field has only a small amount of labeled samples, and the source field has a large amount of labeled samples, the labeled samples of the source field are used as the training set, the existing labeled resources are ingeniously used, the knowledge learned by the named entity recognition model is transferred to the scene with a small amount of labeled samples, and the problems of high cost of obtaining labeled samples, inability to work before obtaining sufficient labeled samples of the target field, and low overall development efficiency are solved. BRIEF DESCRIPTION OF DRAWINGS
[0032] The accompanying drawings, which are included to provide a further understanding of the present application, constitute a part of the present application and illustrate the illustrative embodiments of the present application and their description serve to explain the present application, but do not constitute improper limitations on the present application. In the drawings:
[0033] Figure 1 is a flowchart of the training method of the named entity recognition model according to the embodiments of the present application;
[0034] Figure 2 is a flowchart of the test of the named entity recognition model according to the embodiments of the present application;
[0035] Figure 3 is a flowchart of the named entity recognition method according to the embodiments of the present application. DETAILED DESCRIPTION
[0036] In order to make the objectives, technical solutions and advantages of the present application clearer, the present application will be described and explained below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only intended to explain the present application and should not be used to limit the present application. Based on the embodiments provided by the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort fall within the scope of the present application. In addition, it should be understood that, although the efforts made in this development process can be complex and lengthy, some design, manufacture or production changes made on the basis of the technical content disclosed in the present application by those of ordinary skill in the art related to the content disclosed in the present application are only routine technical means and should not be understood as insufficient disclosure of the present application.
[0037] In the present application, the term "embodiment" means that the specific features, structures or characteristics described in conjunction with the embodiment can be included in at least one embodiment of the present application. The appearance of this phrase in various places in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment to other embodiments. It is explicitly and implicitly understood by those of ordinary skill in the art that the embodiments described in the present application can be combined with other embodiments without conflict.
[0038] Unless otherwise defined, the technical terms or scientific terms involved in the present application should be understood as the usual meaning understood by those of ordinary skill in the art to which the present application belongs. The terms "one", "a", "an", "the", and the like similar words involved in the present application do not represent quantity limitation, but can represent singular or plural. The terms "include", "contain", "have", and any variations thereof involved in the present application are intended to cover non-exclusive inclusion; for example, a process, method, system, product or device including a series of steps or modules (units) is not limited to the listed steps or units, but can also include steps or units not listed, or can also include other steps or units inherent to these processes, methods, products or devices. The terms "connected", "connected", "coupled" and the like similar words involved in the present application are not limited to physical or mechanical connections, but can include electrical connections, whether direct or indirect. The term "multiple" involved in the present application means greater than or equal to two. The term "and / or" describes the association between the associated objects, which means that there can be three relationships, for example, "A and / or B" can represent the existence of A alone, the existence of A and B together, and the existence of B alone. The terms "first", "second", "third" and the like involved in the present application are only to distinguish similar objects, and do not represent a specific order for the objects.
[0039] Before specifically introducing the embodiments of the present application, some terms used therein will be explained as follows:
[0040] BERT is a language model developed and released by Google in late 2018. Its full name is Bidirectional Encoder Representations from Transformers.
[0041] CRF (Conditional Random Fields) is a probabilistic undirected graphical model that, given an input random variable x, solves for the conditional probability P(y│x). The CRF model needs to model the conditional probability distributions of the input and output variables. CRFs are commonly used for labeling or analyzing sequence data, such as natural language text or biological sequences. When used for sequence labeling, the input and output random variables are two sequences of equal length.
[0042] Entity tags are tags used to indicate whether a corresponding word is an entity and what type of entity it is.
[0043] This embodiment provides a training method for a named entity recognition model, which includes the BERT-CRF model. Figure 1 This is a flowchart of a training method for a named entity recognition model according to an embodiment of this application, such as... Figure 1 As shown, the training method includes the following steps:
[0044] Step S101: Obtain the training set, which includes multiple batches of meta-training data. Each batch of meta-training data includes a training support set and a training query set. The training set consists of labeled samples from domains similar to the target domain. In this embodiment, the domains similar to the target domain are called source domains. The source domain is used as the training set, and each labeled sample from the source domain is used as a batch of meta-training data. Each batch of meta-training data includes N training support set samples and M training query set samples, where N and M are any integers greater than 1. The training samples in the training set include training statements and category labels corresponding to entities in the training statements.
[0045] Step S102: Train the named entity recognition model using each batch of meta-training data. Each training round includes: inputting the training query set and training support set into the BERT layer of the BERT-CRF model in the named entity recognition model, obtaining the emission score and transition score of the training query set samples, inputting the emission score and transition score of the training query set samples into the CRF layer of the BERT-CRF model in the named entity recognition model, obtaining the loss function of the named entity recognition model, and adjusting the parameters of the named entity recognition model according to the loss function of the named entity recognition model.
[0046] By the above steps S101 and S102, compared with the related art, when the named entity in the target field is identified, a large number of labeled samples of the target field are needed to train the named entity model, and the trained named entity recognition model can identify the named entity in the target field. In order to obtain the labeled samples of the target field, manual labeling is needed, which leads to high cost, and before sufficient labeled samples of the target field are obtained, work cannot be carried out, and the overall development efficiency is low. The present application trains the named entity model by using the labeled samples of the similar field of the target field, uses a large number of labeled resources of the similar field, and migrates the knowledge learned by the named entity recognition model to the target field scene with only a small amount of labeled samples, which greatly reduces the cost of manual labeling samples and improves the overall development efficiency.
[0047] In some embodiments, after training the named entity recognition model with the labeled samples of the source field, the named entity recognition model is tested with the labeled samples of the target field, and whether the named entity recognition model needs to be continuously trained is determined according to the test result, Figure 2 is a flowchart for testing the named entity recognition model according to the embodiments of the present application, as shown in Figure 2 The testing method comprises the following steps:
[0048] Step S201, in each training process, a test set is obtained, the test set comprising a test support set and a test query set, wherein the test set is a small amount of labeled samples of the target field;
[0049] Step S202, input the test support set and the test query set into the BERT layer of the BERT-CRF model in the named entity recognition model, obtain the emission score and the transition score of the test query set sample; input the emission score and the transition score of the test query set sample into the CRF layer of the BERT-CRF model in the named entity recognition model, obtain the test category label of the test query set sample;
[0050] Step S203, according to the test category label of the test query set sample and the real category label, judge the accuracy of the test set, if the accuracy of the test set is greater than or equal to a preset value, stop training, if the accuracy of the prediction result is less than the preset value, continue to train the named entity recognition model with the next batch of training set.
[0051] Through the steps S201 to S203, when there are only a small amount of labeled samples in the target domain, which are insufficient to train the named entity recognition model, the named entity recognition model is trained using a large amount of labeled samples of the similar domain of the target domain, and the named entity recognition model is tested using a small amount of labeled samples of the target domain. If the accuracy of the test result does not meet the requirements, the named entity recognition model is continuously trained using a large amount of labeled samples of the similar domain of the target domain. When the accuracy of the test result meets the requirements, it is indicated that the named entity recognition model has been trained and meets the requirements of named entity recognition of the unlabeled samples of the target domain, and the accuracy of the recognition result can be ensured when the named entity recognition of the unlabeled samples of the target domain is performed.
[0052] In some embodiments, the training query set and the training support set are input into the BERT layer of the BERT-CRF model of the named entity recognition model, and obtaining the emission score of the training query set sample includes:
[0053] The training query set and the training support set are input into the BERT layer of the BERT-CRF model of the named entity recognition model to obtain the feature representation vector of the training support set sample and the feature representation vector of the training query set sample. Since the training query set sample may exhibit different meanings after being concatenated with different training support set samples, in order to better represent the features of the words in the sample, the training query set sample is connected with each sample in the training support set, and the features of each word in the training query set sample and the training support set sample are calculated by the unsupervised model (BERT model) to obtain the features of each query-support sample pair. The average value is calculated, and then the length before concatenation is cut into the feature representation vector of the training query set sample and the feature representation vector of the training support set sample. For example, before the training query set sample and the training support set sample are concatenated, a training query set sample has 100 words, a training support set sample has 50 words, and the concatenated sentence has 150 words. The features of the 150 words are cut according to the length before concatenation. The features of the first 100 words are the feature representation vector of the training query set sample, and the features of the last 50 words are the feature representation vector of the training support set sample.
[0054] A predefined anchor category feature representation vector is obtained, and the anchor category feature representation vector is adjusted by a loss backpropagation vector. In this embodiment, the dimension of the anchor category feature representation vector is consistent with the vector dimension of each word in the sample.
[0055] According to the feature representation vectors of the training support set samples, a feature representation vector of each class label in the training support set is obtained, singular value decomposition is performed on the difference vector between the feature representation vector of each class label in the training support set and the anchor category feature representation vector, and a feature mapping function is obtained; in this embodiment, for the class label of each word in the training support set samples, the feature representation vector of the corresponding word in each sample is found, and the average value of the feature representation vectors of all words under the class label is calculated as the feature representation vector of each class label in the training support set, wherein the average value of the feature representation vectors of all words is obtained by normalizing the feature representation vector of each class label in the training support set by dividing the L1 norm of the feature representation vector of each class label in the training support set, singular value decomposition (Singular Value Decomposition, SVD for short) is an algorithm widely used in the field of machine learning, and SVD can be used not only for feature decomposition in dimension reduction algorithms, but also for recommendation systems, natural language processing and other fields.
[0056] According to the feature mapping function, the similarity between the feature representation vector of the training query set sample and the anchor category feature representation vector is calculated, and the emission score of the training query set sample is obtained. In this embodiment, after the feature representation vector of the training query set sample and the anchor category feature representation vector are mapped onto the same space by the feature mapping function, the dot product similarity is calculated between the feature representation vector of each word in the training query set sample and each anchor category feature representation vector, and the similarity between the feature representation vector of each word and all anchor category feature representation vectors is obtained, that is, the emission score of each word is obtained.
[0057] In some embodiments, the training query set and the training support set are input into the BERT layer of the BERT-CRF model of the named entity recognition model, and obtaining the transition score of the training query set sample comprises:
[0058] According to the label category in the training query set sample, a label category transition matrix is obtained, the label category transition matrix is adjusted according to the loss back propagation in the training, and the transition score of the training query set sample is obtained according to the label category transition matrix. In the embodiment, there are three labeling methods for label categories in named entity recognition, which are BIO, BMES and BIOES. Taking BIO as an example, B-X represents the beginning of entity X, I-X represents the end of the entity, and O represents not belonging to any type. According to the label categories under BIO, a 3-row and 5-column label category transition matrix is set in advance, 3 rows correspond to the 3 label categories of BIO, and 5 columns correspond to the probabilities of transition from BIO to “O, B of the same type, B of different type, I of the same type, and I of different type”. Among them, the same and different types refer to whether they are the same “person name”, “place name” and other named entity types. For the number of label types of the training query set, the label category transition matrix is instantiated and extended, that is, the type is changed to all types of the training query set. For example, if the training query set has a total of 2 types of labels “person name” and “place name”, the label category transition matrix is extended to a 5-row and 5-column label category transition matrix, 5 rows correspond to “O, B-person name, I-person name, B-place name, I-place name”, and 5 columns correspond to “O, B-person name, I-person name, B-place name, I-place name”. According to the label category transition matrix, the transition score of the training query set sample can be obtained.
[0059] In some embodiments, before obtaining the training set and the test set, according to the target field, a plurality of source fields of the similar fields of the target field are obtained. The labeled data set of a single field is a batch of meta-training data, and the number of each type of label contained in each batch of meta-training data is balanced. In the embodiment, in order to ensure that the number of each type of label contained in each batch of meta-training data is as balanced as possible, samples with each type of label are added to each batch of meta-training data, and then the number of samples of labels containing too many samples is reduced while ensuring that the reduction of samples does not affect the sample amount of other labels.
[0060] In some embodiments, after balancing the number of each type of label included in each batch of meta-training data, the sequence number of each word or wordpiece in the model vocabulary and the sequence number of the label corresponding to each word or wordpiece in all labels in the field are saved in the field data (domain_data), the sequence number of the sample in the meta-training data in the field data is saved in the meta data sequence number (meta_data_idx), and each batch of meta-training data is loaded through the domain_data and the meta_data_idx, wherein the annotation data set of each batch of meta-training data includes multiple samples, each sample includes multiple words or wordpieces, and each word or wordpiece has a label. In this embodiment, in order to speed up the loading speed of the meta-training data during training and reduce the memory required to load the meta-training data, each batch of meta-training data is loaded through the domain_data and the meta_data_idx, that is, the sequence number of each batch of meta-training data in the domain_data in the meta_data_idx is used to find the corresponding data in the domain_data to form each batch of meta-training data. The wordpiece model is a kind of Subword model, and the Subword model divides the granularity between words and characters, for example, "looking" can be divided into "look" and "ing" two wordpieces, and the divided "look" and "ing" can be used to construct other words, such as "look" and "ed" wordpieces can form the word "looked", so the Subword method can greatly reduce the size of the model vocabulary, and can better process similar words.
[0061] The embodiment of the present application also provides a named entity recognition method, Figure 3 is a flowchart of the named entity recognition method according to the embodiment of the present application, as Figure 3 shown, the named entity recognition method uses the named entity recognition model obtained by any one of the named entity recognition model training methods to perform named entity recognition, and the method includes the following steps:
[0062] Step S301, obtaining a prediction support set and a prediction query set of a target field, wherein the prediction support set is an annotated data set, and the prediction query set is an unannotated data set;
[0063] Step S302, inputting the prediction support set and the prediction query set into the named entity recognition model to obtain the predicted class label of the prediction query set sample.
[0064] Through the above steps S301 to S302, the purpose of using the named entity recognition model trained by the annotated samples of the similar field of the target field to recognize the unannotated samples in the target field is achieved.
[0065] It should be noted that the steps shown in the above flow or the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from here.
[0066] The embodiment also provides an electronic device including a memory and a processor, the memory storing a computer program, and the processor being configured to execute the computer program to perform the steps in any of the above method embodiments.
[0067] Optionally, the above electronic device can further include a transmission device connected with the processor and an input and output device connected with the processor.
[0068] It should be noted that the specific examples in the embodiment can refer to the examples described in the above embodiments and optional implementation manners, and the embodiment will not be described here.
[0069] In addition, in combination with the training method of the named entity recognition model and the named entity recognition method in the above embodiments, the embodiment of the application can provide a storage medium for implementation. The storage medium has a computer program stored thereon; the computer program is executed by a processor to implement any of the training method of the named entity recognition model and the named entity recognition method in the above embodiments.
[0070] In one embodiment, a computer device is provided, which can be a terminal. The computer device includes a processor, a memory, a network interface, a display screen and an input device connected through a system bus. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operating system and the computer program in the non-volatile storage medium to run. The network interface of the computer device is used to communicate with external terminals through network connection. The computer program is executed by the processor to implement a training method of a named entity recognition model and a named entity recognition method. The display screen of the computer device can be a liquid crystal display screen or an electronic ink display screen. The input device of the computer device can be a touch layer overlaid on the display screen, or a key, trackball or touchpad arranged on the shell of the computer device, or an external keyboard, touchpad or mouse, etc.
[0071] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer readable storage medium. When the computer program is executed, it can include the processes of the above-mentioned embodiment methods. Any reference to memory, storage, database or other medium used in the embodiments provided in the present application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration but not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDR SDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
[0072] Those skilled in the art should understand that each technical feature of the above-mentioned embodiments can be combined arbitrarily, and in order to make the description simple, not all possible combinations of each technical feature in the above-mentioned embodiments are described, however, as long as the combination of these technical features does not exist contradictory, it should be considered as the scope of the present application.
[0073] The above-mentioned embodiments only express several implementation manners of the present application, and the description is more specific and detailed, but it should not be understood as a limitation on the scope of the patent. It should be pointed out that for ordinary skilled in the art, without departing from the concept of the present application, a number of modifications and improvements can be made, which are all within the scope of the present application. Therefore, the scope of protection of the patent of the present application should be subject to the appended claims.
Claims
1. A method of training a named entity recognition model, wherein, The named entity recognition model comprises a BERT-CRF model, and the training method comprises the following steps: Obtain a training set, wherein the training set comprises multiple batches of meta training data, each batch of the meta training data comprises a training support set and a training query set, the training set is annotated samples of a target field and a similar field, and the number of labels of each type in each batch of the meta training data is balanced; Train the named entity recognition model using each batch of the meta training data, wherein each round of training comprises the following steps: inputting the training query set and the training support set into a BERT layer of a BERT-CRF model in the named entity recognition model, obtaining emission scores and transition scores of the training query set samples, inputting the emission scores and the transition scores of the training query set samples into a CRF layer of the BERT-CRF model in the named entity recognition model, obtaining a loss function of the named entity recognition model, and adjusting parameters of the named entity recognition model according to the loss function of the named entity recognition model, wherein the step of inputting the training query set and the training support set into the BERT layer of the BERT-CRF model in the named entity recognition model to obtain the transition scores of the training query set samples comprises the following steps: obtaining a label category transition matrix according to label categories in the training query set samples, adjusting the label category transition matrix according to loss back propagation in training, and obtaining the transition scores of the training query set samples according to the label category transition matrix, The method further comprises the following steps: saving a sequence number of each word or subword corresponding to a model vocabulary and a sequence number of a label corresponding to each word or subword in all labels in the field in field data, saving sequence numbers of samples in the meta training data in the field data in meta data sequence numbers, and loading each batch of the meta training data through the field data and the meta data sequence numbers.
2. The training method of claim 1, wherein, In each round of training, the training method further comprises the following steps: Obtain a test set, wherein the test set comprises a test support set and a test query set, and the test set is annotated samples of a target field; inputting the test support set and the test query set into the BERT layer of the BERT-CRF model in the named entity recognition model to obtain emission scores and transition scores of the test query set samples; inputting the emission scores and the transition scores of the test query set samples into the CRF layer of the BERT-CRF model in the named entity recognition model to obtain test category labels of the test query set samples; determining the accuracy of the test set according to the test category labels of the test query set samples and real category labels, stopping training if the accuracy of the test set is greater than or equal to a preset value, and continuing to train the named entity recognition model using the next batch of the meta training data if the accuracy of the test set is less than the preset value.
3. The training method of claim 1, wherein, The step of inputting the training query set and the training support set into the BERT layer of the BERT-CRF model in the named entity recognition model to obtain the emission scores of the training query set samples comprises the following steps: inputting the training query set and the training support set into a BERT layer of a BERT-CRF model to obtain a feature representation vector of the training support set sample and a feature representation vector of the training query set sample; obtaining a pre-defined anchor category feature representation vector, the anchor category feature representation vector being represented by a loss backpropagation adjustment vector, wherein the number of anchor category feature representation vectors is greater than or equal to the sum of the number of categories in the source domain and the target domain; obtaining a feature representation vector of each category label in the training support set according to the feature representation vector of the training support set sample, and performing singular value decomposition on the difference vector between the feature representation vector of each category label in the training support set and the anchor category feature representation vector to obtain a feature mapping function; calculating the similarity between the feature representation vector of the training query set sample and the anchor category feature representation vector according to the feature mapping function to obtain an emission score of the training query set sample.
4. The training method of claim 3, wherein, The obtaining of the feature representation vector of each category label in the training support set according to the feature representation vector of the training support set sample comprises: obtaining a feature representation vector of each word in each of the training support set samples according to the category label of each word in the training support set sample, and calculating the average value of the feature representation vectors of all words under each category as the feature representation vector of each category label in the training support set.
5. The training method of claim 2, wherein, Before the obtaining of the training set and the test set, the training method further comprises: obtaining a plurality of source domain annotation data sets of similar domains of the target domain according to the target domain, wherein the annotation data set of a single domain is a batch of meta-training data, and the number of each type of label contained in each batch of meta-training data is balanced, wherein the plurality of source domain annotation data sets are training sets, and the annotation data set of the target domain is a test set.
6. The training method of claim 5, wherein, After balancing the number of each type of label contained in each batch of meta-training data, the training method further comprises: The annotation data set of each batch of meta-training data comprises a plurality of samples, and each sample comprises a plurality of words or subwords, each of which has a label.
7. A method of named entity recognition, characterized by, The method adopts the named entity recognition model trained by the named entity recognition model training method of any one of claims 1 to 6 to perform named entity recognition, and the method comprises: obtaining a prediction support set and a prediction query set of the target domain, wherein the prediction support set is an annotated data set, and the prediction query set is an unannotated data set; inputting the prediction support set and the prediction query set into the named entity recognition model to obtain a predicted category label of the prediction query set sample. 8.An electronic device comprising a memory and a processor, the electronic device comprising: The memory stores a computer program, and the processor is configured to run the computer program to execute the steps of the method of any one of claims 1 to 7.
9. A storage medium, characterized by The storage medium stores a computer program, wherein the computer program is configured to execute the steps of the method of any one of claims 1 to 7 when running.
Citation Information
Patent Citations
Slot filling model training method and natural language understanding model
CN111898379A