A method and system for completing a knowledge graph in the field of numerical control programming

By combining hybrid sampling and multi-head self-attention mechanisms with global semantic feature learning, the CAM knowledge graph is completed, which solves the problem of insufficient template accuracy and applicability in CNC programming and improves programming efficiency and code reliability.

CN119311898BActive Publication Date: 2025-12-26JIANGSU UNIV OF SCI & TECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411111930.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-08-14
Publication Date
2025-12-26
Estimated Expiration
2044-08-14

AI Technical Summary

Technical Problem

The accuracy and applicability of existing CNC programming templates are limited by experience. CAM knowledge graph data is sparse and complex, lacking effective knowledge reuse and missing relationships between entities, resulting in low programming efficiency.

Method used

A hybrid sampling method is used to generate negative triples. A multi-head self-attention mechanism is introduced to aggregate neighborhood features. Combined with global semantic feature learning and GCN iterative optimization, the feature vectors of entity relationship interaction modules are fused to predict links and complete the CAM knowledge graph.

Benefits of technology

It improves the efficiency and quality of CNC programming, enhances the adaptability of CAM templates and the intelligence level of programmers, reduces labor intensity, and generates highly reliable toolpaths and NC codes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119311898B_ABST
    Figure CN119311898B_ABST
Patent Text Reader

Abstract

The application discloses a few-sample knowledge graph completion method in the field of numerical control programming, solves the problems of low reliability, great limitation, still needing programming personnel to repeatedly modify and less training entity samples of a numerical control programming template generated by a numerical control programming knowledge graph in an actual production process. First, an entity neighborhood information aggregation network based on a relation path is designed, importance of neighborhood entities is evaluated and distributed through a multi-head self-attention mechanism, and features are aggregated; then, a semantic graph is modeled according to semantic similarity of entity pairs, semantic relations between entities are represented, and global semantic features are output; finally, neighborhood aggregation features and semantic features are combined to perform link prediction. Through comparison experiments with mainstream algorithms on a public dataset of few-sample knowledge graph completion, the effectiveness and accuracy of the algorithm are verified.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of numerical control programming and knowledge graph, and particularly relates to a method and system for completing a knowledge graph in the field of numerical control programming. BACKGROUND

[0002] In the traditional numerical control programming process, the programmer selects a suitable numerical control programming template from a preset CAM template library according to the characteristics of the machining features and subjective experience. This method can reduce the number of programming interactions to a certain extent and improve programming efficiency. However, due to the experience limitations of the numerical control programming template formulator and user, the accuracy and applicability of the numerical control programming template cannot be effectively guaranteed.

[0003] A knowledge graph (KG) is a general semantic knowledge formalization description framework with flexible semantic representation ability and rich knowledge structure model. Its emergence enables the expression of process knowledge model to not only organize the geometric and manufacturing semantic information of CAD model, but also represent the macro and micro process knowledge of numerical control machining and the design intention of higher-level designers, thereby providing a new solution for realizing CAD / CAPP / CAM integration.

[0004] In the CAM field, numerical control programming related knowledge is often scattered in various links of production and manufacturing, and has the characteristics of sparsity, complex relationship, multi-source heterogeneity, etc. The completeness of the CAM knowledge graph constructed manually or automatically is poor, the knowledge reuse accuracy is low, and there is a problem of missing relationship between entities. The generated numerical control programming template cannot be directly applied to actual production. Therefore, in order to improve the application reliability of KG in numerical control programming, the constructed KG needs to be completed to make it effectively applied to actual numerical control programming work.

[0005] KGC is to infer missing information by analyzing existing facts, and few-shot knowledge graph completion (FKGC) is to use existing knowledge graph structure and sparse data samples to design a few-shot triple learning model under the condition of limited number of triple samples and long-tail properties of relations, effectively capture knowledge from heterogeneous information, establish a triple relation scoring function to solve the link prediction problem of (h, r,?) or (?, r, t), and predict and complete the missing triple information. Traditional methods rely on manual addition of new triples or reasoning of missing fact triples in knowledge graphs based on semantic rules, but this method is not suitable for handling large model knowledge graphs. In practical applications, knowledge graphs are usually affected by construction methods, and there is a common problem of few samples. For example, about 10% of the relations in the Wiki dataset have fewer than 10 associated triples. In recent years, knowledge graph embedding models have been widely used in KGC tasks, which can mine the potential features between entities and relations, and design different scoring functions (such as based on translation distance, based on semantic similarity) to predict missing triples. This paper introduces the mainstream methods at home and abroad from the aspects of traditional knowledge graph completion and few-shot knowledge graph completion.

[0006] (1) Traditional knowledge graph completion

[0007] Traditional knowledge graph completion models generally reduce entities and relations to low-dimensional continuous vector space, learn the embedding representation of entities and relations, and infer missing facts. In recent years, embedding models based on representation learning have been extensively studied by scholars at home and abroad. For example, Bordes A et al. proposed the TransE model, which first used the translation invariance of word vectors to predict the missing entities in triples, but lacked the ability to handle complex relationships such as one-to-many. To solve this problem, Trans series models were proposed based on TransE. Although the prediction ability of these models has improved, it has increased the complexity of the calculation and expanded the parameter size. Dettmers T et al. proposed the ConvE model, which first applied convolutional neural networks to the KGC task. As a nonlinear model, its output features are more expressive. After that, convolutional models such as ConvE, ConvKB, and ConvR were proposed to splice and reshape triples in different ways, embedding entities and relations into complex vector spaces to capture features. Zhou Xin et al. proposed an improved InteractE knowledge graph completion algorithm that uses SENet to filter useful feature information in InteractE feature mapping, improving the ability to capture feature interaction information. However, traditional models have the following two problems: (1) Over-reliance on structural information of knowledge graph, using structural view for single-view link prediction work, poor interpretability. (2) Dependence on rich training instances, ignoring the fact that actual application knowledge graphs generally lack sufficient training instances to support dynamic feature updates. Therefore, the few-shot knowledge graph completion task has become a research hotspot in recent years.

