Prompt optimization method and device based on Monte Carlo tree and electronic equipment

Through the prompt optimization method based on Monte Carlo tree, the expert-level prompt production process is simulated and the prompt text is automatically tuned, which solves the problem of insufficient complexity and delicateness of the prompt generation prompts of the automated prompt engineering, and realizes the generation of human expert-level prompts.

CN119669383APending Publication Date: 2025-03-21ZHONGDIAN DATA IND CO LTD +1
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202411727299.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-28
Publication Date
2025-03-21

AI Technical Summary

Technical Problem

The prompts generated by the automated prompt project often cannot reach the complexity and delicateness of the human expert level, and face the challenge of how to automatically generate expert prompts.

Method used

The prompt optimization method based on Monte Carlo tree is used to simulate the expert-level prompt production process through the Monte Carlo tree search algorithm. Starting from the initial prompt text, different prompt optimization directions are automatically explored, and the prompt text is continuously and carefully tuned, and the Monte Carlo tree is gradually constructed and optimized, and the optimized Monte Carlo tree is obtained, and the optimal prompt text corresponding to the target text is determined from it.

Benefits of technology

This enables the prompts generated by the automation prompt engineering to reach the complexity and delicateness of the human expert level, solving the technical problems of low fineness and complexity of the automation prompt engineering.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119669383A_ABST
    Figure CN119669383A_ABST
Patent Text Reader

Abstract

The invention discloses a prompt optimization method and device based on a Monte Carlo tree, electronic equipment and a computer program product, and relates to the technical field of prompt engineering.The prompt optimization method based on the Monte Carlo tree comprises the steps that an initial prompt text corresponding to a target text is obtained, and the initial prompt text serves as a root node of the Monte Carlo tree; performing iterative optimization on the Monte Carlo tree through a Monte Carlo tree search algorithm to obtain an optimized Monte Carlo tree; and based on the optimized Monte Carlo tree, determining an optimal prompt text corresponding to the target text. According to the invention, the complexity and fineness of an automatic prompt project can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of prompt engineering technology, and in particular to a prompt optimization method, device, electronic device and computer program product based on a Monte Carlo tree. Background Art

[0002] Prompt engineering is a key area in the application of large language models, which aims to formulate effective prompts to unleash the full potential of large language models. In the field of artificial intelligence and natural language processing, with the development of large language models, how to effectively utilize these models has become a research hotspot.

[0003] At present, traditional prompt engineering relies heavily on human-computer interaction, which requires prompt designers to have rich domain knowledge and deep intuition of large language models to produce efficient prompts, and is overly dependent on the experience of experts. Automated prompt engineering reduces dependence on experts and improves efficiency in some cases by introducing technologies such as iterative sampling. However, the prompts generated by automated prompt engineering often cannot reach the complexity and sophistication of human expert levels, and face the challenge of how to automatically generate expert-level prompts. Summary of the invention

[0004] The main purpose of this application is to provide a prompt optimization method, device, electronic device and computer program product based on a Monte Carlo tree, aiming to solve the technical problem of low sophistication and complexity of automated prompt engineering.

[0005] To achieve the above objectives, the present application provides a prompt optimization method based on a Monte Carlo tree, the method comprising:

[0006] Obtaining an initial prompt text corresponding to the target text, and using the initial prompt text as the root node of the Monte Carlo tree;

[0007] Iteratively optimizing the Monte Carlo tree by using a Monte Carlo tree search algorithm to obtain an optimized Monte Carlo tree;

[0008] Based on the optimized Monte Carlo tree, the optimal prompt text corresponding to the target text is determined. In one embodiment, the target text is a target question generation text, and the step of iteratively optimizing the Monte Carlo tree by a Monte Carlo tree search algorithm to obtain the optimized Monte Carlo tree includes:

[0009] Based on a preset selection strategy, selecting a node to be expanded from the Monte Carlo tree;

[0010] Inputting the prompt text corresponding to the node to be expanded and the target question generation text into a pre-trained question generation model to obtain a question set corresponding to the node to be expanded;

[0011] Inputting the question set corresponding to the node to be expanded into a pre-trained opinion feedback model to obtain feedback opinions corresponding to the node to be expanded;

[0012] Inputting the prompt text and feedback corresponding to the node to be expanded into a pre-trained prompt improvement model to obtain an improved prompt text corresponding to the node to be expanded;

[0013] Based on the improved prompt text corresponding to the node to be expanded, the node to be expanded is expanded to obtain a node to be simulated;

[0014] Simulating the node to be simulated to obtain a simulation result corresponding to the node to be simulated;

[0015] Back propagation is performed based on the simulation results corresponding to the nodes to be simulated to update the weight parameters of all nodes on the path from the nodes to be simulated to the root node, and the step of selecting the nodes to be expanded from the Monte Carlo tree based on the preset selection strategy is returned to be executed until the Monte Carlo tree meets the preset iteration termination condition to obtain an optimized Monte Carlo tree.

[0016] In one embodiment, the weight parameter includes an average reward, and the step of determining the optimal prompt text corresponding to the target text based on the optimized Monte Carlo tree includes:

[0017] The node with the highest average reward in the optimized Monte Carlo tree is determined as the target node, and the prompt text corresponding to the target node is determined as the optimal prompt text corresponding to the target question generated text.

[0018] In one embodiment, the step of determining the prompt text corresponding to the target node as the optimal prompt text corresponding to the target question generated text includes:

[0019] Inputting the question set corresponding to the target node into a pre-trained question quality evaluation model to obtain the question quality evaluation corresponding to the target node;

[0020] When the question quality evaluation corresponding to the target node is the first question quality evaluation, the prompt text corresponding to the target node is determined as the optimal prompt text corresponding to the target question generated text.

[0021] In one embodiment, the method further comprises:

[0022] When the question quality evaluation corresponding to the target node is the second question quality evaluation, deleting the optimized Monte Carlo tree, and returning to execute the step of using the initial prompt text as the root node of the Monte Carlo tree;

[0023] The second question quality evaluation is different from the first question quality evaluation.

[0024] In one embodiment, the method further comprises:

[0025] Obtaining a preset question generation text list, wherein the question generation text list includes a plurality of different question generation texts of a target type;

[0026] Taking each question generation text as the target text respectively, and executing the step of obtaining the initial prompt text corresponding to the target text, obtaining the optimal prompt text corresponding to each question generation text, the optimal question set corresponding to each optimal prompt text, and the optimal question quality evaluation corresponding to each optimal question set, wherein the optimal question set is composed of at least one optimal question, the optimal question is a question generated by the optimal prompt text, and the optimal question quality evaluation includes the effectiveness evaluation of each optimal question in the optimal question set;

