Rejection judgment question and answer system and method based on intermediate layer feature analysis
By using a PCA probe module based on intermediate layer feature analysis to determine the responsiveness of a Text-to-SQL system, the system's security vulnerabilities in highly sensitive areas are addressed, enabling efficient and secure rejection detection and enhancing system robustness and user trust.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- FUDAN UNIVERSITY
- Filing Date
- 2026-05-11
- Publication Date
- 2026-07-31
AI Technical Summary
Existing Text-to-SQL systems struggle to effectively determine whether a response is possible when dealing with unknown questions, ambiguous semantics, or high-risk scenarios, leading to the generation of erroneous or dangerous SQL statements, posing security risks, especially in highly sensitive fields such as finance, healthcare, and law.
A question-answering system based on intermediate layer feature analysis is adopted. The PCA probe module extracts features from the hidden layer of the language model. The PCA probe optimization and quantization discrimination submodule determines whether the question is answerable and outputs a rejection prompt when it is not answerable.
It improves the robustness and security of the system, avoids the generation of erroneous SQL statements, ensures data security, enhances user trust, reduces computational load and inference time, and is suitable for highly sensitive fields such as finance, healthcare, and law.
Smart Images

Figure CN122489709A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of information systems, and more specifically to a question-answering system and method for rejection judgment based on intermediate layer feature analysis. Background Technology
[0002] In the era of rapid development of big data and artificial intelligence, databases, as the core infrastructure for information storage and processing, play a vital role in social production, scientific research, and business decision-making. However, with the continuous expansion of data volume and the increasing complexity of database structures, how to efficiently and conveniently query data has become a prominent issue. Existing data access methods have two main shortcomings: firstly, form-based or graphical interface-based retrieval tools, while simple to operate, have limited query capabilities and cannot meet complex needs; secondly, low-level tools relying on SQL, while powerful, have high learning and usage barriers, suitable only for a few database experts. For ordinary users, it is often difficult to directly realize the value of data; even for professionals, writing and validating a large number of SQL statements across different fields or scenarios is extremely tedious. To lower the data query barrier, the Text-to-SQL task has emerged. The goal of this task is to automatically convert natural language questions into executable SQL database query statements, enabling users to access databases like a conversation, thereby eliminating the barrier between natural language and structured data.
[0003] With the rise of large language models, the accuracy and applicability of Text-to-SQL have significantly improved. However, existing systems still have shortcomings when dealing with unknown questions, ambiguous semantics, or high-risk scenarios: once the user's input question exceeds the database's scope, involves sensitive privacy, or is semantically ambiguous, the model often forcibly generates SQL statements, leading to erroneous or dangerous results. This situation is particularly serious in highly sensitive fields such as finance, healthcare, and law, urgently requiring a rejection mechanism that allows the system to explicitly output "cannot answer" when necessary. Summary of the Invention
[0004] This invention is made to solve the above-mentioned problems. Its purpose is to provide a question-answering system and method based on intermediate layer feature analysis. By utilizing the hidden state information inside the model, and through PCA probe and representation engineering (RepE) technology, it can effectively determine whether a question is answerable and output a rejection prompt when necessary.
[0005] This invention provides a question-answering system for rejection judgment based on intermediate layer feature analysis, which has the following features:
[0006] The input module is used to input natural language text as a question;
[0007] The language model module contains pre-trained language models for handling text understanding, generation, and reasoning tasks;
[0008] The PCA probe module extracts features from multiple hidden layers of the language model, acquires PCA probes in batches, calculates directional scores for each hidden layer using the PCA probes, and determines whether the input question is answerable based on the comparison between the calculation results and a preset threshold.
[0009] The output module outputs a rejection message when the PCA probe module determines that the input question is unanswerable; if it determines that the question is answerable, it outputs an SQL statement.
[0010] The question-answering system for rejection judgment based on intermediate layer feature analysis provided by this invention may also have the following features:
[0011] The PCA probe is an activation vector extracted from the hidden layer of the language model. It consists of a set of direction vectors and a mean vector. The direction vectors are used to capture the semantic direction of the target attribute in the hidden layer.
[0012] The question-answering system for rejection judgment based on intermediate layer feature analysis provided by this invention may also have the following features:
[0013] The PCA probe module includes an intermediate layer representation extraction submodule, a PCA probe optimization submodule, and a quantization discrimination submodule. The intermediate layer representation extraction submodule performs layer-by-layer feature extraction and analysis on multiple hidden layers of the language model to obtain activation vectors.
[0014] The PCA probe optimization submodule contains a trained PCA probe model, performs dimensionality reduction on the activation vectors, and selects principal components from them to optimize the PCA probe model.
[0015] The quantization and discrimination submodule uses PCA probes to calculate the directionality score of each hidden layer, that is, to calculate the uncertainty measure of each hidden layer. Based on the comparison result of the uncertainty measure and the preset value, it determines whether the input question is answerable.
[0016] The question-answering system for rejection judgment based on intermediate layer feature analysis provided by this invention may also have the following features:
[0017] The training process of the PCA probe model uses a training set and a validation set. The training set uses the principal components with the highest variance contribution rate as input features and optimizes the model by minimizing the cross-entropy loss between the predicted results and the true labels.
[0018] The validation set contains numerical values of the prediction accuracy of each hidden layer. The quantization and discrimination submodule selects the hidden layer with the highest prediction accuracy as the final rejection discrimination layer based on the comparison results of the values in the validation set.
[0019] The question-answering system for rejection judgment based on intermediate layer feature analysis provided by this invention may also have the following features:
[0020] In the quantification and discrimination submodule, the uncertainty measure is the average value of tokens with a highest score higher than 0. When the average value exceeds a preset threshold, the input question is marked as "unanswerable".
[0021] The question-answering system for rejection judgment based on intermediate layer feature analysis provided by this invention may also have the following features:
[0022] When the quantification and discrimination submodule is running, if the scores of three consecutive tokens exceed the preset threshold, a rejection will be triggered directly.
[0023] This invention also provides a method for rejecting responses based on intermediate layer feature analysis, comprising the following steps:
[0024] Input steps: Input natural language text as the question;
[0025] The language model invocation step uses the pre-trained language model to handle text understanding, generation, and reasoning tasks.
[0026] PCA probe extraction optimization and quantization discrimination steps: Extract features from multiple hidden layers of the language model, batch obtain activation vectors and perform dimensionality reduction, establish a PCA probe model and optimize it through principal component analysis, select the hidden layer with the highest prediction accuracy as the final rejection discrimination layer, use PCA probe to calculate the directional score of each token in different layers, compare the calculation results with a preset threshold, and determine whether the input question is answerable based on the comparison results;
[0027] The output steps are as follows: if the input question is determined to be unanswerable, a rejection message is output directly; if the input question is determined to be answerable, an SQL statement is output.
[0028] The present invention also provides a computer-readable storage medium having a computer program stored thereon, characterized in that the computer program, when executed by a processor, implements the above-mentioned rejection judgment method based on intermediate layer feature analysis.
[0029] The present invention further provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that the processor executes the computer program to implement the above-mentioned rejection judgment method based on intermediate layer feature analysis.
[0030] Compared with the prior art, the functions and effects of the present invention include:
[0031] (1) The question answering system based on intermediate layer feature analysis of the present invention directly models the intermediate layer hidden state of the language model through the PCA probe module, compares the differences between “answerable / unanswerable” questions in the hidden space, extracts the direction vector related to answerability, and constructs a rejection discriminator, thus breaking away from the traditional framework that only depends on input / output.
[0032] (2) In the PCA probe module of the present invention, the intermediate layer representation extraction submodule uses the PCA method to activate the hidden layer of the language model, the PCA probe optimization submodule reduces the dimensionality of the activation vector and extracts the main components, and the quantization discrimination submodule makes a rejection judgment. Compared with complex reward models or reinforcement learning, the present invention only needs one PCA projection to complete the discrimination, which greatly reduces the amount of computation.
[0033] (3) In the PCA probe module of the present invention, the quantization discrimination submodule uses the directional score of the token-level to quantify whether the model is responsive, and introduces two dynamic threshold strategies, the average value and the maximum value, to improve robustness.
[0034] (4) The rejection judgment method based on intermediate layer feature analysis of the present invention directly outputs "I don't know" or "cannot answer" when the input question is determined to be unanswerable, instead of forcibly generating SQL statements, to ensure the safety and reliability of the results. Attached Figure Description
[0035] Figure 1 This is an architecture diagram of the question-answering system for rejection judgment based on intermediate layer feature analysis of the present invention.
[0036] Figure 2 This is a schematic diagram of the framework of the rejection judgment method of the present invention in a human resources scenario;
[0037] Figure 3 This is a statistical chart showing the accuracy of the rejection judgment method of the present invention in the directionality judgment of each layer in a human resources scenario.
[0038] Figure 4 This is a heatmap that visualizes the directional scores of the first 100 tokens in an unanswerable question scenario, based on the model of this invention.
[0039] Figure 5 This is a heatmap that visualizes the directional scores of the first 100 tokens in an answerable question scenario, based on the model of this invention.
[0040] In the diagram, 100. Question answering system; 1. Input module; 2. Language model module; 3. PCA probe module; 31. Intermediate layer representation extraction submodule; 32. PCA probe optimization submodule; 33. Quantization discrimination submodule; 4. Output module. Detailed Implementation
[0041] In the description of this application, it should be noted that, unless otherwise expressly specified and limited, the terms "installation," "connection," and "linking" should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral connection; they can refer to a mechanical connection, an electrical connection, or a connection that allows communication between them; they can refer to a direct connection or an indirect connection through an intermediate medium; they can refer to the internal communication between two components or the interaction between two components. Those skilled in the art can understand the specific meaning of the above terms in this application according to the specific circumstances.
[0042] To make the technical means, creative features, objectives and effects of this invention easier to understand, the following embodiments, in conjunction with the accompanying drawings, specifically illustrate the rejection judgment method of the large language module based on intermediate layer feature analysis of this invention.
[0043] Figure 1 This is an architecture diagram of the rejection judgment question answering system 100 based on intermediate layer feature analysis of the present invention.
[0044] like Figure 1 As shown, this embodiment provides a question-answering system 100 for rejection judgment based on intermediate layer feature analysis, including an input module 1, a language model module 2, a PCA probe module 3, and an output module 4.
[0045] Input module 1 is used to input natural language text as a question.
[0046] Language Model Module 2 contains pre-trained language models for handling text understanding, generation, and reasoning tasks.
[0047] PCA probe module 3 includes intermediate layer characterization extraction submodule 31, PCA probe optimization submodule 32, and quantization discrimination submodule 33.
[0048] Specifically, the intermediate layer representation extraction submodule 31 performs layer-by-layer feature extraction and analysis on multiple hidden layers of the language model, and obtains activation vectors in batches, namely PCA probes, which consist of a set of direction vectors and mean vectors. The direction vectors are used to capture the semantic direction of the target attribute in the hidden layer.
[0049] PCA probe optimization submodule 32 contains a trained PCA probe model that performs dimensionality reduction on each activation vector to identify core patterns related to "whether it is responsive".
[0050] Specifically, after extracting activation vectors from multiple candidate hidden layers, the best-performing layers are selected as input based on the validation set results, for example, `hidden_layers = [-1, -2, -3, -4]`. These hidden layers contain abstract semantic information, which can better characterize the latent features in complex tasks. The PCA method is then used to reduce the dimensionality of the activation vectors of these hidden layers, and the principal component with the highest variance contribution rate is selected as the key direction. In the experiments, `n_difference = 1` is set, meaning one principal component is selected as the discrimination criterion. This principal component is used as the input feature to train the PCA probe model, and optimization is performed by minimizing the cross-entropy loss between the predicted result and the true label. The training process of the PCA probe model uses training and validation sets, with `batch_size = 32`, and the prediction accuracy is calculated on each hidden layer. Based on the comparison results on the validation set, the model layer with the highest accuracy is selected as the final rejection discrimination layer.
[0051] The quantization discrimination submodule 33 uses PCA probes to calculate the directional scores of each token in different hidden layers and visualizes the results.
[0052] For example, in unanswerable scenarios, the PCA probe module 3 extracts 20 to 30 layers of hidden states from the first 100 tokens in the responses and calculates an uncertainty metric. When this metric exceeds a preset threshold, the question is marked as "unanswerable." In the experiment, the initial threshold was set to THRESHOLD = 0.0, meaning that when the uncertainty metric is greater than 0, the question-answering system 100 automatically triggers a rejection. This invention only requires one PCA projection to complete the discrimination, greatly reducing the computational load.
[0053] To further optimize the discrimination effect, this invention designs two discrimination strategies: one is the average value strategy, which determines that a token is unanswerable when the average value of the highest-level tokens with scores higher than 0 exceeds a threshold 'a'; the other is the maximum value strategy, which directly triggers a rejection if three consecutive tokens have scores exceeding a threshold 'b'. These two discrimination strategies improve the robustness of the system.
[0054] Output module 4: When PCA probe module 3 determines that the input question is unanswerable, it directly outputs a rejection message; if it determines that the question is answerable, it outputs an SQL statement.
[0055] Therefore, when an input question is determined to be unanswerable, the question-answering system 100 in this embodiment will not continue to generate SQL statements, but will directly output a rejection message. The output can be in the form of a general "cannot answer" or "I don't know," or it can provide targeted feedback based on the specific situation, such as "this question is outside the database range" or "the request involves private information." If the input question is determined to be answerable, an SQL statement is output. This output mechanism can effectively prevent the system from generating incorrect SQL statements in high-risk situations, preventing misleading users or leaking sensitive data from the root. Through this design, users can clearly understand the reasons why the question-answering system 100 refuses to answer, and the transparency and credibility of the system are also improved. This mechanism is particularly important in highly sensitive fields such as finance, healthcare, and law, because it not only ensures data security but also helps users build trust in intelligent systems, thereby promoting the implementation and popularization of this mechanism in practical applications.
[0056] This invention also provides a method for rejecting responses based on intermediate layer feature analysis, comprising the following steps:
[0057] Input steps: Input natural language text as the question;
[0058] The language model invocation step uses the pre-trained language model to handle text understanding, generation, and reasoning tasks.
[0059] The intermediate layer representation extraction step involves extracting and analyzing features layer by layer and token by token from each hidden layer of the language model to obtain activation vectors, i.e., PCA probes.
[0060] The PCA probe optimization steps are as follows: establish a PCA probe model, perform dimensionality reduction on the PCA probe through principal component analysis, and select the hidden layer with the highest prediction accuracy based on the comparison results of the PCA probe model's validation set.
[0061] The quantitative discrimination step involves using a PCA probe to calculate the directional score of each token at different levels while generating the SQL statement, thereby quantitatively judging whether the input question is answerable.
[0062] The output steps are as follows: if the input question is determined to be unanswerable, a rejection message is output directly; if the input question is determined to be answerable, an SQL statement is output.
[0063] The present invention also provides a computer-readable storage medium having a computer program stored thereon, characterized in that the computer program, when executed by a processor, implements the above-mentioned rejection judgment method based on intermediate layer feature analysis.
[0064] The present invention further provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that the processor executes the computer program to implement the above-mentioned rejection judgment method based on intermediate layer feature analysis.
[0065] 1. Accuracy Comparison Experiment and Analysis: To verify the effectiveness of the rejection judgment method of the present invention, we conducted experiments in six typical task scenarios, namely supervision, stocks, risk, retail, loans and human resources.
[0066] The experiment uses a unified Text2SQL task dataset to compare accuracy, precision, recall, F1 score, and inference time under different scenarios. The Text2SQL task refers to automatically converting a user's natural language text input into executable SQL database query statements, enabling non-experts to easily access the database.
[0067] The experimental results are shown in Table 1 below.
[0068] Table 1 Results of the Refusal to Answer Experiment for Each Thematic Scenario
[0069] Supervision 0.96 0.979 0.94 0.959 2.00 Stock 0.99 1.000 0.98 0.989 1.90 risk 1.00 1.000 1.00 1.000 3.05 retail 1.00 1.000 1.00 1.000 2.29 loan 0.98 0.96 1.00 0.980 2.30 Human Resources (HR) 0.86 0.79 0.98 0.875 2.00
[0070] As can be seen from Table 1, the method of the present invention achieves excellent performance in most scenarios:
[0071] In risk and retail scenarios, all metrics (accuracy, precision, recall, and F1 score) reached 1.000, indicating that the model can completely and accurately distinguish between answerable and unanswerable questions.
[0072] The F1 scores for stock and loan scenarios are 0.989 and 0.980, respectively, demonstrating the strong adaptability of this method to financial and loan database tasks.
[0073] The F1 score in the supervised scenario is 0.959, indicating stable overall performance.
[0074] Due to the semantic ambiguity of the samples and the large domain span, the F1 score in the human resources scenario is 0.875, but it is still better than the traditional SFT and Prompt rejection mechanisms.
[0075] Overall, the method achieves an average accuracy of over 0.965 across six scenarios, demonstrating stable performance in rejecting responses and good cross-domain generalization.
[0076] 2. Inference Efficiency Comparison Experiment and Analysis: To evaluate the computational efficiency of the method of this invention, we measured the average inference time (ms / batch) for each scenario on the same hardware platform (NVIDIA A100-80G GPU). The results are shown in Table 1 above, with the average inference time ranging from 1.9 to 3.05 ms / batch.
[0077] Compared to traditional RLHF (PPO) and DPO-type rejection mechanisms that require multiple samplings and additional training, this method only requires a single feature projection to complete the rejection decision, reducing the average inference time by approximately 70% while maintaining high accuracy. For example, in stock scenarios, the single-batch inference time is only 1.90 ms; even in the most computationally complex risk scenarios, the inference time is only 3.05 ms. Compared to the average time of over 10 ms for reinforcement learning-based rejection mechanisms, this method achieves approximately 3 times the inference speedup. This lightweight architecture not only significantly reduces the system's computational cost but also ensures the real-time responsiveness of online Text2SQL systems, making it ideal for deployment in enterprise-level production environments.
[0078] Figure 2 This is a schematic diagram of the framework of the rejection judgment method of the present invention in a human resources scenario.
[0079] like Figure 2 As shown, when a natural language question is input into the question answering system 100, the language model generates SQL while the PCA probe module 3 extracts the hidden state of the intermediate layer and inputs it into the PCA probe model to determine whether the question is answerable and output the result.
[0080] The comparison of the discrimination accuracy of different hidden layers in human resources scenarios is as follows: Figure 3 As shown in the figure, probes in the hidden state at higher levels have a higher accuracy rate in rejecting questions and can better distinguish between responsive and unresponsive questions.
[0081] 3. Comparative Experiment and Analysis of Answerable and Unanswerable Questions: In the comparative experiment of answerable and unanswerable questions, the heatmap showed a significant difference in the color distribution of the first few tokens in the high-level hidden state: answerable questions were mostly blue, while unanswerable questions showed a high proportion of red signals. Through this dynamic threshold mechanism, the system can more effectively avoid forcibly answering unanswerable questions, thereby reducing risk.
[0082] In scenarios with unanswerable questions, the model visualizes the directional scores of the first 100 tokens, as shown in the following display. Figure 4 As shown in the image, the red signals are clearly concentrated, indicating that the system can correctly trigger the rejection response.
[0083] In answerable question scenarios, the model visualizes the directional scores of the first 100 tokens, as shown in the following display. Figure 5 As shown, the blue signal dominates, indicating that the model can correctly identify the question as answerable and generate an SQL statement.
[0084] Those skilled in the art should understand that this invention is not limited to the above embodiments. The embodiments and descriptions in the specification are merely illustrative of the principles of the invention. Various changes and modifications can be made to this invention without departing from its spirit and scope, and all such changes and modifications fall within the scope of the invention as claimed. The scope of protection of this invention is defined by the appended claims and their equivalents.
Claims
1. A rejection judgment question and answer system based on intermediate layer feature analysis, characterized by, include: The input module is used to input natural language text as a question; The language model module contains pre-trained language models for handling text understanding, generation, and reasoning tasks; The PCA probe module extracts features from multiple hidden layers of the language model, acquires PCA probes in batches, calculates directional scores for each hidden layer using the PCA probes, and determines whether the input question is answerable based on the comparison between the calculation results and a preset threshold. The output module, when the PCA probe module determines that the input question is unanswerable, directly outputs a rejection message; if it determines that the question is answerable, it outputs an SQL statement.
2. The question-answering system for rejection judgment based on intermediate layer feature analysis according to claim 1, characterized in that: in, The PCA probe is an activation vector extracted from the hidden layer of the language model. It consists of a set of direction vectors and a mean vector. The direction vectors are used to capture the semantic direction of the target attribute in the hidden layer.
3. The question-answering system for rejection judgment based on intermediate layer feature analysis according to claim 1, characterized in that, in, The PCA probe module includes an intermediate layer characterization extraction submodule, a PCA probe optimization submodule, and a quantization discrimination submodule. The intermediate layer representation extraction submodule performs layer-by-layer feature extraction and analysis on multiple hidden layers of the language model to obtain activation vectors, i.e., the PCA probes. The PCA probe optimization submodule includes a trained PCA probe model, which reduces the dimensionality of the activation vector and selects principal components from it to optimize the PCA probe model. The quantization discrimination submodule uses the PCA probe to calculate the directionality score of each hidden layer, that is, to calculate the uncertainty measure of each hidden layer, and determines whether the input question is answerable based on the comparison result of the uncertainty measure and the preset threshold.
4. The question-answering system for rejection judgment based on intermediate layer feature analysis according to claim 3, characterized in that, in, The training process of the PCA probe model uses a training set and a validation set. The training set uses the principal components with the highest variance contribution rate as input features, and is optimized by minimizing the cross-entropy loss between the predicted results and the true labels; The validation set contains numerical values of the prediction accuracy for each hidden layer. The quantization discrimination submodule selects the hidden layer with the highest prediction accuracy as the final rejection discrimination layer based on the comparison results of the values in the validation set.
5. A question-answering system for rejection judgment based on intermediate layer feature analysis according to claim 3, characterized in that, in, In the quantification and discrimination submodule, the uncertainty measure is the average value of tokens with the highest level score higher than 0. When the average value exceeds a preset threshold, the input question is marked as "unanswerable".
6. The question-answering system for rejection judgment based on intermediate layer feature analysis according to claim 3, characterized in that, in, When the quantization and discrimination submodule is running, if the scores of three consecutive tokens exceed a preset threshold, a rejection will be triggered directly.
7. A question-answering system for rejection judgment based on intermediate layer feature analysis, characterized in that, Includes the following steps: Input steps: Input natural language text as the question; The language model invocation step uses the pre-trained language model to handle text understanding, generation, and reasoning tasks. PCA probe extraction optimization and quantization discrimination steps: Extract features from multiple hidden layers of the language model, batch obtain activation vectors and perform dimensionality reduction, establish a PCA probe model and optimize it through principal component analysis, select the hidden layer with the highest prediction accuracy as the final rejection discrimination layer, use the PCA probe to calculate the directional score of each token in different layers, compare the calculation results with a preset threshold, and determine whether the input question is answerable based on the comparison results; The output steps are as follows: if the input question is determined to be unanswerable, a rejection message is output directly; if the input question is determined to be answerable, an SQL statement is output.
8. 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 rejection judgment method based on intermediate layer feature analysis as described in claim 7.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the rejection judgment method based on intermediate layer feature analysis as described in claim 7.