Large language model question and answer rule packaging method, medium and system

By constructing rule graphs and graph search algorithms, the answers generated by the large language model are gradually corrected to meet multiple rule requirements, solving the problem that the large language model lacks rule considerations when generating answers, and achieving high-quality, safe and reliable question-and-answer output.

CN119149703APending Publication Date: 2024-12-17青岛网信信息科技有限公司 +1

Patent Information

Application Number
CN202411545180.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-01
Publication Date
2024-12-17

AI Technical Summary

Technical Problem

Large language models lack consideration and constraints on rules when generating answers, and it is difficult to generate content that follows rules such as morality, privacy, and security. Existing methods are difficult to flexibly adjust and expand the coupling between the rule module and the model.

Method used

Build multiple lightweight neural networks, each network corresponds to a rule type, determine the rule processing sequence by constructing rule diagrams and graph search algorithms, and gradually correct the initial answers to meet the requirements of various rules.

Benefits of technology

It realizes the generation of high-quality Q&A results that meet user needs and follow multiple rules requirements, improves the flexibility and pertinence of rule processing, and ensures the security and compliance of output content.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119149703A_ABST
    Figure CN119149703A_ABST
Patent Text Reader

Abstract

The invention provides a large language model question and answer rule packaging method, medium and system, belongs to the technical field of large language models, and forms a rule graph by constructing a plurality of lightweight neural networks, each network corresponding to a rule type and calculating the similarity between rules. After a question is received, firstly, an initial answer is given by utilizing a large language model, then the correlation degree between the initial answer and each rule is calculated, and a most relevant rule processing sequence is found out. And inputting the initial answer into each lightweight network in the sequence in sequence, performing regularization processing, and finally outputting a regularized result as a final answer of the question. According to the method, extensive knowledge of a large language model and the special rule processing capacity of a small neural network are combined, and answers better meeting the requirements of questioners can be given. The whole process is high in automation degree and transparent to questioners, and the problem that in the prior art, the coupling degree between a rule module and a large language model is high and is difficult to flexibly adjust and expand can be solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of large language models, and in particular, relates to a large language model question-answering rule encapsulation method, medium and system. Background Art

[0002] Currently, large language models have been widely used in question-answering systems, content production and other fields. These systems based on large language models can give smooth and coherent answers to users' natural language questions. However, these large language models often lack consideration and constraints on relevant rules in the process of generating answers, and it is easy to produce content that violates moral, privacy, security and other rules. For example, when answering questions involving ethical issues, personal privacy, social security, etc., large language models may give some inappropriate and controversial content.

[0003] To address this problem, some researchers have tried to solve it by adding rule constraints when training large language models. However, this method often fails to cover all possible rule scenarios, and the design and implementation of rules are also very complex. Other studies have proposed building a special rule module to assist large language models in generating answers that conform to the rules. However, this method usually requires a large number of manually annotated samples to train the rule module, and the coupling between the rule module and the large language model is high, making it difficult to flexibly adjust and expand.

[0004] Therefore, there is an urgent need for a more general and flexible large language model question-answering rule encapsulation method that can effectively utilize the generation capabilities of large language models and the constraint capabilities of various specialized rules to generate high-quality question-answering results that meet user needs and comply with various rule requirements. Summary of the invention

[0005] In view of this, the present invention provides a large language model question and answer rule encapsulation method, medium and system, which can solve the problem in the prior art that the coupling degree between the rule module and the large language model is high and difficult to flexibly adjust and expand.

