A legal regulation question-answering system based on a generative language model and a construction method

By performing question domain identification, classification, preprocessing, and answer correction on a generative language model-based legal question-answering system, the issues of professionalism and legality of generative language models in the legal field are resolved, resulting in more accurate and reliable legal answer output.

CN117271716BActive Publication Date: 2026-04-21HONGTA TOBACCO (GROUP) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
HONGTA TOBACCO (GROUP) CO LTD
Filing Date
2023-07-11
Publication Date
2026-04-21

AI Technical Summary

Technical Problem

When generative language models are applied in the legal field, there are problems such as toxicity, illusion, and bias in the output results. Furthermore, they need to be carefully trained and filtered for the legal field to ensure the professionalism and legality of the generated text.

Method used

By identifying the problem domain, classifying legal issues, preprocessing knowledge base content, retrieving relevant information, using prompt word engineering and generative language model analysis, and combining answer detection and correction, the accuracy and legality of the output answers are ensured.

Benefits of technology

It improves the accuracy and reliability of the question-and-answer system, ensuring that the generated answers comply with legal norms and ethical requirements, have a wider range of applications, and a higher degree of matching.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117271716B_ABST
    Figure CN117271716B_ABST
Patent Text Reader

Abstract

A legal question-answering system and its construction method based on a generative language model are disclosed, belonging to the field of data processing. The construction method includes the following steps: Step 1: Question domain determination; Step 2: Legal question classification; Step 3: Knowledge base content preprocessing; Step 4: Retrieving corresponding legal knowledge base information; Step 5: Importing the corresponding legal knowledge base information into the generative language model; Step 6: Processing and refining the question using prompt word engineering; Step 7: Analyzing the question and outputting results using the generative language model; Step 8: Detecting and correcting the output results and finally generating the answer. By determining and classifying the question domain, the system categorizes questions into corresponding legal domains, improving the applicability of the question-answering system and the matching degree between the question and the model, thereby improving the accuracy of the answer, ensuring the accuracy and legality of the answer, and enhancing the reliability of the question-answering system.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of data processing, and more specifically relates to a legal and regulatory question-and-answer system and its construction method based on a generative language model. Background Technology

[0002] Generative language models can automatically learn from large amounts of text data, discerning linguistic patterns and generating new text that conforms to these patterns. When applied to the legal field, generative language models face challenges due to the specific terminology and norms often employed in legal contexts, involving numerous unique conditions and cases. This necessitates more refined training and adjustments tailored to the legal domain. In practical applications, to ensure the effectiveness and professionalism of the output, the questions posed should be carefully limited. Furthermore, generative language models are susceptible to issues such as toxicity, illusion, and bias; therefore, meticulous training and filtering are crucial to guarantee that the generated text complies with ethical and legal requirements. Summary of the Invention

[0003] This invention, based on the legal question input by the user, retrieves relevant legal knowledge base information to find related information, and utilizes existing legal knowledge and contextual information to conduct in-depth understanding and analysis of the question, ultimately outputting an accurate and reliable answer or suggestion.

[0004] To achieve the above objectives, the present invention employs the following technical solution: The construction method includes the following steps: Step 1: Problem domain determination; Step 2: Legal problem classification; Step 3: Knowledge base content preprocessing; Step 4: Retrieving corresponding legal knowledge base information; Step 5: Importing the corresponding legal knowledge base information into a generative language model; Step 6: Processing and refining the problem using prompt word engineering; Step 7: Analyzing the problem and outputting results using a generative language model; Step 8: Detecting and correcting the output results and finally generating the answer.

[0005] Preferably, step 1: Question domain determination: First, it is necessary to determine the domain of the question input by the user. A text classifier is used to determine whether the question belongs to a legal question that the question-answering system can answer. If it does not belong to the legal question, the question is refused to be answered.

[0006] Preferably, step 2 involves segmenting the question into words and extracting keywords for the question using the TF-IDF method. These keywords are then used directly as the question category to determine the specific type of the question, such as civil disputes, administrative violations, or criminal cases.

[0007] Preferably, step 3 involves vectorizing the preprocessed knowledge base content by using the Bag of Words model and the Word Embedding model to represent the text as a computer-processed vector form and saving the text vectors.

[0008] Preferably, step 4: the retrieval method uses keyword-based retrieval. Based on the legal question input by the user, keywords are input, and the corresponding legal knowledge base is retrieved through the TF-IDF algorithm and full-text retrieval method to find knowledge base information related to the question, including relevant laws, regulations, cases, and interpretations. The retrieval method is based on vector similarity retrieval, which calculates the similarity between the input query and each document, and selects the document or paragraph with the highest similarity to return.

