A method, system, storage medium and device for stylized legal consultation question and answer

By transforming unstructured data into structured data and fine-tuning the base model using a low-rank approximation method, the latency and robustness issues of pre-trained models in existing technologies are resolved, enabling low-latency personalized legal consultation services and improving consultation efficiency.

CN116821297BActive Publication Date: 2026-05-15HUA DATA TECH (SHANGHAI) CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
HUA DATA TECH (SHANGHAI) CO LTD
Filing Date
2023-06-27
Publication Date
2026-05-15

AI Technical Summary

Technical Problem

Existing large-scale generative pre-trained models like ChatGPT suffer from slow inference, stuttering, high memory consumption, and insufficient robustness on servers, and are also unable to provide personalized legal consulting services.

Method used

By generating structured training text from unstructured data, the base model is fine-tuned using an efficient parameter fine-tuning method based on low-rank approximation. Combined with a local stylized knowledge base and a basic legal knowledge base, answers that match user preferences are generated.

Benefits of technology

It achieves low-latency question-and-answer requirements, ensures the stability and reliability of language model generation, and improves the efficiency and personalized service capabilities of legal consultation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116821297B_ABST
    Figure CN116821297B_ABST
Patent Text Reader

Abstract

The application discloses a style legal consultation question and answer method and system, a storage medium and equipment, relates to the technical field of natural language processing, and the method comprises the following steps: collecting text data and audio and video data in the legal consultation field and converting the text data and audio and video data into texts; generating structured text data sets from the texts by using a base model; dividing the structured text data sets into a basic legal knowledge base and a stylized knowledge base according to the style categories of seed instructions; adopting different styles of vertical field labeled training sets, and obtaining a pre-training fine-tuning model by fine-tuning the base model based on a low-rank approximation fine-tuning method; and generating a corresponding style answer from the pre-training fine-tuning model according to a received user legal consultation question. Through the technical scheme of the application, the stylized model can be iterated more quickly, the low-delay question and answer demand is realized, the legal consultation reply can be provided according to the style preferred by the user, and the work efficiency of legal consultation is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of natural language processing technology, and in particular to an iterative stylized legal consultation question-and-answer method, an iterative stylized legal consultation question-and-answer system, a computer-readable storage medium, and an iterative stylized legal consultation question-and-answer terminal device. Background Technology

[0002] With the rapid development of science and technology, more and more industries are significantly improving their production efficiency under the empowerment of AI, playing a vital role in practical applications. In recent years, the new generation of artificial intelligence technology, AIGC (AI-Generated Content), is mainly based on deep learning theory, using pre-trained basic models as a foundation, and leveraging big data to achieve artificial intelligence technology. The national artificial intelligence strategy, "The New Generation Artificial Intelligence Development Plan," mentions that the state advocates applying artificial intelligence technology to the judicial field, deeply exploring the application of artificial intelligence in legal collaboration tools, and promoting the application of artificial intelligence technology to address hot and difficult issues in social governance such as administrative management, judicial management, urban management, and environmental protection, thereby driving the modernization of social governance. A white paper on artificial intelligence generation, jointly released in 2022 by the China Academy of Information and Communications Technology (CAICT) and JD.com's Exploration Research Institute, elaborates on how AI-generated content is leading a profound transformation, reshaping and even subverting the way digital content is produced, and focuses on discussing new business models represented by virtual digital humans. Against this data backdrop, digital transformation is in full swing, not only in traditional fields such as media and e-commerce, but also in government. Digitalization empowers grassroots petition and consultation services, enabling efficient and easily understandable handling of complaints in a clear and organized manner. This maximizes efficiency while providing personalized services to the public, significantly enhancing their sense of well-being and satisfaction.

[0003] In recent years, intelligent consultation systems designed using natural language processing algorithms have provided users with the most similar results based on semantic relevance and by searching legal consultation databases. The limitation of this method lies in its over-reliance on database information. In actual cases such as petitions and inquiries, the backgrounds and circumstances of the individuals seeking advice vary, and the desired advice differs accordingly. Furthermore, customized consultations based on individual user preferences cannot be achieved. However, the increasingly mature field of pre-trained language models has made it possible to provide personalized and refined consultation services to different users using artificial intelligence-generated content (AIGC).

[0004] In traditional deep learning models, gradient calculation is performed on the parameters of each layer in the neural network. The full-parameter iterative mode of gradient update consumes a lot of computing resources and takes a long time for pre-trained models with a large number of parameters.

[0005] Pre-trained language foundation models are a natural language processing technique based on deep learning. They acquire language capabilities that differ from traditional networks by performing unsupervised learning on large-scale text data. These capabilities are not limited to basic natural language models such as text semantic classification and text translation, but also extend to higher-order capabilities such as text dialogue, context semantic memory and response, and logical reasoning.

