Multi-source prototype fusion-based few-sample relation extraction method and device
Through the multi-source prototype fusion and relationship semantic enhancement methods, the problem of insufficient noise sensitivity and cross-domain adaptability in small sample relationship extraction is solved, efficient and robust relationship recognition and cross-domain migration are achieved, and the annotation cost is reduced.
Patent Information
- Application Number
- CN202510591553.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-08
- Publication Date
- 2025-08-22
AI Technical Summary
The existing small sample relationship extraction methods have strong noise sensitivity, static prototype representation and insufficient cross-domain adaptability, resulting in low recognition accuracy and poor model robustness.
Through multi-source prototype fusion and relational semantic enhancement, the BERT encoder is used to extract entity feature vectors, and the key semantic units are screened in combination with the attention mechanism, multi-source features are dynamically fused, and model parameters are optimized through cross entropy loss.
It improves the recognition accuracy of emerging relationship types under the condition of few samples, supports cross-domain relationship migration, reduces labeling costs, enhances model robustness and cross-domain adaptability, and simplifies model architecture.
Smart Images

Figure CN120524286A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of few-sample relationship extraction, and specifically relates to a few-sample relationship extraction method and device based on multi-source prototype fusion. Background Art
[0002] Few-Shot Relation Extraction (FSRE) is a relation extraction task based on a very small number of labeled samples. Its goal is to train or fine-tune a model using minimal labeled data, enabling it to quickly learn the characteristics of a relation category. Few-Shot Relation Extraction aims to identify new relation types in the target domain using limited labeled samples. It is widely used in fields such as knowledge graph construction and biomedical literature mining. However, existing methods suffer from high noise sensitivity, static prototype representations, and insufficient cross-domain adaptability. Traditional prototype networks construct relation prototypes through simple averaging, which is susceptible to interference from noisy samples in the support set and lacks dynamic adaptation to contextual semantic changes. Recent studies such as TDProto have optimized prototype generation by introducing external knowledge or query interaction. However, their fusion mechanisms often rely on fixed weights or shallow feature interactions, failing to achieve dynamic coordination of multi-source features, resulting in significant prototype bias in cross-domain scenarios. Furthermore, existing methods often use a single classification loss for feature space optimization, limiting the model's robustness to semantic ambiguity. Summary of the Invention
[0003] Aiming at the low accuracy of relationship type recognition and poor model robustness of existing methods, the present invention proposes a few-sample relationship extraction method and device based on multi-source prototype fusion.
[0004] In order to achieve the above-mentioned object of the invention, the technical solution adopted by the present invention is:
[0005] A first aspect of the present invention provides a method for extracting a small number of relations based on multi-source prototype fusion, comprising the following steps:
[0006] S1: Obtain a data set, the data set including a support set, a query set, and a relationship description text, wherein the support set and the query set each include at least two sentences, and the relationship description text is a description of the corresponding relationship name;
[0007] S2: Extract contextual features of entity pairs in the support set and the query set to generate a first entity feature vector for the support set and a second entity feature vector for the query set, wherein the entity pairs include the subject and object in each sentence;
[0008] S3: extracting the global feature vector and the local word vector feature sequence of the relationship description text, performing keyword feature enhancement on the local word vector feature sequence, and then forming an enhanced relationship representation vector with the global feature vector;
[0009] S4: Fusing the first entity feature vector, the second entity feature vector, and the enhanced relationship representation vector to obtain a multi-source fusion feature;
[0010] S5: Input the multi-source fusion features and the second entity feature vector into a classifier, optimize the model parameters through a cross entropy loss function, and obtain a relationship classification result.
[0011] The second aspect of the present invention provides a few-sample relationship extraction device based on multi-source prototype fusion, comprising a memory and a controller that are communicatively connected in sequence, wherein a computer program is stored on the memory, and the controller is used to read the computer program and execute the few-sample relationship extraction method based on multi-source prototype fusion described in the first aspect and any possible one thereof.
[0012] The beneficial effects of the present invention are:
[0013] The present invention performs semantic enhancement through keyword features of relationship description text, and realizes multi-source prototype fusion based on entity feature vectors of support and training sets, effectively improving the recognition accuracy of emerging relationship types under few sample conditions, and supporting cross-domain relationship migration, providing efficient and robust core technical support for knowledge graph construction and intelligent question-answering systems. BRIEF DESCRIPTION OF THE DRAWINGS
[0014] Figure 1 Flowchart of the method of the present invention. DETAILED DESCRIPTION
[0015] The specific embodiments of the present invention are described below to facilitate understanding of the present invention by those skilled in the art. However, it should be clear that the present invention is not limited to the scope of the specific embodiments. For those skilled in the art, as long as various changes are within the spirit and scope of the present invention as defined and determined by the appended claims, these changes are obvious, and all inventions and creations utilizing the concepts of the present invention are protected.
[0016] The first aspect of the present invention provides a method for extracting a few-sample relationship based on multi-source prototype fusion. The method is based on multi-source prototype fusion and contrastive learning. Specifically, Figure 1 As shown, the method includes steps S1 to S5. It should be noted that the step identifiers in this solution are only for the convenience of explaining the method and do not constitute a limitation on the order of steps. The order of steps is based on their language descriptions and the order of signals.
[0017] S1: Obtain a data set, where the data set includes a support set, a query set, and a relationship description text, wherein the support set and the query set each include at least two sentences, and the relationship description text is a description of the corresponding relationship name.
[0018] The data set can be local data, cloud data, or data uploaded in real time.
[0019] Given a relation description text t i , then t i It is a description of the relationship name i.
[0020] S2: Extract contextual features of entity pairs in the support set and the query set to generate a first entity feature vector of the support set and a second entity feature vector of the query set, wherein the entity pairs include the subject and the object in each sentence.
[0021] Entity pairs in a sentence include a subject and an object. Each subject and object in a sentence constitutes an entity pair. To this end, this step first extracts the hidden states of the subject and object for each sentence in the support set and query set, respectively. The hidden states of the subject and object in the support set are then concatenated, along with those in the query set. This yields the first entity feature vector for the support set and the second entity feature vector for the query set.
[0022] Among them, the hidden state of the entity can be extracted using the BERT encoder.
[0023] The entity feature vector e is:
[0024]
[0025] in, are the hidden states of the subject and the object respectively; Concat(.;.) means concatenating the two; R 2d is the dimension of the feature vector, e includes the first entity feature vector and the second entity feature vector Q q .
[0026] S3: extracting the global feature vector and the local word vector feature sequence of the relationship description text, performing keyword feature enhancement on the local word vector feature sequence, and then forming an enhanced relationship representation vector with the global feature vector.
[0027] This step performs semantic enhancement on the relationship description text, uses an attention mechanism to dynamically select key semantic units, and fuses global features with local keyword features to construct a denoised enhanced relationship representation. Specifically, this step can be implemented through steps S31 to S34.
[0028] Step S31: concatenate the relationship name and the description text to obtain a concatenated text.
[0029] Step S32: Input the concatenated text into the encoder to extract the global features of the relationship description text and local word vector feature sequence
[0030] The encoder in this step is the BERT encoder.
[0031] Step S33: Determine keyword enhancement features based on the local word vector feature sequence.
[0032] Local word vector feature sequence Where, ∈R l×d Represents a local word vector feature sequence The vector space dimension is l×d, where l is the length of the local word vector sequence and d is the BERT hidden layer dimension.
[0033] For the local word vector feature sequence, first calculate the attention score of each word in the local word vector feature sequence; then filter the key semantic units through attention weight allocation to generate keyword enhancement features
[0034] In this step, the attention score of the vocabulary can be calculated using a two-layer neural network.
[0035] in,
[0036]
[0037] Where t∈{1,…,l}, l is the length of the local word vector sequence, is the calculated attention score of the i-th word, is the word vector at the tth position in the local word vector feature sequence, Index Operation R d The dimension of the hidden layer is d, and W1 and W2 are both trainable parameter matrices.
[0038] Step S34: Combine the global features and keyword enhanced features to obtain the enhanced relationship representation vector R i .
[0039] Specifically,
[0040] S4: For the first entity feature vector The second entity eigenvector Q q and the enhanced relation representation vector R iFusion is performed to obtain multi-source fusion features.
[0041] This step can construct a relationship-aware prototype and a query-driven prototype through a dual attention mechanism based on relationship awareness and query-driven, and dynamically fuse multi-source features through adaptive weight coefficients to generate context-adaptive multi-source fusion features. Specifically, this step includes steps S41 to S43.
[0042] Step S41: Calculate the first entity feature vector of the support set and the enhanced relation representation vector R i The semantic matching score of the support set is weighted and aggregated based on the attention weight to generate the relationship-aware prototype.
[0043] Specifically, semantic matching score for:
[0044]
[0045] Where d is the hidden layer dimension of BERT output.
[0046] Relationship-aware prototype for:
[0047]
[0048] Where K is the number of the first entity feature vectors in the support set, Softmax() refers to the softmax calculation,
[0049] Step S42: Calculate the first entity feature vector and the second entity eigenvector Q q The negative Euclidean distance similarity is used to generate query-driven prototypes.
[0050] Specifically, we first calculate the negative Euclidean distance similarity, then pool and normalize the similarity to generate a query-driven prototype.
[0051] Negative Euclidean distance similarity for:
[0052]
[0053] Query-driven prototypes for:
[0054]
[0055] Where |Q| is the number of second entity feature vectors in the query set.
[0056] Step S43: performing linear weighted fusion on the relationship-aware prototype, the query-driven prototype, and the enhanced relationship representation vector to obtain a multi-source fusion feature.
[0057] Multi-source fusion feature P i for:
[0058]
[0059] Among them, λ1, λ2, and λ3 are learnable adaptive weight parameters, which are optimized through back propagation.
[0060] S5: Input the multi-source fusion features and the second entity feature vector into a classifier, optimize the model parameters through a cross entropy loss function, and obtain a relationship classification result.
[0061] Specifically, this step first calculates the similarity score s between the multi-source fusion feature and the second entity feature vector i (Q q ),
[0062] represents the negative squared Euclidean distance.
[0063] Optimize the cross entropy loss function L ce , the relationship category result is determined according to the maximum prediction probability in the cross entropy loss function, where the cross entropy loss function L ce for:
[0064]
[0065] Where N is the number of relationship types to be classified in the task, is the predicted probability, is the true label.
[0066] The final output relationship category result is the category with the highest predicted probability.
[0067] The method of the present invention significantly reduces the dependence on manually annotated data through the dynamic fusion of multi-source prototypes and the relationship semantic enhancement mechanism, thereby reducing the annotation costs in professional fields such as biomedicine and finance; it screens key semantic units based on attention to improve the robustness to noise samples and the discriminability of prototype representations; through adaptive weight fusion and residual optimization, it enhances the model's cross-domain semantic adaptability and effectively identifies low-frequency relationships and ambiguous expressions; it relies only on cross-entropy loss to simplify the model architecture and improve deployment efficiency, and can be seamlessly integrated into scenarios such as knowledge graph completion and intelligent question and answer, providing efficient and reliable relationship extraction support for applications such as drug discovery and industrial chain analysis.
[0068] In order to facilitate the understanding of this solution, an example is given to illustrate it.
[0069]
Experimental example / Verification example
[0070] The FewRel 1.0 benchmark dataset was selected as the experimental object. This dataset contains 64 training relations, 16 verification relations, and 20 test relations, each of which contains 700 annotated instances. The text of the support set and query instances are all from Wikipedia, covering general fields (such as geography, people) and some biomedical field relations. The specific test examples of this embodiment are as follows: Training Example 1:
[0071] Support set (3-way 2-shot):
[0072] Relation A(capital_of):
[0073] 1.Berlin is the capital of Germany.
[0074] 2.Paris is the capital of France.
[0075] Relationship B (founder_of):
[0076] 3.Bill Gates founded Microsoft.
[0077] 4. Steve Jobs co-founded Apple Inc.
[0078] Relation C(author_of):
[0079] 5.Leo Tolstoy wrote War and Peace.
[0080] 6.JKRowling authored Harry Potter.
[0081] Query example:
[0082] Tokyo is the capital of Japan.
[0083] Training Example 2:
[0084] Support set (5-way 1-shot):
[0085] Relation D(drug_treats):
[0086] 1.Aspirin is used to treat headache.
[0087] Relation E(located_in):
[0088] 2.The Louvre Museum is located in Paris.
[0089] Test data example:
[0090] Test example 1 (10-way 1-shot):
[0091] Support set: Contains 10 relationships (such as parent_of, manufactured_by, symptom_of), and provides 1 instance for each relationship.
[0092] Example query: Pfizer manufactures COVID-19 vaccine.
[0093] Test Example 2 (5-way 5-shot):
[0094] Support set: Contains 5 types of biomedical relationships (such as gene_associated, protein_interacts), and provides 5 instances for each relationship.
[0095] Example query: CRISPR-Cas9 is associated with gene editing.
[0096] Method implementation details:
[0097] S1: Entity encoding, using BERT-base to extract the hidden state of the entity pair (head entity and tail entity) and concatenate them into a feature vector.
[0098] S2: Relationship semantic enhancement: BERT is used to generate a global CLS vector and a local keyword vector for the relationship description text (such as "capital_of"), which are then fused into an enhanced representation after attention weighting.
[0099] S3: Multi-source prototype fusion
[0100] Relation-aware prototype: Generates prototypes based on the semantic matching weights between support set instances and relation descriptions.
[0101] Query-driven prototypes: Prototypes are aggregated weighted by the negative Euclidean distance similarity between the query instance and the support set.
[0102] Dynamic fusion: Adaptive weight coefficients fuse relationship perception, query drive, and relationship description prototypes to output the final prototype.
[0103] S4: Classification decision, input the fused multi-source prototype and query instance features into the classifier, and output the relationship category prediction result.
[0104] Test case analysis:
[0105] Taking test example 1 (query instance "Pfizer manufactures COVID-19 vaccine") as an example, the classification process of the proposed invention in the 10-way 1-shot scenario is analyzed:
[0106] 1. Entity encoding and relationship semantic enhancement
[0107] Entity feature extraction:
[0108] The entity pair (Pfizer, COVID-19 vaccine) in the query instance is extracted through the BERT encoder to extract the head and tail entity hidden states and spliced into a feature vector.
[0109] Relational semantic enhancements:
[0110] Perform semantic enhancement on the description text of the target relationship "manufactured_by" ("A company produces a product"):
[0111] (1) BERT encoding generates the global CLS vector h CLS With local token feature H tok .
[0112] (2) Filter keywords (such as "produces") through the attention mechanism to generate keyword enhancement vector h key , concatenated with the CLS vector to form the enhanced relation representation R i .
[0113] 2. Multi-source prototype generation and fusion
[0114] Relation-aware prototype: supports 1 instance of “manufactured_by” in the set (“Toyota manufactures Prius”) with enhanced relation representation R i The semantic matching score is calculated by aggregating supporting instance features based on the Softmax weights to generate relation-aware prototypes.
[0115] Query-driven prototype: Computing query instances Qq and supporting instances The negative Euclidean distance, similarity scores are pooled and normalized to generate query-driven prototypes.
[0116] Dynamic Fusion: Prototyping Relationship Perception Query-driven prototypes and relation description R i , fused by adaptive weights.
[0117] 3. Classification Decision
[0118] The similarity score between the query instance and the fusion prototype is calculated. After comparing the 10 relationship prototypes, "manufactured_by" has the highest score, and the model outputs the correct classification.
[0119] During the training phase, the model was optimized using cross-entropy loss. Adam was selected as the optimizer, with a total training iteration count of 20,000, a validation iteration count of 1,000, a batch size of 4, and an initial learning rate of 1e-5.
[0120] The method of the present invention can be applied to texts of various types in various fields, such as biomedicine, finance, justice, scientific and technological literature, etc., and can efficiently extract relationships such as drug-disease treatment relationships, enterprise-industry chain associations, legal clauses-case associations, technology-patent ownership, etc. This method has important application value in multiple scenarios in the industrial sector. Biomedical field: quickly identify the therapeutic relationship between new drugs and target diseases from scientific research literature, and accelerate drug development and clinical trial design; financial field: extract enterprise-supply chain relationships in unstructured financial reports and news, and support industry chain risk analysis and investment decisions; judicial field: analyze the relationship between the parties involved in the case in legal documents, and assist in the construction of the case evidence chain and judgment reasoning; scientific and technological intelligence mining: identify the technology-inventor ownership relationship from patent texts, and support intellectual property management and competition analysis. For example, in the construction of biomedical knowledge graphs, this method only requires a small amount of labeled samples to accurately extract the relationship between rare diseases and gene mutations, significantly reducing the cost of manual labeling and improving the efficiency of graph updates.
[0121] Based on the above method, the second aspect of the present invention provides a small sample relationship extraction device based on multi-source prototype fusion, including a memory and a controller connected in sequence, a computer program stored on the memory, and the controller is used to read the computer program and execute the first aspect and any one of the possible methods described in the small sample relationship extraction method based on multi-source prototype fusion. For example, the memory may include, but is not limited to, a random access memory (RAM), a read-only memory (ROM), a flash memory (FlashMemory), a first-in-first-out memory (FIFO) and or a first-in-last-out memory (FILO), etc.; the controller may be limited to a microcontroller of the STM32F105 series. In addition, the computer device may also include, but is not limited to, a power supply unit, a display screen and other necessary components.
[0122] Those skilled in the art will appreciate that the embodiments described herein are intended to help readers understand the principles of the present invention, and it should be understood that the scope of protection of the present invention is not limited to such specific descriptions and embodiments. Those skilled in the art can make various other specific variations and combinations based on the technical teachings disclosed in the present invention without departing from the essence of the present invention, and such variations and combinations are still within the scope of protection of the present invention.
Claims
1. A few-sample relationship extraction method based on multi-source prototype fusion, characterized by: The following steps are involved: S1: Obtain a data set, the data set including a support set, a query set, and a relationship description text, wherein the support set and the query set each include at least two sentences, and the relationship description text is a description of the corresponding relationship name; S2: Extract contextual features of entity pairs in the support set and the query set to generate a first entity feature vector for the support set and a second entity feature vector for the query set, wherein the entity pairs include the subject and object in each sentence; S3: extracting the global feature vector and the local word vector feature sequence of the relationship description text, performing keyword feature enhancement on the local word vector feature sequence and then forming an enhanced relationship representation vector with the global feature vector; S4: Fusing the first entity feature vector, the second entity feature vector, and the enhanced relationship representation vector to obtain a multi-source fusion feature; S5: Input the multi-source fusion features and the second entity feature vector into a classifier, optimize the model parameters through a cross entropy loss function, and obtain a relationship classification result.
2. The method for extracting few-sample relationships based on multi-source prototype fusion according to claim 1, characterized in that: The extracting context features of entity pairs in the support set and the query set to generate a first entity feature vector of the support set and a second entity feature vector of the query set includes: Extract the hidden states of the subject and object of each sentence in the support set and query set respectively; Concatenate the hidden state of the subject and the hidden state of the object in the support set to obtain the feature vector of the first entity; The hidden state of the subject and the hidden state of the object of the query set are concatenated to obtain the feature vector of the second entity.
3. The method for extracting few-sample relations based on multi-source prototype fusion according to claim 1, characterized in that: The extracting of the global feature vector and the local word vector feature sequence of the relationship description text, performing keyword feature enhancement on the local word vector feature sequence and then forming an enhanced relationship representation vector with the global feature vector, includes: Concatenating the relationship name and the description text to obtain a concatenated text; Inputting the concatenated text into an encoder to extract global features and local word vector feature sequences of the relationship description text; determining keyword enhancement features based on the local word vector feature sequences; The global features and the keyword enhanced features are concatenated to obtain an enhanced relationship representation vector.
4. The method for extracting few-sample relations based on multi-source prototype fusion according to claim 3, characterized in that: Determining the keyword enhancement feature according to the local word vector feature sequence includes: Calculate the attention score of each word in the local word vector feature sequence; Key semantic units are screened by allocating attention weights to generate keyword-enhanced features.
5. The method for extracting few-sample relations based on multi-source prototype fusion according to claim 1, characterized in that: The fusing of the first entity feature vector, the second entity feature vector and the enhanced relationship representation vector includes: Calculating a semantic matching score between the first entity feature vector of the support set and the enhanced relationship representation vector and aggregating the support set features based on the attention weight to generate a relationship-aware prototype; The negative Euclidean distance similarity between the first entity feature vector and the second entity feature vector is calculated to generate a query-driven prototype; and a linear weighted fusion is performed on the relationship-aware prototype, the query-driven prototype and the enhanced relationship representation vector to obtain a multi-source fusion feature.
6. The method for extracting few-sample relations based on multi-source prototype fusion according to claim 5, characterized in that: The multi-source fusion feature obtained by linearly weighted fusion of the relationship-aware prototype, the query-driven prototype and the enhanced relationship representation vector is: Among them, λ1, λ2, λ3 are learnable adaptive weight parameters, P i It is a multi-source fusion feature. For query-driven prototypes, R i To enhance the relationship representation vector, Prototype for relationship perception.
7. The method for extracting few-sample relationships based on multi-source prototype fusion according to claim 1, characterized in that: The step of inputting the multi-source fusion feature and the second entity feature vector into a classifier, optimizing model parameters through a cross entropy loss function, and obtaining a relationship classification result includes: Calculating a similarity score between the multi-source fusion feature and the second entity feature vector; Optimize the cross entropy loss function L ce , the relationship category result is determined according to the maximum prediction probability in the cross entropy loss function, where the cross entropy loss function L ce for: Where N is the number of relationship types to be classified in the task, is the predicted probability, is the true label, and |Q| is the number of second entity feature vectors in the query set.
8. A device for extracting a small number of relations based on multi-source prototype fusion, comprising a memory and a controller in sequential communication connection, wherein the memory stores a computer program, characterized in that: The controller is used to read the computer program and execute the few-sample relationship extraction method based on multi-source prototype fusion described in any one of claims 1-7.