Text generation method, storage medium, electronic device and program product

By analyzing the semantic information of the query request and dynamically selecting the target generation mode, the time-consuming retrieval problem in the text generation process is solved, and faster and more accurate reply text generation is achieved, improving the user experience.

CN119884333BActive Publication Date: 2025-08-08INSPUR SUZHOU INTELLIGENT TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202510388873.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-03-31
Publication Date
2025-08-08
Estimated Expiration
2045-03-31

AI Technical Summary

Technical Problem

The prior art requires searching during text generation, which makes the search process time-consuming and affects the user experience.

Method used

By obtaining the semantic information of the query request, determining the target generation mode, and using this mode to obtain reply information and generate reply text, dynamically adjust the text generation method, and selecting a generation mode that matches the query request.

Benefits of technology

Improves the response speed and accuracy of query and improves user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119884333B_ABST
    Figure CN119884333B_ABST
Patent Text Reader

Abstract

The present application discloses a text generation method, storage medium, electronic device, and program product, relating to the field of data processing technology. The method comprises: first obtaining semantic information of a query request; then determining a target generation mode corresponding to the query request based on the semantic information; then replying to the query request using the target generation mode to obtain reply information corresponding to the query request; and finally generating a reply text corresponding to the query request based on the reply information and the query request. In this way, the semantic information of the query request input by the user can be analyzed to obtain the semantic information to determine the query scope of the query request, select a target generation mode that matches the query scope, and generate a reply text corresponding to the query request using the reply information obtained by the target generation mode. Thus, the text generation mode is dynamically adjusted according to the classification of the query request, and a more targeted target generation model is used to generate the reply text, thereby improving the response speed and accuracy of the query.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of data processing technology, and in particular to a text generation method, a storage medium, an electronic device, and a program product. Background Art

[0002] Text generation is an important task in the field of natural language processing. It usually requires automatically generating matching readable text based on the input or context given by the user to answer the questions raised by the user.

[0003] Currently, related technologies require searching for questions raised by users during the text generation process. The search process is time-consuming, which in turn affects the user experience. Summary of the Invention

[0004] The present disclosure provides a text generation method, storage medium, electronic device, and program product. The main purpose is to solve the problem in related technologies that, during the text generation process, the user's questions need to be searched, and the search process is time-consuming, thereby affecting the user experience.

[0005] In a first aspect, the present application provides a text generation method, comprising:

[0006] Obtaining semantic information of query requests;

[0007] Determine a target generation mode corresponding to the query request based on the semantic information. The target generation mode is a text generation mode that matches the query scope of the query request. Different query request types correspond to different text generation modes.

[0008] Utilize the target generation mode to search the query request and obtain the response information corresponding to the query request;

[0009] Generate a reply text corresponding to the query request based on the reply information and the query request.

[0010] In a second aspect, the present application provides a text generation device, comprising:

[0011] an acquisition module configured to acquire semantic information of a query request;

[0012] a determination module configured to determine a target generation mode corresponding to the query request based on the semantic information, wherein the target generation mode is a text generation mode that matches the query scope of the query request, and different query request types correspond to different text generation modes;

[0013] an acquisition module configured to retrieve the query request using the target generation mode and obtain response information corresponding to the query request;

[0014] The generating module is configured to generate a reply text corresponding to the query request according to the reply information and the query request.

[0015] In a third aspect, the present application provides a computer-readable storage medium having a computer program stored thereon, which implements the method of the first aspect when the computer program is executed by a processor.

[0016] In a fourth aspect, the present application provides an electronic device comprising a storage medium, a processor, and a computer program stored on the storage medium and executable on the processor, wherein the processor implements the method of the first aspect when executing the computer program.

[0017] In a fifth aspect, the present application provides a computer program product having a computer program stored thereon, which implements the method of the first aspect when the computer program is executed by a processor.

[0018] The present disclosure provides a text generation method, storage medium, electronic device, and program product, wherein the method comprises: first obtaining semantic information of a query request; then, based on the semantic information, determining a target generation mode corresponding to the query request, wherein the target generation mode is a text generation mode that matches the query scope of the query request, and different query request types correspond to different text generation modes; then, using the target generation mode to reply to the query request, obtaining reply information corresponding to the query request; and finally, generating a reply text corresponding to the query request based on the reply information and the query request. In this way, the semantic information of the query request input by the user can be analyzed to obtain the semantic information to determine the query scope of the query request, select the target generation mode that matches the query scope, and use the reply information obtained by the target generation mode to generate the reply text corresponding to the query request, thereby dynamically adjusting the text generation method according to the classification of the query request, and using a more targeted target generation model to generate the reply text, thereby improving the response speed and accuracy of the query and enhancing the user experience.

[0019] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present application, nor is it intended to limit the scope of the present application. Other features of the present application will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] In order to more clearly illustrate the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0021] Figure 1 A flowchart of a text generation method provided in an embodiment of the present application is shown;

