Named entity recognition model training method, named entity recognition method and device

By constructing a global boundary smoothing matrix and combining a dual affine decoder with a contrastive learning optimization model, the problem of insufficient recognition accuracy in small sample named entity recognition methods is solved, and efficient named entity recognition under scarce data is achieved.

CN117556819BActive Publication Date: 2026-11-20SOUTH CHINA NORMAL UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311581281.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-11-24
Publication Date
2026-11-20
Estimated Expiration
2043-11-24

AI Technical Summary

Technical Problem

Existing named entity recognition methods with few samples are insufficient in terms of recognition accuracy, especially in specific domains, emerging languages ​​or rare entity types, where it is difficult to effectively utilize a small amount of labeled data for accurate recognition.

Method used

By constructing a global boundary smoothing matrix, the probability around the entity span is redistributed to alleviate the model's overconfidence problem. The entity span extractor and mention classifier in the named entity recognition model are trained using the boundary-smoothed training set. The model is then optimized by combining a dual affine decoder and contrastive learning.

Benefits of technology

It improves the accuracy and generalization ability of named entity recognition in small samples, enhances the model's calibration ability and trainability, and improves the recognition performance under scarce data.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117556819B_ABST
    Figure CN117556819B_ABST
Patent Text Reader

Abstract

The application discloses a named entity recognition model training method, a named entity recognition method and device. The training method comprises the following steps: constructing a training set, each example in the training set indicating a sentence, an entity span corresponding to the sentence and an entity type; assigning a preset proportion of probability in each entity span to entity spans around the entity span to obtain a global boundary smoothing matrix of the entity span; replacing each global boundary matrix in the training set with a global boundary smoothing matrix to obtain a boundary smoothed training set; and training an entity span extractor and a mention classifier in a named entity recognition model by using the boundary smoothed training set. The application improves the generalization ability of the model and improves the recognition accuracy of small sample named entities.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of entity recognition technology, and more specifically, to a named entity recognition model training method, named entity recognition method and apparatus. Background Technology

[0002] Named Entity Recognition (NER) is an important task in Natural Language Processing (NLP), which aims to identify words or phrases in text that have specific named entities and classify them into predefined categories, such as names of people, places, organizations, etc.

[0003] Typically, named entity recognition (NER) models require large-scale labeled data to accurately learn and capture patterns and regularities of various named entities in text. These models rely on a large number of text examples to understand the context, frequency of occurrence, and relationships between different entity categories and other words. However, in some cases, such as domain-specific, emerging languages, rare entity types, or privacy-restricted text data, obtaining sufficient labeled data can become difficult. Therefore, an attractive NER problem has been introduced, which involves identifying new categories of entities while relying on only a small number of labeled samples (i.e., support samples).

[0004] Few-shot Named Entity Recognition (Few-shot NER) is a variant of the named entity recognition task, characterized by performing named entity recognition with very limited training data. As an important task within named entity recognition, it has received increasing attention in recent years. Existing two-stage (span extraction and mention classification) Few-shot NER methods suffer from low recognition accuracy. Therefore, improving the recognition accuracy of Few-shot NER has become a pressing technical problem. Summary of the Invention

[0005] In view of this, this application provides a named entity recognition model training method, a named entity recognition method, and an apparatus to improve the accuracy of small sample entity recognition.

[0006] To achieve the above objectives, the first aspect of this application provides a method for training a named entity recognition model, comprising:

[0007] Construct a training set, wherein each example in the training set indicates a sentence, the entity span corresponding to the sentence, and the entity type;

[0008] The probability of each entity span is assigned to the entity spans surrounding the entity span by a predetermined proportion, thus obtaining the global boundary smoothing matrix of the entity span;

[0009] Replace each global boundary matrix in the training set with a global boundary smoothing matrix to obtain a training set with smoothed boundaries;

[0010] The entity span extractor and mention classifier in the named entity recognition model are trained using the training set after boundary smoothing.

[0011] Preferably, the process of constructing the training set includes:

[0012] The sequence labels in the dataset are converted into labeled entity spans, and the global boundary matrix of each entity span is obtained to obtain the training set, which is a pre-obtained dataset;

[0013] Each example in the training set includes a sentence with several language tokens, a set of entity spans for the sentence, and an entity type for each entity span.

[0014] Preferably, the process of assigning a predetermined proportion of the probability of each entity span to the entity spans surrounding the entity span to obtain the global boundary smoothing matrix of the entity span includes:

[0015] For each entity span:

[0016] Obtain the global boundary matrix of the entity span;

[0017] Based on a preset smoothing size, multiple extensional blocks in the vertical and horizontal directions of the global boundary matrix are determined;

