Controllable text generation method based on framework semantic knowledge
By employing a framework semantic parsing and contrast-aware distributed decoding mechanism, the semantic distinction and consistency issues of large-scale pre-trained language models during knowledge updates are resolved, enabling efficient and controllable knowledge editing and improving the generation accuracy and robustness of the model in different scenarios.
Patent Information
- Application Number
- CN202511069413.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-31
- Publication Date
- 2025-11-18
AI Technical Summary
Existing large-scale pre-trained language models are prone to knowledge obsolescence and factual errors when updating knowledge. Furthermore, traditional methods are costly and prone to catastrophic forgetting. Existing model editing methods suffer from weak semantic differentiation of neighboring knowledge points and weak consistency in updating related knowledge, making it difficult to maintain the accuracy and consistency of knowledge in different scenarios.
We adopt a controllable text generation method based on frame semantic knowledge. Through semantic frame parsing and comparative perceptual distribution decoding mechanism, we enhance the semantic distinguishability of knowledge updates. We design a dual filtering mechanism to improve the accuracy and stability of knowledge fusion and achieve locality and generalization.
It significantly improves the model's generalization ability across domains and tasks, enhances the model's robustness to noisy contexts and the accuracy of knowledge generation, and ensures the reliability and consistency of knowledge updates.
Smart Images