[0008] 2.2 Few-shot knowledge graph completion

[0009] The existing few-shot knowledge graph completion methods can be mainly divided into two categories: (1) metric learning based method: this method learns the matching function of the similarity between samples to identify the most similar sample to be measured with the reference sample. The GMatching model first defines the few-shot knowledge graph completion task, aggregates the one-hop neighbor structure information of the entity by using the neighbor encoder, and learns the metric function to match the entity pair. However, GMatching does not distinguish the importance of different neighbors, and introduces the noise problem. FSRL introduces a static attention mechanism to give different weights to the one-hop neighbors, and obtains more rich entity information. Sheng et al. proposed the FAAN model which dynamically adjusts the weight of neighbor information according to different tasks, which extends the above two methods. (2) optimization based meta-learning method: this method focuses on learning the most important information from the support set to the query set, and the typical model is MetaR model, which defines the most important information in the completion task through relationship meta and gradient meta. The relationship meta is a high-order representation of the relationship between entities, and the gradient meta is the loss gradient of the relationship meta information. Niu et al. proposed the GANA model which introduces TransH based on meta-learning, aggregates neighbor information, and fully considers 1-N, N-1 and N-N complex relationships.

[0010] However, the above models only focus on the aggregation of entity neighbor information, and improve the aggregation method to obtain better entity embedding, only mine the structure information of the knowledge graph itself, and do not fully consider the text description information and attribute values between entities and relationships, and ignore the artificial annotation information generated in the actual application process. SUMMARY

[0011] The purpose of the present application is to provide a method and system for completing a knowledge graph in the field of numerical control programming, which is used for few-shot knowledge graph completion of a CAM knowledge graph constructed by using historical CAM programming cases of an enterprise, realizes effective knowledge reuse of existing numerical control programming design results, solves problems such as sparse CAM knowledge graph data and missing relationships between knowledge, deeply mines hidden information and rules in historical programming cases, and improves the efficiency and quality of numerical control programming.

[0012] TECHNICAL SCHEME: The method for completing a knowledge graph in the field of numerical control programming comprises the following steps:

[0013] (1) The data set sampling module performs negative sampling on the CAM knowledge graph triplets to generate negative example triplets;

[0014] (2) The entity neighborhood information aggregation module introduces a multi-head self-attention mechanism to aggregate neighborhood features, learns the importance of multi-hop domain entities relative to the center entity based on the relationship path through an attention function, and finally obtains the aggregated features of the nodes at each layer to capture the structural information in the CAM knowledge graph;

[0015] (3) The global semantic feature learning module performs word embedding on the manufacturing information of each link in the numerical control programming process to generate a CAM semantic knowledge graph, and applies GCN to iteratively learn and optimize the global semantic features of entities;

[0016] (4) The link prediction module fuses the feature vectors of the entity relationship interaction module and the global semantic features, and performs candidate triple score sorting under the score function calculation to obtain the best prediction result.

[0017] Further, step (1) is as follows: triple negative sampling, i.e., randomly replacing the head and tail nodes in the triple (h, r, t), as shown in equation (1):

[0018]

[0019] where S represents the set of positive triplets; represents the set of negative triplets; and ε represents the set of entities. and represents the negative triplets generated after selecting and replacing the head entity h and the tail entity t. When generating negative samples, replacing the relationship r will generate incorrect negative triplets, and the replacement method cannot be included in the set of negative triplets, as shown in equation (2):

[0020]

[0021] The hybrid sampling module labels the obtained set of negative triplets, introduces a set of positive triplets, mixes the two with a certain mixing coefficient, and uses a loss function based on the boundary distance as the training target to optimize the model, as shown in equation (3):

[0022]

[0023] where the function f(h, r, t) is defined as follows:

[0024] f(h, r, t) = - ||h + r - t||1#(4

[0025] where γ represents the distance between positive and negative samples, and when is greater than 0, the loss function takes the original value, otherwise it takes 0, aiming to maximize the distance between the most similar positive and negative triplets.

[0026] Further, step (2) is as follows: first, the entity and the relationship are input, and all multi-hop neighborhood entities based on the relationship are aggregated, as shown in equation (5):

[0027]

[0028] wherein, denotes the entity set based on the relation r and the center entity i, denotes the jth entity of the lth layer, and H denotes the aggregated neighborhood entity feature; the importance of the neighborhood entity relative to the center entity is learned through the attention function, as shown in the following formula:

[0029]

[0030] wherein, is the attention score, which measures the relevance or importance of entity i and entity j under the relation path r; The greater the value, the greater the influence of entity j on relation r relative to entity i; α T denotes the transpose of the attention vector, W n is a weight matrix used for linear transformation of entity features and , and || denotes concatenation of the transformed features of entity i and entity j; is the attention weight, which represents the importance of entity j to entity i; the attention score is converted into a probability distribution by applying the softmax function, so that the sum of the attention weights of all field entities is 1; the entity i field entity aggregation method based on the relation path r is shown in the following formula:

[0031]

[0032] wherein, denotes the aggregation feature of all neighborhood entities of entity i at the lth layer under the relation path r; denotes the number of field entities of entity i under the relation path r; K denotes the number of heads of multi-head attention, and the features of the field entities are weighted and summed through the multi-head attention mechanism to finally obtain the aggregation feature of entity i at the lth layer.

[0033] Further, step (3) comprises the following steps:

[0034] (31) Using the API function provided by the CAM software, extract part process information, feature size information and machining operation information from the numerical control programming case and store them in the database;

[0035] (32) Based on the extracted CAM manufacturing semantic information, model the semantic knowledge graph, and iteratively learn to obtain the optimal global semantic information embedding of the entity; Tokenization is used to divide the CAM text information, and the word embedding sum, paragraph and position embedding are combined as the input representation of the BER model;

