Question-answering model training method, answer generation method, device, equipment and medium
By generating a water conservancy knowledge map and fine-tuning the parameters of the large language model, combined with enhancing search and intention recognition models, the flexibility and accuracy of the Q&A system in the water conservancy field is solved, efficient and accurate answers to water conservancy problems are achieved, and multi-scene query and emergency decision-making are supported.
Patent Information
- Application Number
- CN202510713052.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-30
- Publication Date
- 2025-08-22
- Estimated Expiration
- 2045-05-30
AI Technical Summary
The question-and-answer system in the water conservancy field in the prior art is poor in flexibility and cannot handle user diversified expressions and complex semantic scenarios. In addition, large language models may fabricate objects or parameters when generating answers, resulting in doubt about the reliability of the results and it is difficult to meet the precise needs of specific professional scenarios.
By obtaining structured and unstructured databases in the field of water conservancy knowledge, a knowledge graph is generated, pre-trained large language models are trained, and the data set is fine-tuned through professional term question and answers, a second question and answer model is generated, and an enhanced search and intent recognition model is combined to generate answers.
It improves the accuracy of answering questions in the field of water conservancy knowledge, avoids the factual risks of large language models, improves the flexibility and accuracy of the question-and-answer system, and supports multi-scene water conservancy knowledge query and emergency decision-making.
Smart Images

