Continuous few-sample relation extraction and unseen relation detection method and device
By adopting task-specific encoder and dynamic prototype module methods in relation extraction and relationship detection models, the catastrophic forgetting problem in continuous and low-sample relationship extraction is solved, and more efficient relationship memory and ability to adapt to new tasks is achieved.
Patent Information
- Application Number
- CN202411906047.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-23
- Publication Date
- 2025-04-15
- Estimated Expiration
- 2044-12-23
AI Technical Summary
The existing technology has catastrophic forgetting problems in continuous low-sample relationship extraction, making it difficult for the model to effectively remember and adapt to the relationship distribution in new tasks.
By constructing a relationship extraction and relationship detection model, a task-specific encoder is used to save and load the fine-tuned parameter state of each task, reducing the interference of new tasks on historical relationship knowledge. At the same time, the dynamic prototype module adaptively handles the complexity of relationship semantics through clustering and prototype comparison learning to generate more accurate relationship prototypes.
It effectively alleviates the problem of catastrophic forgetting, ensures the model's memory of previous relationships, improves the model's discrimination ability and generalization performance, significantly improves the efficiency of continuous learning of few samples, and enhances the ability to detect and classify unseen relationships.
Smart Images

Figure CN119831025A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a method and device for continuous small-sample relationship extraction and unseen relationship detection. Background Art
[0002] Relation extraction aims to identify the semantic relationship between two annotated entities in text. Traditional RE methods usually rely on a fixed set of predefined relations and a one-time training static dataset. However, this approach limits the ability to handle emerging relations outside the predefined set. A simple solution is to retrain the model using historical and new relations, but this will lead to increased computational and storage requirements.
[0003] In response to emerging relations in practical applications, the concept of continuous relation extraction (CRE) has been proposed, which attempts to continuously integrate newly introduced relations without degrading the performance on previous relations. Considering the lack of labeled data for relations, a more challenging task, continuous few-shot relation extraction (CFRE), is proposed, which acquires relation knowledge through only a small number of labeled samples. As a typical continuous learning process, CRE suffers from the inherent catastrophic forgetting problem, i.e., forgetting early relation knowledge. This is because the RE model needs to be trained on a series of tasks, and the relation distribution of each task gradually changes. In order to overcome the forgetting problem, it mainly relies on memory-based methods and establishes a two-stage training paradigm. Specifically, when a new task appears, the RE model first adapts to the new relation and then fine-tunes it through a fixed number of memory samples of the current relation as well as memory samples of historical relations.
[0004] However, these memory-based CRE and CFRE methods assume that each task in the sequence is independent and that the learning difficulty of each relation within each task remains consistent. However, in practice, these assumptions often do not hold. On the one hand, differences in relation distribution may cause interference in the transfer of knowledge from previous tasks to new tasks; on the other hand, the inherent imbalance of learned relations means that allocating a uniform memory size to all relations will hinder the re-learning of those relations that are more difficult to remember, resulting in low efficiency in extracting few-shot relations. Summary of the invention
[0005] Based on this, it is necessary to provide a method and device for continuous few-sample relationship extraction and unseen relationship detection that can improve the efficiency of continuous few-sample relationship extraction in response to the above-mentioned technical problems.
[0006] A method for continuous small sample relationship extraction and unseen relationship detection, the method comprising:
[0007] Obtain sample tasks; the sample tasks include a data set and a relationship set corresponding to the data set; the relationship set includes relationships between multiple data; each relationship includes multiple instances in each sample task; build a relationship extraction and relationship detection model; the relationship extraction and relationship detection model includes a relationship extraction module, a dynamic prototype module and a relationship reasoning module;
[0008] In the relation extraction module, an encoder is used to encode instances according to entity tags to obtain instance-level representations; a classifier is used to calculate the relation probability of the instance-level representations; a loss function of the relation extraction module is designed based on the relation probability, and the trained relation extraction module is used to output an updated instance representation set of the sample task;
[0009] In the dynamic prototype module, the updated instance representation set of the sample task is dynamically clustered to obtain the relationship prototype; the relationship prototype is compared and learned according to the preset prototype comparison learning function to obtain the updated relationship prototype;
[0010] In the relational reasoning module, the instance-level representation of the current input and the updated relation prototype are scored to obtain the relation score; the relation with the highest score is used as the predicted label of the unseen relation.
[0011] A device for continuous small sample relationship extraction and unseen relationship detection, the device comprising:
[0012] Constructing a relation extraction and relation detection model module for obtaining sample tasks; the sample task includes a data set and a relation set corresponding to the data set; the relation set includes relations between multiple data; each relation includes multiple instances in each sample task; constructing a relation extraction and relation detection model; the relation extraction and relation detection model includes a relation extraction module, a dynamic prototype module and a relation reasoning module;
[0013] The instance representation update module is used to encode the instance according to the entity tag using the encoder in the relation extraction module to obtain the instance-level representation; the classifier is used to calculate the relation probability of the instance-level representation; the loss function of the relation extraction module is designed according to the relation probability, and the trained relation extraction module is used to output the updated instance representation set of the sample task;
[0014] The relation extraction module is used to dynamically cluster the updated instance representation set of the sample task in the dynamic prototype module to obtain the relation prototype; perform comparative learning on the relation prototype according to a preset prototype comparative learning function to obtain the updated relation prototype;
[0015] The unseen relationship detection module is used to perform score calculation on the instance-level representation of the current input and the updated relationship prototype in the relationship reasoning module to obtain the relationship score; the highest-scoring relationship is used as the predicted label of the unseen relationship.
[0016] The above-mentioned method and device for continuous few-sample relationship extraction and unseen relationship detection, this application constructs a relationship extraction and relationship detection model. In the relationship extraction module, the task-specific encoder method saves and loads the fine-tuned parameter state of each task, thereby reducing the interference with the existing relationship knowledge when introducing new tasks. It is suitable for continuous learning scenarios, effectively alleviates the catastrophic forgetting problem, and ensures the model's memory of previous relationships. The dynamic prototype module adaptively handles the complexity of relationship semantics by adjusting the clustering radius and the fluctuation radius. For concentrated relationships, average clustering is used; for dispersed relationships, the cluster center is dynamically updated. The multi-center clustering method improves the representativeness and comprehensiveness of storage memory, allowing the model to better adapt to the relationship distribution of complex tasks. At the same time, the combination of dynamic clustering and prototype comparative learning ensures that the generated relationship prototype can more accurately reflect the relationship semantics through dynamic adjustment and fine comparison in the embedding space, significantly improving the model's discrimination ability and generalization performance, thereby improving the efficiency of continuous few-sample learning. In the relational reasoning module, the dynamically updated relational prototypes are used to score the test samples. The accuracy and speed of relational reasoning are ensured through an efficient scoring mechanism. It is applicable to both known and unseen relations, and enhances the model's ability to handle complex relational distributions. This application can significantly improve efficiency in continuous few-sample relation extraction tasks, alleviate forgetting problems, and enhance the detection and classification capabilities of unseen relations. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Figure 1 1 is a flow chart of a method for continuous small-sample relationship extraction and unseen relationship detection in one embodiment;
[0018] Figure 2 Schematic diagram of a framework of a method for continuous few-sample relationship extraction and unseen relationship detection in one embodiment;
[0019] Figure 3 is a structural block diagram of a device for continuous small sample relationship extraction and unseen relationship detection in one embodiment;
[0020] Figure 4 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0021] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0022] In one embodiment, Figure 1 As shown, a method for continuous few-sample relationship extraction and unseen relationship detection is provided, comprising the following steps:
[0023] Step 102, obtain sample tasks; the sample tasks include a data set and a relationship set corresponding to the data set; the relationship set includes relationships between multiple data; each relationship includes multiple instances in each sample task; build a relationship extraction and relationship detection model; the relationship extraction and relationship detection model includes a relationship extraction module, a dynamic prototype module and a relationship reasoning module.
[0024] In the N-way K-shot setting, the model needs to continuously learn a series of tasks. Each task Including its corresponding training set, test set and validation set data sets, respectively and and the corresponding set of relations Dataset Contains N relations, each of which contains K instances in each task, thus forming Each sample (x i ,y i ) includes a sentence x i , which contains a pair of entities (e h ,e t ) and a relationship tag In this step, set K to 10. Test set Contains N relations, each containing 20 texts. In addition, An additional “no relation” type is included to evaluate the model’s filtering performance when dealing with never-seen-relation (NOTA) samples.
[0025] Unlike previous memory-based methods, this application does not require a memory bank to store the original memory samples for each task. Instead, this application proposes a dynamic prototype module for memorizing and The prototype library contains all learned relations since the beginning of training and is updated dynamically. The performance of the model is evaluated by the cumulative test set of all tasks, denoted as This comprehensive evaluation requires the model to accurately identify and classify relations in all the text it has been trained on.
[0026] like Figure 2 As shown, the relationship extraction and relationship detection model implementation of the present application includes several processes, mainly including a lightweight multi-task encoding process; dynamically acquiring the relationship memory prototype through the embedding of the encoder, and storing the obtained prototype in the memory pool.
[0027] For each task LoRA is used as a lightweight fine-tuning method, and the cost of parameter adjustment is significantly reduced through low-rank matrices. During the training process, the parameter state after fine-tuning for each task is saved to create a task-specific encoder. When training each task, the fine-tuned parameters are saved independently to form a task-specific encoder, thereby reducing knowledge interference between tasks. The scale of fine-tuning parameters is significantly reduced by replacing the high-dimensional parameter matrix in traditional fine-tuning with a low-rank matrix. Only a small number of key parameters of the model are adjusted during training, reducing computational costs and adapting to small sample scenarios.
[0028] For each relationship, its prototype representation is obtained through dynamic aggregation. An initial radius r0 and a fluctuation radius r are defined. c In the embedding space, highly concentrated relations are averaged to obtain an embedding as a typical memory prototype. In contrast, for more dispersed types, the cluster centers are dynamically updated according to their displacements to obtain a more comprehensive prototype representation. The prototype representation is optimized by contrastive learning functions, which strengthens the model's ability to perceive the semantic differences between relations.
[0029] For test texts containing both unseen relations (NOTA) and known relations, our threshold criteria are used for classification. This module calculates the similarity score between the test text and the prototype embedding, taking into account the angle and distance factors to complete the relation classification and filter out the text with unseen relations.
[0030] Step 104, in the relationship extraction module, use an encoder to encode the instance according to the entity tag to obtain an instance-level representation; use a classifier to calculate the relationship probability of the instance-level representation; design the loss function of the relationship extraction module according to the relationship probability, and use the trained relationship extraction module to output an updated instance representation set of the sample task.
[0031] The fine-tuning parameter state of each task is saved to form a task-specific encoder to avoid the new task training covering the historical task knowledge. The key parameters are fine-tuned through the low-rank matrix to reduce the interference on the overall structure of the model when learning new tasks. The tasks are made independent through task decoupling to avoid forgetting early tasks due to learning new relationships; LoRA fine-tuning further reduces knowledge interference by updating only a small number of parameters, while reducing the dependence on large-scale annotated data, adapting to small sample scenarios, and significantly reducing training costs.
[0032] Step 106, dynamically clustering the updated instance representation set of the sample task in the dynamic prototype module to obtain a relationship prototype; performing comparative learning on the relationship prototype according to a preset prototype comparative learning function to obtain an updated relationship prototype.
[0033] Dynamically cluster the instance representations of each task, fix the relational prototype representation in the embedding space, and reduce the prototype shift caused by the introduction of new tasks. The dynamic prototype module enhances the model's memory of historical relational knowledge and significantly reduces the risk of forgetting. The prototype representation is optimized using a pre-set contrastive learning function to strengthen the model's ability to distinguish historical relations in the embedding space and prevent catastrophic forgetting.
[0034] Step 108, in the relational reasoning module, the instance-level representation of the current input and the updated relation prototype are scored to obtain a relation score; the relation with the highest score is used as the predicted label of the unseen relation.
[0035] The dynamically updated relationship prototypes are used to score the test samples. The accuracy and speed of relationship reasoning are ensured through an efficient scoring mechanism. It is applicable to both known and unseen relationships, enhances the model's ability to handle complex relationship distributions, effectively solves the problem of detecting unseen relationships, and provides higher robustness and classification accuracy for the CFRE task.
[0036] In the above-mentioned method for continuous few-sample relationship extraction and unseen relationship detection, the present application constructs a relationship extraction and relationship detection model. In the relationship extraction module, the task-specific encoder method saves and loads the fine-tuned parameter state of each task, thereby reducing the interference with the existing relationship knowledge when introducing new tasks. It is suitable for continuous learning scenarios, effectively alleviates the problem of catastrophic forgetting, and ensures the model's memory of previous relationships. The dynamic prototype module adaptively handles the complexity of relationship semantics by adjusting the clustering radius and the fluctuation radius. For concentrated relationships, average clustering is used; for dispersed relationships, the cluster center is dynamically updated. The multi-center clustering method improves the representativeness and comprehensiveness of storage memory, allowing the model to better adapt to the relationship distribution of complex tasks. At the same time, the combination of dynamic clustering and prototype comparative learning ensures that the generated relationship prototype can more accurately reflect the relationship semantics through dynamic adjustment and fine comparison in the embedding space, significantly improving the model's discrimination ability and generalization performance, thereby improving the efficiency of continuous few-sample learning. In the relational reasoning module, the dynamically updated relational prototypes are used to score the test samples. The accuracy and speed of relational reasoning are ensured through an efficient scoring mechanism. It is applicable to both known and unseen relations, and enhances the model's ability to handle complex relational distributions. This application can significantly improve efficiency in continuous few-sample relation extraction tasks, alleviate forgetting problems, and enhance the detection and classification capabilities of unseen relations.
[0037] In one embodiment, encoding the instance according to the entity tag using an encoder to obtain an instance-level representation includes:
[0038] The encoder is used to encode the instance according to the entity tag, and the instance-level representation is obtained as
[0039] h=LayerNorm(W1[h1;h2]+b1),
[0040] in, represents the original weight matrix, is a learnable parameter, [;] is a concatenation operation, h1 and h2 represent the hidden vectors of [E1] and [E2], and [E1] and [E2] represent entity tags.
[0041] In a specific embodiment, an encoder ε(·) based on entity tags is used to learn representations. h ,e t ) instance x, in (e h ,e t ) to indicate the start and end positions:
[0042] {…,[E1],e h ,[ / E1],…,[E2],e t ,[ / E2],…}.
[0043] Then, the token sequence is input into the BERT model to obtain the hidden vectors of [E1] and [E2], denoted as h1 and h2, respectively. Finally, the instance-level representation is obtained as:
[0044] h=LayerNorm(W1[h1;h2]+b1),
[0045] in and is a learnable parameter, and [;] is a concatenation operation.
[0046] By designing an independent lightweight relation encoder for each task, the catastrophic forgetting problem is effectively alleviated, ensuring that the memory of historical relational knowledge and the learning of new tasks do not interfere with each other.
[0047] In one embodiment, calculating the relationship probability of the instance-level representation using a classifier includes:
[0048] The classifier is used to calculate the relationship probability of instance-level representation:
[0049] p(y|x)=softmax(W2h+b2),
[0050] in, represents the original weight matrix different from W1, is a learnable parameter, N is the number of relations in the current task, and h is the instance-level representation.
[0051] In one embodiment, the loss function of the relationship extraction module is designed according to the relationship probability, including:
[0052] The loss function of the relation extraction module designed according to the relation probability is:
[0053]
[0054] Among them, x i It's a task The i-th instance in is x i The true label, p(y i |x i ) represents the probability of the relationship between the i-th instance and the true label, and N×K represents the task The total number of instances of .
[0055] In a specific embodiment, in order to reduce the training overhead, LoRA is applied to the BERT encoder by freezing its original weight matrix And introduce a trainable low-rank matrix and to update the self-attention layer. This approach allows efficient fine-tuning on the current task without having to train all parameters. The weight update mechanism is as follows:
[0056] W′=W+α·PQ,
[0057] Here, α is used as a scaling factor to adjust the impact of the update. We set the rank r to 16, where r <<min(d,k).
[0058] For each task containing N×K training instances Learn and store a different set of P k and Q k 1 In order to optimize these parameters, the cross entropy loss function is used as the main loss function, which is defined as follows:
[0059]
[0060] where x i It's a task The i-th instance in is x i The real label.
[0061] By minimizing the cross entropy loss, P can be effectively adjusted k and Q k parameters, so that they more accurately capture the current task Because LoRA technology freezes the original weight matrix W, the model does not need to adjust the huge weight matrix, and learns P separately by optimizing the cross entropy loss. k and Q k This reduces the training overhead while ensuring adaptability to the current task, thereby achieving efficient fine-tuning. In continuous learning tasks, the cross entropy loss function can guide the model to accurately classify the N×K training instances in the current task while maintaining compatibility with old tasks as much as possible. This is very important for avoiding negative transfer (interference between tasks) and catastrophic forgetting.
[0062] In one embodiment, dynamically clustering the updated instance representation set of the sample task to obtain the relationship prototype includes:
[0063] Get the updated instance representation set of the sample task Set the center set C of the cluster r Initially, it is an empty set, and the number of clusters m is initialized to 0. The updated instance after traversing the sample task represents each sample in the set. If it is the first sample, it is directly used as the first cluster center. For each existing cluster center, the distance from the current sample to the center is calculated. If the distance is less than the predefined cluster radius ρ, the current cluster center is updated. b is the number of embeddings in the current cluster; if the distance is between ρ and ρ+δ, δ is an optional extension of the radius, update the ρ value but keep the center unchanged; if the distance is greater than ρ+δ, create a new cluster center, and increase the number of clusters m by 1 until the set C of all cluster centers is output r ={c1,…,c m}, indicating the relationship prototype.
[0064] In a specific embodiment, a dynamic partition of the embedding representation is computed based on the Euclidean distance between the newly incoming embedding and the existing prototype centers. The target relation r in has a set of instance embeddings, represented as The dynamic process is illustrated in Algorithm 1. In Algorithm 1., b is the number of embeddings in the current cluster, ρ is the predefined cluster radius, and δ is an optional extension of the radius. min This extension term is used when it is slightly larger than ρ but still within the acceptable range (ρ+δ). Through dynamic clustering, a set of center points C can be obtained for each relationship r ={c1,…,c m}, which represent relationship prototypes.
[0065]
[0066]
[0067] In this way, the embedding representation is dynamically adjusted according to the spatial clustering of training texts, providing multi-center prototypes for complex semantic relations and using single-center prototypes for simple relations.
[0068] In one embodiment, the preset prototype contrast learning function is
[0069]
[0070] Among them, σ(·) represents the Sigmoid function, sim pos Represents the prototype cosine similarity between similar pairs, sim neg Represents the prototype cosine similarity between pairs of different classes.
[0071] In a specific embodiment, a contrast loss function is designed to better distinguish different relationships, thereby improving the clustering effect. A contrast method is used to design a similarity calculation loss to better evaluate the classification performance of new inputs. When a new training embedding arrives, its Euclidean distance to all prototypes is calculated, and the nearest prototype is classified as a positive example and other prototypes as negative examples. If the embedding forms a new prototype center, it itself is used as a positive example. The loss is calculated as follows:
[0072]
[0073] Among them, σ(·) represents the Sigmoid function, sim pos Represents the prototype cosine similarity between similar pairs, sim neg Represents the prototype cosine similarity between pairs of different classes.
[0074] During training, a joint loss is used, which is defined as follows:
[0075]
[0076] in, Focuses on optimizing relationship predictions, while Aims to enhance the discriminability of relations in the embedding space.
[0077] The contrast loss function effectively optimizes the distribution of prototypes in the embedding space by calculating the similarity between the input embedding and the existing prototypes (positive examples) and the differences between different prototypes (negative examples). Taking the nearest prototype as a positive example helps to strengthen the clustering of similar relationships, while taking other prototypes as negative examples further distances different types of relationships, making each prototype more recognizable and representative, thereby improving the clustering effect.
[0078] At the same time, the contrastive loss optimizes the comparison between positive examples (similar relations) and negative examples (different relations), making the embedding closer to the correct prototype and farther away from other prototypes, thereby improving the accuracy of classification. In addition, this mechanism is more effective when dealing with unseen relations, because it can dynamically adjust the classification criteria through the formation of new prototypes, reducing the probability that unseen relations are misclassified as known relations. In addition, the mechanism of dynamically updating the center of the prototype combined with the contrastive loss function helps to achieve incremental learning. When dealing with new relationship tasks, the model can continuously optimize the prototype without losing the memory of the old relationship, thereby effectively alleviating the problem of catastrophic forgetting.
[0079] In one embodiment, the instance-level representation of the current input is scored with the updated relation prototype to obtain a score of the relation, including:
[0080] The instance-level representation of the current input is scored with the updated relation prototype, and the score of the relation is
[0081]
[0082] Among them, w1 and w2 are weights used to balance cosine similarity and distance similarity, q k represents the instance-level representation of the current input, c i Represents the updated relation prototype of the i-th instance.
[0083] In one embodiment, taking the highest-scoring relation as the predicted label of the unseen relation includes:
[0084] The highest-scoring relation is used as the predicted label for the unseen relation.
[0085]
[0086] in, represents the rating of the relationship, Represents a sample task A collection of relationships.
[0087] In a specific embodiment, a scoring mechanism is introduced to solve the bias problem in high-dimensional space, because relying solely on distance may lead to inaccuracy. The cosine similarity and Euclidean distance are balanced in the scoring function, and distance and angle are considered comprehensively. For a test sample q, it is input into n lightweight relation encoders to generate its n possible relation representations {q1,…,qn}. For the task The target relation r in the query is q k and compare it with the prototype {c1,…,c m} for comparison. The scoring function is defined as follows:
[0088]
[0089] Among them, w1 and w2 are weights used to balance cosine similarity and distance similarity. Finally, the relationship with the highest score for the test sample is considered as the predicted label:
[0090]
[0091] It should be understood that although Figure 1 The steps in the flowchart are shown in sequence as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified in this document, there is no strict order restriction for the execution of these steps, and these steps can be executed in other orders. Moreover, Figure 1 At least part of the steps may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily executed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least part of the sub-steps or stages of other steps.
[0092] In one embodiment, Figure 3 As shown, a continuous few-sample relationship extraction and unseen relationship detection device is provided, including: a relationship extraction and relationship detection model building module 302, an instance representation update module 304, a relationship extraction module 306 and an unseen relationship detection module 308, wherein:
[0093] Constructing a relationship extraction and relationship detection model module 302, used to obtain sample tasks; the sample tasks include a data set and a relationship set corresponding to the data set; the relationship set includes relationships between multiple data; each relationship includes multiple instances in each sample task; constructing a relationship extraction and relationship detection model; the relationship extraction and relationship detection model includes a relationship extraction module, a dynamic prototype module and a relationship reasoning module;
[0094] The instance representation updating module 304 is used to encode the instance according to the entity tag using the encoder in the relation extraction module to obtain the instance level representation; calculate the relation probability of the instance level representation using the classifier; design the loss function of the relation extraction module according to the relation probability, and use the trained relation extraction module to output the updated instance representation set of the sample task;
[0095] The relation extraction module 306 is used to dynamically cluster the updated instance representation set of the sample task in the dynamic prototype module to obtain the relation prototype; perform comparative learning on the relation prototype according to a preset prototype comparative learning function to obtain the updated relation prototype;
[0096] The unseen relationship detection module 308 is used to perform score calculation on the instance-level representation of the current input and the updated relationship prototype in the relationship reasoning module to obtain the score of the relationship; and use the highest-scoring relationship as the predicted label of the unseen relationship.
[0097] For the specific definition of a continuous few-sample relationship extraction and unseen relationship detection device, please refer to the definition of a continuous few-sample relationship extraction and unseen relationship detection method above, which will not be repeated here. Each module in the above-mentioned continuous few-sample relationship extraction and unseen relationship detection device can be implemented in whole or in part by software, hardware and a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.
[0098] In one embodiment, a computer device is provided. The computer device may be a terminal, and its internal structure diagram may be as follows: Figure 4 As shown. The computer device includes a processor, a memory, a network interface, a display screen and an input device connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a method for continuous small sample relationship extraction and unseen relationship detection is implemented. The display screen of the computer device can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device can be a touch layer covered on the display screen, or a button, trackball or touchpad set on the computer device housing, or an external keyboard, touchpad or mouse, etc.
[0099] Those skilled in the art will understand that Figure 4 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0100] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0101] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0102] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application shall be subject to the attached claims.
Claims
1. A method for continuous small-sample relationship extraction and unseen relationship detection, characterized in that: The method comprises: Acquire a sample task; the sample task includes a data set and a relationship set corresponding to the data set; the relationship set includes relationships between multiple data; each relationship includes multiple instances in each sample task; construct a relationship extraction and relationship detection model; the relationship extraction and relationship detection model includes a relationship extraction module, a dynamic prototype module and a relationship reasoning module; In the relation extraction module, an encoder is used to encode the instance according to the entity tag to obtain an instance-level representation; a classifier is used to calculate the relation probability of the instance-level representation; a loss function of the relation extraction module is designed according to the relation probability, and an updated instance representation set of the sample task is outputted using the trained relation extraction module; Dynamically clustering the updated instance representation set of the sample task in the dynamic prototype module to obtain a relationship prototype; performing comparative learning on the relationship prototype according to a preset prototype comparative learning function to obtain an updated relationship prototype; In the relational reasoning module, the instance-level representation of the current input and the updated relation prototype are scored to obtain a relation score; the relation with the highest score is used as the predicted label of the unseen relation.
2. The method according to claim 1, characterized in that: The encoder is used to encode the instance according to the entity tag to obtain an instance-level representation, including: The encoder is used to encode the instance according to the entity tag, and the instance level representation is obtained as h=LayerNorm(W1[h1;h2]+b1), in, represents the original weight matrix, is a learnable parameter, [;] is a concatenation operation, h1 and h2 represent the hidden vectors of [E1] and [E2], and [E1] and [E2] represent entity tags.
3. The method according to claim 1, characterized in that Calculating the relationship probability of the instance-level representation using a classifier includes: The classifier is used to calculate the relationship probability of the instance-level representation: p(y|x)=softmax(W2h+b2), in, represents the original weight matrix different from W1, is a learnable parameter, N is the number of relations in the current task, and h is the instance-level representation.
4. The method according to any one of claims 1 to 3, characterized in that: Designing a loss function of the relationship extraction module according to the relationship probability includes: The loss function of the relationship extraction module is designed according to the relationship probability: Among them, x i It's a task The i-th instance in is x i The true label, P(y i |x i ) represents the probability of the relationship between the i-th instance and the true label, and N×K represents the task The total number of instances of .
5. The method according to claim 1, characterized in that Dynamically clustering the updated instance representation set of the sample task to obtain a relation prototype includes: Get the updated instance representation set of the sample task Set the center set C of the cluster r Initially, it is an empty set, and the number of clusters m is initialized to 0. The updated instance after traversing the sample task represents each sample in the set. If it is the first sample, it is directly used as the first cluster center. For each existing cluster center, the distance from the current sample to the center is calculated. If the distance is less than the predefined cluster radius ρ, the current cluster center is updated. b is the number of embeddings in the current cluster; if the distance is between ρ and ρ+δ, δ is an optional extension of the radius, update the ρ value but keep the center unchanged; if the distance is greater than ρ+δ, create a new cluster center, and increase the number of clusters m by 1 until the set C of all cluster centers is output r ={c1,…,c m }, indicating the relationship prototype.
6. The method according to claim 1, characterized in that The preset prototype contrast learning function is: Among them, σ(·) represents the Sigmoid function, sim pos Represents the prototype cosine similarity between similar pairs, sim neg Represents the prototype cosine similarity between pairs of different classes.
7. The method according to claim 1, characterized in that The instance-level representation of the current input and the updated relation prototype are scored to obtain a relation score, including: The instance-level representation of the current input is scored with the updated relation prototype to obtain the relation score: Among them, w1 and w2 are weights used to balance cosine similarity and distance similarity, q k represents the instance-level representation of the current input, c i Represents the updated relation prototype of the i-th instance.
8. The method according to claim 1, characterized in that The highest-scoring relation is used as the predicted label for the unseen relation, including: The highest-scoring relation is used as the predicted label for the unseen relation. in, represents the rating of the relationship, Represents a sample task A collection of relationships.
9. A continuous few-sample relationship extraction and unseen relationship detection device, characterized in that: The device comprises: Constructing a relationship extraction and relationship detection model module for obtaining sample tasks; the sample task includes a data set and a relationship set corresponding to the data set; the relationship set includes relationships between multiple data; each relationship includes multiple instances in each sample task; constructing a relationship extraction and relationship detection model; the relationship extraction and relationship detection model includes a relationship extraction module, a dynamic prototype module and a relationship reasoning module; An instance representation updating module is used to encode the instance according to the entity tag using an encoder in the relation extraction module to obtain an instance-level representation; calculate the relation probability of the instance-level representation using a classifier; design a loss function of the relation extraction module according to the relation probability, and output an updated instance representation set of the sample task using the trained relation extraction module; A relation extraction module is used to dynamically cluster the updated instance representation set of the sample task in the dynamic prototype module to obtain a relation prototype; and to perform comparative learning on the relation prototype according to a preset prototype comparative learning function to obtain an updated relation prototype; The unseen relationship detection module is used to perform score calculation on the instance-level representation of the current input and the updated relationship prototype in the relationship reasoning module to obtain the relationship score; and use the highest-scoring relationship as the predicted label of the unseen relationship.
Citation Information
Patent Citations
Method for extracting small sample relation under continuous learning based on prompt contrast learning
CN116719934A
System and method for intent discovery from user logs using deep semi-supervised contrastive clustering
US20240013006A1
Cited By
LoRA-based large model task optimization adjustment method and system
CN120106165A
Zero-sample multi-modal relation extraction method based on multi-modal large model
CN121959448A