Code language model-based science and engineering problem solving method and apparatus, and electronic device

By combining the use of code language models and code interpreters in science and engineering problems, natural language reasoning and code calculation deduction are realized, the accuracy problem caused by model illusion is solved, and the accuracy of answering science and engineering questions is improved.

CN119167918APending Publication Date: 2024-12-20TSINGHUA UNIVERSITY +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411043298.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-31
Publication Date
2024-12-20

Smart Images

  • Figure CN119167918A_ABST
    Figure CN119167918A_ABST
Patent Text Reader

Abstract

The invention provides a code language model-based science and engineering problem solving method and device and electronic equipment. The method comprises the following steps of: obtaining a to-be-solved science and engineering problem; based on a pre-trained code language model and a code interpreter, generating a target solution result according to the science and engineering subject; wherein the code language model is obtained based on the pre-training model through fine adjustment of a training sample data set composed of the science and engineering subject samples and the corresponding code answer result samples. A natural language reasoning process and a code calculation deduction process of a science and engineering subject are generated at the same time through a code language model, a code interpreter is called to execute a target code block in the process of generating a target answer result so as to assist in generating a final answer result, the tool calling capability of the code language model is fully exerted in the process, and the efficiency is improved. The problem that the accuracy of a final generation result is not high due to the fact that the algorithm is prone to being affected by model illusion is solved, the reasoning ability of the code language model on the science and engineering questions is effectively improved, and then the accuracy of solving the science and engineering questions is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of deep learning technology, and in particular to a method, device and electronic equipment for solving science and engineering problems based on a code language model. Background Art

[0002] Since the birth of the large language model, its reasoning ability has been regarded as an important manifestation of intelligence. In recent years, it has gradually begun to be applied in the field of education, such as solving problems in science and engineering.

[0003] At present, the most widely used technical route is to use collected / annotated domain datasets for supervised fine-tuning based on a large language model with general capabilities and world knowledge, and to perform reasoning through thought chains.

[0004] However, in practice, it is often found that the performance of such algorithms that learn pure natural language reasoning patterns is susceptible to model hallucinations, that is, the results generated by the probabilistic model may be contrary to facts, laws, and given information. For example, Newton's laws are used incorrectly in reasoning, or the square method is not correctly expanded in algebraic transformations. Since the output of the model does not strictly follow such established constraints, the accuracy of the final generated results may be seriously damaged.

[0005] Therefore, how to solve the problem that existing science and engineering problem-solving methods are easily affected by model hallucinations, resulting in low accuracy of the final generated results, is an important issue that needs to be urgently solved in the field of deep learning. Summary of the invention

[0006] The present invention provides a method, device and electronic device for solving science and engineering problems based on a code language model, so as to overcome the defect that the existing science and engineering problem-solving method is easily affected by model hallucination, resulting in low accuracy of the final generated results, and effectively improve the reasoning ability of the code language model on science and engineering problems, thereby improving the accuracy of the answers to science and engineering problems.

[0007] On the one hand, the present invention provides a method for solving science and engineering problems based on a code language model, comprising: obtaining science and engineering problems to be solved; generating a target solution result according to the science and engineering problems based on a pre-trained code language model and a code interpreter; wherein the code language model is obtained by fine-tuning a training sample data set composed of science and engineering problem samples and their corresponding coded solution result samples based on the pre-trained model.

[0008] Furthermore, fine-tuning the code language model specifically includes: obtaining an initial problem-solving data set, the initial problem-solving data set including science and engineering question samples and their corresponding natural language answers; obtaining coded answer result samples based on the science and engineering question samples and their corresponding natural language answers, as well as preset prompt words, to obtain a training sample data set; using the science and engineering question samples as model input, using the predicted coded answer results as model output, and using the difference between the coded answer result samples and the predicted coded answer results as training loss, fine-tuning the pre-trained model to obtain a pre-trained code language model.

[0009] Furthermore, the number of the science and engineering questions is single; accordingly, the pre-trained code language model and code interpreter generate a target solution result according to the science and engineering question, including: S310, inputting the science and engineering question into the pre-trained code language model, and starting to generate a coded solution result corresponding to the science and engineering question; the coded solution result contains at least one specific interrupt symbol; S320, when any specific interrupt symbol is matched during the process of generating the coded solution result, stop generating the coded solution result; S330, extracting the target code block before the matched specific interrupt symbol, and inputting the target code block into the code interpreter to obtain the execution result corresponding to the target code block; S340, placing the execution result after the matched specific interrupt symbol, and continuing to generate the coded solution result; S350, iteratively executing steps S320-S340, stopping the iteration when the science and engineering question is completely solved, and outputting the target solution result.

[0010] Furthermore, there are multiple science and engineering questions; accordingly, the pre-trained code language model and code interpreter generate target solution results according to the science and engineering questions, including: S410, inputting multiple engineering questions into the pre-trained code language model at the same time, and starting to generate coded solution results corresponding to the multiple engineering questions at the same time; each coded solution result contains at least one specific interruption symbol; S420, in the process of generating coded solution results for multiple engineering questions, when a specific interruption symbol in the coded solution result of any science and engineering question is matched, stop generating all coded solution results; S430, extracting the target code block before the matched specific interruption symbol, and inputting the target code block into the code interpreter to obtain the execution result corresponding to the target code block; S440, placing the execution result after the matched specific interruption symbol, and continuing to generate coded solution results corresponding to the multiple engineering questions at the same time; S450, iteratively executing steps S420-S440, stopping the iteration when all science and engineering questions are completely answered, and outputting the target solution results for all science and engineering questions.

