Industrial small sample relation extraction method based on prototype network
By introducing the attention mechanism and knowledge distillation method into the prototype network, the problems of information redundancy and poor data quality in industrial small sample relationship extraction are solved, the classification accuracy of the model is improved, and a more stable relationship extraction effect is achieved.
Patent Information
- Application Number
- CN202410632407.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-21
- Publication Date
- 2024-08-30
AI Technical Summary
It is difficult to accurately identify relationships through small sample relationship extraction in the industrial field, and prototype networks that introduce external information can easily lead to information redundancy, making it difficult for traditional models to stably generate category prototypes.
The attention mechanism-based relational attention prototype generation method and knowledge distillation method are used to select important external information knowledge through the attention mechanism, reduce redundant information, and improve the model's accuracy by minimizing the distance between public data sets and industrial data sets. Classification accuracy.
It effectively avoids prototype deviation and improves the classification accuracy of the model. Especially when the quality of industrial data is poor, it significantly improves the accuracy of relationship extraction.
Smart Images

Figure CN118569251A
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of computer natural language processing, and in particular to an industrial small sample relationship extraction method based on a prototype network. Background Art
[0002] In recent years, the demand for intelligent technology in the industrial field has continued to grow, and industrial relationship extraction has gradually become one of the core tasks in the digital transformation of the industry. However, the data generated and accumulated in the industrial field often has a semi-structured format and complex relationships. It is difficult to accurately identify the relationships in the industry when using traditional relationship extraction methods.
[0003] As an effective small-sample relationship extraction method, the prototype network can represent the entire category with only a small amount of data. Some recent studies have found that adding external information (relationship description) to the prototype network can increase the stability of the category prototype vector. However, in industrial scenarios, manually recorded industrial relationship descriptions usually contain a large amount of professional terms and industry-specific language. Unprocessed relationship descriptions are easily integrated into the prototype network as external data and can easily lead to prototype deviation. In addition, industrial data with added relationship descriptions is still difficult to support the generation of stable category prototypes relying solely on the information it contains. With the rapid development of industrial digitalization today, an efficient relationship extraction strategy is urgently needed.
[0004] In summary, there are two main problems in industrial small sample relationship extraction: the prototype network that introduces external information will cause information redundancy; the quality of industrial data is poor, and traditional models are difficult to stably predict categories. Summary of the invention
[0005] In view of the defects of the prior art, the present invention proposes an industrial small sample relationship extraction method based on prototype network, which consists of a relationship attention prototype generation method based on attention mechanism and a prototype distillation method based on knowledge distillation. The attention mechanism selects important knowledge of external information to ensure that the model avoids paying attention to redundant information in the relationship description during the prototype generation process. Drawing on the idea of knowledge distillation, the classification accuracy of the model is improved by minimizing the distance between the category prototypes of the public dataset and the category prototypes of the industrial dataset.
[0006] In order to achieve the above object, the present invention provides an industrial small sample relationship extraction method based on a prototype network, comprising the following steps:
[0007] (1) Obtain industrial and public datasets;
[0008] Including a plurality of categories, each of the categories contains a plurality of sentences, connecting the class name and the class description of each of the categories in the industrial data set and the public data set to obtain an industrial relationship description and a public relationship description;
[0009] Dividing the industrial data set into an industrial support set and an industrial query set, and dividing the public data set into a public support set;
[0010] (2) constructing two identical attention-based relational prototype generation models, corresponding to the teacher model and the student model respectively; the attention-based relational prototype generation model includes a first encoder and an attention mechanism;
[0011] Input the sentences in the public support set and their corresponding public relationship descriptions into the teacher model, and input the sentences in the industrial support set and their corresponding industrial relationship descriptions into the student model, to obtain a public relationship attention prototype representation and an industrial relationship attention prototype representation;
[0012] (3) Constructing a prototype distillation model based on knowledge distillation, including a second encoder and a classifier, performing knowledge distillation on the public relationship attention prototype representation and the industrial relationship attention prototype representation, inputting the sentences in the industrial support set into the prototype distillation model based on knowledge distillation, and obtaining a prediction result based on the industrial relationship attention prototype representation after knowledge distillation.
[0013] Furthermore, the first encoder is a Bert encoder.
[0014] Furthermore, the specific process of the relationship attention prototype generation model based on the attention mechanism is as follows:
[0015] (2.1) Inputting the input sentence into the first encoder to obtain a sentence global feature representation and a sentence local feature representation; inputting the relationship description corresponding to the input sentence into the first encoder to obtain a relationship global feature representation and a relationship local feature representation; the sentence global feature representation and the relationship global feature representation correspond to the CLS vector output by the first encoder, and the sentence local feature representation and the relationship local feature representation correspond to the hidden layer features output by the first encoder;
[0016] Generate entity fusion feature representation by connecting hidden layer features corresponding to the start tags of the head and tail entities in the input sentence;
[0017] (2.2) Feature fusion is performed based on the attention mechanism to obtain the relational attention prototype representation;
[0018] (2.2.1) obtaining an attention output according to the sentence global feature representation and the relationship global feature representation;
[0019]
[0020] in: and W represents the jth sentence global feature and the jth relationship global feature of the i-th category, i=1, 2, 3, ..., N, j=1, 2, 3, ..., K, N represents the total number of categories, K represents the total number of sentences; W q and W k represents the weight coefficient of the query matrix and the key matrix; d represents the embedding dimension;
[0021] (2.2.2) performing Softmax normalized weighted summation on all the attention outputs in each class to obtain multi-instance attention outputs;
[0022]
[0023] in: represents the multi-instance attention output; V represents the value vector;
[0024] (2.2.3) Concatenate the multi-instance attention output with the relational local relation feature representation to obtain the relational attention feature fusion representation P attrel ;
[0025]
[0026] in: represents the multi-instance attention output representation, Representing the local relation feature representation of the relation; Represents a splicing operation;
[0027] (2.2.4) directly adding the relationship attention feature fusion representation and the entity fusion feature representation to obtain a relationship attention prototype representation;
[0028] P final =P attrel +P ent
[0029] Where: P final Indicates that the relationship concerns the prototype representation; P attrel represents the relationship-focused feature fusion representation; P ent represents the fused feature representation.
[0030] Furthermore, the relationship attention prototype representation obtained by inputting the sentences in the public support set and their corresponding public relationship descriptions into the teacher model is the public relationship attention prototype representation; the relationship attention prototype representation obtained by inputting the sentences in the industrial support set and their corresponding industrial relationship descriptions into the student model is the industrial relationship attention prototype representation.
[0031] Furthermore, knowledge distillation is performed on the public relation concern prototype representation and the industrial relation concern prototype representation as follows:
[0032] Calculate distillation losses;
[0033]
[0034] in: Representing the public relations concern prototype representation, represents the industrial relationship attention prototype representation; PD represents the distillation loss function;
[0035] Minimize the distillation loss to ensure that the student prototype simulates the teacher prototype, thereby achieving knowledge distillation and obtaining the industrial relationship attention prototype representation after knowledge distillation
[0036] Furthermore, the distillation loss function uses a mean square error loss function.
[0037] Furthermore, the prototype distillation module based on knowledge distillation is specifically:
[0038] Inputting the sentences in the industrial query set into the second encoder, the CLS vector output by the second encoder is the obtained feature representation of the sentences in the industrial query set;
[0039] The feature representation is input into the classifier, the classifier uses vector dot product to calculate the distance between the feature representation of the sentence in the industrial query set and the industrial relationship attention prototype representation after each knowledge distillation, selects the category with the closest distance as the prediction, and uses Softmax function to calculate the probability distribution;
[0040]
[0041] Where: Q represents the feature representation of the sentence in the industrial query set, represents the industrial relation-attention prototype representation after knowledge distillation, and dp represents the dot product method.
[0042] Furthermore, the cross entropy loss is used as the loss function to obtain the industrial classification loss;
[0043]
[0044] The total loss is:
[0045] Loss = L PD +L cla
[0046] Where: Loss represents the total loss; L cla Indicates the industrial classification loss; L PO represents the distillation loss; N represents the total number of categories in the industrial query set.
[0047] Furthermore, the second encoder is a Bert encoder.
[0048] Beneficial effects of the present invention:
[0049] 1. Aiming at the prototype deviation problem caused by introducing relationship description, the present invention proposes a relationship-attention prototype network algorithm based on the attention mechanism. The attention mechanism selects important knowledge of external information to ensure that the model avoids paying attention to redundant information in the relationship description during the prototype generation process.
[0050] 2. Aiming at the problem of scarcity of domain knowledge during prototype generation, the present invention draws on the idea of knowledge distillation and proposes a prototype distillation algorithm based on knowledge distillation. By minimizing the distance between the category prototypes of the public dataset and the category prototypes of the industrial dataset, compared with traditional knowledge distillation, prototype distillation considers the relative position and characteristics between categories more, reduces the dependence on specific predictions, and improves the classification accuracy of the model. BRIEF DESCRIPTION OF THE DRAWINGS
[0051] Figure 1 The figure is a flow chart of an industrial small sample relationship extraction method based on a prototype network according to an embodiment of the present invention.
[0052] Figure 2 Schematic diagram of the process of generating a relationship-focused prototype model based on the attention mechanism in an embodiment of the present invention.
[0053] Figure 3 Schematic diagram of ablation experiment results according to an embodiment of the present invention. DETAILED DESCRIPTION
[0054] The present invention is described in detail below with reference to the accompanying drawings and specific embodiments.
[0055] like Figure 1 , Figure 2 As shown, an embodiment of the present invention provides a method for extracting industrial small sample relations by relation-focused prototype distillation based on a prototype network, comprising:
[0056] S101. Obtain industrial data sets and public data sets.
[0057] An industrial data set is obtained and divided into three parts: training set, validation set and test set. To facilitate model training, the traditional small sample learning task setting is used, and the training set is divided into an industrial support set and an industrial query set. Specifically, N categories are randomly selected from the industrial data set, each category has K instances (sentences) as the industrial support set, and then q instances (sentences) are selected from the remaining data of the N categories to construct the industrial query set.
[0058] Get a public dataset and randomly select N categories, each with K instances (sentences) as the public support set.
[0059] The class name and class description of each category in the industrial dataset and the public dataset are connected to obtain the industrial relationship description and the public relationship description.
[0060] S102. Construct two identical relation-attention prototype generation models based on the attention mechanism, corresponding to the teacher model and the student model respectively; the relation-attention prototype generation model based on the attention mechanism includes a first encoder and an attention mechanism.
[0061] The first encoder is a BERT encoder, such as Figure 2 As shown in the figure, the specific process of the relational attention prototype generation model based on the attention mechanism is as follows:
[0062] Input the input sentence into the first encoder to obtain the global feature representation x of the sentence glo (CLS vector output by the first encoder) Input the relation description corresponding to the input sentence into the first encoder to obtain the relation global feature representation R glo (CLS vector output by the first encoder), relational local feature representation R loc (Hidden layer features output by the first encoder).
[0063] The entity fusion feature representation R is generated by connecting the hidden layer features corresponding to the start tokens of the head and tail entities in the input sentence ent ;
[0064] By introducing sentence feature representation during feature fusion and introducing an attention mechanism, we use a combination of global and local feature representations to promote the interaction between relation description features and sentence features and capture rich semantic relations. To ensure that the network can directly access the relation enhancement information without error, we simply add the obtained relation attention prototype to the category prototype.
[0065] Specifically, first obtain the sentence global feature representation x glo , Relationship global feature representation R glo The attention output A ij :
[0066]
[0067] in: and W represents the jth sentence global feature and relation global feature of the i-th category, i = 1, 2, 3, ..., N, j = 1, 2, 3, ..., K; W q and W k represents the weight coefficients of the query matrix and the key matrix; d represents the embedding dimension; the square root term in the denominator is used to scale the attention score to prevent the gradient from disappearing or exploding.
[0068] Next, the traditional method is used to calculate the attention output. The attention score is a Softmax normalized weighted sum of multiple instances in each class to obtain a multi-instance attention output, which is then averaged to generate the final attention output. This contains the sentence weights.
[0069]
[0070] Where: V represents the value vector, Represents a concatenation operation.
[0071] Then, the final attention output under the sentence constraint is Local relation feature representation Combined, we get the relation-attention feature fusion representation P attrel . Use the concatenation operation directly connect and To ensure dimensionality consistency during the prototype fusion step:
[0072]
[0073] Finally, the relation-attention feature is fused to represent P attrel Fusion feature representation P ent Directly add to get the industrial relations attention prototype P final , to avoid adding extra parameters:
[0074] P final =P attrel +P ent
[0075] The sentences in the public support set and their corresponding public relationship descriptions are input into the teacher model of the relation-attention prototype generation model based on the attention mechanism, and the sentences in the industrial support set and their corresponding industrial relationship descriptions are input into the student model of the relation-attention prototype generation model based on the attention mechanism to obtain the public relationship attention prototype representation and the industrial relationship attention prototype representation.
[0076] S103. Construct a prototype distillation model based on knowledge distillation, including a second encoder and a classifier, perform knowledge distillation on the public relationship focus prototype representation and the industrial relationship focus prototype representation, input the sentences in the industrial support set into the prototype distillation model based on knowledge distillation, and obtain a prediction result based on the industrial relationship focus prototype representation after knowledge distillation.
[0077] Focus on prototypes for public relations Relationship with industry focuses on prototypes Calculate distillation loss:
[0078]
[0079] in: The public relations attention prototype representation output by the teacher prototype, The industrial relation attention prototype representation output by the student prototype. PD represents the distillation loss function, and the mean square error loss function is selected. For each element of the student prototype, the prototype distillation loss L associated with the teacher prototype is calculated. PD In this process, the similarity loss L between the teacher prototype and the student prototype is PD By minimizing this loss, we can ensure that the student prototype simulates the teacher prototype as much as possible, thus achieving the purpose of knowledge distillation.
[0080] The second encoder is the Bert encoder. The prototype distillation module based on knowledge distillation is as follows:
[0081] The sentences in the industrial query set are input into the second encoder, and the CLS vector output by the second encoder is the feature representation of the sentences in the industrial query set.
[0082] The feature representation is input into the classifier. The classifier uses the vector dot product to calculate the distance between the feature representation of the sentence in the industrial query set and the representation of each industrial relation prototype after distillation. The relation class closest to the class prototype is selected as the prediction, and the Softmax function is used to calculate the probability distribution. It uses the distance calculation result to construct a probability distribution representing the probability of each category:
[0083]
[0084] Where: Q represents the feature representation of the sentence in the industrial query set, represents the industrial relational attention prototype representation after knowledge distillation, and dp represents the dot product method.
[0085] Subsequently, the cross entropy loss is adopted as the loss function to obtain the industrial classification loss.
[0086]
[0087] Where: N represents the total number of classes.
[0088] Finally, the prototype distillation loss is added to the industrial classification loss to complete the prototype distillation:
[0089] Loss = L PD +L cla
[0090] In order to further verify the performance of the embodiments of the present invention, the verification experiment was conducted using PyTorch and run on a system equipped with a 12th generation Intel(R) Core(TM) i7-12700K CPU and an NVIDIA GeForce RTX 4090 GPU with 32GB VRAM. During the training process, the number of training iterations was configured to 30,000, the number of verification iterations was 3000, and the batch size was set to 4.
[0091] Throughout the training process, the present invention divides the data set into three parts: training set, validation set, and test set. The training set is used to adjust the model to enhance its fit with the data set. The validation set is used to evaluate the performance of the model. After each round of training, the model is tested on the validation set to determine and retain the model with the best performance. When the model is trained, the test set is used to evaluate the performance of the model.
[0092] The evaluation index of the present invention follows the traditional small sample learning task setting (N way Kshot). Specifically, N categories are randomly selected from the data set, each category has K instances as the support set, and then q instances are selected from the remaining data of the N categories to construct the query set. The model is then trained using the instances in the support set, and the performance is evaluated using the instances in the query set. The indicator used in the evaluation is accuracy, which refers to the ratio of the number of samples correctly classified by the classifier to the total number of samples, which can be represented by the true positive examples (TP) and true negative examples (TN) in the confusion matrix. The formula is as follows:
[0093]
[0094] The present invention designs and uses a fault detection dataset of a certain automobile manufacturer to verify the accuracy of the model. The dataset contains 6 classes: NS, UNS, ATTR, FAL, OPT and POS, each of which is accompanied by a specific class description, as described in Table 1. Due to the particularity of industrial data, the sample size of each class in the dataset is unbalanced, which greatly increases the complexity of classification and detection tasks.
[0095] Table 1
[0096]
[0097] The baseline models compared in the experiment are as follows:
[0098] SNAIL is a meta-learning model that utilizes a temporal convolutional neural network and an attention module to quickly learn from past experiences.
[0099] MTB: Pre-trained on top of the existing BERT model using their proposed “match the blank” task.
[0100] Siamese proposes a Siamese neural network that can naturally rank inputs and make accurate predictions with only a single example of each new category.
[0101] BERT-PAIR: A method for evaluating similarity of sentence pairs.
[0102] Proto-BERT: The original prototypical network without additional relational information.
[0103] SimpleFSRE: proposes a strategy to directly add relation label information to prototypes.
[0104] HCRP: Introducing a contrastive learning strategy and enhancing prototypes using relation label information.
[0105] Table 2 gives the accuracy results of each model:
[0106] Table 2
[0107]
[0108] From the table above, we can see that the prototype distillation model significantly outperforms the existing small-sample relation extraction models. In the 5-way 1-shot scenario, the accuracy is improved by 5.55% (%) compared to the accuracy of the current state-of-the-art model SimpleFSRE. This clearly demonstrates the powerful ability of prototype distillation in the case of limited samples.
[0109] In order to gain a deeper understanding of the impact of the model on the prototype and evaluate the performance of the model under different tasks. During the test, N*Batchsize*K supporting instance prototypes were obtained. Case analysis of the task was performed under the 5way setting, and the iteration count was set to 1000 and a scatter plot was created. High-dimensional arrays are difficult to visualize directly because the visual system cannot effectively understand data in high-dimensional space. By reducing the high-dimensional array to a two-dimensional array, the data is projected into a lower-dimensional space, making it easier to visualize and understand it.
[0110] like Figure 3 As shown in Figure 2. Compared with the traditional model, the category instances generated using the patented model show stronger clustering and better representation of specific categories in the 5way1shot setting. Although some instances overlap, most categories show clear separation. Similarly, Figure 3 As shown, under the 5way 5shot setting, the model without using this patent model performs poorly in some categories, while the model using this patent maintains excellent clustering effect.
[0111] By comparing the clustering of the traditional model and the patented model, the effect of model training is evaluated, the impact on the stability of model training is explored, and the mechanism of action of the patented model is deeply understood, which helps guide subsequent model design and improvement.
[0112] The preferred specific embodiments of the present invention are described in detail above. It should be understood that a person skilled in the art can make many modifications and changes based on the concept of the present invention without creative work. Therefore, any technical solution that can be obtained by a person skilled in the art through logical analysis, reasoning or limited experiments based on the concept of the present invention on the basis of the prior art should be within the scope of protection determined by the claims.
Claims
1. A method for extracting industrial small sample relations based on prototype network, characterized in that: The steps include: (1) Obtain industrial and public datasets; Including a plurality of categories, each of the categories contains a plurality of sentences, connecting the class name and the class description of each of the categories in the industrial data set and the public data set to obtain an industrial relationship description and a public relationship description; Dividing the industrial data set into an industrial support set and an industrial query set, and dividing the public data set into a public support set; (2) constructing two identical attention-based relational prototype generation models, corresponding to the teacher model and the student model respectively; the attention-based relational prototype generation model includes a first encoder and an attention mechanism; Input the sentences in the public support set and their corresponding public relationship descriptions into the teacher model, and input the sentences in the industrial support set and their corresponding industrial relationship descriptions into the student model, to obtain a public relationship attention prototype representation and an industrial relationship attention prototype representation; (3) Constructing a prototype distillation model based on knowledge distillation, including a second encoder and a classifier, performing knowledge distillation on the public relationship attention prototype representation and the industrial relationship attention prototype representation, inputting the sentences in the industrial support set into the prototype distillation model based on knowledge distillation, and obtaining a prediction result based on the industrial relationship attention prototype representation after knowledge distillation.
2. The industrial small sample relationship extraction method based on prototype network according to claim 1 is characterized by: The first encoder is a Bert encoder.
3. The industrial small sample relationship extraction method based on prototype network according to claim 1 is characterized by: The specific process of the relationship attention prototype generation model based on the attention mechanism is as follows: (2.1) Inputting the input sentence into the first encoder to obtain a sentence global feature representation and a sentence local feature representation; inputting the relationship description corresponding to the input sentence into the first encoder to obtain a relationship global feature representation and a relationship local feature representation; the sentence global feature representation and the relationship global feature representation correspond to the CLS vector output by the first encoder, and the sentence local feature representation and the relationship local feature representation correspond to the hidden layer features output by the first encoder; Generate entity fusion feature representation by connecting hidden layer features corresponding to the start tags of the head and tail entities in the input sentence; (2.2) Feature fusion is performed based on the attention mechanism to obtain the relational attention prototype representation; (2.2.1) obtaining an attention output according to the sentence global feature representation and the relationship global feature representation; in: and W represents the jth sentence global feature and the jth relationship global feature of the i-th category, i=1, 2, 3, ..., N, j=1, 2, 3, ..., K, N represents the total number of categories, K represents the total number of sentences; W q and W k represents the weight coefficient of the query matrix and the key matrix; d represents the embedding dimension; (2.2.2) performing Softmax normalized weighted summation on all the attention outputs in each class to obtain multi-instance attention outputs; Where: P i attglo represents the multi-instance attention output; V represents the value vector; (2.2.3) Concatenate the multi-instance attention output with the relational local relation feature representation to obtain the relational attention feature fusion representation P attrel ; Where: P i attglo represents the multi-instance attention output representation, Representing the local relation feature representation of the relation; Represents a splicing operation; (2.2.4) directly adding the relationship attention feature fusion representation and the entity fusion feature representation to obtain a relationship attention prototype representation; P final =P attrel +P ent Where: P final Indicates that the relationship concerns the prototype representation; P attrel represents the relationship-focused feature fusion representation; P ent represents the fused feature representation.
4. The method for extracting industrial small sample relationships based on prototype networks according to claim 3 is characterized by: The relationship attention prototype representation obtained by inputting the sentences in the public support set and their corresponding public relationship descriptions into the teacher model is the public relationship attention prototype representation; the relationship attention prototype representation obtained by inputting the sentences in the industrial support set and their corresponding industrial relationship descriptions into the student model is the industrial relationship attention prototype representation.
5. The industrial small sample relationship extraction method based on prototype network according to claim 1 is characterized in that: The knowledge distillation for the public relations attention prototype representation and the industrial relations attention prototype representation is specifically as follows: Calculate distillation losses; in: Representing the public relations concern prototype representation, represents the industrial relationship attention prototype representation; PD represents the distillation loss function; Minimize the distillation loss to ensure that the student prototype simulates the teacher prototype, thereby achieving knowledge distillation and obtaining the industrial relationship attention prototype representation after knowledge distillation 6. The method for extracting industrial small sample relationships based on prototype networks according to claim 5 is characterized by: The distillation loss function uses a mean square error loss function.
7. The method for extracting industrial small sample relations based on prototype network according to claim 5 is characterized in that: The prototype distillation module based on knowledge distillation is specifically: Inputting the sentences in the industrial query set into the second encoder, the CLS vector output by the second encoder is the obtained feature representation of the sentences in the industrial query set; The feature representation is input into the classifier, the classifier uses vector dot product to calculate the distance between the feature representation of the sentence in the industrial query set and the industrial relationship attention prototype representation after each knowledge distillation, selects the category with the closest distance as the prediction, and uses Softmax function to calculate the probability distribution; Where: Q represents the feature representation of the sentence in the industrial query set, represents the industrial relation-attention prototype representation after knowledge distillation, and dp represents the dot product method.
8. The method for extracting industrial small sample relationships based on prototype networks according to claim 7 is characterized by: Cross entropy loss is used as the loss function to obtain industrial classification loss; The total loss is: Loss=L PD +L cla Where: Loss represents the total loss; L cla Indicates the industrial classification loss; L PD represents the distillation loss; N represents the total number of categories in the industrial query set.
9. The method for extracting industrial small sample relationships based on prototype networks according to claim 1 is characterized in that: The second encoder is a Bert encoder.