[0006] The development of pre-trained language foundation models can be traced back to 2015, when Google proposed a language model based on recurrent neural networks, namely the Recurrent Neural Network Language Model (RNNLM). This model, trained on large-scale text data, can predict the probability of the next word appearing, thus realizing the function of a language model. In 2018, OpenAI proposed a pre-trained language foundation model based on transformers, namely the Transformer model. This model, through a self-attention mechanism, can effectively handle long texts and has better generalization ability. The success of the Transformer model inspired later researchers to further propose a series of pre-trained language foundation models, such as BERT and GPT-2.

[0007] Django is an open-source web application framework built on Python. It employs the MTV framework pattern, enabling the rapid development of highly secure and maintainable system platforms. Currently, Python is the primary programming language used for artificial intelligence algorithm models. Image data preprocessing and deep neural network algorithms can also be accomplished using Python modules. For example, image preprocessing can be done using OpenCV, Pillow, and Scikit-image, while deep neural network algorithms utilize modules such as Tensorflow, PyTorch, and Keras to quickly construct the required neural networks.

[0008] Currently, large-scale generative pre-trained models like ChatGPT deployed on servers suffer from issues such as slow inference, stuttering, high memory consumption, and poor robustness. Summary of the Invention

[0009] To address the aforementioned issues, this invention provides a stylized legal consultation question-and-answer method, system, storage medium, and device. By generating structured training text from unstructured data, the structured training text facilitates parameter fine-tuning of the base model. Utilizing an efficient parameter fine-tuning method based on low-rank approximation, the stylized model can be iterated more rapidly, achieving low-latency question-and-answer requirements. Furthermore, while ensuring low-latency reasoning, a local stylized knowledge base and a basic legal knowledge base are used to generate response statements based on the user's question, context, and prompts, ensuring the stability and reliability of the language model generation. This allows for the provision of legal provisions and related consultation guidance based on the user's preferred legal consultation service style, reflecting the corresponding tone and logical ability, thereby improving the efficiency of legal consultation work.

[0010] To achieve the above objectives, this invention provides an iterative, stylized legal consultation question-and-answer method, comprising:

[0011] Collect user Q&A data, audio and video data, and legal knowledge data in the field of legal consultation;

[0012] The audio data of the audio and video data is converted into text using speech-to-text technology, and the subtitle area of ​​the video data in the audio and video data is identified and converted into text using OCR recognition technology.

[0013] By leveraging the semantic understanding of the base model and its context-based text generation capabilities, a structured text dataset is generated from the user-generated question-and-answer data, legal knowledge data, and audio / video data.

[0014] A seed instruction database is constructed based on the user's question and answer data. The base model divides the structured text dataset into a basic legal knowledge base and a stylized knowledge base with different styles according to the style categories of the seed instructions in the seed instruction database.

[0015] Using labeled training sets of different styles from vertical domains, the base model is fine-tuned based on the low-rank approximation fine-tuning method LoRA to obtain a pre-trained fine-tuned model;

[0016] Based on the style type of the legal consultation question received from the user, the pre-trained fine-tuning model of the corresponding style generates an answer of the corresponding style based on the basic legal knowledge base or the stylized knowledge base.

[0017] In the above technical solution, preferably, the process of converting the audio data of the audio-video data into text using speech-to-text technology and recognizing the subtitle area of ​​the video data in the audio-video data using OCR recognition technology and converting it into text specifically includes:

[0018] Using AI-based speech-to-text technology, the audio data is read and the corresponding speech is converted into text.

[0019] The video data is read, and the position of the detection box is detected according to the custom preset input box. The video subtitles at the box position are recognized by the deep learning-based OCR recognition technology and converted into text in the corresponding language.

[0020] In the above technical solution, preferably, the process of generating a structured text dataset by utilizing the semantic understanding of the base model and the context-based text generation capability to convert the user's question-and-answer data, the legal knowledge data, and the audio-visual data into text specifically includes:

[0021] Using the semantic understanding capabilities of the base model, key text summaries are extracted from the text obtained by converting user question-and-answer data, legal knowledge data, and audio / video data.

[0022] By leveraging the context-based text generation capabilities of the base model, the extracted key text summaries are transformed into structured text in the form of "instruction-hint-response".

[0023] The text obtained by converting user question-and-answer data, legal knowledge data, and audio / video data is processed in batches to form the structured text dataset.

[0024] In the above technical solution, preferably, the step of constructing a seed instruction database based on the user's question-and-answer data, and the base model dividing the structured text dataset into a basic legal knowledge base and a stylized knowledge base of different styles according to the style categories of the seed instructions in the seed instruction database, specifically includes:

[0025] Analyze the user-used question and answer data to determine seed instructions for different vertical fields, and use the seed instructions to build a seed instruction database;

[0026] Based on the style categories of seed instructions in the seed instruction database, new instructions are regenerated from the structured text in the structured text dataset to form an instruction-response dataset, resulting in an enhanced basic legal knowledge base and a stylized knowledge base.

[0027] In the above technical solution, preferably, the labeled training sets of different styles of vertical domains are used, and the base model is fine-tuned based on the low-rank approximation fine-tuning method LoRA to obtain a pre-trained fine-tuned model. The specific process includes:

[0028] For datasets from different vertical domains, labeled training sets of different style types are obtained through annotation.

[0029] The pedestal model is trained using the labeled training set;

[0030] The parameters of the base model are frozen, and the LoRA mechanism is used to update the trainable attention weight matrix in the Transformer architecture of the base model in a way that uses a low-rank matrix factorization method to identify the parameter changes, thereby obtaining the pre-trained fine-tuning model.

[0031] In the above technical solution, preferably, the step of generating a corresponding style answer based on the style type of the received user legal consultation question, using the pre-trained fine-tuning model corresponding to the style, and based on the basic legal knowledge base or the stylized knowledge base, specifically includes:

[0032] When a legal consultation question is received from a user, the style type of the legal consultation question is determined based on the semantic recognition capability of the base model.

[0033] For each style type of the user's legal consultation question, the user's legal consultation question is input into the pre-trained fine-tuning model corresponding to that style type.

[0034] The pre-trained fine-tuning model selects "instruction-response" data with a similarity to the user's legal consultation question within a preset threshold or a preset number of times based on the user's legal consultation question and the corresponding style type in the basic legal knowledge base or the stylized knowledge base.

[0035] Based on the "instruction-response" data, generate and output response statements with corresponding styles.

[0036] In the above technical solution, preferably, the iterative stylized legal consultation Q&A method also includes:

[0037] Based on the received legal consultation questions from users, new instructions are extracted and fed back to the seed instruction database;

[0038] Based on the generated response statement, new "instruction-response" data of the corresponding style type is generated and stored in the basic legal knowledge base or the stylized knowledge base of the corresponding style type.

[0039] This invention also proposes an iterative, stylized legal consultation question-and-answer system, applying the iterative, stylized legal consultation question-and-answer method disclosed in any of the above technical solutions, including:

[0040] The data collection module is used to collect user Q&A data, audio and video data, and legal knowledge data in the field of legal consultation.

[0041] The data conversion module is used to convert the audio data of the audio and video data into text using speech-to-text technology, and to identify the subtitle area of ​​the video data in the audio and video data and convert it into text using OCR recognition technology;

[0042] The data processing module is used to utilize the semantic understanding of the base model and the context-based text generation capability to generate a structured text dataset from the text obtained by converting the user's question-and-answer data, the legal knowledge data, and the audio and video data.

[0043] The knowledge classification module is used to construct a seed instruction database based on the user's question and answer data. The base model divides the structured text dataset into a basic legal knowledge base and a stylized knowledge base with different styles according to the style categories of the seed instructions in the seed instruction database.

[0044] The model fine-tuning module is used to fine-tune the base model using labeled training sets of different styles in vertical domains, based on the low-rank approximation fine-tuning method LoRA, to obtain a pre-trained fine-tuned model.

[0045] The question-answering module is used to generate answers in the corresponding style based on the style type of the received user legal consultation questions, using the pre-trained fine-tuning model of the corresponding style, and based on the basic legal knowledge base or the stylized knowledge base.

[0046] The present invention also proposes a computer-readable storage medium storing at least one instruction that, when executed by a processor, enables an iterative, stylized legal consultation question-and-answer method as disclosed in any of the above-described technical solutions.

[0047] The present invention also proposes an iterative stylized legal consultation question-and-answer terminal device, the terminal device including a memory and a processor, the memory for storing at least one instruction, and the processor for executing the at least one instruction to implement the iterative stylized legal consultation question-and-answer method disclosed in any of the above technical solutions.

[0048] Compared with existing technologies, the beneficial effects of this invention are as follows: By generating structured training text from unstructured data, the structured training text facilitates parameter fine-tuning of the base model. Furthermore, by utilizing an efficient parameter fine-tuning method based on low-rank approximation, the stylized model can be iterated more quickly, achieving low-latency question-answering. Moreover, while ensuring low-latency inference, the invention utilizes a local stylized knowledge base and a basic legal knowledge base to generate answer statements related to the context and prompts of the question based on the user's question, ensuring the stability and reliability of the language model generation. This allows the invention to provide legal provisions and related consultation guidance based on the user's preferred style of legal consultation service, reflecting the corresponding tone and logical ability, thus improving the efficiency of legal consultation work. Attached Figure Description