[0027] According to the number of optimal problems in each optimal problem set and the number of optimal problem sets, the average number of problems in the optimal problem set is calculated, and according to the effectiveness evaluation of each optimal problem in each optimal problem set, the problem effectiveness corresponding to each optimal problem set is determined;

[0028] Substituting the question efficiency corresponding to each optimal question set and the average number of questions in the optimal question set into a preset comprehensive score calculation formula, calculating the comprehensive score corresponding to each optimal question set, and determining the optimal prompt text corresponding to the optimal question set with the highest comprehensive score as the optimal prompt corresponding to the target type;

[0029] The comprehensive score calculation formula is:

[0030] score = a*Avg+b*Eff;

[0031] Among them, score is the comprehensive score, Avg is the average number of questions in the optimal question set, Eff is the question efficiency, a is the first preset experience value, and b is the second preset experience value.

[0032] In one embodiment, the step of inputting the question set corresponding to the node to be expanded into a pre-trained feedback model to obtain feedback corresponding to the node to be expanded includes:

[0033] Input the target question generation text, the question set corresponding to the node to be expanded, and a small number of preset samples corresponding to the target type into a pre-trained opinion feedback model to obtain feedback opinions corresponding to the node to be expanded;

[0034] The preset small number of samples includes a plurality of different question generation text samples of the target type, and a question set corresponding to each of the question generation text samples.

[0035] In addition, to achieve the above purpose, the present application also provides a prompt optimization device based on a Monte Carlo tree, and the prompt optimization device based on a Monte Carlo tree includes:

[0036] An initial module, used to obtain an initial prompt text corresponding to the target text, and use the initial prompt text as the root node of the Monte Carlo tree;

[0037] An optimization module, used for iteratively optimizing the Monte Carlo tree by using a Monte Carlo tree search algorithm to obtain an optimized Monte Carlo tree;

[0038] A determination module is used to determine the optimal prompt text corresponding to the target text based on the optimized Monte Carlo tree.

[0039] In addition, to achieve the above-mentioned purpose, the present application also provides an electronic device, which includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the Monte Carlo tree-based prompt optimization method as described above.

[0040] In addition, to achieve the above-mentioned purpose, the present application also provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, the steps of the Monte Carlo tree-based prompt optimization method as described above are implemented.

[0041] The present application provides a prompt optimization method, device, electronic device and computer program product based on a Monte Carlo tree. The present application simulates an expert-level prompt production process through a Monte Carlo tree search algorithm, automatically explores different prompt optimization directions starting from an initial prompt text, continuously and meticulously tunes the prompt text, and selects the most promising node for expansion in each iteration to generate a new prompt variant, thereby gradually constructing and optimizing the Monte Carlo tree to obtain an optimized Monte Carlo tree, and determining the optimal prompt text corresponding to the target text therefrom, thereby making the prompts generated by the automated prompt engineering reach the complexity and sophistication of human experts, solving the technical problem of low sophistication and complexity of the automated prompt engineering. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

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

[0044] Figure 1 A flowchart diagram of the first embodiment of the prompt optimization method based on the Monte Carlo tree of the present application;

[0045] Figure 2 A flow chart of the second embodiment of the prompt optimization method based on the Monte Carlo tree of the present application;

[0046] Figure 3 A flowchart diagram of the third embodiment of the prompt optimization method based on the Monte Carlo tree of the present application;

[0047] Figure 4 This is a schematic diagram of the module structure of the prompt optimization device based on the Monte Carlo tree in an embodiment of the present application;

[0048] Figure 5 Schematic diagram of the device structure of the hardware operating environment involved in the Monte Carlo tree-based prompt optimization method in the embodiment of the present application.

[0049] The purpose, features and advantages of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION

[0050] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application and are not used to limit the present application.

[0051] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.

[0052] At present, traditional prompt engineering relies heavily on human-computer interaction, which requires prompt designers to have rich domain knowledge and deep intuition of large language models to produce efficient prompts, and is overly dependent on the experience of experts. Automated prompt engineering reduces dependence on experts and improves efficiency in some cases by introducing technologies such as iterative sampling. However, the prompts generated by automated prompt engineering often cannot reach the complexity and sophistication of human expert levels, and face the challenge of how to automatically generate expert-level prompts.

[0053] The main solution of the embodiment of the present application is: obtain the initial prompt text corresponding to the target text, and use the initial prompt text as the root node of the Monte Carlo tree; iteratively optimize the Monte Carlo tree through the Monte Carlo tree search algorithm to obtain the optimized Monte Carlo tree; based on the optimized Monte Carlo tree, determine the optimal prompt text corresponding to the target text.

[0054] The embodiment of the present application simulates the expert-level prompt production process through the Monte Carlo tree search algorithm, starting from the initial prompt text, automatically explores different prompt optimization directions, continuously and carefully tunes the prompt text, and selects the most promising node in each iteration for expansion to generate new prompt variants, thereby gradually building and optimizing the Monte Carlo tree, obtaining the optimized Monte Carlo tree, and determining the optimal prompt text corresponding to the target text, thereby making the prompts generated by the automated prompt engineering reach the complexity and sophistication of human experts, solving the technical problem of low sophistication and complexity of the automated prompt engineering.

[0055] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.

[0056] This application proposes a prompt optimization method of the first embodiment, please refer to Figure 1 , Figure 1 A flowchart diagram of the first embodiment of the prompt optimization method based on the Monte Carlo tree of the present application is provided.

[0057] In this embodiment, the prompt optimization method based on the Monte Carlo tree includes steps S100 to S300:

[0058] Step S100, obtaining an initial prompt text corresponding to the target text, and using the initial prompt text as the root node of the Monte Carlo tree;

[0059] It should be noted that the target text refers to the original input information that the user wants the large language model to generate a specific response or output based on its content. It can be a paragraph, a question, a task description, or any other form of text data. The initial prompt text is a prompt text to be optimized to guide the large language model on how to understand the target text and generate a specific response or output. It is the starting point of the prompt optimization process.

[0060] For example, the target text may be a description of a medical condition, and the user hopes that the large language model will generate diagnosis and treatment recommendations based on the description of the medical condition. The initial prompt text corresponding to the target text may be "Please generate a detailed diagnosis and treatment recommendation based on this case, including a treatment plan and precautions."

