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

By analyzing the semantic information of the query request input by the user, determining the target generation mode, using this mode to obtain reply information and generate reply text, the time-consuming retrieval problem in the text generation process in the prior art is solved, the response speed and accuracy of the query are improved, and the user experience is improved.

CN119884333AActive Publication Date: 2025-04-25INSPUR SUZHOU INTELLIGENT TECH CO LTD

Patent Information

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

AI Technical Summary

Technical Problem

The prior art requires searching questions raised by users during text generation, which takes time to take and affects the user experience.

Method used

By obtaining the semantic information of the query request, determining the target generation mode corresponding to the query request, using the target generation mode to reply to the query request, obtaining the reply information, and generating a reply text based on the reply information.

Benefits of technology

By dynamically adjusting the text generation method, using a more targeted target generation model to generate reply text, improve the response speed and accuracy of the query, and improve user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119884333A_ABST
    Figure CN119884333A_ABST
Patent Text Reader

Abstract

The invention discloses a text generation method, a storage medium, electronic equipment and a program product, and relates to the technical field of data processing.The method comprises the steps that firstly, semantic information of a query request is obtained; determining a target generation mode corresponding to the query request according to the semantic information; replying the query request by using the target generation mode to obtain reply information corresponding to the query request; and finally, according to the reply information and the query request, generating a reply text corresponding to the query request. In this way, the semantic information of the query request input by the user is analyzed, the semantic information is obtained, the query range of the query request is determined, the target generation mode matched with the query range is selected, the reply information is obtained through the target generation mode, and the reply text corresponding to the query request is generated. Therefore, the text generation mode is dynamically adjusted according to the classification of the query request, the reply text is generated by using a more targeted target generation model, and the response speed and accuracy of query are improved.
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] At present, in the process of text generation, related technologies need to search for questions raised by users. 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 that in the text generation process of related technologies, it is necessary to search for questions raised by users, and the search process is relatively time-consuming, which affects the user experience.

[0005] In a first aspect, the present application provides a text generation method, comprising: Obtaining semantic information of the query request; Determine a target generation mode corresponding to the query request based on the semantic information, the target generation mode being a text generation mode that matches the query scope of the query request, and different query request types correspond to different text generation modes; Retrieve the query request using the target generation mode to obtain the response information corresponding to the query request; Based on the reply information and the query request, a reply text corresponding to the query request is generated.

[0006] In a second aspect, the present application provides a text generation device, comprising: An acquisition module, configured to acquire semantic information of a query request; A determination module is 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; An acquisition module is configured to retrieve the query request using the target generation mode to obtain the response information corresponding to the query request; The generation module is configured to generate a reply text corresponding to the query request according to the reply information and the query request.

[0007] 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.

[0008] 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.

[0009] 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.

[0010] The text generation method, storage medium, electronic device and program product provided by the present disclosure include: firstly, obtaining semantic information of a query request; then, determining 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; then, replying to the query request using the target generation mode, obtaining reply information corresponding to the query request; 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, the query scope of the query request can be determined by obtaining semantic information, the target generation mode that matches the query scope can be selected, and the reply text corresponding to the query request can be generated using the reply information obtained by the target generation mode, thereby dynamically adjusting the text generation mode according to the classification of the query request, and generating the reply text using a more targeted target generation model, thereby improving the response speed and accuracy of the query, and improving the user experience.

[0011] 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

[0012] 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 paying any creative work.

[0013] Figure 1 A schematic diagram of a flow chart of a text generation method provided in an embodiment of the present application is shown; Figure 2 An example diagram of a Router model provided in an embodiment of the present application is shown; Figure 3 An example diagram of a Critic model provided in an embodiment of the present application is shown; Figure 4A model training flow chart provided in an embodiment of the present application is shown; Figure 5 An example diagram of an application system provided by an embodiment of the present application is shown; Figure 6 A structural schematic diagram of a text generation device provided in an embodiment of the present application is shown. DETAILED DESCRIPTION

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

[0015] It should be noted that, in the description of this application, the terms "include", "comprise" or any other variant thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also includes other elements not explicitly listed, or also includes 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 specific order or sequence.

[0016] In practical applications, using large language models (LLM) to obtain semantic information of query requests is a key step in modern natural language processing applications, especially when building intelligent question-answering systems, search engines, and dialogue systems. By using these models, we can deeply understand the user's query intent, extract key information, and generate more accurate and relevant responses. Related technologies usually use vertical field data to fine-tune or retrain a large-scale pre-trained language model for text generation tasks. However, this method usually requires a lot of time and labor costs, which increases the R&D cycle.