[0018] The probability of a preset ratio is evenly distributed to each extension block, and the remaining probability is distributed to the global boundary matrix to obtain the global boundary smoothing matrix of the entity span.

[0019] Preferably, the process of training the entity span extractor in the named entity recognition model using the boundary-smoothed training set includes:

[0020] Utilize an encoder to obtain the contextual embedding representation of the sentence;

[0021] Based on the contextual embedding representation of the sentence, the scoring vector of each entity span in the sentence is obtained by using a dual affine decoder;

[0022] Each score vector is fed into the classifier to obtain the entity type prediction result for each entity span;

[0023] The parameters in the entity span extractor are optimized using cross-entropy loss.

[0024] The span of each sentence and each entity is derived from the training set after the boundary smoothing.

[0025] Preferably, the process of training the mention classifier in the named entity recognition model using the boundary-smoothed training set includes:

[0026] Based on the training set after boundary smoothing, obtain the prototype of each entity type;

[0027] The first target is defined as the entity span whose similarity score with the prototype of the first entity span is higher than the similarity score between the first entity span and the second entity span, wherein the entity type of the second entity span is different from the entity type of the first entity span.

[0028] The second objective is defined as the entity type of the first entity span being higher than that of the second entity span being higher than that of the third entity span. Specifically, the entity type of the first entity span is the same as that of the second entity span, and the entity type of the first entity span is different from that of the third entity span.

[0029] Using the first target and the second target as training objectives, the mention classifier in the named entity recognition model is trained.

[0030] Preferably, the first objective is represented as:

[0031]

[0032] in, Belonging to entity types t and c t c is the prototype of entity type t. t′ Let N be the prototype of entity type t′, where N represents the total number of entity types and K represents the total number of entity spans.

[0033] The second objective is expressed as:

[0034]

[0035] For entity span pairs with the same entity type, For entity span pairs with different entity types.

[0036] A second aspect of this application provides a named entity recognition method, comprising:

[0037] Obtain the text to be recognized;

[0038] The text to be identified is input into the trained few-sample named entity recognition FNER model to obtain the recognition result output by the FNER model, and the recognition result contains each named entity in the text to be identified;

[0039] The FNER model was trained using the aforementioned named entity recognition model training method.

[0040] A third aspect of this application provides a named entity recognition model training device, comprising:

[0041] A dataset construction unit is used to construct a training set, wherein each example in the training set indicates a sentence, the entity span corresponding to the sentence, and the entity type;

[0042] A boundary smoothing unit is used to assign a preset proportion of the probability in each entity span to the entity spans around the entity span, thereby obtaining a global boundary smoothing matrix for the entity span.

[0043] The training set construction unit is used to replace each global boundary matrix in the training set with a global boundary smoothing matrix to obtain a boundary-smoothed training set.

[0044] The model training unit is used to train the entity span extractor and mention classifier in the named entity recognition model using the boundary-smoothed training set.

[0045] The fourth aspect of this application provides a named entity recognition model training device, including: a memory and a processor;

[0046] The memory is used to store programs;

[0047] The processor is used to execute the program to implement each step of the named entity recognition model training method described above.

[0048] The fifth aspect of this application provides a storage medium having a computer program stored thereon, which, when executed by a processor, implements the various steps of the named entity recognition model training method described above.

[0049] As described in the above technical solution, this application first constructs a training set, where each example in the training set indicates a sentence, the corresponding entity span, and the entity type. Then, a predetermined proportion of the probability in each entity span is assigned to the entity spans surrounding it, resulting in a global boundary smoothing matrix for the entity span. It should be noted that in the training set, each labeled entity span is assigned the full probability, while unlabeled spans are assigned zero probability; that is, the boundary of each labeled entity span is a hard boundary. Because this creates a clear boundary between the classification targets of adjacent spans, the model is prone to overconfidence. In practical applications, the boundaries of entity spans may be ambiguous and inconsistent; therefore, spans surrounding labeled entity spans should have a small probability of becoming entity spans. This application, by explicitly assigning probabilities to surrounding spans, prevents the model from concentrating all probability quality on scarce positive samples through boundary smoothing. Next, each global boundary matrix in the training set is replaced with a global boundary smoothing matrix to obtain a boundary-smoothed training set. Finally, the entity span extractor and mention classifier in the named entity recognition model are trained using the smoothed training set. This application uses a global boundary matrix for smoothing, preventing the model from concentrating all probability quality on scarce positive samples. This helps alleviate overconfidence, improves the model's generalization ability, and enhances the recognition accuracy of named entities in small samples. Attached Figure Description

