Method for converting knowledge graph into natural language large model training sample and related device

By selecting key anchor points in the knowledge graph to construct a symmetrical meta-path subgraph and using various instruction prompt templates to generate training samples, the mismatch problem when converting knowledge graphs into training samples for large-scale language models is solved. This achieves structurally coherent, semantically faithful, and diverse training data generation, improving the training effect of the model in vertical domains.

CN122432661APending Publication Date: 2026-07-21SOUTH CHINA UNIV OF TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202610277607.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-03-09
Publication Date
2026-07-21

AI Technical Summary

Technical Problem

Existing technologies for converting knowledge graphs into training samples for large-scale language models suffer from problems such as mismatch between graph structure and text serialization, loss of long-distance semantic dependency information, and data format not conforming to the instruction tuning paradigm, resulting in poor model training performance.

Method used

By selecting key anchor points, a symmetric meta-path subgraph is constructed, and various instruction prompt templates are used to generate structurally coherent, semantically faithful, and diverse training samples, including structured information, path information, and metadata enrichment templates. This generates data pairs that meet the requirements of instruction tuning for fine-tuning of large-scale language models.

Benefits of technology

It effectively preserves the long-distance semantic dependencies and structural information of knowledge graphs, generates diverse training data, improves the knowledge generalization ability and practicality of large language models in vertical domains, and fills the data format gap in existing technologies.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122432661A_ABST
    Figure CN122432661A_ABST
Patent Text Reader

Abstract

The embodiment of the application provides a method for converting a knowledge graph into a natural language large model training sample and related equipment, and belongs to the technical field of artificial intelligence. The method comprises the following steps: selecting a key anchor point from the knowledge graph based on a graph centrality measurement index; taking a key anchor point pair as a starting point and an ending point, extracting a symmetric element path connecting the two, and constructing a subgraph; generating multi-perspective paths for the same core entity through an anchor point switching mechanism; converting subgraph information into a (instruction, output) sample pair conforming to the instruction fine-tuning paradigm by using a structured information template, a path information template and a metadata enrichment template; and fine-tuning a large language model by using the generated corpus. By introducing the symmetric element path and the multi-dimensional instruction template, the embodiment of the application realizes semantic preservation and structured mapping of complex relationships in the knowledge graph, and effectively improves the knowledge understanding, reasoning and generalization ability of the large model in a specific field such as the power secondary equipment field.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of artificial intelligence technology, and in particular to a method and related equipment for converting knowledge graphs into training samples for large natural language models. Background Technology

[0002] With the breakthroughs achieved by large language models (LLMs) in the field of natural language processing, how to effectively inject domain-specific expertise into these general-purpose models to improve their performance in vertical industries has become a key research direction. Knowledge graphs (KGs), as an effective way to store human knowledge in a structured form, are considered an ideal carrier for delivering domain knowledge to LLMs.

[0003] However, applying knowledge graphs to LLM training faces a series of inherent technical challenges.

[0004] The primary challenge stems from the fundamental differences in data structures. Large language models, such as those based on the Transformer architecture, are designed to handle linear, serial data—text. Knowledge graphs, on the other hand, are non-linear, complex network structures. This structural "impedance mismatch" means that the graph structure must first be transformed into a serialized format that LLMs can understand; this process is called "graph linearization."

[0005] Existing graph linearization methods have significant limitations. Simple linearization strategies, such as random walks or simply listing adjacency lists of nodes and edges, often destroy the rich structural information and deep semantic relationships inherent in knowledge graphs. Research shows that effective linearization methods must preserve properties similar to natural language, such as "local dependencies" and "global alignment," otherwise the generated training data will be difficult for LLMs to understand effectively. Furthermore, large knowledge graphs are vast in scale, while LLMs have finite context windows, necessitating the segmentation of the graph into smaller subgraphs for processing. Inappropriate segmentation methods can easily sever long-distance dependencies between entities, leading to the loss of global structural information—a common challenge faced by existing technologies.

