Model construction method and device based on knowledge graph and electronic equipment

By building a knowledge graph in the field of legal taxation and integrating it with a large language model, the existing legal tax consultation tools are solved, and automated and intelligent legal tax consultation is realized, and personalized and efficient consulting services are provided.

CN119903927APending Publication Date: 2025-04-29GREATER BAY AREA INST FOR INNOVATION HUNAN UNIV +1
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202510377100.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-28
Publication Date
2025-04-29

AI Technical Summary

Technical Problem

The existing legal and tax consulting tools are inefficient, insufficient accuracy, and lack personalized services, and cannot effectively integrate and utilize fragmented information resources in the legal and tax field.

Method used

Using a model construction method based on knowledge graph, a knowledge graph is constructed by extracting entities and relationships in the legal and tax field, and fusing it with a large language model, pre-training and fine-tuning, and a target model is generated to handle user consultation.

Benefits of technology

It realizes automated and intelligent legal and tax consultation, and quickly generates consulting solutions that meet the requirements of regulations, greatly improving the efficiency and accuracy of consultation, and providing personalized solutions according to the specific situation of users.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119903927A_ABST
    Figure CN119903927A_ABST
Patent Text Reader

Abstract

The invention relates to a knowledge graph-based model construction method and apparatus, and an electronic device. The method comprises the following steps: extracting a plurality of relationships among entities based on a preset knowledge base in the field of law and tax, constructing a knowledge graph according to the relationships among the entities, mapping the relationships among the entities in the knowledge graph to obtain vector representation of the knowledge graph, fusing the vector representation into a preset large language model, and obtaining the knowledge graph. And performing pre-training and fine tuning on the fused preset large language model to generate a target model which is used for answering questions input by the user and related to the law and tax field. According to the scheme provided by the invention, professional knowledge in the law and tax field can be accurately applied, the user consultation can be automatically and intelligently processed, and the feasible consultation scheme meeting the requirements of laws and regulations is generated.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of artificial intelligence technology, and in particular to a knowledge graph-based model building method, device, and electronic device. Background Art

[0002] In today's era of rapid globalization and digitalization, the importance of the legal and tax fields in economic activities has become increasingly prominent. The legal and tax affairs faced by enterprises and individuals are becoming increasingly complex, and the demand for accurate and efficient legal and tax consulting services continues to grow. The traditional legal and tax consulting model has long relied on the professional knowledge and practical experience of professionals. Although this approach has the advantage of strong professionalism, it also faces a series of severe challenges. The training cycle of professional talents is long, and the knowledge update speed of professionals often lags behind the frequent changes in legal and tax regulations and policies.

[0003] With the popularization of Internet technology, a huge amount of legal and tax information resources have emerged on the Internet. Various government websites, professional forums, legal databases and other platforms have gathered a large number of legal and regulatory provisions, tax policy interpretations, case analysis and other materials. However, these information resources are seriously fragmented and disordered. Information is scattered on different websites and platforms, lacking an effective integration mechanism, and users face great difficulties in retrieving and using this information. In addition, the quality of information on the Internet varies, and a large amount of information that has not been professionally reviewed is flooded. It is difficult for ordinary users to distinguish the authenticity and is easily misled, thus making wrong decisions. Online legal and tax knowledge bases or query tools can be used in related technologies, but such tools only provide basic legal and regulatory text retrieval functions, lack the ability to deeply analyze specific user problems, and cannot provide personalized and targeted solutions based on the user's actual situation. The accuracy and practicality of the answers to questions are low.

[0004] Therefore, there is an urgent need for a solution that can solve many problems in the legal and tax consulting process, such as low efficiency, lack of accuracy, and lack of personalized services. Summary of the invention

[0005] In order to solve or partially solve the problems existing in the relevant technologies, this application provides a model construction method, device and electronic equipment based on knowledge graph, which can accurately apply professional knowledge in the field of law and taxation, realize automatic and intelligent processing of user consultations, and generate consulting solutions that meet regulatory requirements and are practical.

[0006] The first aspect of the present application provides a model construction method based on a knowledge graph, comprising: Extract several entities and the relationships between them based on the preset knowledge base in the field of law and taxation; Construct a knowledge graph according to the entities and the relationships between the entities; Mapping the entities in the knowledge graph and the relationships between the entities to obtain a vector representation of the knowledge graph; Fusion the vector representation into a preset large language model; The fused preset large language model is pre-trained and fine-tuned to generate a target model, and the target model is used to answer questions related to the law and taxation field input by the user.

[0007] Preferably, mapping the entities in the knowledge graph and the relationships between the entities to obtain a vector representation of the knowledge graph includes: For the entity in the knowledge graph, the entity is mapped to a low-dimensional vector space by a preset mapping function to generate a vector representation of the entity; With respect to the relationship between the entities in the knowledge graph, the relationship is mapped to a low-dimensional vector space through a preset mapping function to generate a vector representation of the relationship.

[0008] Preferably, fusing the vector representation into a preset large language model comprises: Obtaining a word vector by encoding the preset large language model; Setting weight coefficients corresponding to the word vector, the vector representation of the entity, and the vector representation of the relationship; A fusion vector is generated according to the word vector, the vector representation of the entity, the vector representation of the relationship, and the corresponding weight coefficients, so as to fuse the vector representation into a preset large language model.

[0009] Preferably, the constructing a knowledge graph according to the entities and the relationships between the entities includes: constructing triples based on the entities and the relationships between the entities; Extracting the attributes of each of the entities to form an attribute set corresponding to each of the entities; A knowledge graph is constructed according to the attribute set and the triples.

[0010] Preferably, the pre-training and fine-tuning of the fused preset large language model to generate a target model comprises: Acquire a first training data set and a second training data set based on the preset knowledge base; the first training data set includes a plurality of first training samples, and the second training data set includes a plurality of second training samples; Pre-training the preset large language model using the first training data set; The second training data set is used to fine-tune the pre-trained preset large language model to generate the target model.