[0006] The present invention is achieved in that: A first aspect of the present invention provides a large language model question-answering rule encapsulation method, which includes the following steps: S10. Construct multiple lightweight neural networks, each lightweight neural network corresponds to a rule type; each lightweight neural network is provided with a trigger phrase, including multiple trigger words, and the similarity between all trigger phrases is calculated; specifically, it includes: first, construct multiple lightweight neural networks, each lightweight neural network corresponds to a rule type. This lightweight neural network adopts a multi-layer perceptron structure and is used for text classification and content modification. The input is the text vector to be processed, and the output is the modified text vector and its corresponding rule compliance score. Secondly, each lightweight neural network is set to have a trigger phrase, including multiple trigger words. In order to calculate the similarity between all trigger phrases, it specifically includes: converting each trigger phrase into a word vector, calculating the cosine similarity between two trigger phrases, and taking the average of the similarities of all word pairs as the final trigger phrase similarity. The purpose of this step is to establish the association relationship between the rules; S20, forming a rule graph with all lightweight neural networks, wherein the nodes of the rule graph are each lightweight neural network, the values ​​of the nodes are the corresponding trigger phrases, and the edges of the rule graph are the similarities between the trigger phrases corresponding to two nodes; the purpose of this step is to construct a rule relationship network that can be retrieved and traversed; S30, receiving the question input by the questioner, inputting the question into the large language model, and obtaining an initial answer; the purpose of this step is to obtain the initial answer generated by the large language model as a basis; S40. Calculate the correlation between the initial answer and each trigger phrase, taking the node corresponding to the trigger phrase with the highest correlation as the starting node, and taking the node corresponding to the trigger phrase with the lowest correlation higher than the minimum threshold as the destination node; Calculate the correlation between the initial answer and each trigger phrase. Take the node corresponding to the trigger phrase with the highest correlation as the starting node, and take the node corresponding to the trigger phrase with the lowest correlation higher than the minimum threshold as the destination node. The minimum threshold can be obtained by the following steps: collect a large amount of sample data, calculate the correlation distribution of the trigger phrases in the sample data, and select the minimum correlation value that can cover 80% of the samples as the minimum threshold, with a default value of 0.5. The purpose of this step is to determine the scope of the rules that need to be applied, that is, to determine the starting node and the destination node; S50, in the rule graph, using a graph search algorithm to determine the shortest path from the start node to the destination node, the nodes on the shortest path forming a rule processing sequence; S60, input the initial answer into the lightweight neural network corresponding to each node in the rule processing sequence in sequence, each lightweight neural network performs corresponding rule processing on the input content, and outputs the regularized result; specifically, it includes: performing semantic analysis on the input text, identifying the content that violates the corresponding rules, and modifying or deleting the illegal content, and finally outputting the text that meets the requirements of the rules. The purpose of this step is to gradually correct and improve the initial answer using various rules; S70. Use the regularization result output by the last lightweight neural network in the rule processing sequence as the final answer to the questioner's question.

[0007] On the basis of the above technical solution, the large language model question-answering rule encapsulation method of the present invention can also be improved as follows: Among them, the rule types include at least moral rules, public opinion rules, privacy rules, security rules, cultural rules, legal rules, emotional rules, and logical rules.

[0008] Furthermore, each lightweight neural network processes the input content according to corresponding rules, specifically performs semantic analysis on the input text, identifies content that violates corresponding rules, modifies or deletes the illegal content, and finally outputs text that meets the requirements of the rules.

[0009] Furthermore, the lightweight neural network adopts a multi-layer perceptron structure for text classification and content modification, the input is the text vector to be processed, and the output is the modified text vector and its corresponding rule compliance score.

[0010] Furthermore, the steps of constructing the training data set of the lightweight neural network specifically include collecting a large number of text samples that meet and violate specific rules, preprocessing and labeling the samples, converting the samples into vector form, and dividing the training set and the validation set.

[0011] Furthermore, the training steps of the lightweight neural network specifically include initializing network parameters, using batch gradient descent method for forward propagation and back propagation, calculating loss function and updating parameters, evaluating model performance on a validation set, and repeating the above steps until convergence or reaching a preset training round.

[0012] Furthermore, the step of calculating the similarity between the trigger phrases is to convert each trigger phrase into a word vector, calculate the cosine similarity between the two trigger phrases, and take the average of the similarities of all word pairs as the final trigger phrase similarity.

[0013] Furthermore, the minimum threshold is 0.5 by default.

[0014] The minimum threshold can also be obtained by the following steps: collecting a large amount of sample data, calculating the relevance distribution of trigger phrases in the sample data, and selecting the minimum relevance value that can cover 80% of the samples as the minimum threshold.

