Knowledge graph relation reasoning method for food safety supervision field
By extracting information from multi-source heterogeneous data in the knowledge graph in the field of food safety supervision, and using convolution kernel and adaptive weighted fusion mechanism to fusion structure and semantic features, the problem that the knowledge graph relationship inference method in the existing technology has failed to effectively integrate multi-source data, achieving more accurate relationship inference and graph improvement.
Patent Information
- Application Number
- CN202411706124.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-26
- Publication Date
- 2025-03-11
AI Technical Summary
The existing knowledge graph relationship inference method in the field of food safety supervision failed to effectively integrate multi-source heterogeneous data, deeply extract structural features and semantic features, and achieve efficient fusion between different features, resulting in a large number of potential and critical link relationships missing in the map.
By obtaining food safety-related information from multi-source heterogeneous data, a food safety supervision knowledge graph is constructed, context semantic features are extracted using convolution kernels, and structural features are fused with semantic features through an adaptive weighted fusion mechanism to generate an optimized embedded representation, and finally, a relationship prediction scoring function is used to predict potential relationships.
It realizes more accurate and interpretable inference results of entities and relationships in the food safety supervision knowledge graph, enhances the comprehensiveness and effectiveness of the graph, and can effectively predict potential missing link relationships.
Smart Images

Figure CN119599132A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the fields of natural language processing and knowledge graphs, and in particular to a knowledge graph relationship reasoning method for the field of food safety supervision. Background Art
[0002] As food safety issues become increasingly complex, how to ensure food quality and consumer safety through efficient regulatory means has become a key challenge. As an effective tool that can connect various types of food safety-related information, knowledge graphs in the field of food safety supervision have been widely used in food traceability, risk assessment, regulatory decision-making and other fields. However, most of the knowledge graphs in the field of food safety supervision currently rely on traditional rules or artificial standards to build, and there are problems such as lagging knowledge updates and incomplete associations. These problems have resulted in the loss of a large number of potential and critical links in the graph, thus affecting its comprehensiveness and effectiveness.
[0003] Relational reasoning is an important graph improvement method used to infer and predict the implicit relationships between entities. However, existing knowledge graph relational reasoning is mostly simple inference based on statistical laws, which fails to fully consider the diversity and complexity of entities and relationships in the graph. Especially in the field of food safety supervision, the diversity and complexity of data require relational reasoning to be able to process structural information and deep semantic knowledge at the same time, and provide more accurate and explainable reasoning results.
[0004] Therefore, for knowledge graph relational reasoning in the field of food safety supervision, how to effectively integrate multi-source heterogeneous data, deeply extract structural features and semantic features, and achieve efficient fusion between different features is a major challenge facing current technology. Summary of the invention
[0005] In order to solve the above technical problems, the present invention provides a knowledge graph relationship reasoning method for the field of food safety supervision, and its solution includes:
[0006] Step S1: Obtain food safety related information from multi-source heterogeneous data, including food safety standard documents, food product sampling information, etc., and construct a food safety supervision knowledge graph through data cleaning, entity recognition and relationship extraction;
[0007] Step S2: Randomly initialize the representation vectors of entities and relations in the triples, extract contextual semantic features using different convolution kernel sizes, and generate triple feature representations containing context-aware information through weighted fusion;
[0008] Step S3: Iteratively update the structural features of entities and relationships by measuring the relevance of neighboring nodes, and use a new adaptive weighted fusion mechanism to generate a fused embedding representation through the structural features of entity relationships and context-aware information;
[0009] Step S4: Use the optimized embedding vector generated in step S3 to perform convolution and normalization operations to unify the feature scale and retain key relationship information. Then input the features into the relationship prediction scoring function for scoring and sorting, predict potential missing link relationships, and realize relational reasoning of the food safety supervision knowledge graph.
[0010] Compared with the prior art, the present invention has the following advantages:
[0011] 1. The present invention discloses a knowledge graph relationship reasoning method for the field of food safety supervision. It integrates the structural features of entity relationships with contextual semantic feature information, and uses a prediction scoring function for relationships to score and rank candidate triples to predict potential relationships.
[0012] 2. The present invention designs a new adaptive weighted fusion mechanism, which inputs the features fused by the gated units into the variational autoencoder, and optimizes the feature distribution of entity and relationship nodes by learning the distribution of the feature latent space. BRIEF DESCRIPTION OF THE DRAWINGS
[0013] Figure 1 This is a flow chart of a knowledge graph relationship reasoning method for the field of food safety supervision in an embodiment of the present invention;
[0014] Figure 2 A technical framework diagram of a knowledge graph relationship reasoning method for the field of food safety supervision in an embodiment of the present invention;
[0015] Figure 3 This is a flowchart of step S1 in a knowledge graph relational reasoning method for food safety supervision in an example of the present invention: obtaining food safety related information from multi-source heterogeneous data, including food safety standard documents, food product sampling information, etc., and constructing a food safety supervision knowledge graph through data cleaning, entity recognition and relationship extraction;
[0016] Figure 4 A flowchart of step S2 in a knowledge graph relational reasoning method for food safety supervision in an example of the present invention: randomly initializing the representation vectors of entities and relations in triples, extracting contextual semantic features using different convolution kernel sizes, and generating triple feature representations containing context-aware information through weighted fusion;
[0017] Figure 5This is a technical framework diagram of step S2 in a knowledge graph relational reasoning method for food safety supervision in an example of the present invention: randomly initializing the representation vectors of entities and relations in triples, extracting contextual semantic features using different convolution kernel sizes, and generating triple feature representations containing context-aware information through weighted fusion;
[0018] Figure 6 A flowchart of step S3 in a knowledge graph relational reasoning method for food safety supervision in an example of the present invention: iteratively updating the structural features of entities and relationships by measuring the relevance of neighboring nodes, and using a new adaptive weighted fusion mechanism to generate a fused embedded representation through the structural features of entity relationships and context-aware information;
[0019] Figure 7 This is a flowchart of step S4 in a knowledge graph relational reasoning method for the field of food safety supervision in an example of the present invention: using the optimized embedding vector generated by step S3, performing convolution and normalization operations, unifying feature scales and retaining key relationship information, and then inputting features into a relationship prediction scoring function for scoring and sorting, predicting potential missing link relationships, and realizing relational reasoning of a food safety supervision knowledge graph. DETAILED DESCRIPTION
[0020] The present invention provides a knowledge graph relational reasoning method for the field of food safety supervision. Firstly, food safety standard documents, food product sampling information, etc. are obtained from public data on the Internet, and data cleaning, entity recognition and relationship extraction are performed to convert unstructured data into structured data in the form of triples; secondly, the text form triples are encoded using a dynamic convolution kernel and converted into an embedded vector representation containing context information; then, the neighbor node correlation of the entity is measured by a Sigmoid function, the node aggregation structural features with higher correlation are selected, and the entity and relationship context embedding vector features and structural information features are fused using a gating unit; finally, the embedding vectors of the entity pairs and candidate relationships are input into a relationship prediction scoring function for scoring and sorting, and the relationship with the highest score is output as the prediction result.
[0021] In order to make the purpose, technical solutions and advantages of the present invention more clear, the present invention is further described in detail below through specific implementations and in conjunction with the accompanying drawings.
[0022] Embodiment 1
[0023] like Figure 1 , Figure 2 As shown, in this embodiment, the present invention provides a knowledge graph relationship reasoning method for the field of food safety supervision, including the following steps:
[0024] Step S1: Obtain food safety related information from multi-source heterogeneous data, including food safety standard documents, food product sampling information, etc., and construct a food safety supervision knowledge graph through data cleaning, entity recognition and relationship extraction;
[0025] Step S2: Randomly initialize the representation vectors of entities and relations in the triples, extract contextual semantic features using different convolution kernel sizes, and generate triple feature representations containing context-aware information through weighted fusion;
[0026] Step S3: Iteratively update the structural features of entities and relationships by measuring the relevance of neighboring nodes, and use a new adaptive weighted fusion mechanism to generate a fused embedding representation through the structural features of entity relationships and context-aware information;
[0027] Step S4: Use the optimized embedding vector generated in step S3 to perform convolution and normalization operations to unify the feature scale and retain key relationship information. Then input the features into the relationship prediction scoring function for scoring and sorting, predict potential missing link relationships, and realize relational reasoning of the food safety supervision knowledge graph.
[0028] like Figure 3 As shown, in this embodiment, the above step S1: obtains food safety related information from multi-source heterogeneous data, including food safety standard documents, food product sampling information, etc., and constructs a food safety supervision knowledge graph through data cleaning, entity recognition and relationship extraction, which specifically includes:
[0029] Step S11: using the web crawler tool Scrapy to automatically crawl relevant information from multi-source heterogeneous data such as food safety standard documents and food product sampling information to form an initial data set;
[0030] Step S12: Use the Pandas library to clean the initial data set, including processing missing values, removing noise data, and unifying the data format to ensure the standardization and consistency of the data;
[0031] Step S13: Use the SpaCy model to perform entity recognition and relationship extraction on the cleaned data, generate triples, and store the constructed food safety supervision knowledge graph in the Neo4j graph database.
[0032] like Figure 4 , 5 As shown, in this embodiment, the above step S2: randomly initializes the representation vectors of entities and relations in the triples, extracts contextual semantic features using different convolution kernel sizes, and generates triple feature representations containing context-aware information through weighted fusion, specifically including:
[0033] Step S21: Input M triples (hi , r i , t i ) and generate vectors using the Xavier initialization method and They correspond to the head entity, tail entity and relationship in the triple respectively;
[0034] Step S22: Dynamically generate the head entity position code p through the interaction between entities and relationships h and tail entity position encoding p t :
[0035] p i =ReLU(W pos [x i ;x r ]+b pos )
[0036] Among them, i represents an entity or relationship, x r is the relation embedding, W pos and b pos is a trainable parameter; the dynamic positional encoding of the relationship takes its embedding representation:
[0037] p r =x r
[0038] Combine dynamic position encoding to generate context-aware vectors u of head entity, tail entity and relation h 、u t 、u r :
[0039] u i =ReLU(W context [x i ;p i ]+b context )
[0040] Among them, i represents the head entity, tail entity or relationship, x i is the embedding representation, p i is the dynamic position encoding, W context and b cotext are model parameters;
[0041] Step S23: embedding context awareness into u h 、u t 、u r Splicing to generate candidate probability distribution p of convolution kernel size k :
[0042] p k =softmax(MLP(u h ;u r ;ut ))
[0043] Among them, MLP is a multi-layer perceptron, which is used to learn the probability distribution of different convolution kernel sizes. The GumbelSoftmax method is used to learn the probability distribution p from the probability distribution p. k The convolution kernel size k is sampled i :
[0044]
[0045] Among them, g i ~Gumbel(0,1) is the noise term sampled from the Gumbel distribution, the temperature parameter τ is used to control the smoothness of the sampling, and p is the candidate probability of different convolution kernel sizes;
[0046] Step S24: convolution kernel size k obtained according to sampling i , perform a one-dimensional convolution operation on the context-aware vector to extract triple features:
[0047]
[0048] The features extracted by each convolution kernel size are fused by weighted summation to capture multi-level context information and generate a triple feature representation containing context-aware information. context :
[0049]
[0050] Among them, w is a trainable parameter.
[0051] like Figure 6 As shown, in this embodiment, the above step S3: iteratively updating the structural features of entities and relationships by measuring the relevance of neighboring nodes, and using a new adaptive weighted fusion mechanism to generate a fused embedding representation through the structural features of entity relationships and context-aware information, specifically includes:
[0052] Step S31: Assume that the input graph is G = {V, E}, where V e is the entity node set, V r is the set of relationship nodes, E is the set of edges, and the feature vector of each node obtained in step S22 is expressed as and Based on each pair of entity nodes v i and its neighbor node v j Different convolution kernels K are used for different types of relationships between ij Modeling the relationship, N(h i ) represents node h i The neighbor node set of , then the node update process is:
[0053]
[0054] in It is a metric function that calculates the similarity of neighbor nodes through Sigmoid. ij are different convolution kernels; the structural features of entities and relationships are extracted from the knowledge graph through iterative updates;
[0055] Step S32: In order to fuse the feature vector representation containing contextual awareness information obtained in step S22 and the feature vector representation containing structural information obtained in step 31, an adaptive weighted fusion mechanism is designed; for entity node v i , and its embedding feature is expressed as Relation Embedding Features Structural information features Generate gating information for each feature through the gating unit:
[0056]
[0057] in, is the gating information of each feature, W e and W s is the weight matrix used to project the feature representation into the corresponding space, b e , b r , b s is the bias vector; and the features are fused using the addition weighting strategy, and the fused node feature vector is obtained by performing element-wise multiplication:
[0058]
[0059] Step S33: The features after the gated unit fusion Input into the variational autoencoder, by mapping the node feature representation to the latent space, learning the potential distribution of the data, thereby optimizing the feature expression and enhancing its representation ability; the encoder obtains the mean difference μ of the latent variable through the feedforward neural network output i and label difference δ i , by reparameterization technique, latent variables z are sampled from the latent distribution i :
[0060] z i =μ i +δ i ·ε,ε~N(0,I)
[0061] Where ε is the noise term sampled from the standard normal distribution N(0,I);
[0062] Use a fully connected neural network as a decoder to transform the latent variable zi Map back to the high-dimensional feature space to obtain the optimized feature representation Calculating the latent distribution and the standard normal distribution p(z i ), regularizing the distribution in the latent space:
[0063]
[0064] By minimizing the loss L VAE , the variational autoencoder optimizes the latent variable distribution and generates more expressive node features
[0065] like Figure 7 As shown, in this embodiment, the above step S4: using the optimized embedding vector generated in step S3, performing convolution and normalization operations, unifying the feature scale and retaining the key relationship information, and then inputting the features into the relationship prediction scoring function for scoring and sorting, predicting the potential missing link relationship, and realizing the relationship reasoning of the food safety supervision knowledge graph, specifically includes:
[0066] Step S41: Use convolution operation to capture the local feature relationship between embedded vectors, and use 1D convolutional neural network to optimize the embedding vector matrix H∈R n×d Perform a convolution operation, slide the convolution kernel K′ and apply it to the embedding vector:
[0067] H`=Conv1D(H i , K`)
[0068] Step S42: Finally, the Hadamard product is applied to calculate each pair of entities e i and e i and the relationship between them k Matching score:
[0069]
[0070] Among them, σ represents the Sigmoid function, H` i and H` j are the feature vectors of entities i and j respectively, R k and The relationship r k The embedding vector and weight matrix of b k is a trainable parameter.
Claims
1. A knowledge graph relational reasoning method for food safety supervision, which has the following features: Step S1: Obtain food safety related information from multi-source heterogeneous data, including food safety standard documents, food product sampling information, etc., and construct a food safety supervision knowledge graph through data cleaning, entity recognition and relationship extraction; Step S2: Randomly initialize the representation vectors of entities and relations in the triples, extract contextual semantic features using different convolution kernel sizes, and generate triple feature representations containing context-aware information through weighted fusion; Step S3: Iteratively update the structural features of entities and relationships by measuring the relevance of neighboring nodes, and use a new adaptive weighted fusion mechanism to generate a fused embedding representation through the structural features of entity relationships and context-aware information; Step S4: Use the optimized embedding vector generated in step S3 to perform convolution and normalization operations to unify the feature scale and retain key relationship information. Then input the features into the relationship prediction scoring function for scoring and sorting, predict potential missing link relationships, and realize relational reasoning of the food safety supervision knowledge graph.
2. According to claim 1, a knowledge graph relationship reasoning method for food safety supervision is characterized in that: The step S1: obtaining food safety related information from multi-source heterogeneous data, including food safety standard documents, food product sampling information, etc., and constructing a food safety supervision knowledge graph through data cleaning, entity recognition and relationship extraction, including: Step S11: using the web crawler tool Scrapy to automatically crawl relevant information from multi-source heterogeneous data such as food safety standard documents and food product sampling information to form an initial data set; Step S12: Use the Pandas library to clean the initial data set, including processing missing values, removing noise data, and unifying the data format to ensure the standardization and consistency of the data; Step S13: Use the SpaCy model to perform entity recognition and relationship extraction on the cleaned data, generate triples, and store the constructed food safety supervision knowledge graph in the Neo4j graph database.
3. According to claim 1, a knowledge graph relationship reasoning method for food safety supervision is characterized in that: The step S2: randomly initializing the representation vectors of entities and relations in the triples, extracting contextual semantic features using different convolution kernel sizes, and generating triple feature representations containing contextual perception information by weighted fusion, including: Step S21: Input M triples (h i , r i , t i ) and generate vectors using the Xavier initialization method and They correspond to the head entity, tail entity and relationship in the triple respectively; Step S22: Dynamically generate the head entity position code p through the interaction between entities and relationships h and tail entity position encoding p t : p i =ReLU(W pos [x i ;x r ]+b pos ) Among them, i represents an entity or relationship, x r is the relation embedding, W pos and b pos is a trainable parameter; the dynamic positional encoding of the relationship takes its embedding representation: p r =x r Combine dynamic position encoding to generate context-aware vectors u of head entity, tail entity and relation h 、u t 、u r : her i =ReLU(W context [x i pp i ]+b context ) Among them, i represents the head entity, tail entity or relationship, x i is the embedding representation, p i is the dynamic position encoding, W cotext and b context are model parameters; Step S23: embedding context awareness into u h 、u t 、u r Splicing to generate candidate probability distribution p of convolution kernel size k : p k =softmax(MLP(u h ;u r ;u t )) Among them, MLP is a multi-layer perceptron, which is used to learn the probability distribution of different convolution kernel sizes; the Gumbel Softmax method is used to learn the probability distribution p from the probability distribution p. k The convolution kernel size k is sampled i : Among them, gi~Gumbel(0,1) is the noise term sampled from the Gumbel distribution, the temperature parameter τ is used to control the smoothness of the sampling, and p is the candidate probability of different convolution kernel sizes; Step S24: convolution kernel size k obtained according to sampling i , perform a one-dimensional convolution operation on the context-aware vector to extract triple features: The features extracted by each convolution kernel size are fused by weighted summation to capture multi-level context information and generate a triple feature representation containing context-aware information. context : Among them, w is a trainable parameter.
4. The knowledge graph relationship reasoning method for food safety supervision according to claim 1 is characterized in that: The step S3: iteratively updating the structural features of entities and relationships by measuring the relevance of neighboring nodes, and using a new adaptive weighted fusion mechanism to generate a fused embedding representation through the structural features of entity relationships and context-aware information, including: Step S31: Assume that the input graph is G = {V, E}, where V e is the entity node set, V r is the set of relationship nodes, E is the set of edges, and the feature vector of each node obtained in step S22 is expressed as and Based on each pair of entity nodes v i and its neighbor node v j Different convolution kernels K are used for different types of relationships between ij Modeling the relationship, N(h i ) represents node h i The neighbor node set of , then the node update process is: in It is a metric function that calculates the similarity of neighbor nodes through Sigmoid. ij are different convolution kernels; the structural features of entities and relationships are extracted from the knowledge graph through iterative updates; Step S32: In order to fuse the feature vector representation containing contextual awareness information obtained in step S22 and the feature vector representation containing structural information obtained in step 31, an adaptive weighted fusion mechanism is designed; for entity node v i , and its embedding feature is expressed as Relation Embedding Features Structural information features Generate gating information for each feature through the gating unit: in, is the gating information of each feature, W e and W s is the weight matrix used to project the feature representation into the corresponding space, b e 、b r 、b s is the bias vector; and the features are fused using the addition weighting strategy, and the fused node feature vector is obtained by performing element-wise multiplication: Step S33: The features after the gated unit fusion Input into the variational autoencoder, by mapping the node feature representation to the latent space, learning the potential distribution of the data, thereby optimizing the feature expression and enhancing its representation ability; the encoder obtains the mean difference μ of the latent variable through the feedforward neural network output i and label difference δ i , by reparameterization technique, latent variables z are sampled from the latent distribution i : z i =μ i +d i ·ε,ε~N(0,I) Where ε is the noise term sampled from the standard normal distribution N(0, I); Use a fully connected neural network as a decoder to transform the latent variable z i Map back to the high-dimensional feature space to obtain the optimized feature representation Calculating the latent distribution The difference between the standard normal distribution p(zi) and the regularized distribution in the latent space: By minimizing the loss L VAE , the variational autoencoder optimizes the latent variable distribution and generates more expressive node features 5. The knowledge graph relationship reasoning method for food safety supervision according to claim 1 is characterized in that: The step S4: using the optimized embedding vector generated in step S3, performing convolution and normalization operations, unifying feature scales and retaining key relationship information, and then inputting the features into the relationship prediction scoring function for scoring and sorting, predicting potential missing link relationships, and realizing relationship reasoning of the food safety supervision knowledge graph, including: Step S41: Use convolution operation to capture the local feature relationship between embedded vectors, and use 1D convolutional neural network to optimize the embedding vector matrix H∈R n×d Perform a convolution operation, slide the convolution kernel K′ and apply it to the embedding vector: H`=Conv1D(H i ,K`) Step S42: Finally, the Hadamard product is applied to calculate each pair of entities e i and e i and the relationship between them k Matching score: Among them, σ represents the Sigmoid function, H` i and H` j are the feature vectors of entities i and j respectively, R k and The relationship r k The embedding vector and weight matrix of b k is a trainable parameter.