[0011] Preferably, the pre-training the preset large language model using the training data set includes: For each of the first training samples, a first predicted label of the first training sample is generated by the preset large language model; the first training sample has a true label; Calculating a loss value between the true label and the first predicted label, and calculating a probability distribution of the first predicted label according to a first parameter set of the preset large language model; Calculate a first training loss of the first training sample according to the probability distribution of the true label and the first predicted label, and calculate a second training loss of the first training data set based on the first training loss of the first training sample; Based on the loss value and the second training loss, a first parameter set of the large language model is updated, and the step of generating a first predicted label of the training sample by using the preset large language model for each of the first training samples is returned until a first preset condition is met.

[0012] Preferably, the fine-tuning of the pre-trained preset large language model using the training data set includes: After the first preset condition is met, inserting an adapter into the preset large language model, wherein the adapter has a second parameter set; For each of the second training samples, generating a probability distribution of a second predicted label of the second training sample by using the preset large language model based on the first parameter set and the second parameter set; Calculate a first fine-tuning loss of the second training sample according to the probability distribution of the second predicted label, and calculate a second fine-tuning loss of the first training data set and the second training data set based on the first fine-tuning loss of the second training sample; The first parameter set and the second parameter set are updated based on the second fine-tuning loss, and the step of generating a second predicted label of the second training sample and a probability distribution of the second predicted label through the preset large language model based on the first parameter set and the second parameter set for each second training sample is returned until a second preset condition is met.

[0013] Preferably, the preset knowledge base contains knowledge text data and legal and tax consultation record data, and the steps before extracting a number of entities and relationships between entities based on the preset knowledge base in the field of law and tax include: Preprocessing the knowledge text data; The legal and tax consulting record data is enhanced.

[0014] The second aspect of the present application provides a model building device based on a knowledge graph, comprising: An extraction module, used to extract a number of entities and the relationships between them based on a preset knowledge base in the field of law and taxation; A construction module, used for constructing a knowledge graph according to the entities and the relationships between the entities; A mapping module, used to map the entities in the knowledge graph and the relationships between the entities to obtain a vector representation of the knowledge graph; A fusion module, used for fusing the vector representation into a preset large language model; A generation module is used to pre-train and fine-tune the fused preset large language model to generate a target model, and the target model is used to answer questions related to the law and taxation field input by the user.

[0015] A third aspect of the present application provides an electronic device, including: Processor; and The memory stores executable codes thereon, and when the executable codes are executed by the processor, the processor is caused to execute the method as described above.

[0016] The technical solution provided by the present application may include the following beneficial effects: The embodiment of the present application provides a model construction method based on a knowledge graph, including: extracting the relationship between several entities and entities based on a preset knowledge base in the field of law and tax, constructing a knowledge graph according to the relationship between entities and entities, mapping the relationship between entities and entities in the knowledge graph, obtaining a vector representation of the knowledge graph, fusing the vector representation into a preset large language model, pre-training and fine-tuning the fused preset large language model, generating a target model, and the target model is used to answer questions related to the field of law and tax input by users. Through the above scheme, it is possible to effectively integrate the fragmented knowledge in the field of law and tax, construct a knowledge graph to make the knowledge association clear, fuse the knowledge graph with the large model, comprehensively use cutting-edge technologies, realize automatic and intelligent processing of user consultations, quickly generate solutions, greatly shorten the consultation response time, improve the overall consultation efficiency, enable enterprises and individuals to obtain the required legal and tax advice in a timely manner, avoid affecting decision-making or business processes due to long waiting time, and meet the diverse needs of different users in various legal and tax scenarios.

[0017] The technical solution of the present application can also fine-tune the model after pre-training the model and integrating the knowledge graph, so that the model can focus on key legal and tax information, better understand the semantics and logic of legal and tax issues, design multi-level loss functions, and comprehensively evaluate and optimize the model's performance in knowledge understanding, logical reasoning, solution generation, etc., to ensure that the generated consulting solution meets both legal and tax professional requirements and the actual needs of users.

[0018] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] The above and other objects, features and advantages of the present application will become more apparent by describing in more detail the exemplary embodiments of the present application in conjunction with the accompanying drawings, wherein the same reference numerals generally represent the same components in the exemplary embodiments of the present application.

[0020] Figure 1 It is a flowchart of a method for building a model based on a knowledge graph according to an embodiment of the present application; Figure 2 It is another flow chart of the method for building a model based on a knowledge graph shown in an embodiment of the present application; Figure 3 It is another flow chart of the method for building a model based on a knowledge graph shown in an embodiment of the present application; Figure 4 It is a schematic diagram of a model building method based on a knowledge graph shown in an embodiment of the present application; Figure 5 It is a structural schematic diagram of a knowledge graph-based model building device shown in an embodiment of the present application; Figure 6 It is a schematic diagram of the structure of an electronic device shown in an embodiment of the present application. DETAILED DESCRIPTION

[0021] The embodiments of the present application will be described in more detail below with reference to the accompanying drawings. Although the embodiments of the present application are shown in the accompanying drawings, it should be understood that the present application can be implemented in various forms and should not be limited by the embodiments described herein. On the contrary, these embodiments are provided to make the present application more thorough and complete, and to fully convey the scope of the present application to those skilled in the art.

[0022] The terms used in this application are for the purpose of describing specific embodiments only and are not intended to limit this application. The singular forms of "a", "said" and "the" used in this application and the appended claims are also intended to include plural forms unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.

[0023] It should be understood that although the terms "first", "second", "third", etc. may be used in this application to describe various information, this information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of this application, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Thus, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features. In the description of this application, the meaning of "multiple" is two or more, unless otherwise clearly and specifically defined.

[0024] In the related technologies, online legal and tax knowledge bases or query tools can be used, but such tools only provide basic legal and regulatory retrieval functions, lack the ability to conduct in-depth analysis of specific user questions, and cannot provide personalized and targeted solutions based on the user's actual situation. The accuracy and practicality of the answers to questions are low. Therefore, there is an urgent need for a solution that can solve many problems in the legal and tax consultation process, such as low efficiency, lack of accuracy, and lack of personalized services.