[0022] Figure 2 An example diagram of a Router model provided in an embodiment of the present application is shown;

[0023] Figure 3 An example diagram of a Critic model provided in an embodiment of the present application is shown;

[0024] Figure 4 The following is a flowchart of the model training provided by the embodiment of the present application;

[0025] Figure 5 An example diagram of an application system provided by an embodiment of the present application is shown;

[0026] Figure 6 A structural schematic diagram of a text generation device provided in an embodiment of the present application is shown. DETAILED DESCRIPTION

[0027] The following will be combined with the accompanying drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.

[0028] It should be noted that, in the description of this application, the terms "comprises," "includes," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. The terms "first," "second," etc., in this application are used to distinguish similar objects, and are not used to describe a particular order or sequence.

[0029] In practical applications, leveraging large language models (LLMs) to capture semantic information from query requests is a key step in modern natural language processing applications, particularly when building intelligent question-answering systems, search engines, and conversational systems. These models can provide a deep understanding of user query intent, extract key information, and generate more accurate and relevant responses. Related technologies typically leverage vertical domain data to fine-tune or retrain a large-scale pre-trained language model for text generation tasks. However, this approach typically consumes significant time and labor costs, increasing R&D cycles.

[0030] Specifically, the process of aligning a model trained on general data to vertical domain data may lead to a decline in the generalization ability of cognitive reasoning. Therefore, in vertical domain applications, the base model and vertical domain tasks and data are usually integrated based on the Retrieve Augmented Generation (RAG) architecture. The generalization ability of the agent in vertical domain applications is expanded by defining and building specific role templates, workflows, task combinations, and modules such as data or knowledge bases built based on vertical domains. Among them, one of the core functions of the retrieval augmentation model is text retrieval, and it usually takes a long time to execute the retrieval function and regenerate it. As the model scale increases and the size of the external retrieval database increases, the use of the original RAG model to generate responses often has a high delay, which reduces the user experience.

[0031] In order to improve the related technology in the text generation process, it is necessary to search for the questions raised by the user, and the search process is relatively time-consuming, thereby affecting the user experience. This embodiment provides a text generation method, such as Figure 1 As shown, the method comprises the following steps:

[0032] Step 101: Obtain semantic information of the query request.

[0033] In some embodiments, a query request input by a user can be received, and the semantic features of the query request can be analyzed. For example, intent recognition, entity extraction, etc. can be used to parse the semantic information corresponding to the query request, and the corresponding prompt word Prompt can be extracted based on the obtained semantic information to identify important words and entities in the query, which helps to classify the query request, such as factual questions, opinion inquiries, complex reasoning questions, etc. In this way, it is easy to understand the core intent of the user's query, extract key information, improve the efficiency of replying to the query request, and thereby improve the efficiency of generating the reply text.

[0034] Step 102: Determine a target generation mode corresponding to the query request based on the semantic information. The target generation mode is a text generation mode that matches the query scope of the query request. Different query request types correspond to different text generation modes.

[0035] Exemplarily, the target generation mode may include but is not limited to direct generation mode (such as direct answer mode, thought chain direct answer mode), indirect generation mode (such as retrieval generation mode, thought chain retrieval generation mode).

[0036] In some embodiments, the query scope corresponding to the query request, such as the common sense scope or search scope, can be determined based on the semantic information corresponding to the query request, and the query request type, such as direct query or indirect query, can be determined. For example, if the user's query question seeks specific information or answers, such as factual questions or definition explanations, which fall within the common sense scope, the corresponding query request type is a direct query and does not require a complex reasoning process. In this case, a direct generation mode can be used for text generation. If the semantic information determines that the query request requires external knowledge or data for a response, which falls within the search scope, the corresponding query request type is an indirect query. In this way, an indirect generation mode can be used to call the retrieval system to retrieve the query request and obtain the response information. In this way, a response information generation mode that better matches the query request scope can be dynamically selected, a more targeted text generation solution can be adopted, and the flexibility and efficiency of text generation can be improved.

[0037] Step 103: Use the target generation mode to respond to the query request and obtain response information corresponding to the query request.

[0038] For example, if the target generation mode is a direct generation mode, the base model in the preset retrieval model can be used to directly answer the query question, or through internal reasoning, matching response information can be obtained; if the target generation mode is an indirect generation mode, the query request can be routed to the retrieval system, and the retrieval system (such as a search engine or a vector database) can be used to retrieve the query request, and the retrieved text fragments can be sorted, summarized or reasoned to obtain response information, thereby effectively improving the accuracy and response speed of the query.

[0039] Step 104: Generate a reply text corresponding to the query request based on the reply information and the query request.

