Low-resource natural language-to-SPARQL generation method and system based on remote supervision pruning and confidence transfer
By employing remote supervised pruning and confidence propagation, combined with lightweight graph pruning and quantized language models, the problem of Text-to-SPARQL generation in low-resource environments is solved. This enables efficient and accurate SPARQL query generation on consumer-grade graphics cards, reducing the risks of knowledge illusion and logical breaks.
Patent Information
- Application Number
- CN202610126094.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-01-29
- Publication Date
- 2026-05-22
AI Technical Summary
Existing Text-to-SPARQL generation methods face problems such as knowledge illusion in generative models, resource efficiency bottlenecks, and inefficiency of blind correction mechanisms in low-resource environments, making it difficult to deploy and generate accurate SPARQL query statements on consumer-grade graphics cards.
We employ a method based on remote supervised pruning and confidence propagation. Through an end-to-end framework with lightweight graph pruning planning and large model generation capabilities, combined with graph attention networks and quantized language models, we perform entity linking, semantic feature fusion, and adaptive correction to generate efficient and accurate SPARQL query statements.
It achieves efficient and accurate SPARQL generation in low-resource environments, reduces the risk of knowledge illusion and logical breaks, improves query accuracy and the targeted nature of error correction, and is suitable for hardware environments with limited video memory.
Smart Images