[0025] In response to the above problems, the embodiments of the present application provide a model building method based on a knowledge graph, which can accurately apply professional knowledge in the field of law and taxation, realize automated and intelligent processing of user consultations, and generate consulting solutions that meet regulatory requirements and are practical.

[0026] The technical solution of the embodiments of the present application is described in detail below with reference to the accompanying drawings.

[0027] Figure 1 It is a flow chart of the knowledge graph-based model building method shown in an embodiment of the present application.

[0028] See also Figure 1 , the method comprising: Step 101, extracting a number of entities and relationships between them based on a preset knowledge base in the field of law and taxation.

[0029] In the embodiment of the present application, different types of data such as legal text data, tax text data, and comprehensive texts in the field of law and tax can be collected to establish a preset knowledge base in the field of law and tax. Legal text data can include implementation documents, explanatory documents, persuasive documents, normative legal texts, legal works, etc., implementation documents can include legislative documents, judicial documents, judgments, and private legal documents, etc., explanatory documents can include letters from lawyers to clients, memoranda of law firms, legal works and educational materials, etc., normative legal texts can include laws and regulations, contract clauses, etc., and legal works can include legal review articles, legal papers, monographs, and judges' opinions. Tax text data can include laws, regulations, rules, normative documents, and official documents related to taxation. Comprehensive texts in the field of law and taxation can include law enforcement and regulatory documents, judicial practice documents, policy interpretation and guidance documents, corporate tax documents, etc.

[0030] Through NLP (Natural Language Processing) technology, various legal and tax knowledge such as legal provisions, tax policies, cases, and the relationships between knowledge are extracted from the data of the preset knowledge base, and the extracted knowledge is regarded as an entity, and the relationships between knowledge are regarded as the relationships between entities.

[0031] In an optional embodiment of the present application, the preset knowledge base includes knowledge text data and legal and tax consultation record data, and before step 101, it also includes: Step S1, preprocessing the knowledge text data.

[0032] The preset knowledge base contains knowledge text data, which covers a rich variety of legal and tax content, laying the foundation for the model to learn common language patterns, legal and tax knowledge, and semantic understanding.

[0033] Data preprocessing operations can be performed on the knowledge text data in the preset knowledge base. First, noise reduction and deduplication preprocessing are performed, and regular expressions and other methods are used to remove noise data in the text, such as garbled characters, special symbols, etc. At the same time, duplicate data is identified and deleted to ensure the purity and uniqueness of the data. Then, key information is extracted using rule-based and statistical methods. For example, based on the fixed format of legal clauses and the keyword table of tax categories, based on statistics, the frequency and co-occurrence relationship of vocabulary in a large amount of legal and tax text data are analyzed to determine key information (such as legal clause number, specific clause content, tax classification code, tax category name, legal and tax case information, relevant corporate entity information, important time nodes, amount data, etc.), and then combined with the rule extraction results for verification and optimization, so as to accurately identify and extract key legal and tax elements.

[0034] Each item of knowledge text data can also be converted into the format of text instructions, which can be used for pre-training of subsequent models. Examples of text instructions are shown in Table 1 below: Table 1

[0035] Step S2, enhancing the legal and tax consultation record data.

[0036] The preset knowledge base also contains legal and tax consultation record data, which contains a series of historical consultation questions related to the legal and tax fields and the corresponding expert responses. For legal and tax consultation record data, each item of data in the legal and tax consultation record data can be converted into the instruction-input-output format for subsequent supervised fine-tuning training of the large model. An example of an instruction-input-output instruction is shown in Table 2 below: Table 2

[0037] The instruction part corresponds to the questions raised by the customer in the legal and tax consulting record data, the input part is the content after the key information is extracted from the questions raised by the customer using NLP natural language processing technology (the key information is extracted to allow the model to better understand user needs), and the output part corresponds to the expert's reply to the customer's question in the legal and tax consulting record data. Putting these pieces of information together constitutes the instruction-input-output instruction.

[0038] In order to expand the data in the legal and tax consultation record data and improve the generalization ability of the model and its adaptability to different expressions, data enhancement methods such as back-translation, random insertion, and original text rewriting are used to generate more text data with similar semantics. Data enhancement is mainly for the content of the instruction and output parts, so as to generate a variety of similar questions and responses. Back-translation generates texts with similar semantics but diverse expressions by translating the text into other languages ​​and then translating it back to the original language; random insertion randomly inserts synonyms or related words into the text to enrich the diversity of data samples. Rewriting is to rewrite the sentence structure or vocabulary. These operations effectively expand the scale of data in the preset knowledge base, improve the generalization ability and adaptability of the model to the expression of different legal and tax issues, and provide rich and high-quality data for subsequent training.

[0039] Step 102, construct a knowledge graph based on entities and relationships between entities.

[0040] In order to enhance the model's ability to perceive the knowledge in the preset knowledge base, so that the model can mine more knowledge from it to solve the user's legal and tax consulting demands and generate more professional responses, a knowledge graph can be constructed and integrated into the model. After extracting the relationship between entities from the preset knowledge base, a legal and tax knowledge graph can be constructed using a graph database to store and associate legal provisions, tax policies, cases and other knowledge in a structured form. Through NLP technology, knowledge is converted into nodes of the knowledge graph, and the relationship between knowledge is converted into edges of the knowledge graph, thereby forming a structured knowledge network. For example, specific legal clauses are used as nodes, and the reference relationship between clauses is used as an edge; tax policies are associated with applicable enterprise types, etc.

[0041] In an optional embodiment of the present application, step 102 includes: Construct triples based on entities and relationships between them; Extract the attributes of each entity and form a set of attributes corresponding to each entity; Construct a knowledge graph based on attribute sets and triples.