[0050] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of this application. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.

[0051] Figure 1 This is a schematic diagram of the named entity recognition model training method disclosed in the embodiments of this application;

[0052] Figure 2 This application illustrates a smoothing method for the global boundary matrix disclosed in its embodiments;

[0053] Figure 3 This application illustrates a few-sample named entity recognition model disclosed in its embodiments;

[0054] Figure 4 This is a schematic diagram of the named entity recognition method disclosed in the embodiments of this application;

[0055] Figure 5 This is a schematic diagram of the named entity recognition model training device disclosed in the embodiments of this application;

[0056] Figure 6 This is a schematic diagram of the named entity recognition model training device disclosed in the embodiments of this application. Detailed Implementation

[0057] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0058] Terminology Explanation:

[0059] Meta-learning is a machine learning method designed to enable machine learning algorithms to better learn new tasks or domains without requiring large amounts of training data. The core idea of ​​meta-learning is to teach models how to learn so that they can quickly adapt and generalize when faced with new tasks.

[0060] Entity span: A continuous sequence of characters in text that represents a named entity. It is typically used to identify and locate named entities in text, such as names of people, places, and organizations. The starting and ending characters of the entity span together define the position of the named entity in the text.

[0061] Global Boundary Matrix: Used to record information about entity boundaries. Typically, the rows of this matrix represent possible starting positions of entities, and the columns represent possible ending positions. The values ​​in the matrix indicate whether a valid entity boundary exists between these two positions. If it is a valid entity boundary, the corresponding value is usually 1; otherwise, it is 0. This helps the model determine the specific boundary locations of entities, especially when dealing with situations where multiple entity boundaries may overlap.

[0062] Biaffine Decoder: A neural network architecture commonly used in syntactic analysis tasks in natural language processing, especially dependency parsing. It calculates dependency probability scores between each word and other words. By comparing these probability scores, the model can determine whether a candidate entity span constitutes a valid entity boundary.

[0063] Prototypical Networks: The core idea is to classify by learning a prototype for each category. In few-shot classification tasks, typically only a small number of training samples are available for each category. Prototypical networks determine which category a test sample belongs to by calculating a prototype for each category and comparing each sample to these prototypes.

[0064] Contrastive learning is a self-supervised learning method that aims to teach models useful representations from data, making the differences between different samples more obvious and the differences between the same samples smaller. The goal of contrastive learning is to form discriminative features in the representation space by bringing similar samples closer together and separating dissimilar samples.

[0065] The inventors of this application discovered that in existing entity span-based models, the labeled boundaries are considered absolutely reliable; that is, each labeled entity span is assigned the full probability of an entity, while unlabeled entity spans are assigned zero probability. This probability allocation is called a hard boundary. It creates a clear boundary between the classification targets of adjacent entity spans, thus affecting the trainability of the neural network. Simultaneously, these models are prone to overconfidence, where the confidence level of predicted entities is much higher than their correct probability. To address this problem, this application applies boundary smoothing to the labeled global boundary matrix. By explicitly redistributing entity probabilities from labeled spans to surrounding spans, it effectively alleviates the overconfidence problem, thereby improving the model's calibration ability. Furthermore, it provides more continuous targets between spans, resulting in a flatter minimum and a smoother loss curve, which is generally associated with better generalization and trainability.

[0066] The following describes the named entity recognition model training method provided in the embodiments of this application. Please refer to... Figure 1 The named entity recognition model training method provided in this application embodiment may include the following steps:

[0067] Step S101: Construct the training set.

[0068] Each example in the training set indicates a sentence, the corresponding entity span, and the entity type. Specifically, the training set D... train It can be divided into support set S train Query set Q train and entity type set T rain :

[0069] E train =(S train Q train ,T train )∈D train

[0070] Among them, E train Represents the training set data, |T train | = N. For each example in the support set and query set, it can be represented as:

[0071] (X,M,Y)∈S train ∪Q train

[0072] in, This represents a sentence with L language tokens. Let s represent the set of entity spans of a sentence. j and e j Let s represent the start and end positions of the j-th entity span in the sentence, respectively, satisfying 0 ≤ s j ≤e j ≤L, where L′ represents the number of entity spans. Represents a collection of entity types, y j ∈T train Represents the span (s) of the j-th entity. j ,e j The label is used to represent the example (X,M,Y)∈S. Generally, support examples (X,M,Y)∈S are used. train To train the model, use query examples (X,M,Y)∈Q train To validate the model.

[0073] Step S102: Assign a predetermined proportion of the probability in each entity span to the entity spans surrounding the entity span to obtain the global boundary smoothing matrix of the entity span.