[0017] Specifically, the process of aligning the model trained with general data to the vertical domain data may lead to a decline in the generalization ability of cognitive reasoning. Therefore, in vertical domain applications, the base model and the tasks and data of the vertical domain are usually integrated based on the Retrieve Augmented Generation (RAG) architecture, and the generalization ability of the agent in the vertical domain 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 enhancement 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 generation of responses using the original RAG model often has a high delay, which reduces the user experience.

[0018] 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 time-consuming, which in turn affects the user experience. This embodiment provides a text generation method, such as Figure 1 As shown, the method comprises the following steps: Step 101: Obtain semantic information of a query request.

[0019] 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 then improve the efficiency of generating the reply text.

[0020] 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.

[0021] 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).

[0022] In some embodiments, the query scope corresponding to the query request can be determined based on the semantic information corresponding to the query request, such as the common sense scope, the search scope, etc., and the query request type can be determined, such as direct query, indirect query, etc. For example, if the question queried by the user is used to seek specific information or answers, such as factual questions, definition explanations, etc., which belong to the common sense scope, the corresponding query request type is direct query, and does not require a complex reasoning process, then the direct generation mode can be used for text generation; if it is determined based on the semantic information that the query request needs to rely on external knowledge or data for a reply, it belongs to the search scope, and the corresponding query request type is indirect query, then the indirect generation mode can be used to call the search system to retrieve the query request and obtain the reply information. In this way, it is possible to dynamically select a reply information generation mode that better matches the request scope of the query request, adopt a more targeted text generation scheme, and improve the flexibility and efficiency of text generation.

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

[0024] Exemplarily, 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 matching response information can be obtained through internal reasoning; 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.

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

[0026] In some embodiments, multiple reply information 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 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 search 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 search results contain similar information from multiple sources, it can be considered to merge this information into a more concise expression. For example, for descriptions of the same topic but from different paragraphs, the core ideas can be extracted and combined; secondly, the semantic coherence of the reply information can be adjusted, and the grammatical and semantic adjustments of the spliced ​​text can be made to ensure that the sentence transition in the reply text is natural and improve the fluency and readability of the reply text.

[0027] Compared with the related art, this embodiment first obtains the semantic information of the query request; then, based on the semantic information, determines the 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; then, the query request is replied using the target generation mode to obtain the reply information corresponding to the query request; finally, based on the reply 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 can be analyzed, the query scope of the query request can be determined by obtaining the semantic information, the target generation mode that matches the query scope can be selected, and the reply information obtained by the target generation mode can be used 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 query response speed and accuracy, and improving the user experience.

[0028] Further, 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.

[0029] In some embodiments, a variety of prompt words corresponding to different query scopes of the query request may 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.

[0030] In some embodiments, a preset retrieval model can be constructed to parse the semantic information of the query request and obtain the prompt words of the query request. 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, which can effectively improve the effect of the generation model in the task of generating text. It introduces a retrieval process to obtain richer information to enhance the generated content and accuracy. In RAG, information retrieval technology is first used to retrieve information related to the current context from a large-scale text library. The retrieved information can be related articles, knowledge base entries, or other forms of structured or unstructured data.

[0031] 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, where 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.

[0032] Specifically, 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. The corresponding prompt words are determined according to the retrieval strategy. A two-layer linear layer and a Softmax() activation output are added 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.