[0042] Assumptions is a collection of entities, is the set of relations between entities. For each entity and relationship ,Using Neo4j graph database to build legal and tax knowledge graph ,in Represents a node set of the knowledge graph, consisting of an entity set Composition, edge set Representing a set of relations For two entities and The relationship between , which can be expressed as a triple When constructing the legal and tax knowledge graph, we analyze the legal and tax texts and use information extraction algorithms to convert information such as legal provisions, tax policies and cases into this triple form.

[0043] Furthermore, each entity can be extracted The properties of Representing Entities The attribute set of , Representing Entities An attribute of .

[0044] By analyzing and associating the attributes of entities and combining triples, a complete knowledge graph can be constructed. The construction process can be formalized as .

[0045] Step 103, map the entities in the knowledge graph and the relationships between them to obtain a vector representation of the knowledge graph.

[0046] The entities and relationships between entities in the knowledge graph are mapped to a low-dimensional vector space through the Word2Vec (word to vector) semantic embedding technology, thereby obtaining a vector representation of the knowledge graph, giving it a numerical representation.

[0047] Step 104: fuse the vector representation into a preset large language model.

[0048] In an embodiment of the present application, the preset large language model can select a large model as the basic architecture, which includes multiple levels of neural network structures, such as a multi-layer Transformer encoder. These encoders can perform deep semantic understanding and feature extraction on the input text. The model uses a multi-head attention mechanism to focus on different parts of the text in parallel to capture key information and semantic relationships in the text. At the same time, the feedforward neural network performs nonlinear transformation on the extracted features to further enrich the feature representation.

[0049] After obtaining the vector representation of the knowledge graph, the vector representation can be integrated into the preset large language model by weighted averaging or concatenation.

[0050] Step 105, pre-training and fine-tuning the fused preset large language model to generate a target model, which is used to answer questions related to the law and taxation field input by the user.

[0051] The output layer of the preset large language model can generate the corresponding preliminary answer text according to the questions related to the legal and tax fields input by the user, providing a basis for fine-tuning and optimization. After fusion, the preset large language model can be pre-trained and fine-tuned to generate a target model. The target model has adapted to the characteristics and needs of the legal and tax fields. When receiving the user's legal and tax consulting related questions, the question is used as input. The target model will automatically analyze and process the input information according to the knowledge and patterns it has learned, and combine the structured knowledge in the knowledge graph and the understanding of legal and tax data to generate detailed consulting solutions covering legal interpretation, tax planning, risk prevention and control, etc., to provide users with comprehensive, accurate and personalized services. For example, when a user enters a question about corporate tax planning, the target model can generate a detailed consulting solution containing specific operation steps, possible risks and countermeasures based on its understanding of the problem, combined with its own knowledge reserves and reasoning ability. Through the pre-training and fine-tuning process, the model can better transfer the knowledge learned in the general language learning stage to the legal and tax field, and at the same time optimize it for legal and tax tasks to ensure that the generated consulting solutions meet both the legal and tax professional requirements and the actual needs of users. After pre-training and fine-tuning, the model will be more targeted and adaptable, and will be able to better provide services to users in the legal and tax field.

[0052] The embodiment of the present application provides a model construction method based on a knowledge graph, including: extracting the relationship between several entities based on a preset knowledge base in the field of law and tax, constructing a knowledge graph based on the relationship between entities, mapping the relationship between entities in the knowledge graph, obtaining a vector representation of the knowledge graph, fusing the vector representation into a preset large language model, pre-training and fine-tuning the fused preset large language model, and generating a target model, which is used to answer questions related to the field of law and tax input by users. Through the above scheme, it is possible to effectively integrate the fragmented knowledge in the field of law and tax, construct a knowledge graph to make the knowledge association clear, fuse the knowledge graph with the large model, comprehensively use cutting-edge technologies, realize automatic and intelligent processing of user consultations, quickly generate solutions, greatly shorten the consultation response time, improve the overall consultation efficiency, enable enterprises and individuals to obtain the required legal and tax advice in a timely manner, avoid affecting decision-making or business processes due to long waiting time, and meet the diverse needs of different users in various legal and tax scenarios.

[0053] Figure 2 It is another flow chart of the knowledge graph-based model building method shown in an embodiment of the present application.

[0054] See also Figure 2 , this method is used to integrate the knowledge graph into the model after building the knowledge graph. The method includes: Step 201, for entities in the knowledge graph, map the entities to a low-dimensional vector space through a preset mapping function to generate a vector representation of the entity.

[0055] For entities in the knowledge graph , let its representation in high-dimensional space be , through the mapping function of Word2Vec , the entity Mapping to vector representation in low-dimensional vector space ,in represents a high-dimensional vector space, Represents a low-dimensional vector space.

[0056] Step 202, for the relationship between entities in the knowledge graph, map the relationship to a low-dimensional vector space through a preset mapping function to generate a vector representation of the relationship.

[0057] For the relationship between entities in the knowledge graph , let its representation in high-dimensional space be , through the mapping function of Word2Vec , the relationship between entities Mapping to vector representation in low-dimensional vector space .

[0058] Step 203, obtain word vectors by encoding the preset large language model.

[0059] The preset large language model has a language encoder AutoTokenizer, which can be used to encode and obtain the word vector of the preset large language model. .

[0060] Step 204, setting weight coefficients corresponding to the word vector, the vector representation of the entity, and the vector representation of the relationship.

[0061] Through pre-training or pre-definition, entities can be Set the corresponding weight coefficient , which is the relationship between entities Set the corresponding weight coefficient , is the word vector Set the corresponding weight coefficient By setting corresponding weight coefficients for word vectors, entity vector representations, and relationship vector representations, the contributions of different parts can be balanced.

[0062] Step 205 , generating a fusion vector according to the word vector, the vector representation of the entity, the vector representation of the relationship and the corresponding weight coefficients, so as to fuse the vector representation into a preset large language model.