[0006] In existing technologies, attempts to enhance LLM using knowledge graphs mainly face two types of problems. The first type of method focuses on using the structural information of the graph to improve the model's reasoning ability. However, it often lacks clear and efficient explanations on how to effectively serialize complex graph structures and input them into the LLM, failing to fundamentally solve the core problem of long-distance semantic dependency information loss during graph-to-text conversion. The second type of method has limitations in its application premises. Its effectiveness often relies on an idealized knowledge graph with complete structure and accurate information, making it unable to handle the common issues of missing, erroneous, or inconsistent information in real-world industrial applications.

[0007] Meanwhile, the adaptation paradigm of LLM has gradually shifted from the traditional pre-training-fine-tuning to "instruction tuning." Instruction tuning is a supervised fine-tuning process performed on a dataset containing (instruction, output) formatted samples, with the goal of training the model to better follow user instructions. Traditional knowledge graph-to-text (KG-to-Text) techniques typically aim to generate readable descriptive paragraphs, and the resulting declarative text does not conform to the data format required for instruction tuning. Therefore, there is a significant "data format gap" between existing KG-to-Text methods and the modern LLM training paradigm.

[0008] In summary, current technologies have significant shortcomings in transforming large-scale, imperfect industrial knowledge graphs into high-quality training samples suitable for LLM instruction tuning. These shortcomings mainly manifest in: 1) a lack of graph linearization methods capable of simultaneously preserving local semantics and global structural information; 2) difficulty in handling the loss of long-distance dependency information due to LLM context window limitations; and 3) a mismatch between the generated data format and the instruction tuning paradigm. Therefore, an innovative solution is urgently needed to address these issues. Summary of the Invention

[0009] The main objective of this application is to propose a method, electronic device, storage medium, and program product for converting knowledge graphs into training samples for large-scale natural language models. It aims to address the core problem of generating structurally coherent, semantically faithful, and diverse natural language training samples when processing large-scale industrial knowledge graphs with potentially incomplete information. These samples are specifically designed for instruction tuning of large-scale language models to overcome the problems of poor model training performance caused by information loss due to long-distance dependencies and insufficient data diversity.

[0010] To achieve the above objectives, one aspect of this application proposes a method for converting knowledge graphs into training samples for large natural language models, the method comprising: Key anchor point selection steps: The processor selects at least two nodes from the knowledge graph as key anchor points based on a preset graph centrality metric. Symmetric subgraph extraction steps: The processor uses the at least two key anchor points as the start and end points of the path, and extracts the symmetric meta-paths connecting the start and end points in the knowledge graph through a graph traversal algorithm, thereby constructing a subgraph containing intermediate nodes and edges. Sample generation step: The processor extracts at least one of the structural information, path information or metadata information from the subgraph and fills it into one or more predefined instruction prompt templates to generate training sample pairs containing natural language instructions and their corresponding outputs; Model fine-tuning steps: The generated training sample pairs are used to fine-tune the large natural language model.

[0011] In some embodiments, the key anchor point selection step further includes: The processor calculates the centrality score of each node based on at least one of degree centrality, betweenness centrality, or PageRank centrality, and selects nodes with scores greater than a preset threshold as the set of key anchor nodes according to the weighted scores.

[0012] In some embodiments, the graph traversal algorithm is selected from the breadth-first search algorithm or Dijkstra's algorithm; When the edges in the knowledge graph are assigned weights representing business meanings, the processor uses Dijkstra's algorithm to extract the optimal path with the lowest cost between the starting point and the ending point.

[0013] In some embodiments, an anchor point switching step is also included: For the same core entity in the subgraph, a pair of different key anchor points are reselected to generate multiple symmetric meta-paths containing the core entity but with different semantic perspectives, thereby generating multiple training samples with different perspectives.

[0014] In some embodiments, the predefined instruction prompt template includes a structured information template; The structured information template is configured to query the local topological attributes of a target node in the subgraph, the local topological attributes including at least one of the node's 1-hop neighbor list or 2-hop neighbor list.

[0015] In some embodiments, the predefined instruction prompt template includes a path information template; The path information template is configured to query node sequence relationships along one of the symmetric meta-paths, the node sequence relationships including at least one of the IP address, port, communication protocol, or communication frequency of the communication link.