[0040] In some embodiments, the multiple reply messages retrieved can be integrated and improved according to the query request to obtain a readable reply text. Specifically, a general template for the reply text corresponding to each target generation mode can be preset, and relevant content can be dynamically filled in according to different query types. Accordingly, in the process of generating the reply text, duplicate information in the reply information can be removed to ensure that the final reply text does not contain redundant content; the retrieval results can also be sorted according to the relevance to the query, for example, the relevance score of each text is calculated and sorted according to the relevance to the query request; if the retrieval results contain similar information from multiple sources, it can be considered to merge this information into a more concise expression. For example, for descriptions about the same topic but from different passages, the core ideas can be extracted and combined; secondly, the reply information can be adjusted for semantic coherence, and the spliced text can be adjusted grammatically and semantically to ensure that the sentence transitions in the reply text are natural, thereby improving the fluency and readability of the reply text.

[0041] Compared to related technologies, this embodiment first obtains the semantic information of a query request; then, based on the semantic information, determines a target generation mode corresponding to the query request. The target generation mode is a text generation mode that matches the query scope of the query request, and different query request types correspond to different text generation modes. The target generation mode is then used to respond to the query request, obtaining response information corresponding to the query request. Finally, based on the response information and the query request, a reply text corresponding to the query request is generated. In this way, the semantic information of the query request input by the user is analyzed to obtain the semantic information to determine the query scope of the query request, select a target generation mode that matches the query scope, and use the response information obtained from the target generation mode to generate the reply text corresponding to the query request. This allows the text generation method to be dynamically adjusted based on the query request classification, and a more targeted target generation model is used to generate the reply text, thereby improving the query response speed and accuracy and enhancing the user experience.

[0042] Furthermore, as a refinement and extension of the above embodiment, in order to specifically illustrate the text generation process, optionally, a preset retrieval model can be used to determine the prompt words corresponding to the semantic information. The preset retrieval model is used to determine the prompt words that match the semantic information according to the retrieval strategy.

[0043] In some embodiments, multiple prompt words corresponding to different query scopes of the query request can be preset first. The prompt words may include but are not limited to direct answer prompt, thinking chain direct answer prompt, retrieval prompt, thinking chain retrieval prompt, etc. By detecting the prompt word type corresponding to the query request, the matching target generation mode is determined.

[0044] In some embodiments, a preset retrieval model can be constructed to parse the semantic information of a query request and obtain the query prompt word. The preset retrieval model may include a Router model (which may be called an Actor model). Specifically, the RAG model combines information retrieval and text generation, effectively improving the effectiveness of the generation model in text generation tasks. By introducing a retrieval process to obtain richer information, the generated content and accuracy are enhanced. In RAG, information retrieval technology is first used to retrieve information relevant to the current context from a large-scale text library. This retrieved information can be related articles, knowledge base entries, or other forms of structured or unstructured data.

[0045] For example, when the generator is trying to complete a text on a specific topic, RAG can retrieve related topic entries or a collection of documents on a specific topic as input. The retrieved information will be encoded into a vector representation and provided to the generator model together with the current context. The generator model will then use the retrieved information and the current context to generate the next text unit. This generation process usually adopts a conditional generation model, in which the generator takes contextual information and retrieved information as input and predicts the probability distribution of the next text unit. The generated text unit may be a word, a phrase, or a complete sentence, depending on the task.

[0046] Specifically, such as Figure 2 As shown in the figure, an example diagram of the Router model is shown. The Actor role is mainly based on the base model (which can be called the base large model), such as DeepSeekV3-671b, or the smaller Qwen2.5-72b. The base model is a model that has learned a large amount of language representation and can be used to directly identify the semantics of the query request. It determines the corresponding prompt words according to the retrieval strategy, and adds a two-layer linear layer and a Softmax() activation output to the final output layer. The output dimension of Softmax is the same as the dimension of the candidate operation Prompt, and the activation function can use ReLU.

[0047] Among them, base models (such as the BERT (Bidirectional Encoder Representations from Transformers) model and the GPT (Generative Pre-trained Transformer) series of models) usually adopt the Transformer architecture, which is an efficient neural network structure that models the input text through the attention mechanism. The GPT series of models can be used to generate coherent and logical articles, stories or conversations. The BERT model can be used for tasks such as question-answering systems, sentiment analysis and named entity recognition.

[0048] Optionally, the training process of the preset retrieval model includes: obtaining a sample query request and a sample retrieval strategy corresponding to the preset retrieval model; determining an advantage function corresponding to the sample query request and the sample retrieval strategy; calculating a loss function of the preset retrieval model based on the advantage function; and updating the training parameters of the preset retrieval model based on the gradient corresponding to the loss function.

