A small sample named entity recognition method based on metric learning
Through a small-sample named entity recognition method based on metric learning, combined with entity type mapping and a custom attention mechanism, the problem of low efficiency and poor reliability of small-sample recognition in the existing technology is solved, and a more refined similarity measurement and better Semantic understanding improves recognition performance and adaptability.
Patent Information
- Application Number
- CN202410977148.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-22
- Publication Date
- 2024-10-01
- Estimated Expiration
- 2044-07-22
AI Technical Summary
Existing small-sample named entity recognition methods are inefficient and unreliable. Especially when facing diverse text data, they cannot fully capture the subtle differences between tokens and lack complex processing of entity types and contextual relationships, which affects the generalization ability of the model.
A small-sample named entity recognition method based on metric learning is used to dynamically integrate entity and type information by constructing a mapping from entity type to entity. It combines a custom attention mechanism and dot product similarity to build a multi-level similarity matrix and optimize the model. Understanding of tag semantics and textual context.
It improves the model's entity recognition performance under small sample conditions, enhances its ability to process complex semantics, improves recognition accuracy and reliability, and adapts to different context environments.
Smart Images

Figure CN118536509B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence technology, and in particular to a small sample named entity recognition method based on metric learning. Background Art
[0002] Named Entity Recognition (NER) is a key task in natural language processing, which aims to extract entity spans from unstructured text and classify them into predefined categories, such as locations, names, organizations, etc. With the development of pre-trained language models, NER research has made significant progress by adding specific classification heads to the models and fine-tuning them. However, although this method is effective, it relies heavily on high-quality annotated data, which is expensive and time-consuming to obtain. Therefore, small-sample NER methods that allow models to effectively learn by observing only a few samples in each category have attracted widespread research interest in the industry.
[0003] In recent years, prompt-based learning methods have become an important research direction in the field of natural language processing, especially in small sample learning tasks, which have shown significant advantages. This method enables pre-trained language models to better understand and perform downstream tasks. However, some current prompt methods have high complexity in the design of prompts and the process of text generation when faced with a large number of entity types. In addition, the prompt design in these methods often ignores the complex relationship between entity types and their related contexts, and lacks the support of specific examples. It is difficult for the model to establish a clear semantic association between labels and entities, which further affects its ability to handle complex semantic scenarios and reduces the difficulty of entity recognition.
[0004] Compared with the prompt learning method, the metric learning-based method shows more significant potential in small sample learning. Currently, most metric learning methods use non-parametric and single similarity measurement functions, such as dot product similarity, Euclidean distance, cosine similarity, etc. These methods often fail to fully capture the subtle differences between tokens when dealing with complex entity recognition tasks, especially in diverse text data. In addition, non-parametric similarity metrics often cannot dynamically adjust the distance metric based on the context of the entity or the semantic relationship between entities. These limitations may weaken the model's generalization ability when dealing with unseen entity types.
[0005] Therefore, there is an urgent need for a method that can improve the accuracy and reliability of text classification under small sample conditions. Summary of the invention
[0006] The present application provides a small sample named entity recognition method based on metric learning, which solves the technical problems of low efficiency and poor reliability of existing small sample learning methods.
[0007] According to a first aspect of the present application, a small sample named entity recognition method based on metric learning is provided, comprising the following steps:
[0008] Acquire corpus data, construct a corpus data training set and a test set, and construct a mapping from entity type to entity based on the training set;
[0009] The training set is divided into a training support set and a training query set, and entity-guided mask prompts are constructed on the training support set and the training query set respectively based on the mapping to obtain a training support set enhanced sequence and a training query set enhanced sequence;
[0010] Using a pre-trained language model to encode the training support set enhanced sequence and the training query set enhanced sequence constructed with entity-guided mask prompts, to obtain a training support set token encoding and a training query set token encoding;
[0011] The acquisition process of the training support set token code and the training query set token code is as follows: inputting the training support set entity type integration prompt enhancement sequence and the training support set type instance guidance prompt enhancement sequence into the model for processing to obtain the training support set output result, using a mask vector to encode the training support set output result and performing weighted processing to obtain the training support set token code; inputting the training query set enhancement sequence into the model for processing to obtain the training query set output result, using a mask vector to encode the training query set output result, and obtaining the training query set token code;
[0012] Calculate the similarity between the training support set token encoding and the training query set token encoding, construct a similarity matrix for similarity analysis, obtain a similarity score, calculate a loss function based on the similarity score, and obtain the pre-trained language model after training;
[0013] The test set is divided into a test support set and a test query set, and the test support set and the test query set data are input into the trained pre-trained language model for processing to perform entity type prediction.
[0014] According to the above aspects and any possible implementation manner, an implementation manner is further provided, wherein the process of constructing a mapping from entity type to entity according to the training set is:
[0015] A frequency function is constructed, and the occurrence frequency of entities under each entity type in the training set is traversed according to the frequency function; a mapping function is constructed, and the entity with the highest frequency under the entity type is used as the mapping value of the entity type.
[0016] According to the above aspects and any possible implementation manner, an implementation manner is further provided, wherein the process of constructing entity-guided mask prompts on the training support set and the training query set respectively based on the mapping to obtain a training support set enhanced sequence and a training query set enhanced sequence is:
[0017] Constructing entity type integration prompts and type instance guidance prompts for the training support set data respectively, obtaining a training support set entity type integration prompt enhancement sequence and a training support set type instance guidance prompt enhancement sequence, and then obtaining a training support set enhancement sequence;
[0018] A type instance guidance prompt is constructed for the training query set to obtain an enhanced sequence of the training query set.
[0019] According to the above aspects and any possible implementation, an implementation is further provided, wherein the process of constructing the entity type integration prompt is as follows:
[0020] Obtain a word sequence and a corresponding label sequence in the training support set, and traverse the label sequence to obtain non-'O' entity type data;
[0021] Mark the word corresponding to the non-'O' entity type data as an entity, and record the entity type corresponding to the entity, construct a terminal prompt string according to the entity and the entity type, and splice the terminal prompt string to the end of the word sequence to obtain a preliminary enhanced sequence;
[0022] Based on the mapping, the entity with the highest frequency of correlation with the entity type is obtained as the mapping entity, and a front-end prompt string is constructed according to the entity type and the mapping entity. The front-end prompt string is spliced to the front end of the preliminary enhanced sequence to complete the entity type integration prompt.
[0023] According to the above aspects and any possible implementation, an implementation is further provided, wherein the construction process of the type instance guidance prompt is:
[0024] All entity types in the mapping and the corresponding most commonly associated entities are identified and paired to form a prompt prefix, and the prompt prefix is spliced to the front end of the word sequence to complete the type instance guidance prompt.
[0025] According to the above aspects and any possible implementation manner, an implementation manner is further provided, wherein the similarity score is calculated as follows:
[0026] The training support set token encoding and the training query set token encoding are transformed by a feature mapping function to obtain a transformed training support set feature vector and a training query set feature vector, and a standardized dot product between the training support set feature vector and the training query set feature vector is calculated to obtain a dot product similarity;
[0027] A custom attention mechanism is used to calculate the similarity between the support set token encoding and the query set token encoding to obtain an attention score;
[0028] A similarity matrix is constructed by combining the dot product similarity and the attention score, and normalized to obtain a similarity score.
[0029] According to the above aspects and any possible implementation, an implementation is further provided, wherein the calculation process of the loss function is:
[0030] The loss function is calculated by the similarity score to obtain a preliminary loss function, and the preliminary loss function is regularized to obtain a final loss function.
[0031] According to the above aspects and any possible implementation, an implementation is further provided, wherein the process of inputting the test support set and the test query set data into the pre-trained language model for processing and performing entity type prediction is as follows:
[0032] Inputting the test support set and the test query set into the model for processing to obtain a test support set token encoding and a test query set token encoding;
[0033] Calculate the Euclidean distance between the test support set token encoding and the test query set token encoding to obtain a distance matrix;
[0034] Based on the distance matrix, the model is used to determine the test query set token encoding corresponding to the minimum distance between each test support set token encoding and the test query set token encoding, and the entity type corresponding to the encoding is used as the prediction result of the test query set token encoding.
[0035] According to the aspects and any possible implementation methods described above, an implementation method is further provided, in which the average value of the hidden states of the last four layers of the pre-trained language model is used as the output result of the training support set and the output result of the training query set.
[0036] This application discloses the following technical effects:
[0037] (1) This application takes into account the importance of label and entity semantic information, and dynamically integrates entities and their type information in the input sequence to improve the model's understanding of label semantics. At the same time, this application embeds labels into the model by converting them into natural language descriptions. In addition to labels, this application further introduces specific entity information to enhance the model's understanding and processing capabilities of text contexts. In the encoding stage, the semantic information of labels and entities is used to deepen the model's understanding of entities, thereby optimizing the model's ability to interpret entity information. At the same time, by constructing a mapping from type to entity and using this mapping information to construct prompts, the construction of prompts is more flexible and semantically rich, and can better adapt to different contexts.
[0038] (2) This application measures the relationship between the support set and the query set by combining a custom attention mechanism with a typical dot product similarity. This multi-level similarity not only matches based on simple features, but also weights the dot product similarity and attention score through learnable weight parameters, thereby achieving flexible adjustment of the similarity calculation and providing a more refined similarity measurement. Moreover, the model can effectively distinguish between content with similar surface morphology but different semantics based on different contextual environments, combined with the weights learned through training and the similarity measurement function, thereby enhancing the ability to process complex semantics and improving the point recognition performance under small sample conditions.
[0039] It should be understood that the contents described in the Summary of the Invention are not intended to limit the key or important features of the embodiments of the present application, nor are they intended to limit the scope of the present application. Other features of the present application will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] The above and other features, advantages and aspects of the embodiments of the present application will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. The accompanying drawings are used to better understand the present solution and do not constitute a limitation of the present application. In the accompanying drawings, the same or similar reference numerals represent the same or similar elements, among which:
[0041] Figure 1 A flow chart of a small sample named entity recognition method based on metric learning according to an embodiment of the present application is shown;
[0042] Figure 2 A schematic diagram of the overall framework of a small sample named entity recognition method based on metric learning according to an embodiment of the present application is shown;
[0043] Figure 3 A schematic diagram of an entity-guided mask prompt process of a small sample named entity recognition method based on metric learning according to an embodiment of the present application is shown. DETAILED DESCRIPTION
[0044] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0045] In order to make the above-mentioned objects, features and advantages of the present application more obvious and easy to understand, the present application is further described in detail below in conjunction with the accompanying drawings and specific implementation methods.
[0046] Please refer to Figure 1 and Figure 2 As shown, this embodiment provides a small sample named entity recognition method based on metric learning, including the following steps:
[0047] S101. Acquire corpus data, obtain a training set and a test set of the corpus data, and construct a mapping from entity type to entity based on the training set.
[0048] This embodiment uses the general corpus OntoNotes 5.0 as the source domain set. This dataset covers a variety of text types and rich language annotations and is suitable for a wide range of language processing tasks.
[0049] In the NER method, entities generally refer to entities with specific meanings or strong referentiality in the text, usually including names of people, places, organizations, dates, times, proper nouns, etc. Academically, the named entities involved in NER generally include three categories (entity, time, and numbers) and seven subcategories (names, places, organizations, time, date, currency, and percentage). Type is the classification name of the entity, and the two have a certain mapping relationship.
[0050] Specifically, in this embodiment, the frequency function is defined To count each entity type Lower Entity The frequency of occurrence of each type is then updated through the training data set. The most frequent entity By mapping function Determine, that is:
[0051] (1)
[0052] Among them: the entity type in the mapping M is the key, and the value is the specific entity with the highest frequency under each type obtained after traversing all the data in the training set.
[0053] S102, dividing the training set into a support set and a query set, constructing entity-guided mask prompts on the support set and the query set based on the mapping, and obtaining a support set enhanced sequence and a query set enhanced sequence.
[0054] In order to enhance the model's ability to understand and recognize entities in the input text, this application proposes an entity-guided mask prompt method, which combines entity type integration prompts and type instance guidance prompts.
[0055] like Figure 3 As shown, this embodiment divides the training set into a support set and a query set, and constructs entity type integration prompts on the word sequences in the support set and the query set, and constructs type instance guidance prompts on the word sequences in the query set. Specifically, for the support set sentences, the two prompts are spliced to the beginning of the input sentence, and then the entities and their types in the sentence are spliced to the end to obtain two prompt enhancement sequences. For the query set sentences, because it is necessary to traverse the actual labels when constructing the entity type integration prompts, only type instance guidance prompts are used when constructing prompts in the query set sentences. That is, the type instance guidance prompts are spliced at the front end of the query set sentences.
[0056] First, the entity type integration hint method aims to improve the model's semantic understanding of labels and their entity information by dynamically integrating the input sequence and mapping the entities and their type information in M. Since the hint method needs to traverse the actual labels when building it, such hints are not applied to the query set in the small sample learning setting.
[0057] Specifically, get the word sequence that supports centralized input And the corresponding label sequence , and then iterate over each type For non-'O' types, the corresponding Mark as entity and record its type L. To construct a prompt, the format of the prompt string is:
[0058] (2)
[0059] These hint strings are then appended to the end of the input sequence, and the corresponding type is retrieved from the mapping M. The most frequently associated entity , , and generates another prompt string in the same format and adds it to the front of the input, thus enhancing the input sequence obtained by integrating prompts with the frame entity type It can be expressed as:
[0060] (3)
[0061] Where: n represents the number of entity types identified in the input sequence x, is the entity obtained from M, M is a mapping, and L is the set of entity types in the input sequence.
[0062] For example, suppose the input sentence is "Jack was born in Hawaii." The input reconstructed using the hint method is "[SEP] Tom: person [SEP]Paris: location [SEP] Jack was born in Hawaii.[SEP]Jack: person [SEP] Hawaii: location [SEP], where "Tom" and "Paris" are obtained through mapping M. This method not only provides complete type information, but also adds specific entities to enhance the type semantics, thereby improving the model's ability to handle complex texts.
[0063] Secondly, type instance guidance hints are constructed on word sequences in the support set and query set. The type instance guidance hints construct prefix hints by utilizing potential tags with corresponding high-frequency entities in order to more effectively fuse the semantics of tags and entities. In limited annotated data, specific tags co-occur with certain entities, and this association can be used to enhance the model's understanding of the text.
[0064] Specifically, this embodiment is based on each entity type in the mapping Most commonly associated entities , identify each entity type Most commonly associated entities , and pair these entities with the corresponding entity types to form The prompt prefix is added to the front of the word sequence, and the enhanced sequence formatted by the prompt , which can be expressed by formula (4) as: (4)
[0065] Where: m is the number of potential entity types, is the set of potential entity types.
[0066] During the training phase, this structured hint prefix helps the model form an understanding of the specific features of each entity type, so that when the model encounters a new or rare entity type, it can make accurate predictions based on the semantics of the learned entity type. In addition, embedding these hints into the model's input not only simplifies the amount of information the model needs to process, but also optimizes the model's capture of key entity features, allowing it to focus more on the learned key entity attributes when parsing text. During the query phase, by continuing to apply these structured hints, the model is able to use the knowledge it has acquired during training to process new text instances.
[0067] For example, suppose the input is “Lily leads marketing at Nike.” After the type instance guidance prompt is constructed, the result is “[SEP] Tom: person [SEP]Paris: location [SEP] 1974: time [SEP]Google : organization [SEP] Lily leads marketing at Nike.”
[0068] S103. Use a pre-trained language model (BERT) to encode the support set enhanced sequence and the query set enhanced sequence constructed with entity-guided mask prompts to obtain the support set token encoding and the query set token encoding.
[0069] First, for the support set, the support set enhanced sequence is passed into the pre-trained language model (BERT) respectively. Considering the multi-layer output characteristics of BERT, this application uses the average value of the hidden state of the last four layers of the output as the encoding feature, and obtains a highly comprehensive semantic representation through formulas (5) and (6).
[0070] ,
[0071] (5)
[0072] (6)
[0073] in: It is The output of the layer, L is the total number of layers of the BERT model, is the average of the outputs of the last four layers. Similarly, another output format can be obtained: Then, the final support set token encoding is obtained by weighted averaging the mask vector and formula (7).
[0074] (7)
[0075] in: is a hyperparameter used to balance the two prompts. and Mask vectors corresponding to the two prompts respectively.
[0076] A similar method is used to obtain the token representation of the query set, but the hint method is different from that of the support set. When constructing hints for the query set, this application only uses type instance guidance hints because its real labels are unavailable. Therefore, the query set encoding can be obtained by formula (8).
[0077] (8)
[0078] S104, calculating the similarity between the support set token encoding and the query set token encoding, and constructing a similarity matrix to perform similarity analysis to obtain a similarity score, and calculating a loss function based on the similarity score.
[0079] After obtaining the token representation of the support set and query set sentences, this application calculates the similarity between each token of the support set and the query set in two ways and then constructs a similarity matrix.
[0080] First, through the feature mapping function and The support set and query set are transformed respectively, and the adjusted feature vector is obtained by formula (9).
[0081] (9)
[0082] Then, the normalized dot product between the query set u and the support set v is calculated to evaluate the dot product similarity between the two. The dot product similarity calculation is shown in formula (10):
[0083] (10)
[0084] in: is the dimension of the feature vector, where represents the matrix multiplication between u and v, where each element represents the dot product between the i-th feature vector in the support set and the j-th feature vector in the query set.
[0085] Normalization makes the similarity score unaffected by the length of the vector and fairly reflects the intrinsic similarity between features.
[0086] In addition to using this typical dot product similarity to measure the similarity between each token in the support set and the query set, inspired by the idea of matching networks, this embodiment uses a custom attention mechanism to calculate the similarity between the support set and the query set, and measures the similarity between each token in the support set and the query set through the attention score. The specific calculation is shown in formula (11):
[0087] (11)
[0088] in: represents element-wise product, GELU and ELU are activation functions, and Linear is a linear layer.
[0089] Then combine the dot product similarity and attention score, adjust by weight and apply After normalization, the final similarity score is calculated by formula (12).
[0090] (12)
[0091] in: and It is to adjust the weights of the two similarity influences, which are automatically adjusted after network learning.
[0092] After calculating the similarity between tokens in the support set and query set sentences using a multi-level similarity method, the model parameters are optimized after calculating the loss function based on the similarity to maximize the similarity scores between tokens of the same type and minimize the similarity scores between tokens of different types. For a given mini-batch, the loss function L focuses on measuring the similarity between each token in the query set Q and the corresponding token with the same label in the support set S. The loss function aims to enhance the similarity between tokens with the same label while reducing the similarity between tokens with different labels. The preliminary loss function is calculated by formula (13):
[0093] (13)
[0094] in: is the token q in the query set Q and the support set The similarity between token p in Is the support set Zhongyu A collection of tokens with the same tag. is the size of the set, is the size of the query set Q.
[0095] To prevent overfitting on the training data, a regularization term is added, and the final loss function is calculated as (14):
[0096] (14)
[0097] in: is the regularization coefficient, is the model parameter.
[0098] S105: Divide the test set into a support set and a query set, input the support set and query set data into the model for processing, and perform entity type prediction.
[0099] The test set is divided into a support set and a query set. First, the input text of the support set and the query set is input into the model for encoding to obtain the support set token encoding and the query set token encoding to generate a high-dimensional embedding representation.
[0100] Then, the Euclidean distance between each token in the query set sentence and each token in the support set sentence is calculated to obtain a distance matrix. For each token in the query set sentence, the model calculates the minimum distance between each token in the query set sentence and a token in all support set sentences through the distance matrix, determines the entity type corresponding to the token in the closest support set sentence, and uses the entity type as the predicted label of the token in the query set sentence.
[0101] In this example, in a k-shot setting, i.e., when there are k>1 samples per category, the model calculates the average distance of the nearest k supporting tokens associated with each entity type. Through this process, the model can accurately classify under small sample conditions, ensuring that each query token can get a reliable prediction result.
[0102] Methods based on metric learning have shown significant potential in small-sample learning. The core idea of this method is to construct an appropriate metric space so that the distance between samples of the same category in the space is as small as possible, while the distance between samples of different categories is as large as possible. In the small-sample NER task, the selection of similarity measurement function for metric learning is crucial, because it not only needs to accurately measure the similarity between samples under limited data conditions, but also directly affects the construction of the metric space in some methods, thereby directly determining the performance of the model.
[0103] The entity-guided mask hint method proposed in this embodiment makes the hint construction more flexible and semantic by dynamically integrating entities and their type information in the input sequence, thereby improving the model's understanding of entities and their type information. In addition, by integrating the multi-level similarity measurement method, this method combines dot product similarity with a custom attention score, so that the model can more accurately measure the relationship between the support set and the query set, thereby improving the recognition performance under small sample conditions. Specific embodiments
[0105] This embodiment conducts experimental comparisons under two settings that simulate real scenarios: a cross-label space setting scenario and a domain transfer setting scenario.
[0106] The core goal of the cross-label space setting is to ensure that the model can effectively recognize and handle new categories that have not been seen in the training phase during the test phase. Specifically, during the training phase, the label space exposed to the model is defined as the set , while in the test phase, the label space that the model needs to process is the set ,in , satisfy ,show and There are no overlapping categories between them. This means that all categories in the test phase are completely new to the training model, and the model must demonstrate its generalization ability on unknown categories. Specifically, the training set consists of sample pairs Composition, each label Correspondingly, the test set , each label This design simulates the continuous expansion of entity categories in the real world and challenges the adaptability and flexibility of the model in a dynamic environment.
[0107] The goal of the domain transfer task setting is to evaluate the model in a data-rich source domain. After training, transfer to a target domain where data is scarce The core challenge of this task is that the model needs to be able to adapt and perform well in the source domain. Be well-trained, leveraging the large amount of labeled data available in the field To learn complex entity recognition patterns. Represents input data, represents the corresponding label, and N is the number of samples in the source domain. Subsequently, the model must use the target domain The fine-tuned model is then evaluated on a set of unseen examples from the target domain. This task not only tests the model's ability to quickly adapt to new domains, but also examines its ability to maintain performance under extreme conditions. In this way, the model's generalization ability when dealing with rare or unseen data can be evaluated, which is critical for resource-constrained situations often encountered in real applications.
[0108] Specifically, in the first set of experiments, the model proposed in this embodiment is evaluated in the cross-label space setting using the FEW-NERD INTER and FEW-NERD INTRA settings of the Few-NERD dataset. In these two settings, the entire entity type set is divided into three mutually exclusive subsets: , , ,satisfy and . In the FEW-NERD INTER setting, fine-grained types are mutually exclusive between different subsets, but coarse-grained types, such as PERSON, can be shared between subsets. This setting allows the model to try to identify new fine-grained types while retaining some category information. In contrast, the entity types in the FEW-NERD INTRA setting are completely isolated at all granularities, that is, the entity types in the training set, validation set, and test set are mutually exclusive at fine granularity and are not shared at coarse granularity. This setting increases the challenge. This embodiment selects recent NER models such as ProtoBERT, NNShot, and StrucShot as comparison models. The experimental results are shown in Table 1, where the final result is the average F1 value and standard deviation of 5 experiments conducted under 5 different random plantings.
[0109] Table 1 Experimental results of this embodiment on the FewNERD dataset under the cross-label space setting
[0110]
[0111] From the experimental results, it can be seen that the method proposed in this embodiment is superior to the previous method to a large extent and achieves improved performance. These data show that ProMSM can not only handle the complexity of the internal label structure, but also show high robustness and adaptability in generalization across label types.
[0112] The model ProMSM proposed in this embodiment makes the construction of prompts more flexible and semantic by dynamically integrating entities and their type information in the input sequence, thereby improving the model's understanding of entities and their type information. In addition, a method of fusing multi-level similarity metrics is proposed, which combines dot product similarity with a custom attention score, so that the model can more accurately measure the relationship between the support set and the query set, thereby improving the recognition performance under small sample conditions.
[0113] In the second set of experiments, the model proposed in this embodiment is used in the domain transfer setting, using the general corpus OntoNotes 5.0 as the source domain training set. This dataset covers a variety of text types and rich language annotations, and is suitable for a wide range of language processing tasks. Then it is tested on CoNLL'03 for news text, WNUT'17 for social media text, and I2B2 for medical health records. The experimental results are shown in Table 2, where the results are the average F1 value and standard deviation results under 10 samples.
[0114] Table 2 Small sample experiment results of this example under the domain transfer setting
[0115]
[0116] From the experimental results, we can see that ProMSM continues to demonstrate its excellent performance and adaptability in the domain transfer task. Compared with COPNER, the strongest baseline model, ProMSM improves the overall average result by 1.57%, achieving an overall average of 49.85%. The performance on the WNUT dataset is particularly significant. These results show that ProMSM can effectively adapt to noisy environments.
[0117] In general, ProMSM shows low standard deviation in each test configuration and task, which shows the stability and reliability of its results. Even with a small number of samples, this embodiment can still achieve optimal performance in most cases, further highlighting its excellent performance and stability. These results not only verify the effectiveness of this embodiment, but also provide strong experimental support for future research, promoting the progress of small sample learning and domain adaptation research.
[0118] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the described order of actions, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all optional embodiments, and the actions and modules involved are not necessarily required by the present application.
[0119] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this application can be executed in parallel, sequentially or in different orders, as long as the expected results of the technical solution disclosed in this application can be achieved, and this document is not limited here.
[0120] The above specific implementations do not constitute a limitation on the protection scope of this application. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions and improvements made within the spirit and principles of this application should be included in the protection scope of this application.
Claims
1. A small sample named entity recognition method based on metric learning, It is characterized in that The following steps are involved: Acquire corpus data, construct a corpus data training set and a test set, and construct a mapping from entity type to entity based on the training set; The training set is divided into a training support set and a training query set, and entity-guided mask prompts are constructed on the training support set and the training query set respectively based on the mapping to obtain a training support set enhanced sequence and a training query set enhanced sequence; The process of constructing entity-guided mask prompts on the training support set and the training query set based on the mapping to obtain a training support set enhanced sequence and a training query set enhanced sequence is as follows: constructing entity type integration prompts and type instance guidance prompts on the training support set data to obtain a training support set entity type integration prompt enhanced sequence and a training support set type instance guidance prompt enhanced sequence, thereby obtaining a training support set enhanced sequence; constructing type instance guidance prompts on the training query set to obtain a training query set enhanced sequence; The construction process of the entity type integration prompt is as follows: Obtain a word sequence and a corresponding label sequence in the training support set, traverse the label sequence to obtain non-'O' entity type data: mark the word corresponding to the non-'O' entity type data as an entity, and record the entity type corresponding to the entity, construct a terminal prompt string according to the entity and the entity type, and splice the terminal prompt string to the end of the word sequence to obtain a preliminary enhanced sequence; based on the mapping, obtain the entity with the highest frequency associated with the entity type as a mapping entity, construct a front-end prompt string according to the entity type and the mapping entity, and splice the front-end prompt string to the front end of the preliminary enhanced sequence to complete the entity type integration prompt; The construction process of the type instance guidance prompt is as follows: Identify all entity types in the mapping and the corresponding most commonly associated entities, and pair them to form a prompt prefix, and splice the prompt prefix to the front end of the word sequence to complete the type instance guidance prompt; Using a pre-trained language model to encode the training support set enhanced sequence and the training query set enhanced sequence constructed with entity-guided mask prompts, to obtain a training support set token encoding and a training query set token encoding; The acquisition process of the training support set token code and the training query set token code is as follows: inputting the training support set entity type integration prompt enhancement sequence and the training support set type instance guidance prompt enhancement sequence into the model for processing to obtain the training support set output result, using a mask vector to encode the training support set output result and performing weighted processing to obtain the training support set token code; inputting the training query set enhancement sequence into the model for processing to obtain the training query set output result, using a mask vector to encode the training query set output result, and obtaining the training query set token code; Calculate the similarity between the training support set token encoding and the training query set token encoding, construct a similarity matrix for similarity analysis, obtain a similarity score, calculate a loss function based on the similarity score, and obtain the pre-trained language model after training; The test set is divided into a test support set and a test query set, and the test support set and the test query set data are input into the trained pre-trained language model for processing to perform entity type prediction.
2. According to the small sample named entity recognition method based on metric learning according to claim 1, It is characterized in that The process of constructing a mapping from entity type to entity based on the training set is: A frequency function is constructed, and the occurrence frequency of entities under each entity type in the training set is traversed according to the frequency function; a mapping function is constructed, and the entity with the highest frequency under the entity type is used as the mapping value of the entity type.
3. According to the small sample named entity recognition method based on metric learning according to claim 1, It is characterized in that The calculation process of the similarity score is: The training support set token encoding and the training query set token encoding are transformed by a feature mapping function to obtain a transformed training support set feature vector and a training query set feature vector, and a standardized dot product between the training support set feature vector and the training query set feature vector is calculated to obtain a dot product similarity; A custom attention mechanism is used to calculate the similarity between the support set token encoding and the query set token encoding to obtain an attention score; A similarity matrix is constructed by combining the dot product similarity and the attention score, and normalized to obtain a similarity score.
4. The small sample named entity recognition method based on metric learning according to claim 1, It is characterized in that The calculation process of the loss function is: The loss function is calculated by the similarity score to obtain a preliminary loss function, and the preliminary loss function is regularized to obtain a final loss function.
5. The small sample named entity recognition method based on metric learning according to claim 1, It is characterized in that The process of inputting the test support set and the test query set data into the pre-trained language model for processing and performing entity type prediction is as follows: Inputting the test support set and the test query set into the model for processing to obtain a test support set token encoding and a test query set token encoding; Calculate the Euclidean distance between the test support set token encoding and the test query set token encoding to obtain a distance matrix; Based on the distance matrix, the model is used to determine the test query set token encoding corresponding to the minimum distance between each test support set token encoding and the test query set token encoding, and the entity type corresponding to the encoding is used as the prediction result of the test query set token encoding.
6. The small sample named entity recognition method based on metric learning according to claim 1, It is characterized in that The average value of the hidden states of the last four layers of the pre-trained language model is used as the training support set output result and the training query set output result.