[0061] Those skilled in the art will know that the Monte Carlo tree search algorithm is a search algorithm that combines the Monte Carlo method and tree search. It constructs and optimizes a decision tree, also known as a Monte Carlo tree, by repeatedly executing the four stages of "selection-expansion-simulation-backpropagation", so as to make decisions in an uncertain environment based on the final generated Monte Carlo tree.

[0062] This embodiment obtains the initial prompt text corresponding to the target text, and uses the initial prompt text as the root node of the Monte Carlo tree to complete the initialization of the Monte Carlo tree, thereby providing a starting point for the subsequent optimization process and ensuring that there is a clear starting point in the subsequent iterative optimization process through the Monte Carlo tree search algorithm.

[0063] Step S200, iteratively optimizing the Monte Carlo tree by using a Monte Carlo tree search algorithm to obtain an optimized Monte Carlo tree;

[0064] In this embodiment, the Monte Carlo tree search algorithm continuously optimizes the prompt text through four sub-steps of selection, expansion, simulation and back propagation. Specifically, selection refers to selecting the most potential node from the current Monte Carlo tree for the next step, expansion refers to generating new prompt variants, i.e., new nodes, based on the selected nodes, simulation refers to evaluating the newly generated prompt variants, usually by letting the large language model generate content based on the prompt variant to measure its effectiveness, and back propagation refers to feeding back the simulation results to all relevant nodes in the tree and updating their weight parameters to facilitate the selection process in subsequent iterations. Through multiple iterations, the tree building process of the Monte Carlo tree search algorithm can simulate the expert-level prompt manufacturing process, thereby gradually discovering those prompt variants that can more effectively guide the large language model to generate high-quality content, improve the complexity and sophistication of the automated prompt engineering, effectively solve the technical problems of low sophistication and complexity of the automated prompt engineering, and avoid the problem of over-reliance on expert experience and manual adjustment in traditional prompt engineering.

[0065] Step S300: determining the optimal prompt text corresponding to the target text based on the optimized Monte Carlo tree.

[0066] It should be noted that the optimal prompt text is obtained by simulating the expert-level prompt creation process through the Monte Carlo tree search algorithm and performing multiple rounds of iterative optimization on the initial prompt text. Compared with the initial prompt text, the optimal prompt text can guide the large language model to understand the initial prompt text more effectively and generate a higher quality specific response or output.

[0067] This embodiment simulates the expert-level prompt production process through the four sub-steps of selection, expansion, simulation and back propagation in the Monte Carlo tree search algorithm. Starting from the initial prompt text, it automatically explores different prompt optimization directions, continuously and carefully tunes the prompt text, and selects the most potential node to expand in each iteration to generate new prompt variants, thereby gradually building and optimizing the Monte Carlo tree to obtain the optimized Monte Carlo tree. Then, from the optimized Monte Carlo tree, according to the weight parameters of each node, the prompt variant is determined as the optimal prompt text corresponding to the target text, thereby making the prompt generated by the automated prompt engineering reach the complexity and sophistication of human experts, solving the technical problem of low sophistication and complexity of the automated prompt engineering.

[0068] Based on the above embodiments, the present application proposes a second embodiment of a prompt optimization method based on a Monte Carlo tree, please refer to Figure 2 , Figure 2 A flowchart diagram of the second embodiment of the prompt optimization method based on the Monte Carlo tree of the present application is provided.

[0069] In this embodiment, the same or similar contents as those in the above embodiments can be referred to the above introduction and will not be described in detail later.

[0070] In this embodiment, the target text is a target question generation text, and step S200 iteratively optimizes the Monte Carlo tree by using a Monte Carlo tree search algorithm to obtain an optimized Monte Carlo tree, which may include steps S210 to S270:

[0071] Step S210, selecting a node to be expanded from the Monte Carlo tree based on a preset selection strategy;

[0072] Those skilled in the art will appreciate that question generation is a natural language processing task, the goal of which is to automatically generate relevant questions based on given text content.

[0073] In this embodiment, the question generation text is the original input information corresponding to the natural language processing task of the question generation type, that is, the original input information that the user hopes the large language model to generate questions based on its content. The target question generation text is the question generation text of a specific type or field, such as the question generation text in the medical field, the question generation text in the architectural field, the question generation text that requires the generation of judgment type questions, the question generation text that requires the generation of short answer type questions, etc.

[0074] This embodiment is explained in detail by taking the target text as generating text for a specific type of question as an example. It can be understood that in addition to generating text for questions, the target text can also be the original input information corresponding to other types of natural language processing tasks such as entity extraction text and sentiment analysis text, and the prompt optimization is achieved using the same principle as this embodiment.

[0075] It is known to those skilled in the art that the selection strategy refers to a method used to determine which child node to select for expansion from the current Monte Carlo tree in the Monte Carlo Tree Search (MCTS) algorithm. Common selection strategies used by those skilled in the art include UCT (Upper Confidence Bound for Trees) and PGS (Policy-Guided Selection).

[0076] It should be noted that the node to be expanded is a node selected from the current Monte Carlo tree for performing the expansion operation through a preset selection strategy.

[0077] This embodiment uses a preset selection strategy to select the most potential node from the current Monte Carlo tree for expansion, which can improve search efficiency and quality. Exemplarily, the selection strategy can be selected based on the number of visits and average reward of the node, ensuring that the node to be expanded selected for performing the expansion operation has a high potential value.

[0078] It is not difficult to understand that since there is only one root node in the initial Monte Carlo tree, that is, the initial prompt text, in the first round of iteration of the Monte Carlo tree, the selection strategy can only select the root node as the node to be expanded to perform the expansion operation.

[0079] Step S220, inputting the prompt text corresponding to the node to be expanded and the target question generation text into a pre-trained question generation model to obtain a question set corresponding to the node to be expanded;

[0080] It should be noted that in this embodiment, the question generation model is a pre-trained model that can generate a series of related questions based on the input prompt text and question generation text, that is, output a question set. It is not difficult to understand that the question set includes at least one question.

[0081] This embodiment generates a set of related questions through a question generation model according to the prompt text corresponding to the sub-node to be expanded and the target question generation text, thereby providing a basis for subsequent evaluation feedback and prompt improvement.

[0082] Step S230, inputting the question set corresponding to the node to be expanded into the pre-trained feedback model to obtain feedback opinions corresponding to the node to be expanded;

[0083] It should be noted that, in this embodiment, the feedback model is a pre-trained model that can generate a series of feedback opinions based on the input question set. The feedback opinions may include opinions pointing out defects or deficiencies in the question set, as well as opinions indicating directions for improvement.