[0049] In some embodiments, a reinforcement learning trajectory dataset can be constructed ,in, It can be a vectorized representation of the input sample query request, It can represent the strategy index corresponding to the sample retrieval strategy adopted. Can represent a given current As a reward for experience, It can be a vector representation of the system state at the next time step, which is generally a contextual representation of the output obtained after taking the strategy. In the training process of the preset retrieval model, the vectorized representation of the sample query request and the index of the sample retrieval strategy can be used first. Calculate the corresponding advantage function, and then obtain the loss function based on the calculation result of the advantage function, train the preset retrieval model based on the gradient descent method, and update the trainable parameters in the model. For example, the base model parameters in the preset retrieval model do not participate in the update, and the linear layer parameters added in the preset retrieval model can be trained, thereby reducing the hardware requirements for the operating environment of the preset retrieval model.

[0050] Optionally, determining the advantage function corresponding to the sample query request and the sample retrieval strategy includes: obtaining the prediction value corresponding to the sample query request and the prediction value corresponding to the sample retrieval strategy; and calculating the advantage function corresponding to the sample query request and the sample retrieval strategy based on the prediction value corresponding to the sample query request and the prediction value corresponding to the sample retrieval strategy.

[0051] For example, the Actor model input is a vector representation of the query request , the output result can be expressed as , that is, the strategy index of the selected strategy given the input problem As the output probability. In summary, after combining the policy gradient method and performing entropy regularization, the loss function of the corresponding Actor model is:

[0052]

[0053]

[0054] In the formula The vector representation requested for a given query and policy index The advantage function of is the entropy regularization term, For a given current As a reward for experience, The vectorized representation s of the current query request, in the given state The value predicted by the preset evaluation model (such as the Critic model) The vector representation corresponding to the next state after executing the strategy The predictive value under When the last state .

[0055] Specifically, Defined as:

[0056]

[0057] In the formula For a given query request (input question) and policy index The corresponding entropy.

[0058] Optionally, the method of this embodiment also includes: calling a preset evaluation model to evaluate the reply quality corresponding to the reply text, the preset evaluation model is used to predict the reply quality corresponding to different retrieval strategies in the preset retrieval model; updating the preset retrieval model according to the reply quality.

[0059] Among them, the preset evaluation model can be used to predict the value estimation of the base model under different choices of the Actor model , assists in training the preset retrieval model, whose structure is the base model as the main body, such as Figure 3 As shown in the figure, an example diagram of the Critic model is shown. The parameters of the base model in the Critic model do not participate in the training. The last layer adds two linear layers to output the predicted scalar value. , you can use the ReLU activation function to optimize the training parameters of the 2-layer linear layer according to the loss function. For example, the loss function of the Critic model is It can be expressed as:

[0060]

[0061] For example, during the training of the preset detection model, the advantage function can be calculated first. , and the vectorized representation of the query request given by the Critic model The predicted value of , then alternately calculate the loss functions of the Actor model and the Critic model, and update the trainable parameters of the corresponding models based on the gradient method.

[0062] Optionally, calling a preset evaluation model to evaluate the reply quality corresponding to the reply text includes: using the preset evaluation model to evaluate the reply quality corresponding to the reply text based on the generation time of the reply text.

[0063] In some embodiments, as Figure 4 As shown in the figure, the model training flow chart is shown. The Router model can be trained based on the Actor-Critic method in reinforcement learning to receive the query request input by the user, and then the query request is preprocessed and input into the Router model, and the Router model is used to determine the retrieval strategy. , identify the prompt words in the query request For example: direct answer prompt, thinking chain direct answer prompt, search prompt, thinking chain search prompt, the base model can execute the corresponding target generation mode according to the prompt word, and then use the critic model to generate the target according to the output of the base model. and the time the reply text was generated , and search strategies and query requests Calculate Reward and calculate the result Feedback is given to the Router model, which enables the Router model to optimize model parameters, thereby reducing the response time and improving the response efficiency while ensuring the response quality of the generated reply text.

[0064] Optionally, a preset evaluation model is used to evaluate the reply quality corresponding to the reply text based on the generation time of the reply text, including: obtaining the reply quality score of the reply text based on the similarity between the reply text and the reference reply text; and determining the reply quality corresponding to the reply text based on the reply quality score and the generation time of the reply text.

[0065] As a possible implementation method, based on the base model output And the output of the Critic model As a basis, calculate the benefits under the current choice, Reward ( ) is calculated as follows:

[0066]

[0067] In the formula, the ROUGE function is used to calculate the generated result and reference results The ROUGE similarity between them is used as the response quality score of the evaluation response text to measure the quality of the generated results covering the query, where the generated results Can be the currently generated reply text, reference result Can reply text for historical reference in the system, The time cost generated by the system calculation when the current prompt is selected for calculation, To balance the coefficient hyperparameters, they can be preset according to the actual environment version of the deployment system, so that the preset retrieval model can be evaluated based on time and response quality to ensure the quality of the generated response results while having the lowest possible time cost.

[0068] In this way, the reward function in reinforcement learning is modeled as a function of the response quality ROUGE score and the answer time cost, and the response quality and response efficiency of the retrieval-enhanced generation model are dynamically balanced through the reinforcement learning training process.

