Question answering method, related device, equipment and storage medium
By generating query instructions to call date sources and generating computer code to perform date calculations in combination with problem statements, the problems of low date calculation accuracy and high cost in the prior art are solved, and high-precision date calculation questions are realized.
Patent Information
- Application Number
- CN202411940905.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-26
- Publication Date
- 2025-04-15
AI Technical Summary
In the answers to date calculation questions, the prior art strongly relies on date sources, which makes it difficult to meet the accuracy, and the model's own reasoning is prone to errors, which increases cost and complexity.
By detecting whether the question statement to be answered needs to be calculated by date, a query instruction is generated for calling the date source, the feedback results are obtained, and computer code is generated based on the question statement and feedback results, date calculation is performed, and finally an answer statement is generated.
It reduces the construction cost of date sources, improves the accuracy of answering date calculation questions, and adapts to complex factors such as calendar rules, time zone conversion and leap year judgment.
Smart Images

Figure CN119831046A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of natural language processing technology, and in particular to a question answering method and related devices, equipment and storage media. Background Art
[0002] With the continuous advancement of artificial intelligence technology, question answering technology has been widely used in business offices, daily life and other scenarios, among which date calculation is one of its important functions.
[0003] At present, in the existing question answering technologies involving date calculation, usually either directly call the date source to give a direct answer, or the model combines the source information with its own reasoning ability to infer the answer. However, the former is strongly dependent on the date source, and the accuracy is difficult to meet, and the support scope and support capabilities of the public source are time-consuming, labor-intensive, and extremely costly; while the latter is dependent on the model's own reasoning ability, which is prone to reasoning errors because date calculation involves factors such as legislative rules, time zone conversion, and leap year judgment rather than simple linear operations. In view of this, how to improve the accuracy of answering date calculation questions while reducing the construction cost of the date source as much as possible has become an urgent problem to be solved. Summary of the invention
[0004] The main technical problem solved by the present application is to provide a question answering method and related devices, equipment and storage media, which can improve the accuracy of answering date calculation questions while reducing the construction cost of date information sources as much as possible.
[0005] In order to solve the above technical problems, the first aspect of the present application provides a question answering method, including: in response to detecting that a question statement to be answered requires date calculation, based on the question statement, generating a query instruction for calling a date information source, calling the date information source based on the query instruction, obtaining a feedback result of the date query, and based on the question statement and the feedback result, generating a computer code for performing date calculation, and running the computer code based on the feedback result to obtain a calculation result of the date calculation; at least based on the question statement and the calculation result, generating an answer statement to reply to the question statement.
[0006] In order to solve the above technical problems, the second aspect of the present application provides a question answering device, including: a date calculation module and a reply generation module, the date calculation module is used to respond to the detection that the question statement to be answered needs to be calculated by date, generate a query instruction for calling a date source based on the question statement, call the date source based on the query instruction, obtain feedback results of the date query, and generate computer code for performing date calculation based on the question statement and the feedback result, and run the computer code based on the feedback result to obtain calculation results of the date calculation; the reply generation module is used to generate a reply statement to reply to the question statement based on at least the question statement and the calculation result.
[0007] In order to solve the above technical problems, the third aspect of the present application provides an electronic device, which at least includes a memory and a processor coupled to each other, the memory at least stores program instructions, and the processor is used to execute the program instructions to implement the question answering method in the above first aspect.
[0008] In order to solve the above technical problem, the fourth aspect of the present application provides a computer-readable storage medium, which stores program instructions that can be executed by a processor, and the program instructions are used to implement the question answering method of the first aspect.
[0009] In the above scheme, in response to detecting that the question statement to be answered needs to be calculated by date, a query instruction for calling the date information source is generated based on the question statement, the date information source is called based on the query instruction, the feedback result of the date query is obtained, and a computer code for executing the date calculation is generated based on the question statement and the feedback result, and the computer code is run based on the feedback result to obtain the calculation result of the date calculation, and then based on this, at least based on the question statement and the calculation result, an answer statement for replying to the question statement is generated. Therefore, on the one hand, since the date query is only performed by relying on the date information source without directly performing the date calculation, the construction cost of the date information source can be reduced as much as possible. On the other hand, after obtaining the feedback result of the date information source, a computer code for executing the date calculation is generated in combination with the question statement, and the calculation result of the date calculation is obtained by running the computer code based on the feedback result. Compared with realizing date calculation through model reasoning, realizing date calculation through computer code is more adaptable to factors such as calendar rules, time zone conversion, leap year judgment, etc., which helps to improve the accuracy of date calculation. Therefore, the answer accuracy of date calculation questions can be improved under the premise of reducing the construction cost of the date information source as much as possible. BRIEF DESCRIPTION OF THE DRAWINGS
[0010] Figure 1 It is a flowchart of an embodiment of a method for answering questions of this application; Figure 2 It is a process diagram of an embodiment of the method for answering questions of the present application; Figure 3It is a schematic diagram of the framework of an embodiment of the question answering device of the present application; Figure 4 It is a schematic diagram of the framework of an embodiment of the electronic device of the present application; Figure 5 It is a schematic diagram of a framework of an embodiment of a computer-readable storage medium of the present application. DETAILED DESCRIPTION
[0011] The scheme of the embodiment of the present application is described in detail below in conjunction with the drawings of the specification.
[0012] In the following description, for the purpose of explanation rather than limitation, specific details such as specific system structures, interfaces, and technologies are provided to facilitate a thorough understanding of the present application.
[0013] The terms "system" and "network" are often used interchangeably in this article. The term "and / or" in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, the fragment " / " in this article generally indicates that the associated objects before and after are in an "or" relationship. In addition, "many" in this article means two or more than two.
[0014] See also Figure 1 , Figure 1 This is a flowchart of an embodiment of the method for answering questions in this application. Specifically, it may include the following steps: Step S11: In response to detecting that the question statement to be answered needs to be subjected to date calculation, a query instruction for calling a date information source is generated based on the question statement, the date information source is called based on the query instruction, and a feedback result of the date query is obtained, and based on the question statement and the feedback result, a computer code for executing the date calculation is generated, and the computer code is run based on the feedback result to obtain a calculation result of the date calculation.
[0015] In the embodiments of the present disclosure, the question statement needs to be characterized by date calculation: the question statement can and can only be answered after date calculation. Exemplarily, taking the question statement "How long is it from tomorrow to the Spring Festival" as an example, it can be answered after date calculation and can only be answered after date calculation, so the question statement is the "need to be calculated by date" described in the embodiments of the present disclosure; or, taking the question statement "According to convention, how long is it from the Dragon Boat Festival to the snowy day every year" as an example, since "snowy day" is not a fixed date, it cannot be calculated by date, so the question statement is not the "need to be calculated by date" described in the embodiments of the present disclosure; or, taking the question statement "Did the oil price rise today" as an example, since the answer to the question statement does not require date calculation, the question statement is also not the "need to be calculated by date" described in the embodiments of the present disclosure. Of course, the above examples are only a few possible examples of question statements in actual application, and the specific contents of the question statements will not be given one by one here.
[0016] In one implementation scenario, whether the question statement needs to be calculated by date can be detected by the question classification model. Specifically, in order to improve the accuracy of the question classification model, the question classification model can be trained in advance. Exemplarily, sample questions can be obtained first, and the sample questions can be marked with sample tags representing positive questions or negative questions. Positive questions need to be calculated by date (such as the aforementioned "How long is it until the Spring Festival tomorrow"), while negative questions cannot be calculated by date (such as the aforementioned "According to convention, how long is it until the snowy day from the Dragon Boat Festival every year"), or negative questions do not need to be calculated by date (such as the aforementioned "Did the oil price rise today"). On this basis, the sample questions can be detected based on the question classification model to obtain a prediction tag that represents the sample question as a positive question or a negative question, and the network parameters of the question classification model can be adjusted based on the difference between the sample tag and the prediction tag. In the above method, whether the question statement needs to be calculated by date is detected by the question classification model. By obtaining sample questions, the sample questions are marked with sample tags representing positive questions or negative questions, and positive questions need to be calculated by date, while negative questions do not need or cannot be calculated by date. Then, based on the question classification model, the sample questions are detected to obtain the prediction tags representing the sample questions as positive questions or negative questions. Then, based on the difference between the sample tags and the prediction tags, the network parameters of the question classification model are adjusted. Therefore, the question classification model can be forced to learn and model the problem representations that need to be calculated by date through positive and negative questions, especially negative questions, which helps to improve the accuracy of subsequent question classification.
[0017] In a specific implementation scenario, the question classification model can be a traditional network model, such as a convolutional neural network, etc.; or, the question classification model can also be a large language model, such as including but not limited to open source large models such as Bloom, LLAMA, etc., or can include but not limited to fine-tuning the parameters of an open source large model based on a specific corpus, or can also include but not limited to a custom large model. The specific source of the large language model is not limited here.
[0018] In a specific implementation scenario, as a possible example, a positive example problem can be represented by a sample label "1", and a negative example problem can be represented by a sample label "0". For example, the probability value of a sample problem predicted as a positive example problem and the probability value of a sample problem predicted as a negative example problem can be detected, and the sample label and the above probability value can be measured based on a loss function such as cross entropy to obtain the training loss of the problem classification model, and then the network parameters of the problem classification model can be adjusted based on the training loss of the problem classification model.
[0019] In an implementation scenario, as described above, a detection may be performed based on the question statement to determine whether the question statement requires date calculation. On this basis, in response to the question statement requiring date calculation, the above step S11 in the embodiment of the present disclosure may be executed until the answer statement of the question statement is obtained. On the contrary, in response to the question statement not requiring or being unable to undergo date calculation (such as the above example), the question statement may be directly processed based on the large language model to obtain an answer statement for the question statement. Still taking the above question statement "According to convention, how long is it from the Dragon Boat Festival to the snowy day every year" as an example, the above question statement may be directly processed by the large language model to obtain an answer statement: "According to convention, the local snowy day is generally in XX month, so according to convention, there are XX days from the Dragon Boat Festival to the snowy day. However, snowy days are affected by many environmental factors such as temperature, humidity, circulation, etc., and the above reasoning is for reference only", "Sorry, since snowy days are affected by many factors such as temperature, humidity, circulation, etc., it is impossible to calculate how many days are left from the Dragon Boat Festival to the snowy day", etc. Of course, the above examples are only several possible examples of answer statements when it is impossible or unnecessary to undergo date calculation, and other possible situations are not given one by one here. The above method first performs detection based on the question sentence to determine whether the question sentence needs to be calculated by date, and then responds to the question sentence that does not need or cannot be calculated by date by directly processing the question sentence based on the large language model to obtain an answer sentence in reply to the question sentence. This can avoid as much as possible the situation where question sentences that do not need to be calculated by date cannot be reasonably answered due to overfitting of the model, and helps to improve the rationality of the answers to the questions.
[0020] In one implementation scenario, when it is detected that the question statement to be answered needs to be calculated by date, a query instruction for calling the date source can be generated based on the question statement. Specifically, a first prompt instruction can be constructed based on the question statement, and the first prompt instruction is used to instruct the first large model to generate a query instruction for calling the date source for replying to the question statement, and then the first prompt instruction is input to the first large model to obtain the output instruction of the first large model as a query instruction. In the above method, the query instruction for calling the date source for replying to the question statement is generated for the question statement by the first large model, and the query instruction for the date source can be generated with the help of the general understanding ability of the large language model, which helps to improve the accuracy and pertinence of the date query.
[0021] In a specific implementation scenario, as a possible example, still taking the question sentence "How long until the Spring Festival tomorrow" as an example, the following first prompt instructions may be constructed, including but not limited to: Please generate a query for the question sentence "How long until the Spring Festival tomorrow?" and a date query for answering the question sentence. make.
[0022] After the first prompt instruction is input into the first large model, the following query instructions may be obtained, including but not limited to: What is the date tomorrow.
[0023] What is the date of Spring Festival?
[0024] Of course, the above example is only a possible example of the first prompt instruction and the query instruction, and does not limit other possible situations of the first prompt instruction and the query instruction. Other possible situations of the first prompt instruction and the query instruction will not be given one by one here.
[0025] In a specific implementation scenario, as mentioned above, the query instruction can be generated by the first large model. In order to improve the generation quality of the query instruction of the first large model, the first large model can be trained in advance. Specifically, the first sample data can be obtained first, and the first sample data can include the first sample question and the sample query instruction. The first sample question needs to be calculated by date, and the sample query instruction is used to call the date source to reply to the first sample question. Exemplarily, the first sample data can include the first sample question "How many days are there from today to the end of next month" and the sample query instructions "What is today's date" and "What is the date at the end of next month". Of course, the above example is only a possible example of the first sample data in the actual application process, and the specific content of the first sample data is not limited here. On this basis, the first sample question can be processed based on the first large model to generate a prediction query instruction. It should be noted that the specific process of generating the prediction query instruction can refer to the relevant description of generating the query instruction above, which will not be repeated here. After that, the network parameters of the first large model can be adjusted based on the difference between the prediction instruction query and the sample query instruction. In the above method, the first sample data is obtained to process the first sample problem based on the first large model, generate a predictive query instruction, and then adjust the network parameters of the first large model based on the difference between the predictive query instruction and the sample query instruction. Therefore, the first large model can be forced to learn to generate query instructions based on the input problem modeling, which helps to improve the pertinence of the query instructions.
[0026] In an implementation scenario, after obtaining the query instruction, a date query is performed accordingly. Specifically, the date information source can be called based on the query instruction to obtain the feedback result of the date query. It should be noted that the date information source may include but is not limited to a date plug-in, etc., and the specific type of the date information source is not limited here. Still taking the aforementioned question statement "How long is it until the Spring Festival tomorrow" as an example, since its query instruction includes "What is the date of tomorrow" and "What is the date of the Spring Festival", the date information source can be called based on the query instruction "What is the date of tomorrow" to obtain one of the feedback results "November 11, 2024", and the date information source can be called based on the query instruction "What is the date of the Spring Festival" to obtain another feedback result "January 29, 2025". Of course, the above example is only a possible example of calling the date information source based on the query instruction in the actual application process, and does not limit other possible situations. Other possible situations will not be given examples one by one here.
[0027] In one implementation scenario, after obtaining the feedback result, the question statement and the feedback result can be combined to generate a computer code for performing date calculation. Specifically, a second prompt instruction can be constructed based on the question statement and the feedback result, and the second prompt instruction is used to instruct the second large model to generate a computer code for replying to the question statement based on the feedback result, and then the second prompt instruction is input to the second large model to obtain the output code of the second large model as the above-mentioned computer code. In the above method, a computer code is generated by combining the question statement and the feedback result with the large model to perform date calculation on the feedback result through the computer code. The code generation capability of the large model can be used to generate computer code for date calculation, which helps to improve the accuracy of the date calculation code.
[0028] In a specific implementation scenario, still taking the question sentence "How long until the Spring Festival tomorrow" as an example, as mentioned above, since the feedback results include "November 11, 2024" and "January 29, 2025", the second prompt instruction can be constructed first in combination with the question sentence: Please use computer language to write an executable code to calculate the starting date "November 11, 2024" The number of days until the expiration date "January 29, 2025".
[0029] On this basis, the second prompt instruction can be input into the second largest model to generate the following computer code using the second largest model: from datetime import datetime.timedelta #Date settings start_date=datetime(2024,11,11) end_date=datetime(2025,1,29) # Calculate the number of days days_diff=(end_date-start_date).days days_diff It should be noted that the above computer code is only a possible example in the actual application process, and the specific content of the computer code is not limited thereto, and the specific content of the computer code is not given examples one by one here. In addition, the computer language used in the computer code may include but is not limited to python, C, java, etc., and the computer language used in the computer code is not limited here.
[0030] In a specific implementation scenario, in order to improve the code generation capability of the second largest model, the second largest model can be trained in advance. Specifically, the second sample data can be obtained, and the second sample data can include the second sample question, the sample feedback result and the sample computer code, the sample feedback result is the feedback result of calling the date source for replying the second sample question, and the sample computer code is the computer code for replying the second sample question based on the sample feedback result. It should be noted that the specific meaning of the sample feedback result can refer to the aforementioned description of the feedback result, and the specific meaning of the sample computer code can refer to the aforementioned description of the computer code, which will not be repeated here. On this basis, the second sample question and the sample feedback result can be processed based on the second largest model to generate a prediction computer code. It should be noted that the acquisition process of the prediction computer code can refer to the aforementioned description of obtaining the computer code, which will not be repeated here. Then, the network parameters of the second largest model can be adjusted based on the difference between the prediction computer code and the sample computer code. In the above manner, the second largest model can be trained by the second sample data, which can force the second largest model to generate a computer code for calculating the date for the input question as the training goal, which helps to improve the code quality of the computer code.
[0031] In one implementation scenario, after obtaining the computer code, the computer code can be run in combination with the aforementioned feedback results to obtain the calculation result of the date calculation. Still taking the aforementioned question statement "How long is it from tomorrow to the Spring Festival" as an example, by running the aforementioned computer code, the calculation result "79 days" can be obtained, which represents the question statement "How long is it from tomorrow to the Spring Festival" that there are "79 days" from "tomorrow" (i.e. November 11, 2024) to the Spring Festival (i.e. January 29, 2025). Of course, the above example is only a possible example in the actual application process, and does not limit other possible situations. Other possible situations will not be given examples one by one here.
[0032] Step S12: Generate an answer statement in reply to the question statement based on at least the question statement and the calculation result.
[0033] In an implementation scenario, as a possible implementation method, the target word expressing the question in the question sentence can be identified, and then the target word is replaced with the calculation result to obtain the answer sentence of the question sentence. Exemplarily, still taking the question sentence "How long is it until the Spring Festival tomorrow" as an example, the target word "how long" expressing the question in the question sentence can be identified, and then replaced with the calculation result "79 days", and the answer sentence of the question sentence "There are 79 days until the Spring Festival tomorrow" can be obtained. Of course, the above example is only a possible example in the actual application process, and other possible situations are not limited thereto, and other possible situations will not be given examples one by one here.
[0034] In another implementation scenario, different from the aforementioned implementation, a third prompt instruction can also be constructed based on the question statement and the calculation result, and the third prompt instruction is used to instruct the third largest model to reply to the question statement with reference to the calculation result. On this basis, the third prompt instruction can be input to the third largest model to obtain the output statement of the third largest model as the answer statement. For example, still taking the question statement "How long until the Spring Festival tomorrow" as an example, the calculation result "79 days" can be combined to construct a third prompt instruction including but not limited to the following: Please generate a natural language expression based on the result of the question "How long until the Spring Festival tomorrow" (79 days) The reply statement of Da.
[0035] After the third prompt instruction is input into the third model, the following answer statements may be obtained, including but not limited to: There are 79 days until the Spring Festival tomorrow.
[0036] After checking, there are still 79 days from tomorrow to the Spring Festival.
[0037] According to calculations, there are 79 days left until the Spring Festival tomorrow.
[0038] It should be noted that the above examples are only several possible examples of the third prompt instruction and the answer statement in the actual application process, and the specific content of the third prompt instruction and the answer statement is not limited here. In the above method, the answer statement is generated by combining the large language model with the question statement and the calculation result, and the naturalness of the representation of the answer statement can be improved by using the generation ability of the large language model. Of course, in order to improve the representation ability of the third model to produce the answer statement, the third model can be trained before this. Exemplarily, the third sample data can be obtained first, and the third sample data can include the third sample question, the sample calculation result and the sample answer statement of the real reply to the third sample question, and the sample calculation result represents the calculation result of the date calculation of the third sample question. On this basis, the third sample question and the sample calculation result can be processed based on the third model at least, and the predicted answer statement can be generated, and then the network parameters of the third model can be adjusted based on the difference between the predicted answer statement and the sample answer statement. It should be noted that the specific meaning of the sample calculation result can refer to the aforementioned description of the calculation result, and the specific process of generating the predicted answer statement based on the third model can refer to the aforementioned description of generating the answer statement based on the third model, which will not be repeated here. The above method uses the third sample data to pre-train the third model, which can improve the representation ability of the third model in generating answer sentences and help improve the naturalness of the expression of the answer sentences.
[0039] In another implementation scenario, different from the aforementioned implementation, in addition to using the question statement and the calculation result as the input data of the third model, at least one of the date source and the computer code can be further used as the input data of the third model to make the answer statement output by the third model more convincing. Exemplarily, taking the date source "perpetual calendar API interface" as the input data as an example, in the aforementioned example of the question statement "how long until the Spring Festival tomorrow", the answer statement may include but is not limited to: "After querying the date in the perpetual calendar API interface, it is calculated that there are 79 days until the Spring Festival tomorrow"; or, taking the computer code (see the aforementioned example) as the input data as an example, in the aforementioned example of the question statement "how long until the Spring Festival tomorrow", the answer statement may include but is not limited to: For your input problem, write the following computer code: from datetime import datetime.timedelta #Date settings start_date=datetime(2024,11,11) end_date=datetime(2025,1,29) # Calculate the number of days days_diff=(end_date-start_date).days days_diff According to the calculation of the above computer code, there are 79 days from tomorrow to the Spring Festival.
[0040] Of course, the above examples are only several possible examples when further including date sources or computer codes as input data, and other possible situations (such as further including date sources and computer codes as input data) are not given one by one here. In addition, when further including at least one of date sources and computer codes as input data, correspondingly, the third sample data used by the third largest model in the training process may also include corresponding types of data. For example, when further including date sources as input data, the third sample data used by the third largest model in the training process may also further include date sources; or, when further including computer codes as input data, the third sample data used by the third largest model in the training process may also further include computer codes; or, when further including date sources and computer codes as input data, the third sample data used by the third largest model in the training process may also further include date sources and computer codes.
[0041] In an implementation scenario, please refer to Figure 2 , Figure 2 1 is a schematic diagram of the process of an embodiment of the question answering method of the present application. Figure 2As shown, for a question statement that needs to be calculated by date (such as "how long until the Spring Festival tomorrow"), a query instruction for calling a date information source (such as "what is the date of tomorrow", "what is the date of the Spring Festival") can be generated based on the question statement first, and then the date information source can be called based on the query instruction to obtain the feedback result of the date query (such as "tomorrow's date: November 11, 2024", "Spring Festival date: January 29, 2025"), and based on the question statement and the feedback result, a computer code for performing date calculation (such as the aforementioned example code) is generated, and the computer code is run based on the feedback result to obtain the calculation result of the date calculation (such as "79 days"). On this basis, an answer statement for replying to the question statement can be obtained based at least on the question statement and the calculation result. For example, the answer statement "there are 79 days until the Spring Festival tomorrow" can be generated based only on the question statement and the calculation result; or, the answer statement can be generated based on the question statement, the calculation result and the date information source (such as the aforementioned example); or, the answer statement can also be generated based on the question statement, the calculation result and the computer code (such as the aforementioned example). Of course, there can also be an answer statement generated based on the question statement, the calculation result, the date source and the computer code. In addition, it should be noted that the "first large model", "second large model", "third large model" and the large language model used to directly process the question statement when the question statement does not need or cannot be calculated by date (for the sake of distinction, it can be called the "fourth large model") in the embodiment of the present disclosure can be the same large language model, or, can also be different large language models, or can be part of the same large language model and part of different large language models (such as "first large model" and "second large model" are the same large language model, "second large model", "third large model" and "fourth large model" are another large language model), which is not limited here. Of course, in the case where each large model is the same large language model, the above-mentioned training process for each large model can be executed separately and independently; it can also be unified in the same training process (that is, different tasks of the large language model are uniformly trained in the same training process). Exemplarily, sample data may be obtained, and the sample data may include at least sample questions, sample query instructions, sample feedback results, and sample answer statements for replying to sample questions. Sample questions may be marked with sample tags that represent positive questions or negative questions. Positive questions require date calculation, while negative questions do not require or cannot be calculated by date. Sample query instructions are used to call date information sources for replying to sample questions, and sample feedback results are feedback results of calling date information sources for replying to sample questions. In the case where the sample question is a positive question, the sample data may also include sample computer code, which is computer code for replying to the sample question based on the sample feedback results.On this basis, the large language model can process sample questions, first generate predicted query instructions, and detect predicted tags representing whether the sample questions are positive questions or negative questions, and when the predicted tags represent positive questions, continue processing to generate predicted computer code in combination with sample feedback results, and the large language model continues to process at least the sample questions and sample calculation results (obtained by executing the sample feedback results by the sample computer code) to generate predicted answer statements, so that the training loss of the large language model can be measured based on the differences between the sample query instructions and the predicted query instructions, the differences between the sample tags and the predicted tags, the differences between the sample computer codes and the predicted computer codes, and the differences between the sample answer statements and the predicted answer statements, and then the network parameters of the large language model can be adjusted based on the training loss of the large language model.
[0042] In the above scheme, in response to detecting that the question statement to be answered needs to be calculated by date, a query instruction for calling the date information source is generated based on the question statement, the date information source is called based on the query instruction, the feedback result of the date query is obtained, and a computer code for executing the date calculation is generated based on the question statement and the feedback result, and the computer code is run based on the feedback result to obtain the calculation result of the date calculation, and then based on this, at least based on the question statement and the calculation result, an answer statement for replying to the question statement is generated. Therefore, on the one hand, since the date query is only performed by relying on the date information source without directly performing the date calculation, the construction cost of the date information source can be reduced as much as possible. On the other hand, after obtaining the feedback result of the date information source, a computer code for executing the date calculation is generated in combination with the question statement, and the calculation result of the date calculation is obtained by running the computer code based on the feedback result. Compared with realizing date calculation through model reasoning, realizing date calculation through computer code is more adaptable to factors such as calendar rules, time zone conversion, leap year judgment, etc., which helps to improve the accuracy of date calculation. Therefore, the answer accuracy of date calculation questions can be improved under the premise of reducing the construction cost of the date information source as much as possible.
[0043] See also Figure 3 , Figure 3 It is a schematic diagram of the framework of an embodiment of the question answering device of the present application. The question answering device 30 includes: a date calculation module 31 and a reply generation module 32. The date calculation module 31 is used to generate a query instruction for calling a date source based on the question statement in response to detecting that the question statement to be answered needs to be calculated by date, call the date source based on the query instruction, obtain the feedback result of the date query, and generate a computer code for performing date calculation based on the question statement and the feedback result, and run the computer code based on the feedback result to obtain the calculation result of the date calculation; the reply generation module 32 is used to generate a reply statement for replying to the question statement based on at least the question statement and the calculation result.
[0044] In the above scheme, the question answering device 30 generates a query instruction for calling a date information source based on the question statement in response to detecting that the question statement to be answered needs to be calculated by date, calls the date information source based on the query instruction, obtains the feedback result of the date query, and generates a computer code for executing the date calculation based on the question statement and the feedback result, and runs the computer code based on the feedback result to obtain the calculation result of the date calculation, and then generates an answer statement for replying to the question statement based on at least the question statement and the calculation result. Therefore, on the one hand, since the date query is only performed by relying on the date information source without directly performing the date calculation, the construction cost of the date information source can be reduced as much as possible. On the other hand, after obtaining the feedback result of the date information source, a computer code for executing the date calculation is generated in combination with the question statement, and the calculation result of the date calculation is obtained by running the computer code based on the feedback result. Compared with realizing date calculation through model reasoning, realizing date calculation through computer code is more adaptable to factors such as calendar rules, time zone conversion, leap year judgment, etc., which helps to improve the accuracy of date calculation. Therefore, the answer accuracy of date calculation questions can be improved under the premise of reducing the construction cost of the date information source as much as possible.
[0045] In some disclosed embodiments, the date calculation module 31 includes a first construction submodule, which is used to construct a first prompt instruction based on a question statement; wherein the first prompt instruction is used to instruct the first large model to generate a query instruction for calling a date source to reply to the question statement; the date calculation module 31 includes a first acquisition submodule, which is used to input the first prompt instruction into the first large model to obtain the output instruction of the first large model as a query instruction.
[0046] In some disclosed embodiments, the query instruction is generated by the first large model, and the question answering device 30 also includes a first sample module for obtaining first sample data; wherein the first sample data includes a first sample question and a sample query instruction, the first sample question needs to be calculated by date, and the sample query instruction is used to call a date source to answer the first sample question; the question answering device 30 also includes a first processing module for processing the first sample question based on the first large model to generate a predictive query instruction; the question answering device 30 also includes a first parameter adjustment module for adjusting the network parameters of the first large model based on the difference between the predictive query instruction and the sample query instruction.
[0047] In some disclosed embodiments, the date calculation module 31 includes a second construction submodule, which is used to construct a second prompt instruction based on the question statement and the feedback result; wherein the second prompt instruction is used to instruct the second large model to generate a computer code for replying to the question statement based on the feedback result; the date calculation module 31 includes a second acquisition submodule, which is used to input the second prompt instruction into the second large model to obtain the output code of the second large model as computer code.
[0048] In some disclosed embodiments, the computer code is generated by the second large model, and the question answering device 30 also includes a second sample module for obtaining second sample data; wherein the second sample data includes a second sample question, a sample feedback result and a sample computer code, and the sample feedback result is a feedback result of calling a date source for replying to the second sample question, and the sample computer code is a computer code for replying to the second sample question based on the sample feedback result; the question answering device 30 also includes a second processing module for processing the second sample question and the sample feedback result based on the second large model to generate a prediction computer code; the question answering device 30 also includes a second parameter adjustment module for adjusting the network parameters of the second large model based on the difference between the prediction computer code and the sample computer code.
[0049] In some disclosed embodiments, the reply generation module 32 includes a third construction submodule, which is used to construct a third prompt instruction based on at least the question statement and the calculation result; wherein the third prompt instruction is used to instruct the third largest model to reply to the question statement with reference to the calculation result; the reply generation module 32 includes a third acquisition submodule, which is used to input the third prompt instruction to the third largest model to obtain the output statement of the third largest model as an answer statement.
[0050] In some disclosed embodiments, the answer statement is generated by the third largest model, and the question answering device 30 also includes a third sample module for obtaining third sample data; wherein the third sample data at least includes a third sample question, a sample calculation result, and a sample answer statement that truly responds to the third sample question, and the sample calculation result represents the calculation result of a date calculation for the third sample question; the question answering device 30 also includes a third processing module for processing at least the third sample question and the sample calculation result based on the third largest model to generate a predicted answer statement; the question answering device 30 also includes a third parameter adjustment module for adjusting the network parameters of the third largest model based on the difference between the predicted answer statement and the sample answer statement.
[0051] In some disclosed embodiments, whether the question statement needs to be calculated by date is detected by the question classification model, and the question answering device 30 also includes a fourth sample module, which is used to obtain a fourth sample question; wherein the fourth sample question is marked with a sample tag representing a positive question or a negative question, and the positive question needs to be calculated by date, while the negative question does not need or cannot be calculated by date; the question answering device 30 also includes a fourth processing module, which is used to detect the fourth sample question based on the question classification model to obtain a prediction tag representing that the fourth sample question is predicted to be a positive question or a negative question; the question answering device 30 also includes a fourth parameter adjustment module, which is used to adjust the network parameters of the question classification model based on the difference between the sample tag and the prediction tag.
[0052] In some disclosed embodiments, the question answering device 30 also includes a question classification module for detecting based on the question statement to determine whether the question statement requires date calculation; the question answering device 30 also includes a direct processing module for directly processing the question statement based on the fourth model to obtain an answer statement in response to the question statement not requiring or unable to undergo date calculation.
[0053] See also Figure 4 , Figure 4 : is a schematic diagram of the framework of an embodiment of an electronic device of the present application. The electronic device 40 includes at least a memory 41 and a processor 42 coupled to each other, the memory 41 stores at least program instructions, and the processor 42 is used to execute the program instructions to implement the steps in any of the above-mentioned question answering method embodiments. For details, please refer to the aforementioned disclosed embodiments, which will not be repeated here. As a possible example, the electronic device 40 may include but is not limited to a server, a camera, a smart phone, a tablet computer, etc., and the specific type of the electronic device 40 is not limited here.
[0054] Specifically, the processor 42 is used to control itself and the memory 41 to implement the steps in any of the above-mentioned question answering method embodiments. The processor 42 can also be called a CPU (Central Processing Unit). The processor 42 may be an integrated circuit chip with signal processing capabilities. The processor 42 can also be a general-purpose processor, a digital signal processor (Digital Signal Processor, DSP), an application-specific integrated circuit (Application Specific Integrated Circuit, ASIC), a field-programmable gate array (Field-Programmable Gate Array, FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. In addition, the processor 42 can be implemented by an integrated circuit chip.
[0055] In the above scheme, the electronic device 40 generates a query instruction for calling a date information source based on the question statement in response to detecting that the question statement to be answered needs to be calculated by date, calls the date information source based on the query instruction, obtains the feedback result of the date query, and generates a computer code for executing the date calculation based on the question statement and the feedback result, and runs the computer code based on the feedback result to obtain the calculation result of the date calculation, and then generates an answer statement for replying to the question statement based on at least the question statement and the calculation result. Therefore, on the one hand, since the date query is only performed by relying on the date information source without directly performing the date calculation, the construction cost of the date information source can be reduced as much as possible. On the other hand, after obtaining the feedback result of the date information source, a computer code for executing the date calculation is generated in combination with the question statement, and the calculation result of the date calculation is obtained by running the computer code based on the feedback result. Compared with realizing date calculation through model reasoning, realizing date calculation through computer code is more adaptable to factors such as calendar rules, time zone conversion, leap year judgment, etc., which helps to improve the accuracy of date calculation. Therefore, the accuracy of answering date calculation questions can be improved under the premise of reducing the construction cost of the date information source as much as possible.
[0056] See also Figure 5 , Figure 5 1 is a schematic diagram of a framework of an embodiment of a computer-readable storage medium 50 of the present application. The computer-readable storage medium 50 stores program instructions 51 that can be executed by a processor, and the program instructions 51 are used to implement the steps in any of the above-mentioned question answering method embodiments.
[0057] In the above scheme, in response to detecting that the question statement to be answered needs to be calculated by date, the computer-readable storage medium 50 generates a query instruction for calling the date information source based on the question statement, calls the date information source based on the query instruction, obtains the feedback result of the date query, and generates a computer code for executing the date calculation based on the question statement and the feedback result, and runs the computer code based on the feedback result to obtain the calculation result of the date calculation, and then generates an answer statement for replying to the question statement based on at least the question statement and the calculation result. Therefore, on the one hand, since the date query is only performed by relying on the date information source without directly performing the date calculation, the construction cost of the date information source can be reduced as much as possible. On the other hand, after obtaining the feedback result of the date information source, a computer code for executing the date calculation is generated in combination with the question statement, and the calculation result of the date calculation is obtained by running the computer code based on the feedback result. Compared with realizing date calculation through model reasoning, realizing date calculation through computer code is more adaptable to factors such as calendar rules, time zone conversion, leap year judgment, etc., which helps to improve the accuracy of date calculation. Therefore, the answer accuracy of date calculation questions can be improved under the premise of reducing the construction cost of the date information source as much as possible.
[0058] In some embodiments, the functions or modules included in the device provided by the embodiments of the present disclosure can be used to execute the method described in the above method embodiments. The specific implementation can refer to the description of the above method embodiments, and for the sake of brevity, it will not be repeated here.
[0059] The above description of various embodiments tends to emphasize the differences between the various embodiments. The same or similar aspects can be referenced to each other, and for the sake of brevity, they will not be repeated herein.
[0060] In the several embodiments provided in the present application, it should be understood that the disclosed methods and devices can be implemented in other ways. For example, the device implementation described above is only schematic. For example, the division of modules or units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, and the indirect coupling or communication connection of devices or units can be electrical, mechanical or other forms.
[0061] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0062] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0063] If the integrated unit is implemented in the form of 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 the present application is essentially 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. The computer software product is stored in a storage medium, including several instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) or a processor to execute all or part of the steps of each implementation method of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program code.
[0064] If the technical solution of this application involves personal information, the product using the technical solution of this application has clearly informed the personal information processing rules and obtained the individual's voluntary consent before processing the personal information. If the technical solution of this application involves sensitive personal information, the product using the technical solution of this application has obtained the individual's separate consent before processing the sensitive personal information, and at the same time meets the "explicit consent" requirement. For example, on personal information collection devices such as cameras, clear and prominent signs are set to inform that the personal information collection scope has been entered and personal information will be collected. If the individual voluntarily enters the collection scope, it is deemed that he or she agrees to the collection of his or her personal information; or on the device that processes personal information, the personal information processing rules are notified by obvious signs / information, and the individual's authorization is obtained through pop-up information or by asking the individual to upload his or her personal information; among them, the personal information processing rules may include information such as the personal information processor, the purpose of personal information processing, the processing method, and the type of personal information processed.
Claims
1. A question answering method, characterized in that: include: In response to detecting that the question statement to be answered needs to be subjected to date calculation, based on the question statement, a query instruction for calling a date information source is generated, the date information source is called based on the query instruction to obtain a feedback result of the date query, and based on the question statement and the feedback result, a computer code for executing the date calculation is generated, and the computer code is run based on the feedback result to obtain a calculation result of the date calculation; An answer sentence in reply to the question sentence is generated based on at least the question sentence and the calculation result.
2. The method according to claim 1, characterized in that The step of generating a query instruction for calling a date information source based on the question statement includes: Based on the question statement, construct a first prompt instruction; wherein the first prompt instruction is used to instruct the first large model to generate a query instruction for calling the date information source to answer the question statement; The first prompt instruction is input to the first large model to obtain an output instruction of the first large model as the query instruction.
3. The method according to claim 1 or 2, characterized in that: The query instruction is generated by a first large model, and the training steps of the first large model include: Acquire first sample data; wherein the first sample data includes a first sample question and a sample query instruction, the first sample question needs to be calculated by date, and the sample query instruction is used to call the date information source to answer the first sample question; Processing the first sample question based on the first large model to generate a prediction query instruction; Based on the difference between the predicted query instruction and the sample query instruction, the network parameters of the first large model are adjusted.
4. The method according to claim 1, characterized in that: The step of generating a computer code for executing the date calculation based on the question statement and the feedback result comprises: Based on the question statement and the feedback result, construct a second prompt instruction; wherein the second prompt instruction is used to instruct the second large model to generate a computer code for replying to the question statement based on the feedback result; The second prompt instruction is input to the second large model to obtain the output code of the second large model as the computer code.
5. The method according to claim 1 or 4, characterized in that: The computer code is generated by a second large model, and the training steps of the second large model include: Acquire second sample data; wherein the second sample data includes a second sample question, a sample feedback result, and a sample computer code, and the sample feedback result is a feedback result of calling the date information source for replying the second sample question, and the sample computer code is a computer code for replying the second sample question based on the sample feedback result; Processing the second sample problem and the sample feedback result based on the second large model to generate a prediction computer code; Based on the difference between the predicted computer code and the sample computer code, the network parameters of the second largest model are adjusted.
6. The method according to claim 1, characterized in that The step of generating an answer statement for replying to the question statement based at least on the question statement and the calculation result includes: At least based on the question statement and the calculation result, construct a third prompt instruction; wherein the third prompt instruction is used to instruct the third large model to reply to the question statement with reference to the calculation result; The third prompt instruction is input to the third largest model to obtain an output sentence of the third largest model as the answer sentence.
7. The method according to claim 1 or 6, characterized in that: The answer statement is generated by the third largest model, and the training steps of the third largest model include: Acquire third sample data; wherein the third sample data at least includes a third sample question, a sample calculation result, and a sample answer statement that truly responds to the third sample question, and the sample calculation result represents a calculation result of performing date calculation on the third sample question; Processing at least the third sample question and the sample calculation result based on the third largest model to generate a predicted answer statement; Based on the difference between the predicted answer sentence and the sample answer sentence, the network parameters of the third largest model are adjusted.
8. The method according to claim 1, characterized in that Whether the question statement needs to be calculated by date is detected by a question classification model, and the training steps of the question classification model include: Obtain a fourth sample problem; wherein the fourth sample problem is marked with a sample mark representing a positive example problem or a negative example problem, and the positive example problem needs to be calculated by date, and the negative example problem does not need or cannot be calculated by date; Detecting the fourth sample question based on the question classification model to obtain a prediction mark indicating that the fourth sample question is predicted to be the positive example question or the negative example question; Based on the difference between the sample label and the predicted label, the network parameters of the problem classification model are adjusted.
9. The method according to claim 1 or 8, characterized in that: Before generating a query instruction for calling a date information source based on the question statement, the method further includes: Performing a test based on the question statement to determine whether the question statement needs to be calculated by date; The method further comprises: In response to the fact that the question statement does not need or cannot be calculated by date, the question statement is directly processed based on the fourth model to obtain an answer statement in response to the question statement.
10. A question answering device, characterized in that: include: A date calculation module, for, in response to detecting that a question statement to be answered needs to be subjected to date calculation, generating a query instruction for calling a date information source based on the question statement, calling the date information source based on the query instruction, obtaining a feedback result of the date query, generating a computer code for executing the date calculation based on the question statement and the feedback result, and running the computer code based on the feedback result to obtain a calculation result of the date calculation; A reply generation module is used to generate an answer statement in reply to the question statement based at least on the question statement and the calculation result.
11. An electronic device, characterized in that: The system at least comprises a memory and a processor coupled to each other, wherein the memory at least stores program instructions, and the processor is used to execute the program instructions to implement the question answering method according to any one of claims 1 to 9.
12. A computer-readable storage medium, characterized in that: Program instructions that can be executed by a processor are stored, and the program instructions are used to implement the question answering method described in any one of claims 1 to 9.