[0011] Furthermore, the execution result buffer set is initialized to be empty, and the maximum generation length of each round of the code language model is set to a preset length; the execution result buffer set is used to cache the execution results output by the code interpreter; accordingly, the execution result is placed after the matched specific interrupt character, and the coded solution results corresponding to multiple science and engineering questions are continued to be generated simultaneously, including: updating the maximum generation length according to the length of the execution result in the execution result buffer set; based on the code language model, a random solution result is generated after the matched specific interrupt character, and the solution results of other science and engineering questions that are not matched to the specific interrupt character are continued to be generated; the length of the random solution result is the updated maximum generation length; the random solution result is replaced by the execution result, and the coded solution results corresponding to multiple science and engineering questions are continued to be generated simultaneously.

[0012] Furthermore, updating the maximum generation length according to the length of the execution result in the execution result buffer set includes: when there are multiple execution results in the execution result buffer set, updating the maximum generation length according to the execution result with the minimum length; correspondingly, replacing the random solution result with the execution result includes: for the execution result with the minimum length in the execution result buffer set, directly replacing the random solution result with a complete execution result; for the execution result with the length greater than the minimum length in the execution result buffer set, replacing the random solution result with a partial execution result; wherein the length of the partial execution result is the minimum length, and the other contents of the execution result except the partial execution result continue to be cached in the execution result buffer set, waiting to be replaced in the next round of generation.

[0013] Furthermore, when the execution result buffer set is empty, the maximum generation length is updated to a preset length.

[0014] In a second aspect, the present invention also provides a science and engineering problem-solving device based on a code language model, comprising: a science and engineering problem acquisition module, used to acquire science and engineering problems to be solved; a science and engineering problem solving module, used to generate a target solution result according to the science and engineering problems based on a pre-trained code language model and a code interpreter; wherein the code language model is obtained by fine-tuning a training sample data set composed of science and engineering problem samples and their corresponding coded solution result samples based on the pre-trained model.

[0015] In a third aspect, the present invention further provides an electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the method for solving science and engineering problems based on a code language model as described above is implemented.

[0016] In a fourth aspect, the present invention further provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements any of the above-described methods for solving science and engineering problems based on a code language model.

[0017] The method for solving science and engineering problems based on a code language model provided by the present invention obtains science and engineering problems to be solved, and generates a target solution result according to the science and engineering problems based on a pre-trained code language model and a code interpreter; wherein the code language model is fine-tuned based on the pre-trained model through a training sample data set consisting of science and engineering problem samples and their corresponding coded solution result samples. The method generates the natural language reasoning process and code calculation deduction process of science and engineering problems simultaneously through the code language model, and calls the code interpreter to execute the target code block in the process of generating the target solution result to assist in the generation of the final solution result. This process gives full play to the tool calling ability of the code language model, alleviates the problem that the algorithm itself is easily affected by the model hallucination and the final generated result has a low accuracy, and effectively improves the reasoning ability of the code language model on science and engineering problems, thereby improving the accuracy of solving science and engineering problems. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0019] Figure 1 A schematic flow chart of a method for solving science and engineering problems based on a code language model provided in an embodiment of the present invention.

[0020] Figure 2 A schematic diagram of fine-tuning the code language model provided by an embodiment of the present invention.

[0021] Figure 3 One of the flow charts of the method for solving science and engineering problems based on the code language model provided in an embodiment of the present invention.

[0022] Figure 4 The second flowchart of the method for solving science and engineering problems based on a code language model provided in an embodiment of the present invention.

[0023] Figure 5 A schematic diagram of the overall process of a method for solving science and engineering problems based on a code language model provided in an embodiment of the present invention.

[0024] Figure 6A schematic diagram of the structure of a science and engineering problem-solving device based on a code language model provided in an embodiment of the present invention.

[0025] Figure 7 A schematic diagram of the physical structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0026] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings in the present invention. Obviously, the described embodiments are 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 are within the scope of protection of the present invention.

[0027] It should be noted that the performance of existing science and engineering problem-solving algorithms is easily affected by model hallucinations, that is, the results generated by the probability model may contradict the facts, laws, and given information. For example, Newton's laws are used incorrectly in reasoning, or the square method is not correctly expanded in algebraic transformations. Since the output of the model does not strictly follow such established constraints, the accuracy of the final generated results may be seriously damaged.

[0028] In view of this, the present invention proposes a method for solving science and engineering problems based on a code language model. Specifically, Figure 1 A flow chart of a method for solving science and engineering problems based on a code language model provided in an embodiment of the present invention is shown.

[0029] like Figure 1 As shown, the method includes steps S110-S120, and steps S110-S120 and related steps will be described in detail below.

[0030] S110, obtaining science and engineering questions to be solved.

[0031] It is understandable that in order to solve science and engineering problems, it is necessary to first obtain science and engineering problems to be solved.

[0032] Specifically, there are many sources of science and engineering questions, including but not limited to textbooks, academic websites and forums, question-solving software, university course webpages, professional books and manuals, library resources, and social media and educational communities.

[0033] In other words, science and engineering questions can be obtained from relevant sources based on actual conditions, and no specific restrictions are made here.