[0069] As another possible implementation method, the profit under the current selection can be calculated according to the following formula: :

[0070]

[0071] In the formula, ROUGE function generates the result of calculation And the corresponding step reference results The ROUGE similarity between them is used to measure the quality of query coverage of generated results. The time cost generated by the system calculation when the current prompt is selected for calculation, To balance the coefficient hyperparameters, manual tuning must be performed according to the actual deployment environment version of the system. is a Dirichlet process random variable, which is implemented by the Stick-breaking process and is defined as follows:

[0072]

[0073] in, is a Beta distribution, is a distribution parameter that can be adjusted as needed. The purpose of introducing this random variable is to balance the reward values of different steps in the thinking chain mode, that is, it satisfies The l-1 order simplex constraint, l is the length of the thinking chain, by setting different initial parameters Control the rewards for different thought chain lengths. When set to a smaller value, it encourages the model to complete the task with the shortest possible thought chain length, thereby reducing service delay. For example, it can be set to , increase the weight of the initial answer and reduce the weight of subsequent steps to encourage the model to complete the task in as few steps as possible, minimize the calculation and delay caused by multi-step iteration of the thinking chain, and have the lowest possible calculation and time cost while ensuring the quality of the generated response results.

[0074] Optionally, step 102 may specifically include: determining a prompt word corresponding to the query request based on semantic information; obtaining a concatenated text of the prompt word and the query request; and determining a target generation mode corresponding to the prompt word based on the concatenated text.

[0075] In some embodiments, the prompt word can be spliced with the query request, and the spliced text can be sent to the base model. The base model can be used to read the information in the spliced text, and the query request can be retrieved according to the target retrieval model corresponding to the prompt word to achieve classification of the query request.

[0076] Optionally, if the target generation mode is a direct generation mode, the target generation mode is used to retrieve the query request to obtain the response information corresponding to the query request, including: using the base model to respond to the query request according to the prompt word to obtain the response information corresponding to the query request.

[0077] In some embodiments, if the prompt word is a direct answer prompt, a direct generation mode can be used to directly answer the query request using the base model to generate reply information; if the prompt word is a thought chain direct answer prompt, the base model can be used to perform thought chain reasoning and obtain the corresponding reply information through a series of logical reasoning steps.

[0078] This method helps obtain more accurate response information, meet various user needs, achieve detailed classification of query requests, reduce system latency, and increase system throughput.

[0079] Optionally, if the target generation mode is an indirect generation mode, the target generation mode is used to search the query request to obtain the reply information corresponding to the query request, including: calling a retrieval system to search the query request to obtain the reply information corresponding to the query request.

[0080] For example, if the prompt is a search prompt, an indirect generation model can be used, routing the query request and prompt to the search system, relying on external knowledge or data to answer and obtain response information. The response information may include text snippets matching the query request, search results, etc. If the prompt is a thought chain search prompt, the query request and prompt can be routed to the search system, obtaining information such as search snippets, and then performing thought chain reasoning on the search snippets to generate response information, which is then used to generate the reply text.

[0081] Optionally, the retrieval system is called to search the query request according to the prompt word to obtain the reply information corresponding to the query request, including: constructing a query statement corresponding to the query request based on the prompt word; calling the retrieval system to search according to the query statement to obtain the text fragment matching the query statement; splicing the text fragment, query statement and prompt word to obtain the reply information.

[0082] For example, a query statement that can be recognized by the retrieval system can be constructed based on the recognized prompt words and combined with the query request. The retrieval system is then called to retrieve the query statement and obtain text fragments. The base model integrates and processes the information in the text fragments to generate and display reply information.

[0083] Optionally, step 104 may specifically include: using the base model to perform text processing on the reply information and the query request to generate a reply text.

[0084] In some embodiments, the base model can be used to highlight or elaborate on specific keywords in a query in the reply message to better meet the user's needs. The reply can also be logically structured based on the characteristics of one or more queries, and the language and format of the reply message can be improved to provide users with more readable reply text. For example, if the query is a comparison, the comparison points can be presented in a table format; if the query requires step-by-step instructions, the steps should be clearly listed in order.

[0085] As a possible implementation method, Figure 5 As shown, an example diagram of the application system is shown. Based on the Actor-Critic reinforcement learning technology, a dynamic routing model for the retrieval enhancement generation model can be constructed. The model can classify the query requests input by the user. For simple problems that can be directly solved by the RAG system base model, there is no need for retrieval and regeneration. For some problems with complex constraints, retrieval and regeneration can be performed. Among them, the dynamic routing model may include a Router model and a base model. The Router model can be used to determine the prompt words corresponding to the query request, such as: direct answer prompt, thinking chain direct answer prompt, retrieval prompt, and thinking chain retrieval prompt. The base model is then used to integrate the direct reply or the retrieved text to output the reply information corresponding to the query request. The Router model and the dynamic routing model can share a base model to reduce the hardware requirements for the model.