[0084] The feedback model of this embodiment evaluates the generated question set and provides feedback, which provides important reference information for subsequent prompt improvements.

[0085] It is worth mentioning that when the feedback model evaluates the generated question set, a small number of relevant samples can also be input for reference by the feedback model, so as to obtain more professional and comprehensive feedback to better guide how to improve the prompt text.

[0086] Exemplarily, in a feasible implementation manner, step S230 may further include step S231:

[0087] Step S231, inputting the target question generation text, the question set corresponding to the node to be expanded, and a small number of preset samples corresponding to the target type into a pre-trained feedback model to obtain feedback opinions corresponding to the node to be expanded;

[0088] Among them, a small number of preset samples include a plurality of different question generation text samples of the target type, and a question set corresponding to each question generation text sample.

[0089] It should be noted that, in the present embodiment, the target type refers to the specific type or field to which the target question generation text belongs, the question generation text sample is the question generation text as a small number of samples, and the question set corresponding to the question generation text sample can be a series of related questions obtained by human experts through question generation based on the content of the question generation text sample, or can be a series of related questions obtained by inputting the question generation text sample and its corresponding prompt text into the question generation model after human experts design a prompt text for the question generation text sample to guide the large language model on how to better understand the question generation text sample and generate high-quality questions.

[0090] This embodiment inputs a small number of preset samples with high professionalism and quality into the feedback model, so that the feedback model can refer to these professional samples when evaluating the generated question set, thereby generating more professional and comprehensive feedback. At the same time, the small number of preset samples covers a variety of situations under the target type, which helps to improve the generalization ability of the feedback model, so that it can provide consistent and high-quality feedback when facing different inputs under the target type.

[0091] Step S240, inputting the prompt text and feedback corresponding to the node to be expanded into a pre-trained prompt improvement model to obtain an improved prompt text corresponding to the node to be expanded;

[0092] It should be noted that, in this embodiment, the prompt improvement model is a pre-trained model, which can fine-tune the input prompt text according to the input feedback and generate a higher quality new prompt text, that is, improve the prompt text.

[0093] In this embodiment, the prompt improvement model improves the prompt text corresponding to the node to be expanded according to the feedback, and generates a higher quality improved prompt text. This step ensures the continuous optimization and improvement of the prompt text by introducing external feedback.

[0094] It is worth mentioning that the prompt improvement model can generate one or more improved prompt texts when generating improved prompt texts.

[0095] Step S250, based on the improvement prompt text corresponding to the node to be expanded, the node to be expanded is expanded to obtain a node to be simulated;

[0096] It should be noted that the node to be simulated is a node for performing simulation operations obtained by performing an expansion operation on the node to be expanded.

[0097] In this embodiment, the improved prompt text corresponding to the node to be expanded can be used as a child node of the node to be expanded, so as to expand the node to be expanded, and a node to be simulated for performing simulation operation is selected from the child nodes of the node to be expanded obtained by expansion.

[0098] It is understandable that when there is only one improvement prompt text corresponding to the node to be expanded, only one child node of the node to be expanded can be expanded, and at this time, the child node obtained by expansion is directly used as the node to be simulated. When there are multiple improvement prompt texts corresponding to the node to be expanded, multiple child nodes of the node to be expanded can be expanded, and then one of them can be selected as the node to be simulated through a certain strategy (such as random selection).

[0099] This embodiment expands the current node and generates a new child node based on improving the prompt text. This step expands the search space, explores more possibilities of prompt text, and provides more options for subsequent optimization.

[0100] Step S260, simulating the node to be simulated to obtain a simulation result corresponding to the node to be simulated;

[0101] It should be noted that, in this embodiment, the simulation of the node to be simulated can be based on the prompt text corresponding to the node to be simulated, guiding the question generation model to generate a question set corresponding to the target question generation text, and then evaluating the effectiveness and standardization of the generated question set to obtain the corresponding evaluation results as the simulation results. It can also be based on the node to be simulated as the starting point, through the question generation model, feedback model and prompt improvement model, continuously perform expansion operations to generate new child nodes until a preset termination condition is reached, such as the number of expansions is greater than a threshold, and then according to the prompt text corresponding to the latest child node expanded, guide the question generation model to generate a question set corresponding to the target question generation text, and evaluate the effectiveness and standardization of the generated question set to obtain the corresponding evaluation results as the simulation results.

[0102] Those skilled in the art will know that, through the simulation results of the node to be simulated, it can be determined whether the improvement direction represented by the node to be simulated has potential, as well as the level of potential, so that through subsequent back-propagation operations, the weight parameters of each node along the way are updated, so that in subsequent iterations, according to the latest weight parameters, the most potential node is selected as the node to be expanded to perform the expansion operation and conduct a new round of iterative search.

[0103] Step S270, back propagation is performed based on the simulation results corresponding to the node to be simulated to update the weight parameters of all nodes on the path from the node to be simulated to the root node, and the step of selecting the node to be expanded from the Monte Carlo tree based on the preset selection strategy is returned to execute until the Monte Carlo tree meets the preset iteration termination condition to obtain the optimized Monte Carlo tree.

[0104] Those skilled in the art will know that in the Monte Carlo tree search algorithm, the weight parameters of the nodes in the Monte Carlo tree mainly include the number of visits, cumulative rewards, average rewards, etc., wherein the number of visits refers to the number of times a specific node is selected and visited during the search process, the cumulative reward refers to the total reward obtained by reaching the final state through a series of actions starting from a certain node, and the average reward is the result of dividing the cumulative reward by the number of visits, which reflects the average reward that can be expected to be obtained each time this path is selected starting from a certain node.

[0105] It should be noted that after simulating and obtaining the simulation results corresponding to the nodes to be simulated, it is necessary to first convert the simulation results into rewards through a preset reward function, and then back propagate according to the converted rewards to update the weight parameters of each node along the way. As for the specific reward function setting, this embodiment does not limit it, and the user can flexibly set it according to actual needs.

[0106] Those skilled in the art will appreciate that each time the weight parameters of each node on the path are updated by back propagation, the number of visits to each node on the path is increased by 1, and the cumulative reward is increased by the reward corresponding to the result of this simulation. The average reward is recalculated by dividing the new cumulative reward by the new number of visits.

[0107] It should also be noted that, in this embodiment, the iteration termination condition is a preset condition. When the iteration termination condition is met, the process of iteratively optimizing the initial prompt text based on the Monte Carlo tree search algorithm (that is, the process of iteratively optimizing the Monte Carlo tree) stops. The iteration termination condition can be that the number of iterations reaches a preset number, the depth of the Monte Carlo tree reaches a preset depth, or a prompt text of sufficiently high quality is found.