[0034] It should be noted that the science and engineering questions to be answered in this step include but are not limited to questions covered by mathematics, physics, and chemistry courses in elementary school, junior high school, high school, and university.

[0035] For example, in a specific embodiment, the science and engineering questions to be answered are particularly focused on questions of difficulty in undergraduate physics and chemistry courses.

[0036] S120, based on a pre-trained code language model and a code interpreter, a target solution result is generated according to the science and engineering question; wherein the code language model is fine-tuned based on the pre-trained model through a training sample data set consisting of science and engineering question samples and their corresponding coded solution result samples.

[0037] It can be understood that, based on obtaining the science and engineering problem to be solved in step S110, step S120 will further generate a target solution result, that is, a solution result of the science and engineering problem, by using a code language model and a code interpreter.

[0038] Specifically, this embodiment gives full play to the tool calling capability of the code language model. In the problem-solving process, it not only generates the reasoning process of natural language, but also attempts to generate scientific computing code to replace the computational deduction process directly generated by the language model. It also obtains the execution result of the corresponding code by calling external tools (code interpreter and execution environment) to assist the code language model in generating the target solution result.

[0039] The code language model is obtained by fine-tuning the pre-trained model using the constructed training sample data set. Each training sample in the training sample data set includes a science and engineering question sample and its corresponding coded solution result sample.

[0040] In actual application, the science and engineering questions to be answered are input into the pre-trained code language model, and the code language model will start to generate coded solution results corresponding to the science and engineering questions. In the process from the beginning to the end of the generation of the code language model, when a specific interrupt symbol in the coded solution result is matched, the code interpreter will be called to execute the target code block in the coded solution result to obtain the corresponding execution result, and the execution result will be fed back to the code language model.

[0041] Furthermore, the code language model places the execution result of the target code block behind the target code block and continues to generate the coded solution result, repeating a series of processes of matching specific interrupt symbols, calling the code interpreter, and continuing to generate coded solution results until the science and engineering problem is completely solved, and outputs the target solution result, that is, the solution result of the science and engineering problem.

[0042] The coded solution result includes at least the natural language reasoning process and the code calculation deduction process. The target solution result includes at least the natural language reasoning process, the code calculation deduction process and the calculation result value fed back by the code interpreter.

[0043] In this embodiment, by obtaining science and engineering questions to be answered, and based on the pre-trained code language model and code interpreter, a target answer result is generated according to the science and engineering questions; wherein the code language model is fine-tuned based on the pre-trained model through a training sample data set consisting of science and engineering question samples and their corresponding coded answer result samples. This method generates the natural language reasoning process and code calculation deduction process of science and engineering questions at the same time through the code language model, and calls the code interpreter to execute the target code block in the process of generating the target answer result to assist in the generation of the final answer result. This process gives full play to the tool calling ability of the code language model, alleviates the problem that the algorithm itself is easily affected by the model hallucination and the final generated result is not accurate, and effectively improves the reasoning ability of the code language model on science and engineering questions, thereby improving the accuracy of the answers to science and engineering questions.

[0044] On the basis of the above-mentioned embodiment, the fine-tuning process of the code language model will be further described in detail below.

[0045] Fine-tuning the code language model specifically includes: obtaining an initial problem-solving data set, which includes samples of science and engineering questions and their corresponding natural language answers; obtaining coded solution result samples based on the science and engineering question samples and their corresponding natural language answers, as well as preset prompt words, to obtain a training sample data set; using the science and engineering question samples as model input, using the predicted coded solution results as model output, and using the difference between the coded solution result samples and the predicted coded solution results as training loss, fine-tuning the pre-trained model, and obtaining a pre-trained code language model.

[0046] It is understandable that an initial problem-solving data set is first obtained, and the initial problem-solving data set can be collected from many relevant teaching materials or from databases in public channels, which is not specifically limited here.

[0047] The initial problem-solving dataset includes samples of science and engineering questions and the natural language answers corresponding to the samples of science and engineering questions, which can be specifically expressed as .in, represents a sample of science and engineering questions (i.e., a specific question), express The corresponding natural language answer, Indicates the question number / sample number, Indicates the total number of questions / total number of samples.

[0048] After obtaining the initial problem-solving dataset, the initial problem-solving dataset is transformed into Natural language answers in Modify the problem-solving process into a coded one to obtain a sample of the coded solution result .

[0049] Specifically, assuming that the large language model given here has the ability to follow instructions, it will generate science and engineering question samples, the natural language answers corresponding to the science and engineering question samples, and the preset prompt words. By inputting them into the large language model together, the corresponding coded answer result samples can be generated. This process can be expressed by the following formula (1).

[0050] (1).

[0051] In formula (1), represents a sample of the coded solution result, represents a pre-given large language model, Indicates sample questions for science and engineering subjects. Indicates sample questions for science and engineering subjects The corresponding natural language answer, Indicates the preset prompt word.

[0052] Specifically, this embodiment uses a large language model to rewrite only the calculation process in the natural language solution in the initial problem-solving dataset into code calculation fragments and execution results using a third-party code library. Specifically, this embodiment uses the Python programming language and the Sympy third-party library to implement scientific computing algorithms commonly used in most science and engineering disciplines.

[0053] About preset prompt words , an example is provided below, and the details can be found in Table 1 below.

[0054] Table 1

[0055] .

[0056] Through the above, we can obtain samples of science and engineering questions and samples of coded solutions, from which we can construct a training sample dataset .