[0049] Figure 1 This is a flowchart illustrating an iterative, stylized legal consultation question-and-answer method disclosed in one embodiment of the present invention.

[0050] Figure 2 This is a schematic diagram illustrating data conversion and data processing according to an embodiment of the present invention;

[0051] Figure 3 This is a schematic diagram of a process for answering questions using a pre-trained and finely tuned pedestal model, as disclosed in one embodiment of the present invention.

[0052] Figure 4 This is a flowchart illustrating the pre-training and fine-tuning process of a base model disclosed in one embodiment of the present invention.

[0053] Figure 5 This is a schematic diagram of the parameter update method of the LoRA method disclosed in one embodiment of the present invention;

[0054] Figure 6 This is a schematic diagram of a module of an iterative stylized legal consultation question-and-answer system disclosed in one embodiment of the present invention.

[0055] In the diagram, the correspondence between the components and the reference numerals is as follows:

[0056] 1. Data collection module, 2. Data transformation module, 3. Data processing module, 4. Knowledge classification module, 5. Model fine-tuning module, 6. Question answering module. Detailed Implementation

[0057] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0058] The present invention will now be described in further detail with reference to the accompanying drawings:

[0059] like Figure 1 As shown, an iterative, stylized legal consultation question-and-answer method provided by the present invention includes:

[0060] Collect user Q&A data, audio and video data, and legal knowledge data in the field of legal consultation;

[0061] The audio data of audio and video data is converted into text using speech-to-text technology, and the subtitle area of ​​video data in audio and video data is identified and converted into text using OCR recognition technology.

[0062] By leveraging the semantic understanding and context-based text generation capabilities of the base model, a structured text dataset is generated from the text obtained by users using question-and-answer data, legal knowledge data, and audio-visual data.

[0063] A seed instruction database is built based on user question and answer data. The base model divides the structured text dataset into a basic legal knowledge base and a stylized knowledge base with different styles based on the style categories of the seed instructions in the seed instruction database.

[0064] Using labeled training sets from different vertical domains, the pedestal model is fine-tuned based on the low-rank approximation fine-tuning method LoRA to obtain a pre-trained fine-tuned model.

[0065] Based on the style type of the legal consultation questions received from users, a pre-trained and fine-tuned model of the corresponding style is used to generate answers in the corresponding style based on a basic legal knowledge base or a stylized knowledge base.

[0066] In this implementation, structured training text is generated from unstructured data. This structured training text facilitates parameter fine-tuning of the base model. The efficient parameter fine-tuning method using low-rank approximation enables faster iteration of the stylized model, achieving low-latency question-answering. Furthermore, while ensuring low-latency inference, a local stylized knowledge base and a basic legal knowledge base are used to generate response statements based on the user's question, context, and prompts. This ensures the stability and reliability of the language model generation. It can provide legal provisions and related consultation guidance based on the user's preferred style of legal consultation service, reflecting the corresponding tone and logical ability, thus improving the efficiency of legal consultation.

[0067] Specifically, this invention aims to provide a sustainably iterative, stylized language model for legal consultations and Q&A sessions. It offers rapid, humorous, and easy-to-understand professional Q&A for practical grassroots petition consultations and civil and criminal case-related consultations, providing user-friendly and professional answers after extracting case elements. The sustainably iterative, stylized legal consultation Q&A method completes an end-to-end language model training process. During implementation, it can be managed and maintained using the Django application framework, enabling automated data filtering, enhanced processing and storage, scheduled model training, and intelligent deployment of the trained model.

[0068] In the implementation process, the method of this invention can be implemented using the Python programming language, which can effectively avoid unnecessary compatibility issues. The information system adopts the Django framework, the algorithm model is mainly based on the PyTorch framework, and the structured data is uniformly implemented using MySQL 5.7 or above database.

[0069] like Figure 2 As shown, in the above embodiment, preferably, speech-to-text technology is used to convert the audio data of the audio and video data into text, and OCR recognition technology is used to identify the subtitle area of ​​the video data in the audio and video data and convert it into text. The specific process includes:

[0070] Using AI-based speech-to-text technology, audio data is read and the corresponding speech is converted into text.

[0071] The system reads video data, detects the position of a frame based on a custom preset input box, uses deep learning-based OCR recognition technology to recognize the text of the video subtitles at the frame position, and converts them into text in the corresponding language.