[0016] In some embodiments, the predefined instruction prompt template includes a metadata enrichment template; The metadata enrichment template is configured to aggregate attribute information of multiple nodes and edges in the subgraph to generate a comprehensive description or inference. The attribute information includes at least one of asset type, geographic location, vendor information, or security vulnerability data.

[0017] In some embodiments, the knowledge graph is a knowledge graph in the field of power secondary equipment.

[0018] 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 method described above.

[0019] 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 method described above.

[0020] To achieve the above objectives, another aspect of the embodiments of this application proposes a computer program product, including a computer program that, when executed by a processor, implements the method described above.

[0021] Compared with the prior art, this application has the following significant advantages: 1) The “key anchor point - other nodes - key anchor point” symmetric meta-path extraction method of this application ensures that each generated training sample describes a complete relationship link between two important entities. The text generated by this method has a clear start and end point, forming a self-contained “narrative” unit, which greatly preserves contextual information and long-distance semantic dependencies, and is far superior to the traditional method that only extracts the local neighborhood of nodes.

[0022] 2) This application not only focuses on entity attributes, but also explicitly transforms the graph topology (such as the number of hops of nodes and neighbor relationships) and sequence path information (such as communication links between devices) into natural language descriptions through a special path information template. This enables LLM to learn deep structural knowledge that is usually lost in simple text conversion, and achieves effective preservation and transformation of structured information.

[0023] 3) In this application, by combining the "anchor switching" mechanism with various instruction prompt templates with different focuses (structured information template, path information template, and metadata enrichment template), the same entity or relationship can be described from different perspectives and with different questioning methods. This greatly enriches the diversity of training data, generates a more robust training set, and thus improves the knowledge generalization ability of LLM and its ability to understand complex queries.

[0024] 4) Knowledge graphs in the industrial field often have missing or incorrect information. This application generates data by focusing on local subgraphs connected by key anchors with high confidence, which effectively avoids the negative impact of global inconsistencies or large-scale missing information in knowledge graphs on the quality of training data and demonstrates stronger practical application value.

[0025] 5) This application directly generates (instruction, output) data pairs that meet the requirements of instruction tuning through instruction prompt templates. This bridges the "data format gap" between traditional KG-to-Text technology and the training needs of modern LLM, enabling the generated corpus to be directly used to efficiently train LLMs to follow domain-specific instructions, thereby significantly improving the model's practicality in vertical domains. Attached Figure Description

[0026] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0027] Figure 1 This application provides a schematic diagram of a system architecture for converting knowledge graphs into training samples for a large natural language model. Figure 2 A detailed flowchart illustrating a method for converting knowledge graphs into training samples for a large natural language model, as provided in this application embodiment; Figure 3 This is a schematic diagram of an exemplary knowledge graph subgraph of secondary power equipment in an embodiment of this application, showing two key anchor points and the symmetric meta-paths connecting them; Figure 4 This is a schematic diagram of the hardware structure of the electronic device provided in the embodiments of this application. Detailed Implementation

[0028] 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.

[0029] 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.

[0030] Before providing a detailed description of the embodiments of this application, some of the nouns and terms involved in the embodiments of this application will be explained first. The nouns and terms involved in the embodiments of this application are subject to the following interpretations.

[0031] 1) A knowledge graph is a semantic network that describes the objective world using a graph structure. Essentially, it's a knowledge base describing concepts, entities, and their relationships, and a major manifestation of knowledge engineering in the field of artificial intelligence. It organizes data using triples, and its construction process includes knowledge extraction, fusion, and processing. It is applied in multiple fields such as semantic search, intelligent question answering, and recommendation systems. A knowledge graph can be formally represented as... ,in It is a collection of entities (nodes). It is a set of relations (edges), and It is a fact triplet A set of.

