An intelligent question and answer method and system based on a numerical control machine tool fault knowledge graph
By constructing a knowledge graph of CNC machine tool faults and integrating GAT and RotatE models, the problems of low accuracy and insufficient efficiency in the fault diagnosis of CNC machine tools in the existing technology are solved, realizing fast and accurate fault diagnosis and personalized query, and improving maintenance efficiency.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- NANJING UNIV OF AERONAUTICS & ASTRONAUTICS
- Filing Date
- 2023-01-30
- Publication Date
- 2026-04-24
AI Technical Summary
Existing CNC machine tool fault knowledge graphs suffer from problems such as a lack of entity relationships, low accuracy of knowledge reasoning models in professional fields, and inability to perform personalized queries, resulting in insufficient efficiency and accuracy in CNC machine tool fault diagnosis.
A knowledge graph of CNC machine tool faults is constructed, integrating the knowledge reasoning models of GAT and RotatE. It is trained through graph attention layer and link prediction layer, and combined with semantic similarity calculation and intent recognition to generate an intelligent question answering system, providing maintenance personnel with a fast and accurate fault diagnosis method.
It improves the speed and accuracy of CNC machine tool fault diagnosis, enhances the reasoning ability and personalized query adaptability of knowledge graphs in professional fields, and improves maintenance efficiency.
Smart Images