[0057] Furthermore, by fine-tuning a pre-given pre-trained model using a training sample data set, a pre-trained code language model can be obtained.

[0058] The pre-trained model here can be the large language model described above, or it can be other pre-trained models in the field of natural language processing and code generation, and is not specifically limited here.

[0059] During the fine-tuning process, samples of science and engineering questions are used as model input, predicted coded solutions are used as model output, and the difference between the coded solution samples and the predicted coded solution is used as the training loss. By fine-tuning the given pre-trained model, a pre-trained code language model can be obtained.

[0060] also, Figure 2 A schematic diagram of fine-tuning the code language model provided by an embodiment of the present invention is shown.

[0061] like Figure 2 As shown, firstly, an initial problem-solving dataset is obtained, and then based on the initial problem-solving dataset, a training sample dataset is further obtained, and finally, the initial model (that is, the given pre-trained model) is fine-tuned using the training sample dataset to obtain the final trained coded model.

[0062] Among them, the process of obtaining the training sample data set according to the initial problem-solving data set can be implemented through a large language model. The large language model here can be the same model as the given pre-training model, and no specific limitation is made here.

[0063] Then, the trained code language model can be used to solve science and engineering problems.

[0064] In this embodiment, an initial problem-solving data set is obtained, which includes samples of science and engineering questions and their corresponding natural language answers, and a coded answer result sample is obtained according to the samples of science and engineering questions and their corresponding natural language answers, as well as preset prompt words, so as to obtain a training sample data set, and then the samples of science and engineering questions are used as model input, the predicted coded answer result is used as model output, and the difference between the coded answer result sample and the predicted coded answer result is used as training loss, and the pre-trained model is fine-tuned to obtain a pre-trained code language model, so as to generate a target answer result according to the science and engineering questions based on the pre-trained code language model and the code interpreter. The method generates the natural language reasoning process and the code calculation deduction process of the science and engineering questions at the same time through the code language model, and calls the code interpreter to execute the target code block in the process of generating the target answer result to assist in the generation of the final answer result. This process gives full play to the tool calling capability of the code language model, alleviates the problem that the algorithm itself is easily affected by the model hallucination and the final generated result is not accurate, effectively improves the reasoning ability of the code language model on science and engineering questions, and thus improves the accuracy of the answer to science and engineering questions.

[0065] On the basis of the above embodiments, the process of generating solutions to science and engineering problems using a code language model and a code interpreter will be described in detail below, especially for the case where the number of science and engineering problems to be solved is only a single one.

[0066] The number of science and engineering questions to be solved is single.

[0067] Accordingly, Figure 3 One of the flowchart diagrams of the method for solving science and engineering problems based on a code language model provided by an embodiment of the present invention is shown, and the execution process of step S120 is specifically described when the number of science and engineering problems is one.

[0068] like Figure 3 As shown, based on the pre-trained code language model and code interpreter, a target answer result is generated according to a science and engineering question, including the following steps S310-S350. The following will describe steps S310-S350 and related steps in detail.

[0069] S310, input the science and engineering question into a pre-trained code language model, and start generating a coded solution result corresponding to the science and engineering question; the coded solution result includes at least one specific interrupt symbol.

[0070] S320, when any specific interruption symbol is matched during the process of generating the coded solution result, stop generating the coded solution result.

[0071] It is easy to understand that the obtained science and engineering questions to be solved are input into the pre-trained code language model, and the code language model begins to generate coded solution results corresponding to the science and engineering questions.

[0072] It is worth mentioning that the present embodiment adds the code block termination symbol "```" as a specific interrupt symbol, that is, the coded solution result includes one or more specific interrupt symbols.

[0073] In this way, as long as the specific interruption symbol appears in the process of generating the coded solution result, the code language model will immediately stop generating the coded solution result.

[0074] S330, extracting the target code block before the matched specific interrupt symbol, and inputting the target code block into a code interpreter to obtain an execution result corresponding to the target code block.

[0075] It is easy to understand that when using the code language model to solve science and engineering problems, it is necessary to use a code interpreter to execute the code written by the model and obtain the corresponding execution results.

[0076] Specifically, after the code language model stops generating coded solution results, the last code block in the partially coded solution results generated for the current science and engineering question, that is, the target code block, can be matched through a regular expression.

[0077] Then, the target code block is input into the code interpreter, which executes the target code block and returns an execution result to the code language model. The execution result here can be a specific value obtained by executing the target code block or a specific calculation expression.

[0078] S340, placing the execution result after the matched specific interrupt symbol, and continuing to generate a coded solution result.

[0079] It is easy to understand that after the code language model receives the execution result fed back by the code interpreter, it randomly generates the answer content according to the byte length of the execution result. In other words, the code language model randomly generates the answer content of the same length as the byte length of the execution result.

[0080] Then, the randomly generated answer content is overwritten and replaced with the execution result.

[0081] Then, the code language model continues to generate coded solutions corresponding to science and engineering questions.

[0082] S350, iteratively executing steps S320-S240 until the science and engineering problem is completely solved, and then the iteration is stopped and the target solution result is output.

[0083] It can be understood that in the process of the code language model generating the coded solution results corresponding to the science and engineering questions, since the coded solution results may contain more than one specific interruption characters, steps S320-S340 are executed each time the specific interruption character appears, until the coded solution results of the current science and engineering question are completely generated, and the final target solution result is output.