[0009] Preferably, step 5 involves importing the corresponding legal knowledge base information into a generative language model. The found legal knowledge base information is then imported into a generative language model based on a general language model for further analysis and processing.

[0010] Preferably, step 6 involves using prompt word engineering to process and improve the question. Prompt word engineering is used to process and improve the question input by the user, and then matching and analyzing it with the generative language model. Prompt word engineering includes keyword expansion, synonym replacement, and standardized description methods to improve the matching degree between the question and the model.

[0011] Preferably, step 7 involves using a generative language model to analyze the problem and output results. The generative language model analyzes the processed problem and outputs corresponding answers or suggestions. The generative language model utilizes existing legal knowledge and contextual information to deeply understand and analyze the problem and provide accurate answers.

[0012] Preferably, step 8: Detecting and correcting the output results and finally generating the answer involves detecting and correcting the output results of the generative language model, monitoring the standardization of the answer, and further processing and adjusting the answer to finally generate an accurate and reliable answer and provide it to the user.

[0013] A legal and regulatory question-answering system based on a generative language model, wherein the system is applicable to any of the methods described above, and the legal and regulatory question-answering review system includes:

[0014] Question Domain Judgment Module: This module determines whether the question entered by the user is a legal question that the question-answering system can answer. This module makes the judgment based on rule-based classification or by using the Transformer model as a text classifier.

[0015] Legal Issue Classification Module: After determining the legal field to which the issue belongs, the issue is classified to determine its specific category, such as civil disputes, administrative violations, and criminal cases. This module extracts keywords based on the TF-IDF method for issue classification and uses the Transformer model as a text classifier.

[0016] Knowledge base content preprocessing module: preprocesses the text information of the knowledge base to improve retrieval efficiency in subsequent retrieval and analysis. Preprocessing methods include using the TF-IDF algorithm or vectorization.

[0017] Legal knowledge base retrieval module: Based on the legal question entered by the user, it retrieves the relevant legal knowledge base and finds knowledge base information related to the question. The retrieval methods are keyword-based retrieval and vector similarity-based retrieval.

[0018] Prompt word engineering module: Processes and improves the user-input questions, matches and analyzes them with generative language models. Prompt word engineering includes keyword expansion, synonym replacement, and standardized description methods to improve the matching degree between questions and models;

[0019] Problem Analysis and Output Module: This module uses a generative language model to analyze the processed problems and output corresponding answers and suggestions. The generative language model utilizes existing legal knowledge and contextual information to deeply understand and analyze the problems and provide accurate answers.

[0020] Answer detection and correction module: Detects and corrects the output of the generative language model, monitors the standardization of the answers, and further processes and adjusts the answers to ensure their accuracy and legality, ultimately generating accurate and reliable answers and providing them to the user.

[0021] Beneficial effects of this invention:

[0022] This invention improves the applicability of the question-answering system by classifying and categorizing questions into relevant legal domains. Furthermore, it enhances the matching degree between questions and models through preprocessing of knowledge base content and tooltip engineering of user input, thereby increasing the accuracy of the question-answering system's responses. Finally, it detects and corrects the output of the generative language model to ensure the accuracy and legality of the answers, thus improving the reliability of the question-answering system. Attached Figure Description

[0023] Figure 1 This is a flowchart of the construction method of the present invention;

[0024] Figure 2 This is a system block diagram of the question-and-answer system of the present invention;

[0025] In the diagram, 201 is the problem domain judgment module, 202 is the legal problem classification module, 203 is the knowledge base content preprocessing module, 204 is the legal knowledge base retrieval module, 205 is the prompt word engineering module, 206 is the problem analysis and output module, and 207 is the answer detection and correction module. Detailed Implementation

[0026] To facilitate understanding and implementation of the present invention by those skilled in the art, the technical solution of the present invention will now be further described in conjunction with the accompanying drawings and specific embodiments.

[0027] like Figure 1 As shown, a method for constructing a legal question-and-answer system based on a generative language model includes: Step 1: Question domain determination; Step 2: Legal question classification; Step 3: Knowledge base content preprocessing; Step 4: Retrieving corresponding legal knowledge base information; Step 5: Importing the corresponding legal knowledge base information into the generative language model; Step 6: Processing and refining the question using prompt word engineering; Step 7: Analyzing the question and outputting results using the generative language model; Step 8: Detecting and correcting the output results and finally generating the answer.