[0032] 2) Large Language Models (LLMs) are deep learning models trained on massive amounts of text data, enabling them to generate natural language text or understand the meaning of language text. These models can provide in-depth knowledge and language production on a wide range of topics through training on large datasets. The core idea is to learn patterns and structures of natural language through large-scale unsupervised training, thus mimicking the human language cognition and generation process to some extent. To address the problems existing in the prior art, this application provides a method, electronic device, storage medium, and program product for converting knowledge graphs into training samples for large natural language models. The aim is to solve the problem in the prior art where the mismatch between the knowledge graph structure and the serialized input of the large language model, especially when processing long text information, leads to the loss of long-distance semantic dependencies and the lack of global structural information, which in turn affects the training effect of the model in vertical domains. A solution for structured subgraph extraction and templated sample generation is proposed. This application, based on a knowledge graph of secondary power equipment, generates training samples through the following steps: First, key structural or semantic anchors are selected programmatically based on graph centrality metrics such as degree centrality, betweenness centrality, or PageRank. Second, logically closed and informationally complete subgraphs are extracted by constructing symmetric meta-paths of "key anchor—intermediate node—key anchor," and an anchor switching mechanism is used to express the same entity features from different perspectives, thereby improving the large model's ability to learn entity semantics and structure from multiple perspectives. Then, using multi-type instruction prompt templates enriched with structured information, path information, and metadata, the extracted subgraphs are transformed into (instruction, output) sample pairs that conform to the instruction fine-tuning paradigm. Finally, the generated corpus is used to fine-tune the large language model. By introducing symmetric meta-paths and multi-dimensional instruction templates, this application achieves semantic preservation and structured mapping of complex relationships in the knowledge graph, effectively improving the large model's knowledge understanding, reasoning, and generalization capabilities in specific domains.

[0033] The method for converting knowledge graphs into training samples for large-scale natural language models provided in this application relates to the field of artificial intelligence 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 that implements the method for converting knowledge graphs into training samples for large-scale natural language models, but is not limited to the above forms.

[0034] 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, 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.

[0035] Please refer to the following: Figure 1 This application provides a system for converting knowledge graphs into training samples for large natural language processing models. The system can be deployed in a computing environment consisting of one or more servers, which includes at least a processor, memory, storage devices, and a network interface. The logical architecture of the system includes: Knowledge graph database: Used to store domain knowledge graphs, for example, using graph databases such as Neo4j and JanusGraph for storage and management. In this embodiment, the database stores a knowledge graph of secondary power equipment, where nodes represent entities such as equipment, manufacturers, substations, and communication protocols, and edges represent relationships between them (such as "production", "located in", "adopted" etc.). Key Anchor Point Selection Module: Responsible for identifying and selecting core nodes as anchor points from the knowledge graph database according to a preset strategy; Subgraph extraction module: Responsible for extracting symmetric meta-path subgraphs from the knowledge graph based on selected anchor pairs; Natural Language Transformation Module: Responsible for converting extracted subgraphs into structured training samples using instruction prompt templates; Large Model Training Module: Responsible for supervised fine-tuning of a basic large language model using the generated training corpus.

[0036] Reference Figure 2 This invention provides a method for converting knowledge graphs into training samples for large natural language processing models. The specific implementation process is as follows: Step S1: Select key anchor points.

[0037] This step aims to identify, in a procedural and reproducible manner, the core nodes from the vast knowledge graph that are crucial for building meaningful training samples.

[0038] Unlike selection methods that rely on human experience or simple rules, this embodiment uses a mature graph theory algorithm—graph centrality analysis—to quantify the "importance" of nodes.

[0039] The choice of centrality metric is not fixed, but can be configured according to the goals of downstream tasks, which constitutes a key aspect of the flexibility of the framework in this application.

[0040] For example, if the downstream task is equipment fault diagnosis, then the focus may need to be on identifying key communication nodes in the network; if the task is supply chain risk analysis, then the importance of manufacturer and component type nodes is higher.

[0041] This task-oriented anchor selection mechanism ensures that the generated training data is highly relevant to the final application goal.

[0042] In practice, the key anchor point selection module can be configured to implement one or more of the following centrality measurement algorithms: Degree Centrality: Calculates the degree centrality of a node. Directly connected edges The quantity. Its standardized calculation formula is:

[0043] Where N is the total number of nodes in the graph. Nodes with high degree centrality are usually hubs for information or interaction. In the power knowledge graph, a substation node connecting a large number of devices, or a communication protocol node used by multiple device models, both exhibit high centrality. Selecting such nodes as anchor points helps generate a large number of training samples about core facilities and common standards; Betweenness Centrality: A measure of a node's betweenness centrality. Appearing in other nodes in the network The frequency of the shortest path between them. The formula for calculation is:

[0044] in It is a node To the node The total number of shortest paths, These are the nodes passed through in these paths. Nodes with high betweenness centrality act as "bridges" or "bottlenecks" in a network, controlling the flow of information. For example, a critical data gateway or router may have high betweenness centrality in the device communication link. Using these nodes as anchor points, training data about network topology and key data flow paths can be generated, which is crucial for training models to understand system-level interactions. PageRank centrality: This is an iterative algorithm that considers the importance of a node not only to the number of nodes connecting to it, but also to the "importance" of those nodes. Its calculation formula is as follows:

[0045] in It is a link to a node The set of nodes, It is a node The degree of exit, It is the total number of nodes. This is the damping coefficient (typically taken as 0.85). In the power sector, a node from a well-known manufacturer used in many critical core devices (such as main transformer protection devices) will have a high PageRank value. Choosing such nodes as anchor points helps generate training samples regarding industry standards, equipment quality, and manufacturer reputation.

[0046] During execution, the key anchor selection module calculates the selected centrality score for all (or specific types of) nodes in the knowledge graph, and selects the top N nodes or nodes with scores exceeding a certain threshold to form a key anchor pool.

[0047] Step S2: Extract the symmetric metapath subgraph between key anchor points.

[0048] This step is one of the core innovations of this application, and its purpose is to extract data fragments from the knowledge graph that contain rich information and have internal logical coherence.

[0049] Traditional subgraph extraction methods, such as extracting all neighbors within the k-hop range of a target node, often introduce a large amount of noise information unrelated to the core semantics, forming a loosely structured "node cloud" and making it difficult to preserve long-distance dependencies.

[0050] The "symmetric meta-path" method proposed in this embodiment provides a "narrative scaffold" for the generated data fragments by constructing a closed path structure that starts from anchor point A, passes through a series of intermediate nodes, and finally reaches anchor point B.

[0051] This scaffold ensures that all information within the subgraph serves to explain the relationship between anchor A and anchor B, thus resolving the issues of missing context and semantic incoherence. This structured path naturally aligns with the narrative logic of human language and provides LLM with the "local dependency" structure it is accustomed to during the pre-training phase, making it easier to learn and understand.

[0052] Algorithm implementation: For a pair of anchors selected from the anchor pool (e.g., anchor A: 'Device 1', anchor B: 'Device 2'), the subgraph extraction module executes a graph traversal algorithm to find all paths connecting the two anchors. The maximum path length (number of hops) is a configurable parameter (e.g., 3-5 hops) to balance information richness and computational complexity.

[0053] Pathfinding Algorithm: This embodiment employs a two-tiered strategy that balances efficiency and business depth in its pathfinding algorithm implementation. Shortest path finding in general: By default, the system uses the Breadth-First Search (BFS) algorithm. This algorithm guarantees finding the path with the fewest hops between two anchor points. In knowledge graphs, the shortest path typically represents the most direct and core semantic relationship between two entities. Using BFS as a general algorithm aims to efficiently generate a large number of basic training samples that reflect the core relationships between entities and have a concise and clear structure.

[0054] Optimal path finding for specific business needs: When the edges of the knowledge graph are assigned weights representing specific business meanings, the system switches to the Dijkstra algorithm for path finding. These weights are quantifiable metrics defined based on specific business needs, for example: Communication delay: refers to the signal transmission time of the communication link between two device nodes.

[0055] Relationship strength or credibility: Indicates the degree of trustworthiness of a fact triple.

[0056] Security risk level: indicates the security risks one must bear when using a certain path or connection.