[0074] For example, Figure 2 (a) Visualized the true label y of an example sentence ij The hard-bound version contains three annotated entities, valid candidate spans cover the upper triangular region of the matrix, each annotated span is assigned a full probability of becoming an entity, and all unannotated spans are assigned a zero probability. Figure 2 (b) Visualized y ij The boundary-smooth version (i.e.) Specifically, for an annotated entity, a portion of the probability ∈ is assigned to the span around it, and the remaining probability 1-∈ is assigned to the span of the original annotation.

[0075] Step S103: Replace each global boundary matrix in the training set with a global boundary smoothing matrix to obtain a training set with smoothed boundaries.

[0076] Step S104: Use the smoothed training set to train the entity span extractor and mention classifier in the named entity recognition model.

[0077] Figure 3 This paper illustrates the few-shot named entity recognition model used in this application, which includes an entity span extractor and a mention classifier. It employs BERT as the encoder and Biaffine Decoder as the decoder to smooth the global boundary matrix and generate a global smooth boundary matrix. It also optimizes the mention classifier through in-depth contrastive learning.

[0078] The named entity recognition model used in this application is the Few-shot Named Entity Recognition (Few-shot NER) model. Its main feature is that it uses a two-stage few-shot named entity recognition method to perform named entity recognition under very limited training data. The two stages include entity span extraction and mention type classification.

[0079] This application first constructs a training set, where each example in the training set indicates a sentence, the corresponding entity span, and the entity type. Then, a predetermined proportion of the probability in each entity span is assigned to the entity spans surrounding it, resulting in a global boundary smoothing matrix for the entity span. It should be noted that in the training set, each labeled entity span is assigned the full probability, while unlabeled spans are assigned zero probability; that is, the boundary of each labeled entity span is a hard boundary. Because this creates a clear boundary between the classification targets of adjacent spans, the model is prone to overconfidence. In practical applications, the boundaries of entity spans may be ambiguous and inconsistent; therefore, spans surrounding labeled entity spans should have a small probability of becoming entity spans. This application, by explicitly assigning probabilities to surrounding spans, prevents the model from concentrating all probability quality on scarce positive samples through boundary smoothing. Next, each global boundary matrix in the training set is replaced with a global boundary smoothing matrix to obtain a boundary-smoothed training set. Finally, the entity span extractor and mention classifier in the named entity recognition model are trained using the smoothed training set. This application uses a global boundary matrix for smoothing, preventing the model from concentrating all probability quality on scarce positive samples. This helps alleviate overconfidence, improves the model's generalization ability, and enhances the recognition accuracy of named entities in small samples.

[0080] In some embodiments of this application, the process of constructing the training set in step S101 may include:

[0081] The sequence labels in the dataset are converted into labeled entity spans, and the global boundary matrix of each entity span is obtained to obtain the training set.

[0082] It is understood that the dataset is obtained in advance; each example in the training set includes a sentence with several language tokens, a set of entity spans of the sentence, and an entity type for each entity span.

[0083] In some embodiments of this application, step S102, which assigns a predetermined proportion of the probability of each entity span to the entity spans surrounding the entity span to obtain the global boundary smoothing matrix of the entity span, may include:

[0084] For each entity span:

[0085] S1, obtain the global boundary matrix of the entity span.

[0086] S2, based on a preset smoothing size, determines multiple extensional blocks in the vertical and horizontal directions of the global boundary matrix.

[0087] S3, the probability of the preset ratio is evenly distributed to each extension block, and the remaining probability is distributed to the global boundary matrix to obtain the global boundary smoothing matrix of the entity span.

[0088] For example, for an annotated entity, a portion of the probability ∈ is assigned to the spans surrounding it, and the remaining probability 1-∈ is assigned to the original annotation span. Using a preset smoothing size D, all spans equal to the Manhattan distance d (d≤D) to the annotated entity share the probability ∈ / D equally. After the entity probability redistribution, any remaining probability of the span is assigned as "non-entity," which can be called the smoothing boundary.

[0089] In some embodiments of this application, step S104, which involves training the entity span extractor in the named entity recognition model using the boundary-smoothed training set, may include:

[0090] S1, use the encoder to obtain the contextual embedding representation of the sentence.

[0091] Specifically, through H = F(X) s ) Obtain the context embedding of the sentence, where F(·) denotes the encoder, for example, the encoder could be BERT, H∈R L×h This is the output representation of the last layer of the encoder, where h represents the embedding size. For X s Each token x in i ∈X s Token embedding can be represented as h i ∈R h .

