A method and device for continuous small-sample relationship extraction and unseen relationship detection
By constructing a relationship extraction and detection model, using task-specific encoders to save parameter states and dynamic prototype modules for clustering learning, the catastrophic forgetting problem is solved, the model's discrimination ability and generalization performance are improved, and the ability to detect and classify unseen relationships is enhanced.
Patent Information
- Application Number
- CN202411906047.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-23
- Publication Date
- 2025-09-23
- Estimated Expiration
- 2044-12-23
AI Technical Summary
Existing continuous relation extraction methods have the problem of increased computation and storage requirements when facing emerging relations, and due to the catastrophic forgetting problem, they lead to the forgetting of existing relation knowledge and inefficient continuous few-shot relation extraction.
By constructing a relationship extraction and relationship detection model, using a task-specific encoder to save the fine-tuned parameter state, and combining it with a dynamic prototype module for clustering and contrastive learning, the clustering radius and fluctuation radius are dynamically adjusted to reduce knowledge interference and adapt to complex relationship distribution.
It significantly improves the model's discriminative ability and generalization performance, enhances the ability to detect and classify unseen relationships, alleviates the forgetting problem, and improves the efficiency of continuous few-shot learning.
Smart Images

Figure CN119831025B_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 (RE) aims to identify semantic relationships between two annotated entities in text. Traditional RE methods typically rely on a fixed set of predefined relations and a one-time training static dataset. However, this approach limits its ability to handle emerging relations outside the predefined set. A naive solution is to retrain the model using both historical and new relations, but this increases computational and storage requirements.
[0003] To address emerging relations in practical applications, the concept of continuous relation extraction (CRE) has been proposed, attempting to continuously integrate newly introduced relations without degrading the performance on previous relations. Given the lack of labeled data for relations, a more challenging task, continuous few-shot relation extraction (CFRE), has been proposed, which acquires relational 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 earlier relational 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. To overcome the forgetting problem, memory-based methods are mainly relied upon, and a two-stage training paradigm has been established. 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 fail to hold. On the one hand, differences in relation distribution can cause knowledge from previous tasks to be transferred to the new task, causing interference. On the other hand, the inherent imbalance of learned relations means that allocating a uniform memory size to all relations hinders the relearning of those that are difficult to remember, resulting in low efficiency in extracting relations from a small number of samples. Summary of the Invention
[0005] Based on this, it is necessary to provide a method and device for continuous small-sample relationship extraction and unseen relationship detection that can improve the efficiency of continuous small-sample relationship extraction in response to the above technical problems.
[0006] A method for continuous small-sample relationship extraction and unseen relationship detection, 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 probabilities of the instance-level representations; a loss function for the relation extraction module is designed based on the relation probabilities, and the trained relation extraction module is used to output an updated set of instance representations for 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 is scored against the updated relation prototype to obtain the relation score; the relation with the highest score is used as the predicted label for the unseen relation.
[0011] A device for continuous small-sample relationship extraction and unseen relationship detection, comprising:
[0012] Build a relationship extraction and relationship detection model module to obtain 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; 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;
[0013] The instance representation update module is used to encode instances based on entity tags using an encoder in the relation extraction module to obtain instance-level representations; the classifier is used to calculate the relation probabilities of the instance-level representations; the loss function of the relation extraction module is designed based on the relation probabilities; and the trained relation extraction module is used to output an updated set of instance representations for 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 the preset prototype comparative learning function to obtain the updated relation prototype;
[0015] The unseen relationship detection module is used to calculate the score of the instance-level representation of the current input and the updated relationship prototype in the relationship reasoning module to obtain the relationship score; the relationship with the highest score is used as the predicted label of the unseen relationship.
[0016] The above-mentioned method and device for continuous few-shot 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 interference with 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 the stored 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-shot 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 the forgetting problem, 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 1 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. 1 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0021] In order to make the purpose, technical solutions and advantages of this application more clear, the following further describes this application in detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain this application and are not intended to limit this application.
[0022] In one embodiment, Figure 1 As shown, a method for continuous few-sample relationship extraction and unseen relationship detection is provided, including 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 relationship set Dataset Contains N relations, each relation 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 representations corresponding to the relations in . The prototype library contains all the relations learned since the start 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 across all texts it has been trained on.
[0026] like Figure 2 As shown, the implementation of the relationship extraction and relationship detection model of this application includes several processes, mainly including a lightweight multi-task encoding process; dynamically obtaining 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, significantly reducing the cost of parameter adjustment through the use of low-rank matrices. During training, the fine-tuned parameter state for each task is saved to create a task-specific encoder. During training for each task, the fine-tuned parameters are independently saved to form a task-specific encoder, thereby reducing knowledge interference between tasks. Replacing the high-dimensional parameter matrix used in traditional fine-tuning with a low-rank matrix significantly reduces the size of the fine-tuning parameters. Only a few key model parameters are adjusted during training, reducing computational costs and making it suitable for low-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 relationships are averaged to obtain a single embedding that serves as a typical memory prototype. Conversely, for more dispersed types, the cluster centers are dynamically updated based on their displacement, resulting in a more comprehensive prototype representation. This contrastive learning function optimizes the prototype representation, strengthening the model's ability to perceive semantic differences between relationships.
[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 both angle and distance factors to complete the relation classification and filter out texts with unseen relations.
[0030] In step 104, the relationship extraction module uses an encoder to encode the instance according to the entity tag to obtain an instance-level representation; a classifier is used to calculate the relationship probability of the instance-level representation; a loss function of the relationship extraction module is designed based on the relationship probability, and the trained relationship extraction module is used to output an updated instance representation set of the sample task.
[0031] The fine-tuning parameter state for each task is saved to form a task-specific encoder, preventing new task training from overwriting knowledge from previous tasks. Key parameters are fine-tuned using a low-rank matrix to reduce interference with the overall model structure when learning new tasks. Task decoupling makes tasks independent, preventing the forgetting of earlier tasks due to learning new relationships. LoRA fine-tuning further reduces knowledge interference by updating only a small number of parameters. This reduces reliance on large-scale annotated data, making it suitable for low-sample scenarios while 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 relation prototype; performing comparative learning on the relation prototype according to a preset prototype comparative learning function to obtain an updated relation prototype.
[0033] Dynamically clustering the instance representations of each task fixes the relational prototype representations in the embedding space, mitigating prototype drift caused by the introduction of new tasks. The dynamic prototype module enhances the model's memory of historical relational knowledge, significantly reducing the risk of forgetting. Using a pre-set contrastive learning function, the prototype representation is optimized, strengthening the model's ability to distinguish historical relations in the embedding space and preventing catastrophic forgetting.
[0034] In step 108, the relationship reasoning module performs a scoring calculation on the instance-level representation of the current input and the updated relationship prototype to obtain a relationship score; the relationship with the highest score is used as the predicted label of the unseen relationship.
[0035] The dynamically updated relationship prototypes are used to score the test samples. The efficient scoring mechanism ensures the accuracy and speed of relationship reasoning. 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-shot 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 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 the stored 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-shot 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 the forgetting problem, and enhance the detection and classification capabilities of unseen relations.
[0037] In one embodiment, encoding an instance according to an 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 points:
[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 based on the relationship probability, including:
[0052] The loss function of the relation extraction module designed based on 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, N×K represents the task The total number of instances.
[0055] In a specific embodiment, in order to reduce 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 set of different P k and Q k 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 true label.
[0061] By minimizing the cross entropy loss, P can be effectively adjusted k and Q k parameters, so that they can 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 training overhead while ensuring adaptability to the current task, enabling 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 older tasks as much as possible. This is very important for avoiding negative transfer (inter-task interference) and catastrophic forgetting.
[0062] In one embodiment, dynamically clustering the updated instance representation set of the sample tasks to obtain relationship prototypes includes:
[0063] Get the updated instance representation set of the sample task Set the center set C of the cluster r Initially, the set is empty, and the number of clusters m is initialized to 0. After traversing the updated instance of the sample task, each sample in the set is represented. 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, updating the ρ value but keeping 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 partitioning 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 When it is slightly larger than ρ but still within the acceptable range (ρ+δ), this extension is used. 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 Indicates 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 and thus improve 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 the other prototypes as negative examples. If the embedding forms a new prototype center, it is itself classified as a positive example. The loss is calculated as follows:
[0072]
[0073] Among them, σ(·) represents the Sigmoid function, sim pos Indicates 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 contrastive loss function effectively optimizes the distribution of prototypes in the embedding space by calculating the similarity between the input embedding and existing prototypes (positive examples) and the differences between different prototypes (negative examples). Using the closest prototype as a positive example helps strengthen the clustering of similar relationships, while using other prototypes as negative examples further increases the distance between different relationships, making each prototype more recognizable and representative, thereby improving clustering results.
[0078] At the same time, contrastive loss optimizes the comparison between positive examples (similar relationships) and negative examples (different relationships), making the embedding closer to the correct prototype and further away from other prototypes, thereby improving classification accuracy. In addition, this mechanism is more effective when dealing with unseen relationships because it can dynamically adjust the classification criteria based on the formation of new prototypes, reducing the probability of unseen relationships being misclassified as known relationships. In addition, the mechanism of dynamically updating the prototype center 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 memory of old relationships, thereby effectively alleviating the problem of catastrophic forgetting.
[0079] In one embodiment, a score calculation is performed on the instance-level representation of the current input and 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 to obtain the relation score:
[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, using the highest-scoring relationship as the predicted label for the unseen relationship 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 problem of bias in high-dimensional space, because relying solely on distance may lead to inaccuracy. The scoring function balances cosine similarity and Euclidean distance, taking distance and angle into consideration. For a test sample q, it is input into n lightweight relation encoders to generate its n possible relation representations {q1,…,q n For tasks The target relation r in the query is retrieved 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. Ultimately, 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. In addition, 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 construction 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 for obtaining 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 configured to encode instances according to entity tags using an encoder in the relation extraction module to obtain instance-level representations; calculate the relation probabilities of the instance-level representations using a classifier; design a loss function for the relation extraction module based on the relation probabilities; and output an updated set of instance representations for the sample task using the trained relation extraction module.
[0095] The relationship extraction module 306 is used to dynamically cluster the updated instance representation set of the sample task in the dynamic prototype module to obtain a relationship prototype; perform comparative learning on the relationship prototype according to a preset prototype comparative learning function to obtain an updated relationship 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 a relationship score; and use the relationship with the highest score as the predicted label of the unseen relationship.
[0097] Regarding the specific limitations of a continuous few-sample relationship extraction and unseen relationship detection device, please refer to the limitations 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, memory, network interface, display screen and input device connected via a system bus. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external terminal via 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 covering the display screen, or a key, trackball or touchpad provided on the computer device housing, or an external keyboard, touchpad or mouse.
[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 shown in the figure, or combine certain components, or have a different component arrangement.
[0100] Those skilled in the art will appreciate that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program. 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. By way of illustration and not limitation, RAM is available in various 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 can 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-described embodiments merely represent several implementation methods of the present application. While the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the present invention. It should be noted that a person skilled in the art could make various modifications and improvements without departing from the spirit of the present application, all of which fall within the scope of protection of the present application. Therefore, the scope of protection of the present patent application shall be determined by the appended claims.
Claims
1. A method for continuous small-sample relationship extraction and unseen relationship detection, characterized in that: The method comprises: Obtain 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; the data set includes multiple relationships; each relationship includes text; The relationship extraction module encodes the instance according to the entity tag using an encoder to obtain an instance-level representation; a classifier is used to calculate the relationship probability of the instance-level representation; a loss function of the relationship extraction module is designed based on the relationship probability, and the trained relationship extraction module is used to output an updated instance representation set of the sample task; 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; Dynamically clustering the updated instance representation set of the sample task to obtain a relationship prototype includes: Get the updated instance representation set of the sample task Set the center set C of the cluster r Initially, the set is empty, and the number of clusters m is initialized to 0. After traversing the updated instance of the sample task, each sample in the set is represented. 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, updating the ρ value but keeping 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.
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, including: 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, h is the instance-level representation, and p(y|x) represents the probability of the relationship between the instance and the true label.
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 based on 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 i-th instance x i and the true label y i The relationship probability, N × K represents the task The total number of instances of Represents a sample task A collection of relationships.
5. The method according to claim 1, wherein The preset prototype contrast learning function is: Among them, σ(·) represents the Sigmoid function, sim pos Indicates the prototype cosine similarity between similar pairs, sim neg Represents the prototype cosine similarity between pairs of different classes.
6. 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.
7. 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.
8. A device for continuous small-sample relationship extraction and unseen relationship detection, characterized in that: The device comprises: Constructing a relationship extraction and relationship detection model module for obtaining 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; 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; the data set includes multiple relationships; each relationship includes text; An instance representation updating module is configured 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 for the relation extraction module based on the relation probability, and output an updated instance representation set for the sample task using the trained relation extraction module; The relationship extraction module is used to dynamically cluster the updated instance representation set of the sample task in the dynamic prototype module to obtain the relationship prototype, including: obtaining the updated instance representation set of the sample task Set the center set C of the cluster r Initially, the set is empty, and the number of clusters m is initialized to 0. After traversing the updated instance of the sample task, each sample in the set is represented. 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, updating the ρ value but keeping 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 }, representing a relationship prototype; performing comparative learning on the relationship prototype according to a preset prototype comparative learning function to obtain an updated relationship 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 a relationship score; and use the relationship with the highest score 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