[0084] In this embodiment, by inputting a single science and engineering question into a pre-trained code language model, the coded solution result corresponding to the science and engineering question is generated, and when any specific interrupt symbol is matched in the process of generating the coded solution result, the generation of the coded solution result is stopped, the target code block before the matched specific interrupt symbol is extracted, the target code block is input into the code interpreter, the execution result corresponding to the target code block is obtained, and then the execution result is placed after the matched specific interrupt symbol, and the coded solution result is continued to be generated, and then steps S320-S350 are iteratively executed until the science and engineering question is completely solved, and the iteration is stopped, and the target solution result is output. The method generates the natural language reasoning process and the code calculation deduction process of the science and engineering question at the same time through the code language model, and calls the code interpreter to execute the target code block in the process of generating the target solution result to assist in the generation of the final solution result. This process gives full play to the tool calling ability of the code language model, alleviates the problem that the algorithm itself is easily affected by the model hallucination and the final generated result is not accurate, effectively improves the reasoning ability of the code language model on science and engineering questions, and thus improves the accuracy of the solution to science and engineering questions.

[0085] On the basis of the above embodiments, the process of generating solutions to science and engineering problems using a code language model and a code interpreter will be described in detail below, especially for the case where the number of science and engineering problems to be solved is in batches / multiple.

[0086] The number of science and engineering questions to be solved is multiple.

[0087] Accordingly, Figure 4 The second flowchart of the method for solving science and engineering problems based on a code language model provided by an embodiment of the present invention is shown, and the execution process of step S120 is specifically described when there are multiple science and engineering problems.

[0088] like Figure 4 As shown, based on the pre-trained code language model and code interpreter, a target answer result is generated according to a science and engineering question, including the following steps S410-S450. The following will describe steps S410-S450 and related steps in detail.

[0089] S410, inputting multiple engineering problems into a pre-trained code language model at the same time, and starting to generate coded solution results corresponding to the multiple engineering problems at the same time; each coded solution result includes at least one specific interrupt symbol.

[0090] S420, during the process of generating coded solution results for multiple science and engineering problems, when a specific interruption symbol in the coded solution results of any science and engineering problem is matched, stop generating all coded solution results.

[0091] It is easy to understand that the obtained multiple engineering problems to be solved are simultaneously input into the pre-trained code language model, and the code language model starts to simultaneously generate coded solution results corresponding to the multiple engineering problems respectively.

[0092] For example, the process of the code language model generating coded solutions to multiple engineering problems at the same time can be seen in Table 2 below.

[0093] Table 2

[0094] .

[0095] In Table 2, the number of rows indicates the number of science and engineering questions, and the number of columns indicates the number of times the questions are generated (the concept of the number of times the questions are generated exists because a specific interrupt symbol may be matched when generating the coded solution result, and the generation needs to be interrupted at this time. If there is an interruption, there will be subsequent continued generation, thus giving rise to the concept of the number of times the questions are generated).

[0096] According to Table 2, the code language model can solve three engineering problems at the same time.

[0097] It is worth mentioning that the present embodiment adds the code block termination symbol "```" as a specific interruption symbol, that is, the coded solution result corresponding to each science and engineering question includes one or more specific interruption symbols.

[0098] In this way, as long as the specific interrupt symbol appears in the process of generating the coded solution results of any science and engineering problem, the code language model will immediately stop generating all coded solution results.