[0092] S2, based on the contextual embedding representation of the sentence, utilizes the score vector of each entity span in the sentence using a dual affine decoder.

[0093] Specifically, H is represented by two affine networks, resulting in two representations: H s ∈R L×h and H e ∈R L×h These correspond to the start and end positions of the span, respectively. For N entity types (including one "non-entity" type), the span from the i-th token to the j-th token can be used to calculate a scoring vector r. ij ∈R N as follows:

[0094]

[0095] in It is a (ji)-width embedding from a dedicated learnable matrix; U∈R h×N×h , b∈R N These are learnable parameters.

[0096] S3 feeds each score vector into the classifier to obtain the entity type prediction result for each entity span.

[0097] For example, r can be ij Feed to the softmax layer:

[0098]

[0099] It generates predicted probabilities for all entity types.

[0100] S4 utilizes cross-entropy loss to optimize the parameters in the entity span extractor.

[0101] According to the marked span M s and the entity type Y s Generate a global boundary matrix y for each example, and a ground truth label y'. ij ∈R N It is a one-hot encoded vector; the value is 1 if the index corresponds to an annotated entity type, and 0 otherwise. After smoothing the global boundary matrix, the resulting labels are... Similarly, It is a one-hot encoded vector.

[0102] Therefore, the model is optimized using boundary smoothing regularized cross-entropy loss for each training example:

[0103]

[0104] For Q train Each query example in (X) q Mq ,Y q This process yields the global boundary smoothing matrix y′ predicted by the span extractor. First, spans predicted as "non-entity" are discarded. Then, the remaining spans are ranked according to their prediction confidence. Spans with lower confidence are also discarded if they conflict with the boundaries of spans with higher confidence. Finally, candidate spans with confidence levels above a predefined threshold θ are selected. This is represented as the prediction result.

[0105] Existing entity prototype networks only focus on the relationship between entities and prototypes, ignoring the relationship between entities themselves, and do not consider using contrastive learning to train prototype vectors. This results in the learned prototype vectors not being reliable as class prototypes. Intuitively, two goals need to be achieved through optimization: (1) For entity-entity pairs, pairs of the same class should obtain a higher similarity score than pairs of different classes. (2) For entity-prototype pairs, prototype c t The similarity score between entities of class t and class t should be higher than that of class c. t Similarity score between the entity and other entities.

[0106] Based on this, in some embodiments of this application, step S104, which uses the boundary-smoothed training set to train the mention classifier in the named entity recognition model, may include:

[0107] S1, Based on the training set after boundary smoothing, obtain the prototype of each entity type.

[0108] Specifically, for a given training set of data E train =(S train Q train ,T train ), can be achieved by analyzing S train All entities of the same type t∈T train The span is represented by an average to calculate the prototype c for each category. t ∈R N In terms of form:

[0109]

[0110] in,

[0111]

[0112] K t Indicates the number of spans for entity type t. v j ∈R N Represents the entity span. It is an indicator function. To measure the similarity between entity spans, the cosine similarity function S(·) is used, where,

[0113]

[0114] S2, the first target is defined as the entity span whose similarity score with the prototype of the first entity span is higher than the similarity score between the first entity span and the second entity span.

[0115] The entity type of the second entity span is different from that of the first entity span.

[0116] It should be noted that during the training phase, each query sentence X q In Q train The marked span set M q and the corresponding type set Y q It is visible. Therefore, the contrastive learning loss for all query sentences can be calculated.

[0117] For example, the entity-prototype loss function (first objective) can be defined as follows:

[0118]

[0119] in, Belonging to entity types t and c t c is the prototype of entity type t. t′ Let N be the prototype of entity type t′, N represent the total number of entity types, and K represent the total number of entity spans.

[0120] S3, the second objective is defined as the entity span with the similarity score between the first entity span and the second entity span being higher than the entity span with the third entity span.

[0121] Among them, the entity type of the first entity span is the same as that of the second entity span, and the entity type of the first entity span is different from that of the third entity span.

[0122] For example, the objective (second objective) for entity-entity interaction can be defined as follows:

[0123]

[0124] For entity span pairs with the same entity type, For entity span pairs with different entity types.

[0125] S4, using the first target and the second target as training targets, train the mention classifier in the named entity recognition model.

[0126] Specifically, combining entity-entity loss and entity-prototype loss, the final training objective can be expressed as:

[0127] L = L entity +L proto

[0128] The above embodiments utilize contrastive learning to adjust the span representation in the semantic space. By incorporating a contrastive loss function between entities, it can cluster entities of the same type and separate entities of different types, thereby improving the representational similarity problem between entities. By incorporating a contrastive loss function between entities and their prototypes, it can make the prototype the center of the class, thus improving the accuracy of mention classification.