[0036] (33) The preprocessed text data is input into the pre-trained BERT model to obtain the encoded representation of the text information. The BERT model outputs the hidden state of each word vector, which is used to represent the initial semantic embedding of the entity;

[0037] (34) An initial semantic knowledge graph is created using KNN, the similarity between the semantic features of each entity is measured by cosine similarity, and a similarity ranking is performed, the top K semantic features are retained, their values are set to 1, and the rest are set to 0, the calculation process is shown in equation (9):

[0038]

[0039] Where S 0 and A 0 are the similarity matrix and adjacency matrix of the initial semantic knowledge graph, represent the position in the i-th row of the similarity matrix in descending order;

[0040] (35) The created initial semantic knowledge graph is encoded using GCN to obtain entity representation, the semantic similarity of entity pairs is calculated using weighted cosine similarity algorithm, and independent similarity values are calculated through different weights; each weight represents the semantic information of each part of the entity, and the calculation process is as follows:

[0041]

[0042] Where S ij is the similarity score of the entity pair; is the cosine similarity of the two entity vectors in the n-th aspect, each aspect representing each part of the semantic features of the entity pair; w n is a learnable weight vector; and is the Hadamard product.

[0043] (36) The semantic knowledge graph G * supplemented after semantic similarity learning is fused with the initial semantic knowledge graph G (0) to generate a semantic knowledge graph G * that best represents the semantic features of the entity The fusion process is shown in the following equation:

[0044]

[0045] G * =μf(G (n) )+(1-μ)f(G (1) )(13)

[0046] Where M is the adjacency matrix of G (0) ; G(n) and G (1) respectively are the semantic knowledge graph after the n-th and first iteration optimization; for the fusion of G * and G (0) linear combination, by weighting the hyperparameter mu to obtain the final learned semantic knowledge graph; when fusing G * and G (0) , the trade-off hyperparameter lambda is used to balance their proportions;

[0047] (37) is, using double-layer GCN coding, the semantic feature V s is subjected to two matrix transformations, and the optimal global semantic feature is output; the output calculation process is shown in formula (14):

[0048]

[0049] wherein, W (0) and W (1) are trainable specific layer weight matrices; sigma (·) is a ReLU activation function; is the global semantic feature matrix output by the global semantic feature module.

[0050] Further, step (4) is specifically as follows: using a learnable parameter alpha, wherein (0 <= |alpha| <= 1) optimizes the aggregation process of each triple vector and semantic feature, and in the training process, random initialization and iterative update are performed in a linear transformation manner, finally obtaining the CAM triple set fused with the numerical control programming text information, and the calculation process is as follows:

[0051]

[0052] The SIE-KGC model is optimized using the Adam optimizer to minimize the loss function as the final training target, and the loss function formula is as follows:

[0053]

[0054] wherein, y i is the entity relationship pair (u, r) of the missing triple information; N is the number of entities in the CAM knowledge graph; is a sigmoid function.

[0055] The numerical control programming field knowledge graph completion system provided by the application comprises:

[0056] The triple module is used for negative sampling of the CAM knowledge graph triples by the data set sampling module, and negative example triples are generated.

[0057] Entity neighborhood information aggregation module: used to introduce a multi-head self-attention mechanism to aggregate neighborhood features, learn the importance of multi-hop domain entities relative to the center entity based on the relationship path through the attention function, and finally obtain the aggregated features of the nodes at each layer to capture the structural information in the CAM knowledge graph;

[0058] Global semantic feature learning module: used to perform word embedding on the manufacturing information of each link in the numerical control programming process to generate a CAM semantic knowledge graph, apply GCN to iteratively learn and optimize the CAM semantic knowledge graph, and generate global semantic features of entities;

[0059] Link prediction module: used to fuse the feature vectors of the entity relationship interaction module and the global semantic features, perform score sorting of candidate triplets under a score function, and obtain the best prediction result.

[0060] Further, in the triplet module, the formula is as follows: the triplet negative sampling is to randomly replace the head and tail nodes in the triplet (h, r, t), as shown in formula (1):

[0061]

[0062] Wherein, S represents a set of positive triplets; represents a set of negative triplets; and ε represents an entity set. and represents a negative triplet generated after selecting and replacing the head entity h and the tail entity t. When generating negative samples, replacing the relationship r will generate an incorrect negative triplet, and the replacement method cannot be included in the negative triplet set, as shown in formula (2):

[0063]

[0064] The hybrid sampling module labels the obtained negative triplet set, introduces a set of positive triplets, mixes the two with a certain mixing coefficient, and uses a loss function based on the boundary distance as the training target to optimize the model, as shown in formula (3):

[0065]

[0066] Wherein, the function f(h, r, t) is defined as follows:

[0067] f(h, r, t) = -||h + r - t||1#(4)

[0068] Wherein, γ represents the distance between positive and negative samples, and when is greater than 0, the loss function takes the original value, otherwise 0, aiming to maximize the distance between the most similar positive and negative triplets.

[0069] Further, the global semantic feature learning module is as follows: first, taking entities and relations as input, aggregating all multi-hop neighborhood entities based on the relation , as shown in equation (5):

[0070]

[0071] wherein, represents the entity set based on the relation r and the center entity i, represents the jth entity of the lth layer, and H represents the aggregated neighborhood entity feature; the importance of neighborhood entities relative to the center entity is learned through an attention function, as shown in the following equation:

[0072]

[0073] wherein, is the attention score, measuring the relevance or importance of entity i and entity j under the relation path r; The greater the value, the greater the influence of entity j on relation r relative to entity i; α T represents the transpose of the attention vector, W n is a weight matrix for linear transformation of entity features and ; and || represents concatenation of the transformed features of entity i and entity j. is the attention weight, representing the importance of entity j to entity i, and the softmax function is applied to convert the attention score into a probability distribution, so that the sum of the attention weights of all field entities is 1; the entity i field entity aggregation method based on the relation path r is as shown in the following equation:

[0074]

[0075] wherein, represents the aggregation feature of all neighborhood entities of entity i at the lth layer under the relation path r; represents the number of field entities of entity i under the relation path r; K represents the number of heads of multi-head attention, and the features of the field entities are weighted and summed through the multi-head attention mechanism to finally obtain the aggregation feature of entity i at the lth layer.

[0076] Further, the global semantic feature learning module includes the following steps:

[0077] (31) Using the API function provided by the CAM software, extracting part process information, feature size information, and machining operation information from the numerical control programming case and storing them in the database after classification;

[0078] (32) Based on the extracted CAM manufacturing semantic information, the semantic knowledge graph is modeled, and iterative learning is performed to obtain the optimal global semantic information embedding of the entity. Tokenization is used to segment the CAM text information, and the combination of word embedding sum, paragraph and position embedding is used as the input representation of the BER model;

[0079] (33) The preprocessed text data is input into the pre-trained BERT model to obtain the encoding representation of the text information. The BERT model outputs the hidden state of each word vector, which is used to represent the initial semantic embedding of the entity;

[0080] (34) The initial semantic knowledge graph is created using KNN, the similarity between the semantic features of each entity is measured by cosine similarity, and the similarity is sorted, the first K semantic features are retained, and their values are set to 1, and the rest are 0, the calculation process is shown in formula (9):

[0081]

[0082] Where S 0 and A 0 are the similarity matrix and adjacency matrix of the initial semantic knowledge graph, represent the position in the i-th row of the similarity matrix in descending order;

[0083] (35) The created initial semantic knowledge graph is encoded using GCN to obtain entity representation, the semantic similarity of entity pairs is calculated using weighted cosine similarity algorithm, and independent similarity values are calculated through different weights; each weight represents the semantic information of each part of the entity, and the calculation process is as follows:

[0084]

[0085] Where S ij is the similarity score of the entity pair; is the cosine similarity of the two entity vectors in the n-th aspect, each aspect representing each part of the semantic features of the entity pair; w n is a learnable weight vector; and is the Hadamard product.

[0086] (36) The semantic knowledge graph G * supplemented after semantic similarity learning is fused with the initial semantic knowledge graph G (0) to generate a semantic knowledge graph G that best represents the semantic features of the entity, and the fusion process is as follows:

[0087]

[0088] G * = μf(G (n) ) + (1 - μ)f(G (1) ) (13)

[0089] where M is the adjacency matrix of G (0) ; G (n) and G (1) are the semantic knowledge graph after the nth and first iteration optimization, respectively; G * and G (0) are linear combinations, and the final learned semantic knowledge graph is obtained by weighting the hyperparameter μ; when fusing G * and G (0) , the trade-off hyperparameter λ is used to balance their proportions;

[0090] (37) is used to encode the semantic feature V s by using double-layer GCN, and the optimal global semantic feature is outputted; the output calculation process is shown in formula (14):

[0091]

[0092] where W (0) and W (1) are trainable specific layer weight matrices; σ(·) is the ReLU activation function; is the global semantic feature matrix outputted by the global semantic feature module.