[0057] In this context, Dijkstra's algorithm is used to find the optimal path between two anchor points with the lowest "cost" (e.g., the path with the lowest latency, lowest risk, or highest reliability). In this way, this application can generate training samples containing deep business logic, enabling large language models not only to learn "the existence of relationships between entities" but also "the business characteristics of these relationships," thereby greatly enhancing the model's expertise in vertical domains.

[0058] "Anchor point switching" data augmentation mechanism: To further increase the diversity of training data, this embodiment introduces an "anchor switching" mechanism. For a core entity to be described (e.g., device 'protective device-123'), the system can generate descriptions from multiple different perspectives.

[0059] Example: Perspective 1 (Manufacturer-Site): Select anchor point A: 'Manufacturer X' and anchor point B: 'Substation Y'. The system finds the path Manufacturer X -> [Production] -> Protection Device-123 -> [Deployed at] -> Substation Y. This path describes the origin and physical location of the device.

[0060] Perspective 2 (Function-Protocol): Switch anchor points, selecting anchor point A: 'Asset Type: Relay Protection' and anchor point B: 'Communication Protocol: IEC-61850'. The system may find the path Asset Type: Relay Protection -> [Yes] -> Protection Device-123 -> [Use] -> Communication Protocol 1. This path describes the same device from both a functional and communication standard perspective.

[0061] In this way, the same entity 'protective device-123' is described in different contexts, generating training samples with different content and structure, which greatly enriches the training corpus and helps the model form a more comprehensive and three-dimensional understanding of the entity.

[0062] Step S3: Convert the subgraph into natural language training samples.

[0063] The goal of this step is to transform the structured subgraph extracted in step S2 into (instruction, output) data pairs that conform to the instruction tuning paradigm. This process is not simply about converting graph structure information into natural language descriptions, but rather aims to generate data pairs that can be used to train large language models to master domain-specific skills such as topological cognition, path reasoning, and multi-source information synthesis by designing instruction prompt templates with different focuses.

[0064] To this end, the natural language conversion module has built-in a variety of instruction prompt templates. These templates are not redundant; they guide the model's learning from different dimensions: Structural templates teach topological cognition, path templates teach logical process reasoning, and metadata enrichment templates teach the ability to synthesize and infer multi-source information.

[0065] By training on a hybrid dataset generated from these three templates, LLM can achieve more comprehensive domain reasoning capabilities.

[0066] Command prompt template; Structured Information Template: This template focuses on describing the local topological environment of nodes, training the model to understand the location and neighborhood relationships of entities in the network.

[0067] Instruction format: "Classify secondary power equipment. Central node: {device name}. It is connected within 1 hop to: {1-hop neighbor list}. It is connected within 2 hops to: {2-hop neighbor list}. What is the most likely device type for {device name}?" Output format: "{Device type}" Path information template; This template aims to linearize a symmetric meta-path and its associated dynamic behavioral features, enabling the training of models to infer core attributes based on the network communication patterns of devices, thereby understanding deep business logic and dependencies.

[0068] Instruction format: "Describe the communication path between secondary power equipment. Central node: {device name}. One of its key communication paths, '{device name (anchor 1)} -- [communication frequency] -> ... -> {communication protocol} -> ... -> {anchor 2}', connects to other devices. The communication details are as follows: via {starting IP}:{starting port}, using {communication protocol}, connecting to {destination IP}:{destination port}. Based on the above connection characteristics, what type of device is {device name} most likely?" Output format: "{Device type}" Metadata enrichment template: This template aggregates the attributes (metadata) of multiple nodes and edges in the subgraph, requiring the model to perform comprehensive analysis and inference.

[0069] Command format: "Analyze the following information about secondary power equipment. Central node: {Equipment Name}, whose summary is 'This equipment is an asset of type {Asset Type}, located in substation {Substation Name}, its manufacturer is {Manufacturer Name}, its known vulnerability information is {FOFA scan data}, and its SCD mapping data is {SCD information}'. It is connected to node {Neighbor Node 1} (whose function is '{Function Description}'). Based on the above information, what is the core identity of this equipment?" Output format: "{Device Core Identity}" The table below illustrates, through a concrete example, how to... Figure 3 The subgraphs shown are applied to these three templates to generate different training samples.