Figure CN120973931A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application belongs to the technical field of natural language processing, and particularly relates to a controllable text generation method based on framework semantic knowledge. BACKGROUND
[0002] With the rapid development of natural language processing technology, large language models (LLMs) based on large-scale pre-training have been widely used in question and answer systems, text generation, machine translation and other tasks, and have shown significant language understanding and generation capabilities. However, since the training process is based on a static data set, these models are prone to knowledge update lag, factual errors and other problems after deployment, which limits their reliability and practicality in open domain tasks.
[0003] To solve the problem of outdated knowledge, traditional methods usually use retraining or fine-tuning of the model to integrate new knowledge into the model. However, such methods not only have high costs, but also easily cause catastrophic forgetting, i.e. the model damages the old knowledge it has mastered in the process of learning new knowledge, causing overall performance degradation.
[0004] In recent years, researchers have proposed the "model editing" task, aiming to make fine-grained modifications to specific knowledge without significantly adjusting the overall parameters of the model. Existing model editing methods mainly include two categories: direct modification of model parameters and introduction of external knowledge modules: the former relies on analysis and positioning of model internal weights, but faces problems such as weak generalization and high computational cost; the latter uses context prompts or external memory to assist model reasoning, but is easily affected by similar semantic interference and weak knowledge transfer ability.
[0005] The core idea of context prompting is to enhance the model's knowledge updating ability through external memory modules or context guidance mechanisms. However, context knowledge editing still has deficiencies in knowledge updating.
[0006] (1) Weak semantic distinction of neighboring knowledge points: when injecting context information of a specific domain, the model is easily disturbed by similar but unrelated knowledge in that domain, leading to a decline in the accuracy and consistency of the generated results.
[0007] (2) Weak consistency of associated knowledge updating: when using context information for editing, the model can usually only recall existing knowledge, but it is difficult to apply updated knowledge flexibly in different scenarios. This limitation significantly weakens the performance of context-aware editing methods in dynamic knowledge updating.
[0008] Therefore, designing an efficient and controllable knowledge editing mechanism while ensuring reliability, locality, and generalization remains a core challenge for current model editing technology. A successful model edit must satisfy the following basic attributes:
[0009] (1) Reliability: After editing, the model can accurately reflect the updated target knowledge without producing deviations or errors.
[0010] (2) Generality refers to the ability of edited knowledge to be consistently applied across different contexts or tasks, rather than being limited to the specific scenario at the time of editing. Example: If the knowledge point "Earth is the third planet in the solar system" is edited, then this fact should be correctly used in question-and-answer, text generation, and reasoning tasks.
[0011] (3) Locality refers to the fact that editing operations only affect the target knowledge without destroying or interfering with other knowledge that is unrelated to it. Example: When editing "The Thames River flows through London", it should not affect the model's understanding and generation of unrelated facts such as "The Nile River flows through Egypt".
[0012] (4) Portability refers to the ability of editing operations to correctly invoke updated knowledge under various tasks or conditions.
[0013] These attributes collectively determine the effectiveness and robustness of knowledge editing methods. An ideal method should accurately update the target knowledge while maintaining the integrity of irrelevant knowledge, and be readily applicable in different scenarios. Summary of the Invention
[0014] Based on the problems and shortcomings of the existing technologies, this invention proposes a controllable text generation method based on frame semantic knowledge, combined with the needs of practical application scenarios. (1) In order to solve the problem of insufficient semantic distinguishability in neighboring knowledge, a semantic frame network is introduced to perform frame semantic parsing on the input and its associated context facts. Based on the comparative analysis of the semantic frame, its similarity is evaluated. An adaptive threshold is set in combination with the comparison results to define the knowledge boundary, thereby enhancing the semantic distinguishability of neighboring knowledge and avoiding interference from irrelevant knowledge. (2) In order to solve the problem of weak consistency in the updating of associated knowledge, a comparative perception distribution decoding mechanism is proposed. By constructing a comparative representation of the original distribution and the distribution after knowledge fusion, the probability distribution shift in the knowledge fusion process is captured. A dual filtering mechanism is designed to improve the accuracy and stability of knowledge fusion.
[0015] To achieve the above objectives, the present invention is implemented through the following technical solution:
[0016] A controllable text generation method based on frame semantic knowledge, the method comprising the following steps:
[0017] Step 1: Obtain user input ;
[0018] Step 2: Using user input as search criteria, retrieve relevant external knowledge from an external knowledge base;
[0019] The specific operation of step 2 is as follows:
[0020] User input Through sentence vector model Map it to a normalized embedding Subsequently, a collection of sentences is loaded from an external knowledge base. and its corresponding embedding Through dot product similarity Compute input embedding A set is formed based on the semantic similarity of all candidate embeddings. And by performing a retrieval operation, the sentences with the highest similarity scores are extracted, i.e., the set. The top-1 element (Top-1) retrieved the following sentence: The sentence Considered as related to user input The closest example in the semantic space is the retrieval of the corresponding external knowledge.
[0021] Step 3: Use user input as input instruction 1, and external knowledge and user input as instruction 2. Use the framework semantic parsing tool to parse the framework information corresponding to external knowledge and user input.
[0022] The specific operation of step 3 is as follows:
[0023] User input and external knowledge The NLTK tool is used for frame semantic parsing to extract the corresponding semantic frames and map them to the corresponding frame vector space for user input. and external knowledge Use a regular expression segmenter to extract the vocabulary set. Stop words and invalid symbols were removed, important words were retained, and the retained words were tagged with their parts of speech. Mark each word The grammatical function of words Query its semantic frame set in FrameNet. ,when Take the first relevant frame As the main semantic framework for this word, the set of frames corresponding to all words in the text. Convert to frame vector According to the framework parsing, the user input is... and external knowledge Constructing semantic framework vectors and The frame vectors are input into the BERT pre-trained model to obtain the BERT-encoded frame vector embeddings, as shown in the formula:
[0024]
[0025] in, and These are the BERT-encoded frame vector embeddings.
[0026] Step 4: Compare the external knowledge with the framework information corresponding to the user input;
[0027] The specific operation of step 4 is as follows:
[0028] The similarity between two frame vector embeddings is calculated using the cosine similarity formula:
[0029]
[0030] in, express and The cosine similarity between the two frames measures their proximity in the semantic space; the final similarity value... express and Similarity in semantic frame space. The closer the value is to 1, the closer the two are semantically. This similarity is used to set a knowledge boundary threshold to determine whether to retrieve facts. Editing or filtering is used as target knowledge to reduce the impact of irrelevant knowledge on the query.
[0031] Step 5: When the external knowledge and the framework information corresponding to the user input are related, the output content of instruction 1 and instruction 2 are obtained, and the comparison and perceptual decoding strategy is used to obtain the content that meets the user's needs; when the two are not related, the output content of instruction 1 is obtained, which is the user's output content.
[0032] The specific operation of step 5 is as follows:
[0033] When user input is detected and external knowledge When the two are highly correlated, a contrastive decoding strategy is used; when they are not correlated, the user input text is directly injected into the LLMs to obtain the corresponding output.
[0034] The contrast-based decoding strategy is as follows:
[0035] 1) Given user input As input instruction 1, the instruction 1 corresponds to the first... The probability distribution of each token is as follows: ;
[0036] in, Indicates the first The original model for prediction The conditional probability distribution, Representing the original model The previously predicted token; the token represents the content corresponding to the model's output Logits;
[0037] external knowledge and user input As instruction 2, the updated model corresponding to instruction 2 The probability distribution is calculated as follows: ;
[0038] and Representing the original model The corresponding item in the editing model;
[0039] Given the original model and updating the model User input Introducing adjustable hyperparameters As a distribution correction factor, the differences in their probability distributions caused by the editing knowledge are captured by the following subtraction: ;
[0040] 2) To address the need to suppress the interference of redundant tokens on the probability distribution, a dual dynamic constraint framework is designed to achieve hierarchical adaptive calibration of the output.
[0041] (1) Adapted to the edited model The probability distribution is numerically stable through log_softmax transformation, and a dynamic threshold is defined based on this. Taking into account the relative proportion of the highest probability value and before The minimum value of the highest-scoring term; ,
[0042] in This represents the number of items arranged in descending order of probability. Major items, ensure at least [retained] One candidate;
[0043] The screening process involves comparison. With threshold The formula for determining whether to retain a character is:
[0044]
[0045] (2) By introducing a dynamic masking mechanism, the decoding process driven by inherent parameter knowledge is subject to structured constraints;
[0046] Log-normalization of the output of the original model:
[0047] By comparison and Construct lifting mask ,express Candidates with increased probability:
[0048]
[0049] Combined with the initial mask The final mask is generated through logical AND and NOT operations. Disable non-priority candidates:
[0050] Based on the final mask right To filter, the masked candidates are set to a minimum value, using the following formula: ,
[0051] in, It represents -10.
[0052] This method employs a priority retention strategy to systematically screen highly relevant information, while establishing an elimination mechanism based on confidence assessment to exclude low-quality candidate content.
[0053] Compared with the prior art, the present invention has the following advantages:
[0054] In terms of generalization, this invention achieves structured modeling of semantic relationships in different contexts by using semantic framework parsing and adaptive threshold setting, which significantly improves the model's generalization ability in cross-domain and cross-task scenarios.
[0055] In terms of robustness, by comparing the dynamic modeling of the original and edited probability distributions and supplementing it with a dual filtering mechanism, false activation and semantic drift are effectively suppressed, and the robustness of the model in the face of high-noise contexts is enhanced.
[0056] In terms of accuracy, the probability offset monitoring and semantic alignment strategies introduced during the knowledge update process enable the edited knowledge to be accurately invoked during the generation process, thereby improving the accuracy of the model at the level of fact representation.
[0057] Experimental results on the ZSRE and CounterFact datasets demonstrate that this method significantly improves the accuracy, generalization, and robustness of knowledge editing. This invention provides a novel approach to improving knowledge updating and fusion in large language models, laying the foundation for more refined knowledge management and optimization in the future. Attached Figure Description
[0058] Figure 1 A flowchart of a controllable text generation method based on frame semantic knowledge;
[0059] Figure 2 Here is a flowchart illustrating a controllable text generation method based on frame semantic knowledge.
[0060] Figure 3 An interaction diagram for a controllable text generation method based on frame semantic knowledge;
[0061] Figure 4 This is an architecture diagram of a controllable text generation method based on framework semantic knowledge.
[0062] Figure 5 This is a knowledge boundary identification method based on a semantic framework;
[0063] Figure 6 For comparison, see the flowchart of the perception decoding process. Detailed Implementation
[0064] To gain a deeper understanding of this invention, we will provide a comprehensive and detailed description. However, this invention has various implementations and is not limited to the specific examples listed herein. These examples are presented to enhance a full understanding of the disclosure of this invention.
[0065] A controllable text generation method based on frame semantic knowledge, the method comprising the following steps:
[0066] Step 1: Obtain user input ;
[0067] Step 2: Using user input as search criteria, retrieve relevant external knowledge from an external knowledge base;
[0068] The specific operation of step 2 is as follows:
[0069] User input Through sentence vector model Map it to a normalized embedding Subsequently, a collection of sentences is loaded from an external knowledge base. and its corresponding embedding Through dot product similarity Compute input embedding A set is formed based on the semantic similarity of all candidate embeddings. And by performing a retrieval operation, the sentences with the highest similarity scores are extracted, i.e., the set. The top-1 element (Top-1) retrieved the following sentence: The sentence Considered as related to user input The closest example in the semantic space is the retrieval of the corresponding external knowledge.
[0070] Step 3: Treat user input as input instruction 1, and external knowledge and user input as instruction 2, and use the framework semantic parsing tool to parse the external knowledge and user input. Corresponding framework information;
[0071] The specific operation of step 3 is as follows:
[0072] User input and external knowledge The NLTK tool is used for frame semantic parsing to extract the corresponding semantic frames and map them to the corresponding frame vector space for user input. and external knowledge Use a regular expression segmenter to extract the vocabulary set. Stop words and invalid symbols were removed, important words were retained, and the retained words were tagged with their parts of speech. Mark each word The grammatical function of words Query its semantic frame set in FrameNet. ,when Take the first relevant frame As the main semantic framework for this word, the set of frames corresponding to all words in the text. Convert to frame vector According to the framework parsing, the user input is... and external knowledge Constructing semantic framework vectors and The frame vectors are input into the BERT pre-trained model to obtain the BERT-encoded frame vector embeddings, as shown in the formula:
[0073]
[0074] in, and These are the BERT-encoded frame vector embeddings.
[0075] Step 4: Compare the external knowledge with the framework information corresponding to the user input;
[0076] The specific operation of step 4 is as follows:
[0077] The similarity between two frame vector embeddings is calculated using the cosine similarity formula:
[0078]
[0079] in, express and The cosine similarity between the two frames measures their proximity in the semantic space; the final similarity value... express and Similarity in semantic frame space. The closer the value is to 1, the closer the two are semantically. This similarity is used to set a knowledge boundary threshold to determine whether to retrieve facts. Editing or filtering is used as target knowledge to reduce the impact of irrelevant knowledge on the query.
[0080] Step 5: When the external knowledge and the framework information corresponding to the user input are related, the output content of instruction 1 and instruction 2 are obtained, and the comparison and perceptual decoding strategy is used to obtain the content that meets the user's needs; when the two are not related, the output content of instruction 1 is obtained, which is the user's output content.
[0081] The specific operation of step 5 is as follows:
[0082] When user input is detected and external knowledge When the two are highly correlated, a contrastive decoding strategy is used; when they are not correlated, the user input text is directly injected into the LLMs to obtain the corresponding output.
[0083] The contrast-based decoding strategy is as follows:
[0084] 1) Given user input As input instruction 1, the instruction 1 corresponds to the first... The probability distribution of each token is as follows: ;
[0085] in, Indicates the first The original model for prediction The conditional probability distribution, Representing the original model The previously predicted token; the token represents the content corresponding to the model's output Logits;
[0086] external knowledge and user input As instruction 2, the updated model corresponding to instruction 2 The probability distribution is calculated as follows: ;
[0087] and Representing the original model The corresponding item in the editing model;
[0088] Given the original model and updating the model User input Introducing adjustable hyperparameters As a distribution correction factor, the differences in their probability distributions caused by the editing knowledge are captured by the following subtraction: ;
[0089] 2) To address the need to suppress the interference of redundant tokens on the probability distribution, a dual dynamic constraint framework is designed to achieve hierarchical adaptive calibration of the output.
[0090] (1) Adapted to the edited model The probability distribution is numerically stable through log_softmax transformation, and a dynamic threshold is defined based on this. Taking into account the relative proportion of the highest probability value and before The minimum value of the highest-scoring term; ,
[0091] in This represents the number of items arranged in descending order of probability. Major items, ensure at least [retained] One candidate;
[0092] The screening process involves comparison. With threshold The formula for determining whether to retain a character is:
[0093]
[0094] (2) By introducing a dynamic masking mechanism, the decoding process driven by inherent parameter knowledge is subject to structured constraints;
[0095] Log-normalization of the output of the original model:
[0096] By comparison and Construct lifting mask ,express Candidates with increased probability:
[0097]
[0098] Combined with the initial mask The final mask is generated through logical AND and NOT operations. Disable non-priority candidates:
[0099] Based on the final mask right To filter, the masked candidates are set to a minimum value, using the following formula: ,
[0100] in, It represents -10.
[0101] This method employs a priority retention strategy to systematically screen highly relevant information, while establishing an elimination mechanism based on confidence assessment to exclude low-quality candidate content.
[0102] This invention conducted comparative experiments with existing methods on the knowledge fusion task on two datasets, ZsRE and CounterFact. The experimental results are shown in Table 1 below.
[0103] Table 1. Experimental results of Zsre and Counterfact datasets on different models.
[0104]
[0105] The ZsRE (Zero-shot Relation Extraction) dataset is specifically designed for evaluating and training relation extraction models. Relation extraction is a key task in natural language processing, aiming to identify and extract relationships between entities from text. In our testing, we replace the entity extraction task with a text generation method, using generation to obtain entity relationships. The unique feature of the ZsRE dataset is that it is primarily designed for zero-shot learning scenarios.
[0106] The CounterFact dataset is specifically designed to evaluate and improve the performance of large-scale language models in generating false or counterfactual information. Counterfactual information refers to information that contradicts known facts and is typically used to test a model's understanding of facts and its ability to maintain factual consistency.
[0107] The FCCE (Fulfilled Completion Certificate) represents the experimental results of this invention. In terms of reliability and generality, compared to the IKE baseline model, the fluctuation range of this method's indicators within the applicable scope of knowledge fusion is strictly controlled within ±0.1%, and its overall performance maintains a competitive advantage. Specifically, on the ZSRE dataset: 1) The reliability indicator maintains statistical equivalence with the baseline on the GPT2-XL, GPTJ, and Llama2-7B models; 2) The generality indicator shows a positive fluctuation within 1% on the GPTJ and Llama2-7B models, and an improvement of 4% on the GPT2-XL model. On the Counterfact dataset, the reliability indicator shows a significant improvement across all test models, with an average improvement of 13%.
[0108] This method demonstrates a significant advantage in locality, exhibiting stronger control over local effects compared to both the baseline model and the comparative experimental group. On the ZSRE dataset, the locality metrics of the GPT2-XL, GPTJ, and Llama2-7B models are significantly improved, while on the Counterfact dataset, this metric shows an increase of approximately 22% on these models, further validating the effectiveness of the method. Locality evaluation aims to measure whether the impact of editing operations on the target knowledge points is controlled, avoiding unexpected global performance fluctuations. In contrast, the comparative experimental group failed to effectively constrain the update impact, leading to a decline in local task performance, highlighting the superiority of this method in locality control.
[0109] The method demonstrates significant advantages in portability, achieving stable performance gains on both the ZSRE and Counterfact datasets, indicating strong task adaptability and domain generalization ability. Specifically, on the ZSRE dataset, the portability metric of the GPT2-XL, GPTJ, and Llama2-7B models improves by an average of approximately 3%; on the Counterfact dataset, this metric improves by an average of 2% across different models, demonstrating good transferability between different models. Although there may be slight fluctuations on specific models or datasets, the overall performance improvement validates the method's transfer stability and adaptability, further demonstrating its applicability and robustness across various model architectures and task settings. This illustrates that our method can incorporate more complex knowledge into text generation, further validating its superiority in utilizing updated and integrated knowledge.
[0110] The above description is only for better explaining the embodiments of the present invention and is not intended to limit them. Any modifications or equivalent substitutions that do not depart from the spirit and scope of the present invention shall fall within the scope of the present invention.
Claims
1. A controllable text generation method based on frame semantic knowledge, characterized in that, The method includes the following steps: Step 1: Obtain user input ; Step 2: Using user input as search criteria, retrieve relevant external knowledge from an external knowledge base; Step 3: Use user input as input instruction 1, and external knowledge and user input as instruction 2. Use the framework semantic parsing tool to parse the framework information corresponding to external knowledge and user input. Step 4: Compare the external knowledge with the framework information corresponding to the user input; Step 5: When the external knowledge and the framework information corresponding to the user input are related, the output content of instruction 1 and instruction 2 are obtained, and the comparison and perception decoding strategy is used to obtain the content that meets the user's needs; when the two are not related, the output content of instruction 1 is obtained, which is the user's output content.
2. The controllable text generation method based on frame semantic knowledge according to claim 1, characterized in that, The specific operation of step 2 is as follows: User input Through sentence vector model Map it to a normalized embedding Subsequently, a collection of sentences is loaded from an external knowledge base. and its corresponding embedding Through dot product similarity Computational input embedding A set is formed based on the semantic similarity of all candidate embeddings. And by performing a retrieval operation, the sentences with the highest similarity scores are extracted, i.e., the set. The top-level element retrieved the following sentence: The sentence Considered as related to user input The closest example in the semantic space is the retrieval of the corresponding external knowledge.
3. The controllable text generation method based on frame semantic knowledge according to claim 1, characterized in that, The specific operation of step 3 is as follows: User input and external knowledge The NLTK tool is used for frame semantic parsing to extract the corresponding semantic frames and map them to the corresponding frame vector space. This is then applied to user input. and external knowledge Use a regular expression segmenter to extract the vocabulary set. Remove stop words and invalid symbols, retain important words, and perform part-of-speech tagging on the retained words. Mark each word The grammatical function of words Query its semantic frame set in FrameNet. ,when Take the first relevant frame As the main semantic framework for this word, the set of frames corresponding to all words in the text. Convert to frame vector According to the framework parsing, the user input is... and external knowledge Constructing semantic framework vectors and The frame vectors are input into the BERT pre-trained model to obtain the BERT-encoded frame vector embeddings, as shown in the formula: ; in, and These are the BERT-encoded frame vector embeddings.
4. The controllable text generation method based on frame semantic knowledge according to claim 1, characterized in that, The specific operation of step 4 is as follows: The similarity between two frame vector embeddings is calculated using the cosine similarity formula: ; in, express and The cosine similarity between the two frames measures their proximity in the semantic space; the final similarity value... express and The degree of similarity in the semantic frame space.
5. The controllable text generation method based on frame semantic knowledge according to claim 1, characterized in that, The specific operation of step 5 is as follows: When user input is detected and external knowledge When the two are highly correlated, a contrastive decoding strategy is used; when they are not correlated, the user input text is directly injected into the LLMs to obtain the corresponding output. The contrast-based decoding strategy is as follows: 1) Given user input As input instruction 1, the instruction 1 corresponds to the first... The probability distribution of each token is as follows: ; in, Indicates the first The original model for prediction The conditional probability distribution, Represents the original model The previously predicted token; the token represents the content corresponding to the model's output Logits; external knowledge and user input As instruction 2, the updated model corresponding to instruction 2 The probability distribution is calculated as follows: ; and Represents the original model The corresponding item in the editing model; Given the original model and updating the model User input Introducing adjustable hyperparameters As a distribution correction factor, the differences in their probability distributions caused by the editing knowledge are captured by the following subtraction: ; 2) To address the need to suppress the interference of redundant tokens on the probability distribution, a dual dynamic constraint framework is designed to achieve hierarchical adaptive calibration of the output. (1) Adapted to the edited model The probability distribution is numerically stable through log_softmax transformation, and a dynamic threshold is defined based on this. Taking into account the relative proportion of the highest probability value and before The minimum value of the highest-scoring term; , in This represents the number of items arranged in descending order of probability. Major items, ensure at least [retained] One candidate; The screening process involves comparison. With threshold The formula for determining whether to retain a character is: ; (2) By introducing a dynamic masking mechanism, the decoding process driven by inherent parameter knowledge is subject to structured constraints; Log-normalization of the output of the original model:
6. Through comparison and Construct lifting mask ,express Candidates with increased probability: ; Combined with the initial mask The final mask is generated through logical AND and NOT operations. Disable non-priority candidates: ; Based on the final mask right To filter, the masked candidates are set to a minimum value, using the following formula: , in, It represents -10.
Citation Information
Cited By
Retrieval enhancement generation method and retrieval enhancement model construction method
CN122262299A
A retrieval augmentation generation method and a construction method of a retrieval augmentation model
CN122262299B