Power safety intelligent question and answer method and product based on knowledge graph constraint reasoning
By constructing a knowledge graph for power safety and combining it with the constraining context of a large language model, the problems of accuracy and reliability of question answering in the field of power safety are solved, and efficient and professional intelligent question answering results are generated.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- POWER RES INST OF STATE GRID SHAANXI ELECTRIC POWER CO LTD
- Filing Date
- 2026-04-08
- Publication Date
- 2026-07-31
AI Technical Summary
Existing intelligent question answering methods in the field of power safety suffer from insufficient semantic understanding capabilities, resulting in inaccurate and inefficient question answering results. Furthermore, general-purpose large language models lack the professional depth and rigor required for the power safety field, making them prone to generating incorrect answers.
A knowledge graph for power safety is constructed based on a knowledge graph. Iterative training is performed by extracting a sample set of entity relationship triples in the power field to generate entity embedding vectors and relationship embedding vectors. Answers are generated by combining multi-hop path reasoning and the constrained context of a large language model, ensuring that the output question-and-answer results are accurate and reliable.
It improves the accuracy and reliability of question answering in the field of power safety, avoids the shortcomings of shallow matching and the illusion problem of large models, and ensures the professionalism and credibility of the output answers.
Smart Images

Figure CN122489689A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of artificial intelligence and natural language processing technology, specifically to an intelligent question-answering method and product for power safety based on knowledge graph-constrained reasoning. Background Technology
[0002] With the continuous expansion of the power grid and the increasing complexity of the system, power safety is facing unprecedented challenges. The power industry has accumulated a vast amount of safety regulations, operating guidelines, and accident case data. The ability to acquire and understand this knowledge in a timely and accurate manner is crucial for ensuring the personal safety of frontline workers and the stable operation of the power grid. Currently, power workers primarily acquire safety knowledge by manually reviewing paper regulations or performing simple keyword searches. However, these methods are not only inefficient and unable to handle complex question-and-answer needs in emergency situations, but also prone to introducing additional operational risks due to individual misunderstandings.
[0003] To improve knowledge acquisition efficiency, the industry has tried using intelligent question answering methods. Currently, the mainstream intelligent question answering methods are mainly divided into two categories: The first category is based on keyword matching or traditional search engines. These methods rely on shallow literal matching and have difficulty understanding complex semantic logic and users' deep query intentions, resulting in inaccurate search results that cannot meet actual business needs. The second category is methods that directly use general-purpose large language models (such as the GPT series). Although these methods have powerful language generation capabilities, they suffer from a serious hallucination problem. That is, in the absence of domain knowledge constraints, the model is prone to generating erroneous answers that are formally grammatically correct but substantially contradict the facts of power safety, and lack the professional depth and rigor required in the field of power safety.
[0004] Therefore, how to efficiently and accurately obtain reliable answers from massive amounts of power safety data through intelligent question answering methods has become a technical challenge that urgently needs to be overcome by those skilled in the art. Summary of the Invention
[0005] The purpose of this invention is to provide a power safety intelligent question answering method and product based on knowledge graph constrained reasoning, so as to overcome the problem that the output question answering results are not accurate and efficient due to insufficient semantic understanding in existing intelligent question answering methods.
[0006] The present invention solves the above-mentioned technical problems through the following technical solution: This invention provides a power safety intelligent question-answering method based on knowledge graph constrained reasoning, comprising the following steps: Based on data from the power safety field, we extract a sample set of entity relationship triples in the power field and construct a power safety knowledge graph. We then use the sample set of entity relationship triples in the power field to iteratively train the knowledge graph representation learning model to obtain entity embedding vectors and relationship embedding vectors. Extract the key entities of the power safety issue to be queried, locate the anchor entities corresponding to the key entities in the power safety knowledge graph, perform multi-hop path reasoning from the anchor entities in the power safety knowledge graph, calculate the correlation score between the anchor entities and other entities in the power safety knowledge graph based on entity embedding vectors and relation embedding vectors, retrieve the subgraph structures with correlation scores greater than a preset threshold, and convert the subgraph structures into constraint context in natural language form. The power safety question to be queried is concatenated with the constraint context through prompting engineering and input into the trained base language model. The base language model performs reasoning and generation under the constraints of the constraint context and outputs the final intelligent question answering result for power safety.
[0007] A further improvement of this invention lies in using a sample set of entity-relation triples from the power sector to iteratively train a knowledge graph representation learning model, obtaining entity embedding vectors and relation embedding vectors, including: Positive triplets and negative triplets generated by randomly replacing entities are constructed from a sample set of entity relationship triplets in the power sector. Positive and negative triplets are input into the knowledge graph representation learning model, and the loss value is calculated based on the hinge loss function. Based on the loss value, the parameters of the first knowledge graph representation learning model are updated using gradient descent until the preset number of iterations is reached, resulting in entity embedding vectors and relation embedding vectors.
[0008] A further improvement of this invention is that the knowledge graph representation learning model is the Qwen3-4b model; The hinge loss function is as follows:
[0009] in, Loss value Summation operation, For the set of positive triples, For the set of negative triples, The preset interval hyperparameter, This is a distance metric function.
[0010] A further improvement of this invention is that the trained base large language model is obtained through the following steps: Based on data from the field of power safety, the original problem and constraint context are spliced together by prompting engineering to construct an instruction fine-tuning dataset. The base large language model is then iteratively fine-tuned and trained using the low-rank adaptation method and gradient descent method to obtain a well-trained base large language model.
[0011] A further improvement of this invention is that the base language model is the Qwen3-8B model.
[0012] A further improvement of this invention lies in the correlation score between the anchor entity and other entities in the power safety knowledge graph, specifically:
[0013] Where N is the total number of entities in the power safety knowledge graph; Anchor point entity; These are the entities in the power knowledge graph other than the key entities. for and The correlation score; and They are respectively and The corresponding entity embedding vector; This is an operation for calculating cosine similarity. for and The reciprocal of the weights of the relation embedding vector; These are the preset weighting coefficients.
[0014] This invention also provides an intelligent question-answering system for power safety based on knowledge graph-constrained reasoning, comprising: The first module is used to extract a sample set of entity relationship triples in the power safety field based on data from the power safety field, and to construct a power safety knowledge graph. The sample set of entity relationship triples in the power safety field is used to iteratively train the knowledge graph representation learning model to obtain entity embedding vectors and relationship embedding vectors. The second module is used to extract the key entities of the power safety issue to be queried, locate the anchor entities corresponding to the key entities in the power safety knowledge graph, perform multi-hop path reasoning from the anchor entities in the power safety knowledge graph, calculate the correlation score between the anchor entities and other entities in the power safety knowledge graph based on entity embedding vectors and relation embedding vectors, retrieve the subgraph structures with correlation scores greater than a preset threshold, and convert the subgraph structures into constraint context in natural language form. The third module is used to concatenate the power safety question to be queried with the constraint context through prompting engineering, and input it into the trained base language model. The base language model performs reasoning and generation under the constraints of the constraint context, and outputs the final intelligent question answering result for power safety.
[0015] The present invention also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps of the above-described intelligent question-answering method for power safety based on knowledge graph constraint reasoning.
[0016] The present invention also provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of the above-described intelligent question-answering method for power safety based on knowledge graph constraint reasoning.
[0017] The present invention also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of the above-described intelligent question-answering method for power safety based on knowledge graph constraint reasoning.
[0018] Compared with the prior art, the positive and progressive effects of the present invention are as follows: The present invention provides an intelligent question-answering method for power safety based on knowledge graph constraint reasoning. By constructing a structured knowledge graph, training semantic embedding vectors, calculating entity correlation, reasoning about related subgraphs and converting them into natural language context, and finally generating answers using a large model under constraints, the method effectively solves the problems of accuracy and reliability of question answering in the field of power safety. Specifically, based on data from the power safety domain, a sample set of entity-relation triples is extracted and a power safety knowledge graph is constructed. This establishes a systematic representation of domain knowledge, providing a structured foundation for subsequent reasoning and ensuring comprehensive knowledge coverage. The sample set is used to train a knowledge graph representation learning model to obtain entity embedding vectors and relation embedding vectors. This encodes the semantic information of entities and relations into numerical form, facilitating efficient similarity calculation and avoiding the shortcomings of shallow matching. Key entities in the query are extracted and anchor entities are located. Relevance scores are calculated based on the embedding vectors, and highly relevant entities are selected through semantic similarity, reducing interference from irrelevant information. Multi-hop path reasoning is performed from the anchor entities in the knowledge graph to retrieve relevant subgraphs, transforming them into natural language constrained context. This provides reliable background constraints for generating answers, preventing illusions. The query and context are concatenated and input into a large-scale power domain model to generate answers under constraints. Combining the reasoning capabilities of the large-scale model with contextual limitations ensures accurate and reliable output. Attached Figure Description
[0019] The accompanying drawings are provided to further understand the invention and constitute a part of this invention. The illustrative embodiments of the invention and their descriptions are used to explain the invention and do not constitute an improper limitation of the invention.
[0020] Figure 1 This is a flowchart illustrating the intelligent question-answering method for power safety based on knowledge graph constraint reasoning, as described in this invention. Detailed Implementation
[0021] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0022] In the description of this invention, it should be understood that the terms "comprising" and "including" indicate the presence of the described features, integrals, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or collections thereof.
[0023] It should also be understood that the terminology used in this specification is for the purpose of describing particular embodiments only and is not intended to limit the invention. As used in this specification and the appended claims, the singular forms “a,” “an,” and “the” are intended to include the plural forms unless the context clearly indicates otherwise.
[0024] It should be understood that although terms such as first, second, third, etc., may be used in the embodiments of the present invention to describe the preset range, these preset ranges should not be limited to these terms. These terms are only used to distinguish the preset ranges from one another. For example, without departing from the scope of the embodiments of the present invention, the first preset range may also be referred to as the second preset range, and similarly, the second preset range may also be referred to as the first preset range.
[0025] Depending on the context, the word "if" as used here can be interpreted as "when," "when," "in response to determination," or "in response to detection." Similarly, depending on the context, the phrase "if determination" or "if detection (of the stated condition or event)" can be interpreted as "when determination," "in response to determination," "when detection (of the stated condition or event)," or "in response to detection (of the stated condition or event)."
[0026] The present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments. This is an explanation of the present invention and not a limitation thereof.
[0027] See Figure 1 This invention provides a power safety intelligent question-answering method based on knowledge graph constrained reasoning, comprising the following steps: Based on data from the power safety field, we extract a sample set of entity relationship triples in the power field and construct a power safety knowledge graph. We then use the sample set of entity relationship triples in the power field to iteratively train the knowledge graph representation learning model to obtain entity embedding vectors and relationship embedding vectors. Extract the key entities of the power safety issue to be queried, locate the anchor entities corresponding to the key entities in the power safety knowledge graph, perform multi-hop path reasoning from the anchor entities in the power safety knowledge graph, calculate the correlation score between the anchor entities and other entities in the power safety knowledge graph based on entity embedding vectors and relation embedding vectors, retrieve the subgraph structures with correlation scores greater than a preset threshold, and convert the subgraph structures into constraint context in natural language form. The power safety question to be queried is concatenated with the constraint context through prompting engineering and input into the trained base language model. The base language model performs reasoning and generation under the constraints of the constraint context and outputs the final intelligent question answering result for power safety.
[0028] The method of this invention effectively solves the problems of accuracy and reliability of question answering in the field of power safety by constructing a structured knowledge graph, training semantic embedding vectors, calculating entity association degree, reasoning related subgraphs and converting them into natural language context, and finally generating answers using a large model under constraints. Specifically, a knowledge graph for power safety is constructed based on data from the power safety domain, and a sample set of entity-relationship triples is extracted. This establishes a systematic representation of domain knowledge, providing a structured foundation for subsequent reasoning and ensuring comprehensive knowledge coverage. The knowledge graph representation learning model is trained using the sample set to obtain entity embedding vectors and relation embedding vectors. This encodes the semantic information of entities and relations into numerical form, facilitating efficient similarity calculation and avoiding the shortcomings of shallow matching. Key entities for the query are extracted, and anchor entities are located. Relevance scores are calculated based on the embedding vectors, and highly relevant entities are selected through semantic similarity, reducing interference from irrelevant information. Multi-hop path reasoning is performed from the anchor entities in the knowledge graph to retrieve relevant subgraphs, transforming them into natural language constrained context. This provides reliable background constraints for generating answers, preventing illusions. The query and context are concatenated and input into a large-scale micro-power domain model to generate answers under constraints. Combining the reasoning capabilities of the large model with contextual limitations ensures accurate and reliable output.
[0029] Specifically, the knowledge graph representation learning model is iteratively trained using a sample set of entity-relation triples from the power sector to obtain entity embedding vectors and relation embedding vectors, including: Positive triplets and negative triplets generated by randomly replacing entities are constructed from a sample set of entity relationship triplets in the power sector. Positive and negative triplets are input into the knowledge graph representation learning model, and the loss value is calculated based on the hinge loss function. Based on the loss value, the parameters of the first knowledge graph representation learning model are updated using gradient descent until the preset number of iterations is reached, resulting in entity embedding vectors and relation embedding vectors.
[0030] By refining the training process of the knowledge graph representation learning model, the problem of insufficient embedding vector quality is addressed, thereby improving the accuracy of subsequent question-answering reasoning. Specifically, positive triples are constructed from a sample set of entity relationship triples in the power sector, ensuring that the training data is based on real power safety knowledge and preserving the semantic authenticity of entity relationships. Simultaneously, negative triples generated by randomly replacing entities are introduced through a simple and efficient method of constructing negative examples, forcing the model to learn to distinguish between positive and negative relationships during training, avoiding overfitting and enhancing the robustness of the representation. The positive and negative triples are input into the knowledge graph representation learning model, and the loss value is calculated based on the hinge loss function. The hinge loss function forces the model to maximize the score interval between positive and negative examples during optimization, strengthening the model's discriminative ability and ensuring that the embedding vectors accurately capture subtle differences in relationships between entities, reducing semantic representation errors. Based on the loss value, the parameters of the first knowledge graph representation learning model are updated using gradient descent. The model weights are gradually adjusted through the gradient descent optimization algorithm to achieve efficient convergence. This continues until the preset number of iterations is reached, controlling the training process to avoid underfitting or overfitting. Finally, high-quality and stable entity embedding vectors and relation embedding vectors are obtained, providing a reliable foundation for subsequent correlation calculations, thereby improving the performance of the entire question answering system.
[0031] Specifically, the knowledge graph representation learning model is the Qwen3-4b model; The hinge loss function is as follows:
[0032] in, Loss value Summation operation, For the set of positive triples, For the set of negative triples, The preset interval hyperparameter, This is a distance metric function.
[0033] By concretizing the knowledge graph representation learning model and the hinge loss function, the training process was optimized, improving the quality of entity and relation embedding vectors. The knowledge graph representation learning model was specified as the Qwen3-4b model. This model, as a pre-trained model, can efficiently capture the deep semantic features of entities and relations in the power safety domain, thereby generating more accurate embedding representations during iterative training and avoiding representation bias caused by insufficient model generality. A hinge loss function was defined, which calculates the distance difference between the positive and negative triplet sets and introduces a margin hyperparameter γ to ensure that the distance value of positive examples is less than the distance value of negative examples minus γ. This helps the model distinguish between positive and negative samples during training, strengthens the discriminative ability of the embedding vectors, reduces training instability, improves embedding quality, and lays a reliable foundation for subsequent multi-hop path reasoning and question answering generation.
[0034] Specifically, the trained base language model is obtained through the following steps: Based on data from the field of power safety, the original problem and constraint context are spliced together by prompting engineering to construct an instruction fine-tuning dataset. The base large language model is then iteratively fine-tuned and trained using the low-rank adaptation method and gradient descent method to obtain a well-trained base large language model.
[0035] By optimizing the fine-tuning training process, the model is ensured to accurately generate answers under the knowledge constraints of the power safety domain, avoiding the illusion problem. Specifically, an instruction fine-tuning dataset is constructed based on power safety domain data. This provides domain-relevant structured training samples, enabling the model to learn professional knowledge and contextual relationships in power safety, thereby enhancing domain adaptability. The base language model is iteratively fine-tuned using a combination of low-rank adaptation and gradient descent. Low-rank adaptation reduces parameter updates through low-rank decomposition, improving training efficiency and reducing the risk of overfitting. Gradient descent gradually adjusts the model weights, ensuring that the model parameters converge to the optimal state during iteration. Ultimately, this combined approach achieves efficient iterative training, resulting in a well-trained base language model that can effectively utilize constrained context in subsequent inference to generate accurate and reliable question-and-answer results.
[0036] Specifically, the base language model is the Qwen3-8B model.
[0037] By specifying the base language model as the Qwen3-8B model, this model, as the basic architecture, can better adapt to the professional needs of the power safety field during fine-tuning training, reduce the possibility of model-generated content that does not conform to the facts, and improve the reliability and rigor of reasoning generation under constrained contexts.
[0038] Specifically, the correlation score between the anchor entity and other entities in the power safety knowledge graph is as follows:
[0039] Where N is the total number of entities in the power safety knowledge graph; Anchor point entity; These are the entities in the power knowledge graph other than the key entities. for and The correlation score; and They are respectively and The corresponding entity embedding vector; This is an operation for calculating cosine similarity. for and The reciprocal of the weights of the relation embedding vector; These are the preset weighting coefficients.
[0040] This invention also provides an intelligent question-answering system for power safety based on knowledge graph-constrained reasoning, comprising: The first module is used to extract a sample set of entity relationship triples in the power safety field based on data from the power safety field, and to construct a power safety knowledge graph. The sample set of entity relationship triples in the power safety field is used to iteratively train the knowledge graph representation learning model to obtain entity embedding vectors and relationship embedding vectors. The second module is used to extract the key entities of the power safety issue to be queried, locate the anchor entities corresponding to the key entities in the power safety knowledge graph, perform multi-hop path reasoning from the anchor entities in the power safety knowledge graph, calculate the correlation score between the anchor entities and other entities in the power safety knowledge graph based on entity embedding vectors and relation embedding vectors, retrieve the subgraph structures with correlation scores greater than a preset threshold, and convert the subgraph structures into constraint context in natural language form. The third module is used to concatenate the power safety question to be queried with the constraint context through prompting engineering, and input it into the trained base language model. The base language model performs reasoning and generation under the constraints of the constraint context, and outputs the final intelligent question answering result for power safety.
[0041] This invention addresses the challenges of accuracy and efficiency in intelligent question answering within the power safety field through a systematic modular design. Its core lies in combining the structured constraints of knowledge graphs with the reasoning capabilities of large language models to avoid shallow matching and illusion problems. Firstly, the system utilizes knowledge graph construction and embedding learning to capture domain semantics. Then, it extracts relevant subgraphs as constraint context through multi-hop reasoning. Finally, it leverages a large power domain model to generate answers under these constraints, ensuring reliable and professional output.
[0042] In a specific embodiment of the present invention, a power safety intelligent question-answering method based on knowledge graph constrained reasoning includes the following steps: Step 1: Collect power safety work procedures, equipment operation manuals, and historical accident cases; perform data cleaning and structuring to obtain a sample set of entity-relationship triples in the power field; construct a power safety knowledge graph; select the Qwen3-4b model as the knowledge graph representation learning model, and train it using the triple sample set to obtain vector representations of entities and relations; specifically: We collect power safety work procedures, equipment operation manuals, and historical accident cases, perform data cleaning and structuring processing, obtain a sample set of entity relationship triples in the power field, and construct a power safety knowledge graph; the triples are represented as follows: Where h represents the head entity, r represents the relation, and t represents the tail entity; The Qwen3-4b model was chosen as the knowledge graph representation learning model. The goal of the Qwen3-4b model is to map entities and relations in the knowledge graph to a low-dimensional continuous vector space, making... The triplet sample set is input into the Qwen3-4b model, and the model is iteratively trained using gradient descent to obtain trained entity embedding vectors and relation embedding vectors. The gradient descent method is used to iteratively train the model, as follows: Let the knowledge graph represent the learning model after... The parameters obtained in the next iteration are Initialize the number of iterations And set the maximum number of iterations for the knowledge graph representation learning model to be [value]. ( ); Initialize the vector representations of entities and relations using normally distributed random numbers with a mean of 0 and a variance of 0.01; Obtain real-existing positive triplets from the sample set. Construct a set of positive examples S; and for each positive triplet, generate negative triplets by randomly replacing the entities. Forming a set of negative examples ; The hinge loss function (Margin-based Ranking Loss) is calculated using the following formula:
[0043]
[0044] in, Indicates the loss value. This represents the summation operation. Let be the set of positive examples. For the set of negative examples, This is the preset interval hyperparameter (margin). For distance measurement functions (such as L1 or L2 norm); Update each parameter of the model according to the following formula:
[0045] in, This represents the updated values of the model parameters. For learning rate, This represents the gradient of the loss function with respect to the parameters; Determine if the current iteration count has reached the set maximum iteration count. If yes, obtain the trained knowledge representation model, and then obtain the trained entity embedding vector and relation embedding vector. If no, let k = k + 1 and return to calculate the hinge loss function.
[0046] Step 2: Construct a knowledge graph-based constrained reasoning module. This module includes a path search algorithm and a logical verification mechanism. It uses entity recognition technology to extract key entities from the queried power safety issue, locates anchor entities in the power safety knowledge graph, and uses Named Entity Recognition (NER) technology to extract key entities (such as transformers and operation tickets). It then locates anchor points in the knowledge graph and uses the constrained reasoning module to perform multi-hop path reasoning within the knowledge graph. Finally, it calculates the association score between the anchor entity and other entities in the knowledge graph using the following formula:
[0047] Step 3: Retrieve subgraph structures with a score greater than the threshold θ, and convert the triples in the subgraphs into natural language text to form a constraint context; Step 4: Select Qwen3-8B as the base large language model and construct the instruction fine-tuning dataset. Utilize the Low-Rank Adaptation (LoRA) method for efficient fine-tuning training of the base model: input each sample from the dataset into the model batch by batch, and iteratively update the LoRA parameters through gradient descent to finally obtain a base large language model adapted to the power industry. Specifically: Qwen3-8B was selected as the base large language model; the Qwen3-8B network includes an embedding layer, a multi-layer Transformer Decoder block, and an output head layer; the Transformer Decoder block consists of a layer normalization layer (LayerNorm), a multi-head attention mechanism (Multi-Head Attention), a residual connection, and a feed-forward network.
[0048] The instruction fine-tuning dataset is input into the base large language model, and the base large model is iteratively fine-tuned and trained using the low-rank adaptation (LoRA) method combined with gradient descent, resulting in a trained base large language model, as follows: Most parameters of the base model are frozen, and only low-rank decomposition matrices A and B are added as bypasses to the Q and V matrices of the Multi-Head Attention mechanism. The cross-entropy loss of the base large language model is calculated using the following formula:
[0049] Where X represents the input question and instruction. For the target output sequence, the first There are 10 tokens, where N is the sequence length and P is the conditional probability.
[0050] By concatenating the original problem and the constraint context through hint engineering, an instruction fine-tuning dataset in the following format is constructed: "[Instruction]: You are an electrical safety expert. Please answer the questions based on the following knowledge graph information. Fabrication is strictly prohibited."
[0051] [Known Information]: {Constraint Context} [Question]: {Power safety issue to be queried} [Answer]: {Standard Answer} Step 5: In practical reasoning applications, the user's original question and the retrieved constraint context are concatenated into a specified format through prompt engineering. This is then input into the trained base language model. The model performs reasoning and generation under the constraints of the constraint context, ultimately outputting the intelligent question-answering result for power safety. The specific format is as follows: "[Instruction]: You are an electrical safety expert. Please answer the questions based on the following knowledge graph information. Fabrication is strictly prohibited."
[0052] [Known Information]: {Constraint Context} [Question]: {Power safety issue to be queried} [answer]:" The model will automatically generate the [answer] as the final output.
[0053] This method introduces knowledge graphs as hard constraints, and by explicitly constraining the generation process of large models through reasoning paths, it overcomes the shortcomings of existing large model technologies such as factual illusion and logical unreliability, and significantly improves the accuracy of power safety question answering. By adopting knowledge graph-based constraint reasoning, it can handle complex problems involving the association of multiple devices and regulations, and overcomes the shortcomings of traditional keyword retrieval in handling logical reasoning problems.
[0054] The following simulation experiments further illustrate the effectiveness of this invention: Simulation experiment conditions: Hardware platform: Intel Xeon Gold 6248R processor, NVIDIA A100 GPU (40GB video memory), 128GB memory.
[0055] The software platform consists of: Ubuntu 20.04 operating system, PyTorch 1.13 deep learning framework, and Neo4j graph database.
[0056] The data in the field of power safety includes the "Safety Regulations" (substation section and line section), typical violation examples, and power safety accident reports from the past five years. The constructed knowledge graph contains 24,000 entities and 115,000 relationships.
[0057] Simulation content and results: The method of this invention, traditional keyword retrieval methods, and a general large model (Baseline) without knowledge graph constraints were used to answer 500 power safety test questions. The test questions covered three categories: concept explanation, operational procedure query, and fault emergency handling. Three senior power safety engineers scored the accuracy and safety (i.e., no misleading information) of the answers (out of 100) and calculated the average inference time. The results are shown in Table 1. Table 1. Comparison of Performance of Different Question-Answering Methods
[0058] Table 1 shows that the accuracy score reflects whether the answer correctly covers the knowledge points, while the security score reflects whether the answer contains serious errors that mislead the user. As can be seen from Table 1, traditional keyword retrieval has low accuracy when handling complex processes and emergency response questions; while the general-purpose large model has strong language organization capabilities, it has a low security score, indicating a significant risk of misleading responses. The method of this invention, by combining constrained reasoning from a knowledge graph, maintains high accuracy while significantly outperforming the general-purpose large model in terms of security score, and its reasoning time is approximately 1.13 seconds, meeting the requirements of real-time question answering. This demonstrates that this invention can combine the understanding capabilities of a large model with the precise facts of a knowledge graph, making it particularly suitable for power scenarios with extremely high security requirements.
[0059] Based on the same inventive concept, this application provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the steps of a knowledge graph-based constrained reasoning intelligent question-answering method for power safety. The memory may include main memory, such as high-speed random access memory, or it may also include non-volatile memory, such as at least one disk storage device. The processor, network interface, and memory are interconnected via an internal bus, which may be an industry-standard architecture bus, a peripheral component interconnection standard bus, an extended industry-standard architecture bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. The memory stores the program; specifically, the program may include program code, which includes computer operation instructions. The memory may include main memory and non-volatile memory, and provides instructions and data to the processor.
[0060] Based on the same inventive concept, embodiments of this application provide a computer-readable storage medium storing a computer program. When executed by a processor, the computer program implements the steps of the power safety intelligent question-answering method based on knowledge graph constraint reasoning. Specifically, the computer-readable storage medium includes, but is not limited to, volatile memory and / or non-volatile memory. The volatile memory may include RAM (Random Access Memory) and / or cache memory, etc. The non-volatile memory may include ROM (Read-Only Memory), hard disk, flash memory, optical disk, magnetic disk, etc.
[0061] Based on the same inventive concept, this application provides a computer program product, which includes a computer program stored on a computer-readable storage medium. The computer program includes program instructions, which, when executed by a computer device, cause the computer device to perform the steps of the above-described intelligent question-answering method for power safety based on knowledge graph constraint reasoning.
[0062] Those skilled in the art will understand that embodiments of the present invention can be provided as methods or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM (Compact Disc Read-Only Memory), optical storage, etc.) containing computer-usable program code.
[0063] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, as well as combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer apparatus or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0064] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer device or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0065] These computer program instructions may also be loaded onto a computer device or other programmable data processing equipment to cause a series of operational steps to be performed on the computer device or other programmable equipment to produce a process implemented by the computer device, thereby providing instructions that execute on the computer device or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0066] Although preferred embodiments of the invention have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including both the preferred embodiments and all changes and modifications falling within the scope of the invention.
[0067] Obviously, those skilled in the art can make various modifications and variations to this invention without departing from its spirit and scope. Therefore, if these modifications and variations fall within the scope of the claims of this invention and their equivalents, this invention also intends to include these modifications and variations.
Claims
1. A power safety intelligent question-answering method based on knowledge graph constrained reasoning, characterized in that, Includes the following steps: Based on data from the power safety field, a sample set of triplet entity relationships in the power field is extracted to construct a power safety knowledge graph; The knowledge graph representation learning model is iteratively trained using a sample set of entity relationship triples in the power sector to obtain entity embedding vectors and relationship embedding vectors. Extract the key entities of the power safety issue to be queried, locate the anchor entities corresponding to the key entities in the power safety knowledge graph, perform multi-hop path reasoning from the anchor entities in the power safety knowledge graph, calculate the correlation score between the anchor entities and other entities in the power safety knowledge graph based on entity embedding vectors and relation embedding vectors, retrieve the subgraph structures with correlation scores greater than a preset threshold, and convert the subgraph structures into constraint context in natural language form. The power safety question to be queried is concatenated with the constraint context through prompting engineering and input into the trained base language model. The base language model performs reasoning and generation under the constraints of the constraint context and outputs the final intelligent question answering result for power safety.
2. The intelligent question-answering method for power safety based on knowledge graph constrained reasoning according to claim 1, characterized in that, The knowledge graph representation learning model is iteratively trained using a sample set of entity-relation triples in the power sector to obtain entity embedding vectors and relation embedding vectors, including: Positive triplets and negative triplets generated by randomly replacing entities are constructed from a sample set of entity relationship triplets in the power sector. Positive and negative triplets are input into the knowledge graph representation learning model, and the loss value is calculated based on the hinge loss function. Based on the loss value, the parameters of the first knowledge graph representation learning model are updated using gradient descent until the preset number of iterations is reached, resulting in entity embedding vectors and relation embedding vectors.
3. The intelligent question-answering method for power safety based on knowledge graph constrained reasoning according to claim 1, characterized in that, The knowledge graph representation learning model is the Qwen3-4b model; The hinge loss function is as follows: in, Loss value Summation operation, For the set of positive triples, For the set of negative triples, The preset interval hyperparameter, This is a distance metric function.
4. The intelligent question-answering method for power safety based on knowledge graph constrained reasoning according to claim 1, characterized in that, The trained base language model is obtained through the following steps: Based on data from the field of power safety, the original problem and constraint context are spliced together by prompting engineering to construct an instruction fine-tuning dataset. The base large language model is then iteratively fine-tuned and trained by combining the low-rank adaptation method and the gradient descent method to obtain a well-trained base large language model.
5. The intelligent question-answering method for power safety based on knowledge graph constrained reasoning according to claim 1, characterized in that, The base language model is the Qwen3-8B model.
6. The intelligent question-answering method for power safety based on knowledge graph constrained reasoning according to claim 1, characterized in that, The correlation score between the anchor entity and other entities in the power safety knowledge graph is as follows: Where N is the total number of entities in the power safety knowledge graph; Anchor point entity; These are the entities in the power knowledge graph other than the key entities. for and The correlation score; and They are respectively and The corresponding entity embedding vector; This is an operation for calculating cosine similarity. for and The reciprocal of the weights of the relation embedding vector; These are the preset weighting coefficients.
7. A power safety intelligent question-answering system based on knowledge graph constrained reasoning, characterized in that, include: The first module is used to extract a sample set of entity relationship triples in the power field based on data in the power security field, and to construct a power security knowledge graph. The knowledge graph representation learning model is iteratively trained using a sample set of entity relationship triples in the power sector to obtain entity embedding vectors and relationship embedding vectors. The second module is used to extract the key entities of the power safety issue to be queried, locate the anchor entities corresponding to the key entities in the power safety knowledge graph, perform multi-hop path reasoning from the anchor entities in the power safety knowledge graph, calculate the correlation score between the anchor entities and other entities in the power safety knowledge graph based on entity embedding vectors and relation embedding vectors, retrieve the subgraph structures with correlation scores greater than a preset threshold, and convert the subgraph structures into constraint context in natural language form. The third module is used to concatenate the power safety question to be queried with the constraint context through prompting engineering, and input it into the trained base language model. The base language model performs reasoning and generation under the constraints of the constraint context, and outputs the final intelligent question answering result for power safety.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the intelligent question-answering method for power safety based on knowledge graph constraint reasoning as described in any one of claims 1 to 6.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the steps of the intelligent question-answering method for power safety based on knowledge graph constraint reasoning as described in any one of claims 1 to 6.
10. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by the processor, it implements the steps of the intelligent question-answering method for power safety based on knowledge graph constraint reasoning as described in any one of claims 1 to 6.