[0099] According to Table 2 above, when the coded solutions to the three engineering problems are generated at the same time, the second problem matches the specific interruption symbol “```” for the first time. At this time, the code language model will stop generating the coded solutions to the three engineering problems at the same time.

[0100] S430, extracting the target code block before the matched specific interrupt symbol, and inputting the target code block into a code interpreter to obtain an execution result corresponding to the target code block.

[0101] It is easy to understand that when using the code language model to solve science and engineering problems, it is also necessary to use a code interpreter to execute the code written by the model and obtain the corresponding execution results.

[0102] Specifically, after the code language model stops generating coded solution results, the last code block in the partially coded solution results generated for the current science and engineering question, that is, the target code block, can be matched through a regular expression.

[0103] Then, the target code block is input into the code interpreter, which executes the target code block and returns an execution result to the code language model. The execution result here can be a specific value obtained by executing the target code block or a specific calculation expression.

[0104] In a specific embodiment, the code interpreter returns an execution result of "9.8" for the target code block in the second question above. This execution result can be placed in an initially empty execution result buffer set. For details, see Table 3 below.

[0105] Table 3

[0106] .

[0107] It should be noted that in the execution result buffer set, rows 2-n correspond to multiple science and engineering questions respectively, the first column represents the execution result corresponding to each science and engineering question, and the second column represents the length of the execution result corresponding to each science and engineering question.

[0108] S440, placing the execution result after the matched specific interrupt symbol, and continuing to generate coded solution results corresponding to multiple engineering questions at the same time.

[0109] It can be understood that in this embodiment, the execution result buffer set is initialized to be empty, and the maximum generation length of each round of the code language model is set to a preset length (for example ). Among them, the execution result buffer set is used to cache the execution results output by the code interpreter, as shown in Table 3 above.

[0110] To place the execution result in the execution result buffer set after the matched specific interrupt character, specifically, first, according to the length of the execution result in the execution result buffer set, update the maximum generation length, specifically including: when there is only one execution result in the execution result buffer set, directly update the maximum generation length according to the length of the execution result; when there are multiple execution results in the execution result buffer set, update the maximum generation length according to the execution result with the shortest length.

[0111] The maximum generated length is updated directly according to the length of the execution result. That is to say, the maximum generated length is equal to the length of the execution result.

[0112] According to the execution result of the minimum length, the maximum generated length is updated. That is to say, the execution result of the minimum length in the execution result buffer is selected, and the maximum generated length is the same as the minimum length.

[0113] For example, in Table 3 above, there is only one execution result in the execution result buffer set, and the length of the execution result is 7. Then, the maximum generation length will be updated to 7 at this time.

[0114] After the maximum generation length is updated, based on the code language model, a random solution result is generated after the matched specific interrupt character, and at the same time, the solution results of other science and engineering questions that have not matched the specific interrupt character continue to be generated; among which, the length of the random solution result is the maximum generation length after the update.

[0115] Specifically, the code language model generates a random solution result in a specific interrupt symbol, and the length of the random solution result is the maximum generation length after the update, that is, the maximum generation length after the update.

[0116] Corresponding to Table 3 above, the code language model generates a random answer result "XXXXXXX" of length 7, as shown in Table 4 below.

[0117] Table 4

[0118] .

[0119] Finally, the random solution results are replaced with the execution results, and the coded solution results corresponding to multiple engineering questions are continuously generated simultaneously.

[0120] The random solution result is replaced with the execution result, including: for the execution result with the minimum length in the execution result buffer, the random solution result is directly replaced with the complete execution result.

[0121] Still taking Table 3 above as an example, since there is only one execution result, the minimum length must be 7, so at this time, the random answer result can be directly replaced with the complete execution result, for example, see the following Table 5.

[0122] Table 5

[0123] .

[0124] It should be noted that after the only execution result in the execution result buffer set is replaced after the target code block, the execution result buffer set is empty, and at this time the maximum generation length is updated to the preset length.

[0125] Replacing the random solution result with the execution result includes: for the execution result in the execution result buffer set whose length is greater than the minimum length, replacing the random solution result with a partial execution result; wherein the length of the partial execution result is the minimum length, and the other contents of the execution result except the partial execution result continue to be cached in the execution result buffer set, waiting to be replaced when the next round is generated.

[0126] It should be noted that the partial execution result here refers to the characters before the target length in the complete execution result, and the target length is the minimum length.

[0127] It is easy to understand that what is described here is the processing method when the execution result buffer set contains two or more execution results at the same time or encounters a forced interruption situation.

[0128] For example, in a specific embodiment, following Table 5, the code language model continues to generate coded solutions corresponding to multiple engineering questions at the same time. For the second time, a specific interrupt symbol is matched in the process of generating the coded solution of the first engineering question. For details, please refer to the following Table 6.

[0129] Table 6

[0130] .

[0131] At this time, the code language model stops generating all coded solution results and inputs the target code block into the code interpreter. At this time, the code interpreter returns an execution result "a1*t+1 / 2a2*t" and caches it in the execution result buffer set. At this time, the execution result buffer set can be seen in Table 7 below.

[0132] Table 7

[0133] .

[0134] Next, according to the length of the execution result "16", the maximum generation length is updated to 16. At this time, the code language model should randomly generate a random solution result after the matched specific interrupt symbol. However, when the random solution result with a length of 6 is generated, the coded solution result of the third engineering problem matches the specific interrupt symbol. At this time, the generation of all coded solution results can only be interrupted. The corresponding target code block is input into the code interpreter.

[0135] At this time, only the first 6 execution results (i.e., partial execution results) can be placed after the matched specific interrupt character, and the remaining 10 execution results can only be replaced when the next round is generated.

[0136] Continuing, the code interpreter returns the execution result "32" corresponding to the target code block in the coded solution result of the third engineering problem, and caches it in the execution result buffer set. At this time, the execution result buffer set can be seen in Table 8 below.

[0137] Table 8

[0138] .

[0139] For the situation in Table 7, the maximum generation length is updated according to the execution result with the minimum length in the execution result buffer set. Obviously, the minimum length is 7, so the maximum generation length is updated to 7.

[0140] The code language model starts to generate random solution results of length 7, and then, for the execution result with the minimum length "execution output:\n```32```", the generated random solution result is directly overwritten and replaced with "execution output:\n```32```" of length 7.

[0141] For the execution results "execution output:\n```a1*t+1 / 2a2*t```" whose length is greater than the minimum length, the generated random solution results are replaced with the execution results "*t+1 / 2a2" whose length is 7, and the execution results of the remaining length of 3 are replaced when the next round is generated. At this time, the execution result buffer set is as shown in Table 9.

[0142] Table 9

[0143] .

[0144] S450, iteratively execute steps 420-S440 until all science and engineering questions are completely answered and the iteration is stopped, and the target answer results of all science and engineering questions are output.

[0145] It is easy to understand that, following Table 9, the code language model continues to generate random solution results of length 3, and continues to generate solution results for other science and engineering questions that do not match the specific interrupt symbol.

[0146] Next, the random solution result is replaced with the remaining execution results in the execution result buffer, that is, “*t```” in Table 9 above.

[0147] At this point, all the science and engineering questions that were input have been completely answered, and the target answer results corresponding to all science and engineering questions have been output.