[0070] Input subgraph information: Anchor point A: (Device 1), Anchor point B: (Device 2).

[0071] One of the paths is: (Manufacturer 1) - [Production] -> (Device 1) -> [IP1] - (Protocol 1) - [IP2] -> - (Device 2) -> [Production] - (Manufacturer 2); The structured template generates the following instructions: Device 1's first-hop neighbor is: Vendor 1, Protocol 1, Security Zone I. Its second-hop neighbor is: Device 2. Based on this structure, what type of device is this? Output: This device is a protection device.

[0072] The path template generation instruction traces the path of device 1 from production to deployment. The path is Vendor 1 -> Protocol 1 -> Device 2 -> Vendor 2. In this path, what kind of device is device 1? Output: This device is a protection device.

[0073] Instructions for generating metadata enrichment templates: Comprehensive analysis device 1: It is manufactured by vendor 1, deployed in security zone I, with a voltage level of 500kV, and communicates via protocol 1. Please summarize the core identity of this device.

[0074] Output generated: Device 1 is a 500kV protection device manufactured by Manufacturer 1 and deployed in Safety Zone I.

[0075] Step S4: Generate training data and fine-tune the model.

[0076] This step automates the aforementioned process to build a large-scale training corpus and perform domain adaptation of the model.

[0077] Training data generation: The system executes iteratively. First, it traverses all labeled types (or all devices selected as anchors) in the knowledge graph. For each device, the system executes steps S1-S3: Consider it as a potential intermediate node.

[0078] An anchor point switching mechanism is applied to match multiple pairs of different key anchor points.

[0079] Extract the symmetric metapath subgraph that connects these anchor points and includes the device.

[0080] Each extracted sub-image is applied to all three types of instruction prompt templates.

[0081] This process is repeated, and the system can generate tens of thousands, or even millions, of text pairs in the format {"instruction":"...", "output": "..."}. These text pairs are formatted into JSONL files, forming the final training set used for LLM fine-tuning.

[0082] Model fine-tuning: The large model training module receives the generated training set and performs supervised fine-tuning (SFT) on a pre-trained general-purpose large language model. The fine-tuning process aims to minimize the difference between the model's predictions and the true output. Its objective function is typically the negative log-likelihood of the conditional language model, which can be expressed as:

[0083] in, These are the parameters of the model. It is the training set data. It is the first in the output sequence Each token The length of the output sequence is adjusted by using optimization algorithms such as gradient descent to adjust the model's internal weights so that when the model receives instructions from the training set, its output can be as close as possible to the "standard answer" given in the dataset.

[0084] Through this process, the model not only memorizes specific factual knowledge in the field of secondary power equipment (such as equipment models, manufacturers, communication protocols, etc.), but more importantly, it learns how to reason and organize this knowledge according to different questioning methods (structure, path, comprehensive analysis), thereby gaining true domain "understanding" ability.

[0085] The final, finely tuned model will be able to answer more accurate and in-depth questions about power secondary equipment, providing strong technical support for advanced applications such as intelligent operation and maintenance, fault diagnosis, and safety analysis of power systems.

[0086] 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.

[0087] 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.

[0088] Please see Figure 4 , Figure 4 The hardware structure of an electronic device according to another embodiment is illustrated. The electronic device includes: The processor 401 can be implemented using a general-purpose CPU (Central Processing Unit), microprocessor, application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of this application. The memory 402 can be implemented as a read-only memory (ROM), a static storage device, a dynamic storage device, or a random access memory (RAM). The memory 402 can store the operating system and other applications. When the technical solutions provided in the embodiments of this specification are implemented through software or firmware, the relevant program code is stored in the memory 402 and is called and executed by the processor 401 using the methods described in the embodiments of this application. Input / output interface 403 is used to implement information input and output; The communication interface 404 is used to enable communication and interaction between this device and other devices. Communication can be achieved through wired means (such as USB, Ethernet cable, etc.) or wireless means (such as mobile network, WIFI, Bluetooth, etc.). Bus 405 transmits information between various components of the device (e.g., processor 401, memory 402, input / output interface 403, and communication interface 404); The processor 401, memory 402, input / output interface 403 and communication interface 404 are connected to each other within the device via bus 405.