[0015] Furthermore, the moral rules are used to identify and process content involving ethical issues, and the corresponding trigger phrases include at least words indicating kindness, integrity, honesty, fairness, responsibility, respect, sympathy, justice, etc., or their synonyms, antonyms, and antonyms; The public opinion rules are used to identify and process content that may cause public opinion disputes, and the corresponding trigger phrases at least include words indicating hot spots, disputes, public opinion, dissemination, influence, viewpoints, attitudes, tendencies, or their synonyms, near-synonyms, and antonyms; The privacy rules are used to identify and protect information related to personal privacy, and the corresponding trigger phrases include at least words representing personal information, privacy, confidentiality, data protection, anonymity, authorization, consent, disclosure, or their synonyms, antonyms, and antonyms; The security rules are used to identify and process content that may threaten public security, and the corresponding trigger phrases at least include words such as danger, threat, risk, safety, protection, warning, emergency, and prevention, or their synonyms, near-synonyms, and antonyms; The cultural rules are used to identify and respect content from different cultural backgrounds, and the corresponding trigger phrases include at least words representing culture, tradition, custom, taboo, etiquette, belief, diversity, tolerance or their synonyms, antonyms, and antonyms; The legal rules are used to identify and process content involving legal issues, and the corresponding trigger phrases include at least words representing laws, regulations, rules, rights, obligations, illegality, legality, litigation, or their synonyms, antonyms, and antonyms; The emotional rules are used to identify and adjust the emotional tendencies in the answers, and the corresponding trigger phrases include at least words that express emotions, feelings, attitudes, tones, resonance, comfort, encouragement, understanding, or their synonyms, antonyms, and near synonyms; The logic rules are used to ensure the logic and coherence of the answers, and the corresponding trigger phrases include at least words representing reasoning, argumentation, causality, premise, conclusion, contradiction, consistency, rationality or their synonyms, near-synonyms and antonyms.

[0016] A second aspect of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores program instructions, and when the program instructions are run in a computer, they are used to execute the above-mentioned large language model question and answer rule encapsulation method.

[0017] A third aspect of the present invention provides a large language model question-answering rule encapsulation system, which includes the above-mentioned computer-readable storage medium.

[0018] Compared with the prior art, the large language model question-answering rule encapsulation method, medium and system provided by the present invention have the following beneficial effects: first, the method constructs multiple lightweight neural networks as implementation modules of various rules, and each module is optimized and trained for a specific rule type. This divide-and-conquer design greatly improves the flexibility and pertinence of rule processing.

[0019] Secondly, the method constructs these rule neural networks into a rule relationship graph and determines the optimal rule processing sequence through a graph search algorithm. This method based on the rule relationship graph can not only automatically identify and apply relevant rules, but also make full use of the correlation between rules to generate more comprehensive and systematic rule-based answers.

[0020] Thirdly, this method dynamically determines the scope of rules to be applied based on the correlation between the preliminary answer and each rule trigger phrase, avoiding the inefficient practice of simply enumerating all rules. At the same time, a method for adaptively adjusting the minimum threshold of the rule is proposed, which further improves the pertinence and robustness of rule application.

[0021] In general, the large language model question-answering rule encapsulation method proposed in the present invention fully utilizes the generation capability of the large language model and the constraint capability of various specialized rules, and can generate high-quality question-answering results that meet both user needs and various rule requirements. Compared with the prior art, this method has stronger versatility, flexibility, and adaptability, and while improving the quality of question-answering, it also ensures the security and compliance of the output content. It solves the problem in the prior art that the degree of coupling between the rule module and the large language model is high and difficult to flexibly adjust and expand. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] Figure 1 A flow chart of the method provided by the present invention; Figure 2 is a rule relationship diagram in Example 2; Figure 3 It is the correlation graph between the preliminary answer and the rule trigger phrase; Figure 4 This is a comparison chart before and after rule processing. DETAILED DESCRIPTION

[0023] In order to make the purpose, technical solution and advantages of the embodiments of the present invention more clear, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present invention.

[0024] like Figure 1 As shown, it is a flow chart of a large language model question-answering rule encapsulation method provided by the first aspect of the present invention. The method comprises the following steps: S10, constructing multiple lightweight neural networks, each lightweight neural network corresponds to a rule type; each lightweight neural network is provided with a trigger phrase, including multiple trigger words, and calculating the similarity between all trigger phrases; S20, forming a rule graph with all lightweight neural networks, where the nodes of the rule graph are each lightweight neural network, the values ​​of the nodes are the corresponding trigger phrases, and the edges of the rule graph are the similarities between the trigger phrases corresponding to the two nodes; S30, receiving the question input by the questioner, inputting the question into the large language model, and obtaining an initial answer; S40, calculating the relevance between the initial answer and each trigger phrase, taking the node corresponding to the trigger phrase with the highest relevance as the starting node, and taking the node corresponding to the trigger phrase with the lowest relevance higher than the minimum threshold as the destination node; S50, in the rule graph, using a graph search algorithm to determine the shortest path from the start node to the destination node, and the nodes on the shortest path constitute a rule processing sequence; S60, inputting the initial answer into the lightweight neural network corresponding to each node in the rule processing sequence in sequence, each lightweight neural network performs corresponding rule processing on the input content, and outputs a regularized result; S70. Use the regularization result output by the last lightweight neural network in the rule processing sequence as the final answer to the questioner's question.