Figure CN122072660A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the fields of natural language processing and knowledge graphs, and relates to a low-resource natural language to SPARQL generation method and system based on remote supervised pruning and confidence propagation. It is suitable for performing complex knowledge base question answering tasks in hardware environments with limited video memory. Background Technology
[0002] With the rapid development of Knowledge Graph (KG) technology, knowledge graph question answering has become an important bridge connecting users' natural language and structured knowledge. The Text-to-SPARQL task aims to transform users' natural language questions into standard SPARQL queries that can be executed on a knowledge graph database, thereby obtaining accurate answers. This technology has broad application prospects in search engines, intelligent customer service, and vertical domain expert systems.
[0003] However, existing Text-to-SPARQL generation methods still face the following serious challenges in practical applications, especially in scenarios with limited computing resources (such as consumer-grade graphics cards): (1) Knowledge Hallucination and Structure Mismatch in Generative Models: Although large language models (LLMs) perform well in natural language understanding, they often suffer from knowledge hallucination when dealing with strongly constrained structured queries. LLMs tend to generate entities or relations that do not exist in the knowledge graph schema (Schema Hallucination), which makes the generated SPARQL statements unable to be executed in the database. In addition, simple retrieval augmentation generation (RAG) methods usually only retrieve static triples as context, ignoring the topological structure information of the graph, making it difficult to guide the model to handle complex problems that require multi-hop reasoning, and easily leading to the breakage of intermediate logical chains.
[0004] (2) Resource efficiency bottleneck of graph search methods: To address the inference depth problem, existing works (such as Think-on-Graph) propose using LLMs as agents to perform beam search on the graph to plan inference paths. However, this "thinking on the graph" mode usually requires traversing a huge search space, resulting in high inference latency and significant consumption of GPU memory. On consumer-grade hardware (such as GPUs with 6GB or 8GB of memory), these methods that rely on large parameter models for full graph search are difficult to deploy and cannot meet the practical needs of "green AI" and low-resource inference.
[0005] (3) Lack of targeted blind correction mechanism: Existing self-correction methods typically employ a simple entity and relation substitution (ERR) algorithm or a random deletion filter strategy when the query result is empty, to address the potential errors in generated SPARQL statements. However, this correction mechanism is often "blind," lacking precise diagnosis of the cause of the error. The system cannot distinguish whether the query failure is due to overly strict logical conditions or an error in the reasoning path itself, leading to inefficient correction and potentially even modifying previously correct logic into incorrect logic, further reducing query accuracy.
[0006] In summary, existing Knowledge Graph Question Answering (KGQA) technologies face multiple challenges in Text-to-SPARQL tasks: First, mainstream Generative Large Models (LLMs) have a huge number of parameters and high memory consumption for inference, making them difficult to deploy on consumer-grade GPUs; second, general-purpose large models lack the ability to perceive specific knowledge graph schemas, easily generating "illusion" queries containing non-existent entities or relationships, and are prone to logical chain breaks when dealing with multi-hop complex problems; third, existing graph inference methods usually rely on full graph search or training graph neural networks with a large amount of manually labeled data, which is costly and inefficient; finally, traditional post-generation correction mechanisms often adopt blind random deletion or retry strategies, lacking accurate diagnosis of error types, resulting in low correction success rates.
[0007] In summary, existing technologies struggle to simultaneously ensure accuracy in generation, legality in structure, and efficiency in reasoning under low-resource conditions. Therefore, there is an urgent need for a Text-to-SPARQL generation method that can effectively utilize graph structure information for lightweight pruning and possess intelligent feedback correction capabilities. Summary of the Invention
[0008] In view of this, the purpose of this invention is to provide a low-resource natural language to SPARQL generation method and system based on remote supervised pruning and confidence propagation. It combines an end-to-end framework with lightweight graph pruning planning and large model generation capabilities, trains the pruner through remote supervision signals, and introduces a confidence propagation mechanism to guide feedback correction, thereby achieving efficient and accurate SPARQL generation in low-resource environments.
[0009] To achieve the above objectives, the present invention provides the following technical solution: A low-resource natural language to SPARQL generation method based on remote supervised pruning and confidence propagation, the method includes the following steps: S1. Obtain the natural language question input by the user, use the inverted index mechanism to map the entities in the natural language question to anchor entities in the knowledge graph, and extract entities centered on the anchor entities. Use the skip neighborhood as the initial subgraph; S2. A pre-trained semantic coding model is used to transform the natural language question and the initial subgraph into question semantic vectors and relation feature vectors. An improved graph attention network model is used to perform structured collaborative pruning based on semantic injection on the fused features of the two to obtain attribute-enhanced reasoning subgraphs. S3. Vectorize the natural language question and retrieve semantically similar question-answer pairs from the historical question-answer database as examples. Use the examples and reasoning subgraphs together as structured constraint contexts, input them into the quantized large language model, and generate the initial SPARQL query statement. S4. Establish a dual feedback correction mechanism based on confidence propagation. In this mechanism, a query confidence profile is established based on the semantic similarity between the relational predicates in the query statement and the relation in the knowledge graph. When the initial SPARQL query statement is empty, the execution logic relaxation strategy or path correction strategy is adaptively selected based on the query confidence profile to obtain the final SPARQL query statement.
[0010] Furthermore, in step S1, the process of generating entity links and the initial subgraph is as follows: The system receives a natural language question Q from the user, performs word segmentation on Q, uses a pre-built inverted index to retrieve n-gram fragments from the question as query terms, and searches for candidate entities in the knowledge graph. It then calculates the edit distance between the candidate entity and the mentioned characters, as well as the entity's popularity, and selects the entity with the highest score as the anchor entity. ; anchor point entity Centered on the knowledge graph, perform a breadth-first search to extract anchor entities. Jump to all triples in the neighborhood and construct the initial subgraph. If the number of nodes in the initial subgraph exceeds the preset threshold, the nodes are truncated according to their degree in the graph, with priority given to retaining high-frequency nodes.
[0011] Furthermore, in step S2, a pre-trained lightweight semantic encoding model is used to extract the question semantic vector and relation feature vector. Specifically, a pre-trained lightweight language encoding model is used to encode the natural language question Q to obtain the question semantic vector. ,in The representation dimension is set considering semantic representation capability and the floating-point computation cost of feature fusion and attention calculation. For each edge in the initial subgraph , and its relation type r Input a learnable embedding layer to obtain relational feature vectors. ; Then, the problem semantic vector is fused with the relation feature vector of each edge to generate a fused feature vector that incorporates the problem context. The process includes: Perform vector fusion to inject the semantics of the problem into the graph structure features:
[0012] In the formula, "Indicates a splicing operation, For linear projection matrices, the stitched matrix will be... dimensional vector mapping back Dimension, generating fused feature vectors , The bias vector of the linear projection layer; Next, the fused feature vector is directly used as the input feature of the corresponding node in the graph attention network, and the correlation coefficient between the target node and its neighboring nodes in the fused feature space is calculated through a multi-head attention mechanism:
[0013] In the formula, It is a non-linear activation function. This is the weight matrix of the GAT layer. For attention vectors, and Representing the target nodes respectively and its neighboring nodes The fusion feature vector generated in the preceding steps; The coefficients are converted into attention weights after normalization:
[0014] Weight This reflects the relationship edge in the current problem context. r The importance of reasoning path; Finally, based on attention weights The initial subgraph is subjected to Top-K retention, which adopts an attribute-accompanying retention strategy: if a relation edge is retained, the attribute node connected to that relation edge is forcibly retained; at the same time, date and numeric attribute values are retained in their entirety first; for long text attribute values, if they exceed a preset length threshold, they are truncated; finally, an attribute-enhanced inference subgraph is generated.
[0015] Furthermore, the graph attention network model in step S2 is trained and optimized based on remote supervision signals. The process of constructing remote supervision signals includes: First, the standard SPARQL query statements in the training set are analyzed to extract the core predicate sequence; Then, the core predicate sequence is mapped back to the knowledge graph subgraph of the training samples, and all entity paths that match the predicate sequence and point to the correct answer are searched. Then mark the relation edges on the matching path as positive samples, and mark the remaining relation edges in the subgraph as negative samples; Finally, a binary classification loss function is constructed based on positive and negative samples to train the graph attention network model, enabling it to identify key inference paths. The binary cross-entropy loss function is expressed as follows:
[0016] in, Preserve the edge probabilities in the model output, i.e. ; Representing relation edges The true label value is determined by marking the edge as 1 if it belongs to the correct inference path, and 0 otherwise. Let | be the set of all relation edges in the current training sample subgraph. | represents the total number of relation edges in this set.
[0017] Furthermore, in step S3, all questions in the historical question-answering database are vectorized in advance using a semantic encoding model, and an efficient vector index library is constructed. During the reasoning phase, an approximate nearest neighbor search algorithm is used to retrieve questions semantically related to the current input question. The top-N most similar historical question-answer pairs are used as examples; the retrieved similar question-answer pairs are used as Few-shot examples and assembled with the generated attribute-enhanced inference subgraph to form a Prompt; the assembled Prompt is input into the quantized large language model, and the initial SPARQL query statement is generated based on the structural constraints in the Prompt.
[0018] Furthermore, in step S4, the process of constructing the query confidence profile is as follows: Before executing the query, the generated SPARQL statement is parsed, and each relation predicate is checked to see if it exists in the schema of the knowledge graph. If it exists, the confidence is 1; if it does not exist, the semantic similarity score between the generated predicate and the candidate relations in the knowledge graph is calculated; then, the matching status or similarity scores of all relation predicates are combined, and similar candidate replacement errors are performed to form the query confidence profile.
[0019] Furthermore, in step S4, the process of adaptively selecting the execution logic relaxation strategy or the path correction strategy includes: Execute the initial SPARQL statement on the knowledge graph engine. If the execution is successful and there is a result, output it directly; if the execution result is an empty set, proceed to the adaptive correction process. Decisions are made based on the uncertainty distribution in the query confidence profile. If the profile shows that the similarity scores of all relation predicates are higher than the preset confidence threshold, the query failure is determined to be due to overly strict logical constraints. The FILTER filter condition in the SPARQL query statement is removed or relaxed first. If the profile shows that the similarity score of at least one relation predicate is lower than the confidence threshold, the query failure is determined to be due to an incorrect inference path. Relation paths with similarity scores lower than the confidence threshold are truncated or rolled back first, and the query path is regenerated.
[0020] On the other hand, a system is also provided for executing the aforementioned low-resource natural language to SPARQL generation method based on remote supervised pruning and confidence propagation. This system includes a graph preprocessing module, a structured pruning module, a generative inference module, and an adaptive feedback module. The graph preprocessing module is configured to access the knowledge graph database, perform entity linking operations, and extract the K-hop neighborhood centered on the anchor entity as the initial subgraph. The structured pruning module has a built-in pre-trained graph attention network model, which calls the semantic encoding model to extract the semantic vector of the question and the feature vector of the relationship respectively, and performs feature fusion operation; and inputs the fused features into the graph network to calculate attention weights, thereby denoising and pruning the initial subgraph and outputting an attribute-enhanced inference subgraph. The generative reasoning module integrates a vector index library and a quantized large language model, which is used to retrieve similar examples and generate initial SPARQL query statements by combining the reasoning subgraph. The adaptive feedback module first parses the SPARQL statement and constructs a query confidence profile. Based on the status of the execution result and the distribution of the confidence profile, it dynamically schedules the logical relaxation algorithm or the path correction algorithm to output the final query result.
[0021] The beneficial effects of this invention are as follows: This invention overcomes the inference bottleneck in low-resource hardware environments: it abandons the energy-intensive methods of traditional large-model brute-force fine-tuning or large-scale graph search, and adopts a combined architecture of "lightweight GNN pruning + quantized LLM generation". GNN pruning greatly compresses the length of the input context, and the quantized model reduces the memory requirements, enabling the complete Text-to-SPARQL inference process to run smoothly on low-memory consumer-grade hardware, which has extremely high engineering application value and promotion significance.
[0022] This invention achieves high-precision structured pruning under unsupervised conditions: Addressing the difficulty of acquiring training data for graph neural networks, this invention proposes a remotely supervised training strategy. This strategy eliminates the need for manual annotation of nodes in the subgraph; instead, it utilizes existing standard query statements to infer the supervision signal, achieving low-cost and high-efficiency model cold start. Simultaneously, the introduced dual-tower feature interaction mechanism enables the GNN to fully understand the semantics of natural language questions, thereby more accurately preserving key inference paths.
[0023] This invention significantly reduces the risks of knowledge illusion and logical breaks, and improves query accuracy: Instead of directly relying on the internal knowledge of the LLM for reasoning, this invention uses attribute-enhanced reasoning subgraphs generated by GAT as strong constraints to guide LLM generation. This "retrieval-pruning-generation" paradigm ensures that the relationships and entities in the generated SPARQL statements are strictly derived from the knowledge graph, fundamentally suppressing schema-level illusions. Simultaneously, the retained attribute nodes provide necessary data support for problems involving numerical comparisons, avoiding logical generation failures due to missing data.
[0024] This invention enhances the targeting and intelligence of error correction: unlike the random correction strategies in existing technologies, this invention introduces a confidence propagation mechanism. This adaptive correction strategy avoids the erroneous deletion of key filtering conditions, significantly improving execution accuracy in complex multi-hop, constrained query scenarios.
[0025] Other advantages, objectives, and features of the invention will be set forth in part in the description which follows, and in part will be apparent to those skilled in the art from the following examination, or may be learned from practice of the invention. The objectives and other advantages of the invention can be realized and obtained through the following description. Attached Figure Description
[0026] To make the objectives, technical solutions, and advantages of the present invention clearer, the preferred embodiments of the present invention will be described in detail below with reference to the accompanying drawings, wherein: Figure 1 This is a schematic diagram of the overall process of the low-resource text to SPARQL generation method based on remote supervised pruning and confidence propagation in an embodiment of the present invention. Figure 2 This is a schematic diagram of the execution process and remote supervised training path of semantic-structural collaborative pruning in an embodiment of the present invention; Figure 3 This is a schematic diagram of the adaptive decision-making logic of the dual feedback correction mechanism based on confidence propagation in an embodiment of the present invention. Detailed Implementation
[0027] The following specific examples illustrate the implementation of the present invention. Those skilled in the art can easily understand other advantages and effects of the present invention from the content disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and various details in this specification can be modified or changed based on different viewpoints and applications without departing from the spirit of the present invention. It should be noted that the illustrations provided in the following embodiments are only schematic representations of the basic concept of the present invention. Unless otherwise specified, the following embodiments and features can be combined with each other.
[0028] The accompanying drawings are for illustrative purposes only and are schematic diagrams, not actual pictures, and should not be construed as limiting the invention. To better illustrate the embodiments of the invention, some parts in the drawings may be omitted, enlarged, or reduced, and do not represent the actual product dimensions. It is understandable to those skilled in the art that some well-known structures and their descriptions may be omitted in the drawings.
[0029] In the accompanying drawings of the embodiments of the present invention, the same or similar reference numerals correspond to the same or similar components. In the description of the present invention, it should be understood that if terms such as "upper," "lower," "left," "right," "front," and "rear" indicate the orientation or positional relationship based on the orientation or positional relationship shown in the drawings, they are only for the convenience of describing the present invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, the terms used to describe positional relationships in the drawings are only for illustrative purposes and should not be construed as limiting the present invention. For those skilled in the art, the specific meaning of the above terms can be understood according to the specific circumstances.
[0030] Please see Figures 1-3 This is a low-resource natural language to SPARQL generation method and system based on remote supervised pruning and confidence propagation.
[0031] Example 1 This embodiment first provides a low-resource natural language to SPARQL generation method based on remote supervised pruning and confidence propagation, such as... Figure 1 As shown, it specifically includes the following steps: Step S1, Entity Localization and Multi-Hop Subgraph Construction: First, receive the natural language question input by the user and preprocess the question text. Using an inverted index mechanism or entity linking tool, map key entity mentions in the natural language question to unique entity IDs in the knowledge graph, serving as anchor entities. Next, centered on the anchor entities, perform a breadth-first search in the knowledge graph to extract all neighbor nodes and relation edges covering a preset number of hops (K-hop, preferably K=2 or 3), constructing an initial subgraph. This initial subgraph contains the potential reasoning paths required to answer the question, but also contains a large number of noisy paths irrelevant to the question, requiring subsequent pruning.
[0032] Specifically, in this embodiment, the specific implementation process is as follows: S11, Entity Linking: Receives a natural language question Q input by the user. First, Q is segmented into words. Using a pre-built inverted index, n-gram fragments from the question are used as query terms to retrieve candidate entities from the knowledge graph. The edit distance between the candidate entity and the mentioned characters, as well as the entity's popularity (PageRank value), are calculated, and the entity with the highest score is selected as the anchor entity.
[0033] S12, K-jump subgraph extraction: using Centered on the knowledge graph, perform a breadth-first search (BFS). Extract all triples within the K-hop neighborhood of the anchor entity to construct an initial subgraph. .
[0034] Parameter settings: In this embodiment, in order to achieve a balance between coverage and video memory usage, the number of jumps is set. .
[0035] Parameter selection basis: settings Based on statistical analysis of mainstream datasets such as WebQSP, approximately 90% of knowledge base problems can be solved through reasoning within two hops. Blindly increasing... Alternatively, with a threshold of 4, the subgraph size will grow exponentially, leading to memory overflow. The node threshold of 500 is calculated based on the maximum memory capacity of a consumer-grade graphics card (e.g., 6GB) running the GAT model. Experiments show that when the number of nodes is controlled below 500, the memory usage of the graph neural network can be stably controlled below 1GB, thus reserving sufficient memory space for subsequent large language model inference.
[0036] If the number of nodes in the initial subgraph exceeds a preset threshold (500 nodes in this embodiment), the nodes are truncated according to their degree in the graph, with high-frequency nodes being retained first.
[0037] Step S2, Structured Collaborative Pruning Based on Semantic Injection: This step aims to utilize Graph Attention Networks (GAT) to filter out the most relevant inference substructures to the semantics of the natural language problem from the large initial subgraph. For example... Figure 2 As shown, the specific process is as follows: S21. Dual-Tower Feature Encoding: Utilizing a pre-trained lightweight semantic coding model (Sentence-BERT), the user-input natural language question is encoded to obtain a question semantic vector; simultaneously, the relation type of each edge in the initial subgraph is encoded to obtain a relation feature vector. The specific process is as follows: (1) Question semantic vector extraction: The natural language question Q is encoded using the pre-trained lightweight language coding model Sentence-BERT to obtain the question semantic vector. ,in (Parameter selection criteria: This embodiment uses a lightweight model with an output dimension of 384, instead of the more common 768-dimensional model. The technical advantage of choosing this dimension is that, while ensuring that the semantic representation capability decreases by no more than 3%, the floating-point operation cost of subsequent feature fusion and attention calculation is reduced by about 50%, significantly improving the inference speed on edge devices.) (2) Relation feature vector extraction: For each edge in the initial subgraph The relation type r is input into a learnable embedding layer to obtain the relation feature vector. .
[0038] S22. Semantic-Structural Feature Fusion: To enable graph neural networks to perceive the semantic intent of natural language questions, this invention performs a feature fusion operation. Specifically, the question semantic vector is fused with the relational feature vector of each edge to generate a fused feature vector that incorporates the question context. In detail, the feature fusion process is as follows: Perform vector fusion to inject the semantics of the problem into the graph structure features. Specifically, this involves vector concatenation followed by linear transformation.
[0039] In the formula, "Indicates a splicing operation, For linear projection matrices, the stitched matrix will be... dimensional vector mapping back Dimension, generating fused feature vectors , This is the bias vector for the linear projection layer. This vector contains information about both "what the question is asking" and "what the relationship between the edges is".
[0040] S23. Graph Attention Calculation and Pruning: The fused feature vector is directly used as the input feature of the corresponding node in the Graph Attention Network (GAT). The GAT network uses a multi-head attention mechanism to calculate the correlation coefficient between the target node and its neighboring nodes in the fused feature space. This coefficient is normalized and converted into attention weights, which directly reflect the importance of a certain relation edge to the derivation of the answer in the current problem context. The specific calculation process is as follows: Fusion features These features are directly used as input features to nodes in a Graph Attention Network (GAT). For the target node... and its neighboring nodes Calculate the attention coefficient :
[0041] in, It is a non-linear activation function. This is the weight matrix of the GAT layer. For attention vectors, and Representing the target nodes respectively and its neighboring nodes The fusion feature vector generated in the aforementioned steps.
[0042] The coefficients are normalized using the Softmax function to obtain the final attention weights. :
[0043] This weight This indicates the importance of the relation edge r to the reasoning path in the current problem context.
[0044] As a further improvement of the present invention, in step S23, the graph attention network model is trained and optimized based on remote supervision signals. Since the knowledge graph subgraph pruning task lacks labeled data (i.e., lacks labels indicating which edges are correct paths), the present invention proposes a label generation method based on standard answer backtracking: (1) Path backtracking: parse the standard SPARQL query statements in the training dataset and extract the core predicate sequence.
[0045] (2) Automatic label generation: The extracted predicate sequence is mapped back to the knowledge graph subgraph of the training samples, and all paths that can match the predicate sequence and ultimately point to the correct answer entity are searched. All relation edges on these paths are marked as positive samples (label 1), and all other relation edges in the subgraph are marked as negative samples (label 0).
[0046] (3) Model training: Based on the generated positive and negative sample labels, a binary classification objective function is constructed. By minimizing the loss value of this objective function, the graph attention network is iteratively trained using the backpropagation algorithm, thereby enabling it to automatically identify key reasoning paths without manual annotation.
[0047] Specifically, this embodiment employs a remote supervised training method that does not require manual annotation: Label generation: Parse standard SPARQL queries in the training set and extract the core predicate sequence. Map this sequence back to the training subgraph and search for all paths that match the sequence and point to the correct answer. Edges on the paths are labeled as positive samples. The remaining edges are marked as negative samples. ).
[0048] Loss function: Construct a binary cross-entropy loss function to optimize the model:
[0049] in Preserve the edge probability in the model output (i.e. ); Representing relation edges The true label value is determined by marking the edge as 1 if it belongs to the correct inference path, and 0 otherwise. Let | be the set of all relation edges in the current training sample subgraph. | represents the total number of relation edges in this set. In this embodiment, the Adam optimizer is used, and the learning rate is set to... .
[0050] 4. Attribute Preservation Strategy: Top-K retention is performed on the initial subgraph based on attention weights. While preserving relation edges, this invention implements an attribute preservation strategy: if a relation edge is preserved, the attribute nodes connected to that edge are forcibly preserved. Simultaneously, to adapt to the context window limitations of subsequent large models, text values in attribute nodes are checked: date and numeric attribute values are preferentially preserved in their entirety; for long text (String) attribute values, if they exceed a preset length threshold, they are truncated. Finally, an attribute-enhanced inference subgraph is generated.
[0051] Specifically, according to weight Preserve the top-K high-confidence relation edges (in this embodiment) ).
[0052] If a relation edge is to be preserved and points to an attribute node, then that node must be preserved.
[0053] Data truncation: For text-type attribute values, truncation is performed if the length exceeds 50 characters. The truncation threshold of 50 characters is chosen because string matching operations in the FILTER conditions generated by SPARQL typically rely only on the entity's header features (such as prefixes and keywords). Excessively long attribute text (such as a complete movie synopsis) not only fails to aid logical judgment but also consumes valuable context windows in the large language model, causing valid instructions to overflow. The 50-character limit achieves an optimal balance between information preservation and context efficiency. Date and numeric attribute values are retained in their entirety to ensure that subsequent FILTER generation is based on reliable data.
[0054] Step S3, Dynamic Example Retrieval and Quantization Model Generation: To improve the adaptability of the generated model to complex logic and reduce resource consumption, this invention adopts a strategy of "retrieval enhancement + quantization reasoning": S31. Dynamic Paradigm Retrieval: All questions in the historical question-answer database are pre-vectorized using a semantic encoding model, and an efficient vector index (e.g., based on FAISS) is constructed. During the inference phase, the Top-N historical question-answer pairs most semantically similar to the current input question are retrieved using an approximate nearest neighbor search algorithm. During online inference, the current question is calculated... Using the cosine similarity of the questions to the questions in the index, retrieve the top-3 most similar question-answer pairs as examples. (Setting...) This analysis is based on the marginal effects of dynamic few-shot learning. Experimental data shows that the accuracy of model generation significantly improves when the number of tokens increases from 1 to 3; however, when the number exceeds 3 (e.g., 5 or more), the accuracy improvement tends to plateau, and too many input tokens lead to a linear increase in the inference latency of the quantized model. Therefore, N=3 is the optimal trade-off between generation quality and inference latency.
[0055] S32. Structured Constraint Generation: The retrieved similar question-answer pairs are used as Few-shot examples and combined with the attribute-enhanced inference subgraph generated in step S2 to form a Prompt. The inference subgraph uses linearized triples as the structured constraint context. The retrieved examples, the attribute-enhanced inference subgraph generated in step S2, and the current question are combined to form the Prompt template shown in Table 1 below: Table 1
[0056] S33, Low-Resource Inference: The assembled Prompt is input into a large language model (such as Quantized Llama-3 or Phi-3) that has undergone 4-bit or 8-bit quantization. This embodiment preferably uses the Phi-3-mini model and loads it using 4-bit quantization technology to achieve efficient inference under low memory constraints. The quantized model significantly reduces memory usage while maintaining high-precision generation capabilities, and generates the initial SPARQL query statement based on the structural constraints in the Prompt.
[0057] Step S4, Dual Feedback Correction Based on Confidence Propagation: To address the issue of no results due to illusions or overly strict logic in the generated SPARQL statements, this invention constructs a closed-loop feedback mechanism of "pre-execution check - post-execution decision," such as... Figure 3 As shown, it specifically includes: S41. Constructing a Query Confidence Profile: Before executing the query, the generated SPARQL statement is parsed, and each relation predicate is checked to see if it exists in the knowledge graph schema. If it exists, the confidence is 1; if it does not exist (i.e., schema illusion occurs), the semantic similarity score between the generated predicate and the candidate relations in the knowledge graph is calculated. The matching status and scores of all relations are combined, and then similar candidates are used to replace erroneous statements to form a query confidence profile. Specifically, before sending the initial SPARQL statement generated by LLM to the execution engine, the following schema linking and replacement process is performed: (1) Relation extraction and detection: Parse each triple pattern (s, p, o) in the SPARQL statement and extract the relation predicate p. Query the knowledge graph schema to determine whether p actually exists.
[0058] (2) Similar candidate recall and replacement: If p does not exist (i.e., it is determined to be a schema illusion), the candidate recall mechanism is initiated. p is encoded into a vector using Sentence-BERT, and the top-N candidate relations with the highest semantic similarity (e.g., p'{cand1}, p'{cand2}, ...) are retrieved from all relation sets in the knowledge graph.
[0059] Calculate p and candidate relation Cosine Similarity:
[0060] Perform the replacement action: Select the candidate relation p'{best} with the highest similarity (Top-1) to replace the erroneous predicate p in the original statement, resulting in the corrected SPARQL statement Q{corrected}.
[0061] (3) Construct a query confidence profile: Based on the replacement results above, record the confidence score for each relation. : If the relation exists as is (no replacement has occurred), then .
[0062] If a replacement occurs, then (That is, the highest similarity score at the time of replacement). The set of scores for all relationships constitutes the query confidence profile.
[0063] S42. Execution and Feedback Decision: Execute the initial SPARQL statement on the knowledge graph engine. If the execution is successful and there is a result, output it directly; if the execution result is an empty set, proceed to the adaptive correction process.
[0064] S43. Adaptive Correction Strategy: Making decisions based on the uncertainty distribution in the query confidence profile. Strategy A (Logical Relaxation): If the profile shows that the similarity scores of all relational predicates are higher than the preset confidence threshold (indicating that the path prediction is likely correct and the problem lies in the filtering conditions), the system determines that the logical constraints are too strict. In this case, the FILTER clause (such as time range or numerical comparison) in the statement is located first, and relaxation operations such as removing or relaxing the conditions are performed.
[0065] Strategy B (Path Correction): If the profile shows that at least one relation predicate has a similarity score lower than the confidence threshold (indicating that the model has generated an incorrect illusory relation), the system determines that the inference path is incorrect. In this case, priority is given to truncating (pruning to a shorter path) or backtracking the path corresponding to the low-scoring relation, and attempting to regenerate the query using candidate relations.
[0066] Specifically, executing the modified statements on the knowledge graph engine .
[0067] Scenario 1: Execution succeeds and returns a non-empty result set. Output the answer directly.
[0068] Scenario 2: The execution result is an empty set. In this case, the preset confidence threshold is read. (This embodiment is set) ), parameter selection basis: threshold The value is determined based on the distribution characteristics of cosine similarity in the semantic space. Statistics show that when the vector similarity of two relations is higher than 0.75, they are usually synonyms or hyponyms (e.g., 'director' and 'directed_by'), and substitution is safe. However, when the similarity is lower than 0.75, it often indicates semantic drift (e.g., mismatching 'birth_place' as 'death_place'). In this case, forcibly implementing logical relaxation instead of path correction can easily lead to incorrect answer recall. Therefore, 0.75, as a critical value for distinguishing between 'synonymous substitution' and 'path error', has significant statistical value.
[0069] Execute branching strategies based on profile distribution: Branch A: Logical Relaxation Trigger condition: The score of all relationships in the portrait. .
[0070] Diagnosis: After ERR correction, all relations are highly matched with KG, indicating that the path structure is correct. The reason for no results is that the FILTER conditions (such as time and value) are too strict.
[0071] Action: Identify the FILTER clause in the statement. If it contains numerical comparisons (e.g., >2010), try widening the boundary (e.g., change it to >2000); if it contains string matching, try changing it to fuzzy matching (REGEX) or removing the condition.
[0072] Branch B: Path Correction Triggering condition: Scores for any relationship in the portrait. .
[0073] Diagnosis: Even after ERR replacement, the similarity of the best candidate is still very low (e.g. the model generates completely unrelated words), indicating a fundamental error in the reasoning path.
[0074] operate: Rollback Replacement: Try replacing the low-scoring relationship again with the candidate relationship ranked second in similarity (Top-2), and repeat the process.
[0075] Path truncation: If backtracking is ineffective, truncate the low-score relationship and its subsequent hops, and only execute the preceding high-confidence path.
[0076] Example 2 This embodiment provides a system for executing the aforementioned low-resource natural language to SPARQL generation method based on remote supervised pruning and confidence propagation. The system includes a graph preprocessing module, a structured pruning module, a generative inference module, and an adaptive feedback module. The graph preprocessing module is configured to access the knowledge graph database, perform entity linking operations, and extract the K-hop neighborhood centered on the anchor entity as the initial subgraph.
[0077] The structured pruning module incorporates a pre-trained graph attention network model. This module is configured to call a semantic encoding model to extract the question semantic vector and relation feature vectors respectively, perform feature fusion, and then input the fused features into the graph network to calculate attention weights. Based on this, the initial subgraph is denoised and pruned, outputting an attribute-enhanced inference subgraph.
[0078] The generative inference module integrates a vector index library and a quantized large language model. It is configured to retrieve similar examples and generate initial SPARQL queries based on the inference subgraph.
[0079] The adaptive feedback module is configured to parse SPARQL statements to build a query confidence profile, and dynamically schedule the logical relaxation algorithm or the path correction algorithm based on the status of the execution result (whether it is empty) and the distribution of the confidence profile, and output the final query result.
[0080] Example 3 This embodiment demonstrates a specific execution example based on the methods and systems provided in Embodiments 1 and 2.
[0081] Step S1: Entity Localization and Subgraph Construction. The system first uses an inverted index to parse the input question and identify the core entity mention "Inception". Through an entity linking component, it maps this to a unique anchor entity ID (e.g., m.0bth54) in a knowledge graph (such as Freebase / Wikidata). Next, the system performs a BFS search centered on m.0bth54 to extract all neighbor nodes within a 2-hop (K=2) range. Assume the extracted initial subgraph contains 500 relational edges, including question-related paths (such as directed_by, birth_date) and numerous irrelevant noisy paths (such as narrative_location, cast_member, generation, etc.).
[0082] Step S2: Semantic-Structure Co-pruning (Core Step) To process this subgraph with low GPU memory resources, the system calls a pre-trained semantic encoding model (Sentence-BERT) to extract the problem semantic vector. And extract the feature vectors of each relation type in the subgraph. The Graph Attention Network (GAT) calculates the attention weight for each edge after merging the features: for the relation `directed_by` (director), the model calculates an attention weight of 0.92 (high confidence); for the relation `narrative_location` (narrative location), the weight is only 0.05 (low confidence). Based on the weight ranking, the system performs pruning, retaining only the top-10 key paths. Simultaneously, an attribute preservation strategy is implemented: when the system retains an edge pointing to the director entity (Christopher Nolan), it forcibly retains the attribute node "1970-07-30"^^xsd:date. This step ensures that subsequent generative models can obtain the crucial data to answer the "When" (time) question, avoiding information loss due to over-pruning.
[0083] Step S3: The dynamic example retrieval and quantization generation system uses the Facilitation Indices Service (FAISS) vector index library to retrieve the historical question-answer pair most semantically similar to the current question: "Who directed Titanic? -> James Cameron". The system assembles this example with the "attribute-enhanced inference subgraph" generated in Step S2 into a Prompt, which is then input into the 4-bit quantized Phi-3-mini model. Assume the model generates the following pseudocode for the initial SPARQL query statement, as shown in Table 2: Table 2
[0084] Step S4: Dual Feedback Correction Based on Confidence Propagation Before query execution, the adaptive feedback module constructs a "query confidence profile": Schema detection: The system detected that the wdt:director relationship does not exist in the knowledge graph schema (determined to be an illusion).
[0085] Similarity Calculation: The system calculates the semantic similarity between the erroneous predicate and the candidate relation. The calculation reveals that the cosine similarity between `wdt:director` and the correct relation `wdt:directed_by` is 0.88, which is higher than the preset threshold. .
[0086] Profile generation and decision-making: The confidence profile shows a low-scoring (non-existent) relationship, but scores higher after candidate replacement. The system determines that the main reason is schema illusion, rather than path reasoning error.
[0087] Correction execution: The system automatically replaces wdt:director with wdt:directed_by and generates a corrected query statement.
[0088] Final execution: The revised statement was executed successfully in the database, returning the result "1970-07-30".
[0089] (Note: If the execution result is still empty, and the confidence profile shows that all relationship scores are extremely high, the system will further enter the logical relaxation branch and attempt to remove the FILTER.) (Conditions to obtain broad results.) As can be seen from the above embodiments, the present invention can accurately complete complex knowledge question answering tasks in environments with limited video memory by using pruning and intelligent correction mechanisms.
[0090] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit it. Although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can be made to the technical solutions of the present invention without departing from the spirit and scope of the present invention, and all such modifications or substitutions should be covered within the scope of the claims of the present invention.
Claims
1. A low-resource natural language to SPARQL generation method based on remote supervised pruning and confidence propagation, characterized in that: The method includes the following steps: S1. Obtain the natural language question input by the user, use the inverted index mechanism to map the entities in the natural language question to anchor entities in the knowledge graph, and extract entities centered on the anchor entities. Use the skip neighborhood as the initial subgraph; S2. A pre-trained semantic coding model is used to transform the natural language question and the initial subgraph into question semantic vectors and relation feature vectors. An improved graph attention network model is used to perform structured collaborative pruning based on semantic injection on the fused features of the two to obtain attribute-enhanced reasoning subgraphs. S3. Vectorize the natural language question and retrieve semantically similar question-answer pairs from the historical question-answer database as examples. Use the examples and reasoning subgraphs together as structured constraint contexts, input them into the quantized large language model, and generate the initial SPARQL query statement. S4. Establish a dual feedback correction mechanism based on confidence propagation. In this mechanism, a query confidence profile is established based on the semantic similarity between the relational predicates in the query statement and the relation in the knowledge graph. When the initial SPARQL query statement is empty, the execution logic relaxation strategy or path correction strategy is adaptively selected based on the query confidence profile to obtain the final SPARQL query statement.
2. The low-resource natural language to SPARQL generation method based on remote supervised pruning and confidence propagation according to claim 1, characterized in that: In step S1, the process of generating entity links and the initial subgraph is as follows: The system receives a natural language question Q from the user, performs word segmentation on Q, uses a pre-built inverted index to retrieve n-gram fragments from the question as query terms, and searches for candidate entities in the knowledge graph. It then calculates the edit distance between the candidate entity and the mentioned characters, as well as the entity's popularity, and selects the entity with the highest score as the anchor entity. ; anchor point entity Centered on the knowledge graph, perform a breadth-first search to extract anchor entities. Jump to all triples in the neighborhood and construct the initial subgraph. If the number of nodes in the initial subgraph exceeds the preset threshold, the nodes are truncated according to their degree in the graph, with priority given to retaining high-frequency nodes.
3. The low-resource natural language to SPARQL generation method based on remote supervised pruning and confidence propagation according to claim 2, characterized in that: In step S2, a pre-trained lightweight semantic encoding model is used to extract the question semantic vector and relation feature vector. Specifically, a pre-trained lightweight language encoding model is used to encode the natural language question Q to obtain the question semantic vector. ,in The representation dimension is set considering semantic representation capability and the floating-point computation cost of feature fusion and attention calculation. For each edge in the initial subgraph , and its relation type r Input a learnable embedding layer to obtain relational feature vectors. ; Then, the problem semantic vector is fused with the relation feature vector of each edge to generate a fused feature vector that incorporates the problem context. The process includes: Perform vector fusion to inject the semantics of the problem into the graph structure features: In the formula, " "Indicates a splicing operation, For linear projection matrices, the stitched matrix will be... dimensional vector mapping back Dimension, generating fused feature vectors , The bias vector of the linear projection layer; Next, the fused feature vector is directly used as the input feature of the corresponding node in the graph attention network, and the correlation coefficient between the target node and its neighboring nodes in the fused feature space is calculated through a multi-head attention mechanism: In the formula, It is a non-linear activation function. This is the weight matrix of the GAT layer. For attention vectors, and Representing the target nodes respectively and its neighboring nodes fused feature vectors; The coefficients are converted into attention weights after normalization: Weight This reflects the relationship edge in the current problem context. r The importance of reasoning path; Finally, based on attention weights The initial subgraph is subjected to Top-K retention, which adopts an attribute-accompanying retention strategy: if a relation edge is retained, the attribute node connected to that relation edge is forcibly retained; at the same time, date and numeric attribute values are retained in their entirety first; for long text attribute values, if they exceed a preset length threshold, they are truncated; finally, an attribute-enhanced inference subgraph is generated.
4. The low-resource natural language to SPARQL generation method based on remote supervised pruning and confidence propagation according to claim 3, characterized in that: The graph attention network model in step S2 is trained and optimized based on distant supervision signals. The process of constructing distant supervision signals includes: First, the standard SPARQL query statements in the training set are analyzed to extract the core predicate sequence; Then, the core predicate sequence is mapped back to the knowledge graph subgraph of the training samples, and all entity paths that match the predicate sequence and point to the correct answer are searched. Then mark the relation edges on the matching path as positive samples, and mark the remaining relation edges in the subgraph as negative samples; Finally, a binary classification loss function is constructed based on positive and negative samples to train the graph attention network model, enabling it to identify key inference paths. The binary cross-entropy loss function is expressed as follows: in, Preserve the edge probabilities in the model output, i.e. ; Representing relation edges The true label value is determined by marking the edge as 1 if it belongs to the correct inference path, and 0 otherwise. Let | be the set of all relation edges in the current training sample subgraph. | represents the total number of relation edges in this set.
5. The low-resource natural language to SPARQL generation method based on remote supervised pruning and confidence propagation according to claim 3, characterized in that: In step S3, all questions in the historical question-answering database are vectorized beforehand using a semantic encoding model, and an efficient vector index library is constructed. During the reasoning phase, an approximate nearest neighbor search algorithm is used to retrieve questions semantically related to the current input question. The top-N most similar historical question-answer pairs are used as examples; the retrieved similar question-answer pairs are used as Few-shot examples and assembled with the generated attribute-enhanced inference subgraph to form a Prompt; the assembled Prompt is input into the quantized large language model, and the initial SPARQL query statement is generated based on the structural constraints in the Prompt.
6. The low-resource natural language to SPARQL generation method based on remote supervised pruning and confidence propagation according to claim 5, characterized in that: In step S4, the process of constructing the query confidence profile is as follows: before executing the query, the generated SPARQL statement is parsed, and each relation predicate in it is checked to see if it exists in the schema of the knowledge graph; if it exists, the confidence is 1; if it does not exist, the semantic similarity score between the generated predicate and the candidate relation in the knowledge graph is calculated. Then, the matching status or similarity scores of all relational predicates are combined, and similar candidate replacement errors are performed to form the query confidence profile.
7. The low-resource natural language to SPARQL generation method based on remote supervised pruning and confidence propagation according to claim 6, characterized in that: In step S4, the process of adaptively selecting either the execution logic relaxation strategy or the path correction strategy includes: Execute the initial SPARQL statement on the knowledge graph engine; if the execution is successful and there is a result, output it directly; if the execution result is an empty set, proceed to the adaptive correction process. Decisions are made based on the uncertainty distribution in the query confidence profile. If the profile shows that the similarity scores of all relation predicates are higher than the preset confidence threshold, the query failure is determined to be due to overly strict logical constraints. The FILTER filter condition in the SPARQL query statement is removed or relaxed first. If the profile shows that the similarity score of at least one relation predicate is lower than the confidence threshold, the query failure is determined to be due to an incorrect inference path. Relation paths with similarity scores lower than the confidence threshold are truncated or rolled back first, and the query path is regenerated.
8. A system for executing the low-resource natural language to SPARQL generation method based on remote supervised pruning and confidence propagation as described in any one of claims 1-7, characterized in that: The system includes a graph preprocessing module, a structured pruning module, a generative inference module, and an adaptive feedback module. The graph preprocessing module is configured to access the knowledge graph database, perform entity linking operations, and extract the K-hop neighborhood centered on the anchor entity as the initial subgraph. The structured pruning module has a built-in pre-trained graph attention network model, which calls the semantic encoding model to extract the semantic vector of the question and the feature vector of the relationship respectively, and performs feature fusion operation; and inputs the fused features into the graph network to calculate attention weights, thereby denoising and pruning the initial subgraph and outputting an attribute-enhanced inference subgraph. The generative reasoning module integrates a vector index library and a quantized large language model, which is used to retrieve similar examples and generate initial SPARQL query statements by combining the reasoning subgraph. The adaptive feedback module first parses the SPARQL statement and constructs a query confidence profile. Based on the status of the execution result and the distribution of the confidence profile, it dynamically schedules the logical relaxation algorithm or the path correction algorithm to output the final query result.