[0148] In this embodiment, by simultaneously inputting multiple engineering questions into a pre-trained code language model, coded solution results corresponding to the multiple engineering questions are generated simultaneously, and in the process of generating the coded solution results of the multiple engineering questions, when a specific interruption symbol in the coded solution result of any science and engineering question is matched, the generation of all coded solution results is stopped, the target code block before the matched specific interruption symbol is extracted, and the target code block is input into the code interpreter to obtain the execution result corresponding to the target code block, and then the execution result is placed after the matched specific interruption symbol, and the coded solution results corresponding to the multiple engineering questions are continuously generated simultaneously, and then, steps S420-S440 are iteratively executed until all science and engineering questions are completely answered, and the iteration is stopped, and the target solution results of all science and engineering questions are output. This method uses a code language model to simultaneously generate the natural language reasoning process and code calculation deduction process of science and engineering questions, and calls the code interpreter to execute the target code block in the process of generating the target solution result to assist in the generation of the final solution result. This process gives full play to the tool calling capability of the code language model, alleviates the problem that the algorithm itself is easily affected by model hallucinations, resulting in low accuracy of the final generated results, and effectively improves the reasoning ability of the code language model on science and engineering questions, thereby improving the accuracy of the answers to science and engineering questions.

[0149] Additionally, in some embodiments, Figure 5 The overall flow chart of the method for solving science and engineering problems based on a code language model provided by an embodiment of the present invention is shown.

[0150] like Figure 5 As shown, first, the science and engineering questions to be answered are obtained, and then the science and engineering questions are input into a pre-trained code language model. The code language model begins to generate coded solution results corresponding to the science and engineering questions, and in the generation process, a specific interrupt symbol is set to match the target code block, and the code interpreter is called to execute the target code block, so as to return the execution result to the code language model, thereby achieving the effect of assisting the code language model to generate the target solution result corresponding to the science and engineering questions.

[0151] In some other embodiments, the solution results of the present invention and the prior art for the same science and engineering problem are given.

[0152] It is easy to understand that the method for solving science and engineering problems based on the code language model provided by the embodiment of the present invention can effectively improve the reasoning ability of the model on science and engineering problems and alleviate the problem of calculation errors that are prone to occur in the model due to hallucinations.

[0153] The following is the solution results of the present invention and the prior art for the same science and engineering problem, which can be seen in Table 10 below.

[0154] Table 10

[0155] .

[0156] According to Table 10 above, the prior art that does not use a code interpreter to solve the problem has an illusion when calculating the instantaneous value of the start and end time speed, resulting in a calculation error, while the present invention uses a code interpreter to obtain the correct calculation result.

[0157] It should be noted that the two methods in Table 10 above use the markdown format when generating science formulas.

[0158] Corresponding to the science and engineering problem-solving method based on the code language model described in the above embodiments, the present invention also provides a science and engineering problem-solving device based on the code language model.

[0159] Specifically, Figure 6 A schematic diagram of the structure of a science and engineering problem-solving device based on a code language model provided by an embodiment of the present invention is shown.

[0160] like Figure 6 As shown, the device includes: a science and engineering question acquisition module 610, which is used to obtain science and engineering questions to be answered; a science and engineering question answering module 620, which is used to generate a target answer result according to the science and engineering questions based on a pre-trained code language model and a code interpreter; wherein the code language model is obtained by fine-tuning a training sample data set composed of science and engineering question samples and their corresponding coded answer result samples based on the pre-trained model.

[0161] In this embodiment, the science and engineering questions to be answered are obtained through the science and engineering question acquisition module 610, and the science and engineering question answering module 620 generates a target answer result according to the science and engineering questions based on the pre-trained code language model and code interpreter; wherein the code language model is fine-tuned based on the pre-trained model through a training sample data set consisting of science and engineering question samples and their corresponding coded answer result samples. The device generates the natural language reasoning process and code calculation deduction process of the science and engineering questions at the same time through the code language model, and calls the code interpreter to execute the target code block in the process of generating the target answer result to assist in the generation of the final answer result. This process gives full play to the tool calling ability of the code language model, alleviates the problem that the algorithm itself is easily affected by the model hallucination and the final generated result is not accurate, and effectively improves the reasoning ability of the code language model on science and engineering questions, thereby improving the accuracy of the answer to science and engineering questions.

[0162] It should be noted that the science and engineering problem-solving device based on the code language model provided in this embodiment can correspond to the science and engineering problem-solving method based on the code language model described in the above embodiments, and will not be repeated here.

[0163] Figure 7 An example of a physical structure diagram of an electronic device is shown in FIG. Figure 7 As shown, the electronic device may include: a processor 710, a communication interface 720, a memory 730 and a communication bus 740, wherein the processor 710, the communication interface 720 and the memory 730 communicate with each other through the communication bus 740. The processor 710 may call the logic instructions in the memory 730 to execute a method for solving science and engineering problems based on a code language model, the method comprising: obtaining science and engineering problems to be solved; based on a pre-trained code language model and a code interpreter, generating a target solution result according to the science and engineering problems; wherein the code language model is fine-tuned based on a pre-trained model through a training sample data set consisting of science and engineering problem samples and their corresponding coded solution result samples.

[0164] In addition, the logic instructions in the above-mentioned memory 730 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on this understanding, the technical solution of the present invention can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium, including several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. 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, etc. Various media that can store program codes.