[0025] The specific implementation methods of the above steps are described in detail below: The specific implementation of step S10 is as follows: first, multiple lightweight neural networks are constructed, each lightweight neural network corresponds to a rule type. This lightweight neural network adopts a multi-layer perceptron structure and is used for text classification and content modification. The input is the text vector to be processed, and the output is the modified text vector and its corresponding rule compliance score.

[0026] The steps to construct a training data set for a lightweight neural network include: collecting a large number of text samples that meet or violate specific rules, preprocessing and labeling the samples, converting the samples into vector form, and dividing the training set and the validation set. The training steps include: initializing network parameters, using batch gradient descent for forward and backward propagation, calculating the loss function and updating the parameters, evaluating the model performance on the validation set, and repeating the above steps until convergence or reaching the preset training rounds.

[0027] Each lightweight neural network is set with a trigger phrase, including multiple trigger words. In order to calculate the similarity between all trigger phrases, the specific steps are: convert each trigger phrase into a word vector, calculate the cosine similarity between two trigger phrases, and take the average of the similarities of all word pairs as the final trigger phrase similarity. The purpose of this step is to establish the association relationship between rules.

[0028] The specific implementation of step S20 is: all lightweight neural networks are formed into a rule graph. The nodes of the rule graph are each lightweight neural network, and the values ​​of the nodes are the corresponding trigger phrases. The edges of the rule graph are the similarities between the trigger phrases corresponding to the two nodes. The purpose of this step is to build a rule relationship network that can be retrieved and traversed.

[0029] The specific implementation of step S30 is: receiving the question input by the questioner, inputting the question into the large language model, and obtaining an initial answer. The purpose of this step is to obtain the initial answer generated by the large language model as a basis.

[0030] The specific implementation of step S40 is: calculate the correlation between the initial answer and each trigger phrase. Take the node corresponding to the trigger phrase with the highest correlation as the starting node, and take the node corresponding to the trigger phrase with the lowest correlation higher than the minimum threshold as the destination node. The purpose of this step is to determine the scope of the rules that need to be applied, that is, to determine the starting node and the destination node. The minimum threshold can be obtained by the following steps: collect a large amount of sample data, calculate the correlation distribution of the trigger phrases in the sample data, and select the minimum correlation value that can cover 80% of the samples as the minimum threshold, and the default value is 0.5.

[0031] The specific implementation of step S50 is: in the rule graph, a graph search algorithm is used to determine the shortest path from the start node to the destination node. The nodes on the shortest path constitute a rule processing sequence. The purpose of this step is to determine the rule processing sequence that needs to be applied.

[0032] The specific implementation of step S60 is: the initial answer is sequentially input into the lightweight neural network corresponding to each node in the rule processing sequence. Each lightweight neural network performs corresponding rule processing on the input content and outputs a regularized result. The specific rule processing process is: semantic analysis of the input text, identification of content that violates the corresponding rules, modification or deletion of the illegal content, and finally output of text that meets the requirements of the rules. The purpose of this step is to gradually correct and improve the initial answer using various rules.

[0033] The specific implementation of step S70 is: taking the regularization result output by the last lightweight neural network in the rule processing sequence as the final answer to the questioner's question. The purpose of this step is to output the final regularized answer.

[0034] In general, the core idea of ​​this large language model question-answering rule encapsulation method is: first, build multiple lightweight neural networks specifically for different rule types, each with its own trigger phrase. Then build these neural networks into a rule graph, where the nodes of the rule graph are neural networks and the edges are the trigger phrase similarities. When answering questions, first use the large language model to generate a preliminary answer, then determine the scope of the rules to be applied based on the correlation between the preliminary answer and each trigger phrase, and apply each rule neural network in turn along the shortest path in the rule graph to correct and improve the answer, and finally output the results that meet the requirements of various rules. This method can make full use of the generation ability of the large language model and the constraint ability of various specialized rules to generate high-quality, safe and reliable question-answering output.

[0035] A second aspect of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores program instructions, and when the program instructions are run in a computer, they are used to execute the above-mentioned large language model question and answer rule encapsulation method.

[0036] A third aspect of the present invention provides a large language model question-answering rule encapsulation system, which includes the above-mentioned computer-readable storage medium.