[0108] It should be noted that, in this embodiment, the quality of the prompt text is reflected by the overall quality of the questions in the question set generated based on the prompt text, and the overall quality of the questions in the question set can be determined by pre-training a model specifically used to evaluate the quality of questions and generate quality scores or quality ratings.

[0109] This embodiment updates the weight parameters of all nodes on the path according to the simulation results, reflects the performance of these nodes in the search process, optimizes the Monte Carlo tree, improves the accuracy of selection and expansion in subsequent iterations, and ensures continuous improvement of the optimization process.

[0110] This embodiment ensures that the optimization process stops when the expected effect is achieved through the preset iteration termination condition. This step ensures the efficiency and controllability of the optimization process and avoids unnecessary waste of computing resources.

[0111] Further, in a feasible implementation, the weight parameter includes an average reward, and step S300 determines the optimal prompt text corresponding to the target text based on the optimized Monte Carlo tree, which may include step S310:

[0112] Step S310, determining the node with the highest average reward in the optimized Monte Carlo tree as the target node, and determining the prompt text corresponding to the target node as the optimal prompt text corresponding to the target question generation text.

[0113] In this embodiment, after multiple iterations of optimization, each node in the Monte Carlo tree contains a series of weight parameters, including the average reward. The average reward of each node in the optimized Monte Carlo tree is used as a quantitative indicator to scientifically evaluate the quality of the prompt text corresponding to each node, so that the node with the highest average reward in the optimized Monte Carlo tree is determined as the target node, and the prompt text corresponding to the target node is determined as the optimal prompt text corresponding to the target question generation text, ensuring that the selected prompt text performs best in the multiple iterations of the optimized Monte Carlo tree and has the highest quality and relevance.

[0114] Further, in a feasible implementation manner, the step of determining the prompt text corresponding to the target node as the optimal prompt text corresponding to the target question generated text in step S310 may include steps S311 to S312:

[0115] Step S311, inputting the question set corresponding to the target node into a pre-trained question quality evaluation model to obtain the question quality evaluation corresponding to the target node;

[0116] It should be noted that the question quality evaluation model is a pre-trained model that can perform quality evaluation on an input question set and output a corresponding question quality evaluation, which represents the overall quality of the questions in the question set.

[0117] In this embodiment, the question quality evaluation may be a quality score or a quality rating.

[0118] Step S312: When the question quality evaluation corresponding to the target node is the first question quality evaluation, the prompt text corresponding to the target node is determined as the optimal prompt text corresponding to the target question generated text.

[0119] It should be noted that, in this embodiment, the first question quality evaluation indicates that the overall quality of the questions in the question set is relatively high.

[0120] This implementation method evaluates the question set corresponding to the target node through a question quality evaluation model to ensure that the questions generated based on the prompt text corresponding to the target node have a high overall quality. In this way, not only the target node is selected through the average reward, but the quality of the question set is further verified through the question quality evaluation model. Through the dual evaluation mechanism, the misjudgment caused by a single indicator is reduced, the accuracy of the selection is improved, and it is ensured that the selected prompt text is optimal.

[0121] Furthermore, in a feasible implementation manner, the prompt optimization method based on the Monte Carlo tree further includes step S400:

[0122] Step S400, when the question quality evaluation corresponding to the target node is the second question quality evaluation, the optimized Monte Carlo tree is deleted, and the process returns to the step of using the initial prompt text as the root node of the Monte Carlo tree;

[0123] Among them, the second question quality evaluation is different from the first question quality evaluation.

[0124] It should be noted that, in this embodiment, the first question quality evaluation indicates that the overall quality of the questions in the question set is low.

[0125] In this embodiment, when the problem quality evaluation corresponding to the target node is the second problem quality evaluation, that is, the overall quality of the problems in the problem set corresponding to the target node is low, it indicates that the optimized Monte Carlo tree obtained by the Monte Carlo tree search algorithm has quality problems and is not suitable for selecting the target node therefrom. Therefore, the optimized Monte Carlo tree is deleted, and the step of using the initial prompt text as the root node of the Monte Carlo tree is returned to execute, and starting from the initial prompt text again, a new Monte Carlo tree is constructed through a new round of Monte Carlo tree search algorithm to ensure that the overall quality of the optimized Monte Carlo tree is excellent.

[0126] Based on the above embodiments, the present application proposes a third embodiment of a prompt optimization method based on a Monte Carlo tree, please refer to Figure 3 , Figure 3 A flowchart diagram of the third embodiment of the prompt optimization method based on the Monte Carlo tree of the present application is provided.

[0127] In this embodiment, the same or similar contents as those in the above embodiments can be referred to the above introduction and will not be described in detail later.

[0128] In this embodiment, the prompt optimization method based on the Monte Carlo tree further includes steps S500 to S800:

[0129] Step S500, obtaining a preset question generation text list, wherein the question generation text list includes a plurality of different question generation texts of a target type;

[0130] Step S600, taking each question generation text as the target text, and executing the step of obtaining the initial prompt text corresponding to the target text, obtaining the optimal prompt text corresponding to each question generation text, the optimal question set corresponding to each optimal prompt text, and the optimal question quality evaluation corresponding to each optimal question set, wherein the optimal question set is composed of at least one optimal question, the optimal question is a question generated by the optimal prompt text, and the optimal question quality evaluation includes the effectiveness evaluation of each optimal question in the optimal question set;

[0131] This embodiment uses the question generation texts in the question generation text list as target texts respectively, and uses the Monte Carlo tree-based prompt optimization method provided in the above embodiments to determine the optimized Monte Carlo tree corresponding to each question generation text, thereby obtaining the optimal prompt text corresponding to each question generation text, the optimal question set corresponding to each optimal prompt text, and the optimal question quality evaluation corresponding to each optimal question set.

[0132] It can be understood that in the optimized Monte Carlo tree corresponding to the question generation text, the question set corresponding to the target node is the optimal question set, and the question quality evaluation corresponding to the target node is the optimal question quality evaluation. In addition, the optimal question set can be obtained by directly inputting the question generation text and its corresponding optimal prompt text into the question generation model, and then the optimal question set is input into the question quality evaluation model to obtain the optimal question quality evaluation.

[0133] It should be noted that, in this embodiment, effectiveness evaluation refers to the evaluation of whether the question is effective.