[0086] Specifically, the Router model is used to analyze the semantic information of the user query input, and the direct retrieval prompt, query retrieval prompt, or prompt with a thought chain version is dynamically selected according to the trained strategy. Different types of prompts are dynamically selected as the basic prompt according to the input query, and then the input query and prompt are spliced and input into the base model. The base model will directly answer the user's question according to the prompt's instructions, or the query is input into the retrieval system in the lower right corner. The retrieval system will return the matching text fragment and splice it with the basic prompt, user query and retrieval results into the base model to generate a reply. Among them, the base model is shared by the actor, critic and retrieval enhancement generation system, and the base model parameters are not updated, which reduces the hardware requirements for the operating environment. It should be noted that this embodiment is not limited to the two working modes defined by the prompts of retrieval and direct answer. The strategy of generating answers in a single step can also be strengthened through deep thinking methods such as thought chain or Monte Carlo tree search.

[0087] In specific application scenarios, dynamic routing strategies can be employed in conjunction with a multi-index architecture to achieve efficient query distribution. For example, routing techniques based on metadata (such as timestamps and domain tags) can direct queries to specific sub-indexes, reducing the scope of irrelevant data searches. For example, community detection techniques within knowledge graphs can map queries to relevant entities or topic communities, significantly improving search accuracy and speed. Furthermore, for multilingual scenarios, the system can automatically route queries to the corresponding language index using a language detection module, avoiding redundant computations during cross-language searches. Hybrid routing strategies can also be implemented, combining rule engines with machine learning models. For example, rules can be used to filter the underlying domains corresponding to query requests, and lightweight classification models can be used to further refine routing targets. This hierarchical approach can support adaptation to complex scenarios while ensuring efficiency. For example, reinforcement learning can be used to dynamically optimize routing paths based on historical search feedback. Furthermore, by analyzing the semantic features of queries, routing techniques can be used to map them to predefined knowledge graph nodes or vector space clustering regions. For example, Self-RAG adjusts the routing direction through semantic scoring before generating answers, giving priority to high-confidence data sources and reducing the interference of low-quality retrieval on the generation stage.

[0088] In this way, a dynamic routing selection method for retrieval enhancement generation system based on Actor-Critic reinforcement learning technology is implemented. It is suitable for single-round retrieval enhancement generation tasks and is still effective for multi-round retrieval enhancement generation tasks. It alleviates the delay problem in the RAG model and improves the user's system interaction experience.

[0089] Compared with the current existing technology, by analyzing the semantic information of the query request input by the user, obtaining the semantic information to determine the query scope of the query request, selecting the target generation mode that matches the query scope, and using the reply information obtained by the target generation mode to generate the reply text corresponding to the query request, the text generation method is dynamically adjusted according to the classification of the query request, and the reply text is generated using a more targeted target generation model, thereby improving the response speed and accuracy of the query. In addition, this embodiment can also use a preset retrieval model to determine the prompt word corresponding to the semantic information. When the target generation mode is direct generation, the base model can be used to directly reply to the query request and obtain the reply information. When the target generation mode is indirect generation, the reply information is obtained through the retrieval system. Finally, the base model integrates the reply information and the query request and outputs the final reply text. In this way, the information retrieval and text generation technologies are integrated, and the reply text with higher relevance can be generated more effectively, making the generated text more accurate and rich.

[0090] The embodiment of the present application also provides a text generation device, as Figure 1 The specific implementation of the method shown is as follows Figure 6 As shown, the device includes: an acquisition module 31, a determination module 32, and a generation module 33.

[0091] An acquisition module 31 is configured to acquire semantic information of a query request;

[0092] A determination module 32 is configured to determine a target generation mode corresponding to the query request based on the semantic information, where the target generation mode is a text generation mode that matches the query scope of the query request, and different query request types correspond to different text generation modes;

[0093] The acquisition module 31 is configured to respond to the query request using the target generation mode and obtain response information corresponding to the query request;

[0094] The generating module 33 is configured to generate a reply text corresponding to the query request according to the reply information and the query request.

[0095] In some examples of this embodiment, the determination module 32 is specifically configured to obtain a concatenated text of the prompt word and the query request; and determine a target generation mode corresponding to the prompt word according to the concatenated text.

[0096] In some examples of this embodiment, if the target generation mode is a direct generation mode, the determination module 32 is specifically configured to use the base model to respond to the query request according to the prompt word, and obtain the response information corresponding to the query request. The base model is a basic model obtained by training knowledge text data.

[0097] In some examples of this embodiment, if the target generation mode is the indirect generation mode, the acquisition module 31 is specifically configured to call the retrieval system to search the query request according to the prompt word and obtain the reply information corresponding to the query request.