[0037] Specifically, the principle of the present invention is: First, the method constructs multiple lightweight neural networks as rule implementation modules. Each neural network is optimized for specific rule types, such as ethics rules, privacy rules, security rules, etc. These lightweight networks use a multi-layer perceptron structure, with the input being the text vector to be processed and the output being the modified text vector and its rule compliance score. By training these specialized rule networks separately, the characteristics of different rule types can be fully explored and utilized, greatly improving the pertinence and flexibility of rule processing.

[0038] Secondly, this method constructs these rule neural networks into a rule relationship graph. The nodes of the rule graph are the rule networks, and the values ​​of the nodes are the corresponding trigger phrases; the edges of the rule graph are the similarities between two trigger phrases, reflecting the degree of association between the rules. By establishing such a rule relationship network, the graph search algorithm can be used to automatically determine the optimal rule processing sequence, thereby generating a more comprehensive and systematic regularized answer.

[0039] Thirdly, this method dynamically determines the scope of rules that need to be applied based on the correlation between the preliminary answer and each rule trigger phrase. Specifically, a preliminary answer is first generated using a large language model, and then the correlation between the preliminary answer and each trigger phrase is calculated. Taking the trigger phrase with the highest correlation as the starting node and the lowest trigger phrase with a correlation higher than the minimum threshold as the destination node, the shortest path is searched on the rule graph to determine the sequence of rules that need to be applied in sequence. This dynamic rule determination method based on correlation avoids the inefficient practice of simply enumerating all rules and improves the pertinence of rule application. At the same time, the robustness of the method can be further improved by adaptively adjusting the minimum threshold of the rule.

[0040] Finally, the method inputs the preliminary answers into each lightweight neural network in the rule processing sequence for correction and improvement. Each rule network will perform semantic analysis on the input content, identify the part that violates the corresponding rule, and modify or delete it, and finally output the result that meets the requirements of the rule. Through this step-by-step regularization method, the generation capacity of the large language model and the constraint capacity of various specialized rules can be fully utilized to generate high-quality, safe and reliable question-answering output.

[0041] A specific embodiment 1 of the method of the present invention is given below. The specific implementation of each step in this embodiment 1 is described in detail as follows: First, for step S10, it is necessary to build multiple lightweight neural networks, each network corresponding to a rule type. These lightweight neural networks use a multi-layer perceptron structure for text classification and content modification. Its input is the text vector to be processed , the output is the modified text vector and its corresponding rule compliance score .

[0042] For the network training process, we first need to build a training data set. The specific steps include: 1) Collect a large number of text samples that meet and violate specific rules ,in Indicates 1) Check whether the sample meets the rules; 2) Preprocess and label the sample; 3) Convert the sample into vector form ; 4) Divide into training set and validation set.

[0043] When backpropagating, we need to minimize the loss function ,in is the loss function between text output and label, It is a hyperparameter used to adjust the compliance of the rule. By calculating the gradient And update the parameters , lightweight neural networks that conform to specific rules can be trained.

[0044] When setting trigger phrases, it is necessary to calculate the similarity between all trigger phrases. The specific steps are as follows: 1) Convert to word vector ,in ; 2) Calculate the similarity between the two trigger phrases as ; 3) Take the average of the similarities of all word pairs as the final trigger phrase similarity .

[0045] Next, for step S20, all lightweight neural networks need to be formed into a regular graph. Represents the value of each lightweight neural network node is the corresponding trigger phrase. The edge of the rule graph Indicates the similarity between the trigger phrases corresponding to two nodes . This constructs a regular relationship network that can be retrieved and traversed.

[0046] In step S30, the question input by the questioner is received. , input it into the large language model and get the initial answer The purpose of this step is to obtain a preliminary answer generated by a large language model as a basis.

[0047] In step S40, the initial answer needs to be calculated With each trigger phrase The correlation Specifically, cosine similarity can be used to measure the correlation between the two: ; in Is the trigger phrase The average word vector of .

[0048] Based on relevance , select the node corresponding to the trigger phrase with the highest correlation As the starting node, select the node with a correlation higher than the minimum threshold The node corresponding to the lowest trigger phrase in As the destination node. The purpose of this step is to determine the scope of the rules to be applied. Among them, the minimum threshold This can be obtained by the following steps: 1) Collect a large amount of sample data ; 2) Calculate the relevance distribution of the trigger phrase in each sample ; 3) Select the minimum correlation value that can cover 80% of the samples as the minimum threshold , the default value is 0.5.

