A method and system for large model knowledge graph completion based on causal guidance
By constructing structured mediator variables and a dual-path reasoning model in the knowledge graph completion method and adopting a dynamic loss balancing mechanism, the problems of logical inconsistency and insufficient generalization ability of existing knowledge graph completion methods in personalized learning path recommendation scenarios are solved, and a more efficient knowledge graph completion effect is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- ZHEJIANG NORMAL UNIV
- Filing Date
- 2026-03-05
- Publication Date
- 2026-06-02
Smart Images

Figure CN121787526B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of knowledge graph completion technology, and in particular to a method and system for completing large-scale model knowledge graphs based on causal guidance. Background Technology
[0002] In the field of intelligent education, personalized learning path recommendation systems typically rely on subject-specific knowledge graphs to construct knowledge structure models. These models use "knowledge points" as entities and "predecessor dependencies" or "prerequisite relationships" as the relationships between entities, describing the learning order and logical constraints between different knowledge points. Through such knowledge graphs, the system can generate learning paths that conform to the cognitive patterns of the subject based on the learner's level and learning goals. However, in practical applications, due to factors such as the dispersed sources of teaching materials, frequent knowledge updates, and high costs of manual annotation, subject-specific knowledge graphs generally suffer from missing or incomplete knowledge point dependencies. This leads to errors in the order or incoherence in the learning paths. Therefore, knowledge graph completion technology is needed to automatically infer the missing knowledge point relationships.
[0003] However, existing knowledge graph completion methods still face significant technical limitations in practical applications. On the one hand, traditional embedding-based learning methods mainly rely on geometric assumptions in vector spaces, making it difficult to characterize complex relational semantics and multi-hop reasoning logic, and their generalization ability is insufficient when faced with sparse relations or unseen entities. On the other hand, with the improvement of large language models' capabilities in text understanding and generation, some technical solutions attempt to transform subject knowledge graphs into natural language forms for input into large language models for reasoning, in order to assist in completing missing knowledge point dependencies. However, in the practical application scenario of personalized learning path recommendation, subject knowledge graphs themselves have explicit directed topological structures and transitive constraints. When the graph structure is linearized into a text sequence, the original directional dependencies are easily weakened, making it difficult for the model to distinguish between real knowledge prerequisite relationships and semantic associations formed only based on text co-occurrence.
[0004] Furthermore, existing large-model-based completion methods often require simultaneous optimization of structural fitting and language modeling objectives during the training phase. Gradient conflicts between these different optimization objectives can easily arise, leading to instability in the training process and significant fluctuations in inference results. Current technologies generally lack effective mechanisms to distinguish and constrain statistical co-occurrence bias and real-world knowledge dependencies at the mechanistic level. This makes it difficult to ensure the logical consistency and stability of inference results in personalized learning path recommendation scenarios while maintaining semantic understanding capabilities.
[0005] In summary, the technical problems existing in the relevant technologies need to be improved. Summary of the Invention
[0006] The main objective of this application is to propose a method and system for completing a large model knowledge graph based on causal guidance, which can improve the accuracy of knowledge graph completion while enhancing the controllability, interpretability, and training stability of the reasoning process.
[0007] To achieve the above objectives, one aspect of this application proposes a causal-guided method for completing large-scale model knowledge graphs, the method comprising the following steps:
[0008] Obtain the target knowledge graph and the input triples to be completed; the input triples include a head entity, a tail entity, and a relation;
[0009] Based on the target knowledge graph, structured analysis processing is performed on the relations in the input triples to extract key topological feature vectors;
[0010] Based on the key topological feature vectors, construct structured mediator variables;
[0011] The structured mediation variables are mapped to structured guide prefixes in the form of continuous vectors, and the structured guide prefixes are injected into the input sequence of the large model to generate a structured large model input representation;
[0012] Based on the input representation of the large model, a dual-path reasoning model is constructed;
[0013] Based on the dual-path inference model, inference prediction results are generated for the input triples;
[0014] Based on the inference prediction results of the input triples, a gradient-aware dynamic loss balancing mechanism is adopted to dynamically adjust the corresponding loss weights.
[0015] Based on the inference prediction results adjusted by dynamic weights, the knowledge graph completion result of the input triple is output.
[0016] In some embodiments, the step of performing structured analysis processing on the relations in the input triples based on the target knowledge graph to extract key topological feature vectors includes:
[0017] Based on the target knowledge graph, the frequency of occurrence of relations in the input triples is counted, and the occurrence frequency is normalized to obtain relation frequency features.
[0018] Based on the head and tail entities connected by the relation in the input triplet, the tightness of the entity connection is calculated to obtain the connectivity feature;
[0019] Based on the forward and backward connection distribution of the relations in the input triples in the target knowledge graph, the relation symmetry index is calculated to obtain the symmetry features;
[0020] Based on the node degree distribution of relational entities in the input triplet, the relation confusion index is calculated to obtain potential confusion features.
[0021] The relationship frequency feature, the connectivity feature, the symmetry feature, and the potential confusion feature are combined to form a key topological feature vector.
[0022] In some embodiments, the formula for the structured mediator variable is as follows:
[0023] ;
[0024] in, This represents the final generated structured mediator variable embedding. This represents a predefined learnable basic prefix matrix for relation r; Represents the projection matrix, with dimension . ; and Let represent the embedding vectors of the head and tail entities of the input triplet, respectively. Represents the global knowledge embedding of a large language model. Let || denote a non-linear activation function, and || denote a vector concatenation operation. Represents the bias vector of the projection layer; This represents the key topological feature vector.
[0025] In some embodiments, mapping the structured mediation variables to structure-guided prefixes in the form of continuous vectors and injecting the structure-guided prefixes into the input sequence of a large model to generate a structure-guided large model input representation includes:
[0026] The structured mediator variables are subjected to vector space projection processing, which maps the structured mediator variables to a continuous vector representation consistent with the dimension of the large model space, to obtain the structure-guided prefix vector;
[0027] Based on the text embedding sequence corresponding to the structure-guided prefix vector and the input triple, a prefix concatenation operation is performed on the sequence dimension to generate an input embedding sequence that integrates structural information.
[0028] The input embedding sequence is input into the large model, so that the structure-guided prefix vector participates in multi-layer self-attention operations as a key vector and numerical vector in attention calculation;
[0029] Based on the self-attention operation results, a large model input representation containing structural constraint information is obtained.
[0030] In some embodiments, the dual-path reasoning model includes an association path sub-model and an intervention path sub-model.
[0031] In some embodiments, the associated path sub-model includes:
[0032] Based on the input representation of the large model, conditional probability modeling is performed on the input triples to obtain the predicted probability of the associated path.
[0033] Based on the predicted probability of the associated path and the true label corresponding to the input triple, an associated path loss function is constructed; the associated path loss function is used to characterize the fitting error of the large model to the true value of the triple under the observation distribution;
[0034] During the training of the associated path sub-model, backpropagation is performed to update the parameters of the large model based on the associated path loss function.
[0035] In some embodiments, the intervention path sub-model includes:
[0036] Based on the input representation of the large model, biased inference modeling is performed on the input triples to obtain the predicted probability of the intervention path.
[0037] Based on the historical reliability index of the corresponding relationship type of the input triplet and the distribution characteristics of the relationship category, an intervention weight coefficient is constructed;
[0038] Based on the intervention weight coefficients, the loss terms corresponding to the predicted probabilities of the intervention paths are weighted to form a weighted intervention path loss function;
[0039] During the training of the intervention path sub-model, the parameters of the large model are updated by backpropagation based on the weighted intervention path loss function.
[0040] In some embodiments, the formula for the weighted intervention path loss function is as follows:
[0041] ;
[0042] in, The value represents the weighted intervention path loss function; N represents the total number of samples participating in the loss calculation in the current training batch; i represents the sample index; Indicates the first Intervention weight coefficients corresponding to each sample; Indicates the first The true labels of the input triples; This indicates the intervention path for the first... The predicted probability of the intervention path given by the input triplet; and These represent the log-likelihood terms for the prediction results of positive and negative samples, respectively.
[0043] In some embodiments, the inference prediction result based on the input triples employs a gradient-aware dynamic loss balancing mechanism to dynamically adjust the corresponding loss weights, including:
[0044] Based on the inference prediction results of the input triples, the gradient magnitude of the dual-path inference model with respect to the structured mediator variables is calculated;
[0045] A gradient conflict metric is constructed based on the gradient magnitude.
[0046] When the gradient conflict metric exceeds a preset threshold, the loss weights corresponding to the intervention path loss function are adaptively adjusted based on the gradient-aware dynamic loss balancing mechanism.
[0047] Based on the adjusted dual-path inference model, a joint optimization objective function is constructed.
[0048] The parameters of the large model are updated by backpropagation based on the joint optimization objective function.
[0049] To achieve the above objectives, another aspect of this application proposes a causal-guided large-scale model knowledge graph completion system, the system comprising:
[0050] The acquisition module is used to acquire the target knowledge graph and the input triples to be completed;
[0051] The feature extraction module is used to perform structured analysis processing on the relations in the input triples based on the target knowledge graph, and extract key topological feature vectors.
[0052] The first construction module is used to construct structured mediator variables based on the key topological feature vectors;
[0053] The structure-guided prefix generation module is used to map the structured mediation variables into structure-guided prefixes in the form of continuous vectors, and inject the structure-guided prefixes into the input sequence of the large model to generate a structure-guided large model input representation;
[0054] The second construction module is used to construct a dual-path inference model based on the input representation of the large model;
[0055] The inference prediction module is used to generate inference prediction results for the input triples based on the dual-path inference model.
[0056] The optimization module is used to dynamically adjust the corresponding loss weights based on the inference prediction results of the input triples using a gradient-aware dynamic loss balancing mechanism.
[0057] The result output module is used to output the knowledge graph completion result of the input triple based on the inference prediction result after dynamic weight adjustment.
[0058] To achieve the above objectives, another aspect of this application provides an electronic device, which includes a memory and a processor. The memory stores a computer program, and the processor executes the computer program to implement the above-described method.
[0059] To achieve the above objectives, another aspect of the embodiments of this application proposes a computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described method.
[0060] To achieve the above objectives, another aspect of this application provides a computer program product, including a computer program that, when executed by a processor, implements the above-described method.
[0061] The embodiments of this application include at least the following beneficial effects: This application provides a method and system for completing a large-scale model knowledge graph based on causal guidance. This scheme acquires the target knowledge graph and the input triples to be completed, performs structured analysis on the relations in the input triples, extracts key topological features, and constructs structured mediator variables. This allows the potential causal dependencies between entities and relations to be explicitly expressed, avoiding inference biases that rely solely on statistical correlation. The structured mediator variables are mapped to structure-guided prefixes and injected into the large-scale model input sequence, achieving structural constraints and causal guidance on the large-scale model's inference process, thereby enhancing the model's generalization ability in complex relations, long-tail relations, and sparse sample scenarios. By constructing a dual-path inference model, the structural causal path and semantic inference path are co-modeled, enabling the model to fully utilize the structural information of the knowledge graph while maintaining the expressive power of the large-scale model, improving the consistency and robustness of the inference results. By introducing a gradient-aware dynamic loss balancing mechanism, the weights of different loss terms are adaptively adjusted based on the gradient feedback of the inference prediction results, effectively alleviating the optimization imbalance problem that easily occurs during multi-objective training and promoting stable model convergence. This invention can significantly improve the overall performance of knowledge graph completion while ensuring the controllability of reasoning, and has good engineering practical value. Attached Figure Description
[0062] Figure 1 This is a flowchart illustrating a causal-guided large-scale model knowledge graph completion method provided in an embodiment of this application.
[0063] Figure 2 yes Figure 1 The flowchart for step S7 in the process;
[0064] Figure 3This is a schematic diagram of a module of a causal-guided large model knowledge graph completion system provided in an embodiment of this application. Detailed Implementation
[0065] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of this application and are not intended to limit it. In the following description, when referring to the accompanying drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with those of this application; they are merely examples of apparatuses and methods consistent with some aspects of the embodiments of this application as detailed in the appended claims.
[0066] It is understood that the terms “first,” “second,” etc., used in this application may be used herein to describe various concepts, but unless otherwise stated, these concepts are not limited by these terms. These terms are only used to distinguish one concept from another. For example, without departing from the scope of the embodiments of this application, first information may also be referred to as second information, and similarly, second information may also be referred to as first information. Depending on the context, the words “if,” “when,” or “in response to a determination” as used herein may be interpreted as “when…” or “when…” or “in response to a determination.”
[0067] As used in this application, the terms "at least one", "multiple", "each", "any", etc., "at least one" includes one, two or more, "multiple" includes two or more, "each" refers to each of the corresponding multiples, and "any" refers to any one of the multiples.
[0068] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of this application only and is not intended to limit this application.
[0069] Before providing a detailed description of the embodiments of this application, some of the nouns and terms used in the embodiments of this application will be explained first. The nouns and terms used in the embodiments of this application shall be interpreted as follows:
[0070] PyTorch is an open-source deep learning framework developed by Meta. It is based on a dynamic computation graph mechanism, supports automatic differentiation and GPU acceleration, and is widely used in the construction, training and deployment of neural network models.
[0071] HuggingFace is a technology organization and platform focused on open-source natural language processing and large model ecosystems. It provides model libraries such as Transformers and pre-trained model resources for model downloading, fine-tuning, and inference deployment.
[0072] CoDEx-S refers to a small-scale knowledge graph completion dataset in the CoDEx (Comprehensive Knowledge Graph Completion Benchmark) benchmark suite, used to evaluate knowledge graph embedding and completion methods. It is more diverse and challenging than traditional benchmark datasets in terms of entities, relations, and positive / hard negative triples.
[0073] FB15K-237N refers to a variant of the knowledge graph completion evaluation dataset derived from Freebase. The "N" indicates that some relations containing mediator nodes have been removed. The original FB15K-237 (a subset of Freebase with 237 relations) has been cleaned up to reduce complexity and improve evaluation quality. It is used for tasks such as triple classification or link prediction.
[0074] LLaMA-3-8B-Instruct refers to the 8 billion parameter version (8B) of the third-generation large language model LLaMA 3 (Large Language Model Meta AI 3) released by Meta. It has been fine-tuned with instructions to better understand and execute natural language instructions. It is often used for dialogue, reasoning and fine-tuning of downstream tasks.
[0075] LoRA stands for Low-Rank Adaptation, a parameter-efficient fine-tuning technique that introduces a trainable low-rank decomposition matrix into the original model's weight matrix to achieve efficient fine-tuning of large models, while significantly reducing trainable parameters and maintaining model performance.
[0076] TransE refers to a knowledge graph embedding model based on the vector translation hypothesis. Its core idea is to model relations in a continuous vector space as a translation operation from the head entity to the tail entity.
[0077] RotatE refers to a knowledge graph embedding model based on the complex space rotation assumption. It models relations as rotational transformations of head entity vectors through complex multiplication, and can represent complex relations such as symmetric and antisymmetric relations.
[0078] KG-BERT refers to a completion method that transforms knowledge graph triples into text sequences and inputs them into a pre-trained language model for authenticity determination. It mainly relies on semantic modeling capabilities to complete reasoning.
[0079] KoPA is a knowledge graph augmentation method based on knowledge-aware prefix or cue tuning, which injects structural knowledge into the reasoning process of large models by introducing learnable prefix vectors.
[0080] SAT stands for Self-Attention, which models global dependencies within a sequence through weighted calculations of queries, keys, and values. It is the core computational mechanism of the Transformer architecture.
[0081] This application provides a method and system for large-scale knowledge graph completion based on causal guidance. The scheme acquires the target knowledge graph and the input triples to be completed, performs structured analysis on the relationships within the input triples, extracts key topological features, and constructs structured mediator variables. This explicitly expresses the potential causal dependencies between entities and relationships, avoiding inference biases that rely solely on statistical correlation. The structured mediator variables are mapped to structure-guided prefixes and injected into the large-scale model's input sequence, achieving structural constraints and causal guidance for the large-scale model's inference process, thereby enhancing the model's generalization ability in complex relationships, long-tail relationships, and sparse sample scenarios. By constructing a dual-path inference model, the structural causal path and semantic inference path are co-modeled, allowing the model to fully utilize the structural information of the knowledge graph while maintaining the expressive power of the large-scale model, improving the consistency and robustness of the inference results. By introducing a gradient-aware dynamic loss balancing mechanism, the weights of different loss terms are adaptively adjusted based on the gradient feedback of the inference prediction results, effectively alleviating the optimization imbalance problem that easily occurs during multi-objective training and promoting stable model convergence. This invention can significantly improve the overall performance of knowledge graph completion while ensuring the controllability of reasoning, and has good engineering practical value.
[0082] This application provides a method for completing a large-scale knowledge graph based on causal guidance, relating to the field of knowledge graph completion technology. This method can be applied to a terminal, a server, or software running on either a terminal or a server. In some embodiments, the terminal can be a smartphone, tablet, laptop, desktop computer, smart speaker, smartwatch, or in-vehicle terminal, but is not limited to these. The server can be configured as an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms. The server can also be a node server in a blockchain network. The software can be an application implementing a method for completing a large-scale knowledge graph based on causal guidance, but is not limited to the above forms.
[0083] This application can be used in a wide variety of general-purpose or special-purpose computer system environments or configurations. Examples include: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics devices, network PCs, minicomputers, mainframe computers, and distributed computing environments including any of the above systems or devices. This application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc., that perform specific tasks or implement specific abstract data types. This application can also be practiced in distributed computing environments where tasks are performed by remote processing devices connected via a communication network. In distributed computing environments, program modules can reside in local and remote computer storage media, including storage devices.
[0084] Figure 1 This is an optional flowchart of a causal-guided large model knowledge graph completion method provided in an embodiment of this application. Figure 1 The method may include, but is not limited to, steps S1 to S8:
[0085] S1: Obtain the target knowledge graph and the input triples to be completed; where the input triples include the head entity, the tail entity, and the relation;
[0086] In this embodiment, the target knowledge graph is first obtained. The target knowledge graph is stored in the form of structured triples, containing entity sets, relation sets, and directed connection information between entities. An indexing mechanism maintains the mapping relationship between entity identifiers, relation types, and graph structure adjacency information. The knowledge graph can originate from domain databases, business system knowledge bases, or historically constructed graph resources. Internally, it is stored in a graph database or key-value mapping method to support subsequent efficient structured access and topology analysis processing.
[0087] After acquiring the target knowledge graph, input triples to be completed are constructed according to the requirements of the knowledge graph completion task. Each input triple includes at least three parts: a head entity, a relation, and a tail entity. The head entity and relation are known items, while the tail entity can be a missing entity to be predicted or a candidate entity used for truth determination. In practice, the input triples can be automatically generated by the system based on missing edges, low-confidence relations, or external query requests in the graph, or they can be specified by the user or upper-layer applications to trigger the completion reasoning process for specific relations.
[0088] Furthermore, when generating input triples, this embodiment performs normalization processing on the head entity, relation, and tail entity, including entity unique identifier alignment, relation type encoding, and entity category consistency verification, to ensure that the input triples are structurally consistent with the target knowledge graph. Simultaneously, the input triples are associated with and bound to the entity index and relation index in the target knowledge graph, enabling subsequent steps to directly locate the corresponding adjacency relationships, path information, and statistical features in the graph structure space based on the input triples. This provides a stable and traceable data foundation for subsequent structured analysis and causal reasoning.
[0089] S2: Based on the target knowledge graph, perform structured analysis on the relations in the input triples to extract key topological feature vectors;
[0090] Specifically, based on the target knowledge graph, structured analysis is performed on the relations in the input triples to extract key topological feature vectors, including:
[0091] S21: Based on the target knowledge graph, count the frequency of occurrence of relations in the input triples, and normalize the frequency of occurrence to obtain relation frequency features;
[0092] S22: Based on the head and tail entities connected by the relation in the input triples, calculate the tightness of the entity connections to obtain the connectivity features;
[0093] S23: Based on the distribution of forward and backward connections of relations in the input triples in the target knowledge graph, calculate the relation symmetry index to obtain symmetry features;
[0094] S24: Based on the node degree distribution of relational entities in the input triples, calculate the relation confusion index to obtain potential confusion features;
[0095] S25: Combine relational frequency features, connectivity features, symmetry features, and potential confusion features to form a key topological feature vector.
[0096] In this embodiment, for a given input triplet First, from the knowledge graph Extracting relations Key topological feature vectors This vector contains features in the following four dimensions, designed to comprehensively characterize the structural properties of the relationship:
[0097] Relationship frequency characteristics ( This indicator reflects the prevalence of a certain relationship in the graph and the stability of the statistical pattern. The calculation formula is as follows: ,in For relationship The number of triples. High frequency usually indicates that the relationship has strong statistical regularity and can serve as a basic source of confidence for the model.
[0098] Connectivity features ( This indicator measures the relationship. The tightness of the connection between the head set and the tail set of entities. High connectivity means that statistical associations can be effectively propagated through this relationship, indicating that this is a reliable inference path rather than a random, noisy connection.
[0099] Symmetry characteristics ( This indicator is used to identify whether a relationship has symmetric attributes (e.g., spouses are symmetrical, while parents and children are asymmetrical). It is calculated by satisfying... The proportion is obtained. Explicitly encoding symmetry is crucial for preventing directional reasoning fallacies.
[0100] Potential confusing features ( This indicator serves as a proxy variable for potential confusion. Relationships connecting high-frequency entities often carry more non-specific statistical co-occurrence information and are prone to becoming confusing paths. Introducing this feature can encourage the model to learn to identify and reduce the weight of such high-risk paths.
[0101] The key topological feature vector is represented as:
[0102] ;
[0103] in, This represents a four-dimensional real vector space.
[0104] S3: Construct structured mediator variables based on key topological feature vectors;
[0105] The formula for the structured mediator variable is as follows:
[0106] ;
[0107] in, This represents the final generated structured mediator variable embedding. This represents a predefined learnable basic prefix matrix for relation r; Represents the projection matrix, with dimension . ; and Let represent the embedding vectors of the head and tail entities of the input triplet, respectively. Represents the global knowledge embedding of a large language model. Let || denote a non-linear activation function, and || denote a vector concatenation operation. Represents the bias vector of the projection layer; This represents the key topological feature vector.
[0108] S4: Map the structured mediator variables to structured guide prefixes in the form of continuous vectors, and inject the structured guide prefixes into the input sequence of the large model to generate a structured large model input representation;
[0109] Specifically, the structured mediation variables are mapped to structured guiding prefixes in the form of continuous vectors, and these guiding prefixes are injected into the input sequence of the large model to generate a structured guiding input representation of the large model, including:
[0110] S41: Perform vector space projection on the structured mediator variables to map them to a continuous vector representation consistent with the dimension of the large model space, thus obtaining the structured guided prefix vector;
[0111] S42: Based on the text embedding sequence corresponding to the structure-guided prefix vector and the input triple, perform prefix concatenation operation on the sequence dimension to generate an input embedding sequence that integrates structural information;
[0112] S43: Input the input embedding sequence into the large model, so that the structure-guided prefix vector can participate in the multi-layer self-attention operation as the key vector and numerical vector in the attention calculation.
[0113] S44: Based on the self-attention operation results, a large model input representation containing structural constraint information is obtained.
[0114] In this embodiment, after obtaining the structured mediator variables, the structured mediator variables are mapped to structure-guided prefixes in continuous vector form, and the structure-guided prefixes are injected into the input sequence of the large model to generate a structure-guided large model input representation. Specifically, the structured mediator variables are not converted into natural language text, but their continuous vector form is retained, so that the structural information can directly participate in subsequent inference calculations in the vector space, thereby avoiding the weakening of structural constraints during text serialization.
[0115] First, a vector space projection process is performed on the structured mediator variables, mapping them to a continuous vector representation with the same dimensionality as the large model space, resulting in structure-guided prefix vectors. This mapping process ensures that the structured mediator variables maintain consistency with the large model input embedding in terms of numerical distribution and dimensionality, providing a foundation for subsequent concatenation and attention operations.
[0116] Subsequently, based on the structure-guided prefix vector and the text embedding sequence corresponding to the input triples, a prefix concatenation operation is performed at the sequence level to generate an input embedding sequence that incorporates structural information. Specifically, the structure-guided prefix vector is placed at the beginning of the text embedding sequence, so that the large model receives the structural constraint signal corresponding to the relation before processing the semantic information of the input triples, thereby guiding the subsequent inference direction at the overall input level.
[0117] Finally, the input embedding sequence is fed into the large model, allowing the structure-guided prefix vector to participate in the attention computation as both a key vector and a numerical vector during the multi-layer self-attention operation. Based on the accumulated results of the multi-layer self-attention operation, a large model input representation containing structural constraint information is obtained, enabling the model to maintain semantic expressiveness while adhering to the structural logic constraints of the knowledge graph during subsequent inference.
[0118] Specifically, due to the key topological feature vector Since the word embedding space pre-trained by Large Language Models (LLMs) is inconsistent in dimensionality and semantic representation, this embodiment designs a learnable projection layer. This projection layer utilizes a projection matrix. Mapping low-dimensional structural features to the high-dimensional hidden space of LLM. That is, the low-dimensional structural features are mapped to the high-dimensional hidden layer space of LLM through the projection matrix.
[0119] Sequence concatenation: In the input layer, the projected structured mediator variables are concatenated. As a prefix, it is appended to the front of the serialized text embedding input LLM. Let the text serialization embedding of the input triples be... The final input is the embedding sequence of the LLM. Represented as: in This represents the concatenation operation of vectors along the length dimension of the sequence.
[0120] Structure guidance based on self-attention mechanism: Large model reception Subsequently, in the self-attention sublayers of each layer of the Transformer decoder, the structured prefix is... It participates in the calculation as part of the Key and Value matrices. Because It explicitly encodes the topological logic of the graph, which changes the attention weight distribution of the LLM to subsequent text tokens, guiding the model to focus on semantic features that conform to the logic of the graph structure, thereby effectively blocking false inference paths that rely solely on text co-occurrence.
[0121] S5: Construct a dual-path reasoning model based on the input representation of the large model; the dual-path reasoning model includes an association path sub-model and an intervention path sub-model.
[0122] In this embodiment, after obtaining the large model input representation containing structural constraint information, a dual-path inference model is constructed based on the large model input representation. The dual-path inference model includes at least an association path sub-model and an intervention path sub-model. The association path sub-model is used to learn the statistical correlation between input triples and true labels under the observed data distribution, thereby forming basic predictive capabilities; the intervention path sub-model is used to subsequently correct biases. When constructing the association path sub-model, the large model input representation is used as a unified input, ensuring that subsequent statistical modeling is based on the same structurally guided input, guaranteeing the comparability and fusion of the two paths.
[0123] The associated path sub-model includes:
[0124] Based on the large model input representation, conditional probability modeling is performed on the input triples to obtain the predicted probability of associated paths;
[0125] Based on the predicted probability of the associated path and the true label corresponding to the input triple, an associated path loss function is constructed; the associated path loss function is used to characterize the fitting error of the large model to the trueness of the triple under the observation distribution.
[0126] During the training of the associated path sub-model, backpropagation is performed on the parameters of the large model based on the associated path loss function.
[0127] In this embodiment, conditional probability modeling is performed on the input triples based on the large model input representation to obtain the predicted probability of the association path. Specifically, the large model input representation is input to the output layer or classification head used for triple discrimination. Binary classification probability estimation is performed on the "true / false" of the input triples to output the predicted probability of the association path. For scenarios where the tail entities are a candidate set, each candidate tail entity can be combined with the head entity and relation to form candidate triples, and the predicted probability can be calculated separately to obtain a score sequence of candidate entities. This score sequence also serves as the probability output result of the association path.
[0128] After obtaining the predicted probabilities of associated paths, an associated path loss function is constructed based on the predicted probabilities and the ground truth labels corresponding to the input triples. This function characterizes the fitting error of the large model to the ground truth of the triples under the observed distribution. In practice, the ground truth labels can be obtained from the known facts labeled in the target knowledge graph: ground truth triples existing in the graph are used as positive samples, and erroneous triples generated through a negative sampling strategy are used as negative samples. The positive and negative samples are combined into training batches, so that the associated path loss function can reflect the prediction bias and fitting degree of the model under the current observed sample distribution.
[0129] Finally, during the training of the association path sub-model, backpropagation is performed on the parameters of the main model based on the association path loss function. Specifically, for each training batch, forward computation is first performed to obtain the predicted probability of the association path, then the loss value is calculated based on the true labels and the gradient is backpropagated; and the parameters of the main model or its trainable adaptive parameters are updated based on the gradient, thereby gradually improving the association path sub-model's ability to discriminate the authenticity of triples under the observed distribution. Through this training process, the association path sub-model forms a stable learning of common relationships and semantic patterns, providing a basic predictive reference for subsequent bias-free inference of intervention paths.
[0130] Specifically, the formula for the associated path loss function is as follows:
[0131] ;
[0132] in, This represents the value of the associated path loss function. This indicates the total number of samples involved in loss calculation in the current training batch. Indicates the first The true label of each sample (0 or 1, indicating whether the triple is true). Probability of associated path prediction.
[0133] The intervention path sub-model includes:
[0134] Based on the input representation of the large model, biased inference modeling is performed on the input triples to obtain the predicted probability of the intervention path;
[0135] Based on the historical reliability index of the input triple correspondence type and the distribution characteristics of the relation category, an intervention weight coefficient is constructed;
[0136] Based on the intervention weight coefficient, the loss terms corresponding to the predicted probabilities of the intervention path are weighted to form a weighted intervention path loss function;
[0137] During the training of the intervention path sub-model, backpropagation is performed on the parameters of the large model based on the weighted intervention path loss function.
[0138] In this embodiment, based on the structure-guided large model input representation, bias-free inference modeling is performed on the input triples to obtain the predicted probability of the intervention path. Specifically, while maintaining consistency between the input representation and the associated path, causal bias-free constraints are introduced to adjust the inference process. This allows the model to not only rely on textual semantic associations when predicting the authenticity of input triples, but also to focus on the graph structure information carried by structured mediator variables, thereby weakening the tendency for misjudgment caused by high-frequency co-occurrence or corpus bias.
[0139] Furthermore, intervention weight coefficients are constructed based on the historical reliability index of the input triplet correspondence type and the distribution characteristics of the relation categories. In practice, the historical performance of different relation types during training is statistically analyzed to form a historical reliability index reflecting the stability and credibility of the relation. Simultaneously, considering the distribution of relations in the sample set, high-frequency relations and low-frequency long-tail relations are identified. The training influence of high-frequency relations is appropriately reduced, while the weight of low-frequency relations is appropriately increased to alleviate the bias problem caused by uneven relation distribution. The historical reliability information and category distribution characteristics are then comprehensively processed to obtain the intervention weight coefficients used for sample-level adjustment.
[0140] Specifically, the formula for the intervention weight coefficient is as follows:
[0141] ;
[0142] in, Indicates the first Intervention weight coefficients corresponding to each sample; Indicates the first The relation type identifier corresponding to each sample; Representing relations The historical inference reliability weight is used to comprehensively reflect the statistical performance of the corresponding prediction results, such as accuracy, confidence, and F1 score, during the training process. Representing relations The category distribution balancing weight is used to alleviate the training bias problem caused by the long-tail distribution of relation types in the knowledge graph. This factor is usually inversely proportional to the frequency of relation occurrence, and is used to suppress the excessive dominance of high-frequency relations in the training process, while increasing the learning weight of low-frequency and sparse relation samples in the intervention path. This indicates that the model, in the current training phase, is performing well on the input samples. Prediction results correspond to real labels The confidence evaluation function.
[0143] After obtaining the intervention weight coefficients, the loss terms corresponding to the predicted probabilities of the intervention paths are weighted according to these coefficients to form a weighted intervention path loss function. By differentially adjusting the loss contribution of different input triples, samples with strong structural consistency and low confusion risk play a greater role in the model optimization process, while the optimization weight of samples that are more affected by statistical co-occurrence is relatively suppressed, thereby guiding the model to gradually converge towards a reasoning direction that is structurally reasonable and causally consistent.
[0144] Finally, during the training of the intervention path sub-model, backpropagation updates the parameters of the large model based on the weighted intervention path loss function. Through multiple rounds of training iterations, the model continuously strengthens its ability to respond to reliable structural evidence and reduces its dependence on spurious relevance patterns, achieving stable debiased inference on input triples and providing reliable support for subsequent dual-path fusion and knowledge graph completion output.
[0145] Specifically, the formula for the weighted intervention path loss function is as follows:
[0146] ;
[0147] in, represents the weighted intervention path loss function value; N represents the total number of samples participating in the loss calculation in the current training batch; j represents the sample index; Indicates the first Intervention weight coefficients corresponding to each sample; Indicates the first The true labels of the input triples; This indicates the intervention path for the first... The predicted probability of the intervention path given by the input triplet; and These represent the log-likelihood terms for the prediction results of positive and negative samples, respectively.
[0148] S6: Based on the dual-path inference model, generate inference prediction results for the input triples;
[0149] In this embodiment, after constructing the dual-path inference model, inference predictions are performed on the input triples based on the association path sub-model and the intervention path sub-model, respectively. Specifically, the association path sub-model, based on the structure-guided input representation of the large model, focuses on utilizing the large model's statistical learning capabilities for entity semantics and relational patterns to perform conditional probability inference on the input triples, outputting prediction results that reflect the strength of statistical association, which are used to characterize the probability of the triples being true under the observed data distribution.
[0150] Meanwhile, the intervention path sub-model, under the same input representation of the large model, introduces structured mediator variables as explicit constraints to impose causal intervention on the reasoning process. This path weakens the predictive tendency that relies solely on text co-occurrence or high-frequency patterns during reasoning, focusing instead on determining the logical consistency of the input triples based on structural connectivity, directionality, and relational reliability information in the knowledge graph, thereby outputting inference prediction results under causal constraints.
[0151] Furthermore, this embodiment retains the prediction results of the association path sub-model and the intervention path sub-model as independent outputs instead of immediately performing simple fusion. This allows subsequent steps to dynamically adjust the contribution of the two paths based on their performance differences across different samples and relationship types. This approach ensures that the model possesses both statistical generalization ability and structural logic constraint ability during the inference phase, providing a sufficient information foundation for subsequent loss balancing and result optimization.
[0152] S7: Based on the inference prediction results of the input triples, a gradient-aware dynamic loss balancing mechanism is adopted to dynamically adjust the corresponding loss weights.
[0153] Among them, reference Figure 2 As shown, based on the inference prediction results of the input triples, a gradient-aware dynamic loss balancing mechanism is adopted to dynamically adjust the corresponding loss weights, including:
[0154] S71: Based on the inference prediction results of the input triples, calculate the gradient magnitude of the two-path inference model with respect to the structured mediator variables;
[0155] S72: Constructing a gradient conflict metric based on gradient magnitude;
[0156] S73: When the gradient conflict metric exceeds the preset threshold, the loss weight corresponding to the intervention path loss function is adaptively adjusted based on the gradient-aware dynamic loss balancing mechanism.
[0157] S74: Construct a joint optimization objective function based on the adjusted dual-path inference model;
[0158] S75: Perform backpropagation updates on the parameters of a large model based on the joint optimization objective function.
[0159] In this embodiment, based on the inference prediction results of the input triples, a gradient-aware dynamic loss balancing mechanism is introduced to dynamically adjust the loss weights corresponding to the associated path and the intervention path in the dual-path inference model. Since the associated path focuses on fitting the statistical correlation in the observed data, while the intervention path focuses on suppressing statistical co-occurrence bias and strengthening structural constraints, the two paths may have inconsistent update directions during training. Therefore, a dynamic adjustment mechanism is needed to achieve collaborative optimization.
[0160] In practice, during each training iteration, the gradient magnitude of the dual-path inference model with respect to the structured mediator variable is calculated based on the inference prediction results of the input triples. The structured mediator variable, as a shared structural constraint carrier between the two paths, reflects the intensity of structural information updates made by both paths during the current training phase through its gradient changes, providing a basis for subsequent judgments regarding the existence of gradient conflicts.
[0161] After obtaining the gradient magnitudes corresponding to the two paths, a gradient conflict metric is constructed based on these magnitudes. This metric measures the degree of gradient difference between the associated path and the intervention path in the current training state. When the gradient difference is small, it indicates that the two paths have good synergy; when the gradient difference increases significantly, it indicates that the two paths have obvious conflict in the optimization direction, which may affect training stability.
[0162] When the gradient conflict metric exceeds a preset threshold, a gradient-aware dynamic loss balancing mechanism is triggered, adaptively adjusting the loss weights corresponding to the intervention path loss function. When the gradient of the associated path is dominant and the conflict is significant, the intervention path loss weights are increased to strengthen the bias removal constraint; conversely, when the gradient of the intervention path is dominant and the conflict is significant, the intervention path loss weights are appropriately reduced to avoid training instability caused by over-correction.
[0163] Finally, based on the dynamically adjusted dual-path inference model, a joint optimization objective function is constructed, and backpropagation updates are performed on the large model parameters based on the joint optimization objective function. By continuously performing gradient conflict awareness and loss weight adjustment during training, the model maintains stable convergence at different training stages, and the reliability and consistency of inference results in the knowledge graph completion task are improved.
[0164] Specifically, the relationship between the two paths and the mediating variables is first calculated in real time. gradient magnitude difference ratio As a measure of the degree of conflict:
[0165] ;
[0166] in, A metric signal representing the degree of gradient conflict, with a value range of... Represents the value of the associated path loss function. For structured mediator variables gradient vector, Represents the weighted intervention path loss function For structured mediator variables gradient vector, The L2 norm (magnitude) of the gradient is represented.
[0167] When the conflict signal Exceeding the threshold When the time comes, the mechanism is activated, dynamically adjusting the weights of the intervention pathways. :
[0168] ;
[0169] in, The dynamic adjustment weights represent the loss of the intervention path. This represents the basic weight hyperparameter. Indicates the dynamic adjustment factor. The activation threshold representing gradient conflict. This represents the truncation function.
[0170] The final joint optimization objective function is:
[0171] ;
[0172] in, This represents the value of the joint optimization objective function.
[0173] S8: Based on the inference prediction results adjusted by dynamic weights, output the knowledge graph completion result of the input triples.
[0174] In this embodiment, based on the weighted inference prediction results, the input triples are subjected to a final knowledge graph completion judgment. Specifically, according to the dynamically balanced optimization objective function, the output results of the association path sub-model and the intervention path sub-model are comprehensively evaluated, so that in cases of strong gradient conflict or high statistical bias risk, the prediction results corresponding to the intervention path have a higher weight in the final judgment.
[0175] In the triple authenticity determination scenario, this embodiment compares the final inference prediction result with a preset determination threshold and outputs a completion result indicating whether the input triple is true. In the tail entity prediction scenario, the candidate tail entity set is sorted based on the final prediction score, and one or more entities with the highest scores are selected as the completion result. In this way, it is ensured that the completion result not only has high confidence at the numerical level, but also conforms to the topological constraints of the knowledge graph at the structural and causal levels.
[0176] Finally, the knowledge graph completion results are written into the target knowledge graph to add relation edges, correct existing low-confidence relations, or annotate reasoning credibility information, thereby achieving continuous expansion and optimization of the knowledge graph. Because the completion process is guided by causality and controlled by structural constraints, the generated completion results can effectively avoid logical inversion and spurious association problems caused by statistical co-occurrence, ensuring the consistency and interpretability of the overall graph structure.
[0177] In this embodiment, multiple experimental scenarios were used to compare and test the performance of this method with traditional embedding methods, PLM methods, and the latest LLM methods on different datasets.
[0178] This embodiment was conducted in a PyTorch and HuggingFace-based experimental environment:
[0179] Datasets and basic configuration: The experiments selected two widely used standard benchmark datasets:
[0180] CoDEx-S contains 2,034 entities and 42 relations, with a training set of 32,888 samples, representing a medium-sized graph.
[0181] FB15K-237N: A more challenging dataset, with reverse relationships removed to avoid data leakage. It contains 13,104 entities and 93 relationships, and is used to test complex reasoning capabilities.
[0182] Model parameters: The base model uses LLaMA-3-8B-Instruct. Structure-aware prefix length. Set to 12, structural embedding dimension Set to 64. LoRA fine-tuning rank , Dynamic equilibrium parameters .
[0183] Evaluation metrics: Accuracy (Acc) and F1-score (F1) are the main evaluation metrics to comprehensively measure the accuracy and robustness of the model's predictions.
[0184] Baseline Algorithm Comparison: To verify the technical effectiveness of this invention, the following three representative methods were selected as baselines for comparison:
[0185] Traditional geometric embedding methods:
[0186] TransE: Referencing "Translating embeddings for modeling multi-relational data" proposed by Bordes et al. in 2013, published at NEURIPS 2013 (Neural Information Processing Systems Conference), this method is based on the translation assumption and is a classic knowledge graph embedding model.
[0187] RotatE: Referencing the paper "Rotate: Knowledge graph embedding by relational rotation in complex space" by Sun et al., published at ICLR 2019 (the 7th International Conference on Learning Representations), this method models triples in complex space through relational rotation and excels at handling symmetric and antisymmetric relations.
[0188] PLM-based methods:
[0189] KG-BERT: Based on the paper "Kg-bert: BERT for knowledge graph completion" proposed by Yao et al. in 2019, it is a pioneering work in introducing pre-trained language models into knowledge graph tasks. This method treats triple classification as a sequence pair classification task and utilizes BERT's bidirectional attention mechanism to capture semantics.
[0190] Large Language Model-based Methods:
[0191] KoPA: Referencing "Making large language models perform better in knowledge graph completion" proposed by Zhang et al. in 2024, published at ACM Multimedia 2024, this method utilizes a structure-aware adapter to enhance the graph awareness capabilities of LLMs.
[0192] SAT: Referencing the paper "Enhancing large language model for knowledge graph completion via structure-aware alignment-tuning" proposed by Liu et al. in 2025, published at EMNLP2025 (Empirical Methods in Natural Language Processing 2025), this method, through a structure-aware alignment fine-tuning strategy, is one of the state-of-the-art (SOTA) baseline methods.
[0193] The experimental results and analysis are as follows:
[0194] Refer to Table 1: Performance comparison of different methods on the CoDEx-S and FB15K-237N datasets;
[0195]
[0196] Table 1 presents the performance comparison results of different categories of methods on the CoDEx-S and FB15K-237N knowledge graph completion benchmark datasets. The evaluation metrics include accuracy (Acc) and F1 score (F1), which are used to comprehensively reflect the accuracy and stability of the model in determining the authenticity of triples.
[0197] From a model classification perspective, traditional embedding methods (such as TransE and RotatE) generally exhibit low performance, especially on the complex and sparsely structured FB15K-237N dataset, where both accuracy and F1 scores are low, indicating that relying solely on geometric embeddings is insufficient to characterize complex relational structures. Methods based on pre-trained language models (KG-BERT) achieve some improvement on the CoDEx-S dataset, but their accuracy drops significantly on FB15K-237N, reflecting that textual semantic modeling alone is insufficient to adapt to graph scenarios with stronger structural constraints and greater co-occurrence interference.
[0198] In large model-based methods, KoPA (2024) and SAT (2025) achieved significant improvements over the aforementioned methods by introducing a structure-aware mechanism, demonstrating that introducing graph structure information within a large model framework can effectively improve completion performance. However, these methods still mainly focus on structure enhancement or alignment, and have not explicitly addressed the issues of statistical co-occurrence bias and structural confusion from a causal perspective. Therefore, there is still room for improvement in performance on complex datasets.
[0199] In comparison, the method of this invention achieves the highest Acc and F1 scores on both datasets. Specifically, on the CoDEx-S dataset, the accuracy reaches 87.92% and the F1 score reaches 88.84%; on the more structurally complex and more challenging FB15K-237N dataset, the accuracy and F1 score reach 84.74% and 84.82%, respectively, both outperforming existing state-of-the-art large-model methods. These results demonstrate that this invention, through structured mediator variable construction, structure-guided prefix injection, dual-path inference, and a gradient-aware dynamic loss balancing mechanism, can effectively suppress spurious correlation inference caused by statistical co-occurrence while maintaining semantic modeling capabilities.
[0200] In summary, the experimental results fully verify the effectiveness of the technical solution of this invention in knowledge graph completion tasks. In particular, in scenarios with high confusion and a high proportion of long-tail relationships, it can achieve more stable and reliable reasoning performance, demonstrating the significant technical effect and substantial progress of the causal guidance and structured reasoning method compared with the prior art.
[0201] It should be noted that ablation experiments were conducted to verify the independent contribution of each innovative component in this invention.
[0202] Refer to Table 2: Results of ablation experiments on core components;
[0203]
[0204] Table 2 compares the performance of the complete model of this invention and various model variants after removing key technical features on the CoDEx-S and FB15K-237N datasets, and provides corresponding conclusions and analyses based on the experimental results to verify the necessity and synergistic effect of the technical solution of this invention.
[0205] First, our method (complete model) achieves state-of-the-art results on both datasets, demonstrating that structured mediator variables, structured guided prefixes, dual-path inference, and gradient-aware dynamic loss balancing mechanisms can work together effectively. While ensuring semantic modeling capabilities, it significantly improves structural consistency and debiased inference capabilities, thus verifying the effectiveness of the overall technical solution.
[0206] The model performance showed the largest drop after removing the structure-aware prefix (without the structure-aware prefix), especially on the more structurally complex FB15K-237N dataset. This indicates that if structured mediator variables are not injected into the input sequence of large models as continuous vector prefixes, large models still have difficulty perceiving the topological logic of the graph and are prone to regressing to a reasoning mode that relies on text co-occurrence. This verifies the key role of this application in overcoming the structural blindness problem of large models.
[0207] When only the associated path is retained and the intervention path is removed (without the intervention path, only the associated path), the model performance drops significantly. The conclusion shows that the model has the problem of overfitting statistical associations, indicating that relying solely on supervised learning and observation distribution modeling can easily amplify spurious correlations and make it difficult to achieve causal debiased inference. This result directly proves the necessity of the "intervention path sub-model" in this application in suppressing statistical co-occurrence bias.
[0208] Conversely, when only the intervention path is retained and the association path is removed (without the association path, only the intervention path), the model also shows a performance degradation and a slower convergence speed. This indicates that without basic statistical modeling capabilities, the model has difficulty learning basic semantic patterns quickly, which verifies the rationality of the design of the "dual-path reasoning model" in this application through the complementary and synergistic interaction of the association path and the intervention path.
[0209] Furthermore, when the dynamic loss balancing mechanism is removed (without dynamic loss balancing), although the model performance is better than the variant with partial structure removal, it is still significantly lower than the complete model. The conclusion also indicates that gradient conflicts cannot be effectively mitigated during training, affecting the final accuracy. This result demonstrates that the "gradient-aware dynamic loss balancing mechanism" proposed in this application has significant technical effects on coordinating the optimization objectives of associated and intervention paths and ensuring training stability.
[0210] In summary, the ablation experiment results show that the various technical features of this invention are not simply superimposed, but rather form a close cooperation in terms of structure guidance, causal bias correction, and dynamic optimization. The absence of any single key feature will significantly weaken the model performance, thus fully verifying the integrity, necessity, and substantial improvement effect of this method compared with the prior art.
[0211] In this embodiment, a detailed description is provided in conjunction with the personalized learning path recommendation scenario.
[0212] Scenario Background: A precise subject knowledge graph is the foundation for intelligent education platforms to complete personalized recommendations. Given that the entities in the graph are "knowledge points" and the relationships are "predecessor dependencies", it is necessary to fill in the missing dependency links between knowledge points in the system to generate a complete and feasible learning path.
[0213] Technical issue: In a vast amount of educational materials, "deep learning" and "calculus" often co-occur frequently in the same paragraph. Traditional large-scale models are misled by this statistical regularity. In such cases, traditional large-scale models can easily make incorrect inferences due to the illusion caused by statistical correlation.
[0214] Implementation process of this invention:
[0215] Input construction: The system inputs the query triples.
[0216] Structural feature injection: Injecting the topological features of the subject graph of knowledge points (such as connectivity index) directional characteristics ), encoding converted into structured mediator variables .
[0217] Causal biased reasoning: structured mediator variables By introducing directed graph structure constraints, high confidence scores obtained solely from text co-occurrence are suppressed, and the model is forced to focus on unidirectional transitive logic.
[0218] Comparison of inference performance: To visually demonstrate the beneficial effects of the present invention, Table 3 shows the differences between the method of the present invention (CaReKGC) and the traditional large model after judging the knowledge points "deep learning" and "calculus" which have strong text co-occurrence interference.
[0219] Refer to Table 3: Comparison of the effects of knowledge point pre-relationship reasoning in educational scenarios;
[0220]
[0221] Table 3 selects several representative input query triples, compares the prediction results of Ground Truth, Vanilla LLM, and the method of this invention, and provides a difference analysis to intuitively demonstrate the differences in reasoning performance of different methods in scenarios with complex semantic co-occurrence and structural constraint conflicts.
[0222] In the first type of example, the input query triple is "deep learning—predecessor dependency—calculus," but the actual logical relationship is not valid. Traditional large-scale models are easily influenced by statistical co-occurrence due to the high frequency of co-occurrence of "deep learning" and "calculus" in a large amount of text, misjudging them as having a predecessor relationship. The method of this invention explicitly introduces graph topological constraints before inference by using structured mediator variables and structured guiding prefixes. This identifies the absence of a reverse path from "deep learning" to "calculus" in the knowledge graph and suppresses the erroneous influence of statistical co-occurrence through causal debiasing inference, thereby obtaining prediction results consistent with the true logic.
[0223] In the second type of example, the input query triple is "calculus—predecessor dependency—deep learning," and its true logical relationship is true. Both traditional large models and the method of this invention can give correct predictions, but the method of this invention, in this scenario, not only relies on textual semantic judgment, but also combines the explicitly existing topological connections in the graph, so that the prediction result is further verified at the structural level, demonstrating the stability and interpretability of the reasoning process.
[0224] In the third example, the input query triple is "linear algebra—predecessor dependency—deep learning." This relationship holds true in the real-world graph but is rarely mentioned directly in the text corpus, making it a typical long-tail relationship. Traditional large-scale models, due to their over-reliance on high-frequency co-occurrence information, neglect this implicit structural relationship, leading to prediction errors. The method in this invention, through intervention paths in the dual-path inference mechanism and a weight adjustment strategy based on category distribution awareness, increases attention to low-frequency relationships and sparse structural patterns, ultimately successfully completing the missing relationship.
[0225] In summary, this comparative analysis shows that traditional large models are easily affected by text co-occurrence frequency and corpus distribution bias in knowledge graph completion tasks, resulting in logical inversion or long-tail omissions. In contrast, this invention, through the construction of structured mediator variables, structure-guided prefix injection, dual-path causal reasoning, and dynamic loss balancing mechanism, can effectively restore the true structural logic of knowledge graphs under complex co-occurrence interference environments, significantly improving the accuracy, stability, and causal consistency of reasoning results.
[0226] Please see Figure 3 This application also provides a causal-guided large-scale model knowledge graph completion system, the system comprising:
[0227] The acquisition module is used to acquire the target knowledge graph and the input triples to be completed;
[0228] The feature extraction module is used to perform structured analysis on the relations in the input triples based on the target knowledge graph, and extract key topological feature vectors.
[0229] The first building module is used to construct structured mediator variables based on key topological feature vectors;
[0230] The structure-guided prefix generation module is used to map structured mediation variables into structure-guided prefixes in the form of continuous vectors, and inject the structure-guided prefixes into the input sequence of the large model to generate a structure-guided large model input representation;
[0231] The second building module is used to construct a dual-path inference model based on the input representation of the large model;
[0232] The inference prediction module is used to generate inference prediction results for input triples based on a dual-path inference model.
[0233] The optimization module is used to dynamically adjust the corresponding loss weights based on the inference prediction results of the input triples using a gradient-aware dynamic loss balancing mechanism.
[0234] The results output module is used to output the knowledge graph completion results of the input triples based on the inference prediction results adjusted by dynamic weights.
[0235] It is understood that the content of the above method embodiments is applicable to this system embodiment. The specific functions implemented in this system embodiment are the same as those in the above method embodiments, and the beneficial effects achieved are also the same as those achieved in the above method embodiments.
[0236] This application also provides an electronic device, which includes a memory and a processor. The memory stores a computer program, and the processor executes the computer program to implement the above-described method. This electronic device can be any smart terminal, including tablet computers, in-vehicle computers, etc.
[0237] It is understood that the content of the above method embodiments is applicable to this device embodiment. The specific functions implemented by this device embodiment are the same as those of the above method embodiments, and the beneficial effects achieved are also the same as those achieved by the above method embodiments.
[0238] This application also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described method.
[0239] It is understood that the content of the above method embodiments is applicable to this storage medium embodiment. The specific functions implemented in this storage medium embodiment are the same as those in the above method embodiments, and the beneficial effects achieved are also the same as those achieved in the above method embodiments.
[0240] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the above-described method.
[0241] It is understood that the content of the above method embodiments is applicable to the embodiments of this program product. The specific functions implemented by the embodiments of this program product are the same as those of the above method embodiments, and the beneficial effects achieved are also the same as those achieved by the above method embodiments.
[0242] Memory, as a non-transitory computer-readable storage medium, can be used to store non-transitory software programs and non-transitory computer-executable programs. Furthermore, memory may include high-speed random access memory, and may also include non-transitory memory, such as at least one disk storage device, flash memory device, or other non-transitory solid-state storage device. In some embodiments, memory may optionally include memory remotely located relative to the processor, and these remote memories can be connected to the processor via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.
[0243] This application provides a method and system for large-scale knowledge graph completion based on causal guidance. The scheme acquires the target knowledge graph and the input triples to be completed, performs structured analysis on the relationships within the input triples, extracts key topological features, and constructs structured mediator variables. This explicitly expresses the potential causal dependencies between entities and relationships, avoiding inference biases that rely solely on statistical correlation. The structured mediator variables are mapped to structure-guided prefixes and injected into the large-scale model's input sequence, achieving structural constraints and causal guidance for the large-scale model's inference process, thereby enhancing the model's generalization ability in complex relationships, long-tail relationships, and sparse sample scenarios. By constructing a dual-path inference model, the structural causal path and semantic inference path are co-modeled, allowing the model to fully utilize the structural information of the knowledge graph while maintaining the expressive power of the large-scale model, improving the consistency and robustness of the inference results. By introducing a gradient-aware dynamic loss balancing mechanism, the weights of different loss terms are adaptively adjusted based on the gradient feedback of the inference prediction results, effectively alleviating the optimization imbalance problem that easily occurs during multi-objective training and promoting stable model convergence. This invention can significantly improve the overall performance of knowledge graph completion while ensuring the controllability of reasoning, and has good engineering practical value.
[0244] The embodiments described in this application are for the purpose of more clearly illustrating the technical solutions of the embodiments of this application, and do not constitute a limitation on the technical solutions provided by the embodiments of this application. As those skilled in the art will know, with the evolution of technology and the emergence of new application scenarios, the technical solutions provided by the embodiments of this application are also applicable to similar technical problems.
[0245] Those skilled in the art will understand that the technical solutions shown in the figures do not constitute a limitation on the embodiments of this application, and may include more or fewer steps than shown, or combine certain steps, or different steps.
[0246] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.
[0247] Those skilled in the art will understand that all or some of the steps in the methods disclosed above, as well as the functional modules / units in the systems and devices, can be implemented as software, firmware, hardware, or suitable combinations thereof.
[0248] The terms “first,” “second,” “third,” “fourth,” etc. (if present) in the specification and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms “comprising” and “having,” and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0249] The preferred embodiments of the present application have been described above with reference to the accompanying drawings, but this does not limit the scope of the claims of the present application. Any modifications, equivalent substitutions, and improvements made by those skilled in the art without departing from the scope and substance of the embodiments of the present application shall be within the scope of the claims of the present application.
Claims
1. A method for causal-guided large model knowledge graph completion, characterized in that, The method includes the following steps: Obtain the target knowledge graph and the input triples to be completed; the input triples include a head entity, a tail entity, and a relation; Based on the target knowledge graph, structured analysis processing is performed on the relations in the input triples to extract key topological feature vectors; Based on the key topological feature vectors, construct structured mediator variables; The structured mediation variables are mapped to structured guide prefixes in the form of continuous vectors, and the structured guide prefixes are injected into the input sequence of the large model to generate a structured large model input representation; Based on the input representation of the large model, a dual-path reasoning model is constructed; Based on the dual-path inference model, inference prediction results are generated for the input triples; Based on the inference prediction results of the input triples, a gradient-aware dynamic loss balancing mechanism is adopted to dynamically adjust the corresponding loss weights. Based on the inference prediction results adjusted by dynamic weights, the knowledge graph completion result of the input triple is output; The formula for the structured mediator variable is as follows: ; wherein, denotes the final generated structured intermediate variable embedding, denotes a predefined learnable base prefix matrix for relation r; denotes a projection matrix with dimension ; and denote the embedding vectors of the input triple head entity and tail entity, respectively, denotes the global knowledge embedding of the large language model, denotes a nonlinear activation function, and || denotes a vector concatenation operation, denotes a bias vector of the projection layer; denotes a key topological feature vector; The step of mapping the structured mediation variables to structure-guided prefixes in the form of continuous vectors, and injecting the structure-guided prefixes into the input sequence of the large model to generate a structure-guided large model input representation, includes: The structured mediator variables are subjected to vector space projection processing, which maps the structured mediator variables to a continuous vector representation consistent with the dimension of the large model space, to obtain the structure-guided prefix vector; Based on the text embedding sequence corresponding to the structure-guided prefix vector and the input triple, a prefix concatenation operation is performed on the sequence dimension to generate an input embedding sequence that integrates structural information. The input embedding sequence is input into the large model, so that the structure-guided prefix vector participates in multi-layer self-attention operations as a key vector and numerical vector in attention calculation; Based on the self-attention operation results, a large model input representation containing structural constraint information is obtained.
2. The method according to claim 1, characterized in that, The step of performing structured analysis on the relations in the input triples based on the target knowledge graph to extract key topological feature vectors includes: Based on the target knowledge graph, the frequency of occurrence of relations in the input triples is counted, and the occurrence frequency is normalized to obtain relation frequency features. Based on the head and tail entities connected by the relation in the input triplet, the tightness of the entity connection is calculated to obtain the connectivity feature; Based on the forward and backward connection distribution of the relations in the input triples in the target knowledge graph, the relation symmetry index is calculated to obtain the symmetry features; Based on the node degree distribution of relational entities in the input triplet, the relation confusion index is calculated to obtain potential confusion features. The relationship frequency feature, the connectivity feature, the symmetry feature, and the potential confusion feature are combined to form a key topological feature vector.
3. The method according to claim 1, characterized in that, The dual-path reasoning model includes an association path sub-model and an intervention path sub-model.
4. The method according to claim 3, characterized in that, The associated path sub-model includes: Based on the input representation of the large model, conditional probability modeling is performed on the input triples to obtain the predicted probability of the associated path. Based on the predicted probability of the associated path and the true label corresponding to the input triple, an associated path loss function is constructed; the associated path loss function is used to characterize the fitting error of the large model to the true value of the triple under the observation distribution; During the training of the associated path sub-model, backpropagation is performed to update the parameters of the large model based on the associated path loss function.
5. The method according to claim 3, characterized in that, The intervention path sub-model includes: Based on the input representation of the large model, biased inference modeling is performed on the input triples to obtain the predicted probability of the intervention path. Based on the historical reliability index of the corresponding relationship type of the input triplet and the distribution characteristics of the relationship category, an intervention weight coefficient is constructed; Based on the intervention weight coefficients, the loss terms corresponding to the predicted probabilities of the intervention paths are weighted to form a weighted intervention path loss function; During the training of the intervention path sub-model, the parameters of the large model are updated by backpropagation based on the weighted intervention path loss function.
6. The method according to claim 5, characterized in that, The formula for the weighted intervention path loss function is as follows: ; in, The value represents the weighted intervention path loss function; N represents the total number of samples participating in the loss calculation in the current training batch; i represents the sample index; Indicates the first Intervention weight coefficients corresponding to each sample; Indicates the first The true labels of the input triples; This indicates the intervention path for the first... The predicted probability of the intervention path given by the input triplet; and These represent the log-likelihood terms for the prediction results of positive and negative samples, respectively.
7. The method according to claim 1, characterized in that, The inference prediction result based on the input triplet employs a gradient-aware dynamic loss balancing mechanism to dynamically adjust the corresponding loss weights, including: Based on the inference prediction results of the input triples, the gradient magnitude of the dual-path inference model with respect to the structured mediator variables is calculated; A gradient conflict metric is constructed based on the gradient magnitude. When the gradient conflict metric exceeds a preset threshold, the loss weights corresponding to the intervention path loss function are adaptively adjusted based on the gradient-aware dynamic loss balancing mechanism. Based on the adjusted dual-path inference model, a joint optimization objective function is constructed. The parameters of the large model are updated by backpropagation based on the joint optimization objective function.
8. A large-scale knowledge graph completion system based on causal guidance, characterized in that, The system is applied to the method as described in any one of claims 1-7, the system comprising: The acquisition module is used to acquire the target knowledge graph and the input triples to be completed; The feature extraction module is used to perform structured analysis processing on the relations in the input triples based on the target knowledge graph, and extract key topological feature vectors. The first construction module is used to construct structured mediator variables based on the key topological feature vectors; The structure-guided prefix generation module is used to map the structured mediation variables into structure-guided prefixes in the form of continuous vectors, and inject the structure-guided prefixes into the input sequence of the large model to generate a structure-guided large model input representation; The second construction module is used to construct a dual-path inference model based on the input representation of the large model; The inference prediction module is used to generate inference prediction results for the input triples based on the dual-path inference model. The optimization module is used to dynamically adjust the corresponding loss weights based on the inference prediction results of the input triples using a gradient-aware dynamic loss balancing mechanism. The result output module is used to output the knowledge graph completion result of the input triple based on the inference prediction result after dynamic weight adjustment.