[0072] Specifically, during implementation, at the data processing end, a system decision-making logic is provided to classify and structure sample data generated from multiple terminals. An automated program determines the data type and automatically processes local corpus data, thereby transforming massive amounts of stored local user records, open-source audio and video information, and other data into usable text information. Compared to traditional methods that lack spoken text information from audio and video when generating Chinese training datasets, the method of this invention has a wider range of data sources.

[0073] The specific process includes:

[0074] (1) When faced with complete data question-and-answer type user question and answer data, Python automatically identifies and prepares it into a matching "instruction-hint-question-answer" type dataset;

[0075] (2) When faced with a complete voice dataset, use artificial intelligence to realize the AI ​​speech-to-text function and save the generated unstructured text;

[0076] (3) When dealing with video data, the OCR vision capabilities based on OpenCV deep learning are utilized to perform batch recognition on selected text boxes according to the position of the custom input box detection box, obtaining the txt text data of Chinese and English subtitles corresponding to the video time in the area below the video. When using OCR to recognize the subtitles below the video, sensitive information is removed from the txt file of the subtitles.

[0077] like Figure 2 As shown, in the above implementation, preferably, the semantic understanding and context-based text generation capabilities of the base model are utilized to generate a structured text dataset from the text obtained by converting user-generated question-and-answer data, legal knowledge data, and audio / video data. The specific process includes:

[0078] Leveraging the semantic understanding capabilities of the base model, key text summaries are extracted from text converted from user question-and-answer data, legal knowledge data, and audio / video data.

[0079] By leveraging the context-based text generation capabilities of the base model, the extracted key text summaries are transformed into structured text in the form of "instruction-hint-response".

[0080] The system performs batch processing on text obtained from user-generated question-and-answer data, legal knowledge data, and audio / video data, resulting in a structured text dataset.