[0134] Step S700, calculating the average number of problems in the optimal problem set according to the number of optimal problems in each optimal problem set and the number of optimal problem sets, and determining the problem efficiency corresponding to each optimal problem set according to the effectiveness evaluation of each optimal problem in each optimal problem set;

[0135] It should be noted that, in this embodiment, the average number of problems in the optimal problem set refers to the average number of optimal problems in each problem set among multiple optimal problem sets, which reflects the average level of the number of problems in each optimal problem set. Problem efficiency refers to the proportion of effective problems in each optimal problem set, and effective problems refer to problems whose effectiveness is evaluated as effective.

[0136] In this embodiment, the average number of problems in the optimal problem set is obtained by dividing the sum of the numbers of optimal problems in each optimal problem set by the number of optimal problem sets, and the problem efficiency is obtained by dividing the number of problems evaluated as effective in the optimal problem set by the number of optimal problems in the optimal problem set.

[0137] Step S800, substituting the question efficiency and the average number of questions in each optimal question set into a preset comprehensive score calculation formula, calculating the comprehensive score corresponding to each optimal question set, and determining the optimal prompt text corresponding to the optimal question set with the highest comprehensive score as the optimal prompt corresponding to the target type;

[0138] The comprehensive score calculation formula is:

[0139] score = a*Avg+b*Eff;

[0140] Among them, score is the comprehensive score, Avg is the average number of questions in the optimal question set, Eff is the question efficiency, a is the first preset experience value, and b is the second preset experience value.

[0141] It should be noted that, in this embodiment, the first preset experience value and the second preset experience value are both weight coefficients pre-set by the user, and their specific values ​​can be flexibly adjusted according to actual conditions, mainly used to balance the impact of inconsistent numbers of optimal questions generated by different optimal prompt texts.

[0142] It should also be noted that the optimal prompt is the best general prompt text generated for the entire target type. The comprehensive score is used to filter out the optimal prompt under the target type from multiple optimal prompt texts.

[0143] This embodiment targets a question generation task of a specific type or field (i.e., the target type), and generates an optimized Monte Carlo tree corresponding to different question generation texts under the specific type or field through a Monte Carlo tree search algorithm, thereby selecting the optimal prompt text corresponding to the optimal question set with the highest comprehensive score from the optimal prompt texts of each question generation text under the specific type or field through a comprehensive score calculation formula, as the optimal prompt corresponding to the specific type or field, and then the optimal prompt can be used as the optimal prompt text for all question generation texts under the specific type or field, and it can be ensured that when the optimal prompt is used to guide the large language model to understand any question generation text under the specific type or field and generate a corresponding question set, a high-quality question set can be obtained, which takes into account both universality and high quality under the specific type or field.

[0144] Through this embodiment, it is possible to obtain high-quality optimal prompts that are common to all question generation tasks of a specific type or field. Therefore, when constructing a corpus for question generation tasks of this specific type or field, the optimal prompts can be used to batch process question generation texts to obtain corresponding question sets, and the question generation texts and their corresponding question sets can be associated and stored in the corpus, thereby completing the corpus construction of the question generation tasks of this specific type or field efficiently and with high quality.

[0145] It can be understood that, in the above, this embodiment is explained in detail by taking the target type of question generation task as an example. Similar to the above second embodiment, other types of natural language processing tasks such as target type entity extraction text, sentiment analysis text, etc. can also be used. The method with the same principle as this embodiment can be used to generate optimal prompts. Therefore, when constructing a corpus of other natural language processing tasks (such as entity extraction tasks, sentiment analysis tasks, etc.) under a specific type or field, the natural language processing task texts (such as entity extraction texts, sentiment analysis texts, etc.) are batch processed through the corresponding generated optimal prompts to obtain corresponding output responses, and the natural language processing task texts and their corresponding output responses are associated and stored in the corpus, thereby completing the corpus construction of other natural language processing tasks under this specific type or field efficiently and with high quality.

[0146] In addition, this application also provides a prompt optimization device based on Monte Carlo tree, please refer to Figure 4 , Figure 4 This is a schematic diagram of the module structure of a prompt optimization device based on a Monte Carlo tree according to an embodiment of the present application.

[0147] In this embodiment, the prompt optimization device based on the Monte Carlo tree includes:

[0148] An initial module 10 is used to obtain an initial prompt text corresponding to the target text, and use the initial prompt text as the root node of the Monte Carlo tree;

[0149] An optimization module 20, configured to iteratively optimize the Monte Carlo tree by using a Monte Carlo tree search algorithm to obtain an optimized Monte Carlo tree;

[0150] The determination module 30 is used to determine the optimal prompt text corresponding to the target text based on the optimized Monte Carlo tree.

[0151] In one embodiment, the optimization module 20 is further configured to:

[0152] The target text is the text generated by the target question. The Monte Carlo tree is iteratively optimized through the Monte Carlo tree search algorithm to obtain the optimized Monte Carlo tree. The steps include:

[0153] Based on the preset selection strategy, select the node to be expanded from the Monte Carlo tree;

[0154] Input the prompt text and target question generation text corresponding to the node to be expanded into the pre-trained question generation model to obtain the question set corresponding to the node to be expanded;

[0155] Input the question set corresponding to the node to be expanded into the pre-trained opinion feedback model to obtain the feedback opinions corresponding to the node to be expanded;

[0156] Input the prompt text and feedback corresponding to the node to be expanded into the pre-trained prompt improvement model to obtain the improved prompt text corresponding to the node to be expanded;

[0157] Based on the improved prompt text corresponding to the node to be expanded, the node to be expanded is expanded to obtain the node to be simulated;

[0158] Simulate the node to be simulated and obtain the simulation result corresponding to the node to be simulated;

[0159] Back propagation is performed based on the simulation results corresponding to the nodes to be simulated to update the weight parameters of all nodes on the path from the nodes to be simulated to the root node, and the step of selecting the nodes to be expanded from the Monte Carlo tree based on the preset selection strategy is returned until the Monte Carlo tree meets the preset iteration termination condition to obtain the optimized Monte Carlo tree.

[0160] In one embodiment, the weight parameter includes an average reward, and the determination module 30 is further configured to:

[0161] The node with the highest average reward in the optimized Monte Carlo tree is determined as the target node, and the prompt text corresponding to the target node is determined as the optimal prompt text corresponding to the target question generation text.

[0162] In one embodiment, the determination module 30 is further configured to:

[0163] Input the question set corresponding to the target node into the pre-trained question quality evaluation model to obtain the question quality evaluation corresponding to the target node;