[0063] The vector representation of the knowledge graph can be fused into the preset large language model by weighted averaging or concatenation. For example, for a knowledge graph subgraph containing multiple entities and relationships, its fused vector It can be calculated by formula (1): (1) By effectively integrating fragmented legal and tax knowledge, the constructed knowledge graph makes knowledge associations clear, which not only facilitates the model to utilize knowledge generation solutions, but also promotes industry knowledge exchange and dissemination through sharing knowledge graphs, improves the overall level of legal and tax knowledge, provides learning and research resources for practitioners, and promotes knowledge development and innovation in the legal and tax fields.

[0064] Step 206, pre-training and fine-tuning the fused preset large language model to generate a target model, which is used to answer questions related to the law and taxation field input by the user.

[0065] After fusion, the preset large language model can be pre-trained and fine-tuned to generate a target model. The target model has adapted to the characteristics and needs of the legal and tax fields. When receiving legal and tax consulting related questions from users, the questions are used as input. The target model will automatically analyze and process the input information based on the knowledge and patterns it has learned, and combine the structured knowledge in the knowledge graph and the understanding of legal and tax data to generate detailed consulting solutions covering legal interpretation, tax planning, risk prevention and control, etc., to provide users with comprehensive, accurate and personalized services. Personalized consulting solutions can be provided according to different user needs. For enterprises of different industries and sizes, such as manufacturing and service industries, or high-income and ordinary-income individuals, exclusive legal and tax suggestions can be given based on their characteristics, covering tax optimization, risk prevention and control, etc., to help users maximize their benefits under the premise of legal and tax compliance. For example, when a user enters a question about corporate tax planning, the model can generate a detailed consulting solution containing specific operation steps, possible risks and countermeasures based on its understanding of the problem, combined with its own knowledge reserves and reasoning ability.

[0066] The embodiment of the present application provides a model construction method based on a knowledge graph, which can be combined with the knowledge graph construction so that the model can deeply understand the essence of legal and tax issues, accurately apply professional knowledge, generate consulting solutions that meet regulatory requirements and are practical, and effectively reduce legal and tax risks caused by inaccurate solutions.

[0067] Figure 3 It is another flow chart of the knowledge graph-based model building method shown in an embodiment of the present application.

[0068] See also Figure 3 , this method is used to fuse the knowledge graph into the model, and the method includes: Step 301: Acquire a first training data set and a second training data set based on a preset knowledge base; the first training data set includes a plurality of first training samples, and the second training data set includes a plurality of second training samples.

[0069] Based on the knowledge text data in the preset knowledge base in the field of law and taxation, the first training data set is established ,in is the first training sample, representing a text instruction (a piece of knowledge in the field of law and taxation).

[0070] In the legal and tax consulting record data in the preset knowledge base in the legal and tax field, for an instruction-input-output instruction, instruction and input are combined to form a second training data set, and the second data contains a second training sample , , Represents the words in the second training sample, and the output part is , as the annotation information of the second training sample.

[0071] Step 302: for each first training sample, generate a first predicted label of the first training sample by using a preset large language model; the first training sample has a true label.

[0072] For the first training sample ,in Represents the words in the first training sample, which can be input into a preset large language model for pre-training. During the pre-training process, self-supervised learning is usually used to allow the model to learn the common language patterns and feature representations of the text. In addition, some of the words in the input first training sample D can be randomly replaced with mask tags to let the model predict the masked words. The mask position in the text of the first training sample D yes After the first training sample D is input into the preset large language model, its corresponding first predicted label can be generated.

[0073] Step 303: Calculate the loss value between the true label and the first predicted label, and calculate the probability distribution of the first predicted label according to the first parameter set of the preset large language model.

[0074] Through forward propagation, the loss value between the true label and the first predicted label can be calculated. Furthermore, the probability distribution of the first predicted label can be calculated by presetting the first parameter set of the large language model. , It can be calculated by formula (2): (2) Wherein, f is a probability distribution function, and θ is a first parameter set of a preset large language model.

[0075] Step 304: Calculate a first training loss of the first training sample according to the probability distribution of the true label and the first predicted label, and calculate a second training loss of the first training data set based on the first training loss of the first training sample.

[0076] According to the probability distribution of the first training sample , the first training loss of the first training sample can be calculated , the calculation formula is as shown in formula (3): (3) After obtaining the first training loss of a single first training sample, the second training loss of the entire training data set can be calculated based on the cross entropy loss. , the calculation formula is as shown in formula (4): (4) Step 305 , updating the first parameter set of the large language model based on the loss value and the second training loss, and returning to the step of generating a first prediction label of the training sample by using the preset large language model for each first training sample until the first preset condition is met.

[0077] After obtaining the second training loss, the first parameter set of the model is updated using the gradient descent algorithm, and the gradient of the second training loss with respect to the overall parameters of the model is calculated by back propagation according to the loss value to measure the direction and amplitude of the parameter adjustment. According to the calculated gradient and the set learning rate, the first parameter set θ of the model is adjusted in the direction of reducing the second training loss. After updating the first parameter set, the step of generating the first prediction label of the training sample by the preset large language model for each first training sample is returned to, and multiple rounds of iterations are performed to re-pre-train the preset large language model until the first preset condition is met, and the learning ability of the preset large language model for the general features of the text is continuously optimized, so that the model learns the general semantics and grammatical structure of the text. The first preset condition may be that the actual number of training rounds reaches the preset number of training rounds, or the value of the second training loss reaches a stable value, etc.

[0078] Step 306: After the first preset condition is met, insert an adapter into the preset large language model, where the adapter has a second parameter set.

[0079] After the first preset condition is met, the pre-training ends, and the pre-trained preset large language model is fine-tuned by using Adapter Tuning. Adapter A is inserted into the middle layer of the preset large language model. Adapter A consists of a down-projection fully connected layer, a nonlinear transformation layer, and an up-projection fully connected layer, and has a second parameter set .

[0080] Step 307 : For each second training sample, generate a probability distribution of a second predicted label of the second training sample by using a preset large language model based on the first parameter set and the second parameter set.

