Medical question and answer method and device, electronic equipment and storage medium
By using embedding model and classification model in the medical question-answer system, matching candidate questions and target questions of medical questions, the problem of low answer accuracy in the existing medical question-and-answer system is solved, and more professional and accurate medical question responses are achieved.
Patent Information
- Application Number
- CN202411470406.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-21
- Publication Date
- 2025-02-11
AI Technical Summary
In existing medical Q&A systems, the answers are less accurate, which may lead to misleading patients or doctors to make wrong diagnosis and treatment decisions.
By obtaining medical problems and their corresponding multiple reference questions, using pre-trained embedding models and classification models, we determine candidate questions and target questions that match medical problems, and then provide the answers to the questions as a response to medical questions.
Improve the accuracy of medical Q&A, ensure more professional and accurate responses to medical questions, and reduce the risk of wrong responses.
Smart Images

Figure CN119418959A_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present invention relate to the field of artificial intelligence technology, and in particular, to a medical question-and-answer method, device, electronic device, and storage medium. Background Art
[0002] With the rapid development of artificial intelligence and natural language processing technology, question-answering systems based on large models have been widely used in various fields. Especially in the medical field, question-answering systems are often used to assist doctors in diagnosis, provide health advice, and answer patients' questions.
[0003] In the prior art, question-answering systems usually rely on pre-trained large-scale language models, which are generative / autoregressive models trained with a large amount of medical literature and clinical data. However, generative / autoregressive models can easily produce misleading answers, sometimes generating seemingly reasonable but actually wrong or inaccurate answers. In the medical field, such errors can lead to serious consequences, such as misleading patients or doctors to make wrong diagnoses and treatment decisions.
[0004] Therefore, the present invention proposes a medical question-and-answer method to obtain more professional and accurate responses to medical questions. Summary of the invention
[0005] The present invention provides a medical question-and-answer method, device, electronic device and storage medium to solve the technical problem of low accuracy of answers in the medical question-and-answer process.
[0006] According to one aspect of the present invention, a medical question-answering method is provided, the method comprising:
[0007] obtaining a medical problem and a plurality of reference questions corresponding to the medical problem;
[0008] Inputting the medical problem and each of the reference problems into a pre-trained embedding model respectively, and determining a preset number of candidate problems in each of the reference problems that match the medical problem;
[0009] Inputting the medical problem and each of the candidate problems into a pre-trained classification model, and determining a target problem among each of the candidate problems that matches the medical problem;
[0010] An answer to the target question is determined, and the answer is used as a response to the medical question.
[0011] According to another aspect of the present invention, a medical question-answering device is provided. The device comprises:
[0012] A question acquisition module, used for acquiring a medical question and a plurality of reference questions corresponding to the medical question;
[0013] A first matching module, used to input the medical question and each of the reference questions into a pre-trained embedding model, and determine a preset number of candidate questions in each of the reference questions that match the medical question;
[0014] A second matching module is used to input the medical problem and each of the candidate problems into a pre-trained classification model to determine a target problem among each of the candidate problems that matches the medical problem;
[0015] The answer determination module is used to determine the answer to the target question and use the answer as the response to the medical question.
[0016] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising:
[0017] at least one processor; and
[0018] a memory communicatively connected to the at least one processor; wherein,
[0019] The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the medical question-and-answer method described in any embodiment of the present invention.
[0020] According to another aspect of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to implement the medical question-and-answer method described in any embodiment of the present invention when executed by a processor.
[0021] The technical solution of the embodiment of the present invention obtains a medical problem and multiple reference questions corresponding to the medical problem. The medical problem and each of the reference questions are respectively input into a pre-trained embedding model to determine a preset number of candidate questions in each of the reference questions that match the medical problem. In this technical solution, multiple candidate questions with a high similarity to the medical problem can be selected relatively quickly and accurately through the embedding model. Afterwards, the medical problem and each of the candidate questions are input into a pre-trained classification model to relatively accurately select the target question that best matches the medical problem in each of the candidate questions. Then, the answer to the target question is determined, and the answer to the question is used as the question response to the medical problem. The technical solution of the embodiment of the present invention solves the technical problem of low accuracy of the response answer in the existing medical question-and-answer process, achieves more professional and accurate responses to medical problems, and improves the accuracy of medical questions and answers.
[0022] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present invention, nor are they intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0024] Figure 1 A flowchart of a medical question-and-answer method provided by an embodiment of the present invention;
[0025] Figure 2 A flowchart of a medical question-and-answer method provided by an embodiment of the present invention;
[0026] Figure 3 A schematic diagram of training an embedding model applicable to the medical question-answering method provided in an embodiment of the present invention;
[0027] Figure 4 A flowchart of a medical question-and-answer method provided by an embodiment of the present invention;
[0028] Figure 5 A schematic diagram of training a classification model applicable to the medical question-answering method provided in an embodiment of the present invention;
[0029] Figure 6 A schematic diagram of the structure of a medical question-and-answer device provided by an embodiment of the present invention;
[0030] Figure 7 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0031] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.
[0032] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0033] It is understandable that the data involved in this technical solution (including but not limited to the data itself, the acquisition or use of the data) shall comply with the requirements of relevant laws, regulations and relevant provisions.
[0035] Figure 1 A flowchart of a medical question-and-answer method provided in an embodiment of the present invention. This embodiment is applicable to situations where medical questions are answered. The method can be performed by a medical question-and-answer device, which can be implemented in the form of hardware and / or software. The medical question-and-answer device can be configured in an electronic device such as a computer or a server.
[0036] like Figure 1 As shown, the method of this embodiment includes:
[0037] S110, obtaining a medical problem and a plurality of reference questions corresponding to the medical problem.
[0038] Among them, medical questions can be understood as medical questions to be answered. The number of medical questions can be one, two, or more than two. In an embodiment of the present invention, the way of obtaining medical questions can be specifically to receive medical questions input by the user based on an input device, wherein the input device can be a physical input device (such as a mouse, keyboard and / or writing device, etc.) and / or a touch device (such as a virtual keyboard and / or handwriting area, etc.). Reference questions can be understood as historical medical questions with standard answers. In an embodiment of the present invention, obtaining multiple reference questions corresponding to the medical questions can include: determining a medical question database; the medical question database can be used to store multiple historical medical questions with standard answers. The multiple historical medical questions stored in the medical question database are used as multiple reference questions corresponding to the medical questions. In an embodiment of the present invention, the number of medical question databases can be one, two, or more than two.
[0039] In an embodiment of the present invention, multiple historical medical questions in at least one medical question database may be used as multiple reference questions corresponding to the medical question. Optionally, in order to improve the accuracy of the answer to the medical question, all historical medical questions in all medical question data may be used as multiple reference questions corresponding to the medical question to provide a large amount of historical medical questions.
[0040] S120, respectively inputting the medical problem and each of the reference problems into a pre-trained embedding model, and determining a preset number of candidate questions in each of the reference problems that match the medical problem.
[0041] Among them, the pre-trained embedding model can be an embedding model based on BERT fine-tuning, which can be used to match a preset number of candidate questions that match the medical problem from each of the reference questions. In an embodiment of the present invention, using a pre-trained embedding model, multiple candidate questions can be selected from a large number of reference questions relatively quickly, shortening the response time for medical questions and effectively improving the efficiency of responding to medical questions. In an embodiment of the present invention, the preset number can be set or adjusted according to actual needs, and its value is not specifically limited here, for example, 10, 50 or 100, etc. Candidate questions can be understood as a preset number of historical medical questions that match the medical problem in multiple reference questions.
[0042] In an embodiment of the present invention, respectively inputting the medical problem and each of the reference problems into a pre-trained embedding model to determine a preset number of candidate problems in each of the reference problems that match the medical problem may include: inputting the medical problem into the pre-trained embedding model to obtain a first embedding vector of the medical problem; inputting each of the reference problems into the pre-trained embedding model to obtain a second embedding vector of each of the reference problems; calculating the vector distance between the first embedding vector and each of the second embedding vectors; and determining a preset number of candidate problems in each of the reference problems that match the medical problem based on the vector distances.
[0043] Among them, the first embedding vector can be understood as the embedding vector of the medical problem. The second embedding vector can be understood as the embedding vector of the reference problem. The vector distance can be understood as the distance between the first embedding vector and the second embedding vector, which can be used to represent the similarity between the medical problem and the reference problem. It can be understood that the larger the vector distance between the first embedding vector and the second embedding vector, the smaller the similarity between the first embedding vector and the second embedding vector; the smaller the vector distance between the first embedding vector and the second embedding vector, the greater the similarity between the first embedding vector and the second embedding vector.
[0044] Specifically, the medical problem can be first input into the pre-trained embedding model to obtain the embedding vector of the medical problem, that is, to obtain the first embedding vector. Then, each reference problem can be input into the pre-trained embedding model in turn to obtain the embedding vector of each reference problem, that is, to obtain each second embedding vector. Alternatively, each reference problem can be first input into the pre-trained embedding model in turn to obtain the second embedding vector of each reference problem. Then, the medical problem can be input into the pre-trained embedding model in turn to obtain the first embedding vector of the medical problem.
[0045] After obtaining the first embedding vector and each second embedding vector, the vector distance between the first embedding vector and each second embedding vector can be calculated based on the first embedding vector and each second embedding vector. Therefore, based on each vector distance, a preset number of candidate questions matching the medical question in each reference question can be determined. In an embodiment of the present invention, calculating the vector distance between the first embedding vector and each second embedding vector can specifically include: for each second embedding vector, calculating the vector distance between the second embedding vector and the first embedding vector. Specifically, the cosine similarity between the second embedding vector and the first embedding vector can be calculated, and the cosine similarity can be used as the vector distance between the second embedding vector and the first embedding vector.
[0046] In an embodiment of the present invention, the determination of a preset number of candidate questions matching the medical question in each of the reference questions based on each of the vector distances may include: selecting a preset number of reference questions in order of vector distance from small to large as candidate questions matching the medical question, that is, determining a preset number of candidate questions matching the medical question in each of the reference questions. Exemplarily, the preset number may be 3, and the reference questions may include question A, question B, question C, question D, question E, question F, and question G. The vector distances between the medical question and each of the reference questions may be 0.7, 0.1, 0.2, 0.5, 0.3, 0.8, and 0.4, respectively. Then, three reference questions are selected in order of vector distance from small to large, namely, question B, question C, and question E, that is, the candidate questions include question B, question C, and question E.
[0047] S130, inputting the medical problem and each of the candidate questions into a pre-trained classification model, and determining a target question among each of the candidate questions that matches the medical problem.
[0048] Among them, the pre-trained classification model can be a classification model based on BERT fine-tuning, which can be used to match the target question that best matches the target medical question from each of the candidate questions. In an embodiment of the present invention, using a pre-trained classification model, the target question can be matched more accurately from multiple candidate questions, and a more professional and accurate response can be obtained for the medical question, thereby improving the accuracy of medical questions and answers. The target question can be understood as the question that best matches the medical question among the candidate questions.
[0049] In an embodiment of the present invention, the step of inputting the medical problem and each of the candidate questions into a pre-trained classification model to determine a target question among each of the candidate questions that matches the medical problem may include: inputting the medical problem and each of the candidate questions into a pre-trained classification model to obtain the similarity between the medical problem and each of the candidate questions; and taking the candidate question with the greatest similarity to the medical problem as the target question corresponding to the medical problem.
[0050] Optionally, the medical problem and each candidate problem are input into a pre-trained classification model to obtain the similarity between the medical problem and each candidate problem, which may specifically include: for each candidate problem, the candidate problem and the medical problem are combined (e.g., spliced, etc.). Thus, each combined data can be obtained. Then, each combined data can be input into a pre-trained classification model. Thus, the similarity score output by the classification model for each combined data can be obtained. Thus, based on each similarity score, the similarity between the medical problem and each candidate problem can be determined.
[0051] Furthermore, the method of using the candidate question with the greatest similarity to the medical question as the target question corresponding to the medical question may specifically include determining the combined data with the greatest similarity score. Thus, the candidate question included in the combined data with the greatest similarity score may be used as the candidate question with the greatest similarity to the medical question, that is, the target question that best matches the medical question.
[0052] It should be noted that the sample problem for training the embedding model and the sample problem for training the classification model can be the same or different.
[0053] S140, determining an answer to the target question, and using the answer as a response to the medical question.
[0054] Specifically, after determining the target question, the answer to the question corresponding to the target question can be determined according to the correspondence between the question and the answer, so that the answer to the question can be used as the question reply corresponding to the medical question.
[0055] Based on the above embodiment, when the data format of the medical problem is not in the target format, the data format of the medical problem can be converted into the target format, wherein the target format is a format recognizable by the embedding model and the classification model. Optionally, the target format can be a digital format. In other words, the specific expression of the medical problem is digital information.
[0056] Specifically, when the data format of the medical question is in audio format, the data format of the medical question can be converted from audio format to text format first. After that, the data format of the medical question can be converted from text format to target format. So that the medical question in the target format can be recognized by the embedding model and the classification model. In short, the text information of the medical question is converted into a token. Specifically, the text information of the medical question can be processed by text segmentation, so as to obtain the token of the medical question based on the result of the segmentation processing.
[0057] Based on the above embodiment, after obtaining the answer to the medical question, if the data format of the answer to the question is not in the preset format, the data format of the answer to the question can be converted to the preset format. The preset format can be set according to requirements, for example, text format and / or audio format.
[0058] It should be noted that, in the embodiment of the present invention, before the medical questions and reference questions are input into the embedding model and the classification model, the data format of the medical questions and the reference questions can be a data format recognizable by the embedding model and the classification model. In other words, the medical questions and the reference questions can be digital information.
[0059] The technical solution of the embodiment of the present invention obtains a medical problem and multiple reference questions corresponding to the medical problem. The medical problem and each of the reference questions are respectively input into a pre-trained embedding model to determine a preset number of candidate questions in each of the reference questions that match the medical problem. In this technical solution, multiple candidate questions with a high similarity to the medical problem can be selected relatively quickly and accurately through the embedding model. Afterwards, the medical problem and each of the candidate questions are input into a pre-trained classification model to relatively accurately select the target question that best matches the medical problem in each of the candidate questions. Then, the answer to the target question is determined, and the answer to the question is used as the question response to the medical problem. The technical solution of the embodiment of the present invention solves the technical problem of low accuracy of the response answer in the existing medical question-and-answer process, achieves more professional and accurate responses to medical problems, and improves the accuracy of medical questions and answers.
[0061] Figure 2A flow chart of a medical question-and-answer method provided for an embodiment of the present invention. Based on the aforementioned embodiment, optionally, the medical question-and-answer method implemented by the present invention further includes: obtaining first sample data and first expected data corresponding to the first sample data, wherein the first sample data includes a first question and a second question, and the first expected data is a first label corresponding to the sample data pair, and the first label is used to indicate whether the first question and the second question are the same question; respectively inputting the first question and the second question into a pre-constructed embedding model to obtain a third embedding vector for the first question and a fourth embedding vector for the second question; calculating the cosine similarity between the third embedding vector and the fourth embedding vector, and adjusting the model parameters of the pre-constructed embedding model based on the cosine similarity and the expected data to obtain a trained embedding model. Among them, technical features that are the same or similar to those in the aforementioned embodiment will not be repeated here. Figure 2 As shown, the method of this embodiment specifically includes:
[0062] S210. Obtain first sample data and first expected data corresponding to the first sample data, wherein the first sample data includes a first question and a second question, the first expected data is a first label corresponding to the sample data pair, and the first label is used to indicate whether the first question and the second question are the same question.
[0063] Among them, the first sample data and the first expected data can be used to train a pre-built embedding model. In an embodiment of the present invention, the first sample data may include a first question and a second question. The first question and the second question may be two identical questions, or may be two different questions. The first expected data is a first label corresponding to the sample data pair, and the first label is used to indicate whether the first question and the second question are the same question. Exemplarily, if the first question and the second question are the same question, the first label can be set to 1. If the first question and the second question are not the same question, the first label can be set to -1.
[0064] S220: Input the first question and the second question into a pre-built embedding model respectively to obtain a third embedding vector of the first question and a fourth embedding vector of the second question.
[0065] The pre-built embedding may be a pre-trained model based on BERT. The third embedding vector may be understood as the embedding vector of the first question in the first sample data. The fourth embedding vector may be understood as the embedding vector of the second question in the first sample data.
[0066] Specifically, the first question may be input into a pre-built embedding model to obtain an embedding vector of the first question, i.e., a third embedding vector. Afterwards, the second question may be input into the pre-built embedding model to obtain an embedding vector of the second question, i.e., a fourth embedding vector.
[0067] S230, calculating the cosine similarity between the third embedding vector and the fourth embedding vector, and adjusting the model parameters of the pre-built embedding model based on the cosine similarity and the expected data to obtain a trained embedding model.
[0068] Specifically, the cosine similarity between the third embedding vector and the fourth embedding vector is calculated. After obtaining the cosine similarity, the cosine similarity can be compared with the expected data. In the case that the cosine similarity is inconsistent with the expected data, the model parameters of the pre-constructed embedding model can be adjusted. When the number of adjustments reaches a first preset number of adjustments; or, when the cosine similarity output by the embedding model reaches a first preset error condition; or, when the loss function reaches a first preset convergence condition, the model training can be stopped. Thereby, a trained embedding model is obtained. In an embodiment of the present invention, the first preset number of adjustments, the first preset error condition, and the first preset convergence condition can be set according to actual needs, which are not specifically limited here.
[0069] It should be noted that during the training of the embedding model, if the first question and the second question are the same, the label is 1. The training goal of the model is that the third embedding vector is equal to the fourth embedding vector, that is, the cosine similarity loss is as small as possible; if the first question and the second question are different, the label is -1. The training goal of the model is that the third embedding vector is not equal to the fourth embedding vector, that is, the cosine loss function is as large as possible.
[0070] Optionally, the cosine similarity between the third embedding vector and the fourth embedding vector may be calculated according to the following formula:
[0071]
[0072] Among them, CosineEmbeddingLoss can be expressed as the loss function of the embedding model, which can be used to calculate the cosine similarity between the third embedding vector and the fourth embedding vector. embeddingA can be expressed as the third embedding vector. embeddingB can be expressed as the fourth embedding vector. marge is expressed as a hyperparameter from 0 to 1. Among them, in, It can be expressed as embeddingA, the third embedding vector. It can be expressed as embeddingB, the fourth embedding vector.
[0073] See also Figure 3 , the medical question can be question A, the reference question can be question B, and the pre-built embedding model can be bert_E. Then, the training process of bert_E can be specifically as follows: input question A into bert_E to obtain embeddingA, and input question B into bert_E to obtain embeddingB. After obtaining embeddingA and embeddingB, the cosine similarity of embeddingA and embeddingB can be calculated. Therefore, based on the cosine similarity and the labels corresponding to question A and question B, the parameters of bert_E are adjusted to obtain the trained embedding model.
[0074] S240, obtaining a medical problem and a plurality of reference questions corresponding to the medical problem; respectively inputting the medical problem and each of the reference questions into a pre-trained embedding model, and determining a preset number of candidate questions in each of the reference questions that match the medical problem.
[0075] S250, input the medical question and each candidate question into a pre-trained classification model, determine a target question among each candidate question that matches the medical question; determine the answer to the target question, and use the answer as a question response to the medical question.
[0076] The technical solution of the embodiment of the present invention is to obtain first sample data and first expected data corresponding to the first sample data, wherein the first sample data includes a first question and a second question, and the first expected data is a first label corresponding to the sample data pair, and the first label is used to indicate whether the first question and the second question are the same question; the first question and the second question are respectively input into a pre-constructed embedding model to obtain a third embedding vector of the first question and a fourth embedding vector of the second question; the cosine similarity between the third embedding vector and the fourth embedding vector is calculated, and the model parameters of the pre-constructed embedding model are adjusted based on the cosine similarity and the expected data to obtain a trained embedding model, so that the trained embedding model can quickly and accurately select multiple candidate questions with high similarity to medical problems.
[0078] Figure 4 A flow chart of a medical question-and-answer method provided for an embodiment of the present invention. Based on the aforementioned embodiment, optionally, the medical question-and-answer method implemented by the present invention further includes: obtaining second sample data and second expected data corresponding to the second sample data, wherein the second sample data is a question pair including a third question, and the second expected data is a second label corresponding to the question pair, and the second label is used to indicate whether the third question and the fourth question in the question pair are the same question; inputting the question pair into a pre-constructed classification model to obtain an actual output result, determining a loss function value based on the actual output result and the second expected data, and adjusting the model parameters of the pre-constructed classification model based on the loss function value to obtain a trained classification model. Among them, technical features that are the same or similar to those in the aforementioned embodiment will not be repeated here. Figure 4 As shown, the method of this embodiment specifically includes:
[0079] S310. Obtain second sample data and second expected data corresponding to the second sample data, wherein the second sample data is a question pair including a third question, the second expected data is a second label corresponding to the question pair, and the second label is used to indicate whether the third question and the fourth question in the question pair are the same question.
[0080] Among them, the second sample data and the second expected data can be used to train a pre-built classification model. In an embodiment of the present invention, the second sample data can be a question pair including the third question. That is, the second sample data can be obtained by combining the third question and other historical medical questions. It should be noted that other historical medical questions may include the third question or may not include the third question. The second expected data is a second label corresponding to the question pair. The second label can be used to indicate whether the third question and the fourth question in the question pair are the same question. Exemplarily, if the third question and the fourth question are the same question, the first label can be set to 1. If the third question and the fourth question are not the same question, the first label can be set to 0.
[0081] S320. Input the problem pair into a pre-constructed classification model to obtain an actual output result, determine a loss function value based on the actual output result and the second expected data, and adjust the model parameters of the pre-constructed classification model based on the loss function value to obtain a trained classification model.
[0082] Among them, the pre-built classification model can be a pre-trained model based on BERT. The actual output result can be understood as the similarity output by the pre-built classification model for the third question and the fourth question in the question pair. In other words, the actual output result can be used to represent the similarity between the third question and the fourth question in the question pair. Optionally, the question pair input to the pre-built classification model can include a token for the medical question and a token for the candidate question.
[0083] Specifically, a classification model is pre-constructed first. Afterwards, the problem pair can be input into the pre-constructed classification model to obtain an actual output result. Then, the loss function value can be determined based on the actual output result and the second expected data. Thus, the model parameters of the pre-constructed classification model can be adjusted based on the loss function value. When the number of adjustments reaches the second preset number of adjustments; or, when the actual output result output by the classification model reaches the first preset error condition; or, when the loss function reaches the first preset convergence condition, the model training can be stopped. Thus, a trained classification model is obtained. In an embodiment of the present invention, the second preset number of adjustments, the second preset error condition, and the second preset convergence condition can be set according to actual needs, and they are not specifically limited here.
[0084] In this embodiment of the present invention, the loss function of the classification model is a cross entropy loss function, which can be expressed by the following formula:
[0085] CrossEntropyLoss=-(y label ·log(ypredict )+(1-y label )·log(1-y predict ))
[0086] Among them, y label It can be expressed as the second expected data corresponding to the second sample data. predict It can be expressed as the actual output result obtained after the second sample data is input into the classification model.
[0087] Using the above example, see Figure 5 , the medical problem is question A, and the candidate questions may include question 1, question 2, ..., question K. The pre-built classification model is bert_C. Then, the training process of bert_C may specifically include: for each candidate question, combining the candidate question and question A. Thus, question A+question 1, question A+question 1, ..., question A+question K can be obtained. Afterwards, each combination is input into bert_C, and the score output by bert_C for each combination can be obtained, that is, the similarity of the two questions included in the combination. Then, bert_C can be adjusted based on the relative degrees and the labels of the combinations, so that a trained classification model can be obtained.
[0088] S330, obtaining a medical problem and a plurality of reference questions corresponding to the medical problem; inputting the medical problem and each of the reference questions into a pre-trained embedding model respectively, and determining a preset number of candidate questions in each of the reference questions that match the medical problem.
[0089] S340, input the medical question and each candidate question into a pre-trained classification model, determine a target question among each candidate question that matches the medical question; determine the answer to the target question, and use the answer as a question response to the medical question.
[0090] The technical solution of the embodiment of the present invention is to obtain second sample data and second expected data corresponding to the second sample data, wherein the second sample data is a question pair including a third question, the second expected data is a second label corresponding to the question pair, and the second label is used to indicate whether the third question and the fourth question in the question pair are the same question; the question pair is input into a pre-constructed classification model to obtain an actual output result, a loss function value is determined based on the actual output result and the second expected data, and the model parameters of the pre-constructed classification model are adjusted based on the loss function value to obtain a trained classification model, so that the trained classification model can more accurately select the target question that best matches the medical question from each candidate question, thereby improving the accuracy of medical questions and answers.
[0092] Figure 6 FIG. 1 is a schematic diagram of the structure of a medical question-answering device provided by an embodiment of the present invention. Figure 6 As shown, the device includes: a question acquisition module 410, a first matching module 420, a second matching module 430 and an answer determination module 440.
[0093] Among them, the question acquisition module 410 is used to obtain a medical question and multiple reference questions corresponding to the medical question; the first matching module 420 is used to input the medical question and each reference question into a pre-trained embedding model respectively, and determine a preset number of candidate questions matching the medical question in each reference question; the second matching module 430 is used to input the medical question and each candidate question into a pre-trained classification model, and determine a target question matching the medical question in each candidate question; the answer determination module 440 is used to determine the answer to the target question, and use the answer to the question as the question response to the medical question.
[0094] The technical solution of the embodiment of the present invention obtains a medical problem and a plurality of reference questions corresponding to the medical problem through a question acquisition module. The medical problem and each of the reference questions are respectively input into a pre-trained embedding model through a first matching module to determine a preset number of candidate questions matching the medical problem in each of the reference questions. In this technical solution, a plurality of candidate questions with a high similarity to the medical problem can be selected relatively quickly and accurately through the embedding model. Afterwards, the medical problem and each of the candidate questions are input into a pre-trained classification model through a second matching module, and the target question that best matches the medical problem in each of the candidate questions can be selected relatively accurately. The answer to the target question is then determined through an answer determination module, and the answer to the question is used as the question reply to the medical problem. The technical solution of the embodiment of the present invention solves the technical problem of low accuracy of the reply answer in the existing medical question-answering process, achieves more professional and accurate replies to medical problems, and improves the accuracy of medical questions-answering.
[0095] Optionally, the first matching module 420 is specifically used to input the medical problem into a pre-trained embedding model to obtain a first embedding vector of the medical problem; input each reference problem into the pre-trained embedding model to obtain a second embedding vector of each reference problem; calculate the vector distance between the first embedding vector and each second embedding vector; and based on each vector distance, determine a preset number of candidate questions in each reference problem that match the medical problem.
[0096] Optionally, the second matching module 430 is specifically used to input the medical problem and each candidate question into a pre-trained classification model to obtain the similarity between the medical problem and each candidate question; and use the candidate question with the greatest similarity to the medical problem as the target question corresponding to the medical problem.
[0097] Optionally, the device also includes a first training module; wherein the first training module is used to obtain first sample data and first expected data corresponding to the first sample data, wherein the first sample data includes a first question and a second question, the first expected data is a first label corresponding to the sample data pair, and the first label is used to indicate whether the first question and the second question are the same question; the first question and the second question are respectively input into a pre-constructed embedding model to obtain a third embedding vector of the first question and a fourth embedding vector of the second question; the cosine similarity between the third embedding vector and the fourth embedding vector is calculated, and the model parameters of the pre-constructed embedding model are adjusted based on the cosine similarity and the expected data to obtain a trained embedding model.
[0098] Optionally, the device also includes a second training module; wherein the second training module is used to obtain second sample data and second expected data corresponding to the second sample data, wherein the second sample data is a question pair including a third question, the second expected data is a second label corresponding to the question pair, and the second label is used to indicate whether the third question and the fourth question in the question pair are the same question; the question pair is input into a pre-constructed classification model to obtain an actual output result, a loss function value is determined based on the actual output result and the second expected data, and the model parameters of the pre-constructed classification model are adjusted based on the loss function value to obtain a trained classification model.
[0099] Optionally, the question acquisition module 410 includes an acquisition unit; wherein the acquisition unit is used to determine a database corresponding to the medical problem, and use the questions stored in the database as multiple reference questions corresponding to the medical problem.
[0100] Optionally, the device also includes a format conversion module; wherein the format conversion module is used to convert the data format of the medical problem into a target format after obtaining the medical problem, if the data format of the medical problem is not the target format, wherein the target format is a format recognizable by the embedding model and the classification model.
[0101] The medical question-and-answer device provided in the embodiment of the present invention can execute the medical question-and-answer method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0102] It is worth noting that the various units and modules included in the above-mentioned medical question-and-answer device are only divided according to functional logic, but are not limited to the above-mentioned division, as long as the corresponding functions can be achieved; in addition, the specific names of the functional units are only for the convenience of distinguishing each other, and are not used to limit the protection scope of the embodiments of the present invention.
[0104] Figure 7 A schematic diagram of the structure of an electronic device 10 that can be used to implement an embodiment of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.
[0105] like Figure 7As shown, the electronic device 10 includes at least one processor 11, and a memory connected to the at least one processor 11, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 to the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other through a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0106] A number of components in the electronic device 10 are connected to the I / O interface 15, including: an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0107] The processor 11 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 11 executes the various methods and processes described above, such as the medical question-answering method.
[0108] In some embodiments, the medical question-and-answer method may be implemented as a computer program that is tangibly contained in a computer-readable storage medium, such as a storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the medical question-and-answer method described above may be performed. Alternatively, in other embodiments, the processor 11 may be configured to perform the medical question-and-answer method in any other suitable manner (e.g., by means of firmware).
[0109] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0110] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the computer program is executed by the processor, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer program may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0111] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in combination with an instruction execution system, device or equipment. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0112] To provide interaction with a user, the systems and techniques described herein may be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).
[0113] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0114] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The client and server relationship is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services.
[0115] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps described in the present invention can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution of the present invention can be achieved, and this document does not limit this.
[0116] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A medical question-answering method, characterized in that: The method comprises: obtaining a medical problem and a plurality of reference questions corresponding to the medical problem; Inputting the medical problem and each of the reference problems into a pre-trained embedding model respectively, and determining a preset number of candidate problems in each of the reference problems that match the medical problem; Inputting the medical problem and each of the candidate questions into a pre-trained classification model, and determining a target question among each of the candidate questions that matches the medical problem; An answer to the target question is determined, and the answer is used as a response to the medical question.
2. The method according to claim 1, characterized in that The step of inputting the medical question and each of the reference questions into a pre-trained embedding model to determine a preset number of candidate questions in each of the reference questions that match the medical question comprises: Input the medical problem into a pre-trained embedding model to obtain a first embedding vector of the medical problem; Input each reference question into the pre-trained embedding model to obtain a second embedding vector of each reference question; Calculate the vector distance between the first embedding vector and each of the second embedding vectors; Based on each of the vector distances, a preset number of candidate questions matching the medical question are determined in each of the reference questions.
3. The method according to claim 1, characterized in that: The step of inputting the medical problem and each of the candidate problems into a pre-trained classification model, and determining a target problem among each of the candidate problems that matches the medical problem, comprises: Inputting the medical problem and each of the candidate problems into a pre-trained classification model to obtain the similarity between the medical problem and each of the candidate problems; The candidate question with the greatest similarity to the medical question is used as the target question corresponding to the medical question.
4. The method according to claim 1, characterized in that: The method further comprises: Acquire first sample data and first expected data corresponding to the first sample data, wherein the first sample data includes a first question and a second question, the first expected data is a first label corresponding to the sample data pair, and the first label is used to indicate whether the first question and the second question are the same question; Inputting the first question and the second question into a pre-built embedding model respectively to obtain a third embedding vector of the first question and a fourth embedding vector of the second question; The cosine similarity between the third embedding vector and the fourth embedding vector is calculated, and model parameters of the pre-constructed embedding model are adjusted based on the cosine similarity and the expected data to obtain a trained embedding model.
5. The method according to claim 1, characterized in that: The method further comprises: Acquire second sample data and second expected data corresponding to the second sample data, wherein the second sample data is a question pair including a third question, the second expected data is a second label corresponding to the question pair, and the second label is used to indicate whether the third question and a fourth question in the question pair are the same question; The problem pair is input into a pre-built classification model to obtain an actual output result, a loss function value is determined based on the actual output result and the second expected data, and the model parameters of the pre-built classification model are adjusted based on the loss function value to obtain a trained classification model.
6. The method according to claim 1, characterized in that A plurality of reference questions corresponding to the medical problem are obtained, including: A database corresponding to the medical problem is determined, and the questions stored in the database are used as a plurality of reference questions corresponding to the medical problem.
7. The method according to claim 1, characterized in that After obtaining the medical problem, the method further includes: When the data format of the medical question is not in a target format, the data format of the medical question is converted into a target format, wherein the target format is a format recognizable by the embedding model and the classification model.
8. A medical question-and-answer device, characterized in that: The device comprises: A question acquisition module, used for acquiring a medical question and a plurality of reference questions corresponding to the medical question; A first matching module, used to input the medical question and each of the reference questions into a pre-trained embedding model, and determine a preset number of candidate questions in each of the reference questions that match the medical question; A second matching module is used to input the medical problem and each of the candidate problems into a pre-trained classification model to determine a target problem among each of the candidate problems that matches the medical problem; The answer determination module is used to determine the answer to the target question and use the answer as the response to the medical question.
9. An electronic device, characterized in that: The electronic device comprises: at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can perform the medical question-and-answer method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the medical question-and-answer method according to any one of claims 1 to 7 when executed.