[0164] When the question quality evaluation corresponding to the target node is the first question quality evaluation, the prompt text corresponding to the target node is determined as the optimal prompt text corresponding to the target question generated text.

[0165] In one embodiment, the Monte Carlo tree-based prompt optimization device is further used for:

[0166] When the question quality evaluation corresponding to the target node is the second question quality evaluation, the optimized Monte Carlo tree is deleted, and the process returns to the step of using the initial prompt text as the root node of the Monte Carlo tree;

[0167] Among them, the second question quality evaluation is different from the first question quality evaluation.

[0168] In one embodiment, the Monte Carlo tree-based prompt optimization device is further used for:

[0169] Obtaining a preset question generation text list, wherein the question generation text list includes a plurality of different question generation texts of a target type;

[0170] Taking each question generation text as the target text respectively, and executing the step of obtaining the initial prompt text corresponding to the target text, obtaining the optimal prompt text corresponding to each question generation text, the optimal question set corresponding to each optimal prompt text, and the optimal question quality evaluation corresponding to each optimal question set, wherein the optimal question set is composed of at least one optimal question, the optimal question is a question generated by the optimal prompt text, and the optimal question quality evaluation includes the effectiveness evaluation of each optimal question in the optimal question set;

[0171] According to the number of optimal problems in each optimal problem set and the number of optimal problem sets, the average number of problems in the optimal problem set is calculated, and according to the effectiveness evaluation of each optimal problem in each optimal problem set, the problem effectiveness corresponding to each optimal problem set is determined;

[0172] Substitute the question efficiency and the average number of questions in each optimal question set into the preset comprehensive score calculation formula to calculate the comprehensive score of each optimal question set, and determine the optimal prompt text corresponding to the optimal question set with the highest comprehensive score as the optimal prompt corresponding to the target type;

[0173] The comprehensive score calculation formula is:

[0174] score = a*Avg+b*Eff;

[0175] Among them, score is the comprehensive score, Avg is the average number of questions in the optimal question set, Eff is the question efficiency, a is the first preset experience value, and b is the second preset experience value.

[0176] In one embodiment, the optimization module 20 is further configured to:

[0177] Input the target question generation text, the question set corresponding to the node to be expanded, and a small number of preset samples corresponding to the target type into the pre-trained opinion feedback model to obtain the feedback opinions corresponding to the node to be expanded;

[0178] Among them, a small number of preset samples include a plurality of different question generation text samples of the target type, and a question set corresponding to each question generation text sample.

[0179] The Monte Carlo tree-based prompt optimization device provided by the present application adopts the Monte Carlo tree-based prompt optimization method in the above-mentioned embodiment, which can solve the technical problem of low sophistication and complexity of automated prompt engineering. Compared with the prior art, the beneficial effects of the Monte Carlo tree-based prompt optimization device provided by the present application are the same as the beneficial effects of the Monte Carlo tree-based prompt optimization method provided by the above-mentioned embodiment, and other technical features in the Monte Carlo tree-based prompt optimization device are the same as the features disclosed in the above-mentioned embodiment method, which will not be repeated here.

[0180] In addition, this application also provides an electronic device, please refer to Figure 5 , Figure 5 Schematic diagram of the device structure of the hardware operating environment involved in the Monte Carlo tree-based prompt optimization method in the embodiment of the present application.

[0181] In this embodiment, the electronic device includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the Monte Carlo tree-based prompt optimization method in the above-mentioned embodiment.

[0182] Reference below Figure 5 , which shows a schematic diagram of the structure of an electronic device suitable for implementing the embodiments of the present application. The electronic devices in the embodiments of the present application may include, but are not limited to, mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., fixed terminals such as digital TVs, desktop computers, physical servers, etc., and cloud servers. Figure 5 The electronic device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0183] like Figure 5As shown, the electronic device may include a processing device 1001 (e.g., a central processing unit, a graphics processor, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. In RAM1004, various programs and data required for the operation of the electronic device are also stored. The processing device 1001, ROM1002, and RAM1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Generally, the following systems can be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touch pad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD: Liquid Crystal Display), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 can allow the electronic device to communicate with other devices wirelessly or by wire to exchange data. Although the figure shows an electronic device with various systems, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems can be implemented or have alternatively.

[0184] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.

[0185] The electronic device provided by the present application adopts the prompt optimization method based on the Monte Carlo tree in the above embodiment, which can solve the technical problem of low sophistication and complexity of the automated prompt engineering. Compared with the prior art, the beneficial effects of the electronic device provided by the present application are the same as the beneficial effects of the prompt optimization method based on the Monte Carlo tree provided in the above embodiment, and the other technical features in the electronic device are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.

[0186] In addition, the present application also provides a storage medium having computer-readable program instructions (ie, computer programs) stored thereon, wherein the computer-readable program instructions are used to execute the Monte Carlo tree-based prompt optimization method in the above-mentioned embodiment.

[0187] The storage medium provided in the present application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, systems or devices, or any combination of the above. More specific examples of storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this embodiment, the storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, system or device. The program code contained on the storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination of the above.

[0188] The above storage medium may be included in the electronic device; or may exist independently without being installed in the electronic device.

[0189] The storage medium carries one or more programs. When the one or more programs are executed by an electronic device, the electronic device: obtains an initial prompt text corresponding to a target text, and uses the initial prompt text as a root node of a Monte Carlo tree; iteratively optimizes the Monte Carlo tree through a Monte Carlo tree search algorithm to obtain an optimized Monte Carlo tree; and determines the optimal prompt text corresponding to the target text based on the optimized Monte Carlo tree.

[0190] Computer program code for performing the operations of the present application may be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages ​​such as Java, Smalltalk, C++, and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0191] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0192] The modules involved in the embodiments described in this application may be implemented by software or hardware, wherein the name of the module does not constitute a limitation on the unit itself in some cases.

[0193] The storage medium provided in this application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned prompt optimization method based on the Monte Carlo tree, and can solve the technical problem of low sophistication and complexity of automated prompt engineering. Compared with the prior art, the beneficial effects of the medium provided in this application are the same as the beneficial effects of the prompt optimization method based on the Monte Carlo tree provided in the above-mentioned embodiment, and will not be repeated here.

[0194] In addition, the present application also provides a computer program product, including a computer program, which implements the steps of the Monte Carlo tree-based prompt optimization method as described above when executed by a processor.