[0093] Further, in the link prediction module, the following is used: a learnable parameter α is used, where (0≤|α|≤1 is used to optimize the aggregation process of each triple vector and semantic feature, and in the training process, it is randomly initialized and iteratively updated in a linear transformation manner, and finally the CAM triple set fused with the numerical control programming text information is obtained, and the calculation process is as follows:

[0094]

[0095] The SIE-KGC model is optimized using the Adam optimizer to minimize the loss function as the final training target, and the loss function formula is as follows:

[0096]

[0097] where y i is the entity relationship pair (u, r) with missing triple information; N is the number of entities in the CAM knowledge graph; is the sigmoid function.

[0098] Beneficial effects: compared with the prior art, the present application has the following remarkable advantages: the mixed sampling method expands the training set of the few-sample knowledge graph, the entity neighborhood information aggregation network based on the relationship path is designed, the multi-head self-attention network is introduced to make up for the deficiency of the traditional entity neighborhood aggregation network, and the semantic graph is created to make full use of the text information other than the structure view, combine the structure characteristics of the triple and the semantic characteristics of the entity, and improve the performance of the link prediction model. Compared with the mainstream knowledge graph completion algorithm model, the method has good performance. After the CAM knowledge graph is completed, the generated tool path and NC code have high reliability in actual numerical control programming work, effectively improve the reuse ability of enterprise historical case knowledge and realize the self-adaptation of the CAM template parameters, thereby reducing the labor intensity of the programming personnel and improving the efficiency and intelligent level of the CAM programming. BRIEF DESCRIPTION OF DRAWINGS

[0099] Figure 1 The algorithm model of the present application is shown in the figure;

[0100] Figure 2 The entity neighborhood information aggregation principle of the present application is shown in the figure;

[0101] Figure 3 The marine diesel engine connecting rod manufacturing semantic information extraction of the present application is shown in the figure;

[0102] Figure 4 The semantic knowledge graph of the thrust end yoke of the present application is shown in the figure. DETAILED DESCRIPTION

[0103] The technical solutions of the present application will be further described below with reference to the accompanying drawings.

[0104] As shown in the figure, the embodiment of the present application provides a method for completing the knowledge graph in the field of numerical control programming, which comprises the following steps: Figure 1 (1) The data set sampling module performs negative sampling on the triple of the CAM knowledge graph to generate negative triplets; the formula is as follows: triple negative sampling means randomly replacing the head and tail nodes in the triple (h, r, t), as shown in formula (1):

[0105]

[0106]

[0107] Among them, S represents the positive triple set; represents the negative triple set; and ε represents the entity set. and represent the negative triplets generated after selecting and replacing the head entity h and the tail entity t. When generating negative samples, replacing the relationship r will generate incorrect negative triplets, and the replacement method cannot be included in the negative triple set, as shown in formula (2): ​

[0108]

[0109] The mixed sampling module labels the obtained negative triple set, introduces a positive triple set, mixes the two with a certain mixing coefficient, and optimizes the model using a boundary distance-based loss function as a training target. The loss function is shown in equation (3):

[0110]

[0111] wherein the function f(h, r, t) is defined as follows:

[0112] f(h, r, t) = - ||h + r - t||1 (4

[0113] wherein γ represents the distance between positive and negative samples, and when is greater than 0, the loss function takes the original value, otherwise 0, aiming to maximize the distance between the most similar positive and negative triplets.

[0114] (2) The entity neighborhood information aggregation module introduces a multi-head self-attention mechanism to aggregate neighborhood features. The importance of multi-hop neighborhood entities relative to the center entity based on the relationship path is learned through an attention function. Finally, the aggregated features of the node at each layer are obtained to capture the structural information in the CAM knowledge graph, as shown in equation (5): Figure 2 The entity neighborhood information aggregation principle diagram is shown in FIG. 1; the specific process is as follows: first, the entity and the relationship are input, and all multi-hop neighborhood entities based on the relationship are aggregated, as shown in equation (5):

[0115]

[0116] wherein represents the entity set based on the relationship r and the center entity i, represents the jth entity at the lth layer, and H represents the aggregated neighborhood entity features; the importance of the neighborhood entities relative to the center entity is learned through an attention function, as shown in equation (6):

[0117]

[0118] wherein is the attention score, which measures the relevance or importance of entity i and entity j under the relationship path r; The greater the value, the greater the influence of entity j on entity i under the relationship r; α T represents the transpose of the attention vector, W n is a weight matrix used to combine the entity features and linear transformation, ∥ represents the concatenation of the features of entity i and entity j after transformation; is the attention weight, which represents the importance of entity j to entity i, and the softmax function is applied to convert the attention score into a probability distribution, so that the sum of the attention weights of all domain entities is 1; the entity i domain entity aggregation method based on the relationship path r is shown in the following formula:

[0119]

[0120] wherein, represents the aggregation feature of all neighborhood entities of entity i at the lth layer under the relationship path r; represents the number of domain entities of entity i under the relationship path r; K represents the number of heads of multi-head attention, and the features of the domain entities are weighted and summed through the multi-head attention mechanism to finally obtain the aggregation feature of entity i at the lth layer.

[0121] (3) The global semantic feature learning module performs word embedding on the manufacturing information of each link in the numerical control programming process to generate a CAM semantic knowledge graph, and applies GCN to iteratively learn and optimize it to generate global semantic features of the entity; including the following steps:

[0122] (31) Using the API function provided by the CAM software, the part process information, feature size information and machining operation information are extracted from the numerical control programming case and stored in the database; as shown in Figure 3 The manufacturing semantic information extraction of the marine diesel engine connecting rod is shown. Based on the extracted CAM manufacturing semantic information, the semantic knowledge graph is modeled and iteratively learned to obtain the optimal global semantic information embedding of the entity, as shown in Figure 4 The semantic knowledge graph taking the "thrust end bracket" machining feature as an example is shown.

[0123] (32) Based on the extracted CAM manufacturing semantic information, the semantic knowledge graph is modeled and iteratively learned to obtain the optimal global semantic information embedding of the entity, using Tokenization to perform word segmentation on the CAM text information, combining word embedding sum, paragraph and position embedding as input representation of the BER model;

[0124] (33) The preprocessed text data is input into the pre-trained BERT model to obtain the encoding representation of the text information; the BERT model outputs the hidden state of each word vector, which is used to represent the initial semantic embedding of the entity;

[0125] (34) Use KNN to create an initial semantic knowledge graph, measure the similarity between the semantic features of each entity by cosine similarity, and sort the similarity, keep the top K semantic features, set their values to 1, and the rest to 0, and its calculation process is shown in formula (9):

[0126]

[0127] where S 0 and A 0 are the similarity matrix and adjacency matrix of the initial semantic knowledge graph, respectively, denotes the position in the i-th row of the similarity matrix when arranged in descending order;

[0128] (35) The initial semantic knowledge graph created is encoded using GCN to obtain entity representations, the semantic similarity of entity pairs is calculated using a weighted cosine similarity algorithm, and independent similarity values are calculated by different weights; each weight represents the semantic information of each part of the entity, and the calculation process is as follows:

[0129]

[0130] where S ij is the similarity score of the entity pair; is the cosine similarity of the two entity vectors in the n-th aspect, each aspect representing each part of the semantic features of the entity pair; w n is a learnable weight vector; and ⊙ denotes Hadamard product.

[0131] (36) The semantic knowledge graph G * supplemented after semantic similarity learning is fused with the initial semantic knowledge graph G (0) to generate a semantic knowledge graph G that best represents the semantic features of entities, and the fusion process is as follows:

[0132]

[0133] G * = μf(G (n) ) + (1-μ)f(G (1) )13)

[0134] where M is the adjacency matrix of G (0) ; G (n) and G (1) are the semantic knowledge graphs after the n-th and first iteration optimization, respectively; G * and G (0) are linearly combined to obtain the final learned semantic knowledge graph by weighting the hyperparameter μ; when G * and G (0) are fused, the weighting hyperparameter λ is used to balance their proportions;

[0135] ​(37) is, using double-layer GCN coding, the semantic feature V s Two matrix transformations are performed to output the optimal global semantic feature; the output calculation process is shown in equation (14):

[0136]

[0137] wherein W (0) and W (1) are trainable specific layer weight matrices; and σ(·) is a ReLU activation function; is the global semantic feature matrix output by the global semantic feature module

[0138] (4) The link prediction module fuses the feature vectors of the entity relationship interaction module and the global semantic feature, and sorts the candidate triplets under the score function calculation to obtain the best prediction result. Specifically, the learnable parameter α is used, wherein (0≤|α|≤1) optimizes the aggregation process of each triplet vector and semantic feature, and is randomly initialized and iteratively updated in a linear transformation manner during the training process, and finally the CAM triplet set fused with the numerical control programming text information is obtained, and the calculation process is as follows:

[0139]

[0140] The SIE-KGC model is optimized using the Adam optimizer to minimize the loss function as the final training target, and the loss function formula is as follows:

[0141]

[0142] wherein y i is the entity relationship pair (u, r) of the missing triplet information; N is the number of entities in the CAM knowledge graph; is a sigmoid function.

[0143] To evaluate the performance of the algorithm model proposed in the present application, the traditional knowledge graph completion models represented by TransE and ComplEx and the few-shot knowledge graph completion models represented by GMatching, FSRL, MetaR, FAAN and GANA are selected as baseline models, comparative experiments are carried out on the public data set of the knowledge graph, and the experimental results are analyzed.

[0144] Dataset introduction

[0145] The data sets commonly used in the few-shot knowledge graph completion task are used in the experiment: FB15k237-One and NELL-One. The two data sets are selected from FB15k237 and NELL data sets, and the entity pairs with the same relationship and the number of triples between 50 and 500 are counted, and the text description of each entity and relationship in the data set is counted to construct the semantic information of the entity pair. Table 1 details the data set information, and #Ent: entity number, #Rel: relationship number, #Tri: triple number, #Splits: training set / verification set / test set ratio, #Sem: entity pair semantic information sample number.

[0146] Table 1 Data set information

[0147]

[0148] Evaluation criteria

[0149] Two evaluation indexes commonly used in the knowledge graph completion task are used to evaluate the performance of the SIE-KGC model proposed in this paper: MRR (mean reciprocal rank) and Hits@k.

[0150] MRR is the average reciprocal rank, which represents the average value of the reciprocal of the correct triple rank. The calculation formula is shown in equation (17):

[0151]

[0152] In the formula, S represents the triple set, |S| represents the number of triple sets, rank i represents the ranking of the i-th triple.

[0153] Hits@k represents the proportion of correct triples in the first k candidate triples. In the experiment, k takes the value of 1, 5, and 10. The calculation formula is shown in equation (18):

[0154]

[0155] In the formula, |Numk| represents the number of correct triples in the first k candidate triples.

[0156] The larger the values of MRR and Hits@k, the better the effect of the model in the knowledge graph completion task.

[0157] Parameter setting

[0158] In the model training process, after parameter tuning, in the FB15k237-One dataset, the batch size is set to 512, the entity and relationship embedding dimension is 200, the learning rate is 0.001, the interval γ between positive and negative samples is 1, and the iteration number is 1000. In the NELL-One dataset, the batch size is set to 256, the embedding dimension is 200, the learning rate is 0.001, and the iteration number is 500.

[0159] Experimental results

[0160] To evaluate the effect of the proposed SIE-KGC model on the few-shot knowledge graph completion task, the mainstream model is compared and analyzed on the few-shot knowledge graph public dataset, and Table 2 and Table 3 respectively give the experimental results of each model on the FB15k237-One and NELL-One datasets. Compared with the best-performing GANA model on the FB15k237-One dataset, the MRR index of the SIE-KGC model is improved by 3.1%, and the Hits@1, Hits@5 and Hits@10 are improved by 3.5%, 4.4% and 4.9% respectively; on the NELL-One dataset, the MRR index is improved by 4.3%, and the Hits@1, Hits@5 and Hits@10 are improved by 3.8%, 5.4% and 6% respectively.

[0161] Table 2 Experimental results of each model on FB15k237-One dataset

[0162]

[0163] Table 3 Experimental results of each model on NELL-One dataset

[0164]

[0165]

[0166] Because the NELL-One dataset has more training sets than the FB15k237-One dataset, the experimental results are more obvious. Combining the experimental results of the two public datasets, it can be concluded that the SIE-KGC model achieves good experimental results on the FB15k237-One and NELL-One datasets, proving the reliability and effectiveness of the model in the knowledge graph completion task. The SIE-KGC model proposed in the present application fuses the neighbor interaction information and global semantic information between entities, enriches the embedding of entities and relationships, learns more fine-grained link information, and improves the knowledge graph link prediction effect.

[0167] The embodiment of the present application provides a kind of NC programming field knowledge graph completion system, comprising:

[0168] Triplet module: for the data set sampling module to sample negative triples of the CAM knowledge graph, generate negative example triples; the formula is as follows: the negative sampling of triples is to randomly replace the head and tail nodes in the triple (h, r, t), as shown in formula (1):

[0169]

[0170] Wherein, S represents a set of positive example triples; represents a set of negative example triples; ε represents an entity set; and represents the negative example triples generated after selecting and replacing the head entity h and the tail entity t. When generating negative samples, replacing the relationship r will generate incorrect negative example triples, and the replacement method cannot be included in the negative example triple set, as shown in formula (2):

[0171]

[0172] The mixed sampling module labels the obtained negative example triple set, introduces a set of positive example triples, mixes the two with a certain mixing coefficient, and uses a loss function based on boundary distance as a training target to optimize the model, and the loss function is as shown in formula (3):

[0173]

[0174] Wherein, the function f(h, r, t) is defined as follows:

[0175] f(h, r, t) = -||h + r - t||1#(4)

[0176] Wherein, γ represents the distance between positive and negative samples, and when is greater than 0, the loss function takes the original value, otherwise 0, aiming to maximize the distance between the most similar positive and negative example triples.

[0177] Entity neighborhood information aggregation module: for introducing a multi-head self-attention mechanism to aggregate neighborhood features, learning the importance of multi-hop domain entities relative to the center entity based on the relationship path through the attention function, and finally obtaining the aggregated features of the nodes at each layer, capturing the structural information in the CAM knowledge graph; as follows: first, input the entity and the relationship Aggregate all multi-hop neighborhood entities based on the relationship , as shown in formula (5):

[0178]

[0179] Wherein, represents the entity set based on the relationship r and the center entity i, H represents the aggregated neighborhood entity feature, and the importance of the neighborhood entity relative to the center entity is learned through the attention function, as shown in the following formula:

[0180]

[0181] wherein, is the attention score, which measures the relevance or importance of entity i and entity j under the relationship path r; The greater the value, the greater the influence of entity j on relationship r relative to entity i; alpha T represents the transpose of the attention vector, W n is a weight matrix for linear transformation of entity features and , and || represents concatenation of the transformed features of entity i and entity j; is the attention weight, which represents the importance of entity j to entity i, and the softmax function is applied to convert the attention score into a probability distribution, so that the sum of the attention weights of all field entities is 1; the entity i field entity aggregation method based on the relationship path r is shown in the following formula:

[0182]

[0183] wherein, represents the aggregation feature of all neighborhood entities of entity i at the lth layer under the relationship path r; represents the number of field entities of entity i under the relationship path r; K represents the number of heads of multi-head attention, and the features of the field entities are weighted and summed through the multi-head attention mechanism to finally obtain the aggregation feature of entity i at the lth layer.

[0184] Global semantic feature learning module: used for word embedding of manufacturing information in each link of the numerical control programming process to generate a CAM semantic knowledge graph, and iteratively learning and optimizing it using GCN to generate global semantic features of entities; including the following steps:

[0185] (31) Using the API function provided by the CAM software, extracting part process information, feature size information, and machining operation information from the numerical control programming case and storing them in the database after classification;

[0186] (32) Based on the extracted CAM manufacturing semantic information, model the semantic knowledge graph and iteratively learn to obtain the optimal global semantic information embedding of the entity; use Tokenization to tokenize the CAM text information, combine word embedding sum, paragraph and position embedding, and use them as input representations of the BER model;

[0187] (33) The preprocessed text data is input into the pre-trained BERT model to obtain the encoded representation of the text information. The BERT model outputs the hidden state of each word vector, which is used to represent the initial semantic embedding of the entity;

[0188] (34) An initial semantic knowledge graph is created using KNN, the similarity between the semantic features of each entity is measured by cosine similarity, and a similarity ranking is performed. The top K semantic features are retained, with their values set to 1 and the remaining values set to 0. The calculation process is shown in equation (9):

[0189]

[0190] where S 0 and A 0 are the similarity matrix and adjacency matrix of the initial semantic knowledge graph, respectively, represents the position in the i-th row of the similarity matrix in descending order;

[0191] (35) The initial semantic knowledge graph created is encoded using GCN to obtain entity representation. The semantic similarity of entity pairs is calculated using a weighted cosine similarity algorithm, and independent similarity values are calculated by different weights. Each weight represents the semantic information of each part of the entity, and the calculation process is as follows:

[0192]

[0193] where S ij is the similarity score of the entity pair; is the cosine similarity of the two entity vectors in the n-th aspect, each aspect representing each part of the semantic features of the entity pair; w n is a learnable weight vector; and is the Hadamard product.

[0194] (36) The semantic knowledge graph G * supplemented after semantic similarity learning is fused with the initial semantic knowledge graph G (0) to generate a semantic knowledge graph G that best represents the semantic features of the entity. The fusion process is shown in the following equation:

[0195]

[0196] G * = μf(G (n) ) + (1-μ)f(G (1) )(13)

[0197] where M is the adjacency matrix of G (0) ; and G​(n ) and G (1) are the semantic knowledge graph after the n-th and first iteration optimization, respectively; G * and G (0) are linear combinations, and the final learned semantic knowledge graph is obtained by weighting the hyperparameter μ; when fusing G * and G (0) , the trade-off hyperparameter λ is used to balance their proportions;

[0198] (37) is, using double-layer GCN encoding, performing two matrix transformations on the semantic feature V s , and outputting the optimal global semantic feature; its output calculation process is shown in equation (14):

[0199]

[0200] where W (0) and W (1) are trainable specific layer weight matrices; σ(·) is the ReLU activation function; is the global semantic feature matrix output by the global semantic feature module.

[0201] Link prediction module: used to fuse the feature vectors of the entity relationship interaction module and the global semantic feature, and to perform candidate triple score ranking under the score function calculation to obtain the best prediction result. Specifically, the learnable parameter α is used, where (0≤|α|≤1) optimizes the aggregation process of each triple vector and semantic feature, and in the training process, it is randomly initialized and iteratively updated in a linear transformation manner, and finally the CAM triple set fused with numerical control programming text information is obtained, and its calculation process is as follows:

[0202]

[0203] The SIE-KGC model is optimized using the Adam optimizer to minimize the loss function as the final training target, and the loss function formula is as follows:

[0204]

[0205] where y i is the entity relationship pair (u, r) with missing triple information; N is the number of entities in the CAM knowledge graph; is the sigmoid function.

Claims

1. A method for completing a knowledge graph in the field of numerical control programming, characterized in that, The method comprises the following steps: (1) The data set sampling module performs negative sampling on the CAM knowledge graph triplets to generate negative example triplets; (2) The entity neighborhood information aggregation module introduces a multi-head self-attention mechanism to aggregate neighborhood features, learns the importance of multi-hop domain entities relative to the center entity based on the relationship path through an attention function, and finally obtains the aggregated features of the nodes at each layer to capture the structural information in the CAM knowledge graph; (3) The global semantic feature learning module performs word embedding on the manufacturing information of each link in the numerical control programming process to generate a CAM semantic knowledge graph, and iteratively learns and optimizes the CAM semantic knowledge graph using a GCN to generate global semantic features of entities; comprising the following steps: (31) Using the API function provided by the CAM software, extracting part process information, feature size information and machining operation information from the numerical control programming case and storing them in the database; (32) Based on the extracted CAM manufacturing semantic information, a semantic knowledge graph is modeled, and iterative learning is performed to obtain the optimal global semantic information embedding of the entity; Tokenization is used to divide the CAM text information, and the word embedding sum, paragraph and position embedding are combined as the input representation of the BERT model; (33) The preprocessed text data is input into the pre-trained BERT model to obtain the encoding representation of the text information; the BERT model outputs the hidden state of each word vector, and the hidden state is used to represent the initial semantic embedding of the entity; (34) An initial semantic knowledge graph is created using KNN, the similarity between the semantic features of each entity is measured by cosine similarity, and a similarity ranking is performed, the top K semantic features are retained, the values of the top K semantic features are set to 1, and the values of the remaining semantic features are set to 0, and the calculation process is as shown in formula (9): wherein S 0 and A 0 are the similarity matrix and the adjacency matrix of the initial semantic knowledge graph, respectively, denotes the position in the similarity matrix in the i-th row; and in the i-th row; and (35) The created initial semantic knowledge graph is encoded using GCN to obtain entity representation, the semantic similarity of entity pairs is calculated using a weighted cosine similarity algorithm, and independent similarity values are calculated through different weights; wherein each weight represents the semantic information of each part of the entity, and the calculation process is as follows: where S ij is the similarity score of the entity pair; is the cosine similarity of the two entity vectors in the n-th aspect, each aspect representing each part of the semantic features of the entity pair; w n is a learnable weight vector; and ⊙ denotes the Hadamard product. (36)The semantic knowledge graph G supplemented after semantic similarity learning * is fused with the initial semantic knowledge graph G (0) to generate a semantic knowledge graph G that best represents the semantic characteristics of entities The fusion process is as follows: G * = μf(G (n) ) + (1 - μ)f(G (1) )(13) where M is the adjacency matrix of G (0) G (n) and G (1) are the semantic knowledge graph after the n-th and first iteration of optimization, respectively; G * and G (0) are linearly combined by weighting the hyper-parameter μ to obtain the final learned semantic knowledge graph; when fusing G * and G (0) , a trade-off hyper-parameter λ is used to balance their proportions; (37) Using double-layer GCN coding, the semantic features V s Two matrix transformations are performed to output the optimal global semantic features; the output calculation process is shown in equation (14): wherein, W (0) and W (1) are trainable specific layer weight matrices; σ(·) is a ReLU activation function; is a global semantic feature matrix output by the global semantic feature module. (4) The link prediction module fuses the feature vectors of the entity relationship interaction module and the global semantic features, performs score ranking on the candidate triplets under the score function calculation, and obtains the best prediction result. 2.The method of claim 1, wherein, Step (1) is as follows: negative sampling of triplets means randomly replacing the head and tail nodes in the triplet (h, r, t), as shown in formula (1): where S represents a set of positive triplets; represents a set of negative triplets; ε represents a set of entities; and represents a negative triplet generated after selecting and replacing the head entity h and the tail entity t; when generating negative samples, replacing the relation r will generate incorrect negative triplets, and the replacement method cannot be included in the set of negative triplets, as shown in equation (2): The mixed sampling module labels the obtained negative example triplet set, introduces a positive example triplet set, mixes the two with a certain mixing coefficient, and uses a loss function based on boundary distance as a training target to optimize the model, and the loss function is as shown in formula (3): Wherein, the function f(h, r, t) is defined as follows: f(h, r, t) = -||h + r - t||1 (4) where γ denotes the margin between positive and negative samples, and The loss function takes the original value when γ > 0, and 0 otherwise, aiming to maximize the distance between the most similar positive-negative triplets. 3.The method of claim 1, wherein, Step (2) is specified as follows: First, the entities and relations are aggregated based on the relations of all multi-hop neighborhood entities as shown in equation (5): wherein, denotes the set of entities based on the relation r and the center entity i, denotes the jth entity of the lth layer, H denotes the aggregated neighborhood entity features; the importance of the neighborhood entities relative to the center entity is learned through an attention function, as shown in the following formula: wherein, is an attention score, measuring the relevance or importance of entity i and entity j under the relationship path r; The larger the value, the greater the influence of entity j on relationship r relative to entity i; αT represents the transpose of the attention vector, Wn is a weight matrix for the linear transformation of entity features and is spliced; represents the linear transformation of entity i and entity j after the feature; is an attention weight, indicating the importance of entity j to entity i, and the attention score is converted into a probability distribution by applying a softmax function, so that the sum of the attention weights of all domain entities is 1; the entity i domain entity aggregation method based on the relationship path r is as follows: wherein, represents all neighborhood entity aggregation features of entity i at the l-th layer under the relationship path r; represents the number of domain entities of entity i under the relationship path r; K represents the number of heads of multi-head attention, and the features of the domain entities are weighted and summed through the multi-head attention mechanism to finally obtain the aggregation features of entity i at the l-th layer.

4. The method of claim 1, wherein, Step (4) is as follows: a learnable parameter a is used to optimize the aggregation process of each triplet vector and semantic feature, and in the training process, a linear transformation is used for random initialization and iterative update, and finally a CAM triplet set fused with numerical control programming text information is obtained; wherein, 0≤|α|≤1; the calculation process is as follows: The SIE-KGC model is optimized using an Adam optimizer to minimize the loss function as the final training objective, and the loss function formula is as follows: where y i is the entity relation pair (u, r) missing triple information; N is the number of entities in the CAM knowledge graph; is the sigmoid function.

Citation Information

Patent Citations

  • Knowledge graph completion method fusing text description and graph convolution mechanism

    CN116383401A

  • Knowledge graph completion method and system based on triple global information interaction

    CN117035080A