[0028] Step 1: Question Domain Judgment. First, the question input by the user needs to be classified into legal domains. A text classifier is used to determine whether the question belongs to a legal question that the question-answering system can answer. If not, the question is refused to be answered.

[0029] For example, the question, "A product quality problem has resulted in multiple injuries or deaths. How should the company minimize the financial impact?", although it involves the company's legal liability and financial issues, is beyond the scope of a question-and-answer system and therefore the system should refuse to answer it.

[0030] This invention uses a rule-based classification method to determine whether a question is a legal question that a question-and-answer system can answer. First, keywords are extracted and stored from the knowledge base of the question-and-answer system. Second, the question is segmented into words, and the segmented results are queried one by one in the knowledge base keywords. If no segmented result can be found in the knowledge base, then the question is not a legal question that the question-and-answer system can answer, and the question is refused to be answered.

[0031] For example, the question "What are the requirements for the time of contract signing?" is segmented into "contract", "signing", "time", and "requirements". These segmented results are used to search the knowledge base. If relevant content is found, proceed to the next step.

[0032] Using the Transformer model as a text classifier, it is trained on labeled question-based data to achieve higher classification accuracy and better generalization ability. Specifically, the Transformer model is used to classify legal consultation questions based on whether they fall under the category of legal issues. After training, it can determine whether a question is a legal issue.

[0033] Step 2: Classify legal issues. After determining the legal field to which the issue belongs, it is necessary to classify the issue to determine its specific category, such as civil disputes, administrative violations, criminal cases, etc.

[0034] For example, the question, "What are the requirements for the timing of contract signing?", falls under the contract category.

[0035] The question is segmented into words, and the TF-IDF method is used to extract the keywords for the question. The keywords are then used directly as the question classification.

[0036] For example, in the question "What are the requirements for the time of contract signing?", the keywords extracted using the TF-IDF method are "contract" and "signing". These keywords are the category of the question.

[0037] Using the Transformer model as a text classifier, it is trained on labeled question-based data to achieve higher classification accuracy and better generalization ability. Specifically, the Transformer model is trained on legal consultation question data to determine which question category it belongs to. After training, it can then determine the question's category.

[0038] Step 3: Knowledge base content preprocessing. The text information of the knowledge base is preprocessed to facilitate subsequent retrieval and analysis, thereby improving retrieval efficiency.

[0039] The knowledge base content is preprocessed using the TF-IDF algorithm, which performs word segmentation, stop word removal, and stemming. The term frequency (TF) and inverse document frequency (IDF) of the knowledge base content are pre-calculated, and the results are saved. The knowledge base content is then vectorized using models such as the Bag of Words and Word Embedding to represent the text as computer-processable vectors, and these text vectors are saved.

[0040] Step 4: Retrieve relevant legal knowledge base information. Based on the legal question entered by the user, the relevant legal knowledge base will be searched to find related information, such as relevant laws, regulations, cases, and interpretations. The search method uses keyword-based retrieval. Users can input one or more keywords and quickly retrieve relevant knowledge base content using algorithms such as TF-IDF and full-text search.

[0041] For example, in the question "What are the requirements for the time of contract signing?", the keywords "contract" and "signing" have high TF-IDF values ​​in the Contract Law of the Civil Code and the Regulations on Enterprise Contract Management. Therefore, we further search the full text of these two documents for paragraphs containing the keywords.

[0042] The retrieval method is based on vector similarity. It calculates the similarity between the input query and each document, and selects the document or paragraph with the highest similarity to return.

[0043] For example, the sentence "What are the requirements for the contract signing time?" is converted into word vectors, and the similarity between this vector and all knowledge base vectors is calculated. The calculation methods include cosine similarity and Euclidean distance, and the top few texts and paragraphs with the highest similarity are used as search results.

[0044] Step 5: Import the relevant legal knowledge base information into the generative language model. The found legal knowledge base information needs to be imported into a generative language model based on a general language model for further analysis and processing. The model can be optimized through fine-tuning by collecting more data from specialized fields to further refine the pre-trained model and better adapt it to the characteristics of the legal domain.

[0045] For example, by adding new layers or modifying some parameters on top of a generative language model, and using pre-labeled legal question-and-answer training data, the generative language model can be further trained to help it learn task-related features to adapt to legal question-and-answer tasks.