[0195] The computer program product provided by the present application can solve the technical problem of low sophistication and complexity of automated prompt engineering. Compared with the prior art, the beneficial effects of the computer program product provided by the present application are the same as the beneficial effects of the prompt optimization method based on the Monte Carlo tree provided in the above embodiment, which will not be elaborated here.

[0196] It should be understood that the various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.

[0197] The above descriptions are only some embodiments of the present application, and are not intended to limit the patent scope of the present application. All equivalent structural changes made using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect applications in other related technical fields are included in the patent protection scope of the present application.

Claims

1. A prompt optimization method based on Monte Carlo tree, characterized in that: The method comprises: Obtaining an initial prompt text corresponding to the target text, and using the initial prompt text as the root node of the Monte Carlo tree; Iteratively optimizing the Monte Carlo tree by using a Monte Carlo tree search algorithm to obtain an optimized Monte Carlo tree; Based on the optimized Monte Carlo tree, an optimal prompt text corresponding to the target text is determined.

2. The Monte Carlo tree-based prompt optimization method according to claim 1, characterized in that: The target text is a target question generated text, and the step of iteratively optimizing the Monte Carlo tree by using a Monte Carlo tree search algorithm to obtain an optimized Monte Carlo tree includes: Based on a preset selection strategy, selecting a node to be expanded from the Monte Carlo tree; Inputting the prompt text corresponding to the node to be expanded and the target question generation text into a pre-trained question generation model to obtain a question set corresponding to the node to be expanded; Inputting the question set corresponding to the node to be expanded into a pre-trained opinion feedback model to obtain feedback opinions corresponding to the node to be expanded; Inputting the prompt text and feedback corresponding to the node to be expanded into a pre-trained prompt improvement model to obtain an improved prompt text corresponding to the node to be expanded; Based on the improved prompt text corresponding to the node to be expanded, the node to be expanded is expanded to obtain a node to be simulated; Simulating the node to be simulated to obtain a simulation result corresponding to the node to be simulated; Back propagation is performed based on the simulation results corresponding to the nodes to be simulated to update the weight parameters of all nodes on the path from the nodes to be simulated to the root node, and the step of selecting the nodes to be expanded from the Monte Carlo tree based on the preset selection strategy is returned to be executed until the Monte Carlo tree meets the preset iteration termination condition to obtain an optimized Monte Carlo tree.

3. The Monte Carlo tree-based prompt optimization method according to claim 2, characterized in that: The weight parameter includes an average reward. The step of determining the optimal prompt text corresponding to the target text based on the optimized Monte Carlo tree includes: The node with the highest average reward in the optimized Monte Carlo tree is determined as the target node, and the prompt text corresponding to the target node is determined as the optimal prompt text corresponding to the target question generated text.

4. The Monte Carlo tree-based prompt optimization method according to claim 3, characterized in that: The step of determining the prompt text corresponding to the target node as the optimal prompt text corresponding to the target question generated text comprises: Inputting the question set corresponding to the target node into a pre-trained question quality evaluation model to obtain the question quality evaluation corresponding to the target node; When the question quality evaluation corresponding to the target node is the first question quality evaluation, the prompt text corresponding to the target node is determined as the optimal prompt text corresponding to the target question generated text.

5. The Monte Carlo tree-based prompt optimization method according to claim 4, characterized in that: The method further comprises: When the question quality evaluation corresponding to the target node is the second question quality evaluation, deleting the optimized Monte Carlo tree, and returning to execute the step of using the initial prompt text as the root node of the Monte Carlo tree; The second question quality evaluation is different from the first question quality evaluation.

6. The Monte Carlo tree-based prompt optimization method as claimed in claim 5, characterized in that: The method further comprises: Obtaining a preset question generation text list, wherein the question generation text list includes a plurality of different question generation texts of a target type; Taking each question generation text as the target text respectively, and executing the step of obtaining the initial prompt text corresponding to the target text, obtaining the optimal prompt text corresponding to each question generation text, the optimal question set corresponding to each optimal prompt text, and the optimal question quality evaluation corresponding to each optimal question set, wherein the optimal question set is composed of at least one optimal question, the optimal question is a question generated by the optimal prompt text, and the optimal question quality evaluation includes the effectiveness evaluation of each optimal question in the optimal question set; According to the number of optimal problems in each optimal problem set and the number of optimal problem sets, the average number of problems in the optimal problem set is calculated, and according to the effectiveness evaluation of each optimal problem in each optimal problem set, the problem effectiveness corresponding to each optimal problem set is determined; Substituting the question efficiency corresponding to each optimal question set and the average number of questions in the optimal question set into a preset comprehensive score calculation formula, calculating the comprehensive score corresponding to each optimal question set, and determining the optimal prompt text corresponding to the optimal question set with the highest comprehensive score as the optimal prompt corresponding to the target type; The comprehensive score calculation formula is: score = a*Avg+b*Eff; Among them, score is the comprehensive score, Avg is the average number of questions in the optimal question set, Eff is the question efficiency, a is the first preset experience value, and b is the second preset experience value.

7. The Monte Carlo tree-based prompt optimization method as claimed in claim 6, characterized in that: The step of inputting the question set corresponding to the node to be expanded into a pre-trained feedback model to obtain feedback corresponding to the node to be expanded includes: Input the target question generation text, the question set corresponding to the node to be expanded, and a small number of preset samples corresponding to the target type into a pre-trained opinion feedback model to obtain feedback opinions corresponding to the node to be expanded; The preset small number of samples includes a plurality of different question generation text samples of the target type, and a question set corresponding to each of the question generation text samples.

8. A prompt optimization device based on Monte Carlo tree, characterized in that: The prompt optimization device based on the Monte Carlo tree comprises: An initial module, used to obtain an initial prompt text corresponding to the target text, and use the initial prompt text as the root node of the Monte Carlo tree; An optimization module, used for iteratively optimizing the Monte Carlo tree by using a Monte Carlo tree search algorithm to obtain an optimized Monte Carlo tree; A determination module is used to determine the optimal prompt text corresponding to the target text based on the optimized Monte Carlo tree.

9. An electronic device, characterized in that: The electronic device comprises: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the Monte Carlo tree-based hint optimization method according to any one of claims 1 to 7.

10. A computer program product, characterized in that The computer program product comprises a computer program, and when the computer program is executed by a processor, the steps of the Monte Carlo tree-based hint optimization method according to any one of claims 1 to 7 are implemented.

Citation Information

Cited By

  • Text classification method and device, equipment, medium and product

    CN121144520A

  • Text classification method, apparatus, device, medium, and product

    CN121144520B