[0098] In some examples of this embodiment, the acquisition module 31 is specifically configured to construct a query statement corresponding to the query request based on the prompt word; call the retrieval system to search according to the query statement to obtain a text fragment matching the query statement; splice the text fragment, query statement and prompt word to obtain reply information.

[0099] In some examples of this embodiment, the generation module 33 is specifically configured to use a preset evaluation model to evaluate the reply quality corresponding to the reply text based on the generation time of the reply text.

[0100] In some examples of this embodiment, the acquisition module 31 is specifically configured to determine the prompt word corresponding to the semantic information using a preset retrieval model, and the preset retrieval model is used to determine the prompt word matching the semantic information according to the retrieval strategy.

[0101] In some examples of this embodiment, the acquisition module 31 is specifically configured to obtain a sample query request and a sample retrieval strategy corresponding to a preset retrieval model; determine an advantage function corresponding to the sample query request and the sample retrieval strategy; calculate the loss function of the preset retrieval model based on the advantage function; and update the training parameters of the preset retrieval model based on the gradient corresponding to the loss function.

[0102] In some examples of this embodiment, the acquisition module 31 is specifically configured to obtain the prediction value corresponding to the sample query request and the prediction value corresponding to the sample retrieval strategy; and calculate the advantage function corresponding to the sample query request and the sample retrieval strategy based on the prediction value corresponding to the sample query request and the prediction value corresponding to the sample retrieval strategy.

[0103] In some examples of this embodiment, the acquisition module 31 is specifically configured to call a preset evaluation model to evaluate the reply quality corresponding to the reply text, and the preset evaluation model is used to predict the reply quality corresponding to different retrieval strategies in the preset retrieval model; and update the preset retrieval model according to the reply quality.

[0104] In some examples of this embodiment, the acquisition module 31 is specifically configured to use a preset evaluation model to evaluate the reply quality corresponding to the reply text based on the generation time of the reply text.

[0105] In some examples of this embodiment, the acquisition module 31 is specifically configured to obtain the reply quality score of the reply text based on the similarity between the reply text and the reference reply text; and determine the reply quality corresponding to the reply text based on the reply quality score and the generation time of the reply text.

[0106] It should be noted that for other corresponding descriptions of the functional units involved in the text generation device provided in this embodiment, please refer to Figure 1 The corresponding description in will not be repeated here.

[0107] Based on the above Figure 1 The method shown in FIG. 1 is a method for performing the above-mentioned steps. Accordingly, this embodiment further provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the computer program can realize the above-mentioned steps. Figure 1 The method shown.

[0108] Based on the above Figure 1 The method shown in FIG. 1 is a method for performing the above-mentioned operations. Accordingly, this embodiment further provides a computer program product having a computer program stored thereon. When the computer program is executed by a processor, the above-mentioned Figure 1 The method shown.

[0109] Based on this understanding, the technical solution of the present application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, USB flash drive, mobile hard disk, etc.), and includes a number of instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) to execute the methods of various implementation scenarios of the present application.

[0110] Based on the above Figure 1 The method shown, and Figure 6 In order to achieve the above-mentioned purpose, the embodiment of the present application further provides an electronic device, such as a personal computer or a server, which includes a storage medium and a processor; the storage medium is used to store a computer program; the processor is used to execute the computer program to achieve the above-mentioned Figure 1 The method shown.

[0111] In some embodiments, the physical device may further include a user interface, a network interface, a camera, a radio frequency (RF) circuit, a sensor, an audio circuit, a Wi-Fi module, and the like. The user interface may include a display, an input unit such as a keyboard, and the like. Optional user interfaces may also include a USB interface and a card reader interface. In some embodiments, the network interface may include a standard wired interface or a wireless interface (such as a Wi-Fi interface).

[0112] Those skilled in the art will understand that the above-mentioned physical device structure provided in this embodiment does not constitute a limitation on the physical device, and may include more or fewer components, or a combination of certain components, or different component arrangements.

[0113] The storage medium may also include an operating system and a network communication module. The operating system is a program that manages the hardware and software resources of the physical device, supporting the execution of information processing programs and other software and / or programs. The network communication module is used to enable communication between components within the storage medium, as well as with other hardware and software within the physical information processing device.

[0114] Through the description of the above embodiments, it is clear to those skilled in the art that the present invention can be implemented by means of software plus the necessary general hardware platform, or by hardware. By applying the solution of this embodiment, compared with the current existing technology, this embodiment analyzes the semantic information of the query request input by the user, obtains the prompt word corresponding to the semantic information, and then dynamically selects the target generation mode according to the prompt word, and uses the reply information obtained by the target generation mode to generate the reply text corresponding to the query request, thereby dynamically adjusting the search mode from a variety of search modes according to the query request, improving the flexibility of the search mode, thereby improving the accuracy and response speed of the query, improving the efficiency of text retrieval, reducing system delay, and thus improving the user experience. In addition, this embodiment can use a preset retrieval model to determine the prompt word corresponding to the semantic information. When the target generation mode is direct generation, the base model can be used to directly reply to the query request and obtain the reply information. When the target generation mode is indirect generation, the reply information is obtained through the retrieval system. Finally, the base model integrates the reply information and the query request and outputs the final reply text. In this way, the information retrieval and text generation technologies are integrated, and the reply text with higher relevance can be generated more effectively, making the generated text more accurate and rich.