[0049] In step S50, it is necessary to determine in the rule graph the starting node To the destination node This can be achieved using graph search algorithms such as the Dijkstra algorithm or the A* algorithm. Specifically, the Dijkstra algorithm can be expressed as: 1) Initialization: , for , forall ; 2) Create a priority queue ; 3) while : ; foreachneighbor of : ; ; ; 4) Return the shortest path .

[0050] Among them, the edge weight It reflects the similarity between two rules. The nodes on the shortest path constitute the rule processing sequence.

[0051] In step S60, the initial answer Enter the lightweight neural network corresponding to each node in the rule processing sequence in turn. Specifically, for the first Nodes ,Will Input the corresponding neural network and get the modified output and its rule compliance score After all the regular neural network processing, the final regularized result is obtained. The purpose of this step is to gradually correct and improve the initial answer using various rules.

[0052] Finally, in step S70, the regularization result output by the last lightweight neural network in the rule processing sequence is As a final answer to the questioner's question.

[0053] In summary, the core idea of ​​this large language model question-answering rule encapsulation method is: first, build multiple lightweight neural networks specifically for different rule types, each with its own trigger phrase. Then build these neural networks into a rule graph, where the nodes of the rule graph are neural networks and the edges are the trigger phrase similarities. When answering questions, first use the large language model to generate a preliminary answer, then determine the scope of the rules to be applied based on the correlation between the preliminary answer and each trigger phrase, and apply each rule neural network in turn along the shortest path in the rule graph to correct and improve the answer, and finally output the results that meet the requirements of various rules. This method can make full use of the generation ability of the large language model and the constraint ability of various specialized rules to generate high-quality, safe and reliable question-answering output.

[0054] In order to better understand and implement the present invention, Example 2 of a specific application scenario of the present invention is provided below: This Example 2 takes an artificial intelligence assistant system as the background, and describes how to use the large language model question and answer rule encapsulation method proposed in the present invention to provide the system with safe and rule-compliant question and answer services.

[0055] The artificial intelligence assistant system is aimed at ordinary users and can interact with users in natural language through voice or text to answer various questions of users. In order to ensure that the answers generated by the system meet both user needs and comply with various important rule requirements, the rule encapsulation method proposed in the present invention is adopted.

[0056] First, eight lightweight neural networks were constructed, each corresponding to a rule type: moral rules, public opinion rules, privacy rules, security rules, cultural rules, legal rules, emotional rules, and logical rules. Taking the moral rule network as an example, its trigger phrases include: Moral rule trigger phrases Words explain Kind Refers to the qualities of noble character and upright behavior upright Refers to the quality of behaving properly and without deception or hypocrisy honest The quality of speaking and acting in a way that is consistent with the facts fair Refers to the quality of following fair and reasonable principles responsibility The quality of taking on obligations and responsibilities respect Refers to the quality of treating others or things with an appropriate attitude pity Refers to the quality of being able to understand and care about the feelings of others justice Refers to the quality of upholding the right path and upholding justice These words summarize the most basic moral qualities and can be used to identify and deal with content involving ethical issues. In practical applications, these trigger words can be further enriched and adjusted according to needs.

[0057] Similarly, corresponding trigger phrases are designed for the other 7 rule types, as follows: Trigger phrases for each rule type Rule Type Trigger phrase Rules of public opinion Hotspot, controversy, public opinion, communication, influence, viewpoint, attitude, tendency Privacy Policy Personal information, privacy, confidentiality, data protection, anonymity, authorization, consent, disclosure Safety Rules danger, threat, risk, safety, protection, warning, emergency, prevention Cultural rules Culture, tradition, custom, taboo, etiquette, belief, diversity, tolerance Legal rules Laws, regulations, rules, rights, obligations, illegality, legality, litigation Emotional rules Emotions, feelings, attitude, tone, resonance, comfort, encouragement, understanding Logical rules Reasoning, argumentation, cause and effect, premise, conclusion, contradiction, consistency, rationality With these rule neural networks and trigger phrases, we can build a rule graph to describe the relationship between various rules. Figure 2 The relationship between the eight rule types is shown, and the weight of the edge reflects the similarity between two rules. This rule graph can be used to determine the sequence of rules that need to be applied in sequence when answering a specific question.

[0058] Next, let's look at a specific question-and-answer scenario:

[0059] The user asked: "I recently saw a piece of news about XXXX, and I was so angry. This XX should be severely punished!" For this question, first use the large language model to generate a preliminary answer: "I understand your anger about this person's behavior, and he should be severely punished according to the law. But we should also look at this issue objectively and not simply generalize. Perhaps we can understand the whole story and consider the overall performance of this person in order to make a more fair judgment." Next, calculate the relevance of this preliminary answer to each rule trigger phrase: Correlation between the initial answer and the rule trigger phrase Rule Type Relevance Ethical rules 0.78 Rules of public opinion 0.72 Privacy Policy 0.45 Safety Rules 0.32 Cultural rules 0.27 Legal rules 0.68 Emotional rules 0.61 Logical rules 0.75 It can be seen that the correlation between moral rules, public opinion rules, legal rules and logical rules is relatively high, indicating that this issue mainly involves these aspects. Figure 3 The bar chart shows the correlation between the initial answers generated by the system and the trigger phrases of 8 different rule types. The specific correlation value is marked above each column. It can be clearly seen from the figure that the correlation between moral rules, public opinion rules, legal rules and logical rules is high, which explains why the system chooses these rules for subsequent processing. Therefore, the nodes corresponding to moral rules, public opinion rules, legal rules and logical rules are set as the starting node and the destination node respectively, and the shortest path is searched on the rule graph, and the following rule processing sequence is obtained: Moral rules → public opinion rules → legal rules → logical rules; Next, the preliminary answer is input into each lightweight neural network in this rule processing sequence for correction. First, it enters the moral rule network for processing. The network will perform semantic analysis on the input text, identify content that violates moral rules, such as "should be severely punished" and other overly intense expressions, and modify them to more moderate expressions, such as "should be punished according to law." The processing results are: "I understand your concern about the XX behavior of this person, and he should indeed be punished according to the law. But we must also look at this issue objectively and not simply generalize. Perhaps we can understand the whole story in depth and consider the overall performance of this person, so as to make a more fair judgment." Then enter the public opinion rule network for processing. The network will analyze whether the text contains expressions that may cause public opinion controversy, such as "XXXX" and "severe punishment", and modify or supplement them appropriately to reduce public opinion risks. The processing results are: "Regarding the reports that XX is suspected of XX, I understand your concerns. This is indeed a hot topic that may arouse public attention. We should adopt an objective and fair attitude, thoroughly understand the whole incident and XX's overall performance, and then make a fair judgment. Although XX's behavior should be punished according to law, we should also remain rational and calm, and avoid emotional excitement that may lead to inappropriate remarks." Then it enters the legal rules network for processing. The network will check whether the text involves legal issues, such as "punished according to law", and ensure that the statement complies with legal norms. The processing results are: "Regarding the reports that XX is suspected of XX, I understand your concerns. This is indeed a hot topic that may arouse public attention. We should adopt an objective and fair attitude, thoroughly understand the whole incident and XX's overall performance, and then make a fair judgment in accordance with the law. XX's behavior should indeed be punished according to the law, but we should also remain rational and calm, avoid emotional excitement and inappropriate remarks, and ensure that our remarks are legal and compliant." Finally, it enters the logic rule network for processing. The network will analyze the logic and coherence of the text to ensure that the answer is smooth and reasonable as a whole. The processing result is:

[0060] "Regarding the reports that XX is suspected of XX, I understand your concerns. This is indeed a hot topic that may arouse public attention. We should adopt an objective and fair attitude, thoroughly understand the whole incident and XX's overall performance, and then make a fair judgment in accordance with the law. XX's behavior should indeed be punished according to the law, but we must also remain rational and calm, avoid emotional excitement and inappropriate remarks, and ensure that the remarks are legal and compliant. Only in this way can we make objective and fair conclusions and maintain social fairness and justice." Through this step-by-step rule processing, an answer is finally generated that meets user needs and complies with various important rule requirements. Figure 4 As shown in the figure, the comparison before and after rule processing is made through expert scoring. The horizontal axis represents the different stages of processing (initial answer to final logical rule processing), and the vertical axis represents the scores of the three key indicators of the answer (objectivity, compliance, and logic). Through this figure, we can intuitively see how rule processing gradually improves the quality of answers.

[0061] This answer not only objectively analyzes the entire incident, but also emphasizes the importance of handling it in accordance with the law. At the same time, it also pays attention to issues such as public opinion influence and language compliance, reflecting a comprehensive and rational attitude.

[0062] If the rule encapsulation method of the present invention is not adopted and the large language model is simply used to generate answers, some problems are likely to occur, such as: 1) Overly emotional words may cause inappropriate public opinion; 2) Simple statements such as "should be punished" lack objective analysis of the entire incident; 3) Ignoring the constraints of relevant laws and regulations may result in non-compliant content.