Figure CN120234621B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of natural language processing technology, and in particular to a question-answering model training method, answer generation method, device, equipment and medium. Background Art
[0002] Professional knowledge in the field of water conservancy is highly dispersed and highly specialized. Its knowledge system covers multiple sub-fields such as hydrology, water conservancy engineering, water resources management, flood control and drought relief, and involves a large number of industry terms, technical specifications and dynamic data, such as real-time water level and flow monitoring information.
[0003] Existing question-answering systems are often based on fixed templates, whose response logic relies on predefined rules and keyword matching. These fixed sentence template question-answering systems lack flexibility, are unable to handle diverse user expressions, and struggle to cover complex semantic scenarios. On the other hand, large language models (such as GPT and Wenxin Yiyan) utilize massive amounts of pre-trained data to provide a certain level of semantic understanding and generation capabilities, enabling them to directly answer open-ended questions.
[0004] Existing large language models may fabricate objects or parameters when generating answers to questions in the water conservancy field, and may obtain different answers to multiple questions, resulting in questionable reliability of the results and making it difficult to meet the precise needs of specific professional scenarios. Summary of the Invention
[0005] The purpose of this application is to provide a question-answering model training method, answer generation method, device, equipment and medium, which can solve the problem of low answer accuracy in the existing technology for questions and answers in the water conservancy field.
[0006] To achieve the above objectives, this application provides the following solutions:
[0007] In a first aspect, the present application provides a question-answering model training method, comprising:
[0008] Acquire a structured database in the field of water conservancy knowledge, and generate a first knowledge graph based on the structured database;
[0009] Acquire an unstructured database in the field of water conservancy knowledge, and update the first knowledge graph to generate a second knowledge graph based on the unstructured database;
[0010] Training the pre-trained large language model according to the second knowledge graph, and obtaining the first question-answering model after the training is completed;
[0011] Obtain a professional terminology question-answer pair dataset, and fine-tune the parameters of the first question-answer model based on the professional terminology question-answer pair dataset to obtain a second question-answer model; the second question-answer model is used to process the obtained water conservancy knowledge field questions and generate a final answer.
[0012] Optionally, updating the first knowledge graph according to the unstructured database to generate a second knowledge graph includes:
[0013] Performing sentence segmentation processing on the text in the unstructured data to obtain a plurality of sentences, and performing preprocessing on the sentences to obtain a plurality of first text segments;
[0014] Identify the first text segment according to a pre-trained entity recognition model to obtain a first entity, and extract the first text segment including the first entity as a second text segment;
[0015] Performing relationship recognition on the second text segment according to a pre-trained entity relationship recognition model to obtain the relationship between the first entities;
[0016] Obtain first triple data based on the relationship between the first entities, traverse the nodes in the first knowledge graph relationship according to the query statement, and determine whether there is a relationship indicated by the first triple data in the first knowledge graph. If not, update the first knowledge graph according to the first triple to obtain a second knowledge graph.
[0017] In a second aspect, the present application provides an answer generation method, comprising:
[0018] Obtaining a user question, and searching a preset professional database to obtain a first answer based on the user question using an enhanced search generation method;
[0019] Determine whether the first answer exists; if the first answer exists, use the first answer as the final answer;
[0020] If the first answer does not exist, a second answer is obtained based on the pre-trained intent recognition model and the trained large language model, and the second answer is used as the final answer; wherein, the trained large language model is the second question-answering model obtained according to the above-mentioned question-answering model training method.
[0021] Optionally, the method of searching a preset professional database to obtain a first answer according to the user question using the enhanced search generation method includes:
[0022] Using a pre-trained text embedding model as a searcher of the enhanced retrieval generation method to process the user question to obtain an answer paragraph and related text of the answer paragraph; wherein the pre-trained text embedding model is a trained model obtained by training a preset text embedding model based on the preset professional database;
[0023] The trained large language model is used as a generator of the enhanced retrieval generation method to perform context generation on the answer paragraph based on the relevant text to obtain the first answer.
[0024] Optionally, obtain the final answer based on a pre-trained intent recognition model and a pre-trained large language model, including:
[0025] Processing the user question using the pre-trained intent recognition model to obtain the user intent;
[0026] The user question and user intention are input into a pre-trained large language model to obtain the final answer outputted.
[0027] Optionally, the method of using a pre-trained text embedding model as a searcher of the enhanced retrieval generation method to process the user question to obtain an answer paragraph and related text of the answer paragraph specifically includes:
[0028] Generate a FAISS vector database based on the preset professional database through a pre-trained text embedding model;
[0029] Preprocessing the user question using the pre-trained text embedding model to obtain a question vector and keywords, and searching the FAISS vector database based on the question vector to obtain at least one candidate paragraph;
[0030] The similarity between the candidate paragraph and the keyword is calculated by using the pre-trained text embedding model, and the candidate paragraph whose similarity is greater than a preset similarity is obtained as the answer paragraph.
[0031] Optionally, the determining whether the first answer exists specifically includes:
[0032] If the candidate paragraph exists with the similarity greater than the preset similarity, determining that the first answer exists;
[0033] If the candidate paragraphs whose similarity is greater than the preset similarity do not exist, it is determined that the first answer does not exist.
[0034] In a third aspect, the present application provides a question-answering model training device, comprising:
[0035] A first graph module is used to obtain a structured database in the field of water conservancy knowledge and generate a first knowledge graph based on the structured database;
[0036] A second graph module is used to obtain an unstructured database in the field of water conservancy knowledge, and update the first knowledge graph according to the unstructured database to generate a second knowledge graph;
[0037] A training module, configured to train the pre-trained large language model according to the second knowledge graph, and obtain the first question-answering model after the training is completed;
[0038] A fine-tuning module is used to obtain a professional terminology question-answer pair dataset, and fine-tune the parameters of the first question-answer model based on the professional terminology question-answer pair dataset to obtain a second question-answer model; the second question-answer model is used to process the acquired water conservancy knowledge field questions and generate a final answer.
[0039] In a fourth aspect, the present application provides an answer generation method and apparatus, comprising:
[0040] A first answer module is used to obtain a user question and search a preset professional database based on the user question to obtain a first answer through an enhanced search generation method;
[0041] A judgment module, configured to judge whether the first answer exists; if the first answer exists, taking the first answer as the final answer;
[0042] The second answer module is used to obtain a second answer based on the pre-trained intent recognition model and the trained large language model if the first answer does not exist, and use the second answer as the final answer; wherein the trained large language model is the second question-answering model obtained according to the above-mentioned question-answering model training method.
[0043] In a fifth aspect, the present application provides a computer device comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of any one of the above-mentioned question-answering model training methods or answer generation methods.
[0044] In a sixth aspect, the present application provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps of any one of the above-mentioned question-answering model training methods or answer generation methods are implemented.
[0045] In the seventh aspect, the present application provides a computer program product, including a computer program, which, when executed by a processor, implements the steps of any of the above-mentioned question-answering model training methods or answer generation methods.
[0046] According to the specific embodiments provided in this application, this application discloses the following technical effects:
[0047] The present application provides a question-answering model training method, answer generation method, device, equipment and medium. The question-answering model divides the knowledge data in the field of water conservancy knowledge into structured data and unstructured data, and generates or updates the knowledge graph through targeted methods for different data types to obtain a second knowledge graph, thereby improving the accuracy of the knowledge graph expression; the pre-trained large language model is trained according to the second knowledge graph to obtain a first question-answering model, and the parameters of the first question-answering model are fine-tuned through a professional terminology question-answering dataset to obtain a second question-answering model; the second question-answering model is used to complete the generation of answers to questions in the water conservancy field, which can avoid the factual risks of the large language model and improve the accuracy of answers to questions in the water conservancy knowledge field. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0049] Figure 1 This is a flowchart of a question-answering model training method in one embodiment of the present application;
[0050] Figure 2 for Figure 1 Detailed flow diagram of step 102;
[0051] Figure 3 A flowchart of a method for generating an answer according to an embodiment of the present application is provided;
[0052] Figure 4 for Figure 1 Detailed flow diagram of step 301;
[0053] Figure 5 The answer is output based on the large language model;
[0054] Figure 6 An answer output by an answer generation method provided in this application;
[0055] Figure 7 A schematic diagram of the functional modules of a question-answering model training device provided in one embodiment of the present application;
[0056] Figure 8 A schematic diagram of the functional modules of an answer generation device provided in one embodiment of the present application;
[0057] Figure 9 A schematic diagram of the structure of a computer device provided in one embodiment of the present application. DETAILED DESCRIPTION
[0058] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0059] In order to make the above-mentioned purposes, features and advantages of the present application more obvious and easy to understand, the present application is further described in detail below with reference to the accompanying drawings and specific implementation methods.
[0060] In an exemplary embodiment, Figure 1 As shown, a question-answering model training method is provided, which is executed by a computer device, specifically a computer device such as a terminal or a server, or a terminal and a server, and includes the following steps 101 to 104. Among them:
[0061] Step 101: Obtain a structured database in the field of water conservancy knowledge, and generate a first knowledge graph based on the structured database.
[0062] Specifically, the structured database includes several structured data tables, which are CSV (Comma-Separated Values) files that represent triples obtained from basic water conservancy data. Basic water conservancy data can be obtained from various sources such as literature, reports, and web pages.
[0063] Specifically, entity types and relationship types are defined based on table column headers. For example, each row represents an entity. Associations between specific columns can be defined as relationships.
[0064] Specifically, the first knowledge graph is generated by importing data from a CSV file using Neo4j.
[0065] Specifically, Neo4j is a high-performance graph database that uses the Property Graph Model to store data. It is suitable for processing highly connected data (such as social networks, recommendation systems, knowledge graphs, etc.). Neo4j uses the Cypher query language to perform data operations, such as creating nodes, querying nodes, querying relationships, and updating nodes and relationships.
[0066] Specifically, in the Knowledge Graph, the triple includes "Subject"-"Relation"-"Object", which is the basic element for constructing the Knowledge Graph. Together, they constitute a triple, which is used to represent the relationship between entities. The subject and object are both entities and are also nodes in the Knowledge Graph.
[0067] For example, in the triple (Yangtze River, originates from, Qinghai), "Yangtze River" is the "subject," representing the name of a river, a specific entity. "Originates from" is the "relationship," indicating the geographical relationship between "Yangtze River" and "Qinghai." "Qinghai" is the "object," representing another entity, the place where the source of the Yangtze River is located.
[0068] As an embodiment, the structured data table includes tangible information such as hydrological data, meteorological data, and water conservancy project data. These entities can be connected through geographical relationships, functional relationships, hierarchical management relationships, etc.
[0069] Furthermore, hydrological data includes relevant information such as water quantity, water quality, water level and precipitation of rivers, lakes and groundwater.
[0070] Furthermore, meteorological data includes information related to weather conditions, such as temperature, humidity, wind speed and direction data of a certain area, and other related information.
[0071] Furthermore, water conservancy project data includes information on the design, construction, and operational status of water conservancy infrastructure, such as reservoir or levee project data (capacity, water storage capacity, dam height, dam length, levee number, materials, maintenance status, etc.).
[0072] As another embodiment, the structured data table may also include water conservancy projects, geographical attributes, river basin organizations, personal events, etc. These entities may be connected through geographical relationships, functional relationships, hierarchical management relationships, etc.
[0073] Step 102: Train the pre-trained large language model according to the second knowledge graph, and obtain the first question-answering model after the training is completed.
[0074] Specifically, unstructured databases include but are not limited to hydrological data, engineering data, policies and regulations, and degree theses, journal articles and other text materials related to the water conservancy field.
[0075] Specifically, entity relationship recognition is performed on the unstructured database to obtain triple data, and the first indication graph is updated according to the triple database to obtain the second knowledge graph.
[0076] Step 103: Obtain a dataset of professional terminology question and answer pairs, and fine-tune the parameters of the first question and answer model based on the dataset of professional terminology question and answer pairs to obtain a second question and answer model; the second question and answer model is used to process the obtained water conservancy knowledge field questions and generate a final answer.
[0077] Optionally, select an open-source large language model from the ChatGLM (Chat Generative Language Model) series and train it based on the second knowledge graph.
[0078] For example, you can install PyTorch (an open source deep learning framework) and GLM dependency libraries in the created virtual environment, download the ChatGLM3-6B model from Hugging Face (a model training tool), and then run it locally.
[0079] Step 104: Obtain a dataset of professional terminology question and answer pairs, and fine-tune the parameters of the first question and answer model based on the dataset of professional terminology question and answer pairs to obtain a second question and answer model; the second question and answer model is used to process questions in a preset field and generate answers.
[0080] Specifically, the large language model can be fine-tuned using a fine-tuning dataset, which is a dataset of professional terminology questions and answers. Given the highly professional nature of data in the water conservancy field, the model needs to be fine-tuned to improve the accuracy of the model's questions and answers.
[0081] Specifically, Prompt Tuning technology can be used to fine-tune parameters. By optimizing the input prompt instead of modifying the model parameters, the performance of specific tasks can be improved, enabling the second question-answering model to better understand and respond to instructions in the water conservancy field.
[0082] Specifically, the professional terminology question-answer pair dataset includes several question-answer pairs of professional terminology questions and answers, and the question-answer pairs are in a "command-response" data structure.
[0083] For example:
[0084] The instruction is: "Explain the application principle of Manning's formula in river channel design, and explain the meaning and units of each parameter."
[0085] The response is: "The Manning Formula is the core formula for calculating the uniform flow velocity in an open channel. The expression is: ;
[0086] Where V is the average flow velocity in the open channel (unit: m / s or ft / s); n is the Manning roughness coefficient (dimensionless), which reflects the roughness of the channel wall; R is the hydraulic radius (unit: m or ft), R = A / P;
[0087] Where, A: cross-sectional area of water flow (unit: m² or ft²);
[0088] P: wetted perimeter (unit: m or ft), that is, the perimeter of the contact between the water flow and the channel wall;
[0089] S: hydraulic slope (dimensionless), usually equal to the channel bottom slope (for uniform flow)".
[0090] Furthermore, fine-tuning the parameters of the first question-answering model based on the professional terminology question-answering dataset can enhance its understanding of professional terminology and business logic and improve the accuracy of question-answering.
[0091] By implementing steps 101 to 104 above, the knowledge data in the water conservancy field is divided into structured and unstructured data. A knowledge graph is generated or updated using targeted methods for different data types to obtain a second knowledge graph, thereby improving the accuracy of the knowledge graph representation. A pre-trained large language model is trained based on the second knowledge graph to obtain a first question-answering model. The parameters of the first question-answering model are then fine-tuned using a dataset of professional terminology question-answering pairs to obtain a second question-answering model. This approach mitigates the factual risks of the large language model and improves the accuracy of responses to questions in the water conservancy field.
[0092] In addition, in order to further update the first knowledge graph, such as Figure 2 Step 102 can be replaced by steps 201 to 204, which specifically include:
[0093] Step 201 : Segment the text in the unstructured data to obtain a plurality of sentences, and pre-process the sentences to obtain a plurality of first text segments.
[0094] Specifically, sentence segmentation is performed according to punctuation marks, and each sentence is preprocessed, including steps such as removing stop words and extracting stems to obtain the first text segment.
[0095] Step 202: Identify the first text segment according to the pre-trained entity recognition model to obtain the first entity, and extract the first text segment including the first entity as the second text segment.
[0096] Optionally, the entity recognition model can be selected from one of the following: the BERT model (Bidirectional Encoder Representations from Transformers), the BiLSTM-CRF model (Bidirectional Long Short-Term Memory-Conditional Random Field), and the ELMo model (Embeddings from Language Models).
[0097] Step 203: Perform relationship recognition on the second text segment according to the pre-trained entity relationship recognition model to obtain the relationship between the first entities.
[0098] Optionally, the entity relationship recognition model can select one of the Transformer architecture (self-attention architecture) based RoBERTa model (Robustly Optimized BERT Approach, robustly optimized BERT model), ALBERT model (ALite BERT, lightweight BERT model) and ELECTRA model (Efficiently Learning an Encoder that Classifies Token Replacements Accurately, replacement detection training task).
[0099] As a preferred embodiment, a pre-trained large language model is selected as the above-mentioned entity relationship recognition model.
[0100] Step 204: obtain the first triple data based on the relationship between the first entities, traverse the nodes in the first knowledge graph relationship according to the query statement, and determine whether there is a relationship indicated by the first triple data in the first knowledge graph. If not, update the first knowledge graph according to the first triple to obtain the second knowledge graph.
[0101] Specifically, Cypher is the query language of the Neo4j graph database, which can be used to query nodes, traverse the first triplet data, and query whether the node in the first graph contains the first entity in the first triplet. If the node does not exist, the graph is updated by reading the first triplet according to Neo4j.
[0102] If the node exists, check whether the relationship of the node in the first triplet exists in the first graph. If so, ignore it; if not, read the first triplet according to Neo4j to update the graph.
[0103] Furthermore, before step 204, the method further includes: performing conflict detection and duplication detection on entities and relationships in the first triple data according to the entities and relationships in the first graph, and fusing and disambiguating conflicts and duplications to obtain more distinct first triple data.
[0104] In an exemplary embodiment, Figure 3 As shown, the present application also provides an answer generation method, which is executed by a computer device, specifically, a computer device such as a terminal or a server, or a terminal and a server. In the embodiment of the present application, the method includes the following steps 301 to 303. Among them:
[0105] Step 301: Obtain a user question, and use an enhanced retrieval generation method to search a preset professional database based on the user question to obtain a final answer.
[0106] Specifically, Retrieval-Augmented Generation (RAG) is a method that combines information retrieval and text generation. It relies on a large language model and aims to improve the performance of the generation model by retrieving relevant information from a large document base.
[0107] As an optional implementation, the preset professional database includes text data corresponding to the above-mentioned structured database and text data in the above-mentioned unstructured database.
[0108] As another optional implementation, the preset professional database includes the above-mentioned second knowledge graph.
[0109] As an example, Figure 4 Step 301 specifically includes steps 401 to 402, which specifically include:
[0110] In step 401, a pre-trained text embedding model is used as a searcher of an enhanced retrieval generation method to obtain an answer paragraph; wherein the pre-trained text embedding model is a trained model obtained by training a preset text embedding model according to a preset professional database.
[0111] Optionally, the open source BAAI / bge-base-en-v1.5 language model (Beijing Academy of Artificial Intelligence / Bidirectional General Embedding-English, Version 1.5) is used as the default text embedding model and embedded in the second question-answering model.
[0112] The pre-trained text embedding model is a trained model obtained by training a preset text embedding model based on a preset professional database.
[0113] As an implementation method, a pre-trained text embedding model generates a FAISS vector database (Facebook AI Similarity Search) based on a preset professional database; pre-processes the user question to obtain a question vector and keywords, searches the FAISS vector database based on the question vector to obtain multiple candidate paragraphs; calculates the similarity between the candidate paragraphs and the keywords, and obtains candidate paragraphs with a similarity greater than a preset similarity as the answer paragraph.
[0114] In step 402, the trained large language model is used as a generator of the enhanced retrieval generation method to perform context generation on the answer paragraph based on the relevant text to obtain a first answer.
[0115] Specifically, the generator receives the relevant documents returned by the retriever as context and generates the final answer or response based on this context.
[0116] Step 302: Determine whether there is a first answer; if there is a first answer, use the first answer as the final answer.
[0117] Specifically, according to the enhanced retrieval generation method, there may be a situation where the first answer cannot be obtained, that is, there is no first answer. If there is a first answer, the first answer is used as the final answer; if not, step 303 is executed.
[0118] Furthermore, if in the above step 401 , the similarities corresponding to all candidate paragraphs are not greater than the preset similarity, it is determined that the first answer does not exist.
[0119] In step 303, if the first answer does not exist, a second answer is obtained based on the pre-trained intent recognition model and the trained large language model, and the second answer is used as the final answer; wherein the trained large language model is the second question-answering model obtained according to the above-mentioned question-answering model training method.
[0120] Specifically, the user question is processed through a pre-trained intent recognition model to obtain the user intent; the user question and user intent are input into the pre-trained large language model to obtain the final output answer.
[0121] Furthermore, after preprocessing the user question, including word segmentation, stop word removal, stem extraction, etc., to obtain a text segment, the text segment is input into a pre-trained intent recognition model to output the user intent.
[0122] Specifically, you can choose intent recognition models including but not limited to the BERT model (Bidirectional Encoder Representations from Transformers), the GRU-CRF model (Gated Recurrent Unit-Conditional Random Field), and the CNN+Tri-CRF model (Convolutional Neural Network+Trigram Conditional Random Field).
[0123] Furthermore, the intent of acquisition includes but is not limited to obtaining factual information, knowledge interpretation, real-time data, text creation, code writing, creative suggestions, route query, location search, etc.
[0124] Specifically, the LangChain framework (a multi-model integration framework) can be used to expand the model, integrate multiple models for calling, support calling external interface data for answers, and trigger defined workflows.
[0125] Figure 5 The answers generated by the existing large language model, Figure 6 To obtain the answer through this application method, Figure 5 and Figure 6 The specific place names in the code are coded. In order to facilitate the understanding of the context, different place names are marked with different letters. Figure 5 and Figure 6 , ask questions about "A underground reservoir", based on actual data, Figure 5 The answers in the questionnaire clearly contain fictitious parameters (such as reservoir capacity and water resources) and unclear data. Figure 6 The answers in the question indicate that this application is able to well understand the user's question intent, accurately retrieve the reservoir's geographical and characteristic data, and help users quickly obtain valid data. In summary, compared with the unmodified large language model, the method provided by this application achieves relatively accurate answers during the question-answering process and performs well in documents retrieved from the knowledge base.
[0126] Specifically, the answer generation method provided by this application has the following technical effects:
[0127] The aforementioned question-and-answer model training method is used to generate the final answer based on the trained large language model. During training, the knowledge data in the water conservancy field is divided into structured and unstructured data. A second knowledge graph is generated or updated using targeted methods for different data types, improving the accuracy of the knowledge graph representation. The pre-trained large language model is trained on the second knowledge graph to obtain the first question-and-answer model. The parameters of the first question-and-answer model are then fine-tuned using a dataset of professional terminology question-and-answer pairs to obtain the second question-and-answer model. This approach mitigates the factual risks of the large language model and improves the accuracy of answers to questions in the water conservancy field.
[0128] Relying on a trained large language model, the Retrieval-Augmented Generation (RAG) method combines the strengths of information retrieval and text generation to retrieve the final answer from a pre-set professional database. This method addresses the problem that traditional large language models rely on the statistical patterns of training data, which can generate false or fabricated information. It significantly improves the accuracy, timeliness, and controllability of large language models. Dynamic intent analysis improves answer accuracy and enhances the flexibility of the water conservancy knowledge graph, supporting multi-scenario water conservancy knowledge query and emergency decision-making.
[0129] As a supplement to the retrieval-augmented generation (RAG) method, the user intent obtained based on the pre-trained intent recognition model is more targeted at the water conservancy field, and can better correct the intent in the second question-answering model and combine it with user questions to obtain more targeted answer results.
[0130] In summary, the answer generation method provided in this application can better understand and respond to instructions in the water conservancy field, solve the two core problems faced by applications in the water conservancy field, namely "factual illusion" and "random bias", improve the accuracy of answers, and enhance the flexibility of water conservancy knowledge graph scenarios, while supporting multi-scenario water conservancy knowledge queries and emergency decision-making.
[0131] This application also provides an application scenario, which applies the above-mentioned question-answering model training method or answer generation method, specifically, a question-answering scenario in the field of water conservancy.
[0132] Based on the same inventive concept, the present application also provides a question-answering model training device for implementing the question-answering model training method described above. The solution to the problem provided by this device is similar to the solution described in the method described above. Therefore, the specific limitations in one or more of the following question-answering model training device embodiments can be found in the limitations of the question-answering model training method described above and will not be repeated here.
[0133] In an exemplary embodiment, Figure 7 As shown, a question-answering model training device is provided, comprising:
[0134] The first graph module is used to obtain a structured database in the field of water conservancy knowledge and generate a first knowledge graph based on the structured database.
[0135] The second graph module is used to obtain an unstructured database in the field of water conservancy knowledge, and update the first knowledge graph based on the unstructured database to generate a second knowledge graph.
[0136] The training module is used to train the pre-trained large language model based on the second knowledge graph, and obtain the first question-answering model after the training is completed.
[0137] The fine-tuning module is used to obtain a dataset of professional terminology question and answer pairs, and fine-tune the parameters of the first question and answer model based on the dataset of professional terminology question and answer pairs to obtain a second question and answer model; the second question and answer model is used to process the acquired water conservancy knowledge field questions and generate the final answer.
[0138] As an optional implementation, the second atlas module is specifically configured to:
[0139] Segmenting the text in the unstructured data to obtain a plurality of sentences, and preprocessing the sentences to obtain a plurality of first text segments;
[0140] Identify the first text segment according to the pre-trained entity recognition model to obtain the first entity, and extract the first text segment including the first entity as the second text segment;
[0141] Perform relationship recognition on the second text segment according to a pre-trained entity relationship recognition model to obtain the relationship between the first entities;
[0142] Obtain the first triple data based on the relationship between the first entities, traverse the nodes in the first knowledge graph relationship according to the query statement, and determine whether there is a relationship indicated by the first triple data in the first knowledge graph. If not, update the first knowledge graph according to the first triple to obtain the second knowledge graph.
[0143] Based on the same inventive concept, the present application also provides an answer generation device for implementing the aforementioned answer generation method. The solution provided by this device is similar to the solution described in the aforementioned method. Therefore, the specific limitations of one or more of the following answer generation device embodiments can be found in the above-mentioned limitations of the answer generation method and will not be further elaborated here.
[0144] In an exemplary embodiment, Figure 8 As shown, an answer generation device is provided, comprising:
[0145] The first answer module is used to obtain the user's question and search the preset professional database to obtain the first answer based on the user's question through the enhanced search generation method;
[0146] A judgment module is used to judge whether there is a first answer; if there is a first answer, the first answer is used as the final answer;
[0147] The second answer module is used to obtain a second answer based on the pre-trained intent recognition model and the trained large language model if the first answer does not exist, and use the second answer as the final answer; wherein the trained large language model is the second question-answering model obtained according to the above-mentioned question-answering model training method.
[0148] As an optional implementation, the first answering module is specifically configured to:
[0149] A pre-trained text embedding model is used as a searcher of the enhanced retrieval generation method to process the user question to obtain an answer paragraph and related text of the answer paragraph; wherein the pre-trained text embedding model is a trained model obtained by training a preset text embedding model based on a preset professional database;
[0150] The trained large language model is used as the generator of the enhanced retrieval generation method to generate the first answer based on the context of the answer paragraph according to the relevant text.
[0151] As an optional implementation, the second answering module is specifically configured to:
[0152] Use the pre-trained intent recognition model to process user questions and obtain user intent;
[0153] Input user questions and user intentions into the pre-trained large language model to obtain the final output answer.
[0154] As an optional implementation, the first answering module is further configured to:
[0155] Generate a FAISS vector database based on a preset professional database through a pre-trained text embedding model;
[0156] The pre-trained text embedding model is used to pre-process the user question to obtain the question vector and keywords. The question vector is then searched in the FAISS vector database to obtain at least one candidate paragraph.
[0157] The similarity between the candidate paragraphs and the keywords is calculated through the pre-trained text embedding model, and the candidate paragraphs with similarity greater than the preset similarity are obtained as the answer paragraphs.
[0158] As an optional implementation, the judgment module is specifically configured to:
[0159] If there is a candidate paragraph with a similarity greater than a preset similarity, it is determined that there is a first answer;
[0160] If there is no candidate paragraph with a similarity greater than the preset similarity, it is determined that there is no first answer.
[0161] In an exemplary embodiment, a computer device is provided. The computer device may be a server or a terminal. The internal structure diagram thereof may be as follows: Figure 9 As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, abbreviated as I / O) and a communication interface. The processor, memory and input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and computer program in the non-volatile storage medium. The database of the computer device is used for data. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a question-answering model training method or an answer generation method is implemented.
[0162] Those skilled in the art will understand that Figure 9 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than shown in the figure, or combine certain components, or have a different component arrangement.
[0163] In an exemplary embodiment, a computer device is further provided, including a memory and a processor. The memory stores a computer program, and the processor implements the steps in the above method embodiments when executing the computer program.
[0164] In an exemplary embodiment, a computer-readable storage medium is provided, storing a computer program. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.
[0165] In an exemplary embodiment, a computer program product is provided, including a computer program. When the computer program is executed by a processor, the steps in the above method embodiments are implemented.
[0166] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant regulations.
[0167] Those skilled in the art will appreciate that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program. The computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the above-mentioned embodiments. In particular, any reference to memory, database, or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM may be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM).
[0168] The databases involved in the various embodiments provided herein may include at least one of a relational database and a non-relational database. Non-relational databases may include, but are not limited to, distributed databases based on blockchains. The processors involved in the various embodiments provided herein may include, but are not limited to, general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic units, data processing logic units based on quantum computing, and the like.
[0169] The technical features of the above embodiments can be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0170] This document uses specific examples to illustrate the principles and implementation methods of this application. The description of the above examples is only intended to help understand the method and core concept of this application. At the same time, those skilled in the art will find that the specific implementation methods and application scopes may vary based on the concept of this application. In summary, the content of this specification should not be construed as limiting this application.
Claims
1. A question-answering model training method, characterized in that: The question-answering model training method includes: Acquire a structured database in the field of water conservancy knowledge, and generate a first knowledge graph based on the structured database; Segmenting the text in the unstructured data to obtain a plurality of sentences, and preprocessing the sentences to obtain a plurality of first text segments; Identify the first text segment according to a pre-trained entity recognition model to obtain a first entity, and extract the first text segment including the first entity as a second text segment; Performing relationship recognition on the second text segment according to a pre-trained entity relationship recognition model to obtain the relationship between the first entities; Acquire first triple data based on the relationship between the first entities, perform conflict detection and duplication detection on the entities and relationships in the first triple data based on the entities and relationships in the first knowledge graph, and fuse and disambiguate the conflicts and duplications to obtain updated first triple data; Traverse the nodes in the first knowledge graph relationship according to the query statement, determine whether there is a relationship indicated by the first triple data in the first knowledge graph, and if not, update the first knowledge graph according to the first triple data to obtain a second knowledge graph; Train the pre-trained large language model based on the second knowledge graph, and obtain the first question-answering model after the training is completed; A professional terminology question-answer pair dataset is obtained, and a second question-answer model is obtained by fine-tuning the parameters of the first question-answer model by optimizing input prompts based on the professional terminology question-answer pair dataset; the second question-answer model is used to process the acquired water conservancy knowledge field questions and generate a final answer, wherein the professional terminology question-answer pair dataset includes several question-answer pairs of professional terminology questions and answers, and the data structure of the question-answer pairs is a "command-response" data structure.
2. A method for generating an answer, characterized in that: The answer generation method comprises: Obtaining a user question, processing the user question using a pre-trained text embedding model as a searcher of the enhanced retrieval generation method to obtain an answer paragraph and related text of the answer paragraph; wherein the pre-trained text embedding model is a trained model obtained by training a preset text embedding model based on a preset professional database; wherein the preset professional database is a second knowledge graph; Using the trained large language model as a generator of the enhanced retrieval generation method to perform context generation on the answer paragraph according to the relevant text to obtain a first answer; Determine whether the first answer exists; if the first answer exists, use the first answer as the final answer; If the first answer does not exist, processing the user question using the pre-trained intent recognition model to obtain the user intent; inputting the user question and user intent into the pre-trained large language model to obtain a second answer as output, and using the second answer as the final answer; The trained large language model is obtained according to the following method: Acquire a structured database in the field of water conservancy knowledge, and generate a first knowledge graph based on the structured database; Segmenting the text in the unstructured data to obtain a plurality of sentences, and preprocessing the sentences to obtain a plurality of first text segments; Identify the first text segment according to a pre-trained entity recognition model to obtain a first entity, and extract the first text segment including the first entity as a second text segment; Performing relationship recognition on the second text segment according to a pre-trained entity relationship recognition model to obtain the relationship between the first entities; Acquire first triple data based on the relationship between the first entities, perform conflict detection and duplication detection on the entities and relationships in the first triple data based on the entities and relationships in the first knowledge graph, and fuse and disambiguate the conflicts and duplications to obtain updated first triple data; Traverse the nodes in the first knowledge graph relationship according to the query statement, determine whether there is a relationship indicated by the first triple data in the first knowledge graph, and if not, update the first knowledge graph according to the first triple data to obtain a second knowledge graph; Training the pre-trained large language model according to the second knowledge graph, and obtaining the first question-answering model after the training is completed; A professional terminology question-answer pair dataset is obtained, and a second question-answer model is obtained by fine-tuning the parameters of the first question-answer model by optimizing input prompts based on the professional terminology question-answer pair dataset; the second question-answer model is used to process the obtained water conservancy knowledge field questions and generate final answers, wherein the professional terminology question-answer pair dataset includes several question-answer pairs of professional terminology questions and answers, and the data structure of the question-answer pairs is a "command-response" data structure.
3. The answer generation method according to claim 2, characterized in that: The method of using the pre-trained text embedding model as a searcher of the enhanced retrieval generation method to process the user question to obtain the answer paragraph and the related text of the answer paragraph specifically includes: Generate a FAISS vector database based on the preset professional database through a pre-trained text embedding model; Preprocessing the user question using the pre-trained text embedding model to obtain a question vector and keywords, and searching the FAISS vector database based on the question vector to obtain at least one candidate paragraph; The similarity between the candidate paragraph and the keyword is calculated by using the pre-trained text embedding model, and the candidate paragraph whose similarity is greater than a preset similarity is obtained as the answer paragraph.
4. The answer generation method according to claim 3, characterized in that: The determining whether the first answer exists specifically includes: If the candidate paragraph exists with the similarity greater than the preset similarity, determining that the first answer exists; If the candidate paragraphs whose similarity is greater than the preset similarity do not exist, it is determined that the first answer does not exist.
5. An answer generation device, characterized in that: The answer generating device comprises: A first answer module is configured to obtain a user question and process the user question using a pre-trained text embedding model as a searcher of the enhanced retrieval generation method to obtain an answer paragraph and related text of the answer paragraph; wherein the pre-trained text embedding model is a trained model obtained by training a preset text embedding model based on a preset professional database; wherein the preset professional database is a second knowledge graph; Using the trained large language model as a generator of the enhanced retrieval generation method to perform context generation on the answer paragraph according to the relevant text to obtain a first answer; A judgment module, configured to judge whether the first answer exists; if the first answer exists, taking the first answer as the final answer; A second answer module is configured to, if the first answer does not exist, process the user question using the pre-trained intent recognition model to obtain the user intent; input the user question and user intent into the pre-trained large language model to obtain a second answer as output, and use the second answer as the final answer; The answer generation device also includes a question-answering model training device, and the question-answering model training device includes: A first graph module is used to obtain a structured database in the field of water conservancy knowledge and generate a first knowledge graph based on the structured database; The second atlas module is used to: Segmenting the text in the unstructured data to obtain a plurality of sentences, and preprocessing the sentences to obtain a plurality of first text segments; Identify the first text segment according to a pre-trained entity recognition model to obtain a first entity, and extract the first text segment including the first entity as a second text segment; Performing relationship recognition on the second text segment according to a pre-trained entity relationship recognition model to obtain the relationship between the first entities; Acquire first triple data based on the relationship between the first entities, perform conflict detection and duplication detection on the entities and relationships in the first triple data based on the entities and relationships in the first knowledge graph, and fuse and disambiguate the conflicts and duplications to obtain updated first triple data; Traverse the nodes in the first knowledge graph relationship according to the query statement, determine whether there is a relationship indicated by the first triple data in the first knowledge graph, and if not, update the first knowledge graph according to the first triple data to obtain a second knowledge graph; A training module, configured to train the pre-trained large language model according to the second knowledge graph, and obtain the first question-answering model after the training is completed; A fine-tuning module is used to obtain a professional terminology question-answer pair dataset, and to obtain a second question-answer model by fine-tuning the parameters of the first question-answer model by optimizing input prompts based on the professional terminology question-answer pair dataset; the second question-answer model is used to process the acquired water conservancy knowledge field questions and generate final answers, wherein the professional terminology question-answer pair dataset includes several question-answer pairs of professional terminology questions and answers, and the data structure of the question-answer pairs is a "command-response" data structure.
6. A computer device comprising: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of the question-answering model training method of claim 1 or the answer generation method of any one of claims 2-4.
7. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, it implements the steps of the question-answering model training method according to claim 1 or the answer generation method according to any one of claims 2-4.
Citation Information
Patent Citations
Knowledge graph construction method, knowledge graph query method, knowledge graph construction device, knowledge graph query device and related system
CN118152578A
Water conservancy knowledge intelligent question and answer method and device based on large model and medium
CN118535703A