[0033] Among them, the base models (such as the BERT (Bidirectional Encoder Representations from Transformers) model and the GPT (Generative Pre-trained Transformer) series 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 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.

[0034] 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 a gradient corresponding to the loss function.

[0035] In some embodiments, a reinforcement learning trajectory data set 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. It can be expressed as given current As a reward for experience, It can be a vector representation of the system state at the next time step, 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 to train the preset retrieval model. Calculate the corresponding advantage function, and then obtain the loss function according to 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. Exemplarily, 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.

[0036] 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.

[0037] 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 on it, the loss function of the corresponding Actor model is:

[0038]

[0039] 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, is the vectorized representation s of the current query request, in a 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 .

[0040] Specifically, Defined as:

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

[0042] 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.

[0043] 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 are not trained. The last layer adds 2 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:

[0044] For example, during the training of the preset detection model, the advantage function may be first calculated , and the vectorized representation of the given query request of the Critic model The predicted value of , and 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.

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

[0046] In some embodiments, Figure 4 As shown in the figure, the model training flow chart is shown. The Router model can be trained and constructed based on the Actor-Critic method in reinforcement learning, and the query request input by the user is received. Then, the query request is preprocessed and input into the Router model, and the retrieval strategy is determined using the Router model. , 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 request Calculate the reward and calculate the result The information is fed back to the Router model, which optimizes the model parameters, thereby reducing the response time and improving the response efficiency while ensuring the response quality of the generated response text.

[0047] 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.

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

[0049] 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 reply quality score of the evaluation reply 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 incurred by the system calculation when the current prompt is selected for calculation. In order to balance the coefficient hyperparameters, they can be preset according to the environment version of the actual deployment system, so that the preset retrieval model can be evaluated based on time and response quality to ensure the quality of generated response results while having the lowest possible time cost.

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

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

[0052] In the formula, the ROUGE function generates the result of the calculation And the corresponding steps reference results The ROUGE similarity between them is used to measure the quality of query coverage of the generated results. The time cost incurred 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 system environment version. is a Dirichlet Process random variable, which is implemented by the Stick-breaking process and is defined as follows:

[0053] 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 weighting of 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 iterations of the thinking chain, and have the lowest possible calculation and time cost while ensuring the quality of the generated response results.

[0054] Optionally, step 102 may specifically include: determining a prompt word corresponding to the query request according to 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 according to the concatenated text.

[0055] 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 searched according to the target retrieval model corresponding to the prompt word to achieve classification of the query request.

[0056] 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 reply information corresponding to the query request, including: using the base model to reply to the query request according to the prompt word to obtain the reply information corresponding to the query request.

[0057] In some embodiments, if the prompt word is a direct answer prompt, the direct generation mode can be used to use the base model to directly answer the query request and 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.

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

[0059] Optionally, if the target generation mode is an indirect generation mode, the target generation mode is used to retrieve 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.

[0060] For example, if the prompt word is a search prompt, the indirect generation mode can be used to route the query request and the prompt word to the search system, rely on external knowledge or data to answer, and obtain the reply information, wherein the reply information may include text segments matching the query request, search results, etc. If the prompt word is a thought chain search prompt, the query request and the prompt word can be routed to the search system to obtain information such as search segments, and then the search segments are subjected to thought chain reasoning to generate reply information for generating reply text.

[0061] Optionally, a 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.

[0062] Exemplarily, 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, and then the retrieval system is called to search the query statement to obtain text fragments. The base model integrates and processes the information in the text fragments to generate and display reply information.

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

[0064] In some embodiments, the base model can be used to highlight or explain in detail specific keywords in the query in the reply information to better meet the needs of users. The logical structure of the reply can also be organized according to the characteristics of one or more queries of the user, and the language and format of the reply information can be improved to provide users with a more readable reply text. For example, if it is a comparison query, the comparison points can be displayed in a table; if it is a step-by-step description query, the steps should be clearly listed in order.

[0065] 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 to perform retrieval regeneration. For some problems with complex constraints, retrieval 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. Then, the base model is used to integrate the text obtained by direct reply or retrieval, and the reply information corresponding to the query request is output. The Router model and the dynamic routing model can share a base model to reduce the hardware requirements for the model.

[0066] 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 thinking chain version is dynamically selected according to the trained and adjusted 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 fragments and the basic prompt, user query and retrieval results, and splice them 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 prompt of retrieval and direct answer, and the strategy of generating answers in a single step can also be strengthened through deep thinking methods such as thinking chain or Monte Carlo tree search.

[0067] In specific application scenarios, dynamic routing strategies can be used in combination with multi-index architectures to achieve efficient query distribution. For example, routing technology based on metadata (such as timestamps and domain tags) can direct queries to specific sub-indexes and reduce the scope of retrieval of irrelevant data. For example, through the community detection technology of the knowledge graph, queries are mapped to relevant entities or subject communities, significantly improving retrieval accuracy and speed. In addition, for multilingual scenarios, the system can automatically route queries to the index library of the corresponding language through the language detection module to avoid redundant calculations for cross-language retrieval. Correspondingly, a hybrid routing strategy combining rule engines and machine learning models can also be used. For example, the basic fields corresponding to query requests are filtered by rules, and the routing targets are further refined through lightweight classification models. Through this hierarchical approach, it is possible to support the adaptation of complex scenarios while ensuring efficiency. Exemplarily, the routing path can also be dynamically optimized based on historical retrieval feedback through reinforcement learning. In addition, by analyzing the semantic features of the query, it can be mapped to a predefined knowledge graph node or vector space clustering area based on routing technology. 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.

[0068] In this way, a dynamic routing selection method for retrieval enhancement generation system based on Actor-Critic reinforcement learning technology is implemented, which 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.

[0069] 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.

[0070] 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.

[0071] An acquisition module 31 is configured to acquire semantic information of a query request; A determination module 32 is 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; 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; 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.

[0072] 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.

[0073] 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 reply to the query request according to the prompt word, and obtain the reply information corresponding to the query request. The base model is a basic model obtained by training knowledge text data.

[0074] 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.

[0075] 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 the text fragment matching the query statement; splice the text fragment, query statement and prompt word to obtain the reply information.

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

[0077] 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.

[0078] 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 a loss function of the preset retrieval model based on the advantage function; and update the training parameters of the preset retrieval model based on a gradient corresponding to the loss function.

[0079] 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; based on the prediction value corresponding to the sample query request and the prediction value corresponding to the sample retrieval strategy, calculate the advantage function corresponding to the sample query request and the sample retrieval strategy.

[0080] 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.

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

[0082] 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.

[0083] 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.

[0084] Based on the above Figure 1 The method shown in the embodiment also provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the above-mentioned Figure 1 The method shown.

[0085] Based on the above Figure 1 The method shown in the embodiment also provides a computer program product, on which a computer program is stored, and when the computer program is executed by a processor, the above-mentioned Figure 1 The method shown.

[0086] 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.), including 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.