[0115] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article, or device that includes a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, method, article, or device that includes the element.

[0116] The above are merely specific embodiments of the present application, which are intended to enable those skilled in the art to understand or implement the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to these embodiments herein, but rather is intended to conform to the widest scope consistent with the principles and novel features of the present application.

Claims

1. A text generation method, characterized in that: include: Obtaining semantic information of query requests; Determining prompt words corresponding to the semantic information using a preset retrieval model, wherein the preset retrieval model is used to determine prompt words matching the semantic information according to a retrieval strategy; wherein the prompt words include at least direct answer prompt words, thought chain direct answer prompt words, retrieval prompt words, and thought chain retrieval prompt words; Obtaining a concatenated text of the prompt word and the query request; Determining a target generation mode corresponding to the prompt word based on the concatenated text, the target generation mode being a text generation mode that matches a query scope of the query request, with different query request types corresponding to different text generation modes; wherein the text generation modes include a direct generation mode and an indirect generation mode, the direct generation mode being used to generate text when the query request type is a direct query, and the indirect generation mode being used to invoke a retrieval system to retrieve the query request and obtain response information when the query request type is an indirect query; the query scope includes at least a common sense scope and a search scope, the common sense scope corresponding to a direct query type and the search scope corresponding to an indirect query type; If the target generation mode is a direct generation mode, the base model is used to directly answer the query request according to the prompt word or obtain the answer information corresponding to the query request through internal reasoning. The base model is a basic model trained with knowledge text data; If the target generation mode is the indirect generation mode, the query request is routed to a retrieval system, the retrieval system is used to search the query request according to the prompt word, and the retrieved text fragments are sorted, summarized or inferred to obtain the response information corresponding to the query request; generating a reply text corresponding to the query request according to the reply information and the query request; The training process of the preset retrieval model includes: Obtaining a sample query request and a sample retrieval strategy corresponding to the preset retrieval model; Determining an advantage function corresponding to the sample query request and the sample retrieval strategy; Calculating the loss function of the preset retrieval model according to the advantage function; Updating the training parameters of the preset retrieval model based on the gradient corresponding to the loss function; The method further comprises: Calling a preset evaluation model to evaluate the quality of a reply corresponding to the reply text, the preset evaluation model being used to predict the quality of replies corresponding to different retrieval strategies in the preset retrieval model; wherein the preset retrieval model and the preset evaluation model share the base model; The preset retrieval model is updated according to the response quality.

2. The method according to claim 1, characterized in that The determining of the advantage function corresponding to the sample query request and the sample retrieval strategy includes: Obtaining the prediction value corresponding to the sample query request and the prediction value corresponding to the sample retrieval strategy; An advantage function corresponding to the sample query request and the sample retrieval strategy is calculated according to the prediction value corresponding to the sample query request and the prediction value corresponding to the sample retrieval strategy.

3. The method according to claim 1, characterized in that Utilizing the retrieval system to search the query request according to the prompt word and organizing, summarizing or inferring the retrieved text fragments to obtain response information corresponding to the query request, including: constructing a query statement corresponding to the query request based on the prompt word; Calling the retrieval system to perform a search based on the query statement to obtain text fragments that match the query statement; The text segment, the query statement and the prompt word are concatenated to obtain the response information.

4. The method according to claim 1, wherein Generating a reply text corresponding to the query request according to the reply information and the query request includes: The base model is used to perform text processing on the reply information and the query request to generate the reply text.

5. The method according to claim 1, wherein The calling of a preset evaluation model to evaluate the reply quality corresponding to the reply text includes: The preset evaluation model is used to evaluate the quality of the reply corresponding to the reply text based on the generation time of the reply text.

6. The method according to claim 5, characterized in that The step of utilizing the preset evaluation model to evaluate the quality of the reply corresponding to the reply text based on the generation time of the reply text includes: Obtaining a response quality score for the response text based on the similarity between the response text and the reference response text; The reply quality corresponding to the reply text is determined based on the reply quality score and the generation time of the reply text.

7. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.

8. An electronic device comprising a storage medium, a processor, and a computer program stored in the storage medium and executable on the processor, wherein: When the processor executes the computer program, the method according to any one of claims 1 to 6 is implemented.

9. A computer program product having a computer program stored thereon, characterized in that: When the computer program product is executed by a processor, the method according to any one of claims 1 to 6 is implemented.

Citation Information

Patent Citations

  • Information generation method and device, information interaction method and device, electronic equipment and medium

    CN119692478A