[0081] During fine-tuning, a second training dataset with labeled data is input into the model. , the model with the adapter predicts the output of the second predicted label, and generates the probability distribution of the second predicted label according to the first parameter set and the second parameter set , It can be calculated by formula (5): (5) in, is the probability distribution function.

[0082] Step 308 , calculating a first fine-tuning loss of the second training sample according to the probability distribution of the second predicted label, and calculating a second fine-tuning loss of the first training data set and the second training data set based on the first fine-tuning loss of the second training sample.

[0083] Different fine-tuning loss functions can be used for different tasks. The supervised fine-tuning task is similar to the text generation task, that is, generating answers that are closest to the semantics of the annotation information of the second training sample through the legal and tax questions asked by the customer. Taking the text generation task as an example, the negative log-likelihood loss is used. For the fine-tuning loss function of a single second training sample, It can be calculated using the following formula (6): (6) in The model predicts the next word given the previous word probability.

[0084] For the second fine-tuning loss of the complete legal tax dataset composed of the first training dataset and the second training dataset, the first fine-tuning loss of the second training sample can be calculated by the following formula (7): (7) Step 309, update the first parameter set and the second parameter set based on the second fine-tuning loss, return to the step of generating the second prediction label of the second training sample and the probability distribution of the second prediction label based on the first parameter set and the second parameter set through the preset large language model for each second training sample, until the second preset condition is met and the target model is generated.

[0085] In the fine-tuning stage, the gradient is calculated by the back-propagation algorithm, and the loss value is calculated by the negative log-likelihood loss for text generation, and then the gradient and learning rate of the adapter and some sensitive model parameters are obtained. According to the gradient and learning rate of the fine-tuning stage, the second parameter set of the adapter is updated. As well as some model parameters in the first parameter set that are sensitive to the tax task. For gradient update, the gradient descent algorithm is used, as shown in the following formula (8): (8) in is the learning rate, Indicates the number of iterations. In this way, the model can focus on the key information of law and taxation while keeping most of the original parameters stable, and better understand the semantics and logic of law and taxation issues, so as to be more adaptable to various tasks in the field of law and taxation. At the same time, since the parameter update amount of the adapter is relatively small, it can effectively reduce the risk of overfitting, so that the model can achieve better performance on the law and taxation dataset. As shown in Table 3, an example of the relevant parameter settings involved in the pre-training and fine-tuning stages is shown: Table 3

[0086] In the update adapter the second parameter set After the model parameters in the first parameter set that are sensitive to the tax task are obtained, the process can return to the step of generating the second predicted label of the second training sample and the probability distribution of the second predicted label through the preset large language model based on the first parameter set and the second parameter set for each second training sample, perform multiple rounds of iterations, and fine-tune the preset large language model again until the second preset condition is met. The first preset condition can be that the actual number of training rounds reaches the preset number of training rounds, or the value of the second training loss reaches a stable value, etc.

[0087] Through the above pre-training and fine-tuning process, the model can better transfer the knowledge learned in the general language learning stage to the field of law and taxation, and optimize it for law and taxation tasks to ensure that the generated consulting solutions meet both the requirements of law and taxation and the actual needs of users. After pre-training and fine-tuning, the model will be more targeted and adaptable, and can better provide services to users in the field of law and taxation.

[0088] like Figure 4 As shown in the figure, it is a schematic diagram of the model construction method based on the knowledge graph, in which the preset knowledge base in the field of law and taxation contains relevant data in the field of law and taxation, such as knowledge text data and legal and taxation consultation record data. For the knowledge text data, various types of legal and taxation knowledge such as legal provisions, tax policies, cases, and the relationship between knowledge in the data of the preset knowledge base are extracted through NLP technology, and the extracted knowledge is used as an entity, and the relationship between knowledge is used as the relationship between entities. A knowledge graph is constructed based on the relationship between entities, and entities and relationships are mapped to a low-dimensional vector space through Word2Vec to integrate the knowledge graph into the preset large language model. Each item of data in the knowledge text data is also converted into the format of a text instruction, thereby obtaining n text instructions, establishing the first training data set, and performing multiple rounds of iterative pre-training on the preset large language model. For the legal and tax consultation record data, data enhancement processing can be performed to extract key information and form instruction-input-output instructions, thereby obtaining m instruction-input-output instructions. Based on the instruction-input-output instructions, a second training data set is established, and the pre-trained preset large language model is fine-tuned using the Adapter Tuning fine-tuning strategy according to the second training data set to generate a target model. When the user inputs questions related to the legal and tax fields, the target model generates a legal and tax fusion consulting solution. The target model uses cutting-edge technologies to realize automatic and intelligent processing of user consultations, quickly generate solutions, greatly shorten the consultation response time, and improve the overall consultation efficiency and accuracy, so that enterprises and individuals can obtain the required legal and tax advice in a timely manner, avoid the decision-making or business process affected by long waiting time, and quickly provide detailed solutions to solve user consultation problems, reducing manual analysis time. In addition, due to the integration of multiple technologies, the solution is highly accurate, based on accurate legal interpretation and case reference, avoiding human errors and improving decision-making reliability. By using data preprocessing, enhancement technology, and fine-tuning of large language models, combined with knowledge graph construction, the model can deeply understand the essence of legal and tax issues, accurately apply professional knowledge, generate consulting solutions that meet regulatory requirements and are practical, and effectively reduce legal and tax risks caused by inaccurate solutions. Based on the detailed information entered by the user, with the help of a variety of integrated technologies, a comprehensive and personalized consulting solution covering legal interpretation, tax planning, risk prevention and control is generated to meet the diverse needs of different users in various legal and tax scenarios, such as customizing exclusive tax planning solutions for enterprises in different industries, and providing accurate legal and tax guidance for personal real estate transactions.

[0089] The embodiment of the present application provides a model building method based on a knowledge graph. After the model is pre-trained and the knowledge graph is integrated, the model is fine-tuned and trained so that the model can focus on key legal and tax information, better understand the semantics and logic of legal and tax issues, design a multi-level loss function, and comprehensively evaluate and optimize the model's performance in knowledge understanding, logical reasoning, and solution generation, to ensure that the generated consulting solution meets both the legal and tax professional requirements and the actual needs of users.

