Model training method, question and answer method and related device
By constructing prompt text to guide the machine learning model to select relevant documents from the reference document set to generate answer data, the problem of low training efficiency in question-answering tasks is solved, and the ability to train efficient and accurate question-answering models and process large-scale data is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-30
- Publication Date
- 2026-03-31
AI Technical Summary
Existing technologies are inefficient in question-answering tasks and struggle to adapt to the demands of large-scale data processing, impacting model training effectiveness and accuracy.
By acquiring a first sample dataset and a reference document set, prompt text is constructed to guide the machine learning model to select relevant documents from the reference document set and generate answer data. The machine learning model is then trained to improve training efficiency and accuracy.
It improves model training efficiency, enhances the accuracy of question answering tasks, and enables the model to adapt to the needs of large-scale data processing.
Smart Images

Figure CN121765035A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of machine learning technology, and in particular to a model training method and apparatus, a question answering method and apparatus, equipment, media and products. Background Technology
[0002] In the field of Natural Language Processing (NLP), question answering, as one of the core NLP tasks, involves users inputting questions into a question-answering model, which then retrieves the corresponding answer from numerous reference documents. The accuracy of the output answer highly depends on the training performance of the question-answering model, which in turn depends highly on the quality of the training data used to train the model. Therefore, how to obtain and utilize training data that maximizes the model's training effect has become a key issue in improving the accuracy of question-answering tasks.
[0003] In related technologies, the process typically involves technical personnel manually searching a vast reference document library for the answer sample that best matches each of many question samples. These question samples and their corresponding answer samples are then used as training data to train a machine learning model, thereby obtaining a question-answering model.
[0004] However, while this method can guarantee the accuracy of question-answering tasks, it has significant limitations in training efficiency and is difficult to adapt to the needs of large-scale data processing. Summary of the Invention
[0005] To address the aforementioned issues, this application provides a model training method, a question-answering method, and related apparatus, which can improve model training efficiency while ensuring the accuracy of question-answering tasks, and enable the trained model to adapt to large-scale data processing needs.
[0006] The embodiments of this application disclose the following technical solutions:
[0007] In view of the above, the first aspect of this application discloses a model training method, the method comprising:
[0008] Obtain a first sample dataset and a reference document set. The first sample dataset includes multiple first question data, which are text data. The reference document set is a collection of reference documents.
[0009] Based on the first sample dataset and the reference document set, a prompt text is constructed. The prompt text is used to prompt the machine learning model to select a reference document from the reference document set to reply to the first question data, and to generate first answer data to reply to the first question data.
[0010] The machine learning model is trained based on the prompt text to obtain a question-answering model.
[0011] A second aspect of this application discloses a question-and-answer method, the method comprising:
[0012] Get the questions to be answered;
[0013] The question-answering model determines the answer to the question to be answered, and the answer displays reference document information corresponding to the answer. The question-answering model is trained using the model training method described in the first aspect.
[0014] A third aspect of this application discloses a model training apparatus, the apparatus comprising: a set acquisition module, a text construction module, and a model training module;
[0015] The set acquisition module is used to acquire a first sample dataset and a reference document set. The first sample dataset includes multiple first question data, which are text data. The reference document set is a collection of reference documents.
[0016] The text construction module is used to construct prompt text based on the first sample dataset and the reference document set. The prompt text is used to prompt the machine learning model to select reference documents from the reference document set to reply to the first question data, and to generate first answer data to reply to the first question data.
[0017] The model training module is used to train the machine learning model based on the prompt text to obtain a question-answering model.
[0018] A fourth aspect of this application discloses a question-answering device, the device comprising: a question acquisition module and an answer output module;
[0019] The question acquisition module is used to acquire questions to be answered;
[0020] The answer output module is used to determine the answer corresponding to the question to be answered through a question-answering model. The answer displays reference document information corresponding to the answer. The question-answering model is trained by the model training method described in the first aspect.
[0021] A fifth aspect of this application discloses a computer device, the device comprising a processor and a memory:
[0022] The memory is used to store program code and transmit the program code to the processor;
[0023] The processor is configured to execute the steps of the model training method described in the first aspect, or the steps of the question-answering method described in the second aspect, according to the instructions in the program code.
[0024] The sixth aspect of this application discloses a computer-readable storage medium for storing program code for performing the steps of the model training method described in the first aspect, or the steps of the question-answering method described in the second aspect.
[0025] The seventh aspect of this application discloses a computer program product, including a computer program or instructions that, when executed by a computer device, implement the steps of the model training method described in the first aspect, or the steps of the question-answering method described in the second aspect.
[0026] Compared with the prior art, this application has the following beneficial effects:
[0027] This application discloses a model training method, a question-answering method, and related apparatus. The method first acquires a first sample dataset and a set of reference documents. Then, it constructs prompt text based on the first sample dataset and the set of reference documents. The prompt text guides the machine learning model to select relevant documents from the set of reference documents to answer a first question, and to generate a first answer to the first question. Finally, the machine learning model is trained based on the prompt text to obtain a question-answering model. Thus, the machine learning model is trained using a thought chain reinforcement method based on the prompt text, enabling it to learn how to select relevant reference documents from the set of reference documents based on a given question, extract key information, and generate an accurate answer. This improves the model's training efficiency, increases the accuracy of the question-answering task, and allows the trained model to adapt to large-scale data processing needs. Attached Figure Description
[0028] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0029] Figure 1 A schematic diagram of a question-answering task provided in an embodiment of this application;
[0030] Figure 2 A scenario architecture diagram of a model training method provided in this application embodiment;
[0031] Figure 3 A flowchart illustrating a model training method provided in this application embodiment;
[0032] Figure 4 A flowchart illustrating the second model training method provided in this application embodiment;
[0033] Figure 5 A schematic diagram illustrating the acquisition of prompt text provided in an embodiment of this application;
[0034] Figure 6A This is a diagram illustrating a type of prompt text;
[0035] Figure 6B A schematic diagram of a prompt text provided for an embodiment of this application;
[0036] Figure 7 A flowchart illustrating the third model training method provided in this application embodiment;
[0037] Figure 8 A schematic diagram illustrating an embodiment of this application for obtaining a training dataset;
[0038] Figure 9 A schematic diagram illustrating a differentially constructed second sample dataset provided in an embodiment of this application;
[0039] Figure 10 A flowchart illustrating a question-and-answer method provided in an embodiment of this application;
[0040] Figure 11 A schematic diagram of a model training device provided in an embodiment of this application;
[0041] Figure 12 A schematic diagram of a question-and-answer device provided in an embodiment of this application;
[0042] Figure 13 This is a schematic diagram of the structure of a terminal device provided in an embodiment of this application;
[0043] Figure 14 This is a schematic diagram of the structure of a server provided in an embodiment of this application. Detailed Implementation
[0044] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of the present application.
[0045] The terms “first,” “second,” “third,” “fourth,” etc. (if present) in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a particular order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms “comprising” and “having,” and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0046] First, the technical terms used in the embodiments of this application will be explained:
[0047] Natural Language Processing (NLP) studies the interaction between computers and human languages (such as Chinese and English), particularly how to enable computers to understand and generate human language in order to communicate with humans more effectively. The main tasks of NLP include question answering, text analysis, sentiment analysis, and text generation.
[0048] As described earlier, in related technologies, technicians typically manually search a vast reference document library for each question sample to find the answer sample with the highest matching degree. These question samples and their corresponding answer samples are then used as training data to train a machine learning model, thereby obtaining a question-answering model. However, although this method can guarantee the accuracy of question-answering tasks, it suffers from significant training inefficiency and limitations in adapting to the needs of large-scale data processing.
[0049] The inventors, through research, proposed a model training method, a question-answering method, and related apparatus. This method first acquires a first sample dataset and a set of reference documents. Then, based on the first sample dataset and the set of reference documents, a prompt text is constructed. This prompt text guides the machine learning model to select relevant documents from the set of reference documents to answer the first question, and to generate the first answer data for the first question. Finally, the machine learning model is trained based on the prompt text to obtain a question-answering model. Thus, the machine learning model is trained using a thought chain reinforcement method based on the prompt text, enabling it to learn how to select relevant reference documents from the set of reference documents based on a given question, extract key information, and generate an accurate answer. This improves the model's training efficiency, increases the accuracy of the question-answering task, and allows the trained model to adapt to large-scale data processing needs.
[0050] Next, the execution entity of the model training method provided in this application embodiment will be described in detail:
[0051] The execution entity of the model training method provided in this application embodiment can be a computer device with data processing capabilities, specifically a terminal device or a server. As examples, terminal devices may include, but are not limited to, mobile phones, desktop computers, tablet computers, laptops, handheld computers, intelligent voice interaction devices, smart home appliances, vehicle terminals, and aircraft. The server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers. Furthermore, the server can also be a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms. In addition, the model training method provided in this application embodiment can also be executed collaboratively by the terminal device and the server. The terminal and server can be directly or indirectly connected via wired or wireless communication, which is not limited herein. Therefore, this application embodiment does not limit the implementation entity of the technical solution of this application.
[0052] Next, the scenarios for the model training method provided in the embodiments of this application will be described in detail:
[0053] See Figure 1 This figure is a schematic diagram of a question-answering task provided in an embodiment of this application. Figure 1 In the process, the question-answering model first receives questions from users. For example, if a user enters "the five most worthwhile attractions in Qingzhou", the question-answering model will then initiate the question-answering process.
[0054] First, the question-answering model receives and parses the user's input question, identifying keywords related to the question. In this embodiment, keywords may include "Qingzhou," "most worthwhile to visit," and "attractions."
[0055] Secondly, the question-answering model retrieves the most relevant reference documents from a pre-built set of reference documents. These reference documents may come from online encyclopedias, travel websites, etc. In this embodiment, the question-answering model may retrieve multiple documents related to Qingzhou tourism as reference documents.
[0056] Subsequently, the question-answering model analyzes the retrieved reference documents and uses NLP technology to extract the answers that best match the question. Furthermore, the reference document numbers (such as [1][2][3][4], etc.) can be marked after certain sentences in the answer to allow users to trace the source of information. In this embodiment, the question-answering model can extract five famous scenic spots in Qingzhou, such as Yunmen Mountain, Tuoshan Mountain, Linglong Mountain, Yangtian Mountain, and Lanxi Valley, and organize them into a clear list of answers. The information about Linglong Mountain comes from a document at www.xxx.com, and the information about Yangtian Mountain comes from a document at www.yyy.com.
[0057] Finally, the question-answering model presents the generated answers in a user-friendly manner. In this example, the user will see a list of five of the most worthwhile attractions in Qingzhou, each accompanied by a brief description and possible location information.
[0058] Therefore, users not only receive answers to their questions but also understand the source of those answers, increasing their credibility. For scenarios requiring further research or verification, users can directly access these reference documents for more detailed information.
[0059] See Figure 2 This figure is a scenario architecture diagram of a model training method provided in an embodiment of this application, including a computer device 100. The computer device 100 can be one of the various types of terminal devices or servers described above. Specifically, the following embodiments use computer device 100 as server A for illustrative purposes.
[0060] Server A is used to acquire the first sample dataset and the reference document set. The first sample dataset contains multiple first question data, each of which is text data. The reference document set is a collection of reference documents that provide rich background information and possible answer sources for the first question data, helping the trained question-answering model to more comprehensively understand the question and generate accurate answers. It is understood that the first sample dataset and the reference document set need to correspond, ensuring that each first question data has one or more corresponding reference documents. This can improve the accuracy when generating first answer data, as each first answer data is generated based on real and relevant reference documents.
[0061] Server A is also used to construct prompt text based on the first sample dataset and the reference document set. The prompt text guides the machine learning model to select one or more reference documents from the reference document set that are most relevant to the user's question, and to generate an answer to the user's question.
[0062] Server A is also used to train a machine learning model based on the prompt text to obtain a question-answering model.
[0063] Understandably, by training a machine learning model, it learns how to find the corresponding reference documents from the reference document set based on the first question data, and how to generate the first answer data to accurately answer the first question data. Furthermore, the trained question-answering model not only accurately answers the first question data in the first sample dataset, but also has a certain generalization ability, enabling it to provide reasonable answers to unseen question data.
[0064] Next, taking server A as the execution entity, the model training method provided in this application embodiment will be described in detail:
[0065] See Figure 3 This figure is a flowchart of a model training method provided in an embodiment of this application. Figure 3 The model training method shown includes the following steps:
[0066] S301: Obtain the first sample dataset and the reference document set. The first sample dataset includes multiple first question data, which are text data. The reference document set is a collection of reference documents.
[0067] The first sample dataset contains multiple first-question datasets, each representing an independent, unanswered question in text format. Examples include "What are the five most worthwhile attractions in Qingzhou?" and "What are the most popular shopping malls in Shanghai?". These first-question datasets cover a wide range of topics and domains, aiming to ensure that the trained question-answering model can handle diverse queries. As the foundation for training the machine learning model, the quality of the first sample dataset directly impacts the performance and accuracy of the question-answering model.
[0068] The reference document set contains multiple reference documents that serve as information sources needed to answer the first question data in the first sample dataset. These reference documents may originate from various resources, including but not limited to online encyclopedias, professional websites, academic papers, books, and forum discussions. These resources provide rich background knowledge and detailed information, which helps generate accurate first-answer data.
[0069] S302: Construct prompt text based on the first sample dataset and the reference document set. The prompt text is used to prompt the machine learning model to select reference documents from the reference document set to reply to the first question data, and to generate the first answer data to reply to the first question data.
[0070] In one specific implementation, the prompt text may include the first question data, reference documents in the reference document set (or indexes / links to reference documents), and prompt content. This prompt content helps the machine learning model narrow down the search scope and quickly select the reference document most relevant to the first question data. Furthermore, this prompt content also helps the machine learning model accurately generate the first answer data to respond to the first question data.
[0071] In another specific implementation, the prompt text may include a first prompt subtext and a second prompt subtext. Specifically, the first prompt subtext includes the first question data, reference documents (or indexes / links to reference documents) in the reference document set, and first prompt content. This first prompt content focuses on helping the machine learning model quickly select the most relevant reference documents from the reference document set. The second prompt subtext includes the first question data, reference documents (or indexes / links to reference documents) in the reference document set, and second prompt content. This second prompt content focuses on guiding the machine learning model on how to accurately generate first answer data to respond to the first question data based on these selected reference documents.
[0072] Understandably, the first implementation method accomplishes both reference document selection and answer generation simultaneously through comprehensive prompt text, while the second implementation method offers greater flexibility and accuracy by breaking down the task into two independent subtasks (reference document selection and answer generation). In practical applications, the appropriate implementation method can be chosen based on specific needs and resource availability. This application does not impose any limitations on this.
[0073] S303: Train a machine learning model based on the prompt text to obtain a question-answering model.
[0074] It should be noted that during or after model training, an independent validation dataset can be used to evaluate the performance of the trained question-answering model. For example, the accuracy, recall, and F1 score of the question-answering model can be evaluated. Based on the evaluation results, the model parameters or model structure of the question-answering model can be further adjusted and optimized to improve the performance of the question-answering model.
[0075] In summary, this application discloses a model training method. The method first acquires a first sample dataset and a set of reference documents. Then, it constructs prompt text based on the first sample dataset and the set of reference documents. This prompt text guides the machine learning model to select relevant reference documents from the set of reference documents to answer the first question and to generate a first answer. Finally, the machine learning model is trained based on the prompt text to obtain a question-answering model. Thus, the machine learning model is trained using a thought chain reinforcement method based on the prompt text, enabling it to learn how to select relevant reference documents from the set of reference documents based on a given question and extract key information to generate an accurate answer. This improves the model's training efficiency, increases the accuracy of the question-answering task, and allows the trained model to adapt to large-scale data processing needs.
[0076] See Figure 4 This figure is a flowchart of the second model training method provided in an embodiment of this application. Figure 4 The model training method shown includes the following steps:
[0077] S401: Obtain the first sample dataset and the reference document set. The first sample dataset includes multiple first question data, which are text data. The reference document set is a collection of reference documents.
[0078] The first sample dataset includes multiple first question data, each of which is a text-formatted question.
[0079] See Figure 5 This figure is a schematic diagram illustrating how to obtain prompt text according to an embodiment of this application. Figure 5 It can be seen that the first sample dataset can come from multiple sources, including but not limited to manual annotation and machine annotation.
[0080] The manual annotation of the first sample dataset refers to the process by which technical personnel sift through, organize, and annotate a large amount of text data to obtain the first sample dataset. Although the manual annotation method is time-consuming and costly, it can ensure the accuracy of the first sample dataset (e.g., free from grammatical errors and typos).
[0081] Machine annotation for generating the first sample dataset refers to the process by which a machine filters, organizes, and annotates a large amount of text data to obtain the first sample dataset, and / or, the machine automatically uses NLP techniques to generate multiple first question datasets to construct the first sample dataset. Machine annotation methods can quickly generate a large amount of first question data to construct the first sample dataset, but the generated first question data may lack accuracy (e.g., it may contain grammatical errors, typos, etc.) and requires further filtering and optimization.
[0082] S402: Determine the classification result for each first question data in the first sample dataset. The classification result represents the industry classification result and the question type classification result of the first question data.
[0083] Industry classification refers to categorizing data based on the industry sector or business scope to which the data in the first question belongs. In some specific implementations, industry classification can include primary industry classification and secondary industry classification, as shown in Table 1 below:
[0084] Table 1
[0085]
[0086]
[0087] Problem type classification refers to dividing the primary problem data into different categories or types based on its nature, purpose, or structural characteristics. In some specific implementations, problem type classification can be illustrated as shown in Table 2 below:
[0088] Table 2
[0089]
[0090]
[0091]
[0092] This application takes the above-mentioned 100 industry categories and 24 question type categories as an example. This means that each first question data is assigned an industry label and a question type label, forming a 100x24 cross-classification system, which includes 2400 classification results.
[0093] For example, let's categorize the first question, "What are the five most worthwhile attractions in Qingzhou?", by industry and question type. Since this question is about tourist attractions, it doesn't directly correspond to the specific industry categories listed in Table 1, but it can be categorized under "Other". Furthermore, this question asks for specific location information, namely the location or name of "the five most worthwhile attractions in Qingzhou". According to the classification in Table 2, this question best fits the "where" category because it requests five addresses, locations, or location information. Therefore, for the first question, "What are the five most worthwhile attractions in Qingzhou?", the classification result is "Other-where".
[0094] S403: Obtain the balanced first sample dataset by balancing the number of first question data corresponding to each classification result.
[0095] In the first sample dataset, the number of first-question data points for different classification results is usually unequal. This can lead to machine learning models being biased towards classifications with more first-question data points during training, while ignoring or misjudging those with fewer. Therefore, to avoid bias in the training process due to too many or too few first-question data points for certain classification results, the first sample dataset needs to be balanced. This means adjusting the number of first-question data points for each classification result to ensure a relatively balanced representation of each result, thereby improving the machine learning model's ability to recognize all classification results.
[0096] Specifically, first, all first-question data are statistically analyzed according to their classification results to obtain the number of first-question data points for each classification result. Second, the median of the first-question data points for all classification results is calculated; this median will serve as the benchmark for selecting the number of first-question data points subsequently. Then, for each classification result, the median number of first-question data points is randomly selected to obtain the balanced first sample dataset. Furthermore, if the number of first-question data points for a particular classification result is less than or equal to the median, all first-question data points for that classification result are used directly.
[0097] For example, the first sample dataset containing 50 first question data points can be classified into 12 first question data points classified as "people-words", 20 first question data points classified as "people-when", and 18 first question data points classified as "books / documents-translation". Since the median of 12, 18, and 20 is 18, 18 first question data points are randomly selected from the 20 first question data points classified as "people-when", and all first question data points classified as "people-words" and all first question data points classified as "books / documents-translation" are selected as the balanced first sample dataset.
[0098] It should be noted that the median mentioned above is merely an example. In practical applications, the average of the first question data from all classification results can also be calculated, and this average can be used as the benchmark for selecting the number of first question data points subsequently. This application does not limit this approach.
[0099] S404: Construct prompt text based on the balanced first sample dataset and reference document set.
[0100] See Figure 6A This image is a schematic diagram of a prompt message. For example... Figure 6AAs shown, one possible prompt is: Use the provided reference documents to provide a comprehensive answer to the given question. Ensure that the reference document number is appended to the corresponding sentence after citing the reference document, such as [1][2][3][4], etc. Finally, please provide your own insights. Thus, the machine learning model can directly generate the answer (i.e., the first question data) based on the question (i.e., the first question data) and all provided reference documents (i.e., the reference document set).
[0101] However, machine learning models trained on such prompt texts struggle to accurately determine which reference documents are most relevant to the current question, and are prone to referencing non-critical or incorrect information, thus generating answers with low accuracy.
[0102] Therefore, in order to improve the ability of machine learning models to answer questions and enable them to follow a clearer and more logical path when answering questions, and generate more accurate first answer data, this application provides a thought chain enhancement step.
[0103] See Figure 6B This figure is a schematic diagram of a prompt content provided in an embodiment of this application. The prompt text provided in this embodiment includes first question data, reference documents in a reference document set, and prompt content. The prompt content is used to prompt the machine learning model to select reference documents from the reference document set to respond to the first question data, and to generate first answer data to respond to the first question data. Therefore, in the process of enhancing the thought chain, the machine learning model needs to first find one or more reference documents most closely related to the first question data in the reference document set based on the first question data and the prompt content, and then generate first answer data corresponding to the first question data based on the one or more reference documents.
[0104] Specifically, in a particular implementation, such as Figure 6BAs shown in A in the example, the prompt provided in this application embodiment can be as follows: First, select a reference document that can answer the question and has complete content from the provided reference documents, and list its number. Second, use the selected reference document to provide a comprehensive answer to the given question. Ensure that the reference document number is marked after the corresponding sentence after citing the reference document, such as [1][2][3][4] etc. Finally, please give your own insights. Thus, firstly, reference documents that can answer the first question and have complete content are selected from the reference document set according to the prompt. Then, according to the prompt, the information integration and information annotation process is performed from the selected reference documents to generate the first answer data. This not only reduces the amount of data that needs to be processed later, making the information integration and information annotation process more efficient, saving computing resources, and speeding up the overall processing speed, but also reduces the interference of noisy data on the machine learning model by removing reference documents that are not directly related to the first question data or have incomplete content, thereby improving the quality and reliability of the final generated first answer data and making the first answer data more in line with the user's actual needs.
[0105] In another specific implementation, the aforementioned thought chain enhancement task can be broken down into two subtasks: a filtering subtask and a reference subtask. Specifically, the filtering subtask involves first selecting complete reference documents from the set of reference documents that can answer the first question based on the prompts. The purpose of this step is to eliminate documents that are irrelevant to the first question or incomplete, ensuring that the dataset processed subsequently is more refined and effective. Furthermore, the selected reference documents are marked with a serial number for easy reference later. The reference subtask, based on the prompts, uses the selected reference documents to further identify which reference documents or parts of those documents are most relevant to the first question, and integrates the most relevant information to form the complete first answer data. Simultaneously, to ensure the accuracy and traceability of the first answer data, the reference document number is appended to the sentence corresponding to the first answer data. Through the collaborative work of these two subtasks, the accuracy and reliability of the machine learning model in answering complex questions can be significantly improved, because the filtering subtask helps filter out irrelevant and distracting information, while the reference subtask focuses on extracting and integrating useful first answer data from the selected reference documents. This splitting approach helps improve processing efficiency and makes each subtask more focused and easier to manage.
[0106] In one specific implementation, after obtaining the balanced first sample dataset, it is still necessary to determine whether the number of first question data for each classification result is greater than the first threshold. This is because even after equalization, the number of first question data for some classification results may still be relatively small, insufficient for the machine learning model to fully learn the features of the first question data for that classification result, which will still affect the training effect and generalization ability of the machine learning model.
[0107] If the number of first question data in all classification results is greater than the first number threshold, then the above-mentioned "constructing prompt text based on the balanced first sample dataset and reference document set" step can be performed.
[0108] If the number of first question data for a certain classification result is less than or equal to the first number threshold, then it is necessary to use a search engine or database to retrieve reference documents related to that classification result, and generate multiple new questions as first question data through manual annotation or machine annotation (such as GPT generation) and integrate them into the first sample dataset.
[0109] In another specific implementation, this application can not only determine whether the number of first question data for each classification result is greater than the first threshold, but also determine whether there are any uncovered classification results among all the first question data in the first sample dataset, that is, whether some classification results are missing in the first sample dataset. Specifically, all classification results in the first sample dataset can be compared with the aforementioned 100x24 cross-classification system to ensure that no classification results are missed. If it is found that there are uncovered classification results in the first sample dataset, that is, some classification results do not have corresponding first question data in the first sample dataset, then a search engine or database can be used to retrieve reference documents related to the uncovered classification results, and multiple new questions can be generated as first question data through manual annotation or machine annotation (such as GPT generation) methods, and then merged into the first sample dataset.
[0110] S405: Train a machine learning model based on the prompt text to obtain a question-answering model.
[0111] To ensure the generalization ability of the trained question-answering model, data augmentation can be performed on the prompt text before training the machine learning model; that is, the machine learning model is trained based on the prompt text and distracting text. The following explanation uses an example where the prompt text includes the first question data, reference documents from the reference document set, and the prompt content:
[0112] In some specific implementations, data augmentation can refer to randomly replacing words, sentences, etc., in a reference document. Specifically, a reference document can be randomly selected from multiple reference documents, and this document can undergo any one or more operations such as word repetition, sentence repetition, word deletion, sentence deletion, word reordering, and sentence reordering (i.e., generating a distractor document). Subsequently, the initial question data, the data-augmented reference document, and the prompt content are used together as the prompt text for training the machine learning model.
[0113] Specifically, repeating words or sentences helps the trained question-answering model improve its ability to handle redundant information; deleting words or sentences helps the machine learning model learn to handle missing text, enabling it to recover useful content from incomplete information; and shuffling words or sentences helps the machine learning model learn to identify key information even when the content order is not fixed. Therefore, randomly replacing words and sentences in the reference document corresponding to the first question data can simulate various errors and changes that may occur in actual reference documents, helping the machine learning model learn how to extract effective information more accurately, thereby improving the accuracy of the trained question-answering model in question-answering tasks.
[0114] In other specific implementations, data augmentation can also refer to replacing correct words in a reference document with misspelled words (such as similar-looking words, homophones, or incorrect words, i.e., generating distractor documents). For example, one or more correct words can be replaced with misspelled words in one or more random sentences from the reference document. The initial question data, the data-augmented reference document, and the prompt content are used together as prompt text to train the machine learning model. This allows the machine learning model to maintain high accuracy and stability when processing text containing spelling errors, thereby improving the accuracy of the trained question-answering model in question-answering tasks.
[0115] In other specific implementations, data augmentation can also refer to randomly adding a reference document unrelated to the first question data (i.e., generating a distractor document). Then, the first question data, the data-augmented reference document, and the prompt content are used together as the prompt text for training the machine learning model. This allows the machine learning model to accurately identify and utilize relevant information to generate the first answer data even in the presence of distracting information, thereby improving the accuracy of the trained question-answering model in question-answering tasks.
[0116] In other specific implementations, data augmentation can also refer to using a pre-trained natural language model (such as GPT-4) to determine whether the semantics of the first question data are clear (i.e., whether it contains ambiguity). If it is unambiguous, the first question data, the data-augmented reference document, and the prompt content are then used together as prompt text to train the machine learning model. This allows the machine learning model to learn to automatically identify and reject questions that are semantically ambiguous or unclear, thereby improving the accuracy of the question-answering model in question-answering tasks.
[0117] It should be noted that any one or more of the above four data augmentation methods can be performed simultaneously, and this application does not limit this.
[0118] In summary, this application provides a model training method. Through the model training method provided in the embodiments of this application, the machine learning model can be trained according to the prompt text through the mind chain enhancement method, learn how to select relevant reference documents from the reference document set according to the given question, extract key information to generate accurate answers, thereby improving the training efficiency of the model, improving the accuracy of question answering tasks, and enabling the trained model to adapt to the needs of large-scale data processing.
[0119] See Figure 7 This figure is a flowchart of the third model training method provided in an embodiment of this application. Figure 7 The model training method shown includes the following steps:
[0120] S701: Obtain the first sample dataset and the reference document set. The first sample dataset includes multiple first question data, which are text data. The reference document set is a collection of reference documents.
[0121] S702: Construct prompt text based on the first sample dataset and the reference document set. The prompt text is used to prompt the machine learning model to select reference documents from the reference document set to reply to the first question data, and to generate the first answer data to reply to the first question data.
[0122] It is understandable that the steps S701-S702 are the same as those S401-S404, and will not be repeated here.
[0123] S703: Obtain the second sample dataset, which includes multiple second question data, and the second question data is text data.
[0124] S704: Determine the classification result for each second question data in the second sample dataset. The classification result represents the industry classification result and the question type classification result of the second question data.
[0125] S705: Obtain the balanced second sample dataset by balancing the number of second question data corresponding to each classification result.
[0126] It is understandable that the steps S704-S705 above are similar to steps S401-S404, and will not be repeated here.
[0127] S706: Based on each second question data in the balanced second sample dataset, select reference documents from the reference document set to respond to the second question data, and generate multiple second answer data to respond to the second question data based on the reference documents.
[0128] See Figure 8 The figure is a schematic diagram of obtaining a training dataset according to an embodiment of this application. It should be noted that multiple second answer data points have been sorted according to accuracy, relevance to the second question data and reference documents to ensure that the most accurate or most relevant answer is presented first.
[0129] For example, if the second question data is: "Question: How to effectively relieve headaches?", then the corresponding reference document could be a medical document, and the corresponding second answer data could be: "Answer 1: Try drinking some warm water, lying down to relax, and applying a cold or hot compress to your forehead. Answer 2: It is recommended to consult a doctor. Answer 3: Headaches may be related to lack of sleep." Among these, Answer 1 has the highest accuracy and relevance, Answer 2 has the second highest accuracy and relevance, and Answer 3 has the lowest accuracy and relevance.
[0130] S707: Determine whether the number of second question data points corresponding to each classification result in the balanced second sample dataset is greater than the second threshold. If yes, proceed to S708; otherwise, proceed to S709.
[0131] Determine if the number of second question data points for each classification result is greater than the second threshold. This is because even after equalization, the number of second question data points for some classification results may still be relatively small, insufficient for the machine learning model to fully learn the features of the second question data for that classification result, thus affecting the training effect and generalization ability of the machine learning model. Therefore, if the number of second question data points for each classification result in the equalized second sample dataset is greater than the second threshold, proceed to step S708; otherwise, proceed to step S709.
[0132] S708: Train a machine learning model based on the training dataset and prompt text to obtain a question-answering model. The training dataset includes second question data, reference documents, and multiple second answer data. The multiple second answer data are sorted according to accuracy, relevance to the second question data and reference documents.
[0133] In the process of training a machine learning model based on a training dataset and prompt text, the model not only learns to select relevant reference documents from a set of references and extract key information to generate accurate answers based on the prompt text through a thought chain reinforcement method, but also possesses a mechanism for automatically evaluating the generated answers. Specifically, the machine learning model can prioritize and present the answer with the highest accuracy and relevance as the primary answer to the user based on accuracy and relevance criteria.
[0134] It should be noted that during the process of training the machine learning model based on the prompt text in step S708, data augmentation can also be performed on the prompt text, as described in step S405, which will not be repeated here.
[0135] S709: Generate differential problem data based on the classification results where the number of data points for the second problem is less than the threshold for the second problem.
[0136] If the number of second question data for a certain classification result is less than or equal to the second threshold, then it is necessary to use a search engine or database to retrieve reference documents related to that classification result, and generate multiple new questions as difference question data through manual annotation or machine annotation (such as GPT generation).
[0137] It should be noted that this application can not only determine whether the number of second question data for each classification result is greater than the second threshold, but also determine whether there are any uncovered classification results among all the second question data in the second sample dataset, that is, whether some classification results are missing in the second sample dataset. Specifically, all classification results in the second sample dataset can be compared with the aforementioned 100x24 cross-classification system to ensure that no classification results are missed. If uncovered classification results are found in the second sample dataset, that is, some classification results do not have corresponding second question data in the second sample dataset, then reference documents related to the uncovered classification results can be retrieved using search engines or databases, and multiple new questions can be generated as difference question data through manual annotation or machine annotation methods (such as GPT generation).
[0138] S710: Select reference documents from the reference document set to respond to the discrepancy question data, and generate multiple discrepancy answer data to respond to the discrepancy question data based on the reference documents. The multiple discrepancy answer data are sorted according to accuracy, and relevance to the discrepancy question data and the reference documents.
[0139] In one specific implementation, multiple discrepancy answer data points can be sorted based on accuracy, relevance to discrepancy question data and reference documents by constructing scoring groups. The specific steps include:
[0140] First, scoring groups are constructed. Each scoring group includes the discrepancy question data, a reference document, two discrepancy answer data sets, and scoring content. This data collectively guides the natural language model to select the better answer data set from the two discrepancy answer data sets. Specifically, the scoring content instructs the natural language model, based on the discrepancy question data and the reference document, to select the target answer data set that has higher accuracy (e.g., excluding typos, unambiguity, etc.) and higher relevance to the discrepancy question data and the reference document.
[0141] Subsequently, the scoring group is input into the natural language model, which evaluates the two differing answer data and obtains the target answer data with better accuracy and relevance.
[0142] Finally, after the natural language model outputs the target answer data for each scoring group, the multiple differential answer data can be sorted as a whole based on these target answer data.
[0143] See Figure 9 This figure is a schematic diagram of a differentially constructed second sample dataset provided in an embodiment of this application. Figure 9 For example, four differential answer data sets were generated from the differential question data: Answer Data 1, Answer Data 2, Answer Data 3, and Blank Answer Data. These four differential answer data sets were then paired into six scoring groups (including: Answer Data 1 and Answer Data 2, Answer Data 1 and Answer Data 3, Answer Data 1 and Blank Answer Data, Answer Data 2 and Answer Data 3, Answer Data 2 and Blank Answer Data, and Answer Data 3 and Blank Answer Data). Each scoring group was then input into a natural language model for evaluation. For each scoring group, the natural language model selected the target answer data with higher accuracy and relevance. Finally, for all scoring groups, all differential answer data sets were ranked, resulting in a ranking of all differential answer data sets.
[0144] It's important to note that, on one hand, each scoring group can be input into a single natural language processing (NLP) model (such as GPT3.5 or GPT4). This NLP model, based on its internally trained data and algorithms, evaluates various aspects of the two differing answer data within each scoring group, such as accuracy, clarity, source reliability (whether it originates from a reference document), content authenticity (whether it is fabricated), and the presence of duplicate content. The NLP model can then directly output a score for each differing answer data. These scores can be numerical (e.g., scores between 0 and 100) or other forms of quantitative indicators. Subsequently, the scores of all differing answer data are sorted.
[0145] On the other hand, each scoring group can be input into multiple natural language models (such as GPT3.5 and GPT4), so that each natural language model outputs the scoring results for the differing answer data in each scoring group. For example, inputting a scoring group into a GPT4 model will allow the GPT4 model to output the scoring results for the two differing answer data in that scoring group, thus allowing comparison to obtain the target answer data with better accuracy and relevance. Simultaneously, inputting a scoring group into GPT3.5 will allow the GPT3.5 model to score the two differing answer data in the scoring group from both positive and negative dimensions. For example, if answer data A and answer data B are simultaneously input into the GPT3.5 model, the GPT3.5 model will first score from the positive dimension (e.g., the superiority or inferiority of answer data A relative to answer data B), obtaining one score result, and then score from the negative dimension (the superiority or inferiority of answer data B relative to answer data A), obtaining another score result. To obtain a comprehensive positive and negative scoring result, the average of these two scores or other suitable statistics can be taken to reflect the overall performance of the two differing answer data in their comparison. Subsequently, after obtaining the GPT4 and GPT3.5 scores, these scores can be combined as needed. For example, a simple weighted average of the GPT4 and GPT3.5 scores can be taken, or a more complex scoring combination strategy can be designed according to the needs of specific scenarios. This application does not limit this approach.
[0146] It should be noted that the above S710 step is explained using GPT annotation of the generated discrepancy question data as an example. In practical applications, manual annotation sequences can also be performed to obtain multiple manually annotated discrepancy answer data. These manually annotated discrepancy answer data, along with the reference answer and the discrepancy question data, are then updated into the second sample dataset. As long as the multiple manually annotated discrepancy answer data are also sorted according to accuracy, relevance to the discrepancy question data and the reference document, this application does not impose any limitations on this.
[0147] S711: Add the difference question data, the corresponding reference answer and difference answer data to the balanced second sample dataset.
[0148] In some specific implementations, discrepancy answer data can be replaced with no-reference answer data. No-reference answer data refers to answer data used to respond to discrepancy questions that was not generated based on a reference document.
[0149] To facilitate understanding, the following explanation will use the example of generating four different answer data points based on one difference question and one reference document as an example (using...). Figure 9 For example:
[0150] After generating four differential answer datasets, firstly, one of the original four differential answer datasets, generated based on a reference document, is replaced with a dataset generated without any reference document (i.e., a dataset without any reference document). Figure 9 (Answer data 3 in the example). The purpose of this replacement is to add "negative training data" to the machine learning model during subsequent training—that is, answer data that is not based on the reference document. In this way, the machine learning model can learn which answer data lacks a reference document, thereby reducing such "unfounded" reasoning in future reasoning processes and reducing the illusion of the machine learning model.
[0151] In some specific implementations, the discrepancy answer data can be replaced with blank answer data. Here, blank answer data serves as a placeholder, indicating that answer data cannot be generated based on the discrepancy question data and the reference document.
[0152] like Figure 9 As shown, one of the four different answer data points can also be replaced with an answer data point that explicitly indicates a refusal to be identified (a blank answer data point, i.e., ...). Figure 9 (4) This blank answer data is typically a placeholder indicating that answer data cannot be generated based on the discrepancy question data and the reference document. The purpose of this replacement is to enhance the machine learning model's ability to identify "don't know" or "cannot answer" queries. When the machine learning model encounters semantically ambiguous, insufficiently documented, or unanswerable situations in practical applications, it can correctly identify and reject the answer, thereby improving user experience and the reliability of the machine learning model.
[0153] Therefore, through these two substitution operations, machine learning models can learn during training how to better identify and reject queries that are semantically ambiguous or cannot be accurately answered, thereby reducing the illusion of machine learning models and improving the overall recognition effect, thus enhancing the stability and reliability of machine learning models in practical applications.
[0154] In summary, this application discloses a model training method. The method first obtains a first sample dataset and a set of reference documents. Then, it constructs prompt text based on the first sample dataset and the set of reference documents. This prompt text guides the machine learning model to select relevant reference documents from the set of reference documents to answer the first question and to generate the first answer data. Finally, the machine learning model is trained based on the prompt text to obtain a question-answering model. Thus, the machine learning model is trained using a thought chain reinforcement method based on the prompt text, enabling it to learn how to select relevant reference documents from the set of reference documents based on a given question and extract key information to generate accurate answers. This improves the model's training efficiency, increases the accuracy of the question-answering task, and allows the trained model to adapt to large-scale data processing needs. Furthermore, when processing the second sample dataset, the equalization of classification results avoids model bias caused by insufficient data in certain categories. Secondly, a multi-answer ranking mechanism is introduced to ensure that the generated answers are not only accurate but also highly relevant to the question and reference documents, thereby improving user satisfaction. In addition, for cases of insufficient classification results, differential question data and differential answer data are generated, ranked, and evaluated, further enhancing the model's robustness and adaptability. In particular, by introducing data with no reference answers and blank answers, the complex situations that may be encountered in real-world applications are simulated, enabling the model to better identify and handle unanswerable or uncertain queries, reducing model illusions and improving overall data recognition performance.
[0155] See Figure 10 This figure is a flowchart of a question-and-answer method provided in an embodiment of this application. Figure 10 The question-and-answer method shown includes the following steps:
[0156] S901: Get the questions to be answered.
[0157] S902: Using a question-and-answer model, determine the answer corresponding to the question to be answered, and display the reference document information corresponding to the answer in the answer.
[0158] It should be noted that the question-answering model is trained using the model training method disclosed in the embodiments of this application.
[0159] In summary, this application discloses a question-answering method that directly determines the answer to the question using a question-answering model. Compared to traditional manual retrieval or simple keyword matching methods, this process significantly improves the processing efficiency of question-answering tasks. Furthermore, the question-answering model, based on advanced technologies such as deep learning, understands the semantics of the question, identifies relevant reference documents from the reference document pool, and quickly finds the most relevant answer from the identified reference documents, thereby improving the accuracy of the answer. Further, the question-answering method disclosed in this application can also display the reference document information corresponding to the answer, a design that greatly enhances the user experience. Users not only obtain the answer to the question but also understand the source of the answer, increasing the credibility of the answer. For scenarios requiring further research or verification, users can directly access these reference documents to obtain more detailed information.
[0160] Based on the model training method provided in the preceding embodiments, this application also provides a corresponding model training apparatus. The model training apparatus provided in this application will be described in detail below:
[0161] See Figure 11 The figure is a schematic diagram of a model training device provided in an embodiment of this application. The model training device 1000 includes: a set acquisition module 1001, a text construction module 1002, and a model training module 1003;
[0162] The set acquisition module 1001 is used to acquire the first sample dataset and the reference document set. The first sample dataset includes multiple first question data, which are text data. The reference document set is a collection of reference documents.
[0163] The text construction module 1002 is used to construct prompt text based on the first sample dataset and the reference document set. The prompt text is used to prompt the machine learning model to select reference documents from the reference document set to reply to the first question data, and to generate the first answer data to reply to the first question data.
[0164] The model training module 1003 is used to train a machine learning model based on the prompt text to obtain a question-answering model.
[0165] In some specific implementations, the prompt text includes:
[0166] The first question data, the reference documents in the reference document set, and the prompt content. The prompt content is used to prompt the machine learning model to select reference documents from the reference document set to respond to the first question data, and to generate the first answer data to respond to the first question data.
[0167] In some specific implementations, the prompt text includes a first prompt subtext and a second prompt subtext:
[0168] The first prompt subtext includes: the first question data, the reference documents in the reference document set, and the first prompt subcontent. The first prompt subcontent is used to prompt the machine learning model to select a reference document from the reference document set to respond to the first question data.
[0169] The second prompt subtext includes: the first question data, reference documents in the reference document set, and the second prompt subtext, which is used to prompt the machine learning model to generate the first answer data to respond to the first question data.
[0170] In some specific implementations, the text construction module 1002 specifically includes: a first construction submodule, a second construction submodule, and a third construction submodule;
[0171] The first construction submodule is used to determine the classification result of each first question data in the first sample dataset. The classification result represents the industry classification result and the question type classification result of the first question data.
[0172] The second construction submodule is used to obtain the balanced first sample dataset by balancing the number of first question data corresponding to each classification result;
[0173] The third construction submodule is used to construct the prompt text based on the balanced first sample dataset and the reference document set.
[0174] In some specific implementations, the second construction submodule is specifically used to: obtain the median value of the number of first question data corresponding to each classification result; filter out the median number of first question data from the classification results where the number of first question data is greater than the median value; and obtain the balanced first sample dataset based on the filtered first question data and the first question data corresponding to the classification results where the number of first question data is less than or equal to the median value.
[0175] In some specific implementations, the third construction submodule is specifically used to: if the number of first question data corresponding to each classification result of the balanced first sample dataset is greater than the first number threshold, then construct the prompt text based on the balanced first sample dataset and the reference document set.
[0176] In some specific implementations, the model training module 1003 is specifically used to: train a machine learning model based on the prompt text and the interfering documents, wherein the interfering documents are documents that have undergone at least one of the following: word repetition, sentence repetition, word deletion, sentence deletion, word disordering, sentence disordering, and the addition of typos, and / or documents that are unrelated to the reference documents in the reference document set.
[0177] In some specific implementations, the model training module 1003 includes: a first training submodule, a second training submodule, and a third training submodule;
[0178] The first training submodule is used to obtain the second sample dataset, which includes multiple second question data, and the second question data is text data.
[0179] The second training submodule is used to select reference documents from the reference document set to respond to the second question data based on each second question data in the second sample dataset, and to generate multiple second answer data to respond to the second question data based on the reference documents;
[0180] The third training submodule is used to train a machine learning model based on the training dataset and the prompt text. The training dataset includes second question data, reference documents, and multiple second answer data. The multiple second answer data are sorted according to accuracy, relevance to the second question data and reference documents.
[0181] In some specific implementations, the second training submodule is specifically used to: determine the classification result of each second question data in the second sample dataset, wherein the classification result represents the industry classification result and the question type classification result of the second question data; obtain the balanced second sample dataset by balancing the number of second question data corresponding to each classification result; and select reference documents from the reference document set to respond to the second question data based on each second question data in the balanced second sample dataset.
[0182] In some specific implementations, the third training submodule is specifically used to: if the number of second question data corresponding to each classification result of the balanced second sample dataset is greater than the second threshold, then train the machine learning model based on the training dataset and the prompt text.
[0183] In some specific implementations, the model training device 1000 also includes: a question generation module, a sorting module, and an adding module;
[0184] The question generation module is used to generate differential question data based on the classification results where the number of second question data corresponding to each classification result in the balanced second sample dataset is less than the second threshold.
[0185] The sorting module is used to select reference documents from the reference document set for responding to the discrepancy question data, and to generate multiple discrepancy answer data for responding to the discrepancy question data based on the reference documents. The multiple discrepancy answer data are sorted according to accuracy, and relevance to the discrepancy question data and the reference documents.
[0186] Add a module to add the discrepancy question data, the corresponding reference answers, and the discrepancy answer data to the balanced second sample dataset.
[0187] In some specific implementations, the model training device 1000 further includes: a first replacement module; the first replacement module is used to: replace the discrepancy answer data with no-reference answer data, wherein the no-reference answer data is answer data not generated based on the reference document for responding to discrepancy question data.
[0188] In some specific implementations, the second replacement module is used to replace the difference answer data with blank answer data, where the blank answer data is a placeholder and indicates that answer data cannot be generated based on the difference question data and the reference document.
[0189] In some specific implementations, the unit for sorting multiple discrepancy answer data based on accuracy, relevance to discrepancy question data and reference documents is as follows:
[0190] The first sorting unit is used to construct a scoring group, which includes the difference question data, reference document, two difference answer data, and scoring content. The scoring content is used to instruct the natural language model to select the target answer data with higher accuracy and relevance to the difference question data and reference document from the two difference answer data based on the difference question data and reference document.
[0191] The second sorting unit is used to input the scoring groups into the natural language model to obtain the target answer data;
[0192] The third sorting unit is used to sort multiple differential answer data based on the target answer data corresponding to multiple scoring groups.
[0193] In summary, this application discloses a model training apparatus. The apparatus first acquires a first sample dataset and a set of reference documents. Then, it constructs prompt text based on the first sample dataset and the set of reference documents. This prompt text guides the machine learning model to select relevant reference documents from the set of reference documents to answer the first question and to generate first answer data to answer the first question. Finally, the machine learning model is trained based on the prompt text to obtain a question-answering model. Thus, the machine learning model is trained using a thought chain reinforcement method based on the prompt text, enabling it to learn how to select relevant reference documents from the set of reference documents based on a given question and extract key information to generate accurate answers. This improves the model's training efficiency, increases the accuracy of the question-answering task, and allows the trained model to adapt to large-scale data processing needs. Furthermore, when processing the second sample dataset, the equalization of classification results avoids model bias caused by insufficient data in certain categories. Secondly, a multi-answer ranking mechanism is introduced to ensure that the generated answers are not only accurate but also highly relevant to the question and reference documents, thereby improving user satisfaction. In addition, for cases of insufficient classification results, the robustness and adaptability of the model are further enhanced by generating differential question data and differential answer data, ranking and evaluating them. In particular, by introducing data with no reference answers and blank answers, the complex situations that may be encountered in real-world applications are simulated, enabling the model to better identify and handle unanswerable or uncertain queries, reducing model illusions and improving overall data recognition performance.
[0194] Based on the question-answering method provided in the preceding embodiments, this application also provides a question-answering device. The question-answering device provided in this application will be described in detail below:
[0195] See Figure 12 The figure is a schematic diagram of a question-and-answer device provided in an embodiment of this application. The question-and-answer device 1100 includes: a question acquisition module 1101 and an answer output module 1102.
[0196] The question retrieval module 1101 is used to retrieve questions to be answered.
[0197] The answer output module 1102 is used to determine the answer to the question to be answered through a question-and-answer model, and the answer displays the reference document information corresponding to the answer.
[0198] It should be noted that the question-answering model is trained using the model training method disclosed in the embodiments of this application.
[0199] In summary, this application discloses a question-answering device that directly determines the answer to the question using a question-answering model. Compared to traditional manual retrieval or simple keyword matching devices, this process significantly improves the processing efficiency of question-answering tasks. Furthermore, the question-answering model, based on advanced technologies such as deep learning, understands the semantics of the question, identifies relevant reference documents from the reference document pool, and quickly finds the most relevant answer from the identified reference documents, thereby improving the accuracy of the answer. Further, the question-answering device disclosed in this application can also display the reference document information corresponding to the answer, a design that greatly enhances the user experience. Users not only obtain the answer to the question but also understand the source of the answer, increasing the credibility of the answer. For scenarios requiring further research or verification, users can directly access these reference documents to obtain more detailed information.
[0200] See Figure 13 , Figure 13 This is a schematic diagram of the structure of a terminal device provided in an embodiment of this application. For example... Figure 13 As shown, for ease of explanation, only the parts related to the embodiments of this application are shown. For specific technical details not disclosed, please refer to the method section of the embodiments of this application. The terminal can be any terminal device including mobile phones, tablets, personal digital assistants, point-of-sale (POS) terminals, in-vehicle computers, etc. Taking a computer as an example:
[0201] Figure 13 This is a block diagram illustrating a portion of the structure of a computer associated with the terminal provided in an embodiment of this application. (Reference) Figure 12 The computer includes: a radio frequency (RF) circuit 1210, a memory 1220, an input unit 1230 (including a touch panel 1231 and other input devices 1232), a display unit 1240 (including a display panel 1241), a sensor 1250, an audio circuit 1260 (which can connect to a speaker 1261 and a microphone 1262), a wireless fidelity (WiFi) module 1270, a processor 1280, and a power supply 1290, etc. Those skilled in the art will understand that... Figure 13 The computer architecture shown does not constitute a limitation on the computer and may include more or fewer components than shown, or combine certain components, or have different component arrangements.
[0202] The memory 1220 can be used to store software programs and modules. The processor 1280 executes various computer functions and data processing by running the software programs and modules stored in the memory 1220. The memory 1220 may mainly include a program storage area and a data storage area. The program storage area may store the operating system, application programs required for at least one function (such as sound playback function, image playback function, etc.), etc.; the data storage area may store data created according to the use of the computer (such as audio data, telephone directory, etc.). In addition, the memory 1220 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device.
[0203] The processor 1280 is the control center of the computer, connecting various parts of the computer through various interfaces and lines. It performs various computer functions and processes data by running or executing software programs and / or modules stored in the memory 1220, and by calling data stored in the memory 1220. Optionally, the processor 1280 may include one or more processing units; preferably, the processor 1280 may integrate an application processor and a modem processor, wherein the application processor mainly handles the operating system, user interface, and applications, and the modem processor mainly handles wireless communication. It is understood that the modem processor may also not be integrated into the processor 1280.
[0204] In this embodiment of the application, the processor 1280 included in the terminal also has the following functions:
[0205] Obtain the first sample dataset and the reference document set. The first sample dataset includes multiple first question data, which are text data. The reference document set is a collection of reference documents.
[0206] Based on the first sample dataset and the reference document set, a prompt text is constructed. The prompt text is used to prompt the machine learning model to select reference documents from the reference document set to reply to the first question data, and to generate the first answer data to reply to the first question data.
[0207] A machine learning model is trained based on the prompt text to obtain a question-answering model.
[0208] or,
[0209] Get the questions to be answered;
[0210] The question-answering model determines the answer to the question and displays the corresponding reference document information. The question-answering model is trained using the model training method described above.
[0211] See Figure 14 , Figure 14 This is a schematic diagram of a server structure provided in an embodiment of this application. The server 1300 can vary significantly due to different configurations or performance, and may include one or more central processing units (CPUs) 1322 (e.g., one or more processors) and memory 1332, and one or more storage media 1330 (e.g., one or more mass storage devices) for storing application programs 1342 or data 1344. The memory 1332 and storage media 1330 can be temporary or persistent storage. The program stored in the storage media 1330 may include one or more modules (not shown in the diagram), each module including a series of instruction operations on the server. Furthermore, the CPU 1322 may be configured to communicate with the storage media 1330 and execute the series of instruction operations in the storage media 1330 on the server 1300.
[0212] Server 1300 may also include one or more power supplies 1326, one or more wired or wireless network interfaces 1350, one or more input / output interfaces 1358, and / or one or more operating systems, such as Windows Server™, Mac OS X™, Unix™, Linux™, FreeBSD™, etc.
[0213] The steps performed by the server in the above embodiments can be based on this Figure 14 The server structure shown.
[0214] CPU1322 is used to perform the following steps:
[0215] Obtain the first sample dataset and the reference document set. The first sample dataset includes multiple first question data, which are text data. The reference document set is a collection of reference documents.
[0216] Based on the first sample dataset and the reference document set, a prompt text is constructed. The prompt text is used to prompt the machine learning model to select reference documents from the reference document set to reply to the first question data, and to generate the first answer data to reply to the first question data.
[0217] A machine learning model is trained based on the prompt text to obtain a question-answering model.
[0218] or,
[0219] Get the questions to be answered;
[0220] The question-answering model determines the answer to the question and displays the corresponding reference document information. The question-answering model is trained using the model training method described above.
[0221] This application also provides a computer-readable storage medium for storing a computer program that executes any one of the implementation methods of the model training method described in the foregoing embodiments, or executes the steps of any one implementation of the question-answering method provided in this application.
[0222] This application also provides a computer program product or computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform any of the implementation methods of the model training methods described in the foregoing embodiments, or to further perform any implementation of the question-answering method provided in this application.
[0223] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0224] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection between apparatuses or units through some interfaces, and may be electrical, mechanical, or other forms.
[0225] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0226] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0227] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing computer programs, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0228] It should be understood that in this application, "at least one (item)" means one or more, and "more than" means two or more. "And / or" is used to describe the relationship between related objects, indicating that three relationships can exist. For example, "A and / or B" can represent three cases: only A exists, only B exists, and both A and B exist simultaneously, where A and B can be singular or plural. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. "At least one (item) of the following" or similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one (item) of a, b, or c can represent: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, and c can be single or multiple.
[0229] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application.
Claims
1. A model training method, characterized in that, The method comprises: obtaining a first sample data set and a reference document set, the first sample data set comprising a plurality of first question data, the first question data being text data, and the reference document set being a collection of reference documents; constructing prompt text based on the first sample data set and the reference document set, the prompt text being used to prompt a machine learning model to select a reference document from the reference document set for replying to the first question data and to generate first answer data for replying to the first question data; training the machine learning model according to the prompt text to obtain a question and answer model.
2. The method of claim 1, wherein, The prompt text comprises: the first question data, a reference document in the reference document set, and prompt content, the prompt content being used to prompt a machine learning model to select a reference document from the reference document set for replying to the first question data and to generate first answer data for replying to the first question data.
3. The method of claim 1, wherein, The prompt text comprises a first prompt subtext and a second prompt subtext: the first prompt subtext comprises the first question data, a reference document in the reference document set, and first prompt subcontent, the first prompt subcontent being used to prompt a machine learning model to select a reference document from the reference document set for replying to the first question data; the second prompt subtext comprises the first question data, a reference document in the reference document set, and second prompt subcontent, the second prompt subcontent being used to prompt a machine learning model to generate first answer data for replying to the first question data.
4. The method of claim 1, wherein, The construction of the prompt text based on the first sample data set and the reference document set comprises: determining a classification result of each first question data in the first sample data set, the classification result representing an industry classification result and a question type classification result of the first question data; obtaining an equalized first sample data set by equalizing the number of the first question data corresponding to each classification result; constructing the prompt text based on the equalized first sample data set and the reference document set.
5. The method of claim 1, wherein, The training of the machine learning model according to the prompt text comprises: training the machine learning model according to the prompt text and interference documents, the interference documents being documents obtained by repeating words, repeating sentences, deleting words, deleting sentences, shuffling words, shuffling sentences, and adding wrong characters in at least one of the reference documents in the reference document set, and / or being documents irrelevant to the reference documents in the reference document set.
6. The method of claim 1, wherein, The training of the machine learning model according to the prompt text comprises: obtaining a second sample data set, the second sample data set comprising a plurality of second question data, the second question data being text data; selecting a reference document from the reference document set for replying to each second question data in the second sample data set according to the second question data, and generating a plurality of second answer data for replying to the second question data according to the reference document; training the machine learning model according to the training data set and the prompt text, the training data set including the second question data, the reference documents, and the plurality of second answer data, the plurality of second answer data being sorted according to accuracy and relevance to the second question data and the reference documents.
7. The method of claim 6, wherein, The selecting, from the reference document set, a reference document for responding to each of the second question data in the second sample data set includes: determining a classification result of each of the second question data in the second sample data set, the classification result representing an industry classification result and a question type classification result of the second question data; obtaining an equalized second sample data set by equalizing the number of the second question data corresponding to each of the classification results; The selecting, from the reference document set, a reference document for responding to each of the second question data in the equalized second sample data set.
8. The method of claim 7, wherein, The training the machine learning model according to the training data set and the prompt text includes: If the number of the second question data corresponding to each of the classification results in the equalized second sample data set is greater than a second number threshold, training the machine learning model according to the training data set and the prompt text.
9. The method of claim 8, wherein, The method further includes: If the number of the second question data corresponding to each of the classification results in the equalized second sample data set is less than a second number threshold, generating a difference question data according to the classification result of which the number of the second question data is less than the second number threshold; selecting, from the reference document set, a reference document for responding to the difference question data, and generating a plurality of difference answer data for responding to the difference question data according to the reference document, the plurality of difference answer data being sorted according to accuracy and relevance to the difference question data and the reference document; adding the difference question data, the reference answer corresponding to the difference question data, and the difference answer data to the equalized second sample data set.
10. The method of claim 9, wherein, The method further includes: replacing the difference answer data with no-reference answer data, the no-reference answer data being answer data for responding to the difference question data that is not generated according to the reference document.
11. The method of claim 9, wherein, The method further includes: replacing the difference answer data with blank answer data, the blank answer data being a placeholder, the blank answer data indicating that answer data cannot be generated according to the difference question data and the reference document.
12. A question and answer method characterized by, The method includes: obtaining a question to be answered; determining an answer corresponding to the question to be answered through a question and answer model, the answer displaying reference document information corresponding to the answer, the question and answer model being trained through the model training method of any one of claims 1 to 11.
13. A model training apparatus, comprising: The apparatus includes a set obtaining module, a text constructing module, and a model training module. The collection obtaining module is configured to obtain a first sample data set and a reference document set, the first sample data set comprises a plurality of first question data, the first question data is text data, and the reference document set is a collection of reference documents; The text construction module is configured to construct prompt text based on the first sample data set and the reference document set, the prompt text is used to prompt a machine learning model to select a reference document for replying to the first question data from the reference document set, and generate first answer data for replying to the first question data; The model training module is configured to train the machine learning model according to the prompt text to obtain a question and answer model.
14. A computer device, comprising: The device comprises a processor and a memory: The memory is configured to store program code and transmit the program code to the processor; The processor is configured to execute the steps of the model training method according to any one of claims 1 to 11 or the question and answer method according to claim 12 according to instructions in the program code.
15. A computer readable storage medium characterized by: The computer readable storage medium is configured to store program code, and the program code is configured to execute the steps of the model training method according to any one of claims 1 to 11 or the question and answer method according to claim 12.