[0046] Step 6: Refine the question using prompt word engineering. This step involves refining and processing the user-input question using prompt word engineering to better match and analyze it with the generative language model. Prompt word engineering includes methods such as keyword expansion, synonym replacement, and standardized descriptions to improve the matching degree between the question and the model.

[0047] For example, the question "What are the requirements for the contract signing time?" can be transformed into "According to Article XX of the Contract Law of the Civil Code and Article XX of the Enterprise Contract Management Regulations, what are the requirements for the contract signing time?" after processing the prompts. The answer should list them one by one, and indicate the names of the relevant documents and specific clauses.

[0048] Step 7: Analyze the problem using a generative language model and output results. This requires using a generative language model to analyze the processed problem and output corresponding answers or suggestions. Generative language models can leverage existing legal knowledge and contextual information to gain a deeper understanding and analysis of the problem and provide accurate answers.

[0049] The question-and-answer system can omit steps 5, 6, and 7, and only query and output relevant legal provisions in the knowledge base, allowing users to determine the answer to the question based on the legal provisions.

[0050] For example, users can select "Only ask about relevant laws" and output the relevant legal texts and paragraphs found in steps 1 to 4.

[0051] Step 8: Detect and correct the output results and finally generate the answer. It is necessary to detect and correct the output results of the generative language model, monitor the standardization of the answer, and process and adjust the answer again to ensure the accuracy and legality of the answer, and finally generate an accurate and reliable answer and provide it to the user.

[0052] For example, the answer is checked to avoid politically sensitive, trade secret, or other text that may harm the interests of third parties, and the format and content are standardized and adjusted before the final output answer is generated.

[0053] This invention also provides a legal and regulatory question-answering system based on a generative language model, which includes the following modules:

[0054] Question Domain Judgment Module 201: This module is used to determine whether the question entered by the user is a legal question that the question-answering system can answer. This module can make the judgment based on rule-based classification or by using the Transformer model as a text classifier.

[0055] Legal Issue Classification Module 202: After determining the legal field to which the issue belongs, the issue is classified to determine its specific category, such as civil disputes, administrative violations, criminal cases, etc. This module can extract keywords based on the TF-IDF method for issue classification, or use the Transformer model as a text classifier.

[0056] Knowledge base content preprocessing module 203: preprocesses the text information of the knowledge base to facilitate subsequent retrieval and analysis, thereby improving retrieval efficiency; preprocessing methods may include using the TF-IDF algorithm or vectorization processing (bag-of-words model and word vector model), etc.

[0057] Legal knowledge base retrieval module 204: Based on the legal question entered by the user, it retrieves the relevant legal knowledge base and finds knowledge base information related to the question; the retrieval method can be based on keyword retrieval (such as TF-IDF algorithm, full text retrieval, etc.) or vector similarity retrieval.

[0058] Prompt word engineering module 205: Processes and improves the user-input questions to better match and analyze them with the generative language model; prompt word engineering includes methods such as keyword expansion, synonym replacement, and standardized description to improve the matching degree between the questions and the model.

[0059] Problem Analysis and Output Module 206: This module uses a generative language model to analyze the processed problem and output corresponding answers or suggestions. The generative language model can utilize existing legal knowledge and contextual information to gain a deeper understanding and analysis of the problem and provide accurate answers.

[0060] Answer detection and correction module 207: Detects and corrects the output of the generative language model, monitors the standardization of the answers, and processes and adjusts the answers again to ensure their accuracy and legality, and finally generates accurate and reliable answers and provides them to users.

[0061] The foregoing has shown and described the basic principles, main features, and advantages of the present invention. Those skilled in the art should understand that the present invention is not limited to the above embodiments. The embodiments and descriptions in the specification are merely preferred examples and are not intended to limit the invention. Various changes and modifications can be made to the invention without departing from its spirit and scope, and all such changes and modifications fall within the scope of the present invention as claimed. The scope of protection of the present invention is defined by the appended claims and their equivalents.

Claims