[0129] During model evaluation, given an evaluation set of data E eval =(S eval Q eval ,T eval )∈D eval First, based on the support set S eval Calculate the prototype representation. Then, for Q... eval For each query sentence, a span extractor can be used to extract all candidate spans. During the classification phase, the same metric is followed: the similarity score between the extracted entity span and the prototype is calculated, and the category with the highest probability score is selected as the prediction result. The probability scores for category t are as follows:

[0130]

[0131] Then, the argmax function is used for prediction:

[0132]

[0133] Based on the named entity recognition model training methods provided in the above embodiments, the trained model can ultimately be used for named entity recognition. Specifically, as shown in the example... Figure 4 As shown in the embodiments of this application, a named entity recognition method is provided, which may include:

[0134] Step S201: Obtain the text to be recognized.

[0135] Step S202: Input the text to be recognized into the trained FNER model to obtain the recognition result output by the FNER model.

[0136] The recognition result includes each named entity in the text to be recognized. The FNER model is trained using the named entity recognition model training method provided in any of the foregoing embodiments.

[0137] The named entity recognition model training apparatus provided in the embodiments of this application is described below. The named entity recognition model training apparatus described below can be referred to in correspondence with the named entity recognition model training method described above.

[0138] Please see Figure 5 The named entity recognition model training apparatus provided in this application embodiment may include:

[0139] Dataset construction unit 21 is used to construct a training set, wherein each example in the training set indicates a sentence, the entity span corresponding to the sentence, and the entity type;

[0140] Boundary smoothing unit 22 is used to assign a preset proportion of the probability in each entity span to the entity spans around the entity span, so as to obtain the global boundary smoothing matrix of the entity span;

[0141] Training set construction unit 23 is used to replace each global boundary matrix in the training set with a global boundary smoothing matrix to obtain a boundary smoothed training set;

[0142] Model training unit 24 is used to train the entity span extractor and mention classifier in the named entity recognition model using the boundary-smoothed training set.

[0143] In some embodiments of this application, the process of constructing the training set by the dataset construction unit 21 may include:

[0144] The sequence labels in the dataset are converted into labeled entity spans, and the global boundary matrix of each entity span is obtained to obtain the training set, which is a pre-obtained dataset;

[0145] Each example in the training set includes a sentence with several language tokens, a set of entity spans for the sentence, and an entity type for each entity span.

[0146] In some embodiments of this application, the process by which the boundary smoothing unit 22 assigns a preset proportion of the probability in each entity span to the entity spans surrounding the entity span, thereby obtaining a global boundary smoothing matrix for the entity span, may include:

[0147] For each entity span:

[0148] Obtain the global boundary matrix of the entity span;

[0149] Based on a preset smoothing size, multiple extensional blocks in the vertical and horizontal directions of the global boundary matrix are determined;

[0150] The probability of a preset ratio is evenly distributed to each extension block, and the remaining probability is distributed to the global boundary matrix to obtain the global boundary smoothing matrix of the entity span.

[0151] In some embodiments of this application, the process by which the model training unit 24 trains the entity span extractor in the named entity recognition model using the boundary-smoothed training set may include:

[0152] Utilize an encoder to obtain the contextual embedding representation of the sentence;

[0153] Based on the contextual embedding representation of the sentence, the scoring vector of each entity span in the sentence is obtained by using a dual affine decoder;

[0154] Each score vector is fed into the classifier to obtain the entity type prediction result for each entity span;

[0155] The parameters in the entity span extractor are optimized using cross-entropy loss.

[0156] The span of each sentence and each entity is derived from the training set after the boundary smoothing.

[0157] In some embodiments of this application, the process by which the model training unit 24 trains the mention classifier in the named entity recognition model using the boundary-smoothed training set may include:

[0158] Based on the training set after boundary smoothing, obtain the prototype of each entity type;

[0159] The first target is defined as the entity span whose similarity score with the prototype of the first entity span is higher than the similarity score between the first entity span and the second entity span, wherein the entity type of the second entity span is different from the entity type of the first entity span.

[0160] The second objective is defined as the entity type of the first entity span being higher than that of the second entity span being higher than that of the third entity span. Specifically, the entity type of the first entity span is the same as that of the second entity span, and the entity type of the first entity span is different from that of the third entity span.

[0161] Using the first target and the second target as training objectives, the mention classifier in the named entity recognition model is trained.

[0162] In some embodiments of this application, the first objective is represented as:

[0163]

