Question and answer large language model optimization method and device, equipment and storage medium
By combining knowledge graphs to optimize large-scale preset language models, the problems of limited knowledge, insufficient field adaptability and limited contextual understanding when processing in specific fields are solved, and higher accuracy and reliability are achieved.
Patent Information
- Application Number
- CN202411974976.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-31
- Publication Date
- 2025-04-18
AI Technical Summary
When existing large-scale preset language models deal with specific areas with strong professionalism, such as the medical field, there are problems such as limited knowledge, insufficient field adaptability and limited contextual understanding, which leads to poor performance in practical applications.
By combining knowledge graphs with structured descriptions of entities and relationships, general models are optimized to improve their domain adaptability, depth of knowledge and contextual understanding in specific fields. The specific methods include obtaining the preset knowledge graph, determining the text embedding vector of the entity triple, filtering the similar feature vectors corresponding to the problem vector, generating knowledge text groups, and generating reply text through the preset language model, and finally verifying the optimization language model through knowledge graph matching.
Effectively integrating knowledge graphs and general models in specific fields improves the accuracy and reliability of the model when dealing with problems in specific fields, and ensures improvement of knowledge reserves and context understanding capabilities.
Smart Images

Figure CN119848209A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of text question answering, and in particular to a method, apparatus, device and storage medium for optimizing a large language model for question answering. Background Art
[0002] With the rapid development of natural language processing technology, large-scale preset language models such as GPT-3 (Generative Pretrained Transformer 3) and BERT (Bidirectional Encoder Representations from Transformers) have strong versatility. Based on this feature, large-scale preset language models have achieved remarkable results in various natural language processing tasks. However, large-scale preset language models still have reliability and practicality issues when dealing with specific fields with strong professionalism. The medical field is used as an example to explain the reasons. Specifically: 1. Limited knowledge: Existing medical question-answering systems usually rely on general language models. However, these models do not have complete knowledge in the medical field, so they may not be able to provide accurate or comprehensive reliable answers when dealing with professional medical terms, disease diagnosis or drug information.
[0003] 2. Insufficient domain adaptability: Although large-scale language models have been extensively pre-trained, they lack deep expertise and the ability to understand complex medical language in specific fields such as medicine, which makes their performance in practical applications unsatisfactory.
[0004] 3. Limited context understanding ability: Medical problems usually involve complex contexts, such as the relationship between patient history, symptoms and corresponding treatment plans. Existing models have limitations in capturing and processing this complex information, which further affects the accuracy and reliability of task processing results.
[0005] To solve the above problems, knowledge graphs with structured descriptions of entities and relationships can be combined to optimize the processing performance of general models for natural language processing tasks in specific fields. However, despite the existence of a large amount of medical data and knowledge graphs, it is still a technical challenge to effectively integrate these field-specific knowledge into large-scale language models.
[0006] Based on this, how to effectively integrate the knowledge graph of a specific field with the general model to optimize the domain adaptability, knowledge depth and context understanding ability of the general model for the specific field is a technical problem that needs to be solved urgently. Summary of the invention
[0007] In order to overcome the shortcomings of the prior art, the present application provides a question-answering large language model optimization method, device, equipment and storage medium to effectively integrate the knowledge graph and the general model, optimize the general model's domain adaptability, knowledge depth and context understanding ability for specific fields, and make the general model more accurate and reliable when dealing with problems in specific fields.
[0008] The technical solution adopted by this application to solve its technical problem is: In a first aspect, the present application provides a method for optimizing a large question-answering language model, the method comprising: Obtain a preset knowledge graph; the preset knowledge graph includes a plurality of entity triples; one of the entity triples includes two node entities and relational data representing the relationship between the two node entities; Determine a text embedding vector corresponding to each entity triple according to the two node entities and the relationship data in the same entity triple; Determine a question vector based on a preset question text, and screen all the text embedding vectors to obtain a similar feature vector corresponding to the question vector; Performing text conversion on the similar feature vectors to obtain a knowledge text group, inputting the knowledge text group and the preset question text into a preset language model, so as to obtain a reply text of the question text based on the knowledge text group through the preset language model; The reply text is matched and verified based on the preset knowledge graph, and the preset language model is optimized according to the obtained verification result.
[0009] Optionally, the step of screening all the text embedding vectors to obtain similar feature vectors corresponding to the question vector includes: Calculate the similarity between each of the text embedding vectors and the question vector to determine the similarity between each of the text embedding vectors and the question vector; All the text embedding vectors are sorted from high to low based on the similarity, and a preset number of text embedding vectors that are sorted first are used as similar feature vectors.
[0010] Optionally, the step of obtaining a reply text to the question text based on the knowledge text group includes: Based on the preset knowledge graph, a text weight corresponding to each of the knowledge texts in the knowledge text group is obtained; one of the knowledge texts, the text weight corresponding to the knowledge text, and the preset question text are associated and recorded as a question-answer association group; All the question-answer association groups are input into the preset language model, so as to generate a reply text corresponding to the preset question text based on each of the question-answer association groups through the preset language model.
[0011] Optionally, determining a corresponding text weight based on the relationship data; the method further includes: Acquire update data; the update data includes two node entities to be verified; Determine whether there is a matching triple corresponding to the updated data in the preset knowledge graph, wherein the matching triple is an entity triple that matches the two node entities and the two node entities to be verified; If the matching triple exists, adjusting the text weight corresponding to the relational data in the matching triple, and updating the adjusted matching triple to the preset knowledge graph; If the matching triple does not exist, an updated triple is constructed based on the updated data and the preset initial weight, and the updated triple is updated to the preset knowledge graph as a new entity triple.
[0012] Optionally, the step of performing matching verification on the reply text based on the preset knowledge graph and optimizing the preset language model according to the obtained verification result includes: The reply text is input into a preset information extraction model to extract the reply text through the preset information extraction model to obtain a reply text triple; one reply text triple includes two node entities and relational data representing the relationship between the two node entities; Among all the entity triples, match the associated triple corresponding to the reply text triple; the associated triple is an entity triple whose node entity and relationship data are the same as a node entity and relationship data in the reply text triple; Sorting all the associated triples from high to low based on the text weight corresponding to each of the associated triples, and taking the top associated triple as the target triple; Determine whether two node entities and relationship data of the target triplet overlap with two node entities and relationship data of the target triplet; If they do not overlap, the target triple and the preset question text are input into the preset language model to optimize the answer text corresponding to the preset question text output by the preset language model based on the target triple.
[0013] Optionally, the step of inputting the reply text into a preset information extraction model to extract the reply text through the preset information extraction model to obtain a reply text triple includes: Acquire preset prompt information; the preset prompt information includes sample text data, sample triples corresponding to the sample text data, and sample requirement information; The reply text and the preset prompt information are input into the preset information extraction model, so as to extract an element group from the reply text based on the sample text data and the sample triples through the preset information extraction model; one element group includes two node entities and one relationship data; The preset information extraction model is used to integrate the node entities and relationship data corresponding to each element group into the reply text triples according to the example requirement information and then output.
[0014] Optionally, the step of obtaining a preset knowledge graph includes: Retrieve the data source to extract all the node entities and all the relationship data; Performing standardization processing on all the node entities and all the relationship data, and determining the relationship data corresponding to every two of the node entities based on all the node entities and all the relationship data after the standardization processing; The two node entities with corresponding relationship data and the corresponding relationship data are taken as an entity triple to obtain multiple entity triples, and the preset knowledge graph is constructed based on all the entity triples.
[0015] In a second aspect, the present application provides a large language model optimization device for question answering, comprising: A knowledge graph acquisition module, used to acquire a preset knowledge graph; the preset knowledge graph includes a plurality of entity triples; one of the entity triples includes two node entities and relationship data representing the relationship between the two node entities; An embedding vector conversion module, used for determining a text embedding vector corresponding to each entity triple according to the two node entities and the relationship data in the same entity triple; A similarity vector screening module is used to determine a question vector based on a preset question text, and to screen all the text embedding vectors to obtain a similar feature vector corresponding to the question vector; A reply text output module, used for performing text conversion on the similar feature vectors to obtain a knowledge text group, inputting the knowledge text group and the preset question text into a preset language model, so as to obtain a reply text of the question text based on the knowledge text group through the preset language model; A matching verification optimization module is used to perform matching verification on the reply text based on the preset knowledge graph, and optimize the preset language model according to the obtained verification results.
[0016] In a third aspect, the present application provides an electronic device, including: one or more processors; one or more memories; and one or more computer programs, wherein the one or more computer programs are stored in the one or more memories, and the one or more computer programs include instructions, which, when executed by the one or more processors, enable the electronic device to perform the above method.
[0017] In a fourth aspect, the present application provides a computer-readable storage medium, in which a program or instruction is stored. When the program or instruction is executed, the above method is implemented.
[0018] By adopting the above technical solution, the pre-prepared knowledge in a specific field, such as facts, concepts or rules, is stored in the knowledge graph in the form of entity triples, and a text embedding vector is assigned to each entity triple. When a user asks a relevant question, the preset question text input by the user is first converted into a corresponding question vector, and similar feature vectors related to it are screened out in the preset knowledge graph based on the question vector, thereby obtaining a knowledge text group related to it. Then, these knowledge text groups and the question text input by the user are input into the preset language model together, and the model answers the question according to the knowledge text group and generates a reply text. After the reply text is generated, the preset knowledge graph is used to match and verify the reply text, and the preset language model is continuously optimized by comparing the verification results, so that it is more accurate and reliable when dealing with problems in specific fields.
[0019] In summary, the present application has at least one of the following beneficial effects: 1. Prepare relevant knowledge in specific fields in advance through knowledge graphs, screen and process the question text input by users based on the knowledge graph, obtain a knowledge text group related to the question text, and answer the question based on the obtained knowledge text group, thereby ensuring the model's knowledge reserve, improving the model's adaptability to specific fields and context understanding capabilities, and making the model more accurate and reliable when dealing with problems in specific fields.
[0020] 2. Perform matching verification on the reply text generated by the model based on the knowledge graph. For example, by matching and comparing the triples extracted from the reply text with the entity triples in the knowledge graph that serve as the basis for generating the reply text, it is possible to determine whether the model has accurately output the information conveyed by the entity triples. If there is a mismatch, error correction and optimization are performed to continuously verify and optimize the model performance, further strengthen the model's understanding of the knowledge graph, and improve the model's accuracy and reliability when dealing with problems in specific fields. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] Figure 1 It is a flowchart of the question-answering large language model optimization method provided in the embodiment of the present application; Figure 2 It is a schematic diagram of the structure of a preset knowledge graph obtained by the question-answering large language model optimization method provided in an embodiment of the present application; Figure 3 It is a virtual structural diagram of the question-answering large language model optimization device provided by the present application; Figure 4 It is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0022] The present application is further described below in conjunction with the accompanying drawings and embodiments.
[0023] The following will clearly and completely describe the concept, specific structure and technical effects of the present application in combination with the embodiments and drawings, so as to fully understand the purpose, characteristics and effects of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of them. Based on the embodiments of the present application, other embodiments obtained by technicians in this field without creative work are all within the scope of protection of the present application. In addition, all the connection / connection relationships involved in the patent do not simply refer to the direct connection of components, but refer to the formation of a better connection structure by adding or reducing connection accessories according to the specific implementation situation. The various technical features created in this application can be combined interactively without conflicting with each other.
[0024] The specific fields mentioned in this application are technical fields with their own unique knowledge systems and professional terms, which require specific knowledge and skills to understand and deal with related problems, including but not limited to the medical field, the financial field, the legal field, the educational field, the scientific field, the art field, etc. In the embodiments provided in this application, the medical field is used as an example for the convenience of explanation. This example is only for illustration and should not impose any limitation on the technical field to which the technical solution provided in this application is applied.
[0025] Reference Figure 1 , Figure 1 : is a flowchart of the question-answering large language model optimization method provided in the embodiment of the present application, which specifically includes the following steps, which are described in detail below: In step S1, a preset knowledge graph is obtained.
[0026] Among them, the preset knowledge graph includes multiple entity triples; one of the entity triples includes two node entities and relationship data representing the relationship between the two node entities.
[0027] Specifically, the preset knowledge graph is a pre-set graphical structure for representing knowledge, which is composed of multiple nodes and edges connecting every two nodes, wherein each node represents an entity, i.e., a node entity, and each edge represents the relationship between entities, i.e., relational data. For example, a node entity is "diabetes", another node entity is "blurred vision", and the relationship between the two entities can be "cause (causal relationship)".
[0028] More specifically, before obtaining the preset knowledge graph, the node entities in the knowledge graph and the relational data between each two node entities used to characterize the relationship between the two node entities have been pre-defined through relevant data sources. Among them, the relevant data sources include but are not limited to relevant literature, papers, news reports, etc. For example, the relationship between disease A and symptoms, drugs and efficacy, etc. are extracted from medical literature. For example, from the sentence "diabetes may cause blurred vision", the node entities "diabetes" and "blurred vision" can be extracted, as well as the relational data "leading to" that characterizes the relationship between the two node entities. Among them, the terms in the relational data such as "leading to" can be uniformly replaced with "symptoms" according to their semantics in the relevant data preprocessing and normalization processing.
[0029] In addition, it can also be manually added based on expert knowledge or business needs, thereby supplementing important information that may be missed by automatic extraction, correcting errors or inaccurate information in automatic extraction, and adding customized entities and relationships based on specific business scenarios.
[0030] More specifically, refer to Figure 2 , Figure 2 It is a structural diagram of the preset knowledge graph obtained by the question-answering language model optimization method provided in the embodiment of the present application. It includes multiple node entities and connecting edges between every two node entities. Each connecting edge corresponds to the relationship data between the two connected node entities. For example, the node entity "Disease A" and the node entity "Symptom A" are connected by an edge, and the connecting edge corresponds to the relationship data "Symptom", thereby forming an entity triple <Disease A, Symptom A, Symptom>, which expresses the meaning of "The symptom of Disease A is Symptom A"; for another example, the node entity "Disease A" and the node entity "Drug A" are connected by an edge, and the connecting edge corresponds to the relationship data "Recommended Medication", thereby forming another entity triple <Disease A, Drug A, Recommended Medication>, which expresses the meaning of "The recommended medication for Disease A is Drug A". It can be seen that through the entity triples of the above examples, a Figure 2 The knowledge graph structure shown.
[0031] More specifically, taking the preset knowledge graph obtained in the embodiment of the present application as an example, the treatment methods corresponding to each node entity "Disease A" may include multiple treatment options, and there are multiple options for drugs, food and even related surgeries. Based on this, in the preset knowledge graph, for each connecting edge, in addition to the relationship data of the two node entities connected to it, the relationship data also includes the corresponding text weight, so that the subsequent preset language model can select the entity triple with a higher text weight as the output result based on the text weight.
[0032] Furthermore, before obtaining the preset knowledge graph, the preset knowledge graph uses the existing knowledge graph that has been constructed, or extracts information from a data source with a large amount of knowledge for independent construction, which specifically includes the following steps: The data source is retrieved to extract all of the node entities and all of the relationship data.
[0033] Specifically, all node entities and relationship data are extracted from different data sources involving corresponding domain knowledge, and all relevant information is collected for subsequent integration processing. For example, in the medical field, information about disease A, symptoms, drugs, and their relationships can be extracted from sources such as medical literature, electronic medical records, and clinical trial data, and disease A, symptoms, and drugs can be used as node entities to be formed, and information about their relationships can be stored as relationship data to be formed.
[0034] Furthermore, standardization processing is performed on all the node entities and all the relationship data, and the relationship data corresponding to each two node entities are determined based on all the node entities and all the relationship data after the standardization processing.
[0035] Specifically, all node entities and all relationship entities obtained in the above steps are standardized, and the standardization process includes but is not limited to cleaning, conversion and normalization, such as removing duplicates, correcting errors, unifying naming conventions and other operations to ensure data consistency. For example, in the standardization process, different expressions of the same disease in different sources can be unified into a standard name, or data in different formats can be converted into a unified format. Then, based on the standardized data, the specific relationship between each two node entities is identified, and the relationship data representing the two node entities is clearly characterized through semantic recognition and other methods based on the extracted source text of the two node entities, which can be saved in a combined form for subsequent calls.
[0036] The two node entities with corresponding relationship data and the corresponding relationship data are taken as an entity triple to obtain multiple entity triples, and the preset knowledge graph is constructed based on all the entity triples.
[0037] Specifically, two node entities with a clear relationship and their relationship are combined into an entity triple. Each entity triple is composed of the format of 〈node entity 1, node entity 2, relationship data〉, which represents a specific semantic relationship. For example, 〈Disease A, Symptom A, Symptom〉 is an entity triple, which means "the symptom of disease A is symptom A". In the knowledge graph to be constructed, node entity 1 "Disease A", node entity 2 "Symptom A" and a connecting edge connecting these two node entities are formed, and the meaning assigned to the connecting edge is "symptom".
[0038] More specifically, the relevant knowledge for "Disease A" may also include multiple associations such as treatment departments, recommended medications, and food taboos. These knowledge will also form entity triples through the above method to gradually improve the knowledge graph about "Disease A". For example, from the text "The recommended medication for Disease A is Drug A", the entity triple <Disease A, Drug A, Recommended Medication> can be extracted, matched, and combined. Since the node entity "Disease A" already exists in the knowledge graph, in this case, it is only necessary to generate the node entity "Drug A" in the knowledge graph and add a connection edge with the relationship data of "Recommended Medication" to connect the node entity "Disease" and the node entity "Drug". Repeat the above steps to integrate all entity triples and finally form a complete knowledge graph.
[0039] In step S2, a text embedding vector corresponding to each entity triple is determined according to the two node entities and the relationship data in the same entity triple.
[0040] Specifically, the text embedding vector corresponding to the entity triple refers to the conversion of the two node entities and the relationship data in the entity triple into a numerical representation that is easy for the model to understand. Specifically, taking the entity triple 〈Disease A, Symptom A, Symptom〉 as an example, "Disease A" is the head node entity, "Symptom A" is the tail node entity, and "Symptom" is the relationship data between the head node entity and the tail node entity. Through the text embedding vector, this entity triple can be converted into a series of numerical vectors, which can reflect the causal relationship between "Symptom" and "Symptom A".
[0041] Specifically, when the knowledge graph is standardized, each node entity and each relationship data can be encoded to generate an embedding vector for the words corresponding to each node entity and each relationship data, so that the entity and relationship vectors can be fused when forming an entity triple to form a single vector that can represent the entire entity triple, and the text embedding vector corresponding to the entity triple can be obtained based on the embedding vector of the words in the group.
[0042] In step S3, a question vector is determined based on a preset question text, and all the text embedding vectors are screened to obtain a similar feature vector corresponding to the question vector.
[0043] Specifically, after the user inputs a preset question text in the relevant device, the preset question text is first converted into a numerical vector that is easy for the model to understand as a question vector, and then based on the question vector, the text embedding vectors obtained in the above steps are screened out that are semantically more closely related to the question vector as similar feature vectors.
[0044] More specifically, the step of screening all the text embedding vectors to obtain similar feature vectors corresponding to the question vector may include: A similarity calculation is performed on each of the text embedding vectors and the question vector to determine the similarity between each of the text embedding vectors and the question vector.
[0045] Specifically, the similarity between the question vector and each text embedding vector is calculated, where the similarity is calculated using a method including but not limited to cosine similarity, Euclidean distance, Manhattan distance, and other measurement methods, and the specific selection depends on the application scenario and data characteristics.
[0046] Furthermore, all the text embedding vectors are sorted from high to low based on the similarity, and a preset number of text embedding vectors ranked first are used as similar feature vectors.
[0047] Specifically, according to the similarity calculated in the above steps, all text embedding vectors are sorted in descending order, that is, the vectors with higher similarity are ranked first, and then the first preset number of text embedding vectors are taken as similar feature vectors corresponding to the question vector. The preset number is k, and k is a positive integer greater than or equal to 1. Generally speaking, the more precise the result is, the smaller the value of k can be set accordingly, and the more comprehensive the result is, the larger the value of k can be set accordingly.
[0048] More specifically, in addition to obtaining similar feature vectors of the question text through the above-mentioned screening and sorting methods, a similarity threshold can also be set. After calculating the similarity of each text embedding vector corresponding to the question vector, only the text embedding vectors exceeding the similarity threshold are retained, and the retained text embedding vectors are used as similar feature vectors corresponding to the question vector, thereby avoiding that low-similarity text embedding vectors are used as input data and affect the output results due to their high ranking.
[0049] More specifically, the screening of similar feature vectors can be combined with the above-mentioned similarity ranking and similarity threshold judgment method to further improve the accuracy. Specifically, only text embedding vectors that simultaneously meet the similarity ranking in the first preset number and the similarity exceeds the similarity threshold will be used as similar feature vectors.
[0050] Through the above screening method, the system can effectively filter out the feature vectors most relevant to the question from a large number of text embedding vectors, provide high-quality input data for the subsequent question-answering system, improve processing efficiency, and ensure user experience.
[0051] In step S4, text conversion is performed on the similar feature vectors to obtain a knowledge text group, and the knowledge text group and the preset question text are input into a preset language model to obtain a reply text of the question text based on the knowledge text group through the preset language model.
[0052] Specifically, the screened similar feature vectors are converted back to natural language texts, that is, the knowledge text corresponding to each similar feature vector is obtained, and all the obtained knowledge texts together constitute a knowledge text group, which is used to be input into the preset language model together with the preset question text. Then, all the input texts are processed using the preset language model, and one or more possible answers are generated based on the content of the question text and the knowledge text group. Among them, the similar feature text based on which the reply text is generated can be determined based on the text weight corresponding to the similar feature text.
[0053] Specifically, in one embodiment provided in the present application, the step of obtaining the answer text of the question text based on the knowledge text group includes: The text weight corresponding to each of the knowledge texts in the knowledge text group is obtained based on the preset knowledge graph.
[0054] Specifically, in the preset knowledge text, the two node entities in each entity triple are connected by a connection edge assigned with relational data representing their relationship, and the relational data assigned on the connection edge also includes the text weight of the connection edge. In the steps of vector conversion, its text weight is gradually retained as the text weight corresponding to each knowledge text, that is, the relational data in each entity triple includes the text weight used to determine the text weight of the knowledge text corresponding to the entity triple. In this step, each knowledge text and its corresponding text weight are matched one by one to facilitate the subsequent combination and processing of data.
[0055] Furthermore, the knowledge text, the text weight corresponding to the knowledge text, and the preset question text are associated and recorded as a question-answer association group.
[0056] Specifically, each set of text weights is associated with the input preset question text to provide a unit-based input division for the preset language model. Specifically, each knowledge text, the text weight corresponding to the knowledge text, and the preset question text are divided into an input unit, so that the preset language model can answer the preset question text in combination with the knowledge text and its corresponding text weight, thereby avoiding the situation where the preset language model processes a large amount of data in a unified manner, resulting in a slow model processing speed or confusing data.
[0057] Furthermore, all the question-answer association groups are input into the preset language model, so as to generate a reply text corresponding to the preset question text based on each of the question-answer association groups through the preset language model.
[0058] Specifically, after receiving the multiple question-answer association groups, the preset language model determines the importance of the corresponding knowledge text based on the text weight in each question-answer association group, and gives more emphasis when generating the reply text. The text weight in each question-answer association group is determined by the text weight corresponding to the relationship data in the entity triplet on which it is based.
[0059] More specifically, as knowledge and technology in a specific field continue to develop, fixed knowledge graphs that cannot be dynamically updated cannot keep up with the latest developments in the field, resulting in the information provided by related systems and decision support tools no longer being the latest or optimal. Taking the medical field as an example, it is necessary to ensure that medical knowledge graphs can be dynamically updated based on the latest medical data, thereby improving the service quality and accuracy of models based on these knowledge graphs. Based on this, an embodiment of the present application also provides a knowledge graph update method, which specifically includes the following steps: Get updated data.
[0060] Wherein, one of the update data includes two node entities to be verified.
[0061] Specifically, the system obtains the latest data from external data sources, and focuses on the updated data of the data sources that have been extracted, so as to obtain updated data. The updated data may contain new information, such as new drug discoveries, disease symptom updates, etc. Then, the updated data is extracted and parsed to obtain two node entities to be verified in the updated data. For example, assuming that the meaning of the updated data obtained based on the data source is "long-term high blood pressure may increase the risk of heart disease", the two node entities to be verified extracted based on the updated data are "hypertension" and "heart disease".
[0062] More specifically, in order to facilitate the subsequent updating of the meaning represented by the updated data to the preset knowledge graph, data preprocessing should be performed in the process of extracting the two node entities to be verified in the updated data, so as to improve the matching accuracy of the existing node entities in the preset knowledge graph in the subsequent steps.
[0063] Furthermore, it is determined whether there is a matching triple corresponding to the updated data in the preset knowledge graph.
[0064] The matching triplet is an entity triplet in which two of the node entities match two of the node entities to be verified.
[0065] Specifically, if the two node entities to be verified obtained by the analysis are both corresponding to the two node entities and the relationship data in the original entity triple, the original entity triple is determined to be a matching triple, indicating that the information disclosed by the matching triple is valid. For example, if the node entities to be verified according to the updated data are "hypertension" and "heart disease", and there is an entity triple in the original preset knowledge graph that contains two node entities "hypertension" and "heart disease", then the entity triple is determined to be the matching triple corresponding to the updated data.
[0066] Furthermore, if the matching triple exists, the text weight corresponding to the relational data in the matching triple is adjusted, and the adjusted matching triple is updated to the preset knowledge graph.
[0067] Specifically, if it is determined through the above steps that there is a matching triple in the original entity triple that corresponds to the new entity triple, it means that the information involved in the original matching triple is further confirmed, and the text weight corresponding to the relationship data in the matching triple can be improved so that it can get more emphasis in the reply text. Then, the matching triple with adjusted text weight is synchronously updated to the preset knowledge graph for subsequent use.
[0068] Furthermore, since the update data is collected periodically, and the collected update data may be hundreds, thousands, or even tens of thousands. Therefore, the number of matching triples can be determined based on the collected update data, and the text weight of the matching triple in the preset knowledge graph can be increased based on the number of matching triples. For example, if the total number of update data is 1000, and the update data corresponding to the matching triple is 100, then 1 is accumulated based on the text weight corresponding to the matching triple.
[0069] Furthermore, if two entities are parsed from the updated data, and these two entities exist in the preset knowledge graph, but the updated data indicates that the two entities are no longer compatible. For example, a certain treatment method is not as effective as before for a certain disease, and a better treatment method has been substituted. In this case, reduce the text weights corresponding to the two entities contained in the preset knowledge graph, or delete the two entities and the relationship edges connecting the two entities.
[0070] More specifically, the text semantics in the data source corresponding to the new entity triple can also be identified in combination with the context to further determine the validity of the matching triple. For example, if the new entity triple and the matching triple are both <Disease A, Drug A, Recommended Medication>, but the updated data can be combined with semantics to determine that "Disease A recommends the use of Drug A but the effect is not good", in this case the text weight corresponding to the relational data in the matching triple should be lowered; conversely, if it can be determined based on semantics that "Disease A recommends the use of Drug A but the effect is very good", the corresponding text weight can be increased. Immediately, the matching triple with the text weight adjustment completed is updated to the preset knowledge graph.
[0071] Otherwise, if the matching triple does not exist, an updated triple is constructed based on the updated data and the preset initial weight, and the updated triple is updated to the preset knowledge graph as a new entity triple.
[0072] Specifically, if there is no matching triple corresponding to the new entity triple in all entity triples included in the preset knowledge graph before the update, the system will determine the relationship between the two node entities to be verified based on the semantics of the corresponding update data, and determine the relationship data corresponding to the two node entities to be verified based on the preset initial weights and the relationship between the two node entities to be verified. Then, based on the relationship data corresponding to the two node entities to be verified, an updated triple consistent with the entity triple format in the preset knowledge graph is constructed, and the updated triple is added to the knowledge graph as an independent new entry, that is, a node entity that did not exist before is generated in the preset knowledge graph (there is no need to generate the node entity that already existed), a connection edge connecting the newly generated node entity is generated, and the connection edge is assigned the relationship data corresponding to the two newly generated node entities.
[0073] For example, from the text "New drug X can effectively treat disease Y", the system identifies the node entities "drug X" and "disease Y" to be verified respectively. After matching, it is determined that there is no entity triple matching "drug X" and "disease Y" in the preset knowledge graph. In this case, the relationship "recommended medication" between the two node entities to be verified is determined based on the text semantics, and the relationship is combined with the preset text weight (for example, 1) to obtain new relationship data. The two node entities to be verified and their corresponding new relationship data are combined to form an updated triple <disease Y, drug X, recommended medication> that is consistent with the entity triple format in the preset knowledge graph. Assuming that there is only the node entity "disease Y" in the original preset knowledge graph, a new node entity "drug X" is generated in the preset knowledge graph, and "disease Y" and "drug X" are connected by a connecting line assigned with new relationship data (text weight is 1, relationship is "recommended medication") to complete the update of the preset knowledge graph, that is, the step of updating the updated triple as a new entity triple to the preset knowledge graph is completed.
[0074] More specifically, in this step, in order to ensure the feasibility of the generated reply text, the generated reply text can be polished, such as removing irrelevant information, adjusting the tone and style, etc., to ensure the quality and applicability of the reply text and improve the user experience.
[0075] In step S5, the reply text is matched and verified based on the preset knowledge graph, and the preset language model is optimized according to the obtained verification result.
[0076] Specifically, after generating the reply text, the preset knowledge graph is used to match and verify the reply text, and the preset language model is continuously optimized by comparing the verification results. Specifically, a reply text triple can be extracted based on the reply text, and the reply text triple can be matched with the entity triple in the preset knowledge graph to determine whether the generation basis of the reply text deviates from the information provided by the preset knowledge graph.
[0077] More specifically, in the embodiment provided in the present application, the step of performing matching verification on the reply text based on the preset knowledge graph and optimizing the preset language model according to the obtained verification result includes: The reply text is input into a preset information extraction model to extract the reply text through the preset information extraction model to obtain a reply text triple.
[0078] Among them, one of the reply text triples includes two node entities and relational data representing the relationship between the two node entities.
[0079] Specifically, the reply text generated by the preset language model is input into a preset information extraction model that is additionally trained. The preset information extraction model can be trained using a large language model as a base, and is used to extract the reply text to obtain a reply text triple corresponding to the above entity triple format, that is, the format of the reply text triple can be <node entity 1, node entity 2, relationship data>. The relationship data includes the text weight of the text segment in the entire text.
[0080] More specifically, in an embodiment provided by the present application, the step of inputting the reply text into a preset information extraction model to extract the reply text through the preset information extraction model to obtain a reply text triple includes: Get the preset prompt information.
[0081] The preset prompt information includes example text data, example triples corresponding to the example text data, and example requirement information.
[0082] Specifically, the preset prompt information is used to deepen the preset information extraction model's understanding of the task to be processed, which includes example text data, example triples corresponding to the example text data, and example requirement information. Among them, the example text data refers to the exemplary original text to be extracted and processed, and the example triples refer to the exemplary triples obtained based on the corresponding extracted keywords of the example text data. In order to facilitate the correspondence with the entity triples in the preset knowledge graph, the format of the exemplary triples should be consistent with the composition format of the entity triples. It is worth noting that in order to prevent the preset information extraction model from understanding the exemplary content as a task item to be processed, specific tags can be used to distinguish the exemplary content. For example, the 〈example〉 and 〈 / example〉 tags can be used to indicate the beginning and end of the example, as follows: The following is an example, marked by 〈example〉 and 〈 / example〉 to indicate the start and end of the example.
[0083] <example> Example text data XXX, the triple extracted based on the example text data is <node entity 1, node entity 2, relationship data> < / example> More specifically, the example requirement information refers to the guiding words of the output result requirement after the preset information extraction model processes the data set, including but not limited to the extracted processing items, keyword arrangement order, format, etc. For ease of understanding, an example requirement information implementation example is provided in the present application: extract triples from the reply text, the triples include node entity 1, node entity 2, and relationship data, and the elements in the generated triples are arranged in order, and the elements are separated by commas. For the medical field, node entity 1 can be further set as a node entity representing "disease", and other node entities can be set as node entity 2.
[0084] Furthermore, the reply text and the preset prompt information are input into the preset information extraction model so as to extract element groups from the reply text based on the example text data and the example triples through the preset information extraction model.
[0085] Wherein, one element group includes two node entities and one relationship data.
[0086] Specifically, the reply text and the preset prompt information are input into the preset information extraction model together, so as to deepen the preset information extraction model's understanding of the matters to be processed in the input reply text through the data processing examples provided by the preset prompt information, wherein the data processing examples refer to the examples adjusted from the above-mentioned example text data to the above-mentioned example triples. Then, the preset information extraction model fine-tuned by the preset prompt words processes the text data of the reply text and extracts an element group, namely, two node entities and relationship data representing the relationship between the two node entities.
[0087] Furthermore, the node entities and relationship data corresponding to each of the element groups are integrated into the reply text triples according to the example requirement information through the preset information extraction model and then output.
[0088] Specifically, through the preset information extraction model, in the text corresponding to the obtained element group, node entity 1, node entity 2 and relationship data are combined based on the above-mentioned example demand information to obtain the reply text triple and output it.
[0089] For example, the example requirement information may be "extracting triples from the reply text, the triples including node entity 1, node entity 2, and relational data used to characterize the relationship between node entity 1 and node entity 2, and the elements in the generated triples are arranged in order and separated by commas"; A data processing example may be "〈example〉 example text data: Diabetes may cause blurred vision; the triple extracted based on the example text data is 〈diabetes, blurred vision, symptoms〉", that is, through the example demand information, the preset language model can clearly understand the user's demand for the output result, and then deepen the preset language model's understanding of node entity 1, node entity 2 and relationship data through the processing example formed by the example text data and the example triplet. Based on the understanding of the above preset prompt information, the reply text is extracted to obtain the reply text triplet.
[0090] Further, among all the entity triples, the associated triples corresponding to the reply text triples are matched.
[0091] Among them, the associated triple is an entity triple whose node entity and relationship data are the same as a node entity and relationship data in the reply text triple.
[0092] Specifically, after obtaining the reply text triple, the associated triple corresponding to the reply text triple is matched in all entity triples of the preset knowledge graph, wherein the associated triple refers to an entity triple that has at least one node entity and the same relationship data as the reply text triple. For example, if the extracted reply text triple includes the node entity "Disease A", the node entity "Drug A" and the relationship data "Recommended Medication", then the entity triple 〈Disease A, Drug A, Recommended Medication〉 and the entity triple 〈Disease A, Drug B, Recommended Medication〉 in the preset knowledge graph can both be confirmed as the associated triple of the reply text triple because they both have the node entity "Disease A" and the relationship data "Recommended Medication".
[0093] Furthermore, all the associated triples are sorted from high to low based on the text weight corresponding to each of the associated triples, and the associated triplet with the highest sorting is used as the target triplet.
[0094] Specifically, the text weights corresponding to all the associated triples are sorted, and the sorting result is obtained according to the descending order, wherein the associated triple with the highest text weight is the associated triple with the highest text weight, which is then used as the target triple. Under normal circumstances, the preset language model should generate the reply text based on the target triple with the highest text weight among the associated triples.
[0095] Further, it is determined whether the two node entities and the relationship data of the target triplet overlap with the two node entities and the relationship data of the target triplet.
[0096] Specifically, the node entities and relationship data in the target triplet are compared one by one with the node entities and relationship data in the reply text triplet to determine whether the target triplet and the reply text triplet completely overlap, thereby verifying whether there is a deviation between the reply text and the target triplet on which it is based, so as to verify the model performance of the preset language model.
[0097] Furthermore, if there is no overlap, the target triple and the preset question text are input into the preset language model to optimize the answer text corresponding to the preset question text output by the preset language model based on the target triple.
[0098] Specifically, if in the above judgment, the target triplet and the reply text triplet do not completely overlap, indicating that the preset language model has an understanding deviation in the process of generating the reply text. In this case, the preset question text and the target triplet are re-input into the preset language model together, so that the preset language model can understand that the question text should correspond to the target triplet, and regenerate the reply text based on the target triplet, thereby ensuring the accuracy of the reply text generation, and deepening the preset language model's understanding of the preset question text through feedback training, thereby further optimizing the model performance.
[0099] More specifically, in the process of re-inputting the preset question text and the target triplet into the preset language model to fine-tune the preset language model, there is no need to perform text conversion on the target triplet again, so that the preset language model records the reply text directly corresponding to the entity triplet, thereby saving text conversion and improving the processing speed of the preset language model. It also reduces the conversion steps to avoid possible deviations in the conversion process, thereby further optimizing the model performance.
[0100] In a specific implementation, the above-mentioned question-answering language model optimization method can be applied to digital humans in medical scenarios. Understandably, in order to facilitate serving patients, more and more hospitals have launched medical digital humans to provide patients with some simple medical question-answering services, such as some routine processes (registration, outpatient matching consultation), basic medication, etc. At this time, the question-answering language model optimization method in this application can be used to periodically update the digital humans in medical scenarios.
[0101] Reference Figure 3 , Figure 3 : is a virtual structural diagram of a large question-answering language model optimization device provided by the present application. The second aspect of the present application provides a large question-answering language model optimization device, including: The knowledge graph acquisition module 100 is used to acquire a preset knowledge graph; the preset knowledge graph includes a plurality of entity triples; one entity triple includes two node entities and relationship data representing the relationship between the two node entities; The embedding vector conversion module 200 is used to determine the text embedding vector corresponding to each entity triple according to the two node entities and the relationship data in the same entity triple; A similarity vector screening module 300 is used to determine a question vector based on a preset question text, and to screen all the text embedding vectors to obtain a similar feature vector corresponding to the question vector; A reply text output module 400 is used to perform text conversion on the similar feature vectors to obtain a knowledge text group, and input the knowledge text group and the preset question text into a preset language model to obtain a reply text of the question text based on the knowledge text group through the preset language model; The matching verification optimization module 500 is used to perform matching verification on the reply text based on the preset knowledge graph, and optimize the preset language model according to the obtained verification results.
[0102] The question-and-answer large language model optimization device described in the embodiment of the present application can execute the question-and-answer large language model optimization method provided in the above embodiment. The question-and-answer large language model optimization device has the corresponding functional steps and beneficial effects of the question-and-answer large language model optimization method described in the above embodiment. Please refer to the embodiment of the above-mentioned question-and-answer large language model optimization method for details. The embodiment of the present application will not be repeated here.
[0103] The present application also provides an electronic device. Figure 4 , Figure 4 It is a structural diagram of an electronic device provided in an embodiment of the present application, and the electronic device may include a processor and a memory, wherein the processor and the memory may be connected via a bus or other means. The processor may be a central processing unit (CPU). The processor may also be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components and other chips, or a combination of the above-mentioned various types of chips. The memory, as a non-transient computer-readable storage medium, can be used to store non-transient software programs, non-transient computer executable programs and modules, such as the program instructions / modules corresponding to the large language model optimization method for question and answer in the embodiment of the present application. The processor executes various functional applications and data processing of the processor by running the non-transient software programs, instructions and modules stored in the memory, that is, the large language model optimization method for question and answer in the above method embodiment is realized.
[0104] The memory may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required by at least one function; the data storage area may store data created by the processor, etc. In addition, the memory may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device. The one or more modules are stored in the memory, and when executed by the processor, the large language model optimization method for question and answer in the above method embodiment is executed. The specific details of the above electronic device can be understood by corresponding to the corresponding descriptions and effects in the above method embodiment, and will not be repeated here. Those skilled in the art can understand that all or part of the processes in the above embodiment method can be completed by instructing the relevant hardware through a computer program, and the program can be stored in a computer-readable storage medium, and the program, when executed, may include the processes of the embodiments of the above methods. Among them, the storage medium can be a read-only memory (ROM), a random access memory (RAM), a flash memory (Flash Memory), a hard disk drive (HDD) or a solid-state drive (SSD), etc.; the storage medium can also include a combination of the above types of memory.
[0105] In the description provided herein, a large number of specific details are described. However, it is understood that the embodiments of the present application can be practiced without these specific details. In some instances, well-known methods, structures and techniques are not shown in detail so as not to obscure the understanding of this description.
[0106] Similarly, it should be understood that in order to streamline the present disclosure and aid in understanding one or more of the various inventive aspects, in the above description of the exemplary embodiments of the present application, the various features of the present application are sometimes grouped together into a single embodiment, figure, or description thereof. However, this disclosed method should not be interpreted as reflecting the following intention: the claimed application requires more features than the features explicitly recited in each claim. More specifically, as reflected in the claims, the inventive aspects lie in less than all the features of the individual embodiments disclosed above. Therefore, the claims that follow the specific embodiment are hereby expressly incorporated into the specific embodiment, with each claim itself serving as a separate embodiment of the present application.
[0107] It should be noted that the above-mentioned embodiments illustrate rather than limit the invention and that those skilled in the art will be able to design alternative embodiments without departing from the scope of the appended claims.
Claims
1. A method for optimizing a large question-answering language model, characterized in that: The method comprises: Obtain a preset knowledge graph; the preset knowledge graph includes a plurality of entity triples; one of the entity triples includes two node entities and relational data representing the relationship between the two node entities; Determine a text embedding vector corresponding to each entity triple according to the two node entities and the relationship data in the same entity triple; Determine a question vector based on a preset question text, and screen all the text embedding vectors to obtain a similar feature vector corresponding to the question vector; Performing text conversion on the similar feature vectors to obtain a knowledge text group, inputting the knowledge text group and the preset question text into a preset language model, so as to obtain a reply text of the question text based on the knowledge text group through the preset language model; The reply text is matched and verified based on the preset knowledge graph, and the preset language model is optimized according to the obtained verification result.
2. The method for optimizing a large question-answering language model according to claim 1, characterized in that: The step of screening all the text embedding vectors to obtain similar feature vectors corresponding to the question vector comprises: Calculate the similarity between each of the text embedding vectors and the question vector to determine the similarity between each of the text embedding vectors and the question vector; All the text embedding vectors are sorted from high to low based on the similarity, and a preset number of text embedding vectors ranked first are used as similar feature vectors.
3. The method for optimizing a large question-answering language model according to claim 1, characterized in that: The step of obtaining the answer text of the question text based on the knowledge text group comprises: Obtaining a text weight corresponding to each of the knowledge texts in the knowledge text group based on the preset knowledge graph; Associating and recording the knowledge text, the text weight corresponding to the knowledge text, and the preset question text into a question-answer association group; All the question-answer association groups are input into the preset language model, so as to generate a reply text corresponding to the preset question text based on each of the question-answer association groups through the preset language model.
4. The method for optimizing a large question-answering language model according to claim 1, characterized in that: Determining the corresponding text weight based on the relationship data; the method further includes: Acquire update data; the update data includes two node entities to be verified; Determine whether there is a matching triple corresponding to the updated data in the preset knowledge graph, wherein the matching triple is an entity triple that matches the two node entities and the two node entities to be verified; If the matching triple exists, adjusting the text weight corresponding to the relational data in the matching triple, and updating the adjusted matching triple to the preset knowledge graph; If the matching triple does not exist, an updated triple is constructed based on the updated data and the preset initial weight, and the updated triple is updated to the preset knowledge graph as a new entity triple.
5. The method for optimizing a large question-answering language model according to claim 1, characterized in that: The step of matching and verifying the reply text based on the preset knowledge graph and optimizing the preset language model according to the obtained verification result includes: The reply text is input into a preset information extraction model to extract the reply text through the preset information extraction model to obtain a reply text triple; one reply text triple includes two node entities and relational data representing the relationship between the two node entities; Among all the entity triples, match the associated triple corresponding to the reply text triple; the associated triple is an entity triple whose node entity and relationship data are the same as a node entity and relationship data in the reply text triple; Sorting all the associated triples from high to low based on the text weight corresponding to each of the associated triples, and taking the top associated triple as the target triple; Determine whether two node entities and relationship data of the target triplet overlap with two node entities and relationship data of the target triplet; If they do not overlap, the target triple and the preset question text are input into the preset language model to optimize the answer text corresponding to the preset question text output by the preset language model based on the target triple.
6. The method for optimizing a large question-answering language model according to claim 5, characterized in that: The step of inputting the reply text into a preset information extraction model to extract the reply text through the preset information extraction model to obtain a reply text triple comprises: Acquire preset prompt information; the preset prompt information includes sample text data, sample triples corresponding to the sample text data, and sample requirement information; The reply text and the preset prompt information are input into the preset information extraction model, so as to extract an element group from the reply text based on the sample text data and the sample triples through the preset information extraction model; one element group includes two node entities and one relationship data; The preset information extraction model is used to integrate the node entities and relationship data corresponding to each element group into the reply text triples according to the example requirement information and then output.
7. The method for optimizing a large question-answering language model according to claim 1, characterized in that: The step of obtaining a preset knowledge graph includes: Retrieve the data source to extract all the node entities and all the relationship data; Performing standardization processing on all the node entities and all the relationship data, and determining the relationship data corresponding to every two of the node entities based on all the node entities and all the relationship data after the standardization processing; The two node entities with corresponding relationship data and the corresponding relationship data are taken as an entity triple to obtain multiple entity triples, and the preset knowledge graph is constructed based on all the entity triples.
8. A large language model optimization device for question answering, characterized in that: include: A knowledge graph acquisition module, used to acquire a preset knowledge graph; the preset knowledge graph includes a plurality of entity triples; one of the entity triples includes two node entities and relationship data representing the relationship between the two node entities; An embedding vector conversion module, used for determining a text embedding vector corresponding to each entity triple according to the two node entities and the relationship data in the same entity triple; A similarity vector screening module is used to determine a question vector based on a preset question text, and to screen all the text embedding vectors to obtain a similar feature vector corresponding to the question vector; A reply text output module, used for performing text conversion on the similar feature vectors to obtain a knowledge text group, inputting the knowledge text group and the preset question text into a preset language model, so as to obtain a reply text of the question text based on the knowledge text group through the preset language model; A matching verification optimization module is used to perform matching verification on the reply text based on the preset knowledge graph, and optimize the preset language model according to the obtained verification results.
9. An electronic device, characterized in that: include: one or more processors; one or more memories; and one or more computer programs, wherein the one or more computer programs are stored in the one or more memories, and the one or more computer programs include instructions, which, when executed by the one or more processors, cause the electronic device to perform the method as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The storage medium stores a program or an instruction, and when the program or the instruction is executed, the method according to any one of claims 1 to 7 is implemented.
Citation Information
Cited By
Request response method and device, electronic equipment and storage medium
CN120407755A
Request response method and apparatus, electronic device, and storage medium
CN120407755B