Figure CN116150337B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of knowledge graph question answering technology, specifically relating to an intelligent question answering method and system based on a knowledge graph of CNC machine tool faults. Background Technology
[0002] With the rapid development of global manufacturing, CNC machine tools are becoming increasingly widely used and indispensable in enterprise production. If malfunctions in certain CNC machine tools are not detected and addressed promptly, it will affect the normal operation of the entire system, or even cause it to shut down, resulting in significant economic losses and personnel casualties for the enterprise. However, during the use of CNC machine tools, factors such as the operating environment and improper operation by staff can inevitably cause malfunctions. Furthermore, once a malfunction occurs, the massive amounts of status data and monitoring variables generated during the operation of the CNC machine tool make repairs far more difficult than with ordinary machine tools.
[0003] Since the beginning of the 21st century, the rapid development of the internet has led to an explosive growth in both the variety and quantity of online information. To effectively manage and utilize this vast amount of information, companies like Google and Microsoft have adopted keyword search methods to optimize their search tools: users simply enter keywords, and the search engine retrieves relevant web pages for them to choose from. However, keyword-based search does not consider the deep semantic relationships between text, resulting in relatively low search efficiency. Against this backdrop, Google proposed the concept of Knowledge Graph (KG) in November 2012 and applied it to its search engine to enhance its capabilities and improve the quality of user searches.
[0004] The main idea of knowledge graph-based intelligent question answering systems is to analyze the question, transform it into a query statement containing entities and relationships, query the knowledge graph, and return the triples as the answer. Knowledge graph-based intelligent question answering systems have been applied to various fields such as movie recommendations and CNC machine tool fault diagnosis. However, existing intelligent question answering systems based on CNC machine tool fault diagnosis knowledge graphs have some shortcomings: First, existing CNC machine tool fault diagnosis knowledge graphs lack a significant amount of information about relationships between entities; second, while existing knowledge reasoning models achieve high accuracy when processing general knowledge graphs such as those for books and movies, they are slower and less accurate when processing specialized knowledge graphs such as those for CNC machine tool fault diagnosis because the deep causal relationships between entities in specialized knowledge graphs are difficult to uncover; third, existing intelligent question answering systems based on CNC machine tool fault diagnosis knowledge graphs directly query the knowledge graph for user-submitted questions without performing reasoning or prediction, resulting in low adaptability to personalized user questions and one-sided query results. Summary of the Invention
[0005] The purpose of this invention is to overcome the shortcomings of the prior art and provide an intelligent question-and-answer method and system based on a knowledge graph of CNC machine tool faults. This invention introduces knowledge graphs and intelligent question-and-answer into the field of fault diagnosis. By integrating the knowledge reasoning models of GAT and RotatE, knowledge reasoning is performed on the knowledge graph of CNC machine tool faults, and an intelligent question-and-answer system is constructed. This provides an effective and fast way for maintenance personnel to find repair methods for CNC machine tool faults.
[0006] To solve the above-mentioned technical problems, the present invention adopts the following technical solution.
[0007] The present invention provides an intelligent question-answering method based on a CNC machine tool fault knowledge graph, comprising the following steps:
[0008] S1. Constructing a CNC machine tool fault knowledge graph: Process the collected CNC machine tool equipment maintenance records, retain the semantic relationships between entities, and generate fault triples. The fault triples include a head entity, a relation, and a tail entity. Store the fault triples in the CNC machine tool fault knowledge base. Proportionally split the fault triples into training sets, validation sets, and test sets. Import the fault triples into the Neo4j graph database to form a brand new CNC machine tool fault knowledge graph.
[0009] S2. Construct and train a knowledge reasoning model that integrates GAT and RotatE: The knowledge reasoning model that integrates GAT and RotatE includes a graph attention layer and a link prediction layer. The fault triples in the CNC machine tool fault knowledge base are input into the graph attention layer. After training, the embedded representation vectors of entities and relations are input into the link prediction layer. In the link prediction layer, negative fault triples are obtained from positive fault triples by random sampling. The scores of positive and negative fault triples are calculated by a scoring function. After iterative optimization, the embedded representation vectors of entities and relations output by the link prediction layer are saved.
[0010] S3. Question Identification: Construct an intelligent question-answering system webpage, obtain the question text submitted by the user, extract keywords from the question text using Python libraries and a custom dictionary, perform semantic similarity calculation between the keywords of the question text and the entities of the CNC machine tool fault triplet, determine the head entity of the question triplet, determine the relationship of the question triplet by combining feature word matching and intent recognition, and randomly select an entity from the CNC machine tool fault knowledge base as the tail entity of the question triplet.
[0011] S4. Answer Output: Replace the tail entity of the question triple with the entity in the CNC machine tool fault knowledge base to obtain the replaced question triple. Call the entity and relation embedding representation vector obtained by training the knowledge reasoning model that integrates GAT and RotatE to convert the replaced question triple into vector form. Calculate the score of the replaced question triple using the scoring function. Sort and filter the replaced question triples according to the score. Finally, output the ten replaced question triples with the lowest scores to the user in the form of a table.
[0012] Furthermore, the construction of the CNC machine tool fault knowledge graph in step S1 includes:
[0013] S1.1 Processing of CNC machine tool equipment maintenance records: The collected CNC machine tool equipment maintenance records are processed, missing and meaningless lines are deleted, and the three entity categories of equipment name, fault condition and maintenance result and the semantic relationships between different entity categories are retained. Based on the retained entity categories and semantic relationships, fault triplets consisting of head entity, relation and tail entity are constructed and stored in the CNC machine tool fault knowledge base.
[0014] S1.2, Divide the training set, validation set and test set: Randomly divide the fault triplet into three parts, namely training set, validation set and test set, according to the ratio of 7:2:1. The training set is used to update the parameters of the knowledge reasoning model that integrates GAT and RotatE. The validation set is used to adjust the parameters of the knowledge reasoning model that integrates GAT and RotatE. The test set is used to evaluate the generalization ability of the knowledge reasoning model that integrates GAT and RotatE.
[0015] S1.3 Constructing a CNC machine tool fault knowledge graph: Using Python, a CNC machine tool fault knowledge graph is created. Fault triples from the CNC machine tool fault knowledge base are inserted into the CNC machine tool fault knowledge graph. The entities and relations of the fault triples are represented by nodes and edges of the CNC machine tool fault knowledge graph, respectively. A brand-new CNC machine tool fault knowledge graph is generated through the Neo4j graph database and visualized.
[0016] Furthermore, the construction and training of the knowledge reasoning model integrating GAT and RotatE described in step S2 includes:
[0017] S2.1 Constructing the Graph Attention Layer: The graph attention layer adopts an attention mechanism, models the graph using an aggregation function, calculates the weight relationship between nodes and their neighbors in the CNC machine tool fault knowledge graph, then performs non-linear activation on the weight relationship, obtains the attention coefficients through a logistic regression function, and finally aggregates the attention coefficients to obtain the node embedding representation vector at output. When implementing the code, specify the number of nodes, learning rate, and number of iterations for each layer of the graph attention layer.
[0018] To transform the entities and relations input to the knowledge reasoning model that integrates GAT and RotatE into a vector space, an initialized matrix W (W∈R) is used. F′×F Define a mapping b:R F′ ×R F →R, where F and F' represent the dimensions of the entity and relation embedding vectors at input and output, respectively. The weight relationship between node i and node j is then calculated using the attention mechanism.
[0019] e ij =b(Wx i Wx j (1)
[0020] Among them, e ij Let be the weight relationship between node i and node j, b be the mapping vector, W be the linear transformation matrix between node i and node j, and x be the weight relationship between node i and node j. i It is node i, x j It is node j, a neighbor of node i;
[0021] By adding the LeakyReLU nonlinear activation function and performing regularization using the softmax function, the attention coefficients of node i are obtained:
[0022]
[0023] Where, α ij N is the attention coefficient of node i. i It is a neighbor node of the i-th node, and exp(x) is the mathematical operation e x || is the vector concatenation operation, b T It is the transpose of the mapping vector b, x k It is a neighbor node of the k-th node;
[0024] By summing the weighted attention coefficients of node i, we can obtain the embedded representation vector of node i after training:
[0025]
[0026] Where σ is a nonlinear transformation operation, x i ′ is the embedding representation vector of node i after training;
[0027] S2.2 Constructing the Link Prediction Layer: Utilize the RotatE model to construct a link prediction layer that integrates the knowledge reasoning models of GAT and RotatE. Use random sampling to obtain negative fault triples from positive fault triples. Calculate the scores of positive and negative fault triples using a scoring function. When implementing the code, specify the dimension, loss function, and scoring function of the embedding representation vectors of entities and relations in the RotatE model.
[0028] The basic idea of the RotatE model comes from Euler's formula:
[0029] e iθ =cosθ+isinθ (4)
[0030] Here, the exponent iθ is represented as the rotation angle θ in the complex vector space; therefore, the RotatE model maps entities and relations to the complex vector space, and defines a relation as the rotation angle from the head entity embedding vector to the tail entity embedding vector; given a faulty triple, the rotation vector obtained by rotating the head entity embedding vector of the faulty triple through the relation embedding vector of the faulty triple should be as close as possible to the tail entity embedding vector of the faulty triple; the closer the rotation vector and the tail entity embedding vector of the faulty triple are, the more accurate the entity and relation embedding vectors of the faulty triple are; the distance function is used to calculate the closeness between the rotation vector and the tail entity embedding vector of the faulty triple, and the calculation formula is as follows:
[0031]
[0032] Where, d r (h,r,t) represents the score of the faulty triple, where h is the head entity embedding vector of the faulty triple, r is the relation embedding vector of the faulty triple, and t is the tail entity embedding vector of the faulty triple. This represents the circular multiplication operation, ||·|| L1 / L2 The L1 norm or L2 norm is represented by the following formula:
[0033]
[0034]
[0035] Where X is a matrix, x i Let i be the i-th element in the matrix;
[0036] S2.3 Training the knowledge reasoning model integrating GAT and RotatE: The training set of fault triples in the CNC machine tool fault knowledge base is input into the graph attention layer of the knowledge reasoning model integrating GAT and RotatE for training. The embedded representation vector of each node in the CNC machine tool fault knowledge graph after training is obtained. The scores of positive and negative fault triples are calculated. The MarginLoss function is designed as the loss function. The formula for calculating the loss function is as follows:
[0037] Loss = max[0, γ + d r (h,t)-d r' (h',t')] (8)
[0038] Where Loss represents the loss function value of the faulty triplet, γ represents the distance between the positive and negative faulty triplets, typically taken as 1, and d r (h,t) represents the score of the positive example fault triplet, d r' (h',t') represents the score of the negative example fault triplet;
[0039] The Adam optimizer is used to optimize learning and continuously update the weight parameters of the knowledge reasoning model that integrates GAT and RotatE, so that the loss function value of the faulty triples is continuously reduced. After the loop ends, the embedding representation vectors of entities and relations of the faulty triples are saved.
[0040] S2.4 Testing the performance of the knowledge reasoning model integrating GAT and RotatE: Using the entity and relation embedding representation vectors of the fault triples obtained after training the knowledge reasoning model integrating GAT and RotatE, the test set of fault triples in the CNC machine tool fault knowledge base is converted into the form of embedding representation vectors. Then, the head entity and tail entity of the test set of the fault triples are replaced to obtain the replaced fault triples. All replaced fault triples are sorted from low to high according to the score results by the scoring function. The positions of the head entity or tail entity of the fault triple before replacement are found. The generalization ability of the knowledge reasoning model integrating GAT and RotatE is evaluated using the Hit@3, Hit@10, MR, and MRR evaluation indicators.
[0041] Furthermore, the problem identification described in step S3 includes:
[0042] S3.1 Building the intelligent question-answering system webpage: Create a project using Python's Django library, modify the routing address, select CSS and JS plugins to write HTML webpage files, so that the backend can receive questions raised by users on the intelligent question-answering system webpage and display the processed results on the intelligent question-answering system webpage;
[0043] S3.2 Entity Recognition: Using Python's jieba library and a custom dictionary, keywords of the user's question are extracted. Semantic similarity is calculated between the keywords of the question and entities in the CNC machine tool fault knowledge base. The entity in the CNC machine tool fault knowledge base with the highest semantic similarity calculation result is the head entity of the question triple.
[0044] S3.3 Constructing Question Triples: Using a combination of feature word matching and intent recognition, the relationship between question triples is confirmed. Then, the head entity of the question triple, the relationship between the question triples, and an entity randomly selected from the CNC machine tool fault knowledge base are used as the tail entity of the question triple to jointly constitute the question triple.
[0045] Furthermore, the answer output described in step S4 includes:
[0046] S4.1 Calculate and sort the scores of negative example problem triplets: Replace the tail entity of the problem triplet with the entity in the CNC machine tool fault knowledge base to obtain the negative example problem triplet. Use the entity and relation embedding representation vector obtained after training the knowledge reasoning model that integrates GAT and RotatE to transform the entity and relation of the negative example problem triplet into the embedding representation vector. Calculate the score of all negative example problem triplets through the scoring function and sort them from low to high according to the score results.
[0047] S4.2 Knowledge Screening: Perform knowledge screening on the sorted negative example problem triples, and remove the negative example problem triples that do not meet the tail entity label requirements.
[0048] S4.3 Returning Answers: The ten negative example question triplets with the lowest scores after knowledge filtering will be displayed to the user in a table format on the intelligent question answering system webpage as answers.
[0049] Specifically, the semantic similarity calculation includes an edit distance similarity component, a character overlap coefficient similarity component, and a cosine similarity component:
[0050] Edit distance similarity is based on string C i To string C j The minimum number of operations required for the transformation, including insertion, deletion, and replacement, is calculated using the following formula:
[0051]
[0052] Where LD is the string C i To string C j The minimum number of operations required for the transformation, length(C) i ) and length(C j ) represent the string C respectively iand string C j The character length, S LD (C i C j ) represents the string C i and string C j Edit distance similarity;
[0053] The character overlap coefficient similarity is based on string C i and string C j The number of identical characters is calculated.
[0054]
[0055] Where N is the string C i and string C j The number of identical characters, length(set(C i C j )) represents the string C i and string C j The length of the set of non-repeating characters in the set, S OC (C i C j ) represents the string C i and string C j Character overlap coefficient similarity;
[0056] Cosine similarity measures the difference between two characters using the cosine of the angle between two vectors in a vector space. In calculating string C... i and string C j When calculating cosine similarity, the embedding representation vectors of entities trained using a knowledge reasoning model that integrates GAT and RotatE are used to convert strings into embedding representation vectors, and then the cosine similarity formula is applied for calculation.
[0057]
[0058] Among them, V Ci and V Cj They are the strings C i and string C j The embedding representation vector, ||V Ci ||and||V Cj || These are strings C. i and string C j The features of the embedding representation vector, S COS (C i C j ) represents the string C i and string C j Cosine similarity;
[0059] String C i and string C j semantic similarity S(C) i C j The edit distance similarity S is defined as... LD (C i C j Character overlap coefficient similarity S OC (C i C j ) and cosine similarity S COS (C i C j The arithmetic mean of the three is calculated using the following formula:
[0060]
[0061] Among them, S(C i C j ) represents the string C i and string C j Semantic similarity.
[0062] The present invention provides an intelligent question-answering system based on a CNC machine tool fault knowledge graph, which, when implemented, executes the aforementioned intelligent question-answering method based on a CNC machine tool fault knowledge graph. The system includes: a CNC machine tool fault knowledge graph construction module, a knowledge reasoning model construction and training module integrating GAT and RotatE, a question identification module, and an answer output module.
[0063] Compared with the prior art, the present invention has the following advantages and beneficial effects:
[0064] 1. This invention processes CNC machine tool fault repair records, constructs fault triples, imports the fault triples into the Neo4j graph database, and generates a brand-new CNC machine tool fault knowledge graph. The CNC machine tool fault knowledge graph generated by this invention is different from existing CNC machine tool fault knowledge graphs. It is a supplement to existing CNC machine tool fault knowledge graphs and realizes further integration and analysis of the CNC machine tool fault domain.
[0065] 2. This invention provides a novel method for calculating the semantic similarity of different strings: First, the edit distance similarity, character overlap similarity, and cosine similarity of different strings are calculated separately. Then, the arithmetic mean of the three semantic similarity calculation results is used as the final semantic similarity calculation result of different strings. The novel semantic similarity calculation method can simultaneously consider the three cases of edit distance, character overlap, and cosine similarity when calculating the semantic similarity of different strings, thereby improving the accuracy of matching different strings through the semantic similarity calculation results.
[0066] 3. This invention provides a knowledge reasoning model that integrates GAT and RotatE. This model includes a graph attention layer and a link prediction layer. When processing CNC machine tool fault knowledge graphs, the knowledge reasoning model that integrates GAT and RotatE can deeply mine the rich semantic information of the entities themselves and the potential causal relationships between entities. The accuracy of link prediction is much higher than that of existing knowledge reasoning models. Attached Figure Description
[0067] Figure 1 This is a flowchart of an intelligent question-answering method based on a CNC machine tool fault knowledge graph, according to an embodiment of the present invention.
[0068] Figure 2 This is a schematic diagram of a triplet in the CNC machine tool fault knowledge graph according to an embodiment of the present invention.
[0069] Figure 3 This is a structural diagram of a knowledge reasoning model that integrates GAT and RotatE to calculate the attention coefficient, according to an embodiment of the present invention.
[0070] Figure 4 This is a simplified illustration of the RotatE model, which is an embodiment of the present invention.
[0071] Figure 5 This is a structural diagram of a knowledge reasoning model that integrates GAT and RotatE according to an embodiment of the present invention.
[0072] Figure 6 This is a webpage image of an intelligent question-and-answer system based on a CNC machine tool fault knowledge graph, according to an embodiment of the present invention. Detailed Implementation
[0073] This invention discloses an intelligent question-answering method based on a CNC machine tool fault knowledge graph, comprising: processing CNC machine tool maintenance records to generate fault triples and a CNC machine tool fault knowledge graph; constructing a knowledge reasoning model integrating GAT and RotatE, and saving the embedded representation vectors of entities and relations after training; identifying head entities and relations from user-submitted questions, randomly selecting tail entities from the CNC machine tool fault knowledge graph, and constructing question triples; replacing the tail entities of the question triples with entities from the CNC machine tool fault knowledge graph to obtain replaced question triples, calculating the scores of the replaced question triples and sorting them, and outputting the sorted results in tabular form after filtering. This invention addresses the problem of low efficiency for maintenance personnel in querying fault maintenance records and consulting maintenance manuals after a CNC machine tool malfunction. By integrating past CNC machine tool maintenance records, it can effectively improve the speed and accuracy of CNC machine tool fault diagnosis and repair.
[0074] The present invention will now be described in further detail with reference to the accompanying drawings.
[0075] The present invention discloses an intelligent question-answering method based on a CNC machine tool fault knowledge graph, the flowchart of which is shown below. Figure 1 As shown, it includes the following steps:
[0076] S1. Constructing a CNC machine tool fault knowledge graph: Process the collected CNC machine tool equipment maintenance records, retain the semantic relationships between entities, and generate fault triples. The fault triples include a head entity, a relation, and a tail entity. Store the fault triples in the CNC machine tool fault knowledge base. Proportionally split the fault triples into training sets, validation sets, and test sets. Import the fault triples into the Neo4j graph database to form a brand new CNC machine tool fault knowledge graph.
[0077] S2. Construct and train a knowledge reasoning model that integrates GAT and RotatE: The knowledge reasoning model that integrates GAT and RotatE includes a graph attention layer and a link prediction layer. The fault triples in the CNC machine tool fault knowledge base are input into the graph attention layer. After training, the embedded representation vectors of entities and relations are input into the link prediction layer. In the link prediction layer, negative fault triples are obtained from positive fault triples by random sampling. The scores of positive and negative fault triples are calculated by a scoring function. After iterative optimization, the embedded representation vectors of entities and relations output by the link prediction layer are saved.
[0078] S3. Question Identification: Construct an intelligent question-answering system webpage, obtain the question text submitted by the user, extract keywords from the question text using Python libraries and a custom dictionary, perform semantic similarity calculation between the keywords of the question text and the entities of the CNC machine tool fault triplet, determine the head entity of the question triplet, determine the relationship of the question triplet by combining feature word matching and intent recognition, and randomly select an entity from the CNC machine tool fault knowledge base as the tail entity of the question triplet.
[0079] S4. Answer Output: Replace the tail entity of the question triple with the entity in the CNC machine tool fault knowledge base to obtain the replaced question triple. Call the entity and relation embedding representation vector obtained by training the knowledge reasoning model that integrates GAT and RotatE to convert the replaced question triple into vector form. Calculate the score of the replaced question triple using the scoring function. Sort and filter the replaced question triples according to the score. Finally, output the ten replaced question triples with the lowest scores to the user in the form of a table.
[0080] Specifically, step S1, which involves constructing a knowledge graph of CNC machine tool faults, includes:
[0081] S1.1 Processing of CNC machine tool equipment maintenance records: The collected CNC machine tool equipment maintenance records are processed, missing and meaningless lines are deleted, and the three entity categories of equipment name, fault condition and maintenance result and the semantic relationships between different entity categories are retained. Based on the retained entity categories and semantic relationships, fault triplets consisting of head entity, relation and tail entity are constructed and stored in the CNC machine tool fault knowledge base.
[0082] S1.2, Divide the training set, validation set and test set: Randomly divide the fault triplet into three parts, namely training set, validation set and test set, according to the ratio of 7:2:1. The training set is used to update the parameters of the knowledge reasoning model that integrates GAT and RotatE. The validation set is used to adjust the parameters of the knowledge reasoning model that integrates GAT and RotatE. The test set is used to evaluate the generalization ability of the knowledge reasoning model that integrates GAT and RotatE.
[0083] S1.3 Constructing a CNC Machine Tool Fault Knowledge Graph: A CNC machine tool fault knowledge graph is created using Python. Fault triples from the CNC machine tool fault knowledge base are inserted into the graph. The entities and relations of these triples are represented by nodes and edges in the CNC machine tool fault knowledge graph, respectively. A completely new CNC machine tool fault knowledge graph is generated using the Neo4j graph database and then visualized. Some triples in the CNC machine tool fault knowledge graph are shown below. Figure 2 As shown, there are three entity categories: equipment name, fault condition, and current status, and two relationship categories: equipment fault and repair result. Among them, the equipment name includes attributes such as id, model and specifications, and manufacturer; the fault condition includes attributes such as id, occurrence date, and repair date; and the current status includes attributes such as id and repair category.
[0084] Specifically, step S2 involves constructing and training a knowledge reasoning model that integrates GAT and RotatE, including:
[0085] S2.1 Constructing the Graph Attention Layer: The graph attention layer adopts an attention mechanism, models the graph using an aggregation function, calculates the weight relationship between nodes and their neighbors in the CNC machine tool fault knowledge graph, then performs non-linear activation on the weight relationship, obtains the attention coefficients through a logistic regression function, and finally aggregates the attention coefficients to obtain the node embedding representation vector at output. When implementing the code, specify the number of nodes, learning rate, and number of iterations for each layer of the graph attention layer.
[0086] The attention coefficient structure diagram of the graph attention model is shown below. Figure 3 As shown, in order to transform the entities and relations input to the knowledge reasoning model that integrates GAT and RotatE into a vector space, an initialized matrix W (W∈R) is used. F′×F Define a mapping b:RF′ ×R F →R, where F and F' represent the dimensions of the entity and relation embedding vectors at input and output, respectively. The weight relationship between node i and node j is then calculated using the attention mechanism.
[0087] e ij =b(Wx i Wx j (1)
[0088] Among them, e ij Let be the weight relationship between node i and node j, b be the mapping vector, W be the linear transformation matrix between node i and node j, and x be the weight relationship between node i and node j. i It is node i, x j It is node j, a neighbor of node i;
[0089] By adding the LeakyReLU nonlinear activation function and performing regularization using the softmax function, the attention coefficients of node i are obtained:
[0090]
[0091] Where, α ij N is the attention coefficient of node i. i It is a neighbor node of the i-th node, and exp(x) is the mathematical operation e x || is the vector concatenation operation, b T It is the transpose of the mapping vector b, x k It is a neighbor node of the k-th node;
[0092] By summing the weighted attention coefficients of node i, we can obtain the embedded representation vector of node i after training:
[0093]
[0094] Where σ is a nonlinear transformation operation, x i ′ is the embedding representation vector of node i after training;
[0095] S2.2 Constructing the Link Prediction Layer: Utilize the RotatE model to construct a link prediction layer that integrates the knowledge reasoning models of GAT and RotatE. Use random sampling to obtain negative fault triples from positive fault triples. Calculate the scores of positive and negative fault triples using a scoring function. When implementing the code, specify the dimension, loss function, and scoring function of the embedding representation vectors of entities and relations in the RotatE model.
[0096] Figure 4This is a simplified diagram illustrating the RotatE model. The basic idea of the RotatE model comes from Euler's formula:
[0097] e iθ =cosθ+isinθ (4)
[0098] Here, the exponent iθ is represented as the rotation angle θ in the complex vector space; therefore, the RotatE model maps entities and relations to the complex vector space, and defines a relation as the rotation angle from the head entity embedding vector to the tail entity embedding vector; given a faulty triple, the rotation vector obtained by rotating the head entity embedding vector of the faulty triple through the relation embedding vector of the faulty triple should be as close as possible to the tail entity embedding vector of the faulty triple; the closer the rotation vector and the tail entity embedding vector of the faulty triple are, the more accurate the entity and relation embedding vectors of the faulty triple are; the distance function is used to calculate the closeness between the rotation vector and the tail entity embedding vector of the faulty triple, and the calculation formula is as follows:
[0099]
[0100] Where, d r (h,r,t) represents the score of the faulty triple, where h is the head entity embedding vector of the faulty triple, r is the relation embedding vector of the faulty triple, and t is the tail entity embedding vector of the faulty triple. This represents the circular multiplication operation, ||·|| L1 / L2 The L1 norm or L2 norm is represented by the following formula:
[0101]
[0102]
[0103] Where X is a matrix, x i Let i be the i-th element in the matrix.
[0104] Knowledge graphs include three relation patterns: symmetric / antisymmetric, inverted, and composite. For example, the classmate relationship belongs to the symmetric / antisymmetric pattern; the teacher and student relationship belongs to the inverted pattern; the uncle relationship consists of the father and brother relationships, so the uncle, father, and brother relationships belong to the composite pattern. Table 1 lists the capabilities of some existing knowledge reasoning models in handling these three relation patterns when the RotatE model was proposed.
[0105] Table 1 summarizes the ability of some knowledge reasoning models to handle three relational patterns.
[0106] Symmetric / Antisymmetric Reversal combination SE × × × TransE × √ √ DistMult √ × × ComplEx √ √ × RotatE √ √ √
[0107] As can be seen from Table 1, before the RotatE model was proposed, other knowledge reasoning models could not handle the three relation patterns simultaneously. For example, the TransE model cannot handle symmetric relation patterns because the embedding vector of the relation in the TransE model is always equal to zero under symmetric relation patterns; the ComplEx model expands the interference by introducing complex embeddings to better model symmetric and inverse relation patterns, but it cannot handle composite relation patterns.
[0108] S2.3 Training the knowledge reasoning model that integrates GAT and RotatE: The structure diagram of the knowledge reasoning model that integrates GAT and RotatE is as follows. Figure 5 As shown, the training set of fault triples in the CNC machine tool fault knowledge base is input into the graph attention layer of the knowledge reasoning model that integrates GAT and RotatE for training. This yields the embedding representation vector of each node in the trained CNC machine tool fault knowledge graph. The scores of positive and negative fault triples are calculated, and the MarginLoss function is designed as the loss function. The formula for calculating the loss function is as follows:
[0109] Loss = max[0, γ + d r (h,t)-d r' (h',t')] (8)
[0110] Where Loss represents the loss function value of the faulty triplet, γ represents the distance between the positive and negative faulty triplets, typically taken as 1, and d r (h,t) represents the score of the positive example fault triplet, d r' (h',t') represents the score of the negative example fault triplet;
[0111] The Adam optimizer is used to optimize learning and continuously update the weight parameters of the knowledge reasoning model that integrates GAT and RotatE, so that the loss function value of the faulty triples is continuously reduced. After the loop ends, the embedding representation vectors of entities and relations of the faulty triples are saved.
[0112] S2.4 Testing the performance of the knowledge reasoning model integrating GAT and RotatE: Using the entity and relation embedding representation vectors of the fault triples obtained after training the knowledge reasoning model integrating GAT and RotatE, the test set of fault triples in the CNC machine tool fault knowledge base is converted into the form of embedding representation vectors. Then, the head entity and tail entity of the test set of the fault triples are replaced to obtain the replaced fault triples. All replaced fault triples are sorted from low to high according to the score results by the scoring function. The positions of the head entity or tail entity of the fault triple before replacement are found. The generalization ability of the knowledge reasoning model integrating GAT and RotatE is evaluated using the Hit@3, Hit@10, MR, and MRR evaluation indicators.
[0113] Specifically, step S3, problem identification, includes:
[0114] S3.1 Building the Intelligent Question Answering System Webpage: Create a project using Python's Django library, modify the routing address, select CSS and JS plugins to write HTML webpage files, and run the HTML files to create an intelligent question answering system webpage based on a CNC machine tool fault knowledge graph, as shown below. Figure 6 As shown, the backend can receive questions submitted by users in text boxes on the intelligent question-and-answer system webpage and display the processed results on the intelligent question-and-answer system webpage.
[0115] S3.2 Entity Recognition: Using Python's jieba library and a custom dictionary, keywords of the user's question are extracted. Semantic similarity is calculated between the keywords and entities in the CNC machine tool fault knowledge base. The entity in the CNC machine tool fault knowledge base with the highest semantic similarity calculation result is the head entity of the question triple.
[0116] The semantic similarity calculation method employed in this invention mainly involves three similarity calculation methods: edit distance similarity (Levenshtein Distance, LD), overlap coefficient similarity (OC), and cosine similarity. First, the edit distance similarity, overlap coefficient similarity, and cosine similarity of different strings are calculated separately. Then, the arithmetic mean of these three semantic similarity results is used as the final semantic similarity calculation result. This invention's semantic similarity calculation method considers edit distance, overlap coefficient, and cosine similarity simultaneously when calculating the semantic similarity of different strings, thereby improving the accuracy of matching different strings using the semantic similarity calculation results.
[0117] Edit distance similarity is based on string C i To string Cj The minimum number of operations required for the transformation, including insertion, deletion, and replacement, is calculated using the following formula:
[0118]
[0119] Where LD is the string C i To string C j The minimum number of operations required for the transformation, length(C) i ) and length(C j ) represent the string C respectively i and string C j The character length, S LD (C i C j ) represents the string C i and string C j Edit distance similarity.
[0120] The character overlap coefficient similarity is based on string C i and string C j The number of identical characters is calculated; the specific calculation formula is shown below:
[0121]
[0122] Where N is the string C i and string C j The number of identical characters, length(set(C i C j )) represents the string C i and string C j The length of the set of non-repeating characters in the set, S OC (C i C j ) represents the string C i and string C j The character overlap coefficient similarity.
[0123] Cosine similarity measures the difference between two characters using the cosine of the angle between two vectors in a vector space. In calculating string C... i and string C j When calculating cosine similarity, the embedding representation vectors of entities trained using a knowledge reasoning model that integrates GAT and RotatE are used to convert strings into embedding representation vectors, and then the cosine similarity formula is applied for calculation.
[0124]
[0125] Among them, V Ci and VCj They are the strings C i and string C j The embedding representation vector, ||V Ci ||and||V Cj || These are strings C. i and string C j The features of the embedding representation vector, S COS (C i C j ) represents the string C i and string C j The cosine similarity.
[0126] This invention will use string C i and C j semantic similarity S(C) i C j The edit distance similarity S is defined as... LD (C i C j Character overlap coefficient similarity S OC (C i C j ) and cosine similarity S COS (C i C j The arithmetic mean of the three is calculated using the following formula:
[0127]
[0128] Among them, S(C i C j ) represents the string C i and string C j Semantic similarity.
[0129] The novel semantic similarity calculation method proposed in this invention can simultaneously consider three factors when calculating the semantic similarity of different strings: edit distance, character overlap, and cosine similarity. This improves the accuracy of matching different strings using the semantic similarity calculation results.
[0130] S3.3 Constructing Question Triples: Using a combination of feature word matching and intent recognition, the relationship between question triples is confirmed. Then, the head entity of the question triple, the relationship between the question triples, and an entity randomly selected from the CNC machine tool fault knowledge base are used as the tail entity of the question triple to jointly constitute the question triple.
[0131] Specifically, the answer output in step S4 includes:
[0132] S4.1 Calculate and sort the scores of negative example problem triplets: Replace the tail entity of the problem triplet with the entity in the CNC machine tool fault knowledge base to obtain the negative example problem triplet. Use the entity and relation embedding representation vector obtained after training the knowledge reasoning model that integrates GAT and RotatE to transform the entity and relation of the negative example problem triplet into the embedding representation vector. Calculate the score of all negative example problem triplets through the scoring function and sort them from low to high according to the score results.
[0133] S4.2 Knowledge Screening: Perform knowledge screening on the sorted negative example problem triples, and remove the negative example problem triples that do not meet the tail entity label requirements.
[0134] S4.3 Returning Answers: The ten negative example question triplets with the lowest scores after knowledge filtering will be displayed to the user in a table format on the intelligent question answering system webpage as answers.
[0135] The present invention provides an intelligent question-answering system based on a CNC machine tool fault knowledge graph, which, when implemented, executes the aforementioned intelligent question-answering method based on a CNC machine tool fault knowledge graph. The system includes: a CNC machine tool fault knowledge graph construction module, a knowledge reasoning model construction and training module integrating GAT and RotatE, a question identification module, and an answer output module.
[0136] The knowledge reasoning model integrating GAT and RotatE proposed in this invention was validated on a CNC machine tool fault knowledge base. The link prediction experiment results are shown in Table 2.
[0137] Table 2. Results of the Link Prediction Experiment Using the Knowledge Reasoning Model Integrating GAT and RotatE
[0138]
[0139] As can be seen from Table 2, the knowledge reasoning model that integrates GAT and RotatE proposed in this invention can effectively predict the tail entity of the fault triple in the fault knowledge base of CNC machine tools when processing the fault knowledge graph. This allows for a better understanding of the past faults and maintenance methods of CNC machine tools, assists in determining the fault maintenance plan for CNC machine tools, and improves the speed and accuracy of fault diagnosis and maintenance of CNC machine tools.
Claims
1. An intelligent question-answering method based on a CNC machine tool fault knowledge graph, characterized in that, Includes the following steps: S1. Constructing a CNC machine tool fault knowledge graph: Process the collected CNC machine tool equipment maintenance records, retain the semantic relationships between entities, and generate fault triples. The fault triples include a head entity, a relation, and a tail entity. Store the fault triples in the CNC machine tool fault knowledge base. Proportionally split the fault triples into training sets, validation sets, and test sets. Import the fault triples into the Neo4j graph database to form a brand new CNC machine tool fault knowledge graph. S2. Construct and train a knowledge reasoning model that integrates GAT and RotatE: The knowledge reasoning model that integrates GAT and RotatE includes a graph attention layer and a link prediction layer. The fault triples from the CNC machine tool fault knowledge base are input into the graph attention layer. After training, the embedded representation vectors of entities and relations are input into the link prediction layer. In the link prediction layer, negative fault triples are obtained from positive fault triples by random sampling. The scores of positive and negative fault triples are calculated by a scoring function. After iterative optimization, the embedded representation vectors of entities and relations output by the link prediction layer are saved. S3. Question Identification: Construct an intelligent question-answering system webpage, obtain the question text submitted by the user, extract keywords from the question text using Python libraries and a custom dictionary, perform semantic similarity calculation between the keywords of the question text and the entities of the CNC machine tool fault triplet, determine the head entity of the question triplet, determine the relationship of the question triplet by combining feature word matching and intent recognition, and randomly select an entity from the CNC machine tool fault knowledge base as the tail entity of the question triplet. S4. Answer Output: Replace the tail entity of the question triplet with the entity in the CNC machine tool fault knowledge base to obtain the replaced question triplet. Call the entity and relation embedding representation vector obtained by training the knowledge reasoning model that integrates GAT and RotatE to convert the replaced question triplet into vector form. Calculate the score of the replaced question triplet using the scoring function. Sort and filter the replaced question triplet according to the score. Finally, output the ten replaced question triplets with the lowest scores to the user in the form of a table. The construction of the CNC machine tool fault knowledge graph in step S1 includes: S1.1 Processing of CNC machine tool equipment maintenance records: The collected CNC machine tool equipment maintenance records are processed, missing and meaningless lines are deleted, and the three entity categories of equipment name, fault condition and maintenance result and the semantic relationships between different entity categories are retained. Based on the retained entity categories and semantic relationships, fault triplets consisting of head entity, relation and tail entity are constructed and stored in the CNC machine tool fault knowledge base. S1.2, Divide the training set, validation set and test set: Randomly divide the fault triplet into three parts, namely training set, validation set and test set, according to the ratio of 7:2:
1. The training set is used to update the parameters of the knowledge reasoning model that integrates GAT and RotatE. The validation set is used to adjust the parameters of the knowledge reasoning model that integrates GAT and RotatE. The test set is used to evaluate the generalization ability of the knowledge reasoning model that integrates GAT and RotatE. S1.3 Constructing a CNC machine tool fault knowledge graph: Using Python, a CNC machine tool fault knowledge graph is created. Fault triples from the CNC machine tool fault knowledge base are inserted into the CNC machine tool fault knowledge graph. The entities and relations of the fault triples are represented by nodes and edges of the CNC machine tool fault knowledge graph, respectively. A brand-new CNC machine tool fault knowledge graph is generated through the Neo4j graph database and visualized. The construction and training of the knowledge reasoning model that integrates GAT and RotatE, as described in step S2, includes: S2.1 Constructing the Graph Attention Layer: The graph attention layer adopts an attention mechanism, models the graph using an aggregation function, calculates the weight relationship between nodes and their neighbors in the CNC machine tool fault knowledge graph, then performs non-linear activation on the weight relationship, obtains the attention coefficients through a logistic regression function, and finally aggregates the attention coefficients to obtain the node embedding representation vector at output. When implementing the code, specify the number of nodes, learning rate, and number of iterations for each layer of the graph attention layer. To transform the entities and relations input to the knowledge reasoning model that integrates GAT and RotatE into a vector space, an initialized matrix W (W∈R) is used. F′×F Define a mapping b:R F′ ×R F →R, where F and F' represent the dimensions of the entity and relation embedding vectors at input and output, respectively. The weight relationship between node i and node j is then calculated using the attention mechanism. e ij =b(Wx i ,Wx j ) (1) Among them, e ij Let be the weight relationship between node i and node j, b be the mapping vector, W be the linear transformation matrix between node i and node j, and x be the weight relationship between node i and node j. i It is node i, x j It is node j, a neighbor of node i; By adding the LeakyReLU nonlinear activation function and performing regularization using the softmax function, the attention coefficients of node i are obtained: Where, α ij N is the attention coefficient of node i. i It is a neighbor node of the i-th node, and exp(x) is the mathematical operation e x || is the vector concatenation operation, b T It is the transpose of the mapping vector b, x k It is a neighbor node of the k-th node; By summing the weighted attention coefficients of node i, we can obtain the embedded representation vector of node i after training: Where σ is a nonlinear transformation operation, x i ′ is the embedding representation vector of node i after training; S2.2 Constructing the Link Prediction Layer: Utilize the RotatE model to construct a link prediction layer that integrates the knowledge reasoning models of GAT and RotatE. Use random sampling to obtain negative fault triples from positive fault triples. Calculate the scores of positive and negative fault triples using a scoring function. When implementing the code, specify the dimension, loss function, and scoring function of the embedding representation vectors of entities and relations in the RotatE model. The basic idea of the RotatE model comes from Euler's formula: e iθ =cosθ+i sinθ (4) Here, the exponent iθ is represented as the rotation angle θ in the complex vector space; therefore, the RotatE model maps entities and relations to the complex vector space, and defines a relation as the rotation angle from the head entity embedding vector to the tail entity embedding vector; given a faulty triple, the rotation vector obtained by rotating the head entity embedding vector of the faulty triple through the relation embedding vector of the faulty triple should be as close as possible to the tail entity embedding vector of the faulty triple; the closer the rotation vector and the tail entity embedding vector of the faulty triple are, the more accurate the entity and relation embedding vectors of the faulty triple are; the distance function is used to calculate the closeness between the rotation vector and the tail entity embedding vector of the faulty triple, and the calculation formula is as follows: Where, d r (h,r,t) represents the score of the faulty triple, where h is the head entity embedding vector of the faulty triple, r is the relation embedding vector of the faulty triple, and t is the tail entity embedding vector of the faulty triple. This represents the circular multiplication operation, ||·|| L1 / L2 The L1 norm or L2 norm is represented by the following formula: Where X is a matrix, x i Let i be the i-th element in the matrix; S2.3 Training the knowledge reasoning model integrating GAT and RotatE: The training set of fault triples in the CNC machine tool fault knowledge base is input into the graph attention layer of the knowledge reasoning model integrating GAT and RotatE for training. The embedded representation vector of each node in the CNC machine tool fault knowledge graph after training is obtained. The scores of positive and negative fault triples are calculated. The MarginLoss function is designed as the loss function. The formula for calculating the loss function is as follows: Loss=max[0,γ+d r (h,t)-d r' (h',t')] (8) Where Loss represents the loss function value of the faulty triplet, γ represents the distance between the positive and negative faulty triplets, typically taken as 1, and d r (h,t) represents the score of the positive example fault triplet, d r' (h',t') represents the score of the negative example fault triplet; The Adam optimizer is used to optimize learning and continuously update the weight parameters of the knowledge reasoning model that integrates GAT and RotatE, so that the loss function value of the faulty triples is continuously reduced. After the loop ends, the embedding representation vectors of entities and relations of the faulty triples are saved. S2.4 Testing the performance of the knowledge reasoning model integrating GAT and RotatE: Using the entity and relation embedding representation vectors of the fault triples obtained after training the knowledge reasoning model integrating GAT and RotatE, the test set of fault triples in the CNC machine tool fault knowledge base is converted into the form of embedding representation vectors. Then, the head entity and tail entity of the test set of the fault triples are replaced to obtain the replaced fault triples. All replaced fault triples are sorted from low to high according to the score results by the scoring function. The position of the head entity or tail entity of the fault triple before replacement is found. The generalization ability of the knowledge reasoning model integrating GAT and RotatE is evaluated using the Hit@3, Hit@10, MR, and MRR evaluation indicators. The problem identification described in step S3 includes: S3.1 Building the intelligent question-answering system webpage: Create a project using Python's Django library, modify the routing address, select CSS and JS plugins to write HTML webpage files, so that the backend can receive questions raised by users on the intelligent question-answering system webpage and display the processed results on the intelligent question-answering system webpage; S3.2 Entity Recognition: Using Python's jieba library and a custom dictionary, keywords of the user's question are extracted. Semantic similarity is calculated between the keywords of the question and entities in the CNC machine tool fault knowledge base. The entity in the CNC machine tool fault knowledge base with the highest semantic similarity calculation result is the head entity of the question triple. S3.3 Constructing Question Triples: Using a combination of feature word matching and intent recognition, the relationship between question triples is confirmed. Then, the head entity of the question triple, the relationship between the question triples, and an entity randomly selected from the CNC machine tool fault knowledge base are used as the tail entity of the question triple to jointly constitute the question triple.
2. The intelligent question-answering method based on a CNC machine tool fault knowledge graph according to claim 1, characterized in that, The answer output described in step S4 includes: S4.1 Calculate and sort the scores of negative example problem triplets: Replace the tail entity of the problem triplet with the entity in the CNC machine tool fault knowledge base to obtain the negative example problem triplet. Use the entity and relation embedding representation vector obtained after training the knowledge reasoning model that integrates GAT and RotatE to transform the entity and relation of the negative example problem triplet into the embedding representation vector. Calculate the score of all negative example problem triplets through the scoring function and sort them from low to high according to the score results. S4.2 Knowledge Screening: Perform knowledge screening on the sorted negative example problem triples, and remove the negative example problem triples that do not meet the tail entity label requirements. S4.3 Returning Answers: The ten negative example question triplets with the lowest scores after knowledge filtering will be displayed to the user in a table format on the intelligent question answering system webpage as answers.
3. The intelligent question-answering method based on a CNC machine tool fault knowledge graph according to claim 1, characterized in that, The semantic similarity calculation includes an edit distance similarity component, a character overlap coefficient similarity component, and a cosine similarity component: Edit distance similarity is based on string C i To string C j The minimum number of operations required for the transformation, including insertion, deletion, and replacement, is calculated using the following formula: Where LD is the string C i To string C j The minimum number of operations required for the transformation, length(C) i ) and length(C j ) represent the string C respectively i and string C j The character length, S LD (C i C j ) represents the string C i and string C j Edit distance similarity; The character overlap coefficient similarity is based on string C i and string C j The number of identical characters is calculated. Where N is the string C i and string C j The number of identical characters, length(set(C i C j )) represents the string C i and string C j The length of the set of non-repeating characters in the set, S OC (C i C j ) represents the string C i and string C j Character overlap coefficient similarity; Cosine similarity is calculated by converting strings into embedded representation vectors and then using the following formula: Among them, V Ci and V Cj They are the strings C i and string C j The embedding representation vector, ||V Ci ||and||V Cj || These are strings C respectively i and string C j The embedding representation of the features of the vector, S COS (C i C j ) represents the string C i and string C j Cosine similarity; String C i and string C j semantic similarity S(C) i C j The edit distance similarity S is defined as... LD (C i C j Character overlap coefficient similarity S OC (C i C j ) and cosine similarity S COS (C i C j The arithmetic mean of the three is calculated using the following formula: Among them, S(C i C j ) represents the string C i and string C j Semantic similarity.
4. An intelligent question-and-answer system based on a CNC machine tool fault knowledge graph, characterized in that, When implemented, the intelligent question-answering method based on the CNC machine tool fault knowledge graph as described in any one of claims 1-3 includes: a CNC machine tool fault knowledge graph construction module, a knowledge reasoning model construction and training module integrating GAT and RotatE, a question identification module, and an answer output module.
Citation Information
Patent Citations
Knowledge graph long-tail relation completion method based on attention mechanism
CN111291139A
Knowledge graph link prediction method and device and computer readable storage medium
CN111460165A