[0164] in, Belonging to entity types t and c tc is the prototype of entity type t. t′ Let N be the prototype of entity type t′, where N represents the total number of entity types and K represents the total number of entity spans.

[0165] The second objective is expressed as:

[0166]

[0167] For entity span pairs with the same entity type, For entity span pairs with different entity types.

[0168] The named entity recognition model training device provided in this application embodiment can be applied to named entity recognition model training devices, such as computers. Optionally, Figure 6 The hardware structure block diagram of the named entity recognition model training device is shown below. Figure 6 The hardware structure of the named entity recognition model training device may include: at least one processor 31, at least one communication interface 32, at least one memory 33 and at least one communication bus 34.

[0169] In this embodiment, the number of processor 31, communication interface 32, memory 33 and communication bus 34 is at least one, and processor 31, communication interface 32 and memory 33 communicate with each other through communication bus 34;

[0170] The processor 31 may be a central processing unit (CPU), an application-specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of this application.

[0171] The memory 33 may include high-speed RAM, and may also include non-volatile memory, such as at least one disk storage device;

[0172] The memory 33 stores a program, and the processor 31 can call the program stored in the memory 33. The program is used for:

[0173] Construct a training set, wherein each example in the training set indicates a sentence, the entity span corresponding to the sentence, and the entity type;

[0174] The probability of each entity span is assigned to the entity spans surrounding the entity span by a predetermined proportion, thus obtaining the global boundary smoothing matrix of the entity span;

[0175] Replace each global boundary matrix in the training set with a global boundary smoothing matrix to obtain a training set with smoothed boundaries;

[0176] The entity span extractor and mention classifier in the named entity recognition model are trained using the training set after boundary smoothing.

[0177] Optionally, the refined and extended functions of the program can be found in the description above.

[0178] This application embodiment also provides a storage medium that can store a program suitable for execution by a processor, the program being used for:

[0179] Construct a training set, wherein each example in the training set indicates a sentence, the entity span corresponding to the sentence, and the entity type;

[0180] The probability of each entity span is assigned to the entity spans surrounding the entity span by a predetermined proportion, thus obtaining the global boundary smoothing matrix of the entity span;

[0181] Replace each global boundary matrix in the training set with a global boundary smoothing matrix to obtain a training set with smoothed boundaries;

[0182] The entity span extractor and mention classifier in the named entity recognition model are trained using the training set after boundary smoothing.

[0183] Optionally, the refined and extended functions of the program can be found in the description above.

[0184] In summary:

[0185] This application first constructs a training set, where each example in the training set indicates a sentence, the corresponding entity span, and the entity type. Then, a predetermined proportion of the probability in each entity span is assigned to the entity spans surrounding it, resulting in a global boundary smoothing matrix for the entity span. It should be noted that in the training set, each labeled entity span is assigned the full probability, while unlabeled spans are assigned zero probability; that is, the boundary of each labeled entity span is a hard boundary. Because this creates a clear boundary between the classification targets of adjacent spans, the model is prone to overconfidence. In practical applications, the boundaries of entity spans may be ambiguous and inconsistent; therefore, spans surrounding labeled entity spans should have a small probability of becoming entity spans. This application, by explicitly assigning probabilities to surrounding spans, prevents the model from concentrating all probability quality on scarce positive samples through boundary smoothing. Next, each global boundary matrix in the training set is replaced with a global boundary smoothing matrix to obtain a boundary-smoothed training set. Finally, the entity span extractor and mention classifier in the named entity recognition model are trained using the smoothed training set. This application uses a global boundary matrix for smoothing, preventing the model from concentrating all probability quality on scarce positive samples, thus mitigating overconfidence and improving the model's generalization ability while enhancing the recognition accuracy of named entities with few samples. Furthermore, this application utilizes contrastive learning to adjust the span representation in the semantic space. By incorporating a contrastive loss function between entities, it can cluster entities of the same type and separate entities of different types, thereby improving the representational similarity problem between entities. By incorporating a contrastive loss function between entities and their prototypes, it can make the prototype the center of the class, thereby improving mention classification accuracy.

[0186] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0187] The various embodiments in this specification are described in a progressive manner. Each embodiment focuses on the differences from other embodiments. The various embodiments can be combined as needed, and the same or similar parts can be referred to each other.