[0165] On the other hand, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to execute the science and engineering problem-solving method based on a code language model provided by the above-mentioned methods, the method comprising: obtaining a science and engineering problem to be solved; based on a pre-trained code language model and a code interpreter, generating a target solution result according to the science and engineering problem; wherein the code language model is obtained by fine-tuning a training sample data set consisting of science and engineering problem samples and their corresponding coded solution result samples based on the pre-trained model.

[0166] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.

[0167] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.

[0168] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A method for solving science and engineering problems based on a code language model, characterized in that: include: Get science and engineering questions to be solved; Based on the pre-trained code language model and code interpreter, generate a target answer result according to the science and engineering questions; The code language model is obtained by fine-tuning a training sample data set based on a pre-trained model using samples of science and engineering questions and their corresponding coded solution result samples.

2. The method for solving science and engineering problems based on a code language model according to claim 1, characterized in that: Fine-tuning the code language model, specifically including: Acquire an initial problem-solving dataset, wherein the initial problem-solving dataset includes samples of science and engineering questions and their corresponding natural language answers; According to the science and engineering question samples and their corresponding natural language answers, as well as preset prompt words, a coded answer result sample is obtained to obtain a training sample data set; The science and engineering question samples are used as model input, the predicted coded solution results are used as model output, the difference between the coded solution result samples and the predicted coded solution results is used as training loss, and the pre-trained model is fine-tuned to obtain a pre-trained code language model.

3. The method for solving science and engineering problems based on a code language model according to claim 1, characterized in that: The number of science and engineering topics is single; Accordingly, the pre-trained code language model and code interpreter generate a target answer result according to the science and engineering question, including: S310, inputting the science and engineering question into a pre-trained code language model, and starting to generate a coded solution result corresponding to the science and engineering question; the coded solution result includes at least one specific interrupt symbol; S320, when any specific interruption symbol is matched during the process of generating the coded solution result, stop generating the coded solution result; S330, extracting the target code block before the matched specific interrupt symbol, and inputting the target code block into a code interpreter to obtain an execution result corresponding to the target code block; S340, placing the execution result after the matched specific interrupt symbol, and continuing to generate a coded solution result; S350, iteratively executing steps S320-S340 until the science and engineering problem is completely solved, and then the iteration is stopped and the target solution result is output.

4. The method for solving science and engineering problems based on a code language model according to claim 1, characterized in that: The number of science and engineering topics is multiple; Accordingly, the pre-trained code language model and code interpreter generate a target answer result according to the science and engineering question, including: S410, inputting multiple engineering problems into a pre-trained code language model at the same time, and starting to generate coded solution results corresponding to the multiple engineering problems at the same time; each coded solution result includes at least one specific interrupt symbol; S420, in the process of generating coded solution results for multiple science and engineering problems, when a specific interruption symbol in the coded solution results of any science and engineering problem is matched, stop generating all coded solution results; S430, extracting the target code block before the matched specific interrupt symbol, and inputting the target code block into a code interpreter to obtain an execution result corresponding to the target code block; S440, placing the execution result after the matched specific interrupt symbol, and continuing to generate coded solution results corresponding to multiple engineering questions at the same time; S450, iteratively executing steps S420-S440 until all science and engineering questions are completely answered, and then the iteration is stopped, and the target answer results of all science and engineering questions are output.

5. The method for solving science and engineering problems based on a code language model according to claim 4, characterized in that: Initialize the execution result buffer set to be empty, and set the maximum generation length of each round of the code language model to a preset length; the execution result buffer set is used to cache the execution results output by the code interpreter; Accordingly, placing the execution result after the matched specific interrupt symbol and continuing to generate coded solution results corresponding to multiple engineering questions simultaneously include: According to the length of the execution result in the execution result buffer, updating the maximum generation length; Based on the code language model, a random solution result is generated after the matched specific interruption character, and the solution results of other science and engineering questions that are not matched with the specific interruption character are continuously generated; the length of the random solution result is the maximum generated length after the update; The random solution result is replaced by the execution result, and the coded solution results corresponding to multiple engineering questions are continuously generated simultaneously.

6. The method for solving science and engineering problems based on a code language model according to claim 5, characterized in that: The updating of the maximum generation length according to the length of the execution result in the execution result buffer set comprises: When there are multiple execution results in the execution result buffer, updating the maximum generation length according to the execution result of the shortest length; Accordingly, replacing the random solution result with the execution result includes: For the execution result with the minimum length in the execution result buffer, directly replace the random answer result with the complete execution result; For execution results in the execution result buffer set whose length is greater than the minimum length, replacing the random solution result with a partial execution result; The length of the partial execution result is the minimum length, and the other contents of the execution result except the partial execution result continue to be cached in the execution result buffer set to be replaced when the next round is generated.

7. The method for solving science and engineering problems based on a code language model according to claim 6, characterized in that: When the execution result buffer set is empty, the maximum generation length is updated to a preset length.

8. A device for solving science and engineering problems based on a code language model, characterized in that: include: A science and engineering question acquisition module is used to acquire science and engineering questions to be answered; A science and engineering question-solving module, which is used to generate a target answer result according to the science and engineering question based on a pre-trained code language model and a code interpreter; The code language model is obtained by fine-tuning a training sample data set based on a pre-trained model using samples of science and engineering questions and their corresponding coded solution result samples.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the method for solving science and engineering problems based on a code language model according to any one of claims 1 to 7 is implemented.

10. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method for solving science and engineering problems based on a code language model as described in any one of claims 1 to 7 is implemented.