Zero-shot graph learning method based on large language model
By sampling neighborhood subgraphs from graph data and using structured prompt templates for multi-stage inference instructions, combined with reinforcement learning to optimize large language models, the problems of zero-shot transfer and cross-domain adaptation in graph learning are solved, achieving efficient and interpretable graph task processing.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- BEIHANG UNIV
- Filing Date
- 2026-03-24
- Publication Date
- 2026-06-23
Smart Images

Figure CN122264017A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of artificial intelligence and machine learning. More specifically, this invention relates to a zero-shot graph learning method based on a large language model. Background Technology
[0002] Graph structure data is widely used in many practical application scenarios such as social networks, knowledge graphs, molecular structures, citation networks, and e-commerce recommendation systems. The corresponding graph tasks cover various types such as node classification, link prediction, edge classification, and graph classification. The core requirement of these tasks is to achieve accurate reasoning and prediction based on the node attributes, edge relationships, and topological structure of the graph.
[0003] In traditional graph learning methods, Graph Neural Networks (GNNs) are the mainstream technology. They aggregate neighborhood node information through message passing mechanisms and exhibit good performance in supervised training scenarios with sufficient labeled data. However, GNNs have significant limitations: their output layer structure is fixed and highly dependent on a specific label space. When faced with out-of-distribution tasks, new category labels, or cross-domain graph data, the model must be retrained or significantly fine-tuned, making it difficult to achieve true zero-shot transfer learning without task-specific training. This severely limits their application in open-world scenarios.
[0004] In recent years, Large Language Models (LLMs) have begun to be applied to graph processing tasks due to their powerful semantic understanding and text generation capabilities. A common approach is to linearize the graph structure into a text sequence and then directly input it into the LLM for prediction. However, this type of method fails to fully consider the topological characteristics of the graph and lacks the necessary structural inductive bias, resulting in poor performance in graph tasks that require complex relational reasoning (such as link prediction and cross-domain graph classification), and it cannot effectively capture the complex dependencies between nodes.
[0005] To overcome these shortcomings, existing technologies have proposed various improved schemes for fusing LLM and GNN: for example, using LLM to generate node description text as input features for GNN, or injecting the structural features encoded by GNN into LLM for joint modeling through cross-modal projection. However, these schemes still rely on GNN components, and GNN needs to undertake feature extraction or part of the prediction task, which not only increases the computational overhead and deployment complexity of the model, but also requires adjusting the GNN structure or realigning modal representations when transferring between tasks and domains, making it impossible to achieve the goal of completely training-free zero-shot inference.
[0006] Therefore, it is necessary to design a technical solution that can overcome the above-mentioned defects. Summary of the Invention
[0007] One objective of this invention is to provide a zero-shot graph learning method based on a large language model, which abandons the dependence on graph neural networks and completes graph tasks solely through the text reasoning capabilities of the large language model, thereby significantly reducing deployment complexity and computational overhead.
[0008] To achieve these objectives and other advantages of the present invention, according to one aspect of the present invention, a zero-shot graph learning method based on a large language model is provided, comprising: S1: sampling neighborhood subgraphs of the graph structure data to be processed, and converting the node attributes and edge relationships within the sampled subgraphs into natural language descriptions to generate graph query text; S2: constructing a structured prompt template containing multi-stage reasoning instructions based on the graph query text, wherein the prompt template instructs the large language model to sequentially perform topological structure analysis, semantic attribute interpretation, multiple candidate answer enumeration, and deep re-evaluation before generating the final answer; S3: constructing a graph reasoning training dataset based on the prompt template; 4. Using a graph reasoning training dataset, fine-tune the basic large language model with full parameters, enabling the large language model to learn to generate reasoning chains following structured prompt templates; S5. Based on the fine-tuned large language model, optimize it using a reinforcement learning algorithm based on group relative advantage, where the reward function assigns different reward values based on the correctness of the model's output answer, whether the correct answer appears in the candidates listed in the deep re-evaluation stage, and the compliance of the output format; S6. For a new graph task to be reasoned, repeat S1 to S2 to generate the corresponding prompt input, and input it into the large language model optimized by S4 and S5, directly outputting the answer containing the reasoning process and the final prediction.
[0009] Furthermore, graph structure data includes directed graphs, undirected graphs, heterogeneous graphs, and knowledge graphs. The task types corresponding to the graph structure data being processed include node classification, link prediction, edge classification, and graph classification.
[0010] Furthermore, the neighborhood subgraph sampling is specifically h-hop neighborhood sampling, where h is an integer greater than 0; before generating the graph query text, the original text attributes of the nodes or edges are automatically summarized.
[0011] Furthermore, the reward function is configured as follows: a first reward value is assigned when the final answer is correct; a second reward value lower than the first reward value is assigned when the final answer is incorrect but the correct answer appears in the candidates listed in the deep re-evaluation stage; a third reward value lower than the second reward value is assigned when only the output format meets the requirements but the content is invalid; and no reward value is assigned in other cases.
[0012] Furthermore, the method for constructing the graph reasoning training dataset includes: acquiring original graph data samples from multiple domains and generating corresponding graph query texts; inputting the graph query texts into a large language model to generate explicit reasoning trajectories containing multi-stage reasoning instructions and corresponding answers, forming initial training samples; filtering the initial training samples based on information sufficiency, answer validity, and logical coherence, retaining samples that meet the preset logical coherence and answer validity to constitute the graph reasoning training dataset.
[0013] Furthermore, the deep re-evaluation includes: performing structural consistency evaluation and semantic consistency evaluation on each candidate answer generated during the multi-candidate answer enumeration stage; wherein, the structural consistency evaluation is based on the topological connection relationship of the subgraph to determine whether the candidate answer matches the structural pattern of the existing nodes or edges in the graph; the semantic consistency evaluation is based on the attribute semantics of nodes and edges to determine the semantic compatibility of the candidate answer with the existing information in the graph; based on the results of the structural consistency evaluation and semantic consistency evaluation, each candidate answer is comprehensively scored and ranked, and the final selected answer and its reasons are output.
[0014] Furthermore, in S4, a phased progressive training strategy is adopted, dividing the graph reasoning training dataset into three stages and inputting them into the model for training sequentially. In the first stage, a simplified prompt template is used for training, which only includes two reasoning stages: topological structure analysis and semantic attribute interpretation, so that the large language model can initially grasp the structural and semantic information of the graph data. In the second stage, training is switched to the complete structured prompt template, and supervision of the output of intermediate stages of the reasoning chain is introduced. The cross-entropy loss between the text generated by the large language model at each reasoning stage and the corresponding stage text labeled in the dataset is calculated. In the third stage, the complete structured prompt template is retained, while the graph query text in the training samples is subjected to local information random masking or semantic perturbation to enhance the reasoning robustness of the large language model under incomplete information or noise conditions. In each training stage, the comprehensive loss function, including the loss of the final answer and the loss of intermediate reasoning stages, is minimized to update the full parameters of the large language model.
[0015] Further, S5 includes: S5.1: Dynamically constructing graph query batches with multiple difficulty levels, each batch containing a set of graph query texts, wherein the graph structure complexity or semantic ambiguity corresponding to each query is pre-classified; S5.2: For each batch of queries, the finely tuned large language model generates a corresponding set of responses; S5.3: Calculating the base reward value for each response based on the reward function; S5.4: Introducing a negative reward mechanism, applying a negative penalty term to the base reward value for responses that generate incorrect final answers and whose reasoning chains exhibit logical fallacies or completely omit the correct answer during the deep re-evaluation stage; S5.5: Weighting the reward values obtained in steps S5.3 and S5.4 according to the preset difficulty level of the current batch, so that the effective progress of the model on complex tasks receives higher rewards; S5.6: Calculating the policy gradient and updating the parameters of the large language model based on the weighted final reward value through group relative advantage estimation.
[0016] Furthermore, it also includes S7, which includes: S7.1: Extracting all candidate answers and their evaluation reasons output by the large language model in the deep re-evaluation stage, and calculating the internal confidence score of each candidate answer based on the coverage and logical coherence of structured and semantic keywords in the reasons; S7.2: Starting from the target node or edge, performing a random walk with restart on its neighborhood subgraph obtained by sampling in S1, and generating a basic category probability distribution independent of the model by statistically analyzing the occurrence frequency of each category node in the walk path; S7.3: Comparing the final answer category predicted by the large language model with the category with the highest probability in the basic probability distribution: if they match, outputting the answer as the final result.
[0017] Furthermore, if there is a discrepancy, cross-source validation is performed: the top K candidate answer categories with the highest internal confidence scores in the large language model are selected, and their intersection is calculated with the top K categories with the highest probabilities in the basic probability distribution; if the intersection is not empty, the answer with the highest internal confidence score is selected from the intersection as the final output; if the intersection is empty, the internal confidence score distribution and the basic probability distribution are weighted and fused, where the fusion weight is dynamically determined based on the topological clustering coefficient and semantic description length of the current subgraph, and the category with the highest probability after fusion is output as the calibrated final answer.
[0018] The present invention has at least the following beneficial effects: This invention abandons reliance on graph neural networks, completing graph tasks solely through the text reasoning capabilities of a large language model, significantly reducing deployment complexity and computational overhead, and eliminating the need for additional feature encoding components. A structured explicit reasoning prompt template forces the model to sequentially perform four stages of reasoning, including topological analysis and semantic interpretation, effectively integrating both structural and semantic information of the graph and improving the reliability of reasoning for complex graph tasks. Combining group relative advantage reinforcement learning with a fine-grained reward function ensures both answer accuracy and the rationality of intermediate reasoning processes, making the output interpretable and facilitating the tracing of answer generation logic. Through subgraph textualization and a general reasoning framework design, it achieves extremely strong zero-shot generalization capabilities, directly handling unseen graph tasks and label spaces, exhibiting excellent cross-domain adaptability. The process is concise and efficient; no task-specific training is required during the reasoning stage, only textualization of the task to be predicted is needed to output the result, making it suitable for various graph reasoning scenarios in open worlds and possessing wide application value.
[0019] Other advantages, objectives and features of the present invention will become apparent in part from the following description, and in part from those skilled in the art through study and practice of the invention. Attached Figure Description
[0020] Figure 1 A flowchart of one embodiment of this application; Figure 2 This is a template diagram for the in-depth re-evaluation prompt of the present invention.
[0021] Figure 3 This is a template diagram of the reward function of the present invention. Detailed Implementation
[0022] The present invention will now be described in further detail so that those skilled in the art can implement it based on the description.
[0023] It should be understood that terms such as "having," "comprising," and "including" used in the embodiments of this application do not exclude the presence or addition of one or more other elements or combinations thereof. All directional indications (such as up, down, left, right, front, back, etc.) in the embodiments of this application are only used to explain the relative positional relationship and movement of components in a specific posture. If the specific posture changes, the directional indication will also change accordingly. When an element is referred to as "fixed to" or "set on" another element, it can be directly on the other element or may have an intervening element present. When an element is referred to as "connected to" another element, it can be directly connected to the other element or indirectly connected to the other element through an intervening element. Descriptions involving "first," "second," etc., in the embodiments of this application are for descriptive purposes only and should not be construed as indicating or implying their relative importance or implicitly specifying the number of indicated technical features. Therefore, a feature defined with "first" or "second" may explicitly or implicitly include at least one of those features.
[0024] It should be noted that the technical solutions of the various embodiments of this application can be combined with each other, but only if they are based on the ability of those skilled in the art to implement them. When the combination of technical solutions is contradictory or cannot be implemented, it should be considered that such combination of technical solutions does not exist and is not within the scope of protection claimed by this application.
[0025] like Figure 1 As shown, embodiments of this application provide a zero-shot graph learning method based on a large language model, including: S1: sampling neighborhood subgraphs of the graph structure data to be processed, and converting the node attributes and edge relationships within the sampled subgraphs into natural language descriptions to generate graph query text; S2: constructing a structured hint template containing multi-stage reasoning instructions based on the graph query text, wherein the hint template instructs the large language model to sequentially perform topological structure analysis, semantic attribute interpretation, multiple candidate answer enumeration, and deep re-evaluation before generating the final answer; S3: constructing a graph reasoning training dataset based on the hint template; S4: utilizing the graph reasoning training dataset... S1: Fine-tune the basic large language model with full parameters to enable it to learn to generate inference chains following structured prompt templates; S2: Based on the fine-tuned large language model, optimize it using a reinforcement learning algorithm based on group relative advantage. The reward function assigns different reward values based on the correctness of the model's output answer, whether the correct answer appears in the candidates listed in the deep re-evaluation stage, and the compliance of the output format; S3: For a new graph task to be reasoned, repeat S1 to S4 to generate the corresponding prompt input and input it into the large language model optimized by S4 and S5, directly outputting the answer containing the reasoning process and the final prediction.
[0026] For example, neighborhood subgraph sampling is performed on the graph structure data to be processed. A neighborhood subgraph refers to a local graph structure surrounding the target node or edge to be predicted, containing the nodes, edges, and attribute information of all related elements that are directly associated (1 hop) or indirectly associated (multi-hop). Subsequently, the node attributes and edge relationships within the sampled subgraph are converted into natural language descriptions. Node attributes can be text or text-readable information such as paper titles, authors, publication years, product categories, prices, and molecular structure strings like SMILES. Edge relationships can be statements that clearly indicate the association, such as "Node A (paper X) and node B (paper Y) have a citation relationship, and node A cites the core algorithm proposed by node B." The generated graph query text must fully present the node attributes, edge relationships, and topological association features of the subgraph. Its core function is to transform unstructured graph data into a text form that can be directly understood and processed by a large language model, building a bridge between graph data and model inference. Based on the query text of the graph, a structured prompt template containing multi-stage reasoning instructions is constructed. This template is a pre-defined text format framework with a fixed logical order, specifically designed to guide large language models to think according to the reasoning logic unique to graph tasks. Topological structure analysis involves systematically analyzing structural features such as the connection methods, connected components, node degrees, and shortest paths between nodes. For example, target node X has 3 one-hop neighbors and 5 two-hop neighbors, forming a triangular connected structure with nodes Y and Z. This structure often exhibits strong correlation characteristics in similar tasks. Semantic attribute interpretation involves mining the core meaning, keyword associations, and domain semantics contained in the text attributes of nodes and edges. For example, the attribute keywords of node X are deep learning, image recognition, and CNN models, while the attribute keywords of node Y are computer vision. Image classification and image reasoning are highly semantically compatible, both belonging to the vision-related field. For multiple candidate answer listing, at least three possible answers must be provided with brief reasons, which must relate to both structural and semantic features. For example, "Candidate 1: Node X belongs to the computer vision category because its neighboring nodes are mostly related to the vision domain, and its topological structure matches the typical structure of this type of node; Candidate 2: Node X belongs to the machine learning category because its attributes contain deep learning keywords, belonging to the machine learning subfield; Candidate 3: Node X belongs to the artificial intelligence category because both computer vision and machine learning belong to the artificial intelligence field, representing a broader category classification." Deep re-evaluation involves a comprehensive comparative analysis of the structural matching degree, semantic compatibility, and logical rigor of each candidate answer, eliminating unreasonable candidates and clarifying the optimal selection criteria. Based on this prompt template, a graph reasoning training dataset is constructed. The dataset must include graph query text, corresponding multi-stage explicit reasoning trajectories, and clear standard answers. Its purpose is to provide supervised training samples for the large language model, allowing the model to master graph task reasoning methods by learning the reasoning logic in the samples.Using this graph inference training dataset, the basic large language model is fine-tuned with full parameter instructions. The basic large language model can be DeepSeek-R1-distilled-Qwen2.5-14B, which balances strong inference ability with moderate computational cost. Full parameter fine-tuning means updating all trainable parameters of the model, rather than just adjusting some layer parameters. During training, the learning rate can be 5e-5, the batch size is 32, and the training epochs are 20. The training objective is to maximize the joint probability of generating a complete inference chain and the correct answer. Specifically, the calculation method is to minimize the language modeling loss, that is, for each training sample, calculate the predicted probability of the model generating an inference chain and each token in the answer, take the logarithm, sum them, and then divide by the total number of tokens in the sample to get the average log probability. Finally, take the negative number as the single sample loss, and the average of the losses of all samples is the overall training loss. The model parameters are iteratively updated through the backpropagation algorithm, so that the model gradually learns to follow the structured prompt template to generate logically coherent inference chains. Based on the fine-tuned large language model, a reinforcement learning algorithm based on group relative advantage is used for optimization. The core logic of the group relative advantage algorithm is to group the responses generated by the model into batches, with each batch containing 8 different responses to the same graph query. The model strategy is updated by the relative merits of the responses within the group. The reward function assigns different reward values based on the correctness of the model's output answer, whether the correct answer appears in the candidates listed in the deep re-evaluation stage, and the compliance of the output format. A KL divergence constraint coefficient of 0.05 is introduced to avoid the inference logic from getting out of control due to excessive model update. The purpose of this optimization step is to further improve the logical rigor and answer accuracy of the model's inference chain, so that the model can not only generate the correct answer, but also output a reasonable intermediate inference process. For a new graph task to be reasoned about, the new graph task can be an unseen cross-domain task (such as a disease-drug association prediction task that crosses from an academic citation network to a biomedical knowledge graph) or an untouched label space task (such as a new rare disease category classification task). Repeat the graph query text generation steps and prompt template construction steps described above, and input the processed prompts into the large language model that has been fine-tuned by instructions and optimized by reinforcement learning. The model will directly output an answer that includes the complete reasoning process (covering four stages: topological structure analysis, semantic attribute interpretation, multiple candidate enumeration, and deep re-evaluation) and the final prediction result. The entire process does not require any additional task-specific training or other auxiliary models and is completed entirely by the model's own reasoning ability.
[0027] In existing technologies, traditional methods often rely on graph neural networks to process graph tasks, requiring extensive training with labeled data for specific tasks. When faced with new graph tasks, fine-tuning is necessary, and some solutions combining large language models lack targeted reasoning guidance, resulting in disjointed reasoning processes. This embodiment, however, does not rely on graph neural networks. Through subgraph textualization and structured prompt templates, it allows the large language model to fully exploit the structural and semantic information of the graph. After instruction fine-tuning and reinforcement learning optimization, it can directly process unseen new graph tasks, generating interpretable reasoning processes. This not only reduces deployment complexity but also improves zero-shot generalization ability, solving the problems of weak generalization and unreliable reasoning processes in existing technologies.
[0028] In another embodiment, the graph structure data includes directed graphs, undirected graphs, heterogeneous graphs, and knowledge graphs, and the task types corresponding to the processed graph structure data include node classification, link prediction, edge classification, and graph classification.
[0029] For example, graph structure data can include directed graphs, undirected graphs, heterogeneous graphs, and knowledge graphs. A directed graph refers to a graph structure where edges have a clear directional attribute and can only reflect unidirectional relationships; an undirected graph refers to a graph structure where edges do not have a directional attribute and can reflect bidirectional symmetrical relationships; a heterogeneous graph refers to a graph structure containing various types of nodes and edges; and a knowledge graph refers to a graph structure that stores entities, attributes, and relationships between entities in a structured form, such as the Baidu Encyclopedia knowledge graph. The task types corresponding to the processed graph structure data can include node classification, link prediction, edge classification, and graph classification. A node classification task refers to determining the preset category of a target node based on the attributes of nodes in the graph, the characteristics of neighboring nodes, and topological relationships. For example, in academic networks, this involves determining the category of a paper based on its title, keywords, and the categories of cited papers. A link prediction task refers to predicting whether there is a potential edge relationship between two unconnected nodes based on existing node relationships in the graph. For example, in e-commerce platforms, this involves predicting the user's link relationship based on their historical purchase records, browsing behavior, and product attributes. The task involves determining whether a purchase association will occur for a product that has not been viewed before. Edge classification involves identifying the type of existing edges in a graph and clarifying their association meaning. For example, in a knowledge graph, for the edge "Li Bai-and-Du Fu," it's necessary to determine whether it belongs to the category of friend, fellow poet, admirer, or teacher-student. Graph classification involves treating the entire graph as a whole and determining its category based on its topological structure, node attribute distribution, and edge relationship characteristics. For example, in the field of drug development, based on the atomic composition, chemical bond type, and topological structure of a molecular graph, it's necessary to determine whether the corresponding compound is an anticancer drug, antibiotic, vitamin, or anti-inflammatory drug. This comprehensive coverage of graph structure data and task types allows the method to adapt to various practical application scenarios in different fields, such as social network analysis, e-commerce recommendation system optimization, academic research classification, drug development assistance, and knowledge graph completion. It eliminates the need to modify the core reasoning logic for specific graph structures or task types, significantly improving the method's versatility and practical application value.
[0030] In another embodiment, neighborhood subgraph sampling is specifically h-hop neighborhood sampling, where h is an integer greater than 0; before generating graph query text, the original text attributes of nodes or edges are automatically summarized.
[0031] For example, neighborhood subgraph sampling is specifically h-hop neighborhood sampling, where h is an integer greater than 0. h can be 2 or 3. The core reason for choosing this range of values is that if h is too small (e.g., h=1), the sampled subgraph will contain insufficient association information and cannot support complex reasoning. If h is too large (e.g., h≥4), it will introduce a large number of redundant nodes and edges, increasing the difficulty of textualization and the processing burden of the model. h=2 is suitable for graph structures with high node density (e.g., social network graphs, where the average number of 1-hop neighbors per node is ≥10), and h=3 is suitable for graph structures with low node density (e.g., molecular structure graphs, where the average number of 1-hop neighbors per node is ≤5). The specific execution process of h-hop neighborhood sampling is as follows: Starting from the target node or edge to be predicted, a breadth-first search (BFS) algorithm is used to first traverse and collect all nodes and corresponding edges directly connected to the target node within a 1-hop range. Then, starting from the 1-hop node, the associated nodes and edges within a 2-hop range are traversed and collected, and so on, until the h-hop traversal is completed. During the traversal, the hop distance between each node and the target node, as well as the connection relationship between nodes, are recorded to ensure that the sampled subgraph can completely retain the core association structure of the target node or edge. The core function of this sampling method is to accurately capture the core information related to the target while strictly controlling the size of the subgraph to avoid data redundancy affecting the efficiency of subsequent processing. Before generating the graph query text, the original text attributes of the nodes or edges need to be automatically summarized. The original text attributes can be long academic paper abstracts (usually 1000-2000 words), detailed product descriptions (500-1500 words), detailed molecular structure descriptions, etc. If these long texts are directly input into a large language model, they may exceed the maximum context window of the model, resulting in the truncation of key information or the model's inability to process them completely. Automatic summarization can be achieved using large language models with strong text extraction capabilities, such as DeepSeek-V3. The process is as follows: First, input the original long text and the summarization command. The model will automatically identify key information such as core keywords, key conclusions, and core attributes in the text, remove redundant embellishments, repetitive expressions, and other irrelevant content, and then use coherent natural language to reorganize the key information into a concise summary text.
[0032] In another embodiment, see Figure 3 The reward function is configured as follows: when the final answer is correct, a first reward value is assigned; when the final answer is incorrect but the correct answer appears in the candidates listed in the deep re-evaluation stage, a second reward value lower than the first reward value is assigned; when only the output format meets the requirements but the content is invalid, a third reward value lower than the second reward value is assigned; and no reward value is assigned in other cases.
[0033] For example, the reward function is configured with a multi-tiered differentiated reward allocation mode. Its core design is to simultaneously consider the accuracy of the final answer, the rationality of the intermediate reasoning process, and the standardization of the output format, guiding the model to comprehensively improve its reasoning ability. When the model's final answer is completely consistent with the standard answer in the dataset, a first reward value is allocated. This first reward value can be set to 1, and it is the highest reward in the entire reward mechanism. Its core function is to directly incentivize the model to prioritize the correctness of the final answer, which is the core objective of graph reasoning tasks. When the model's final answer is inconsistent with the standard answer, but the standard answer clearly appears among the candidate answers listed in the deep re-evaluation stage, a second reward value lower than the first reward value is allocated. This second reward value can be set to 0.3. The design logic of this reward level is to affirm the partial rationality of the model in the intermediate reasoning process. Although the model has not ultimately selected the correct answer, it has already identified the possibility of the correct answer and included it in the evaluation. This reward guides the model to pay attention to the generation quality of multiple candidate answers, encourages the model to comprehensively consider all reasonable possibilities during the reasoning process, and provides direction for subsequent optimization. When the model output only fully conforms to the requirements of the structured prompt template in terms of format, i.e., strictly includes... <structure>Topology analysis within tags <semantic>The semantic attributes of nodes and edges are interpreted within the tags. <comprehensive>The tag should list at least three candidate answers and provide brief reasons. <rethink>Within each tag, a deep re-evaluation and comparison of each candidate answer is performed. For the four tags and their corresponding reasoning stage text, and if the final answer presentation format meets the requirements, but the reasoning content lacks logical coherence, is unrelated to the node attributes and edge relationships described in the graph query text, or the reasoning process is hollow and meaningless (e.g., merely repeating tag names without substantial analysis), a third reward value lower than the second reward value is assigned. The third reward value can be set to 0.01. The main purpose of this reward level is to guide the model to adhere to the preset output format specifications, cultivate the model's habit of outputting according to fixed reasoning logic, and avoid the inability to parse the reasoning process due to chaotic output formats, providing a unified format foundation for subsequent model optimization and result evaluation. In other cases, such as when the final answer is incorrect, the standard answer does not appear in the candidate answers, and the output format does not meet the requirements, no reward value is assigned (reward value is 0). This setting clearly informs the model that such reasoning behavior has no positive significance, avoids the model forming an undesirable tendency of invalid reasoning, and promotes the model to optimize towards "standard format, reasonable reasoning, and correct answer."
[0034] In existing technologies, reinforcement learning reward functions are mostly single-dimensional, focusing only on the correctness of the final answer while ignoring the intermediate reasoning process, resulting in sloppy model reasoning logic. This embodiment designs a multi-level, fine-grained reward function that emphasizes both the accuracy of the final answer and the intermediate reasoning process and output format. This guides the model to comprehensively improve its reasoning ability. Compared with existing technologies, the reward mechanism is more comprehensive and reasonable, effectively improving the logic of the model's reasoning chain and the standardization of its output.
[0035] In another embodiment, the method for constructing a graph reasoning training dataset includes: acquiring original graph data samples from multiple domains and generating corresponding graph query texts; inputting the graph query texts into a large language model to generate explicit reasoning trajectories containing multi-stage reasoning instructions and corresponding answers, forming initial training samples; performing information sufficiency filtering, answer validity filtering, and logical coherence filtering on the initial training samples, retaining samples that meet preset logical coherence and answer validity to constitute a graph reasoning training dataset.
[0036] For example, the method for constructing a graph reasoning training dataset includes the following specific steps: First, obtain original graph data samples from multiple domains. These domains cover various application scenarios such as citation networks, e-commerce platforms, knowledge graphs, molecular structures, and synthetic reasoning graphs. The original graph data samples can be selected from public datasets or actual business scenarios. For example, the Cora dataset can be selected for citation networks, the Amazon Products dataset for e-commerce platforms, and the FB15K237 dataset for knowledge graphs. This ensures that the samples can cover graph tasks at the node, edge, and graph levels, avoiding task type bias in the dataset. Then, according to the preset h-hop (h=2 or 3) sampling rule and text conversion method, subgraph extraction and text processing are performed on the target nodes or target edges of each original sample to generate corresponding graph query text. The graph query text must completely contain the node attributes, edge relationships, and topological association information of the subgraph, ensuring that the model can obtain all graph-related information required for reasoning through the text. Next, the generated graph query text is input into the large language model. This large language model needs to have strong logical reasoning ability and long text processing ability. You can choose DeepSeek-R1 or its distilled version. When inputting, there will be explicit reasoning instructions. The model will automatically generate an explicit reasoning trajectory including four stages: topological structure analysis, semantic attribute interpretation, multiple candidate answer enumeration and deep re-evaluation, based on the graph query text and reasoning instructions. At the same time, it will output the corresponding final answer to form the initial training sample. The initial training samples were then subjected to a three-level rigorous filtering process. The first level was information sufficiency filtering, the core criterion of which was to remove isolated nodes (without any neighboring nodes or edges) or subgraph samples with empty neighborhoods. Such samples lacked sufficient relational information to support effective inference by the model. During filtering, the number of nodes and edges in the subgraph was counted. If the number of nodes was less than 5 or the number of edges was less than 3, it was judged as insufficient information and removed. The second level was answer validity filtering, which compared the answers generated by the model with the real labels in the original data and removed samples whose answers did not match the real labels. Samples containing sensitive content (such as illegal expressions or discriminatory language) were also removed to ensure the accuracy and compliance of the dataset's answers. The third level was logical coherence filtering, which used a language model to logically score the reasoning text (a maximum score of 1.0, with a score ≥0.7 being considered passing). At the same time, a threshold for the length of the reasoning text was set (no less than 80 characters), and samples with reasoning text that were too short, lacked causal logic, or were contradictory were removed to ensure that the reasoning trajectory had a rigorous logical chain. Finally, samples that meet the preset criteria of logical coherence and answer validity are retained and organized into a standard format of "graph query text - explicit reasoning trajectory - standard answer". This constitutes the graph reasoning training dataset. The core function of this dataset is to provide high-quality training data with explicit reasoning annotations for fine-tuning instructions of large language models, helping the model master the reasoning logic and process unique to graph tasks.
[0037] In existing technologies, graph reasoning training datasets often rely on manual annotation, which is costly, inefficient, and lacks samples with explicit reasoning trajectories, thus failing to effectively support model reasoning training. This embodiment automates dataset construction through automatic subgraph sampling, reasoning trajectory generation, and three-level filtering. This reduces annotation costs while ensuring dataset quality, and for the first time provides samples containing explicit reasoning trajectories. Compared to existing technologies, this provides more efficient support for model training, driving performance improvements in large language models in the graph reasoning domain.
[0038] In another embodiment, see Figure 2 The deep re-evaluation includes: performing structural consistency evaluation and semantic consistency evaluation on each candidate answer generated in the multi-candidate answer enumeration stage; wherein, the structural consistency evaluation is based on the topological connection relationship of the subgraph to determine whether the candidate answer matches the structural pattern of the existing nodes or edges in the graph; the semantic consistency evaluation is based on the attribute semantics of nodes and edges to determine the semantic compatibility of the candidate answer with the existing information in the graph; based on the results of the structural consistency evaluation and semantic consistency evaluation, each candidate answer is comprehensively scored and ranked, and the final selected answer and its reasons are output.
[0039] For example, deep re-evaluation includes performing structural consistency evaluation and semantic consistency evaluation on each candidate answer generated in the multi-candidate answer enumeration stage. The two evaluation dimensions complement each other and jointly ensure the rationality of the candidate answers. The structural consistency assessment is based on the topological connectivity of the subgraph. The topological connectivity includes core indicators such as the degree of the node (the number of associated edges of the target node), the length of the connection path (the average number of hops from the target node to nodes of the same type), the distribution of neighboring node types (the proportion of each type of node within h hops of the target node), and the characteristics of connected components (the structural pattern of the connected subgraph where the target node is located). The assessment logic is to determine whether the category characteristics implied by the candidate answer match the actual structural pattern of the existing nodes or edges in the graph. For example, if the candidate answer believes that node X belongs to category A, firstly, the average degree of all nodes in category A (e.g., 8) and the actual degree of the target node X (e.g., 7) are calculated, and the degree difference is calculated (1). If the difference does not exceed the preset threshold (2), the degree feature is matched. Then, the average path length between nodes in category A (e.g., 2) and the average path length from the target node X to the existing nodes in category A (e.g., 2) are calculated. If the path length difference is less than 1, the path feature is matched. If the proportion of matching items is ≥80% when considering all structural indicators, the candidate answer is considered to have passed the structural consistency assessment. Semantic consistency assessment is based on the attribute semantics of nodes and edges. Attribute semantics includes core keywords in the text description, domain affiliation, and semantic association strength. The assessment logic is to determine whether the candidate answer is semantically compatible with the attribute information of existing nodes and edges in the graph. The specific execution process is as follows: extract the core keywords of the candidate answer category (e.g., the keywords for category B are "anti-cancer drugs, targeted therapy, small molecules"), extract the attribute keywords of the target node and neighboring nodes (e.g., the attribute keywords for target node X are "anti-cancer, targeted, small molecule compounds"), and calculate the cosine similarity of the two sets of keywords. If the similarity is higher than 0.6, it is considered semantically compatible. For example, if the candidate answer predicts that node B and node C have a "cooperative relationship", the attribute descriptions of nodes B and C need to be extracted (e.g., "Node B: Technology company, business scope: artificial intelligence algorithm research and development" "Node C: Internet company, business scope: AI product application") to determine whether there is a complementary or synergistic relationship between their business domains. If so, the prediction of a "cooperative relationship" is semantically supported.Based on the results of structural consistency assessment and semantic consistency assessment, a weighted summation method is used to comprehensively score each candidate answer. The weights can be dynamically adjusted according to the task type. In node classification and edge classification tasks, both structural consistency weight and semantic consistency weight can be selected as 0.5. In graph classification tasks, the structural consistency weight can be adjusted to 0.6 and the semantic consistency weight to 0.4. The comprehensive score is calculated as follows: Comprehensive score = Structural consistency score (0-1 points) × Structural weight + Semantic consistency score (0-1 points) × Semantic weight. The structural consistency score is obtained by weighted summation of the matching degree of each structural indicator, and the semantic consistency score is obtained by weighted summation of indicators such as keyword similarity and domain compatibility. Subsequently, all candidate answers are sorted in descending order based on the comprehensive score, and the candidate answer with the highest comprehensive score is selected as the final choice. At the same time, the supporting reasons for the structure and semantics of the corresponding answer are output. For example, the final selection of candidate answer 3 is based on the following reasons: "At the structural level, the target node and the corresponding category of candidate answer 3 have a matching degree of 85% in terms of node degree, path length and other indicators, and the topological structure is highly consistent; at the semantic level, the cosine similarity between the attribute keywords of the target node and the core keywords of the category of candidate answer 3 is 0.78, and the semantic relationship is close. Therefore, candidate answer 3 is determined to be the optimal solution." Through clear evaluation dimensions, scoring methods and reasoning, the rigor and traceability of the deep re-evaluation process are ensured.
[0040] In existing technologies, the re-evaluation of reasoning in large language models is often a general judgment, lacking detailed evaluation of structure and semantics, leading to unreliable re-evaluation results. This embodiment breaks down the re-evaluation into structural and semantic consistency evaluation. Through clear evaluation dimensions and scoring methods, the re-evaluation process becomes more rigorous and can more accurately select reasonable answers, improving the reliability and accuracy of reasoning results compared to existing technologies.
[0041] In another embodiment, in S4, a phased progressive training strategy is adopted, dividing the graph reasoning training dataset into three stages and inputting them into the model for training sequentially. In the first stage, a simplified prompt template is used for training, which only includes two reasoning stages: topological structure analysis and semantic attribute interpretation, so that the large language model can initially grasp the structural and semantic information of the graph data. In the second stage, the model is switched to the complete structured prompt template for training, and supervision of the output of the intermediate stages of the reasoning chain is introduced. The cross-entropy loss between the text generated by the large language model at each reasoning stage and the corresponding stage text labeled in the dataset is calculated. In the third stage, the complete structured prompt template is retained, and the graph query text in the training samples is subjected to local information random masking or semantic perturbation to enhance the reasoning robustness of the large language model under incomplete information or noise conditions. In each training stage, the comprehensive loss function, including the loss of the final answer and the loss of the intermediate reasoning stages, is minimized to update the full parameters of the large language model.
[0042] For example, when fine-tuning the basic large language model with full parameter instructions, a phased progressive training strategy is adopted. The core logic of this strategy is to guide the model to learn gradually from simple to complex and from basic to advanced, avoiding the model's inability to grasp the core reasoning logic due to facing complex tasks all at once. Specifically, the graph reasoning training dataset is divided into three stages and input into the model for training in sequence. In the first stage, a simplified prompt template is used for training. This simplified prompt template only includes two reasoning stages: topological structure analysis and semantic attribute interpretation. The stages of listing multiple candidate answers and deep re-evaluation are removed. The training data selects samples with relatively simple structure and semantics in the dataset (about 30% of the total dataset). Such samples have clear node attributes, simple edge relationships, and simple topological structure (e.g., number of nodes ≤ 20, edge density ≤ 0.3). The training rounds can be selected as 10 rounds, the learning rate is set to 3e-5, and the training batch size is 32. The core goal of this stage is to enable the large language model to initially master the structural feature recognition method and semantic information interpretation skills of graph data. For example, it can accurately identify the connection relationship between nodes, extract attribute keywords, and establish basic semantic associations, laying the foundation for learning in the subsequent complex reasoning stages. In the second stage, training is switched to a complete structured prompt template. The complete template includes four complete inference stages: topological structure analysis, semantic attribute interpretation, multiple candidate answer enumeration, and deep re-evaluation. Supervision of the outputs at intermediate stages of the inference chain is also introduced. This means that not only is the correctness of the final answer considered, but also the output text of each inference stage is supervised during training. Specifically, word embeddings are performed on the text generated by the large language model at each inference stage and the corresponding stage text labeled in the dataset. The text is converted into a high-dimensional vector representation. The predicted probability distribution of each token in the model-generated text is calculated using the softmax function. Then, the negative log-likelihood value is calculated by comparing this distribution with the token distribution in the labeled text to obtain the cross-entropy loss for each inference stage. This stage can be trained for 15 rounds with a learning rate adjusted to 2e-5. Through this training stage, the model masters the complete inference process, improving the accuracy and logic of the outputs at each inference stage. In the third stage, the complete structured prompt template is retained, while the graph query text in the training samples is subjected to local information random masking or semantic perturbation. The proportion of local information random masking is controlled at 10%-15%, specifically by masking non-core keywords in node attributes and replacing them with the symbol "[MASK]". Semantic perturbation involves paraphrasing the edge relationship descriptions, but strictly preserving the core meaning. The training epochs in this stage can be selected as 8 epochs, with the learning rate set to 1e-5. The core objective is to enhance the inference robustness of the large language model under conditions of incomplete information or noise, and to simulate scenarios that may occur in real-world applications, such as missing node attributes and inconsistent edge relationship descriptions.In each training phase, the goal is to minimize the comprehensive loss function, which includes the loss of the final answer and the loss of the intermediate inference phase. The comprehensive loss function can be a weighted sum of the losses of each phase, with all weights set to 1. That is, comprehensive loss = loss of topology analysis phase + loss of semantic attribute interpretation phase + loss of multiple candidate answer enumeration phase + loss of deep re-evaluation phase + loss of final answer. The gradient of the loss function with respect to each parameter of the model is calculated through the backpropagation algorithm, and then the full parameters of the large language model are updated using stochastic gradient descent (SGD) or adaptive moment estimation (Adam) optimizer to ensure that the model can improve the corresponding inference ability in each training phase.
[0043] In existing technologies, model fine-tuning often employs single-stage training, lacking gradual guidance. This makes it difficult for the model to progressively master complex reasoning logic, and it also exhibits poor adaptability to noisy data. This embodiment adopts a phased, progressive training strategy, guiding the model's learning step-by-step from simple to complex. Simultaneously, through intermediate stage supervision and noise-perturbation training, the model's reasoning integrity and robustness are improved. Compared to existing technologies, the training process is more scientific and reasonable, enabling the model to more fully grasp graph reasoning capabilities.
[0044] In another embodiment, S5 includes: S5.1: Dynamically constructing graph query batches with multiple difficulty levels, each batch containing a set of graph query texts, wherein the graph structure complexity or semantic ambiguity corresponding to each query is pre-classified; S5.2: For each batch of queries, the fine-tuned large language model generates a corresponding set of responses; S5.3: Calculating the base reward value for each response based on the reward function; S5.4: Introducing a negative reward mechanism, applying a negative penalty term to the base reward value for responses that generate incorrect final answers and whose reasoning chains exhibit logical fallacies or completely omit the correct answer during the deep re-evaluation stage; S5.5: Weighting the reward values obtained in steps S5.3 and S5.4 according to the preset difficulty level of the current batch, so that the effective progress of the model on complex tasks receives higher rewards; S5.6: Calculating the policy gradient and updating the parameters of the large language model based on the weighted final reward value through group relative advantage estimation.
[0045] For example, the reinforcement learning optimization process specifically includes the following steps: First, dynamically construct graph query batches with multiple difficulty levels. Each batch contains a set of graph query texts. The graph structure complexity is divided according to the number of nodes and edge density. Easy difficulty is defined as ≤20 nodes and ≤0.3 edge density; medium difficulty is defined as 20 < ≤50 nodes and 0.3 < ≤0.6 edge density; and complex difficulty is defined as >50 nodes and >0.6 edge density. Semantic ambiguity is divided according to the degree of ambiguity of attribute texts. Easy difficulty is when the attribute text is unambiguous and the keywords are clear (e.g., "Node attribute: Apple mobile phone, price 5999 yuan"); medium difficulty is when some attributes are ambiguous and need to be understood in context (e.g., "Node attribute: Smart device, can connect to the network"); and complex difficulty is when the attribute text is ambiguous and semantically vague (e.g., "Node attribute: New product, has multiple functions"). Each batch can contain 32 or 64 graph query texts. The sample ratio of easy, medium, and complex difficulty within a batch is controlled at 3:5:2 to ensure a balanced distribution of difficulty within the batch, which not only consolidates the model's basic capabilities but also pushes the model to challenge complex tasks. For each batch of queries, the input is finely tuned into the large language model. The model generates a corresponding set of responses based on the structured prompt template. Each query generates 8 responses, each containing a complete reasoning chain and a final answer. The diversity of the response set provides a more comprehensive basis for subsequent reward evaluation. A base reward value for each response is calculated based on a preset fine-grained reward function. The base reward value is divided into four levels based on the correctness of the answer, whether the correct answer appears in the candidates, and the compliance of the format: 1 for a correct answer, 0.3 for an incorrect answer but the correct answer is in the candidates, 0.01 for only format compliance, and 0 for all other cases. A negative reward mechanism is introduced to apply a negative penalty to the base reward value for responses that generate an incorrect final answer and whose reasoning chain exhibits obvious logical fallacies during the deep re-evaluation stage (such as contradictory conclusions, unfounded assertions about the existence of a certain association, or discrepancies between the topological analysis and the actual subgraph), or completely omit the correct answer (no option related to the standard answer appears among the candidate answers). The negative penalty can be set to -0.2 or -0.5, with -0.2 for logical fallacies and -0.5 for completely omitting the correct answer. The purpose of this mechanism is to constrain the model's invalid reasoning behavior and guide the model to generate logically rigorous reasoning chains. Based on the preset difficulty level of the current batch, the base reward value and the reward value after adjusting the negative penalty are weighted by a difficulty coefficient. The coefficient for easy difficulty can be set to 0.8, the coefficient for medium difficulty is 1.0, and the coefficient for complex difficulty is 1.2. The basis for this setting is that complex tasks are more difficult to learn, and the effective progress of the model on complex tasks should be rewarded with higher rewards to incentivize the model to actively tackle difficult tasks. For example, if the base reward for a certain response in a complex batch is 0.3 and there is no negative penalty, the weighted reward value is 0.3 × 1.2 = 0.36.Based on the weighted final reward value, the policy gradient is calculated and the parameters of the large language model are updated through group relative advantage estimation. The specific process of group relative advantage estimation is as follows: the responses in the same batch are grouped by query, with each group containing 8 responses for the same query. The average reward value of each group is calculated, and the advantage value of each response = the final reward value of the response - the average reward value within the group. Then, the KL divergence constraint (constraint coefficient set to 0.05) is combined to control the update amplitude of the model parameters to avoid the inference logic from getting out of control due to the model updating too quickly. The formula for calculating the policy gradient is: policy gradient = advantage value × log (probability of the model generating this response). The model parameters are iteratively updated through the gradient descent algorithm to make the model more inclined to generate inference chains with high reward values, rigorous logic and accurate prediction.
[0046] In existing technologies, the reward mechanism of reinforcement learning lacks adaptation to task difficulty and negative constraints, resulting in insufficient learning motivation for models on complex tasks and a tendency to produce logical fallacies in reasoning. This embodiment, by dynamically constructing difficulty batches, introducing negative rewards and difficulty weighting, makes the reward mechanism more aligned with the model's learning needs. It guides the model to focus on improving its reasoning ability for complex tasks, reducing logical fallacies. Compared to existing technologies, reinforcement learning achieves superior results, further enhancing the accuracy and rigor of model reasoning.
[0047] In another embodiment, S7 is also included, which includes: S7.1: Extracting all candidate answers and their evaluation reasons output by the large language model in the deep re-evaluation stage, and calculating the internal confidence score of each candidate answer based on the coverage and logical coherence of structured and semantic keywords in the reasons; S7.2: Starting from the target node or edge, performing a random walk with restart on its neighborhood subgraph obtained by sampling in S1, and generating a basic category probability distribution independent of the model by statistically analyzing the occurrence frequency of each category node in the walk path; S7.3: Comparing the final answer category predicted by the large language model with the category with the highest probability in the basic probability distribution; if they match, outputting the answer as the final result.
[0048] For example, the method also includes a result calibration step to improve the reliability of the final answer through multi-dimensional verification. The specific steps are as follows: First, extract all candidate answers and their evaluation reasons output by the large language model in the deep re-evaluation stage. The evaluation reasons are the core basis for the model to judge the rationality of the candidate answers, including analysis content in terms of structural consistency, semantic consistency and other aspects. The internal confidence score of each candidate answer is calculated based on the coverage of structured and semantic keywords and logical coherence in the reasons. The keyword coverage is calculated as follows: First, extract the core keywords (such as node attribute keywords, edge relationship keywords, and topological feature keywords) from the graph query text. Count the number of these core keywords contained in the evaluation reasons, and then divide by the total number of core keywords to obtain the keyword coverage percentage. Multiply this percentage by 0.5 to obtain the keyword coverage score. Logical coherence is scored by a specialized language model. The model analyzes the grammatical fluency, causal logic, and consistency of the text, outputting a logical score of 0-1. Multiply this score by 0.5 to obtain the logical coherence score. The internal confidence score is the sum of the keyword coverage score and the logical coherence score. For example, if there are 5 core keywords in the graph query, and 4 are contained in the evaluation reasons, the keyword coverage percentage is 0.8, corresponding to a score of 0.4. The language model's logical score for the reason text is 0.8, corresponding to a score of 0.4. Therefore, the internal confidence score for this candidate answer is 0.8. Next, starting from the target node or edge, a random walk with restart is performed on the neighborhood subgraph obtained by sampling the neighborhood subgraph. The random walk with restart is an objective analysis method based on graph topology. Its core logic is to statistically analyze the occurrence frequency of each type of node by simulating the random walk process to reflect the objective characteristics of the category distribution in the subgraph. The specific parameters are set as follows: the restart probability can be set to 0.15, that is, there is a 15% probability of staying at the current node and an 85% probability of moving to an adjacent node in each random walk. The preset number of walk steps is 1000. During the walk, the category of the node visited in each step is recorded. After the walk, the occurrence frequency of each category of node is counted. The occurrence frequency of each category is divided by the total number of walk steps to obtain the occurrence frequency of that category. The occurrence frequencies of all categories constitute a basic category probability distribution that is independent of the model. For example, if category A node appears 300 times, category B node appears 200 times, and category C node appears 100 times during the walk, and the total number of steps is 1000, then the basic category probability distribution is A: 0.3, B: 0.2, C: 0.1. Finally, the final answer category predicted by the large language model is compared with the category with the highest probability in the basic probability distribution. If they match, it means that the model's prediction result is consistent with its own reasoning logic and the objective topological features of the graph data. At this point, the answer is output as the final result. The core function of this calibration step is to verify the model's subjective reasoning results through objective topological features, effectively reduce prediction errors caused by the model's own bias or information interpretation deviation, and improve the credibility of the final result.
[0049] In existing technologies, the inference results of large language models rely solely on their own generation logic, lacking verification against the objective features of graph data, which easily leads to predictions that do not match reality. This embodiment calibrates the model results by calculating the internal confidence scores of candidate answers and combining them with the consistency comparison of the probability distribution of the basic categories generated by a random walk with restart. Compared with existing technologies, this effectively reduces errors caused by subjective bias in the model and improves the credibility of the final results.
[0050] In another embodiment, if there is a discrepancy, cross-source verification is performed: the top K candidate answer categories with the highest internal confidence scores in the large language model are selected, and their intersection is calculated with the top K categories with the highest probabilities in the basic probability distribution; if the intersection is not empty, the answer with the highest internal confidence score is selected from the intersection as the final output; if the intersection is empty, the internal confidence score distribution and the basic probability distribution are weighted and fused, wherein the fusion weight is dynamically determined based on the topological clustering coefficient and semantic description length of the current subgraph, and the category with the highest probability after fusion is output as the calibrated final answer.
[0051] For example, if the final answer category predicted by the large language model is inconsistent with the category with the highest probability in the basic probability distribution, a cross-source validation step is performed. This step resolves the conflict between the two by integrating information from multiple sources, ensuring the reliability of the final result. First, the top K candidate answer categories with the highest internal confidence scores in the large language model are selected, where K is a positive integer. K can be either 3 or 5, and the selection is based on the total number of candidate answers. If the total number of candidate answers is ≥ 5, K=5 is selected; if the total number of candidate answers is < 5, K=3 is selected. Simultaneously, the top K categories with the highest probabilities in the basic probability distribution are extracted. The intersection operation is performed on these two groups of categories to find the common category that exists in both groups. If the intersection is not empty, it indicates the existence of a category that both conforms to the model's inference logic (high internal confidence) and fits the objective characteristics of the subgraph (high base probability). In this case, the answer with the highest internal confidence score is selected from the intersection as the final output. For example, if the model's top 3 candidate categories are A, B, and C (with internal confidence scores of 0.8, 0.7, and 0.6 respectively), and the top 3 categories in the base probability are B, C, and D, the intersection is B and C. Since B has a higher internal confidence score than C, B is output as the final answer. This method balances the rationality of the model's inference with the relevance of the objective data. If the intersection is empty, it indicates a significant discrepancy between the model's inference logic and the objective characteristics of the subgraph. In this case, the internal confidence score distribution and the base probability distribution are weighted and fused. The fusion weight is dynamically determined based on the topological clustering coefficient and semantic description length of the current subgraph. The topological clustering coefficient is an indicator reflecting the density of node clustering in a subgraph. It is calculated by dividing the actual number of edges in the subgraph by the maximum possible number of edges. A higher clustering coefficient indicates a more stable subgraph topology and more reliable objective features, corresponding to a higher weight in the basic probability distribution. It can be set to 0.6, with an internal confidence distribution weight of 0.4. The semantic description length refers to the total text length of node and edge attributes in the graph query text. A longer length indicates richer semantic information and more sufficient basis for model inference, corresponding to a higher weight in the internal confidence distribution. It can be set to 0.6, with a basic probability distribution weight of 0.4. The specific calculation method of weighted fusion is as follows: For each category, its internal confidence score is multiplied by the model weight, and its base probability is multiplied by the base weight. The two are added together to obtain the fused probability of that category. For example, if category A has an internal confidence score of 0.6, a base probability of 0.3, and a high topological clustering coefficient (model weight 0.4, base weight 0.6), then the fused probability = 0.6 × 0.4 + 0.3 × 0.6 = 0.24 + 0.18 = 0.42. The fused probability of all categories is calculated in this way, and the category with the highest fused probability is output as the final answer after calibration. The core function of this cross-source verification method is to integrate multi-source information through dynamic weight allocation when there is a conflict between model inference and objective features, balance the value of subjective reasoning and objective data, and obtain a more comprehensive and reliable final result.
[0052] In existing technologies, when model predictions conflict with objective data features, there is a lack of effective coordination mechanisms, which can easily lead to a decrease in the reliability of the results. This embodiment uses a cross-source verification method of intersection filtering and weighted fusion to reasonably integrate information from both sides when model inference and objective features are inconsistent, resulting in more comprehensive and accurate results. Compared with existing technologies, this further improves the robustness and rationality of the results and is applicable to more complex graph reasoning scenarios.
[0053] Although embodiments of the present invention have been disclosed above, they are not limited to the applications listed in the specification and embodiments. They can be applied to various fields suitable for the present invention. For those skilled in the art, other modifications can be easily made. Therefore, without departing from the general concept defined by the claims and their equivalents, the present invention is not limited to the specific details and embodiments shown and described herein.< / rethink> < / comprehensive> < / semantic> < / structure>
Claims
1. A zero-shot graph learning method based on a large language model, characterized in that, include: S1: Sample the neighborhood subgraph of the graph structure data to be processed, and convert the node attributes and edge relationships in the sampled subgraph into natural language descriptions to generate graph query text; S2: Based on graph query text, construct a structured prompt template containing multi-stage reasoning instructions. Before generating the final answer, the prompt template instruction big language model sequentially performs topological structure analysis, semantic attribute interpretation, multiple candidate answer enumeration, and deep re-evaluation. S3: Construct a graph reasoning training dataset based on prompt templates; S4: Using the graph reasoning training dataset, fine-tune the basic large language model with full parameter instructions, so that the large language model learns to generate reasoning chains by following the structured prompt template; S5: Based on the large language model after instruction fine-tuning, a reinforcement learning algorithm based on group relative advantage is used for optimization. The reward function assigns different reward values according to the correctness of the model output answer, whether the correct answer appears in the candidates listed in the deep re-evaluation stage, and the compliance of the output format. S6: For a new graph task to be reasoned, repeat S1 to S2 to generate the corresponding prompt input, and input it into the large language model optimized by S4 and S5, and directly output the answer containing the reasoning process and the final prediction.
2. The large language model based zero-shot graph learning method of claim 1, wherein, Graph structure data includes directed graphs, undirected graphs, heterogeneous graphs, and knowledge graphs. The task types corresponding to the graph structure data being processed include node classification, link prediction, edge classification, and graph classification.
3. The large language model based zero-shot graph learning method of claim 1, wherein, Neighborhood subgraph sampling is specifically h-hop neighborhood sampling, where h is an integer greater than 0; before generating graph query text, the original text attributes of nodes or edges are automatically summarized.
4. The large language model based zero-shot graph learning method of claim 1, wherein, The reward function is configured as follows: when the final answer is correct, a first reward value is assigned; when the final answer is incorrect but the correct answer appears in the candidates listed in the deep re-evaluation stage, a second reward value lower than the first reward value is assigned; when only the output format meets the requirements but the content is invalid, a third reward value lower than the second reward value is assigned; and no reward value is assigned in other cases.
5. The large language model based zero-shot graph learning method of claim 1, wherein, The method for constructing a graph reasoning training dataset includes: acquiring original graph data samples from multiple domains and generating corresponding graph query texts; inputting the graph query texts into a large language model to generate explicit reasoning trajectories containing multi-stage reasoning instructions and corresponding answers, forming initial training samples; filtering the initial training samples based on information sufficiency, answer validity, and logical coherence, retaining samples that meet the preset logical coherence and answer validity to constitute the graph reasoning training dataset.
6. The large language model based zero-shot graph learning method of claim 1, wherein, In-depth reassessment includes: For each candidate answer generated during the multiple candidate answer listing stage, structural consistency evaluation and semantic consistency evaluation are performed sequentially. Structural consistency evaluation is based on the topological connection relationship of the subgraph to determine whether the candidate answer matches the structural pattern of the existing nodes or edges in the graph. Semantic consistency evaluation is based on the attribute semantics of nodes and edges to determine the semantic compatibility of the candidate answer with the existing information in the graph. Based on the results of structural consistency evaluation and semantic consistency evaluation, each candidate answer is comprehensively scored and ranked, and the final selected answer and its reasons are output.
7. The zero-shot graph learning method based on a large language model as described in claim 1, characterized in that, In S4, a phased progressive training strategy is adopted, which divides the graph reasoning training dataset into three phases and inputs them into the model for training in sequence. In the first stage, a simplified prompt template is used for training. The prompt template only includes two inference stages: topological structure analysis and semantic attribute interpretation, so that the large language model can initially grasp the structural and semantic information of the graph data. In the second stage, training is switched to the complete structured prompt template, and supervision of the output of the intermediate stages of the inference chain is introduced. The cross-entropy loss between the text generated by the large language model at each inference stage and the corresponding stage text labeled in the dataset is calculated. In the third stage, the complete structured prompt template is retained, while the graph query text in the training samples is subjected to local information random masking or semantic perturbation to enhance the reasoning robustness of the large language model under incomplete information or noise conditions. In each training phase, the goal is to minimize the comprehensive loss function, which includes the loss of the final answer and the loss of the intermediate inference phases, and update all parameters of the large language model.
8. The zero-shot graph learning method based on a large language model as described in claim 1, characterized in that, S5 include: S5.1: Dynamically construct graph query batches with multiple difficulty levels. Each batch contains a set of graph query texts, where the graph structure complexity or semantic ambiguity corresponding to each query is pre-classified. S5.2: For each batch of queries, the large language model after fine-tuning the instructions generates the corresponding response set; S5.3: Calculate the base reward value for each response based on the reward function described above; S5.4: Introduce a negative reward mechanism to apply a negative penalty to the base reward value for responses that generate an incorrect final answer and whose reasoning chain exhibits logical fallacies or completely omits the correct answer during the deep re-evaluation stage. S5.5: Based on the preset difficulty level of the current batch, the reward values obtained in steps S5.3 and S5.4 are weighted by a difficulty coefficient so that the effective progress of the model on complex tasks can be rewarded more. S5.6: Based on the weighted final reward value, calculate the policy gradient through group relative advantage estimation and update the parameters of the large language model.
9. The zero-shot graph learning method based on a large language model as described in claim 1, characterized in that, It also includes S7, which includes: S7.1: Extract all candidate answers and their evaluation reasons output by the large language model in the deep re-evaluation stage, and calculate the internal confidence score of each candidate answer based on the coverage and logical coherence of structured and semantic keywords in the reasons; S7.2: Starting from the target node or edge, perform a random walk with restart on its neighborhood subgraph obtained by sampling in S1. By statistically analyzing the occurrence frequency of each type of node in the walk path, generate a basic class probability distribution that is independent of the model. S7.3: Compare the final answer category predicted by the large language model with the category with the highest probability in the basic probability distribution: if they match, output the answer as the final result.
10. The zero-shot graph learning method based on a large language model as described in claim 9, characterized in that, If there is a discrepancy, cross-source validation is performed: the top K candidate answer categories with the highest internal confidence scores in the large language model are selected, and their intersection is calculated with the top K categories with the highest probabilities in the basic probability distribution; if the intersection is not empty, the answer with the highest internal confidence score is selected from the intersection as the final output; if the intersection is empty, the internal confidence score distribution and the basic probability distribution are weighted and fused, where the fusion weight is dynamically determined based on the topological clustering coefficient and semantic description length of the current subgraph, and the category with the highest probability after fusion is output as the final calibrated answer.