[0188] The above description of the disclosed embodiments enables those skilled in the art to make or use this application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of this application. Therefore, this application is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A method for training a named entity recognition model, characterized in that, include: Construct a training set, wherein each example in the training set indicates a sentence, the entity span corresponding to the sentence, and the entity type; The probability of each entity span is assigned to the entity spans surrounding the entity span by a predetermined proportion, thus obtaining the global boundary smoothing matrix of the entity span; Replace each global boundary matrix in the training set with a global boundary smoothing matrix to obtain a training set with smoothed boundaries; The entity span extractor and mention classifier in the named entity recognition model are trained using the boundary-smoothed training set. The process of training the mention classifier in the named entity recognition model using the boundary-smoothed training set includes: Based on the training set after boundary smoothing, obtain the prototype of each entity type; The first target is defined as the entity span whose similarity score with the prototype of the first entity span is higher than the similarity score between the first entity span and the second entity span, wherein the entity type of the second entity span is different from the entity type of the first entity span. The second objective is defined as the entity type of the first entity span being higher than that of the second entity span being higher than that of the third entity span. Specifically, the entity type of the first entity span is the same as that of the second entity span, and the entity type of the first entity span is different from that of the third entity span. Using the first target and the second target as training objectives, the mention classifier in the named entity recognition model is trained.

2. The method according to claim 1, characterized in that, The process of constructing the training set includes: The sequence labels in the dataset are converted into labeled entity spans, and the global boundary matrix of each entity span is obtained to obtain the training set, which is a pre-obtained dataset; Each example in the training set includes a sentence with several language tokens, a set of entity spans for the sentence, and an entity type for each entity span.

3. The method according to claim 1, characterized in that, The process of assigning a predetermined proportion of the probability of each entity span to the entity spans surrounding it, thereby obtaining the global boundary smoothing matrix of the entity span, includes: For each entity span: Obtain the global boundary matrix of the entity span; Based on a preset smoothing size, multiple extensional blocks in the vertical and horizontal directions of the global boundary matrix are determined; The probability of a preset ratio is evenly distributed to each extension block, and the remaining probability is distributed to the global boundary matrix to obtain the global boundary smoothing matrix of the entity span.

4. The method according to claim 1, characterized in that, The process of training the entity span extractor in the named entity recognition model using the boundary-smoothed training set includes: Utilize an encoder to obtain the contextual embedding representation of the sentence; Based on the contextual embedding representation of the sentence, the scoring vector of each entity span in the sentence is obtained by using a dual affine decoder; Each score vector is fed into the classifier to obtain the entity type prediction result for each entity span; The parameters in the entity span extractor are optimized using cross-entropy loss. The span of each sentence and each entity is derived from the training set after the boundary smoothing.

5. The method according to claim 1, characterized in that, The first objective is represented as: in, Belongs to entity type , For entity type The prototype, For entity type The prototype, Indicates the total number of entity types. Indicates the total span of the entity; The second objective is expressed as: For entity span pairs with the same entity type, For entity span pairs with different entity types.

6. A named entity recognition method, characterized in that, include: Obtain the text to be recognized; The text to be identified is input into the trained few-sample named entity recognition FNER model to obtain the recognition result output by the FNER model, and the recognition result contains each named entity in the text to be identified; The FNER model is trained using the named entity recognition model training method described in any one of claims 1 to 5.

7. A named entity recognition model training device, characterized in that, include: A dataset construction unit is used to construct a training set, wherein each example in the training set indicates a sentence, the entity span corresponding to the sentence, and the entity type; A boundary smoothing unit is used to assign a preset proportion of the probability in each entity span to the entity spans around the entity span, thereby obtaining a global boundary smoothing matrix for the entity span. The training set construction unit is used to replace each global boundary matrix in the training set with a global boundary smoothing matrix to obtain a boundary-smoothed training set. The model training unit is used to train the entity span extractor and mention classifier in the named entity recognition model using the boundary-smoothed training set. The process by which the model training unit trains the mention classifier in the named entity recognition model using the boundary-smoothed training set includes: Based on the training set after boundary smoothing, obtain the prototype of each entity type; The first target is defined as the entity span whose similarity score with the prototype of the first entity span is higher than the similarity score between the first entity span and the second entity span, wherein the entity type of the second entity span is different from the entity type of the first entity span. The second objective is defined as the entity type of the first entity span being higher than that of the second entity span being higher than that of the third entity span. Specifically, the entity type of the first entity span is the same as that of the second entity span, and the entity type of the first entity span is different from that of the third entity span. Using the first target and the second target as training objectives, the mention classifier in the named entity recognition model is trained.

8. A named entity recognition model training device, characterized in that, include: Memory and processor; The memory is used to store programs; The processor is used to execute the program to implement each step of the named entity recognition model training method as described in any one of claims 1 to 5.

9. A storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements each step of the named entity recognition model training method as described in any one of claims 1 to 5.