[0089] This application also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described method.

[0090] 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.

[0091] 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.

[0092] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the above-described method.

[0093] It is understood that the content of the above method embodiments is applicable to the embodiments of this program product. The specific functions implemented in the embodiments of this program product 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. The executable computer program code or "code" used to perform the various embodiments can be written in high-level programming languages ​​such as C, C++, Python, Smalltalk, Java, JavaScript, Visual Basic, Structured Query Language (e.g., Transact-SQL), Perl, or in various other programming languages.

[0094] 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.

[0095] 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.

[0096] 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.

[0097] 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.

[0098] 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.

[0099] It should be understood that in this application, "at least one (item)" means one or more, and "more than" means two or more. "And / or" is used to describe the relationship between related objects, indicating that three relationships can exist. For example, "A and / or B" can represent three cases: only A exists, only B exists, and both A and B exist simultaneously, where A and B can be singular or plural. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. "At least one (item) of the following" or similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one (item) of a, b, or c can represent: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, and c can be single or multiple.

[0100] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of the units described above is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.

[0101] The units described above as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0102] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0103] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes multiple instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing programs, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0104] 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 converting knowledge graphs into training samples for large natural language models, characterized in that, The method includes the following steps: Key anchor point selection steps: The processor selects at least two nodes from the knowledge graph as key anchor points based on a preset graph centrality metric. Symmetric subgraph extraction steps: The processor uses the at least two key anchor points as the start and end points of the path, and extracts the symmetric meta-paths connecting the start and end points in the knowledge graph through a graph traversal algorithm, thereby constructing a subgraph containing intermediate nodes and edges. Sample generation step: The processor extracts at least one of the structural information, path information or metadata information from the subgraph and fills it into one or more predefined instruction prompt templates to generate training sample pairs containing natural language instructions and their corresponding outputs; Model fine-tuning steps: The generated training sample pairs are used to fine-tune the large natural language model.

2. The method according to claim 1, characterized in that, The key anchor point selection step further includes: The processor calculates the centrality score of each node based on at least one of degree centrality, betweenness centrality, or PageRank centrality, and selects nodes with scores greater than a preset threshold as the set of key anchor nodes according to the weighted scores.

3. The method according to claim 1, characterized in that, The graph traversal algorithm is selected from either breadth-first search or Dijkstra's algorithm; When the edges in the knowledge graph are assigned weights representing business meanings, the processor uses Dijkstra's algorithm to extract the optimal path with the lowest cost between the starting point and the ending point.

4. The method according to claim 1, characterized in that, It also includes the anchor point switching step: For the same core entity in the subgraph, a pair of different key anchor points are reselected to generate multiple symmetric meta-paths containing the core entity but with different semantic perspectives, thereby generating multiple training samples with different perspectives.

5. The method according to claim 1, characterized in that, The predefined instruction prompt template includes a structured information template; The structured information template is configured to query the local topological attributes of a target node in the subgraph, the local topological attributes including at least one of the node's 1-hop neighbor list or 2-hop neighbor list.

6. The method according to claim 1, characterized in that, The predefined instruction prompt template includes a path information template; The path information template is configured to query node sequence relationships along one of the symmetric meta-paths, the node sequence relationships including at least one of the IP address, port, communication protocol, or communication frequency of the communication link.

7. The method according to claim 1, characterized in that, The predefined instruction prompt template includes a metadata enrichment template; The metadata enrichment template is configured to aggregate attribute information of multiple nodes and edges in the subgraph to generate a comprehensive description or inference. The attribute information includes at least one of asset type, geographic location, vendor information, or security vulnerability data.

8. The method according to any one of claims 1 to 7, characterized in that, The knowledge graph in question is a knowledge graph for the field of power secondary equipment.

9. An electronic device, characterized in that, The electronic device includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program to implement the method according to any one of claims 1 to 8.

10. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the method of any one of claims 1 to 8.