[0090] Corresponding to the aforementioned application function implementation method embodiment, the present application also provides a knowledge graph-based model building device, electronic device and corresponding embodiments.

[0091] Figure 5 It is a structural diagram of a knowledge graph-based model building device shown in an embodiment of the present application.

[0092] See also Figure 5 , the device comprises: An extraction module 501 is used to extract a number of entities and relationships between them based on a preset knowledge base in the field of law and taxation; A construction module 502 is used to construct a knowledge graph based on entities and relationships between entities; A mapping module 503 is used to map entities and relationships between entities in the knowledge graph to obtain a vector representation of the knowledge graph; A fusion module 504, used to fuse the vector representation into a preset large language model; The generation module 505 is used to pre-train and fine-tune the fused preset large language model to generate a target model, and the target model is used to answer questions related to the law and taxation field input by the user.

[0093] In an optional embodiment of the present application, the mapping module 503 includes: The first mapping submodule is used to map entities in the knowledge graph to a low-dimensional vector space through a preset mapping function to generate a vector representation of the entity; The second mapping submodule is used to map the relationship between entities in the knowledge graph to a low-dimensional vector space through a preset mapping function to generate a vector representation of the relationship.

[0094] In an optional embodiment of the present application, the fusion module 504 includes: The encoding submodule is used to obtain word vectors by encoding the preset large language model; Set up submodules to set the weight coefficients corresponding to word vectors, entity vector representations, and relationship vector representations; The fusion submodule is used to generate a fusion vector based on the word vector, the vector representation of the entity, the vector representation of the relationship and the corresponding weight coefficients, so as to fuse the vector representation into a preset large language model.

[0095] In an optional embodiment of the present application, the construction module 502 is further used to: Construct triples based on entities and relationships between them; Extract the attributes of each entity and form a set of attributes corresponding to each entity; Construct a knowledge graph based on attribute sets and triples.

[0096] In an optional embodiment of the present application, the generating module 505 includes: A training data submodule is used to obtain a first training data set and a second training data set based on a preset knowledge base; the first training data set includes a plurality of first training samples, and the second training data set includes a plurality of second training samples; A pre-training submodule, used to pre-train a preset large language model using a first training data set; The fine-tuning submodule is used to fine-tune the pre-trained preset large language model using the second training data set to generate a target model.

[0097] In an optional embodiment of the present application, the pre-training submodule is further used for: For each first training sample, a first predicted label of the first training sample is generated by a preset large language model; the first training sample has a true label; Calculate the loss value between the true label and the first predicted label, and calculate the probability distribution of the first predicted label according to the first parameter set of the preset large language model; Calculate a first training loss of the first training sample according to the probability distribution of the true label and the first predicted label, and calculate a second training loss of the first training data set based on the first training loss of the first training sample; The first parameter set of the large language model is updated based on the loss value and the second training loss, and the step of generating a first prediction label of the training sample by using the preset large language model for each first training sample is returned until the first preset condition is met.

[0098] In an optional embodiment of the present application, the fine-tuning submodule is further used for: After the first preset condition is met, inserting an adapter into the preset large language model, the adapter having a second parameter set; For each second training sample, generating a probability distribution of a second predicted label of the second training sample by using a preset large language model based on the first parameter set and the second parameter set; Calculate a first fine-tuning loss for the second training sample according to the probability distribution of the second predicted label, and calculate a second fine-tuning loss for the first training data set and the second training data set based on the first fine-tuning loss for the second training sample; The first parameter set and the second parameter set are updated based on the second fine-tuning loss, and the step of generating a second predicted label of the second training sample and a probability distribution of the second predicted label based on the first parameter set and the second parameter set through a preset large language model for each second training sample is returned until the second preset condition is met.

[0099] In an optional embodiment of the present application, the device further includes: A preprocessing module, used for preprocessing knowledge text data; Enhancement module, used to enhance the processing of legal and tax consulting record data.

[0100] The embodiment of the present application provides a model building device based on a knowledge graph, which can effectively integrate fragmented knowledge in the field of law and taxation, build a knowledge graph to make knowledge associations clear, merge the knowledge graph with the big model, and comprehensively use cutting-edge technologies to realize automated and intelligent processing of user consultations, quickly generate solutions, greatly shorten consultation response time, and improve overall consultation efficiency, so that enterprises and individuals can obtain the required legal and tax advice in a timely manner, avoid affecting decision-making or business processes due to long waiting time, and meet the diverse needs of different users in various legal and tax scenarios.

[0101] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated again here.

[0102] Figure 6 It is a schematic diagram of the structure of an electronic device shown in an embodiment of the present application.

[0103] See also Figure 6 , the electronic device 600 includes a memory 610 and a processor 620 .

[0104] The processor 620 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or the processor may be any conventional processor, etc.

[0105] The memory 610 may include various types of storage units, such as system memory, read-only memory (ROM), and permanent storage devices. Among them, ROM can store static data or instructions required by the processor 620 or other modules of the computer. The permanent storage device may be a readable and writable storage device. The permanent storage device may be a non-volatile storage device that does not lose the stored instructions and data even after the computer is powered off. In some embodiments, the permanent storage device uses a large-capacity storage device (such as a magnetic or optical disk, flash memory) as a permanent storage device. In some other embodiments, the permanent storage device may be a removable storage device (such as a floppy disk, optical drive). The system memory may be a readable and writable storage device or a volatile readable and writable storage device, such as a dynamic random access memory. The system memory may store some or all instructions and data required by the processor at runtime. In addition, the memory 610 may include any combination of computer-readable storage media, including various types of semiconductor storage chips (such as DRAM, SRAM, SDRAM, flash memory, programmable read-only memory), and disks and / or optical disks may also be used. In some embodiments, the memory 610 may include a readable and / or writable removable storage device, such as a laser disc (CD), a read-only digital versatile disc (such as a DVD-ROM, a double-layer DVD-ROM), a read-only Blu-ray disc, an ultra-density optical disc, a flash memory card (such as an SD card, a mini SD card, a Micro-SD card, etc.), a magnetic floppy disk, etc. Computer-readable storage media do not include carrier waves and transient electronic signals transmitted wirelessly or wired.