1. A method for constructing a legal and regulatory question-answering system based on a generative language model, characterized in that: The construction method includes the following steps: Step 1: Question Domain Judgment: The user-inputted question is subject to domain judgment. A text classifier is used to determine whether the question belongs to a legal question that the question-answering system can answer. If not, the question is rejected. Step 2: Legal Question Classification: The legal questions determined to be answerable in Step 1 are segmented into words. TF-IDF is used to extract keywords for the question. These keywords are directly used as the question classification to determine the specific category of the question, including civil disputes, administrative violations, and criminal cases. Step 3: Knowledge Base Content Preprocessing. Step 4: Retrieving Corresponding Legal Knowledge Base Information: The retrieval method uses keyword-based retrieval. Based on the user-inputted legal question and the keywords extracted in Step 2, TF-IDF is used to retrieve the relevant legal knowledge base information. The algorithm or full-text search method retrieves the relevant legal knowledge base to find knowledge base information related to the question. The knowledge base information includes relevant laws, regulations, cases, and interpretations. The retrieval method is based on vector similarity retrieval, calculating the similarity between the input query and each document, and selecting the document or paragraph with the highest similarity to return. Step 5: Import the relevant legal knowledge base information into the generative language model. Step 6: Use prompt word engineering to refine the question. Step 7: Use the generative language model to analyze the question and output the results. Step 8: Detect and correct the output results and finally generate the answer.

2. The method for constructing a legal and regulatory question-answering system based on a generative language model according to claim 1, characterized in that: Step 3: Vectorization processing of the preprocessed knowledge base content, using the Bag of Words model and Word Embedding model to represent the text as a vector form for computer processing, and saving the text vectors.

3. The method for constructing a legal and regulatory question-answering system based on a generative language model according to claim 1, characterized in that: Step 5: Import the relevant legal knowledge base information into the generative language model. Import the found legal knowledge base information into the generative language model based on the general language model for further analysis and processing.

4. The method for constructing a legal and regulatory question-answering system based on a generative language model according to claim 1, characterized in that: Step 6: Use prompt word engineering to process and improve the question. Use prompt word engineering to process and improve the question input by the user, and match and analyze it with the generative language model. Prompt word engineering includes keyword expansion, synonym replacement and standardized description methods to improve the matching degree between the question and the model.

5. The method for constructing a legal and regulatory question-answering system based on a generative language model according to claim 1, characterized in that: Step 7: Use a generative language model to analyze the problem and output the results. Use a generative language model to analyze the processed problem and output the corresponding answers or suggestions. Generative language models utilize existing legal knowledge and contextual information to gain a deep understanding and analysis of problems and provide accurate answers.

6. The method for constructing a legal and regulatory question-answering system based on a generative language model according to claim 1, characterized in that: Step 8: Detect and correct the output results and finally generate the answer. Detect and correct the output results of the generative language model, monitor the standardization of the answer, and process and adjust the answer again to finally generate an accurate and reliable answer and provide it to the user.

7. A legal and regulatory question-answering system based on a generative language model, wherein the system is applicable to the method described in any one of claims 1-6, characterized in that, The legal and regulatory Q&A system includes: Question Domain Judgment Module: This module determines whether the question entered by the user is a legal question that the question-answering system can answer. This module makes the judgment based on rule-based classification or by using the Transformer model as a text classifier. Legal Issue Classification Module: After determining the legal field to which the issue belongs, the issue is classified to determine its specific category, including civil disputes, administrative violations, and criminal cases. This module extracts keywords based on the TF-IDF method for issue classification and uses the Transformer model as the text classifier. Knowledge base content preprocessing module: preprocesses the text information of the knowledge base to improve retrieval efficiency in subsequent retrieval and analysis. Preprocessing methods include using the TF-IDF algorithm or vectorization. Legal knowledge base retrieval module: Based on the legal question entered by the user, it retrieves the legal knowledge base corresponding to the legal question and the keywords extracted by the legal question classification module for the legal question, and finds the knowledge base information related to the question. The retrieval method is based on keyword retrieval or vector similarity retrieval. The prompt word engineering module processes and improves the user-input questions, matches and analyzes them with the generative language model, and includes keyword expansion, synonym replacement, and standardized description methods to improve the matching degree between the questions and the model. Problem Analysis and Output Module: This module uses a generative language model to analyze the processed problems and output corresponding answers and suggestions. The generative language model utilizes existing legal knowledge and contextual information to deeply understand and analyze the problems and provide accurate answers. Answer detection and correction module: Detects and corrects the output of the generative language model, monitors the standardization of the answers, and further processes and adjusts the answers to ensure their accuracy and legality, ultimately generating accurate and reliable answers and providing them to the user.

Citation Information

Patent Citations

  • Intelligent legal question-answering method and device, electronic equipment and storage medium

    CN112948553A

  • Legal question and answer method based on weak supervised learning and joint learning mechanism, and equipment

    CN113297360A