[0081] During implementation, the massive amount of unstructured text data provided by users through question-and-answer data, legal knowledge data, and audio-visual data conversion, which includes legal knowledge-related data (legal texts, legal provisions, judgments, etc.) and audio-visual text (spoken text with a speaker's style), needs to be transformed into structured data in the form of "instruction-prompt-response" and stored in storage devices.

[0082] Based on the semantic understanding and context-based text generation capabilities of the base model, and leveraging the base model's "self-guidance" ability, this method extracts summaries and legal knowledge questions from video text. It utilizes the base model's degree to extract key text summaries within the text, and filters based on the overlap of generated content to generate new, stylized, structured question-and-answer pairs, thus achieving data augmentation. This method can generate batches of instruction-question-answer datasets with high relevance to the original text, and it also demonstrates good instruction-following ability.

[0083] The stylized legal consultation Q&A method disclosed in the above implementation method is further illustrated in the following table with examples to illustrate its data collection and data transformation processes.

[0084]

[0085]

[0086] In the above implementation, preferably, a seed instruction database is constructed based on user question-and-answer data. The base model divides the structured text dataset into a basic legal knowledge base and a stylized knowledge base with different styles based on the style categories of the seed instructions in the seed instruction database. The specific process includes:

[0087] Analyze user-generated question and answer data to identify seed commands for different vertical fields, and use these seed commands to build a seed command database.

[0088] Based on the style categories of seed instructions in the seed instruction database, new instructions are regenerated from the structured text in the structured text dataset to form an instruction-response dataset, resulting in an enhanced basic legal knowledge base and a stylized knowledge base.

[0089] In this implementation, the seed instruction database is designed based on user usage records and input data, containing the vast majority of user instructions used in legal consultation scenarios within the vertical domain. After a seed instruction is input, the base model first determines its category, as there are differences between instructions in the basic legal knowledge base and those in the stylized knowledge base. New instructions are generated based on both the stylized and basic legal knowledge base instructions, and corresponding "instruction-answer" question-and-answer pairs are generated using each unstructured text in the database as input.

[0090] The following is an example:

[0091]

[0092] like Figure 3 As shown, in the above implementation, preferably, labeled training sets of different styles from vertical domains are used, and the base model is fine-tuned based on the low-rank approximation fine-tuning method LoRA to obtain a pre-trained fine-tuned model. The specific process includes:

[0093] For datasets from different vertical domains, labeled training sets of different style types are obtained through annotation.

[0094] The pedestal model is trained using a labeled training set;

[0095] The parameters of the base model are frozen, and the LoRA mechanism is used to update the trainable attention weight matrix in the Transformer architecture of the base model in a way that is a full update, and to a way that identifies the parameter changes in a low-rank matrix factorization manner, so as to obtain a pre-trained fine-tuning model.

[0096] In this implementation, the base model, after fine-tuning and training, can have a stronger ability to follow user instructions. In particular, addressing the problem of insufficient understanding of instructions in the legal consultation vertical field in the original base model, this automated data augmentation approach can reduce the reliance on manual annotation and screening of unannotated unstructured text.

[0097] Specifically, fine-tuning is a commonly used technique in the field of natural language processing. Essentially, it's a supervised learning method that involves training a pre-trained model using a relatively small amount of task-specific text. For pre-trained models with a large number of parameters, this method can reduce computational resource consumption and significantly decrease computation time, improving computational efficiency. In some cases, it can even improve accuracy and generalization ability in specific domains.

[0098] In this implementation, a parameter-efficient fine-tuning technique—low-rank approximation fine-tuning (LoRA)—is employed, such as... Figure 4 and Figure 5As shown, LoRA's model fine-tuning technique is applied in the step of updating model parameters. Because the weight matrix of the pre-trained model has a low intrinsic dimensionality, during the parameter update process, all parameters of the original pre-trained model are frozen, and a bypass is introduced. Simultaneously, the LoRA mechanism is used to fully utilize the low-rank characteristic inherent in large base models, using the bypass to simulate the full parameter fine-tuning process of the entire model. This changes the update method from a full update of the trainable attention weight matrix in the Transformer architecture to a method that uses low-rank matrix factorization to represent parameter changes. The advantage of LoRA is that it reduces the number of updated model parameters in each Transformer layer, thus increasing training throughput without increasing inference latency.

[0099] Specifically, assume that W0 is the parameter of the pre-trained model, and the updated parameter is W1;

[0100] W1 = W0 + ΔW = W0 + BA

[0101] Where W0 is the weight matrix (W0) in the pre-trained Transformer architecture. q W k W v W o Any of these four weight matrices, or the weight matrix of a multilayer perceptron layer.

[0102] The LoRA method allows for efficient model fine-tuning by selecting different numbers of weights based on the user's computing power and accuracy requirements.

[0103] The number of parameters that need to be updated by the LoRA method used in this implementation can be quantified as follows:

[0104] |Θ|=2L Lora rd

[0105] Where r is the rank, d is the input dimension, and L Lora The number of weights for LoRA fine-tuning.

[0106] An example of low-rank approximation simulation parameter updates is as follows:

[0107] The parameter settings are as follows:

[0108] LoRA_R (rank) LoRA_Alpha LoRA_DropOut Target_Modules 8 16 0.05 "query_key_value"

[0109] Among them, Target_modules: sets the weight matrix selected by the LoRA method for parameter updates;

[0110] Query_key_value: W_Q, W_k, W_v;

[0111] LoRA_R: The parameter sets the rank of the parameter matrix updated in the bypass of the pre-trained weight matrix;

[0112] LoRA_Alpha: Alpha usually refers to the hyperparameter in regularization, which is used to control the trade-off between model complexity and generalization ability. Regularization is a commonly used technique to prevent overfitting. It reduces model complexity and improves generalization ability by penalizing model parameters.

[0113] LoRA_Dropout: Dropout is a technique used in neural networks to prevent overfitting, which randomly sets the output of some neurons to 0 during training.

[0114] In the above implementation, preferably, based on the style type of the received user legal consultation question, a pre-trained fine-tuned model of the corresponding style generates an answer of the corresponding style based on a basic legal knowledge base or a stylized knowledge base. The specific process includes:

[0115] When a user sends a legal consultation question, the style type of the user's legal consultation question is determined based on the semantic recognition capability of the base model;

[0116] Based on the style type of user's legal consultation questions, the user's legal consultation questions are input into a pre-trained fine-tuning model of the corresponding style type;

[0117] The pre-trained fine-tuning model selects "instruction-response" data with similarity to the user's legal consultation question within a preset threshold or a preset number of data points from the basic legal knowledge base or stylized knowledge base, based on the user's legal consultation question and the corresponding style type.

[0118] Based on the "instruction-response" data, generate and output response statements with the corresponding style.

[0119] Specifically, by improving the legal understanding and question-answering reliability of the pre-trained fine-tuning model, the model, based on the dictionary of the base model, accesses a local, expandable legal corpus knowledge base. For user input commands, it first uses the semantic recognition capabilities of the base model to select Top K related legal knowledge from the legal corpus knowledge base based on sentence similarity as prompts and context, forming "command-prompt" input information. This guides the pre-trained fine-tuning model to output more reliable and credible legal consultation results while maintaining stylistic answers.

[0120] During implementation, the pre-trained model was fine-tuned according to the style of the legal professor's lecture corpus. The effects of the pre-trained fine-tuned model are demonstrated through examples in the table below:

[0121]

[0122] From the examples in the table above, we can see that:

[0123] In the response of the basic model, the model provides the legal basis for the criminal suspect's violation of the law in the case according to the user's input requirements. This includes explanations of intentional injury and the crime of provoking trouble. It mainly presents the professional tone of the judgment in legal documents, and its target audience should be legal professionals.

[0124] The output of the pre-trained fine-tuning model provides a conversational overview of the case and extracts key details of the crime, such as "Wu grabbed the dumbbell on the ground," and elaborates on them. Combining the suspect's behavior with the case, it provides a more understandable explanation of the severity of the behavior, the corresponding conviction, and the laws violated, making it easier for the general public to understand and accept.

[0125] In the above embodiments, preferably, the iterative stylized legal consultation question-and-answer method further includes:

[0126] Based on the legal consultation questions received from users, new instructions are extracted and fed back to the seed instruction database;

[0127] Based on the generated response statement, new "instruction-response" data of the corresponding style type is generated and stored in the basic legal knowledge base or stylized knowledge base of the corresponding style type.

[0128] By continuously enriching the seed instruction database, as well as the basic legal knowledge base and stylized knowledge base, we can provide more sufficient training data for the model, thereby enabling continuous database updates.

[0129] like Figure 6 As shown, this invention also proposes an iterative stylized legal consultation question-and-answer system, applying any of the iterative stylized legal consultation question-and-answer methods disclosed in the above embodiments, including:

[0130] Data collection module 1 is used to collect user Q&A data, audio and video data, and legal knowledge data in the field of legal consultation;

[0131] Data conversion module 2 is used to convert audio data of audio and video data into text using speech-to-text technology, and to identify the subtitle area of ​​video data in audio and video data and convert it into text using OCR recognition technology;

[0132] Data processing module 3 is used to generate structured text datasets by utilizing the semantic understanding and context-based text generation capabilities of the base model to convert the text obtained by users using question-and-answer data, legal knowledge data and audio and video data.

[0133] Knowledge classification module 4 is used to build a seed instruction database based on user question and answer data. The base model divides the structured text dataset into a basic legal knowledge base and a stylized knowledge base with different styles according to the style categories of the seed instructions in the seed instruction database.

[0134] Model fine-tuning module 5 is used to fine-tune the base model using labeled training sets of different styles in vertical domains, based on the low-rank approximation fine-tuning method LoRA, to obtain a pre-trained fine-tuned model.

[0135] The question-answering module 6 is used to generate answers in the corresponding style based on the style type of the legal consultation questions received from users, using a pre-trained fine-tuned model of the corresponding style, and based on a basic legal knowledge base or a stylized knowledge base.

[0136] In this embodiment, the functions to be implemented by each module in the iterative stylized legal consultation Q&A system are adapted to the implementation methods in the legal consultation Q&A method disclosed in the above embodiments. During implementation, the methods in the above embodiments can be referred to for implementation, and will not be repeated here.

[0137] The present invention also proposes a computer-readable storage medium storing at least one instruction that, when executed by a processor, enables an iterative, stylized legal consultation question-and-answer method as disclosed in any of the above embodiments.

[0138] The present invention also proposes an iterative stylized legal consultation question-and-answer terminal device, the terminal device including a memory and a processor, the memory for storing at least one instruction, and the processor for executing at least one instruction to implement the iterative stylized legal consultation question-and-answer method disclosed in any of the above embodiments.

[0139] The above are merely preferred embodiments of the present invention and are not intended to limit the present invention. Various modifications and variations can be made to the present invention by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.

Claims

1. An iterative, stylized legal consultation question-and-answer method, characterized in that, include: Collect user Q&A data, audio and video data, and legal knowledge data in the field of legal consultation; The audio data of the audio and video data is converted into text using speech-to-text technology, and the subtitle area of ​​the video data in the audio and video data is identified and converted into text using OCR recognition technology. By leveraging the semantic understanding of the base model and its context-based text generation capabilities, a structured text dataset is generated from the user-generated question-and-answer data, legal knowledge data, and audio / video data. Based on the user question and answer data, seed instructions for different vertical fields are determined, and a seed instruction database is constructed. The base model regenerates new instructions from the structured text in the structured text dataset based on the style categories of the seed instructions in the seed instruction database, forming a dataset in the form of "instruction-response", thus obtaining an enhanced basic legal knowledge base and a stylized knowledge base; Using labeled training sets of different styles from vertical domains, the base model is fine-tuned based on the low-rank approximation fine-tuning method LoRA to obtain a pre-trained fine-tuned model; Based on the style type of the legal consultation question received from the user, the pre-trained fine-tuning model of the corresponding style generates an answer of the corresponding style based on the basic legal knowledge base or the stylized knowledge base.

2. The iterative stylized legal consultation question-and-answer method according to claim 1, characterized in that, The process of converting audio data of the audio-video data into text using speech-to-text technology and recognizing subtitle areas of the video data using OCR recognition technology and converting them into text includes: Using AI-based speech-to-text technology, the audio data is read and the corresponding speech is converted into text. The video data is read, and the position of the detection box is detected according to the custom preset input box. The video subtitles at the box position are recognized by the deep learning-based OCR recognition technology and converted into text in the corresponding language.

3. The iterative stylized legal consultation question-and-answer method according to claim 2, characterized in that, The process of generating a structured text dataset by utilizing the semantic understanding and context-based text generation capabilities of the base model to transform the user's question-and-answer data, legal knowledge data, and audio / video data includes: Using the semantic understanding capabilities of the base model, key text summaries are extracted from the text obtained by converting user question-and-answer data, legal knowledge data, and audio / video data. By leveraging the context-based text generation capabilities of the base model, the extracted key text summaries are transformed into structured text in the form of "instruction-hint-response". The text obtained by converting user question-and-answer data, legal knowledge data, and audio / video data is processed in batches to form the structured text dataset.

4. The iterative stylized legal consultation question-and-answer method according to claim 3, characterized in that, The labeled training sets for different vertical domains are used. The base model is fine-tuned based on the low-rank approximation fine-tuning method LoRA to obtain a pre-trained fine-tuned model. The specific process includes: For datasets from different vertical domains, labeled training sets of different style types are obtained through annotation. The pedestal model is trained using the labeled training set; The parameters of the base model are frozen, and the LoRA mechanism is used to update the trainable attention weight matrix in the Transformer architecture of the base model in a way that uses a low-rank matrix factorization method to identify the parameter changes, thereby obtaining the pre-trained fine-tuning model.

5. The iterative stylized legal consultation question-and-answer method according to claim 4, characterized in that, The process of generating a corresponding style answer based on the style type of the received user legal consultation question, using the pre-trained fine-tuned model corresponding to the style, and based on the basic legal knowledge base or the stylized knowledge base, specifically includes: When a legal consultation question is received from a user, the style type of the legal consultation question is determined based on the semantic recognition capability of the base model. For each style type of the user's legal consultation question, the user's legal consultation question is input into the pre-trained fine-tuning model corresponding to that style type. The pre-trained fine-tuning model selects "instruction-answer" data with a similarity to the user's legal consultation question within a preset threshold or a preset number of times based on the user's legal consultation question and the corresponding style type from the basic legal knowledge base or the stylized knowledge base; Based on the "instruction-response" data, generate and output response statements with corresponding styles.

6. The iterative stylized legal consultation question-and-answer method according to claim 5, characterized in that, Also includes: Based on the received legal consultation questions from users, new instructions are extracted and fed back to the seed instruction database; Based on the generated response statement, new "instruction-response" data of the corresponding style type is generated and stored in the basic legal knowledge base or the stylized knowledge base of the corresponding style type.

7. An iterative, stylized legal consultation question-and-answer system, characterized in that: The iterative, stylized legal consultation question-and-answer method as described in any one of claims 1 to 6 includes: The data collection module is used to collect user Q&A data, audio and video data, and legal knowledge data in the field of legal consultation. The data conversion module is used to convert the audio data of the audio and video data into text using speech-to-text technology, and to identify the subtitle area of ​​the video data in the audio and video data and convert it into text using OCR recognition technology; The data processing module is used to utilize the semantic understanding of the base model and the context-based text generation capability to generate a structured text dataset from the text obtained by converting the user's question-and-answer data, the legal knowledge data, and the audio and video data. The knowledge classification module is used to construct a seed instruction database based on the user's question and answer data. The base model divides the structured text dataset into a basic legal knowledge base and a stylized knowledge base with different styles according to the style categories of the seed instructions in the seed instruction database. The model fine-tuning module is used to fine-tune the base model using labeled training sets of different styles in vertical domains, based on the low-rank approximation fine-tuning method LoRA, to obtain a pre-trained fine-tuned model. The question-answering module is used to generate answers in the corresponding style based on the style type of the received user legal consultation questions, using the pre-trained fine-tuning model of the corresponding style, and based on the basic legal knowledge base or the stylized knowledge base.

8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores at least one instruction that, when executed by a processor, enables the iterative, stylized legal consultation question-and-answer method as described in any one of claims 1 to 6.

9. An iterative, stylized legal consultation and Q&A terminal device, characterized in that, The terminal device includes a memory and a processor, the memory being used to store at least one instruction, and the processor being used to execute the at least one instruction to implement the iterative stylized legal consultation question-and-answer method as described in any one of claims 1 to 6.