[0106] The memory 610 stores executable codes, and when the executable codes are processed by the processor 620 , the processor 620 can execute part or all of the above-mentioned methods.

[0107] In addition, the method according to the present application may also be implemented as a computer program or a computer program product, which includes computer program code instructions for executing some or all of the steps in the above method of the present application.

[0108] Alternatively, the present application can also be implemented as a computer-readable storage medium (or non-transitory machine-readable storage medium or machine-readable storage medium) on which executable code (or computer program or computer instruction code) is stored. When the executable code (or computer program or computer instruction code) is executed by a processor of an electronic device (or server, etc.), the processor executes part or all of the steps of the above-mentioned method according to the present application.

[0109] The embodiments of the present application have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and changes will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The selection of terms used herein is intended to best explain the principles of the embodiments, practical applications, or improvements to the technology in the market, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein.

Claims

1. A model construction method based on knowledge graph, characterized by: Extract several entities and the relationships between them based on the preset knowledge base in the field of law and taxation; Construct a knowledge graph according to the entities and the relationships between the entities; Mapping the entities in the knowledge graph and the relationships between the entities to obtain a vector representation of the knowledge graph; Fusion the vector representation into a preset large language model; The fused preset large language model is pre-trained and fine-tuned to generate a target model, and the target model is used to answer questions related to the law and taxation field input by the user.

2. The method according to claim 1, characterized in that: Mapping the entities in the knowledge graph and the relationships between the entities to obtain a vector representation of the knowledge graph includes: For the entity in the knowledge graph, the entity is mapped to a low-dimensional vector space by a preset mapping function to generate a vector representation of the entity; With respect to the relationship between the entities in the knowledge graph, the relationship is mapped to a low-dimensional vector space through a preset mapping function to generate a vector representation of the relationship.

3. The method according to claim 2, characterized in that The fusing the vector representation into a preset large language model comprises: Obtaining a word vector by encoding the preset large language model; Setting weight coefficients corresponding to the word vector, the vector representation of the entity, and the vector representation of the relationship; A fusion vector is generated according to the word vector, the vector representation of the entity, the vector representation of the relationship, and the corresponding weight coefficients, so as to fuse the vector representation into a preset large language model.

4. The method according to claim 1, characterized in that The constructing of a knowledge graph according to the entities and the relationships between the entities comprises: constructing triples based on the entities and the relationships between the entities; Extracting the attributes of each of the entities to form an attribute set corresponding to each of the entities; A knowledge graph is constructed according to the attribute set and the triples.

5. The method according to claim 1, characterized in that The pre-training and fine-tuning of the fused preset large language model to generate a target model comprises: Acquire a first training data set and a second training data set based on the preset knowledge base; the first training data set includes a plurality of first training samples, and the second training data set includes a plurality of second training samples; Pre-training the preset large language model using the first training data set; The second training data set is used to fine-tune the pre-trained preset large language model to generate the target model.

6. The method according to claim 5, characterized in that The pre-training of the preset large language model using the training data set includes: For each of the first training samples, a first predicted label of the first training sample is generated by the preset large language model; the first training sample has a true label; Calculating a loss value between the true label and the first predicted label, and calculating a probability distribution of the first predicted label according to a first parameter set of the preset large language model; Calculate a first training loss of the first training sample according to the probability distribution of the true label and the first predicted label, and calculate a second training loss of the first training data set based on the first training loss of the first training sample; Based on the loss value and the second training loss, a first parameter set of the large language model is updated, and the step of generating a first predicted label of the training sample by using the preset large language model for each of the first training samples is returned until a first preset condition is met.

7. The method according to claim 6, characterized in that The fine-tuning of the pre-trained preset large language model using the training data set includes: After the first preset condition is met, inserting an adapter into the preset large language model, wherein the adapter has a second parameter set; For each of the second training samples, generating a probability distribution of a second predicted label of the second training sample by using the preset large language model based on the first parameter set and the second parameter set; Calculate a first fine-tuning loss of the second training sample according to the probability distribution of the second predicted label, and calculate a second fine-tuning loss of the first training data set and the second training data set based on the first fine-tuning loss of the second training sample; The first parameter set and the second parameter set are updated based on the second fine-tuning loss, and the step of generating a second predicted label of the second training sample and a probability distribution of the second predicted label through the preset large language model based on the first parameter set and the second parameter set for each second training sample is returned until a second preset condition is met.

8. The method according to claim 1, characterized in that The preset knowledge base contains knowledge text data and legal and tax consultation record data. The steps before extracting a number of entities and relationships between entities based on the preset knowledge base in the field of law and tax include: Preprocessing the knowledge text data; The legal and tax consulting record data is enhanced.

9. A model building device based on knowledge graph, characterized in that: The device comprises: An extraction module, used to extract a number of entities and the relationships between them based on a preset knowledge base in the field of law and taxation; A construction module, used for constructing a knowledge graph according to the entities and the relationships between the entities; A mapping module, used to map the entities in the knowledge graph and the relationships between the entities to obtain a vector representation of the knowledge graph; A fusion module, used for fusing the vector representation into a preset large language model; A generation module is used to pre-train and fine-tune the fused preset large language model to generate a target model, and the target model is used to answer questions related to the law and taxation field input by the user.

10. An electronic device, characterized in that: include: processor; as well as A memory having executable codes stored thereon, which, when executed by the processor, causes the processor to execute the method according to any one of claims 1 to 8.

Citation Information

Cited By

  • Tax processing method based on AI intelligent question and answer of large language model

    CN121681726A