[0063] The method of the present invention can effectively identify and correct these problems and generate more comprehensive, reasonable and compliant answers. This not only meets the needs of users, but also ensures the security and reliability of the output content, which is of great significance for building a safe and reliable human-computer interaction system.

[0064] In general, the large language model question-answering rule encapsulation method proposed in the present invention fully integrates the generation capability of the large language model and the constraint capability of various specialized rules, generating high-quality question-answering results that meet user needs and comply with various important rule requirements.

[0065] The above description is only a specific implementation mode of the present invention, but the protection scope of the present invention is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed by the present invention, which should be covered by the protection scope of the present invention.

Claims

1. A large language model question answering rule encapsulation method, It is characterized in that The following steps are involved: S10, constructing multiple lightweight neural networks, each lightweight neural network corresponds to a rule type; each lightweight neural network is provided with a trigger phrase, including multiple trigger words, and calculating the similarity between all trigger phrases; S20, forming a regular graph with all lightweight neural networks, wherein the nodes of the regular graph are each lightweight neural network, the values ​​of the nodes are corresponding trigger phrases, and the edges of the regular graph are the similarities between the trigger phrases corresponding to two nodes; S30, receiving a question input by a questioner, inputting the question into a large language model, and obtaining an initial answer; S40, calculating the relevance between the initial answer and each trigger phrase, taking the node corresponding to the trigger phrase with the highest relevance as the starting node, and taking the node corresponding to the trigger phrase with the lowest relevance higher than the minimum threshold as the destination node; S50, in the rule graph, using a graph search algorithm to determine the shortest path from the start node to the destination node, the nodes on the shortest path forming a rule processing sequence; S60, sequentially inputting the initial answer into the lightweight neural network corresponding to each node in the rule processing sequence, each lightweight neural network performs corresponding rule processing on the input content, and outputs a regularized result; S70. Use the regularization result output by the last lightweight neural network in the rule processing sequence as the final answer to the questioner's question.

2. A large language model question-answering rule encapsulation method according to claim 1, It is characterized in that The rule types include at least moral rules, public opinion rules, privacy rules, security rules, cultural rules, legal rules, emotional rules, and logical rules.

3. A large language model question-answering rule encapsulation method according to claim 2, It is characterized in that Each lightweight neural network processes the input content according to the corresponding rules, specifically performs semantic analysis on the input text, identifies the content that violates the corresponding rules, modifies or deletes the illegal content, and finally outputs text that meets the requirements of the rules.

4. A large language model question-answering rule encapsulation method according to claim 3, It is characterized in that The lightweight neural network adopts a multi-layer perceptron structure for text classification and content modification, the input is a text vector to be processed, and the output is a modified text vector and its corresponding rule compliance score.

5. A large language model question-answering rule encapsulation method according to claim 4, It is characterized in that The steps of constructing the training data set of the lightweight neural network specifically include collecting a large number of text samples that meet and violate specific rules, preprocessing and labeling the samples, converting the samples into vector form, and dividing the training set and the verification set.

6. A large language model question-answering rule encapsulation method according to claim 5, It is characterized in that The training steps of the lightweight neural network specifically include initializing network parameters, using batch gradient descent method for forward propagation and back propagation, calculating loss function and updating parameters, evaluating model performance on a validation set, and repeating the above steps until convergence or reaching a preset training round.

7. A large language model question-answering rule encapsulation method according to claim 6, It is characterized in that The step of calculating the similarity between the trigger phrases is to convert each trigger phrase into a word vector, calculate the cosine similarity between the two trigger phrases, and take the average of the similarities of all word pairs as the final trigger phrase similarity.

8. A large language model question-answering rule encapsulation method according to claim 7, It is characterized in that The default minimum threshold is 0.

5.

9. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores program instructions, and when the program instructions are executed in a computer, they are used to execute the large language model question-answering rule encapsulation method according to any one of claims 1 to 8.

10. A large language model question answering rule encapsulation system, It is characterized in that A computer-readable storage medium comprising the computer-readable storage medium of claim 9.

Citation Information

Patent Citations

  • Robot answering method, medium and system according to understanding ability of questioner

    CN118152547A

  • Text review method and device, equipment and storage medium

    CN118378631A

  • Systems and Methods for Implementing Smart Assistant Systems

    US20230135179A1

Cited By

  • Method for guaranteeing security of large model generation content through alignment mechanism

    CN120220696A