[0087] 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 also provides an electronic device, such as a personal computer, 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.

[0088] In some embodiments, the above-mentioned physical device may also include a user interface, a network interface, a camera, a radio frequency (RF) circuit, a sensor, an audio circuit, a WI-FI module, etc. The user interface may include a display, an input unit such as a keyboard, etc., and the optional user interface may also include a USB interface, a card reader interface, etc. The network interface may include a standard wired interface, a wireless interface (such as a WI-FI interface), etc. in some embodiments.

[0089] Those skilled in the art will appreciate 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 arrangements of components.

[0090] 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 above-mentioned physical device, and supports the operation of the information processing program and other software and / or programs. The network communication module is used to realize the communication between the components inside the storage medium, and the communication with other hardware and software in the information processing physical device.

[0091] Through the description of the above implementation mode, the technicians in this field can clearly understand that the present application can be implemented by means of software plus the necessary general hardware platform, or by hardware. By applying the scheme of this embodiment, compared with the current prior art, 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, so as to dynamically adjust the retrieval method from a variety of retrieval methods according to the query request, improve the flexibility of the retrieval method, and then improve the accuracy and response speed of the query, improve the text retrieval efficiency, reduce the system delay, and then improve the user experience. In addition, this embodiment can use the 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 technology are integrated, and the reply text with higher correlation can be generated more effectively, making the generated text more accurate and rich.

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

[0093] The above is only a specific implementation of the present application, so that those skilled in the art can 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 can 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 will conform to the widest scope consistent with the principles and novel features applied for herein.

Claims

1. A text generation method, characterized in that: include: Obtaining semantic information of the query request; Determine, based on the semantic information, 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; Replying to the query request using the target generation mode to obtain reply information corresponding to the query request; A reply text corresponding to the query request is generated according to the reply information and the query request.

2. The method according to claim 1, characterized in that: The determining, based on the semantic information, a target generation mode corresponding to the query request includes: Determining a prompt word corresponding to the query request according to the semantic information; Obtaining a concatenated text of the prompt word and the query request; According to the concatenated text, a target generation mode corresponding to the prompt word is determined.

3. The method according to claim 2, characterized in that The determining, according to the semantic information, a prompt word corresponding to the query request includes: The prompt word corresponding to the semantic information is determined by using a preset retrieval model, and the preset retrieval model is used to determine the prompt word matching the semantic information according to a retrieval strategy.

4. The method according to claim 3, characterized in that 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; The training parameters of the preset retrieval model are updated based on the gradient corresponding to the loss function.

5. The method according to claim 4, 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; According to 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.

6. The method according to claim 2, characterized in that If the target generation mode is a direct generation mode, the step of using the target generation mode to reply to the query request and obtaining reply information corresponding to the query request includes: The query request is answered according to the prompt word using a base model to obtain answer information corresponding to the query request, wherein the base model is a basic model obtained through training with knowledge text data.

7. The method according to claim 2, characterized in that If the target generation mode is an indirect generation mode, the step of replying to the query request using the target generation mode to obtain reply information corresponding to the query request includes: 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.

8. The method according to claim 7, characterized in that The calling retrieval system searches 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 perform retrieval according to the query statement to obtain text fragments matching the query statement; The text segment, the query statement and the prompt word are concatenated to obtain the reply information.

9. The method according to claim 6, characterized in that The step of 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.

10. The method according to claim 3, characterized in that The method further comprises: Calling a preset evaluation model to evaluate the reply quality corresponding to the reply text, wherein the preset evaluation model is used to predict the reply quality corresponding to different retrieval strategies in the preset retrieval model; The preset retrieval model is updated according to the response quality.

11. The method according to claim 10, characterized in that 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.

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

13. 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 12 is implemented.

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

15. 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 12 is implemented.

Citation Information

Patent Citations

  • Retrieval and generation combined Zhuang language dialogue method and system

    CN118503381A

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

    CN119692478A

Cited By

  • Control method and device of reply model, storage medium and electronic equipment

    CN120851221A

  • Control method and device of reply model, storage medium and electronic equipment

    CN120851221B