Food safety risk prediction method and device based on heterogeneous graph neural network
By constructing a heterogeneous graph neural network, shaping the doping weights using SHAP values and combining with the self-attention mechanism, the problems of data heterogeneity and complex correlation in food safety risk prediction are solved, and high-precision risk assessment and early warning are achieved.
Patent Information
- Application Number
- CN202510430481.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-08
- Publication Date
- 2025-08-05
AI Technical Summary
The prior art is difficult to effectively integrate heterogeneous data of multiple types of entities in food safety risk prediction, and traditional methods are difficult to dynamically capture multi-hop heterogeneous relationships and semantic interactions, resulting in low prediction accuracy and efficiency.
A heterogeneous graph neural network is constructed, dopant weight is calculated through SHAP values, combined with heterogeneous graph representation learning and self-attention mechanisms, and dynamically quantify food safety risks.
It realizes high-precision prediction of food safety risks, accurately identify complex relationships, and supports accurate risk warning and management decision-making.
Smart Images

Figure CN120430800A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of food safety risk prediction, and in particular to a food safety risk prediction method and device based on a heterogeneous graph neural network. Background Art
[0002] In recent years, with the advancement of society and the improvement of living standards, food safety has become a core issue of global concern, directly related to personal health and profoundly affecting quality of life. To address the increasingly severe food safety risks, it is urgent to establish more efficient regulatory mechanisms, including continuous monitoring of potential hazards, risk prediction, and early warning systems. Although big data technology provides a data foundation for food safety risk analysis, the complexity of food sampling data (such as high dimensionality, diversity, and nonlinearity) still poses a serious challenge to risk prediction methods. Traditional machine learning methods (such as random forests and gradient boosting decision trees) can improve prediction accuracy but are susceptible to data noise and overfitting. Neural networks (such as radial basis function networks and backpropagation networks) have shown certain advantages in food risk assessment, but they rely on manual feature engineering and have difficulty capturing multidimensional correlations. Although deep learning can automatically extract multidimensional features through a layered architecture (such as deep radial basis function networks and long short-term memory networks have achieved certain results in food risk prediction), existing technologies still have shortcomings in automated feature processing and heterogeneous data fusion.
[0003] Graph neural networks (GNNs) have shown unique advantages in processing graph-structured food relationships, but existing methods still face three key issues: First, some technologies rely on experts to manually assign weights or define risk values (such as the analytic hierarchy process (AHP)), which leads to subjective bias and high labor costs; Second, food data involves multiple types of entities (such as products, testing indicators, manufacturers) and complex multi-relationship networks, but existing methods mostly adopt homogenization processing, ignoring the semantic associations of heterogeneous information, resulting in the loss of key information; Finally, traditional HGNNs are limited by manually predefined fixed meta-paths, making it difficult to dynamically capture multi-hop heterogeneous relationships and semantic interactions, resulting in inefficient feature extraction, which further affects prediction accuracy and computational efficiency.
[0004] Therefore, it is of great practical significance to develop a new method that can integrate multi-type entities, automatically mine complex multi-relationships and improve the accuracy of food risk prediction. Summary of the Invention
[0005] In order to overcome the above-mentioned deficiencies in the prior art, the present invention proposes a food safety risk prediction method and device based on a heterogeneous graph neural network to meet the challenges of food safety risk prediction.
[0006] This method uses raw food sample data as input to train a predictive model for food safety risk assessment. The entire process is divided into three main stages: food safety risk assessment, food safety graph representation learning, and risk prediction. The specific steps are as follows:
[0007] Step 1: Assess food safety risk. First, a classification model is trained to distinguish between acceptable and unacceptable food samples. The model is then interpreted using SHAP values to calculate the weights of each adulterant's impact on food compliance. Finally, by integrating these weights, an overall risk value is calculated for each sample and used as the predicted label.
[0008] 1.1 Screening and cleaning data: This invention aims at food risk prediction and studies the potential risk factors in unqualified products. First, all food samples with unqualified test results are screened out from the data set, and the following screening conditions are set: (1) Each food category must contain no less than 200 samples; (2) The number of samples with the same adulterant in the same food category must be more than 1. Subsequently, field association processing is performed on the screened samples: all adulterant names are extracted from the "adulterant" field, and matched one by one with the corresponding adulterant addition amount in the "test result" field, to construct a data set D with the sample-adulterant relationship as the core.
[0009] 1.2 Calculation of adulterant weights: Based on the constructed data set, the present invention uses XGBoost to train a classification model, using the qualified or unqualified food samples as classification labels to learn the key features that affect food safety. During the training process, the data set is divided into a training set and a test set in a ratio of 8:2 to ensure the generalization ability of the model. After the classification model training is completed, the present invention uses the SHAP value calculation method to perform feature importance analysis on each sample and calculate the impact of different adulterants on the qualified or unqualified food samples. Specifically, let the model obtained by XGBoost training be f(x). For a sample x, the calculation formula of the SHAP value is as follows:
[0010]
[0011] Among them, φ i represents the SHAP contribution value of feature i, S is a subset of the feature set, F is the set of all features, and F(S) represents the model output when predicting using only the feature set S. By calculating the SHAP values of all adulterants for each sample and averaging them over all samples in the dataset, we can obtain the average impact of each adulterant on food conformity, which is used as the final weight of each adulterant, namely:
[0012]
[0013] where wk is the final weight of adulterant i, N is the total number of samples, φ i,j is the SHAP contribution of adulterant i in sample j.
[0014] 1.3 Calculation of food sample risk value: This paper designs a new standardization method for food safety data sets - legality standardization - to calculate the risk value of adulterants. This method takes the legal threshold of each adulterant into consideration, making the distribution of detection values more uniform. The result calculated using this method will be called the risk score of each adulterant. The specific calculation process is as follows: First, determine the detection values of all adulterants in each food sample and their corresponding legal thresholds. Suppose the i-th food sample contains n adulterants, where the detection value of the k-th adulterant is represented by sample ik , the corresponding legal threshold is expressed as threshold k Next, the risk score for each adulterant in sample i is calculated:
[0015] risk_score ik =sample ik / threshold k (3)
[0016] Among them, risk_score refers to the relative risk assessment of adulterant k. Specifically, risk_score ik It represents the ratio of the detection value of the kth adulterant in sample i to its legality threshold. The larger this value is, the higher the content of the adulterant is, the more illegal it is, and the greater the risk. In order to comprehensively assess the risk level of the entire sample, the relative risk score of each adulterant is further weighted and summed. According to the adulterant feature weight w extracted in step 1.2 k , the total risk value of the i-th sample total_risk i The calculation is as follows:
[0017]
[0018] By adopting this approach, not only the specific detection value and legal threshold of each adulterant are taken into account, but their respective weightings are also combined to produce a comprehensive risk assessment.
[0019] Step 2: Food Safety Graph Representation Learning Module. This module is used to capture complex relationships within food samples to identify potential risk patterns. First, a heterogeneous food safety graph is constructed to represent various entities and their relationships. Second, a heterogeneous graph neural network (HGNN) incorporating meta-path context is used to process the graph data, generating embedded representations of food sample nodes, which are then passed to the third stage.
[0020] 2.1 Constructing a Food Safety Graph: This paper constructs a heterogeneous graph containing four key node types: food samples, food production cities, food testing cities, and detected food adulterants. Formally, the heterogeneous graph can be represented as G = (V, E, T V ,T E ), where V is the node set, E is the edge set, and T V is a set of node types, and T E is an edge type set. In the food heterogeneous graph of the present invention, the node type set T V Including food samples, food production cities, food testing cities and detected food adulterants, and the edge type set T E It contains three different types of associations, connecting different entities: production relationship, which connects the food production city with the food sample, indicating the origin of the sample; supervision relationship, which connects the food testing city with the food sample, indicating the city responsible for quality control and safety assessment; detection relationship, which connects the food sample with the directly detected food adulterants, indicating the presence of contaminants in the sample.
[0021] 2.2 Constructing Meta-Path Context: In the heterogeneous graph G = (V, E) used for food detection, different types of entities may have different feature dimensions. To solve this problem, a linear transformation strategy is used to map the features of different types of nodes into a common vector space, thereby ensuring that all nodes have consistent feature representations. For nodes without initial features, a unique hot encoding can be assigned to them as the initial features. i The embedding representation X' of the node can be obtained by the following formula:
[0022]
[0023] in, is the original feature, and are learnable weights and biases.
[0024] After feature preprocessing, for each meta-path For node i in the metapath, MECCH constructs a metapath context, which is represented as a neighborhood subgraph around the node, including all nodes and their adjacent nodes that satisfy the metapath P. Specifically, assume that the node type and edge type sequence of the metapath P is Given a central node v of type A i The meta path context covers the path starting with v i The neighborhood subgraph centered on v i and its adjacent node v j and v k, and the connecting edges e1 and e2. This forms a local subgraph centered at node i The complete structural relationship between the target node and the adjacent nodes defined by the meta-path is clarified.
[0025] 2.3 Constructing Meta-path Context Encoder; In order to distinguish the influence of different meta-path contexts, MECCH uses a meta-path context encoder to learn the structure and semantic information embedded in it after constructing the context. The specific implementation of the encoder is as follows: Figure 3 As shown in Figure 2. To achieve this, the encoder utilizes a self-attention mechanism, which allows the model to consider information from the entire sequence when processing each element of the sequence. In the self-attention mechanism, the correlation between the target node and its first-order neighbors is first calculated. Next, the first-order neighbors further aggregate information through their connected second-order neighbors. The query, key, and value vectors are generated through a linear transformation:
[0026]
[0027] in, is the first-order neighbor of the target node, and and is a learnable parameter matrix. Next, we use scaled dot product attention to calculate the attention score between the query and all keys:
[0028]
[0029] Among them, d k is the dimension of the key vector, which is used to scale the dot product to prevent the gradient explosion problem. The scaled attention scores are then normalized by the softmax function to obtain the attention weights:
[0030]
[0031] Finally, the values are weighted summed according to the attention weights to obtain the context vector:
[0032]
[0033] Since we ultimately want to obtain the vector representation of the target node, we update the representation of the target node by adding the original vector of the target node to the vector representation of its aggregated second-order neighbors:
[0034]
[0035] vector It captures the structural and semantic information within the meta-path context centered on node i. In the model, multiple such self-attention encoders can be stacked to capture structural and semantic information at different levels. The output of each encoder serves as the input of the next encoder, enabling the model to learn more complex patterns.
[0036] 2.4 Fusion of Attention Paths: After completing the meta-path context encoding, the model uses a fusion layer to integrate the encoded information from different meta-paths to form a unified node representation. This paper adopts an adaptive method to evaluate and merge this information. By introducing learnable weights instead of static averaging, the contribution of each meta-path is adjusted. Assume that the target node i has n different meta-paths, and each meta-path p corresponds to an encoded representation We learn a weight vector To perform a weighted summation of these representations, we can obtain the global representation of the node. This can be expressed mathematically as:
[0037]
[0038] Among them, w p is the learnable weight of the meta-path p, reflecting the relative importance of this meta-path in the fusion process, and the weight is generated using the softmax function:
[0039]
[0040] Among them, θ p is a learnable parameter corresponding to the meta-path p. Through this adaptive fusion strategy, MECCH can effectively integrate information from different meta-paths, thereby achieving better performance in graph data analysis tasks.
[0041] Step 3: Use risk level labels and node embedding vectors to classify samples and dynamically assess food safety risks.
[0042] After completing the effective integration of meta-path context encoding and fusion layer, the node representation in the food safety graph is is endowed with the ability to perform food safety prediction. First, a fully connected layer is defined, and the node representation is transformed into Mapped to the original score I:
[0043]
[0044] in, is the weight matrix, d is the node representation The dimension of , C represents the number of risk levels. Next, in order to convert the output raw score I into a probability distribution, we apply the softmax function for normalization:
[0045]
[0046] in, Is the normalized probability distribution after the softmax function, indicating the probability of the node belonging to each risk level. In order to train the model and optimize its parameters, the cross entropy loss function is used to quantify the difference between the predicted probability distribution and the true label:
[0047]
[0048] Among them, N is the number of samples, C is the number of categories, δ ic is an indicator variable that is 1 if node i belongs to category c and 0 otherwise. ic is the probability predicted by the model that node i belongs to category c.
[0049] The second aspect of the present invention relates to a food safety risk prediction device based on a heterogeneous graph neural network, comprising a memory and one or more processors, wherein the memory stores executable code, and when the one or more processors execute the executable code, they are used to implement a food safety risk prediction method based on a heterogeneous graph neural network of the present invention.
[0050] The third aspect of the present invention relates to a computer-readable storage medium having a program stored thereon, which, when executed by a processor, implements a food safety risk prediction method based on a heterogeneous graph neural network of the present invention.
[0051] The working principle of the present invention is: the core working principle of the present invention is to construct a graph structure that can capture complex risk associations by fusing multi-source heterogeneous data and feature weight analysis, and use meta-path and self-attention mechanism to learn node embedding, combined with risk label training prediction model, to achieve high-precision food safety risk assessment, and effectively solve the problems of data heterogeneity and complex risk factors in traditional methods.
[0052] The innovations of the present invention are: (1) The present invention constructs a heterogeneous graph of food samples, production / testing cities and adulterants, dynamically quantifies risk weights, and breaks through the limitations of traditional static weights and insufficient data correlation. (2) A "legality standardization" method is proposed to combine the detection value of adulterants with their legal thresholds to calculate a standardized risk score. Not only is the absolute content of adulterants considered, but the regulatory compliance dimension is also introduced to make risk assessment closer to actual regulatory needs. (3) Meta-paths are introduced to define complex association patterns between entities, and multi-order neighborhood information is dynamically aggregated through a self-attention mechanism. The multi-dimensional association of food risks is effectively captured, and the semantic expression ability of the graph structure is significantly improved.
[0053] The advantages of the present invention are: (1) a SHAP value-based adulterant weight analysis method is proposed, which can accurately calculate the contribution weight of adulterant characteristics and provide more accurate data support for risk prediction. (2) a method for constructing a food heterogeneous graph is developed to integrate multidimensional features and effectively capture the heterogeneity and complexity of food safety data. (3) an advanced heterogeneous graph neural network (HGNN) is applied to solve the problems of node loss and redundant calculation, accurately identify complex associations, and support precise food safety risk warning and management decision-making. BRIEF DESCRIPTION OF THE DRAWINGS
[0054] Figure 1 It is an overall flow chart of the method of the present invention.
[0055] Figure 2 It is a schematic diagram of the meta-path context construction of the method of the present invention.
[0056] Figure 3 Schematic diagram of the meta-path context encoder of the method of the present invention.
[0057] Figure 4 It is a schematic diagram of the device of the present invention. DETAILED DESCRIPTION
[0058] The specific implementation of the present invention is described below with reference to the embodiments.
[0059] Example 1
[0060] This paper uses a food safety inspection dataset compiled by the International Research Center for Data Analysis and Management at Zhejiang University. This dataset contains publicly available data from 247 websites, covering approximately 2.6 million food inspection samples from 215 counties across 31 provinces in China. The research focuses on national food safety inspection data from 2010 to 2020, with a particular focus on 89,202 unqualified samples across 20 different food categories. The dataset was cleaned according to the pre-defined conditions described in the present invention.
[0061] The food safety risk prediction method based on heterogeneous graph neural network of this embodiment has the following steps:
[0062] 1. Calculate risk assessment and adulterant weights for food samples;
[0063] 1.1 The dataset of the target food category is set to D, and D is divided into a training set and a test set with a ratio of 8:2. The qualified samples are assigned a label of 1, and the unqualified samples are assigned a label of 0.
[0064] 1.2 Calculate the adulterant weight.
[0065] (1) Use the XGBoost algorithm to train a classification model.
[0066] (2) Calculate the weight of the dopant according to formula (1) (2).
[0067] 1.3 Calculation of food sample risk values. Formulas (3) and (4) were used to calculate the risk value of each food sample, and the risk ranges were comprehensively divided into “high risk”, “medium-high risk”, “medium risk” and “low risk”.
[0068] 2. Food safety graph representation learning;
[0069] 2.1 9,275 food samples were extracted from the entire dataset, covering categories such as alcoholic beverages. Based on the invention summary 2.1, a food safety graph was constructed, which contains 9,275 food sample nodes, 2,006 production province nodes, 2,139 sales province nodes, and 86 food adulteration nodes. The information of each node is regarded as the feature of the entity. For entities without nodes, their initial features are obtained by random initialization, and the feature matrix X of the food samples is obtained. f , with a dimension of 9275×128, the feature matrix X of the production province p , dimension is 2006×32, sales province X s , with a dimension of 2139×32, the feature matrix X of food adulterants a , with dimensions of 86×64.
[0070] 2.2 Feature Linearity. Apply formula (5) to map different features into a common vector space to obtain the feature matrix X, with a dimension of 13506×128.
[0071] 2.3 Build meta path context. Target node v i As the center, build the meta path context
[0072] 2.4 Meta-path context encoding. Apply formula (6)(7)(8)(9)(10) to get the updated target node representation O i h .
[0073] 2.5 Attention meta-path fusion. Apply formulas (11) and (12) to calculate the node representation O after fusing different meta-path contexts. i .
[0074] 2.6 Use the Adam algorithm to minimize the generator loss function (15) and optimize the node representation.
[0075] 3. Anticipate risks;
[0076] 3.1 The target node from step 2.4 is denoted as O i h , the risk category c for each sample from step 1.3.
[0077] 3.2 Apply formulas (13) and (14) to calculate the probability that the i-th node falls into the risk interval c.
[0078] 3.3 Take steps 2.3 to 3.2 as a complete iterative process, repeat the iteration, use the Adam algorithm to minimize the generator loss function (15), and optimize the node representation.
[0079] This concludes the specific implementation steps of food safety risk prediction based on heterogeneous graph neural networks for NMPA dataset.
[0080] Example 2
[0081] Reference Figure 4 This embodiment relates to a food safety risk prediction device based on a heterogeneous graph neural network, including a memory and one or more processors, wherein the memory stores executable code, and when the one or more processors execute the executable code, they are used to implement a food safety risk prediction method based on a heterogeneous graph neural network of Example 1.
[0082] Example 3
[0083] This embodiment relates to a computer-readable storage medium having a program stored thereon. When the program is executed by a processor, the method for predicting food safety risks based on a heterogeneous graph neural network in embodiment 1 is implemented.
[0084] The contents described in the embodiments of this specification are merely an enumeration of the implementation forms of the inventive concept. The scope of protection of the present invention should not be regarded as limited to the specific forms described in the embodiments. The scope of protection of the present invention also extends to equivalent technical means that can be conceived by those skilled in the art based on the inventive concept.
Claims
1. A food safety risk prediction method based on heterogeneous graph neural network, comprising the following steps: Step 1: Assessing food safety risk: First, a classification model is trained to distinguish between acceptable and unacceptable food samples. The model is then interpreted using SHAP values to calculate the weights of the impact of various adulterants on food compliance. Finally, an overall risk value is calculated for each sample by integrating the weights and used as the predicted label. Step 2: Food safety graph representation learning to capture complex relationships in food samples and identify potential risk patterns: Construct a heterogeneous food safety graph to represent various entities and their relationships. Use a heterogeneous graph neural network (HGNN) that incorporates meta-path context to process the graph data and generate embedding vectors for food sample nodes. Step 3: Risk prediction: Using the predicted labels and the embedding vectors of the food sample nodes, the food samples are classified and the food safety risks are dynamically assessed.
2. The food safety risk prediction method based on heterogeneous graph neural network according to claim 1, characterized in that: Step 1 specifically includes: 1.1 Data screening and cleaning: First, all food samples with unqualified test results were screened out from the dataset, and the following screening conditions were set: (1) Each food category must contain no less than 200 samples; (2) The number of samples with the same adulterant in the same food category must be more than one; then, field association processing was performed on the screened samples: all adulterant names were extracted from the "adulterant" field and matched one by one with the corresponding adulterant addition amount in the "test result" field, thus constructing a dataset D with the sample-adulterant relationship as the core; 1.2 Adulterant Weight Calculation: Based on the constructed dataset, XGBoost was used to train a classification model, using the qualified or unqualified food samples as classification labels to learn the key features that affect food safety. During the training process, the dataset was divided into a training set and a test set in an 8:2 ratio to ensure the generalization ability of the model. After the classification model training was completed, the SHAP value method was used to perform feature importance analysis on each sample and calculate the impact of different adulterants on the qualified or unqualified food samples. Specifically, let the model trained by XGBoost be f(x). For a sample x, the SHAP value calculation formula is as follows: Among them, φ i represents the SHAP contribution value of feature i, S is a subset of the feature set, F is the set of all features, and F(S) represents the model output when only the feature set S is used for prediction. By calculating the SHAP values of all adulterants for each sample and averaging all samples in the data set, the average impact of each adulterant on food conformity can be obtained, which is used as the final weight of each adulterant, that is: where w k is the final weight of adulterant i, N is the total number of samples, φ i,j is the SHAP contribution of adulterant i in sample j; 1.3 Calculating the risk value of food samples: Design a legality standardization method for food safety datasets to calculate the risk value of adulterants, taking the legal threshold of each adulterant into consideration to make the detection value distribution more uniform: First, determine the detection values of all adulterants in each food sample and their corresponding legal thresholds. Suppose the i-th food sample contains n adulterants, where the detection value of the k-th adulterant is denoted as sample ik , the corresponding legal threshold is expressed as threshold k Next, calculate the risk score for each adulterant in sample i: risk_score ik =sample ik / threshold k (3) Among them, risk_score refers to the relative risk assessment of adulterant k; specifically, risk_score ik It represents the ratio of the detection value of the kth adulterant in sample i to its legality threshold. The larger this value is, the higher the content of the adulterant is, the more illegal it is, and the greater the risk is. In order to comprehensively evaluate the risk level of the entire sample, the relative risk score of each adulterant is further weighted and summed. According to the adulterant feature weight w extracted in step 1.2, k , the total risk value of the i-th sample total_risk i The calculation is as follows:
3. The food safety risk prediction method based on heterogeneous graph neural network according to claim 1, characterized in that: Step 2 specifically includes: 2.1 Constructing a heterogeneous food safety graph: It contains four key node types: food samples, food production cities, food testing cities, and detected food adulterants. The heterogeneous graph is represented as G = (V, E, T V ,T E ), where V is the node set, E is the edge set, and T V is a set of node types, and T E is the edge type set; the node type set T V Including food samples, food production cities, food testing cities and detected food adulterants, the edge type set T E It contains three different types of associations, connecting different entities: the production relationship, which connects the food production city with the food sample, indicating the origin of the sample; the supervision relationship, which connects the food testing city with the food sample, indicating the city responsible for quality control and safety assessment; the detection relationship, which connects the food sample with the directly detected food adulterants, indicating the presence of contaminants in the sample; 2.2 Constructing meta-path context: In the heterogeneous graph G = (V, E) used for food detection, different types of entities may have different feature dimensions. To solve this problem, a linear transformation strategy is adopted to map the features of different types of nodes into a common vector space, thereby ensuring that all nodes have consistent feature representations; for nodes without initial features, a unique hot encoding is assigned to them as the initial feature; the type is t i The embedding representation X' of the node can be obtained by the following formula: in, is the original feature, and are learnable weights and biases; After feature preprocessing, for each meta-path For node i in the metapath, MECCH constructs a metapath context, which is represented as a neighborhood subgraph around the node, including all nodes and their adjacent nodes that satisfy the metapath P. Specifically, assuming that the node type and edge type sequence of the metapath P is Given a central node v of type A i The meta path context covers the path starting with v i The neighborhood subgraph centered on v i and its adjacent node v j and v k , and connecting edges e1 and e2; forming a local subgraph centered on node i , clarify the complete structural relationship between the target node and the adjacent nodes defined by the meta-path; 2.3 To distinguish the influence of different meta-path contexts, MECCH adopts a meta-path context encoder after constructing the context to learn the structural and semantic information embedded in it; the encoder utilizes the self-attention mechanism, which enables the model to consider the information of the entire sequence when processing each element of the sequence; in the self-attention mechanism, the correlation between the target node and its first-order neighbors is first calculated; next, the first-order neighbors further aggregate information through their connected second-order neighbors; the query, key, and value vectors are generated through linear transformation: in, is the first-order neighbor of the target node, and and is a learnable parameter matrix; next, the scaled dot product attention is used to calculate the attention score between the query and all keys: Among them, d k is the dimension of the key vector, which is used to scale the dot product to prevent the gradient explosion problem; the scaled attention score is then normalized by the softmax function to obtain the attention weight: Finally, the values are weighted summed according to the attention weights to obtain the context vector: Since we ultimately want to obtain the vector representation of the target node, we update the representation of the target node by adding the original vector of the target node to the vector representation of its aggregated second-order neighbors: vector It captures the structural and semantic information within the meta-path context centered on node i. In the model, multiple such self-attention encoders are stacked to capture structural and semantic information at different levels. The output of each encoder serves as the input of the next encoder, enabling the model to learn more complex patterns. 2.4 Attention Path Fusion: After completing the meta-path context encoding, the model uses a fusion layer to integrate the encoded information from different meta-paths to form a unified node representation; an adaptive method is used to evaluate and merge this information; the contribution of each meta-path is adjusted by introducing learnable weights instead of static averaging; assuming that the target node i has n different meta-paths, each meta-path p corresponds to an encoded representation By learning a weight vector To perform a weighted summation of these representations to obtain the global representation of the node; this can be mathematically expressed as: Among them, w p is the learnable weight of the meta-path p, reflecting the relative importance of this meta-path in the fusion process, and the weight is generated using the softmax function: Among them, θ p is a learnable parameter corresponding to the meta-path p; through this adaptive fusion strategy, MECCH can effectively integrate information from different meta-paths, thereby achieving better performance in graph data analysis tasks.
4. The food safety risk prediction method based on heterogeneous graph neural network according to claim 1, characterized in that: Step 3 specifically includes: After completing the effective integration of meta-path context encoding and fusion layer, the node representation in the food safety graph is It is endowed with the ability to perform food safety prediction; first, a fully connected layer is defined, and the nodes are represented by the following linear transformation Mapped to the original score I: in, is the weight matrix, d is the node representation The dimension of , C represents the number of risk levels; Next, in order to convert the output raw score I into a probability distribution, the softmax function is applied for normalization: in, is the normalized probability distribution after softmax function processing, indicating the probability of the node belonging to each risk level; in order to train the model and optimize its parameters, the cross entropy loss function is used to quantify the difference between the predicted probability distribution and the true label: Among them, N is the number of samples, C is the number of categories, δ ic is an indicator variable that is 1 if node i belongs to category c and 0 otherwise. ic is the probability predicted by the model that node i belongs to category c.
5. A food safety risk prediction device based on heterogeneous graph neural network, characterized in that: It includes a memory and one or more processors, wherein the memory stores executable code, and when the one or more processors execute the executable code, they are used to implement a food safety risk prediction method based on a heterogeneous graph neural network as described in any one of claims 1 to 4.
6. A computer-readable storage medium, characterized in that A program is stored thereon, and when the program is executed by a processor, a food safety risk prediction method based on a heterogeneous graph neural network as described in any one of claims 1-4 is implemented.
Citation Information
Cited By
Constructional engineering cost management and control method and system based on cloud platform
CN121329133A
Food safety risk comprehensive prediction and grading evaluation method and system
CN121936929A
