Smart home-oriented attention diffusion knowledge graph reasoning method
By employing an attention-diffusion knowledge graph reasoning method for smart homes, and utilizing multi-head attention mechanisms and message diffusion processes, this approach addresses the issues of low reasoning efficiency, poor accuracy, and insufficient modeling of complex relationships in knowledge graphs within smart homes, thereby achieving efficient and accurate knowledge reasoning and device management.
Patent Information
- Application Number
- CN202511287075.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-10
- Publication Date
- 2025-11-18
- Estimated Expiration
- 2045-09-10
AI Technical Summary
Existing knowledge graphs suffer from low reasoning efficiency, poor accuracy, insufficient modeling of complex relationships, and inadequate generalization ability in smart home applications, especially under dynamic updates or sparse data conditions.
We adopt an attention diffusion knowledge graph reasoning method for smart homes. Through multi-head attention mechanism and message diffusion process, we dynamically adjust attention weights, optimize information transmission paths, and improve reasoning accuracy and efficiency by combining multi-level relationship modeling and entity feature representation.
It improves the accuracy and efficiency of knowledge graph reasoning in smart home scenarios, adapts to dynamic changes and data sparsity, and provides new technical means for device management and user behavior analysis.
Smart Images

Figure CN120806173B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the fields of knowledge graph and artificial intelligence technology, specifically relating to an attention diffusion knowledge graph reasoning method for smart homes. Background Technology
[0002] Knowledge graphs are an important research direction in the field of artificial intelligence, used for structured representation and storage of knowledge. By constructing a network of entities and relationships between entities, they help people better understand and mine the potential information in data, and are widely used in natural language processing, recommendation systems, smart homes and other fields. In the context of smart homes, knowledge graphs can be used for tasks such as device management, user behavior analysis, and scene linkage. However, current knowledge graph reasoning in smart home applications faces the following key problems: (1) Efficiency and accuracy of knowledge reasoning: Traditional methods rely on rules and shallow models, which are difficult to handle complex relationships and large entity networks, resulting in low efficiency and poor accuracy. (2) Modeling of complex relationships: Relationships in knowledge graphs are complex and diverse, such as hierarchical relationships, dynamic relationships and cross-domain associations, and traditional methods are difficult to fully capture deep semantic information. (3) Insufficient generalization ability: Existing methods have weak reasoning ability for unseen entities or relationships, especially in the case of dynamic updates or sparse data, the reasoning effect is not good. To solve these problems, researchers have proposed reasoning models based on deep learning, such as graph neural networks (GNNs) and convolutional neural networks (CNNs). While these methods improve inference performance, they still fall short in terms of complex relationship modeling and cross-scenario adaptability.
[0003] This invention proposes an attention diffusion knowledge graph reasoning method for smart homes, aiming to address the shortcomings of existing methods in terms of efficiency, accuracy, and complexity modeling, and to provide a more efficient and accurate knowledge graph reasoning scheme, which is particularly suitable for device management and user behavior analysis in smart home scenarios. Summary of the Invention
[0004] To address the aforementioned problems, this invention provides an attention diffusion knowledge graph reasoning method for smart homes.
[0005] To achieve the above objectives, the present invention employs the following technical solution:
[0006] This invention provides an attention diffusion knowledge graph reasoning method for smart homes, comprising the following steps:
[0007] S1. Extract entity, relation, and triple data from the publicly available WN18RR knowledge graph dataset;
[0008] S2. Determine the number of propagation layers in the reasoning process. And initialize the head entity set; the subsequent reasoning process will be conducted here. In the layer, repeat steps S3 to S6 to gradually construct the feature representation of the target entity;
[0009] S3. According to the first For the head entity, find all relationships connected to it and information about adjacent target entities to obtain the first... The relevant triple set of the layer;
[0010] S4. For the first Each specific triple in the relevant triple set of the layer captures entity features in the knowledge graph through a multi-head attention mechanism, generating message passing based on head entities and query relationships;
[0011] S5. Based on the message passing captured by the multi-head attention model, the message passing and aggregation of the target entity are realized, and finally the feature representation of the target entity is generated;
[0012] S6. Based on semantic relevance measurement, filter the neighbor relationships between nodes, select the top-k target nodes, and propagate to the next layer; jump to step S3;
[0013] S7. Passing through After the layer message is diffused, the feature representation of the final target entity is linearly mapped to obtain the inference result.
[0014] Furthermore, step S1 specifically includes:
[0015] S11. Read the entity set from the WN18RR knowledge graph dataset Relation set Read a set of triples from the WN18RR dataset. ,in ;in, This represents the positive samples in the dataset. Represents the head entity, Represents the tail entity. They all belong to entity sets r represents a de novo entity Pointing to tail entity The connection;
[0016] S12. Generate negative samples: Generate inverse triplets for each positive sample triplet. The expression for the inverse triplet is: ,in, This represents the total number of relationships in the knowledge graph. The total number of relationships was exceeded, which disrupted the original correct triples in order to enhance the model's discriminative power;
[0017] S13. Constructing a knowledge graph The expression is: ,in, Refers to a collection of entities. Refers to a set of relations. This refers to all positive and negative samples.
[0018] Furthermore, step S2 specifically includes:
[0019] S21. Set the number of propagation layers in the reasoning process as follows: Let the first Starting from the layer, =1, repeat steps S3 to S6 until... Finish;
[0020] S22. Based on the query information The inference target entity, where, This indicates a query for the head entity of the triple. This indicates the relation of the query triples, and initializes the head entity of the query triples with the head entity set of level 1. , represented as: .
[0021] Furthermore, step S3 specifically includes:
[0022] According to the The head entity of the layer, from the known knowledge graph Query the target entity and deduplicate the target entity to get the first one. The triplet information of the layer is expressed by the following formula:
[0023] ,
[0024] ,
[0025] in, Refers to from the 1st floor to The layer has already been selected as the head entity. From knowledge graph The target entity queried in the query; This indicates the number after deduplication. Layer triple information, Represents the known current Layer head entity, This represents the target entity after deduplication. This represents the relationship edge between the header entity and the target entity.
[0026] Furthermore, step S4 specifically includes:
[0027] S41. Represent the query relation characteristics as follows: The characteristic representation of the current layer triple relationship is as follows: , respectively with the current diffusion layer number The data is concatenated to obtain relevance information based on the number of diffusion layers, and then passed through a linear mapping layer to generate query Q and key K for multi-head attention; currently propagating to the [number]th [level]... Head entity of the layer Feature representation The value V in the multi-head attention is obtained after the linear mapping layer, and the formula is expressed as follows:
[0028] ,
[0029] ,
[0030] ,
[0031] in, These represent the feature representations of the query relation, the current layer triple relation, and the current layer head entity, respectively. They are generated by calling the embedding layer random encoding based on the index of the entity and relation, and are gradually corrected as the model learns. Information representing the number of diffusion layers, Let represent the transformation matrices that linearly map query Q, key K, and value V, respectively, and let n represent the number of long positions. These represent the offsets for the linear mapping of query Q, key K, and value V, respectively. This indicates that the vectors are concatenated along the second dimension.
[0032] S42. Attention Calculation: Calculate the attention weight matrix by considering the transpose of query Q and key K. The formula is expressed as follows:
[0033] ,
[0034] in, These represent the transpose of query key Q and key K, respectively; express Activation function; This indicates a regularization technique based on the dropout method; Indicates the dimension of key K;
[0035] S43. Using an attention weight matrix Weighted summation of the value V: summing the attention weights of all nodes i AND value vector Perform element-wise multiplication and summation to obtain the weighted vector of node j. Finally, the weighted vectors of the n nodes are concatenated to obtain the output of the multi-head attention mechanism. The formula is expressed as follows:
[0036] ,
[0037] ,
[0038] in, Indicates from The value in the i-th row and j-th column is extracted from the data. , represents the number of rows, Represents the column number, used for traversal. ;
[0039] S44. The output of the multi-head attention mechanism is processed by a linear mapping layer to obtain the initial message content. The formula is expressed as follows:
[0040]
[0041] in, Represents the transformation matrix of the first linear mapping; This represents the first trainable offset; This indicates the message content generated by the current triple;
[0042] S45. Combine the output of the multi-head attention mechanism with the attention weight matrix. Concatenation optimizes relevance in message passing. To ensure accuracy, the splicing result passes through a linear mapping layer to obtain the local message relevance of the current layer. The formula is expressed as follows:
[0043] ,
[0044] in, This indicates the weight matrix expansion operation; Represents the transformation matrix of the second linear mapping; This represents the trainable second offset; Representing local message relevance
[0045] S46. Design variables to store the correlation of the previous layer. Establish connections and further optimize message passing relevance based on historical relevance. The accuracy is determined by normalizing the relevance of the current message to a decimal, which is then processed through a linear mapping layer and an activation function to obtain the final relevance weight. The formula is expressed as follows:
[0046] ,
[0047] in, This indicates the local message relevance of the higher level. Indicates the message relevance of the current layer. Initialize as a vector of zeros; Represents the transformation matrix of the second linear mapping; This represents the trainable second offset; express Activation function; This indicates a normalization operation; The decimal value represents the final relevance weight;
[0048] S47. Final relevance weights Compared to the initial message content Element-wise multiplication yields the message passing based on the current triple. The formula is expressed as follows:
[0049]
[0050] in, This indicates an element-wise multiplication operation. This indicates message passing based on the current triple. .
[0051] Furthermore, step S5 specifically includes:
[0052] S51. Regarding the first Repeat step S4 for all triples in the layer to obtain message passes for all triples. Concatenate all message passes to obtain message passes for all target entities. The formula is expressed as: ,
[0053] Indicates the first Number of triples in the layer;
[0054] S52. Aggregate messages pointing to the same target entity, and obtain the feature representation of the target entity through a linear mapping. The formula is expressed as follows:
[0055] ,
[0056] in, For message aggregation operations, it means performing a summation operation on message passing to the same target entity; The transformation matrix represents the third linear mapping. This represents the trainable third offset; This represents the tanh activation function; The feature representation of the target entity.
[0057] Furthermore, step S6, the diffusion process based on semantic information, specifically includes:
[0058] Relevance information is captured through a linear mapping layer, and then passed through a... The activation function yields the relevance percentage for each target entity, expressed by the following formula:
[0059] ,
[0060] in, Represents a linear mapping layer. Indicates the current number The target entity set of the layer Based on the semantic relevance ratio, select the top-k target entities to retain; if The target entity to be selected, and the feature representation of the selected target entity. Pass the message to the next level and jump to step S2; otherwise, execute the final step S6.
[0061] Furthermore, step S7 specifically includes:
[0062] Will pass The feature representation of the target entity in the layer message diffusion process is obtained by linear mapping to obtain a score value. The target entity is predicted according to the score, and the target entity with the highest score is the inference result. The formula is as follows:
[0063] ,
[0064] in, Indicates the process Feature representation of the target entity in the layer message diffusion process; Represents the transformation matrix of the fourth linear mapping; This represents the trainable fourth offset; This indicates the score value.
[0065] The advantages of this invention are:
[0066] This invention combines a multi-head attention mechanism with a diffusion process to improve the accuracy and efficiency of knowledge graph reasoning in smart home scenarios. In the multi-head attention mechanism, information propagation is guided by query relationships, enabling dynamic adjustment of attention weights and accurate capture of multi-level relationships between devices. During the diffusion process, selecting the top-k target nodes for message propagation effectively optimizes the information transmission path and improves reasoning efficiency. Because entities in the knowledge graph all use a unified representation, the model framework has excellent generalization capabilities, adapting to the dynamic changes and data sparsity of smart home scenarios. This invention not only improves the accuracy of knowledge graph reasoning in smart homes but also provides new technical means and methods for smart home device management, user behavior analysis, and scene linkage. Attached Figure Description
[0067] The accompanying drawings are provided to further illustrate the invention and form part of the specification. They are used together with the embodiments of the invention to explain the invention and do not constitute a limitation thereof.
[0068] Figure 1 This is a flowchart of the steps of the method of the present invention. Detailed Implementation
[0069] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0070] Example 1
[0071] In this embodiment, as Figure 1 As shown, this invention provides an attention diffusion knowledge graph reasoning method for smart homes, the specific steps of which include:
[0072] S1. Extract entity, relation, and triple data from the publicly available WN18RR knowledge graph dataset.
[0073] Specifically, S11. Read the entity set from the WN18RR knowledge graph dataset. Relation set Read a set of triples from the WN18RR dataset. ,in ;in, This represents the positive samples in the dataset. Represents the head entity, Represents the tail entity. They all belong to entity sets r represents a de novo entity Pointing to tail entity The connection;
[0074] S12. Generate negative samples: Generate inverse triples for each positive triplet to expand the dataset. The expression for the inverse triplet is: ,in, This represents the total number of relationships in the knowledge graph. The total number of relationships was exceeded, which disrupted the original correct triples in order to enhance the model's discriminative power;
[0075] S13. Constructing a knowledge graph The expression is: ,in, Refers to a collection of entities. Refers to a set of relations. This refers to all positive and negative samples.
[0076] S2. Determine the number of propagation layers in the reasoning process. And initialize the head entity set; the subsequent reasoning process will be conducted here. In the layer, repeat steps S3 to S6 to gradually construct the feature representation of the target entity.
[0077] Specifically, S21. Set the number of propagation layers in the reasoning process as follows: Let the first Starting from the layer, =1, repeat steps S3 to S6 until... Finish;
[0078] S22. Based on the query information The inference target entity, where, This indicates a query for the head entity of the triple. This indicates the relation of the query triples, and initializes the head entity of the query triples with the head entity set of level 1. , represented as: .
[0079] S3. According to the first For the head entity, find all relationships connected to it and information about adjacent target entities to obtain the first... The set of relevant triples for each layer.
[0080] Specifically, according to the first The head entity of the layer, from the known knowledge graph Query the target entity and deduplicate the target entity to get the first one. The triplet information of the layer is expressed by the following formula:
[0081] ,
[0082] ,
[0083] in, Refers to from the 1st floor to The layer has already been selected as the head entity. From knowledge graph The target entity queried in the query; This indicates the number after deduplication. Layer triple information, Represents the known current Layer head entity, This represents the target entity after deduplication. This represents the relationship edge between the header entity and the target entity.
[0084] S4. For the first Each specific triple in the set of relevant triples in the layer captures entity features in the knowledge graph through a multi-head attention mechanism, generating message passing based on head entities and query relationships.
[0085] Specifically, S41. Represent the query relation characteristics as The characteristic representation of the current layer triple relationship is as follows: , respectively with the current diffusion layer number The data is concatenated to obtain relevance information based on the number of diffusion layers, and then passed through a linear mapping layer to generate query Q and key K for multi-head attention; currently propagating to the [number]th [level]... Head entity of the layer Feature representation The value V in the multi-head attention is obtained after the linear mapping layer, and the formula is expressed as follows:
[0086] ,
[0087] ,
[0088] ,
[0089] in, These represent the feature representations of the query relation, the current layer triple relation, and the current layer head entity, respectively. They are generated by calling the embedding layer random encoding based on the index of the entity and relation, and are gradually corrected as the model learns. The information representing the number of diffusion layers gradually decreases as the number of diffusion layers increases; Let represent the transformation matrices that linearly map query Q, key K, and value V, respectively, and let n represent the number of long positions. These represent the offsets for the linear mapping of query Q, key K, and value V, respectively. This indicates that the vectors are concatenated along the second dimension.
[0090] S42. Attention Calculation: Calculate the attention weight matrix by considering the transpose of query Q and key K. The formula is expressed as follows:
[0091] ,
[0092] in, These represent the transpose of query key Q and key K, respectively; express Activation function; This indicates a regularization technique based on the dropout method; It represents the dimension of the key K; it can avoid dependence on certain neurons, prevent overfitting, and improve generalization ability.
[0093] S43. Using an attention weight matrix Weighted summation of the value V: summing the attention weights of all nodes i AND value vector Perform element-wise multiplication and summation to obtain the weighted vector of node j. Finally, the weighted vectors of the n nodes are concatenated to obtain the output of the multi-head attention mechanism. The formula is expressed as follows:
[0094] ,
[0095] ,
[0096] in, Indicates from The value in the i-th row and j-th column is extracted from the data. , represents the number of rows, Represents the column number, used for traversal. ;
[0097] S44. The output of the multi-head attention mechanism is processed by a linear mapping layer to obtain the initial message content. The formula is expressed as follows:
[0098]
[0099] in, Represents the transformation matrix of the first linear mapping; This represents the first trainable offset; This indicates the message content generated by the current triple;
[0100] S45. Combine the output of the multi-head attention mechanism with the attention weight matrix. Concatenation optimizes relevance in message passing. To ensure accuracy, the splicing result passes through a linear mapping layer to obtain the local message relevance of the current layer. The formula is expressed as follows:
[0101] ,
[0102] in, This indicates the weight matrix expansion operation; Represents the transformation matrix of the second linear mapping; This represents the trainable second offset; Representing local message relevance
[0103] S46. Design variables to store the correlation of the previous layer. Establish connections and further optimize message passing relevance based on historical relevance. The accuracy is determined by normalizing the relevance of the current message to a decimal, which is then processed through a linear mapping layer and an activation function to obtain the final relevance weight. The formula is expressed as follows:
[0104] ,
[0105] in, This indicates the local message relevance of the higher level. Indicates the message relevance of the current layer. Initialize as a vector of zeros; Represents the transformation matrix of the second linear mapping; This represents the trainable second offset; express Activation function; This indicates a normalization operation; The decimal value represents the final relevance weight;
[0106] S47. Final relevance weights Compared to the initial message content Element-wise multiplication yields the message passing based on the current triple. The formula is expressed as follows:
[0107]
[0108] in, This indicates an element-wise multiplication operation. This indicates message passing based on the current triple. .
[0109] S5. Based on the message passing captured by the multi-head attention model, the message passing and aggregation of the target entity are realized, and finally the feature representation of the target entity is generated.
[0110] Specifically, S51. Regarding the first Repeat step S4 for all triples in the layer to obtain message passes for all triples. Concatenate all message passes to obtain message passes for all target entities. The formula is expressed as: ,
[0111] Indicates the first Number of triples in the layer;
[0112] S52. Aggregate messages pointing to the same target entity, and obtain the feature representation of the target entity through a linear mapping. The formula is expressed as follows:
[0113] ,
[0114] in, For message aggregation operations, it means performing a summation operation on message passing to the same target entity; The transformation matrix represents the third linear mapping. This represents the trainable third offset; This represents the tanh activation function; The feature representation of the target entity.
[0115] S6. Based on semantic relevance measurement, filter the neighbor relationships between nodes, select the top-k target nodes, and propagate to the next layer. Proceed to step S3.
[0116] The diffusion process based on semantic information specifically includes:
[0117] Relevance information is captured through a linear mapping layer, and then passed through a... The activation function yields the relevance percentage for each target entity, expressed by the following formula:
[0118] ,
[0119] in, Represents a linear mapping layer. Indicates the current number The target entity set of the layer Based on the semantic relevance ratio, select the top-k target entities to retain; if The target entity to be selected, and the feature representation of the selected target entity. Pass the message to the next level and jump to step S2; otherwise, execute the final step S6.
[0120] S7. Passing through After the layer message is diffused, the feature representation of the final target entity is linearly mapped to obtain the inference result.
[0121] Specifically, it will go through The feature representation of the target entity in the layer message diffusion process is obtained by linear mapping to obtain a score value. The target entity is predicted according to the score, and the target entity with the highest score is the inference result. The formula is as follows:
[0122] ,
[0123] in, Indicates the process Feature representation of the target entity in the layer message diffusion process; Represents the transformation matrix of the fourth linear mapping; This represents the trainable fourth offset; This indicates the score value.
[0124] Example 2
[0125] This embodiment presents a knowledge graph-based device management method for smart home scenarios. This method is applicable to typical home environments and covers a variety of smart devices, including but not limited to air purifiers, humidifiers, dehumidifiers, dust concentration sensors, and humidity sensors. The method aims to achieve intelligent linkage between environmental monitoring and home comfort services, dynamically adjusting device decisions through diffusion inference technology to improve the overall comfort of the living environment.
[0126] In step S1, a pre-built smart home knowledge graph is loaded. This graph is used to uniformly model various device entities, environmental state parameters, and behavioral actions in the home environment. Nodes in the graph include smart devices (such as humidifiers, window controls, air purifiers, etc.), environmental parameters (such as "outdoor rainfall" and "indoor humidity increase"), and device behaviors (such as "start" and "stop"). Edge relationships are used to describe the logical linkages between nodes, including various types such as "detection", "trigger", "accompanying", and "dependency".
[0127] Here are some examples of the original triples constructed: (Weather service interface, detection, outdoor rainfall), (Outdoor rainfall, trigger, window closed), (Window closed, accompanied by indoor temperature rise), (Indoor temperature rise, trigger, air conditioning cooling), (Outdoor rainfall, trigger, humidity exceeds threshold), (Humidity exceeds threshold, trigger, dehumidifier starts). These triples describe the fluctuations in the indoor environment caused by weather changes and trigger device behavior adjustments through graph linkage, thereby achieving intelligent response based on environmental perception. To support reverse path reasoning, corresponding reverse triples are further generated, such as: (Window closed, triggered, outdoor rainfall), (Humidifier closed, triggered, indoor humidity rises), (Dehumidifier starts, triggered, humidity exceeds threshold).
[0128] Following steps S2-S7 of the attention-diffusion knowledge graph reasoning method for smart homes, in this embodiment, for the query (weather service interface, detection, outdoor rainfall), the model performs multi-layer diffusion reasoning through the constructed knowledge graph. In the final reasoning results, "dehumidifier dehumidification" scores the highest, and "air conditioner cooling" ranks second, thus being selected as a possible response device. Through this method, the system can intelligently adjust the living environment based on the user's physiological state, achieving environmental linkage control services.
[0129] Example 3
[0130] The proposed solution was tested on the public datasets UMLS and WN18RR for inference prediction. The experimental results are shown in Table 1. The results in Table 1 demonstrate that the Multi-DiffE model of this invention has a significant advantage in inference capability compared to the current best knowledge graph inference models CompGCN, NBFNet, ConGLR, RED-GNN, and DiffusionE. Specifically, it achieves superior results in both inference scenarios under the specified metrics. These results illustrate the excellence and feasibility of the model proposed in this invention. In Table 1, MRR represents the average of the reciprocal rankings of correct predictions; a larger value indicates a higher ranking. Hit@k represents the proportion of correct predictions within the top-k range; a larger value is better.
[0131] Table 1 compares the proposed method on the UMLS and WN18RR datasets with a general knowledge graph reasoning model on reasoning tasks.
[0132]
[0133] Finally, it should be noted that the above descriptions are merely preferred embodiments of the present invention and are not intended to limit the present invention. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art can still modify the technical solutions described in the foregoing embodiments or make equivalent substitutions for some of the technical features. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A knowledge graph reasoning method for attention diffusion in smart homes, characterized in that, Includes the following steps: S1. Extract entity, relation, and triple data from the publicly available WN18RR knowledge graph dataset; the nodes in the knowledge graph include smart devices, environmental parameters, and device behaviors; the edges include detection, triggering, companion, and dependency. S2. Determine the number of propagation layers in the reasoning process. And initialize the head entity set; the subsequent reasoning process will be conducted here. In the layer, repeat steps S3 to S6 to gradually construct the feature representation of the target entity; S3. According to the first For the head entity, find all relationships connected to it and information about adjacent target entities to obtain the first... The relevant triple set of the layer; S4. For the first Each specific triple in the relevant triple set of the layer captures entity features in the knowledge graph through a multi-head attention mechanism, generating message passing based on head entities and query relationships; the specific steps include: S41. Represent the query relation characteristics as follows: The characteristic representation of the current layer triple relationship is as follows: , respectively with the current diffusion layer number The data is concatenated to obtain relevance information based on the number of diffusion layers, and then passed through a linear mapping layer to generate query Q and key K for multi-head attention; currently propagating to the [number]th [level]... Head entity of the layer Feature representation The value V in the multi-head attention is obtained after the linear mapping layer, and the formula is expressed as follows: , , , in, These represent the feature representations of the query relation, the current layer triple relation, and the current layer head entity, respectively. They are generated by calling the embedding layer random encoding based on the index of the entity and relation, and are gradually corrected as the model learns. Information representing the number of diffusion layers, Let represent the transformation matrices for linear mapping of query Q, key K, and value V, respectively, and let n represent the number of long positions. These represent the offsets for the linear mapping of query Q, key K, and value V, respectively. This indicates that the vectors are concatenated along the second dimension. S42. Attention Calculation: Calculate the attention weight matrix by considering the transpose of query Q and key K. The formula is expressed as follows: , in, These represent the transpose of query key Q and key K, respectively; express Activation function; This indicates a regularization technique based on the dropout method; Indicates the dimension of key K; S43. Using an attention weight matrix Weighted summation of the value V: summing the attention weights of all nodes i AND value vector Perform element-wise multiplication and summation to obtain the weighted vector of node j. Finally, the weighted vectors of the n nodes are concatenated to obtain the output of the multi-head attention mechanism. The formula is expressed as follows: , , in, Indicates from The value in the i-th row and j-th column is extracted from the data. , represents the number of rows, Represents the column number, used for traversal. ; S44. The output of the multi-head attention mechanism is processed by a linear mapping layer to obtain the initial message content. The formula is expressed as follows: , in, Represents the transformation matrix of the first linear mapping; This represents the first trainable offset; This indicates the message content generated by the current triple; S45. Combine the output of the multi-head attention mechanism with the attention weight matrix. Concatenation optimizes relevance in message passing. To ensure accuracy, the splicing result passes through a linear mapping layer to obtain the local message relevance of the current layer. The formula is expressed as follows: , in, This indicates the weight matrix expansion operation; Represents the transformation matrix of the second linear mapping; This represents the trainable second offset; Representing local message relevance S46. Design variables to store the correlation of the previous layer. Establish connections and further optimize message passing relevance based on historical relevance. The accuracy is determined by normalizing the relevance of the current message to a decimal, which is then processed through a linear mapping layer and an activation function to obtain the final relevance weight. The formula is expressed as follows: , in, This indicates the local message relevance of the higher layer. Indicates the message relevance of the current layer. Initialize as a vector of zeros; Represents the transformation matrix of the second linear mapping; This represents the trainable second offset; express Activation function; This indicates a normalization operation; The decimal value represents the final relevance weight; S47. Final relevance weights Compared to the initial message content Element-wise multiplication yields the message passing based on the current triple. The formula is expressed as follows: in, This indicates an element-wise multiplication operation. This indicates message passing based on the current triple. ; S5. Based on the message passing captured by the multi-head attention model, the message passing and aggregation of the target entity are realized, and finally the feature representation of the target entity is generated; S6. Based on semantic relevance measurement, filter the neighbor relationships between nodes, select the top-k target nodes, and propagate to the next layer; jump to step S3; S7. Passing through After the layer message is diffused, the feature representation of the final target entity is linearly mapped to obtain the inference result.
2. The attention diffusion knowledge graph reasoning method for smart homes according to claim 1, characterized in that, Step S1 specifically includes: S11. Read the entity set from the WN18RR knowledge graph dataset Relation set Read a set of triples from the WN18RR dataset. ,in ;in, This represents the positive samples in the dataset. Represents the head entity, Represents the tail entity. They all belong to entity sets r represents a de novo entity Pointing to tail entity The connection; S12. Generate negative samples: Generate inverse triplets for each positive sample triplet. The expression for the inverse triplet is: ,in, This represents the total number of relationships in the knowledge graph. The total number of relationships was exceeded, which disrupted the original correct triples in order to enhance the model's discriminative power; S13. Constructing a knowledge graph The expression is: ,in, Refers to a collection of entities. Refers to a set of relations. This refers to all positive and negative samples.
3. The attention diffusion knowledge graph reasoning method for smart homes according to claim 2, characterized in that, Step S2 specifically includes: S21. Set the number of propagation layers in the reasoning process as follows: Let the first Starting from the layer, =1, repeat steps S3 to S6 until... Finish; S22. Based on the query information The inference target entity, where, This indicates a query for the head entity of the triple. This indicates the relation of the query triples, and initializes the head entity of the query triples with the head entity set of level 1. , is represented as: .
4. The attention diffusion knowledge graph reasoning method for smart homes according to claim 3, characterized in that, Step S3 specifically includes: According to the The head entity of the layer, from the known knowledge graph Query the target entity and remove duplicates from the target entity to obtain the first... The triplet information of the layer is expressed by the following formula: , , in, Refers to from the 1st floor to The layer has already been selected as the head entity. From knowledge graph The target entity queried in the query; This indicates the number after deduplication. Layer triple information, Represents the known current Layer head entity, This represents the target entity after deduplication. This represents the relationship edge between the header entity and the target entity.
5. The attention diffusion knowledge graph reasoning method for smart homes according to claim 4, characterized in that, Step S5 specifically includes: S51. Regarding the first Repeat step S4 for all triples in the layer to obtain message passes for all triples. Concatenate all message passes to obtain message passes for all target entities. The formula is expressed as: , Indicates the first Number of triples in the layer; S52. Aggregate messages pointing to the same target entity, and obtain the feature representation of the target entity through a linear mapping. The formula is expressed as follows: , in, For message aggregation operations, it means performing a summation operation on message passing to the same target entity; The transformation matrix represents the third linear mapping. This represents the trainable third offset; This represents the tanh activation function; The feature representation of the target entity.
6. The attention diffusion knowledge graph reasoning method for smart homes according to claim 5, characterized in that, Step S6, the diffusion process based on semantic information, specifically includes: Relevance information is captured through a linear mapping layer, and then passed through a... The activation function yields the relevance percentage for each target entity, expressed by the following formula: , in, Represents a linear mapping layer. Indicates the current number The target entity set of the layer Based on the semantic relevance ratio, select the top-k target entities to retain; if The target entity to be selected, and the feature representation of the selected target entity. Pass the message to the next level and jump to step S2; otherwise, execute the final step S6.
7. The attention diffusion knowledge graph reasoning method for smart homes according to claim 6, characterized in that, Step S7 specifically includes: Will pass The feature representation of the target entity in the layer message diffusion process is obtained by linear mapping to obtain a score value. The target entity is predicted according to the score, and the target entity with the highest score is the inference result. The formula is as follows: , in, Indicates the process Feature representation of the target entity in the layer message diffusion process; Represents the transformation matrix of the fourth linear mapping; This represents the trainable fourth offset; This indicates the score value.
Citation Information
Patent Citations
Knowledge graph completion method based on topology perception hybrid convolutional network
CN120317346A
Knowledge graph construction and product recommendation method and system based on user data
CN120338924A