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

Through the combination of multi-dimensional retrieval and text rewriting of pre-trained models, the problem of low retrieval accuracy and incoherent generated content in text generation of large language models is solved, and high-quality intelligent replies are achieved.

CN118396123BActive Publication Date: 2024-10-01INSPUR SUZHOU INTELLIGENT TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410833500.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-06-26
Publication Date
2024-10-01
Estimated Expiration
2044-06-26

AI Technical Summary

Technical Problem

Large language models have problems such as low retrieval accuracy, redundant information, and incoherent or unnatural generated language structures in text generation. Especially after the introduction of external knowledge into the RAG system, it is difficult to provide high-quality responses.

Method used

Obtain text blocks related to user request questions through multi-dimensional retrieval, and evenly distribute them to multiple pre-trained models for text rewriting. Combined with user historical question and answer records to generate text prompt information, an evaluation strategy is used to select the most matching reply.

Benefits of technology

Improved the quality and accuracy of text responses, ensuring that the generated content is semantically coherent, natural, and matches the user's request question.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118396123B_ABST
    Figure CN118396123B_ABST
Patent Text Reader

Abstract

The present application provides a text generation method, device, computer program product, electronic device and medium, the method comprising: obtaining N first text blocks associated with a user request question and meeting preset conditions, determined based on multiple dimensional retrieval; evenly distributing the N first text blocks to M pre-trained models for text rewriting, and obtaining N target text blocks; after determining the N text prompt information corresponding to the N target text blocks, processing the N text prompt information based on the M pre-trained models to obtain a candidate reply set, the text prompt information including the target text block, the user request question and the historical question and answer record; evaluating the candidate replies in the candidate reply set based on the evaluation strategy, and selecting the reply information matching the user request question. The present application can improve the retrieval accuracy, provide semantically coherent and natural text content, provide reply information matching the user request question, and ensure the quality of intelligent replies.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of artificial intelligence technology, and in particular to a text generation method, device, computer program product, electronic device and medium. Background Art

[0002] In recent years, large-scale basic models such as ChatGPT (Chat Generative Pre-trained Transformer) (e.g., LLM (Large Language Model)) have shown impressive performance in tasks such as text generation and text-to-image generation. However, large language models have inherent limitations, including a tendency to produce hallucinations and a lack of explainability of answers. In order to fully utilize the powerful summarization capabilities of large language models, enhancing the generation results of large language models by retrieving external relevant information is a common means of solving the above problems, that is, using RAG (Retrieval-Augmented Generation) technology to provide more reliable and fact-based information.

[0003] When providing information enhancement based on RAG technology to generate large language models, the following defects exist: 1. Low retrieval precision, that is, not all document blocks in the retrieval set are relevant to the query content, which may lead to incorrect or incoherent information. The second is low recall, that is, failure to retrieve all relevant document blocks makes it impossible for the large language model to obtain enough background information to synthesize answers. 2. When multiple retrieved text segments contain similar information, redundancy and repetition become problems, which may lead to duplication of generated content. Submitting all relevant documents to the large language model at once may exceed the context window limit. Connecting a large number of documents to form a lengthy retrieval prompt is ineffective, which will introduce noise and hinder the large language model from focusing on key information. 3. The retrieved content may have a different writing style or tone from the query content, causing the generated language structure to become less coherent or natural.

[0004] It can be seen that in the RAG system, although the introduction of external knowledge can enrich and concretize the generated text content, it also has defects such as low retrieval accuracy, information redundancy, and incoherent or unnatural generated language structure. Summary of the invention

[0005] In view of the above problems, embodiments of the present application provide a text generation method, device, computer program product, electronic device and medium that overcome the above problems or at least partially solve the above problems.

[0006] In a first aspect, an embodiment of the present application provides a text generation method, comprising:

[0007] Acquire N first text blocks that are associated with the user's request question and meet preset conditions, wherein the N first text blocks are determined based on retrieval of multiple dimensions;

[0008] Evenly distribute the N first text blocks to M pre-trained models for text rewriting to obtain N target text blocks, where M and N are both integers greater than or equal to 1;

[0009] After determining N text prompt information corresponding to the N target text blocks, the N text prompt information is processed based on the M pre-trained models to obtain a candidate reply set, where the text prompt information includes the target text block, the user request question, and the user's corresponding historical question and answer record;

[0010] The candidate replies in the candidate reply set are evaluated based on the evaluation strategy, and reply information matching the user request question is selected.

[0011] Optionally, the obtaining of N first text blocks associated with the user's request question and satisfying a preset condition includes:

[0012] Retrieving text information whose relevance to the user's question meets the semantic relevance requirement in multiple dimensions, and obtaining a candidate text block set including K second text blocks;

[0013] The candidate text block set is subjected to text block deduplication and sorting processing to obtain the N first text blocks.

[0014] Optionally, the retrieving text information whose relevance to the user's question meets the semantic relevance requirement in multiple dimensions to obtain a candidate text block set including K second text blocks includes:

[0015] Based on the user request question and the historical question and answer records corresponding to the user, a keyword list and a target request question rewritten from the user request question are obtained, wherein the keyword list and the target request question are obtained based on the corresponding model service;

[0016] Text information retrieval is performed in multiple dimensions according to the user request question, the target request question and the keyword list to obtain the K second text blocks.

[0017] Optionally, performing text information retrieval in multiple dimensions according to the user request question, the target request question and the keyword list to obtain the K second text blocks includes:

[0018] Inputting the user request question, the target request question and the keyword list into a target encoding model respectively to obtain a plurality of text vectors;

[0019] Retrieve text blocks whose semantic relevance with each text vector meets the semantic relevance requirement in the target database respectively, so as to determine the K second text blocks;

[0020] The target database stores vector indexes and corresponding text blocks.

[0021] Optionally, the method further comprises:

[0022] Constructing a fine-tuning dataset including a plurality of text data, wherein the text data includes question information and answer information, and the text data is data in a target domain;

[0023] Adjusting the initial coding model based on the fine-tuning data set to determine the target coding model;

[0024] According to the determined text block size, the input document is divided into blocks, wherein the input document is generated based on the information collected in the target field;

[0025] The multiple text blocks obtained by the block processing are input into the target coding model to determine the target database.

[0026] Optionally, the method further comprises:

[0027] Determining a block adjustment range based on a maximum number of words supported by the initial coding model;

[0028] According to the constructed multiple test data sets, the text block size is determined within the block adjustment range.

[0029] Optionally, performing text block deduplication and sorting processing on the candidate text block set to obtain the N first text blocks includes:

[0030] Traversing and calculating the similarity between any two second text blocks in the candidate text block set;

[0031] Determine a target text block group according to the similarity calculation result, wherein any two second text blocks constitute a text block group, and a text block group whose similarity of the two second text blocks is greater than a preset threshold is the target text block group;

[0032] Determine a second text block with a low relevance to the user request question in the target text block group, and delete the determined second text block to deduplicate the second text block;

[0033] After performing second text block deduplication on the target text block group, obtaining a target text block set;

[0034] Extracting feature information of a second text block in the target text block set, and performing score evaluation on the second text block based on the extracted feature information to obtain a first score corresponding to the second text block;

[0035] Based on the first score corresponding to the second text block, N first text blocks are determined in the target text block set.

[0036] Optionally, the determining N first text blocks in the target text block set based on the first score corresponding to the second text block includes:

[0037] Based on the first score corresponding to the second text block, the second text blocks in the target text block set are sorted to determine a sorting result, wherein the sorting order of the second text blocks is positively correlated with the relevance corresponding to the second text blocks;

[0038] Based on the ranking result, N second text blocks with higher first scores in the target text block set are determined, and the N second text blocks are determined as the N first text blocks.

[0039] Optionally, extracting feature information from a second text block in the target text block set, and performing score evaluation on the second text block based on the extracted feature information to obtain a first score corresponding to the second text block includes:

[0040] Extract feature information from the second text block to obtain at least one of a first semantic similarity between the second text block and the user's question, a second semantic similarity between the second text block and a preceding text of the user's question, and text quality;

[0041] A score evaluation is performed based on at least one of the first semantic similarity, the second semantic similarity, and the text quality to obtain a first score corresponding to the second text block.

[0042] Optionally, the evenly distributing the N first text blocks to M pre-trained models for text rewriting to obtain N target text blocks includes:

[0043] According to the principle of balanced distribution, the N first text blocks are divided into M parts, and a pre-trained model corresponding to each first text block is determined;

[0044] Based on the correspondence between the first text block and the pre-trained model, M copies of the first text block are concurrently input into the corresponding pre-trained model for text rewriting to obtain N target text blocks after text rewriting.

[0045] Optionally, the processing the N text prompt information based on the M pre-trained models to obtain a candidate reply set includes:

[0046] After generating N text prompt information based on the N target text blocks, the user request question and the user's corresponding historical question and answer records, based on the correspondence between the first text block and the pre-trained model, the N text prompt information is concurrently input into the corresponding pre-trained model to obtain the candidate response set;

[0047] Each text prompt message corresponds to at least one candidate reply.

[0048] Optionally, the evaluating the candidate replies in the candidate reply set based on the evaluation strategy and selecting reply information matching the user request question includes:

[0049] Evaluate at least one of response fidelity, response relevance, and context relevance on the candidate response to obtain at least one second score;

[0050] Determining a target score corresponding to the candidate response based on the at least one second score;

[0051] Based on the target score, reply information matching the user request question is selected from the candidate replies corresponding to the candidate reply set.

[0052] Optionally, when evaluating at least one of reply fidelity, reply relevance and context relevance of the candidate reply, the candidate reply is processed based on a pre-trained model corresponding to the candidate reply;

[0053] Among them, the pre-trained model corresponding to the candidate reply is determined based on the corresponding relationship between the first text block and the pre-trained model.

[0054] In a second aspect, an embodiment of the present application provides a text generation device, comprising:

[0055] An acquisition module, used to acquire N first text blocks associated with the user's request question and satisfying a preset condition, wherein the N first text blocks are determined based on a search in multiple dimensions;

[0056] An allocation and acquisition module, used to evenly allocate the N first text blocks to M pre-trained models for text rewriting, and obtain N target text blocks, where M and N are both integers greater than or equal to 1;

[0057] A processing and obtaining module, configured to, after determining N text prompt information corresponding to the N target text blocks, process the N text prompt information based on the M pre-trained models to obtain a candidate reply set, wherein the text prompt information includes the target text block, the user request question, and the user's corresponding historical question and answer record;

[0058] The evaluation and selection module is used to evaluate the candidate replies in the candidate reply set based on the evaluation strategy, and select reply information matching the user request question.

[0059] In a third aspect, an embodiment of the present application provides a computer program product, including a computer program / instruction, which, when executed by a processor, implements the text generation method described in the first aspect.

[0060] In a fourth aspect, an embodiment of the present application provides an electronic device, comprising a processor, a memory, and a computer program stored in the memory and capable of running on the processor, wherein the computer program, when executed by the processor, implements the text generation method described in the first aspect.

[0061] In a fifth aspect, an embodiment of the present application provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the text generation method described in the first aspect is implemented.

[0062] The technical solution provided by the embodiments of the present application brings at least the following beneficial effects:

[0063] Based on multi-dimensional retrieval, N first text blocks related to the user's request question are obtained, so as to achieve relatively comprehensive collection of content related to the user's request question and improve retrieval accuracy; after determining the N first text blocks, the N first text blocks are evenly distributed to M pre-trained models for text rewriting to obtain N target text blocks, and the pre-trained model can be used to output text content that is adapted to the style of the pre-trained model, semantically coherent and natural, so as to improve the quality of text replies in the future; after determining the text prompt information, based on the correspondence between the pre-trained model and the first text block, the N text prompt information is distributed to the M pre-trained models for processing to obtain a candidate reply set, and an evaluation strategy is used to evaluate each candidate reply in the candidate reply set. The adapted pre-trained model can be used to output the candidate reply, and the candidate reply is evaluated to select the candidate reply that best suits the user's request question, so as to provide reply information that matches the user's request question, thereby improving the reply accuracy and ensuring the quality of the intelligent reply. BRIEF DESCRIPTION OF THE DRAWINGS

[0064] Figure 1 A schematic diagram of a text generation method provided in an embodiment of the present application;

[0065] Figure 2 A schematic diagram of determining three requests to be retrieved provided in an embodiment of the present application;

[0066] Figure 3 A flowchart of building a legally relevant target database provided in an embodiment of the present application;

[0067] Figure 4 A flowchart of determining N first text blocks based on three requests to be searched provided in an embodiment of the present application;

[0068] Figure 5 A flowchart of rewriting text and determining a candidate reply set provided in an embodiment of the present application;

[0069] Figure 6 A schematic diagram of the overall implementation process of the text generation method provided in the embodiment of the present application;

[0070] Figure 7 A schematic diagram of a text generation device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0071] To make the purpose, technical scheme and advantages of the embodiments of the present application clearer, each embodiment of the present application will be described in detail below in conjunction with the accompanying drawings. However, it will be appreciated by those skilled in the art that in each embodiment of the present application, many technical details are proposed in order to enable the reader to better understand the present application. However, even without these technical details and various changes and modifications based on the following embodiments, the technical scheme claimed in the present application can also be implemented. The division of the following embodiments is for the convenience of description, and the specific implementation of the present application should not constitute any limitation, and the various embodiments can be combined with each other and referenced to each other without contradiction.

[0072] At present, when using a large language model for intelligent reply, the introduction of RAG technology can provide more reliable and fact-based information, but at the same time there are defects such as low retrieval accuracy, information redundancy, and incoherent or unnatural generated language structure. In order to reduce the problems caused by the introduction of RAG technology, the embodiment of the present application provides a text generation method to provide strong support for intelligent reply in fields such as law, medical care, and tourism that require questions and answers.

[0073] like Figure 1 As shown, the text generation method provided in the embodiment of the present application includes:

[0074] Step 101: Obtain N first text blocks that are associated with a user's request question and meet preset conditions, wherein the N first text blocks are determined based on retrieval of multiple dimensions.

[0075] The text generation method provided in the embodiment of the present application is applied to a server. In an intelligent question-answering scenario, a user asks a question on a client, and the server receives the user's request question sent by the client. Based on the user's request question, a search is performed in multiple dimensions to determine the text content associated with the user's request question, and the retrieved text content is processed to determine N first text blocks. The value of N is greater than or equal to 1, so that at least one first text block associated with the user's request question is determined by multi-dimensional retrieval and processing of the retrieval results. And by retrieving content related to the user's request question in multiple dimensions, the content related to the user's request question can be relatively comprehensively collected, thereby improving the retrieval accuracy.

[0076] Among them, the client is an application that supports intelligent question-answering, and the user request question obtained by the server can be a question related to a specific field, such as a question related to the legal, medical or tourism field. As an embodiment of the present application, in an intelligent question-answering scenario, the user asks a legal question on the client, and the client sends the user request question to the server. The server searches for relevant content in multiple dimensions based on the received user request question and determines one or more first text blocks.

[0077] Step 102: Evenly distribute the N first text blocks to the M pre-trained models for text rewriting to obtain N target text blocks.

[0078] After obtaining N first text blocks related to the user's request question, the server evenly distributes the N first text blocks to the M pre-trained models deployed on the server, so as to rewrite the first text blocks through the pre-trained models. By rewriting the first text blocks through the pre-trained models, text content that is adapted to the style of the pre-trained models, semantically coherent and natural can be output, thereby obtaining N target text blocks that have been rewritten in the text style.

[0079] The value of N is greater than or equal to 1, and correspondingly, the value of M is greater than or equal to 1. When the values ​​of N and M are the same, the first text block can be directly assigned to the pre-trained model in a one-to-one correspondence; when the value of N is greater than M, the N first text blocks are relatively evenly assigned to the M pre-trained models; when the value of N is less than M, the N first text blocks are evenly assigned to some of the M pre-trained models. As an embodiment of the present application, the server deploys pre-trained model A, pre-trained model B, pre-trained model C, and pre-trained model D on different GPUs (Graphics Processing Units), and evenly assigns the 8 first text blocks to the above 4 pre-trained models.

[0080] By inputting the first text block into a pre-trained model for text rewriting, text content with an adapted style can be output based on the pre-trained model to transform the first text block and provide semantically coherent and natural text content to improve the semantic coherence of the reply information generated in response to the user's request question.

[0081] Step 103: After determining the N text prompt information corresponding to the N target text blocks, the N text prompt information is processed based on M pre-trained models to obtain a candidate reply set, where the text prompt information includes the target text block, the user request question, and the user's corresponding historical question and answer record.

[0082] After rewriting the first text block based on the text style of the pre-trained model to obtain N target text blocks, corresponding text prompt information is generated for each target text block, and the text prompt information corresponding to the target text block includes the target text block, the user's request question, and the user's corresponding historical question and answer record. Then, based on the correspondence between the target text block and the pre-trained model, the N text prompt information is assigned to M pre-trained models, and the M pre-trained models process the N text prompt information to determine a set of candidate responses.

[0083] The text prompt information can be generated based on a combination of a target text block, a user request question, and a historical question and answer record corresponding to the user. The N text prompt information is provided to the corresponding pre-trained model according to the previous allocation strategy, so that the pre-trained model processes the text prompt information and outputs candidate replies adapted to the text prompt information, and a candidate reply set is generated based on the candidate replies provided by the M pre-trained models.

[0084] Step 104: Evaluate the candidate responses in the candidate response set based on the evaluation strategy, and select response information that matches the user's request question.

[0085] After obtaining a set of candidate replies based on the pre-trained model, an evaluation strategy is used to evaluate each candidate reply in the set of candidate replies, so as to select the candidate reply that best matches the user's request question through the evaluation of the candidate replies, and use the selected candidate reply as the reply information that matches the user's request question.

[0086] When using an evaluation strategy to evaluate each candidate response in a candidate response set, the candidate response can be evaluated based on one or more evaluation indicators. In the case of using multiple evaluation indicators for evaluation, a weight corresponding to each evaluation indicator is set, and then the final evaluation result is determined based on the weight and the score corresponding to the evaluation indicator.

[0087] The above implementation scheme of the present application obtains N first text blocks related to the user's request question based on multi-dimensional retrieval, realizes relatively comprehensive collection of content related to the user's request question, and improves retrieval accuracy; after determining the N first text blocks, the N first text blocks are evenly distributed to M pre-trained models for text rewriting to obtain N target text blocks, and the pre-trained model can be used to output text content that is adapted to the style of the pre-trained model, semantically coherent and natural, so as to improve the quality of text replies in the future; after determining the text prompt information, based on the correspondence between the pre-trained model and the first text block, the N text prompt information is distributed to the M pre-trained models for processing to obtain a set of candidate replies, and an evaluation strategy is used to evaluate each candidate reply in the candidate reply set. The adapted pre-trained model can be used to output the candidate replies, and the candidate replies are evaluated to select the candidate reply that best suits the user's request question, so as to provide reply information that matches the user's request question, thereby improving the reply accuracy and ensuring the quality of the intelligent reply.

[0088] The specific process of obtaining N first text blocks related to the user's request question based on multiple dimensional retrieval is introduced below. As an optional embodiment of the present application, when obtaining N first text blocks associated with the user's request question and meeting the preset conditions, it includes:

[0089] Retrieving text information whose relevance to the user's request question meets the semantic relevance requirement in multiple dimensions, and obtaining a candidate text block set including K second text blocks;

[0090] The candidate text block set is subjected to text block deduplication and sorting processing to obtain N first text blocks.

[0091] After obtaining the user's request question, text information whose relevance to the user's request question meets the semantic relevance requirements is retrieved in multiple dimensions. The retrieved text information may be text information whose relevance to the user's request question is greater than a preset first threshold, or the retrieved text information may be a preset number of text information ranked high in relevance to the user's request question, wherein the higher the ranking, the higher the relevance. When searching, the search is performed in a pre-generated database storing text information.

[0092] After obtaining a candidate text block set including K second text blocks related to the user's request question through multi-dimensional retrieval, the second text blocks in the candidate text block set are deduplicated, so as to simplify the content in the candidate text block set through text block filtering, avoid obtaining redundant information, and retain necessary text content. After filtering the second text blocks in the candidate text block set through deduplication, the remaining second text blocks in the candidate text block set are sorted, and the second text blocks in the candidate text block set that meet the set conditions are determined through sorting, thereby obtaining N first text blocks related to the user's request question.

[0093] In the above implementation process, a candidate text block set is obtained through multi-dimensional retrieval, so that relatively comprehensive text information related to the user's request question can be obtained; after the candidate text block set is determined through retrieval, the content in the candidate text block set is deduplicated and sorted, which can streamline the content and avoid information redundancy while providing text blocks with a high degree of relevance to the user's request question.

[0094] Optionally, when retrieving text information whose relevance to the user's request question meets the semantic relevance requirement in multiple dimensions and obtaining a candidate text block set including K second text blocks, it includes:

[0095] Based on the user's request question and the user's corresponding historical question and answer records, obtain a keyword list and a target request question that is rewritten from the user's request question. The keyword list and the target request question are obtained based on the corresponding model service.

[0096] According to the user request question, the target request question and the keyword list, text information retrieval is performed in multiple dimensions to obtain K second text blocks.

[0097] In the intelligent question-answering scenario, when users have multiple rounds of conversations with the pre-trained model, the user's request question may be incomplete. Since the pre-trained model has shown excellent request rewriting capabilities in conversational dense retrieval, the current user's request question can be rewritten to provide a request that is complete and meets the requirements. Rewriting the user's request question can be understood as expanding the user's request question, so that the initial question becomes complete and clear through content expansion.

[0098] The request rewriting capability of the pre-trained model is implemented based on the request rewriting model service supported by the pre-trained model. While supporting the request rewriting model service, the pre-trained model also supports the keyword extraction model service, and the two model services support concurrent calls. Therefore, the user request question can be rewritten and keyword information can be obtained by calling the corresponding model service.

[0099] That is, when searching in multiple dimensions, the historical question and answer records corresponding to the current user are obtained based on the user's request question. The historical question and answer records are the historical conversations of the user based on the pre-trained model deployed on the client and server in the intelligent question and answer scenario. Then, two model services are called, and the user's request question and the user's corresponding historical question and answer records are used as input. The request is rewritten and the keyword is extracted based on the two model services to obtain the target request question and keyword list after the user's request question is rewritten. In order to improve efficiency, the two model services can be called in a multi-process concurrent manner to perform request rewriting and keyword extraction operations at the same time.

[0100] Optionally, the request rewriting model service and the keyword extraction model service can also be merged into one model service. In this case, two functions are implemented through one model service; still optionally, the request rewriting capability can be implemented based on the cooperation of at least two model services, and the keyword extraction capability can be implemented based on the cooperation of at least two model services. I will not elaborate on this here.

[0101] It should be noted that the model service can be a service supported by any pre-trained model deployed by the server, or a service supported by a specific pre-trained model. The server can obtain a keyword list and rewrite the user request question by calling the model service, or it can use other means to extract keywords and obtain the rewritten request.

[0102] The following is an introduction to the process of rewriting requests and extracting keywords through an embodiment of the present application. For example, the following template is used to form the input text, and the corresponding model service performs request rewriting: As a legal question-and-answer assistant, its job is to understand the user's true intentions. Please complete the user's current request question based on the above scenario. Among them, the above scenario is: {conversation record}, ​​and the user's current request question is: {current question}. Based on the above content, rewrite the user's request question to make its meaning clear. Finally, please output a rewritten different request question without any other explanation or intermediate process.

[0103] For another example, the following template is used to form the input text, and the corresponding model service extracts keywords: As a legal question-and-answer assistant, its job is to understand the user's true intention. Please extract keywords based on the context. The context is: {conversation record}, ​​{current question}. Please output the three most important keywords without any other explanation or intermediate process.

[0104] After obtaining the keyword list and rewriting the user request question to determine the target request question, in order to ensure the retrieval accuracy, the user request question is retained as the request to be retrieved 1 (represented by Q1), the target request question is used as the request to be retrieved 2 (represented by Q2), and the keyword list is used as the request to be retrieved 3 (represented by Q3). According to Q1, Q2, and Q3, text information is retrieved in multiple dimensions to obtain K second text blocks, so as to adapt to different query types and information needs based on the hybrid retrieval strategy, and ensure consistent retrieval of highly relevant and context-rich information.

[0105] As an embodiment of the present application, the process of determining the request to be retrieved 1, the request to be retrieved 2, and the request to be retrieved 3 based on the user's request question and the user's corresponding historical question and answer records can be seen in Figure 2 . The user request question and the historical question and answer records corresponding to the user are input into model service 1, and the target request question after rewriting the user request question output by model service 1 is obtained; the user request question and the historical question and answer records corresponding to the user are input into model service 2, and the keyword list output by model service 2 is obtained. The user request question is taken as request 1 to be retrieved, the target request question is taken as request 2 to be retrieved, and the keyword list is taken as request 3 to be retrieved, so as to determine three requests to be retrieved based on the user request question and the historical question and answer records corresponding to the user.

[0106] In the above implementation process, by rewriting the user request question and extracting keywords based on the conversation record and the current user request question, a complete and clear rewritten target request question can be obtained and key information points can be extracted. Moreover, by using a multi-process concurrent method to call two model services to perform request rewriting and keyword extraction operations at the same time, processing efficiency can be improved. Text information retrieval is performed in multiple dimensions based on the user request question, target request question and extracted keywords, and hybrid retrieval can be used to adapt to different query types and information needs.

[0107] Optionally, performing text information retrieval in multiple dimensions according to the user request question, the target request question and the keyword list to obtain K second text blocks includes:

[0108] Input the user request question, the target request question and the keyword list into the target encoding model respectively to obtain multiple text vectors;

[0109] The target database is respectively searched for text blocks whose semantic relevance with each text vector meets the semantic relevance requirement to determine K second text blocks, and the target database stores the vector index and the corresponding text block.

[0110] After determining the target request question and keyword list, the user request question, the target request question and the keyword list are respectively input into the target encoding model to obtain multiple text vectors, such as obtaining the corresponding first text vector E1 based on the user request question, obtaining the corresponding second text vector E2 based on the target request question, and obtaining the corresponding third text vector E3 based on the keyword list. Then, in a target database for storing vector indexes and corresponding text blocks, text blocks semantically related to the first text vector E1, text blocks semantically related to the second text vector E2, and text blocks semantically related to the third text vector E3 are retrieved, and a candidate text block set including K second text blocks is determined based on the retrieved text blocks.

[0111] Optionally, the text vectors obtained based on the target encoding model can also be other numbers, such as obtaining 4 text vectors, and the keyword list corresponds to two text vectors; or obtaining 2 text vectors, and the user request question and the target request question correspond to the same text vector; other numbers of text vectors can also be obtained, which are not listed here.

[0112] The text blocks semantically related to the text vector retrieved in the target database may be text blocks whose correlation with the text vector is greater than a threshold, or may be a specific number of text blocks ranked at the top in terms of correlation with the text vector. In this case, the closer the text block is to the front, the higher its correlation with the text vector.

[0113] The target encoding model is a model determined by adjustment based on the initial encoding model, and the size of the text block in the target database is the optimal block size determined by testing. When determining the text block size, it includes: determining the block adjustment range based on the maximum number of words supported by the initial encoding model; and determining the text block size within the block adjustment range based on the multiple test data sets constructed.

[0114] When building a RAG system, block size is a key parameter. Generally speaking, it is desirable to retain some overlap between blocks to ensure that semantic context is not lost between blocks. In most cases, fixed-size chunking is the best path. Compared with other forms of chunking, fixed-size chunking is computationally inexpensive and easy to use because it does not require the use of any NLP (Natural Language Processing) library. The embodiment of the present application uses a small-to-large manner to adjust blocks. After selecting the initial coding model, the block adjustment range is determined based on the maximum number of words supported by the initial coding model, and then the block size test is performed in the block adjustment range in an ascending order based on the multiple test data sets constructed to determine the optimal block size.

[0115] As an embodiment of the present application, bge-base-zh-v1.5 is used as the initial encoding model, which supports a maximum of 512 words (tokens). Therefore, the block adjustment range is designed to be [128, 256, 384, 512], and 100 test sets are constructed, for example. Based on the constructed 100 test data sets, block size tests are performed in order from small to large, and the optimal block size is determined through testing.

[0116] The embodiments of the present application may also adopt other methods, such as reinforcement learning, to determine the optimal block size. After determining the block adjustment range, multiple corresponding codes are determined based on the multiple block sizes corresponding to the block adjustment range, and each code corresponds to a block size. The core of searching for the optimal block size based on reinforcement learning is: using a policy network to obtain the code of the text block size, calculating the accuracy of text retrieval based on the block size, and using the accuracy as a reward for updating the reinforcement learning policy network. That is, when performing text retrieval based on the block size in the block adjustment range, determine the accuracy, update the policy network based on the determined accuracy, so as to continuously optimize the policy network, and determine the optimal block size when the policy network optimization is completed.

[0117] Wherein, in the case of determining the size of the text block, the method further comprises:

[0118] Constructing a fine-tuning dataset including multiple text data, where the text data includes question information and answer information, and the text data is data in the target domain;

[0119] Adjust the initial encoding model based on the fine-tuning data set and determine the target encoding model;

[0120] According to the determined text block size, the input document to be processed is divided into blocks, and the input document to be generated based on the information collected in the target field;

[0121] The multiple text blocks obtained by the block processing are input into the target coding model to determine the target database.

[0122] In this embodiment, in order to improve the retrieval quality and ensure that the acquired content is highly relevant to the query content, the initial encoding model is fine-tuned, the target encoding model is determined, and after the target encoding model is determined, based on the target encoding model and the input documents corresponding to the target field, a target database for storing vector indexes and corresponding text blocks is constructed to store the continuously developing or rare terms in the target field in the target database, thereby ensuring the comprehensiveness of the data stored in the target database and improving the retrieval quality.

[0123] Before fine-tuning the initial encoding model, a fine-tuning dataset including multiple text data is constructed, each of which is data corresponding to the target field including question information and reply information, and the text data can be generated based on the pre-trained model, and the size of the text data is not specifically limited. Then, the model parameters of the initial encoding model are adjusted based on the fine-tuning dataset to determine the target encoding model. For example, a fine-tuning dataset including 10,000 text data is constructed, and the bge-base-zh-v1.5 model is fine-tuned based on the constructed fine-tuning dataset to determine the target encoding model, which is used to output a text vector based on the input text content.

[0124] After determining the target coding model by fine-tuning the initial coding model, the input document is divided into blocks according to the determined text block size to obtain multiple text blocks, and the multiple text blocks are input into the target coding model to determine the text vectors corresponding to the multiple text blocks, set the vector index corresponding to the text vector, and build the target database based on the correspondence between the vector index and the text block. The input document is generated based on the collected information of the target field, and the collected information can include information in text form, audio form and / or video form, and the audio and video form information needs to be converted into text form to form the input document.

[0125] The above implementation process selects the optimal block size, builds a target database based on the optimal block size, and searches the target database based on the text vectors corresponding to the user request question, the target request question, and the keyword list. It can provide text blocks that are respectively adapted to multiple dimensions, and then generate a candidate text block set including K second text blocks.

[0126] As an optional embodiment of the present application, the target field is the legal field, the constructed target database is a target database related to law, and the legal questions raised by users are answered based on the constructed database. Figure 3 As shown in the figure, it is the implementation process of constructing a target database related to law. Collect legal books, official website related links, relevant regulations and other legal documents, and the legal documents are the documents to be input. Based on the determined text block size (optimal text block size), the input document is divided into blocks, multiple text blocks are obtained, and multiple text blocks are input into the target encoding model. The text vector is obtained and the vector index is set. The target database related to law is constructed based on the vector index and the corresponding text block. Among them, the constructed target database related to law can include various legal knowledge to ensure the comprehensiveness of the information covered by the target database.

[0127] After constructing a target database related to law, suitable text content can be retrieved from the database for law-related questions raised by users, so as to provide a basis for answering the users' questions based on the constructed target database.

[0128] The following describes the process of determining N first text blocks from a candidate text block set. Optionally, after generating a candidate text block set including K text blocks, performing text block deduplication and sorting processing on the candidate text block set to obtain N first text blocks, including:

[0129] Traversing and calculating the similarity between each second text block in the candidate text block set;

[0130] Determine the target text block group according to the similarity calculation result, wherein any two second text blocks constitute a text block group, and the text block group whose similarity of the two second text blocks is greater than a preset threshold is the target text block group;

[0131] Determine a second text block with a low relevance to the user's request question in the target text block group, and delete the determined second text block to deduplicate the second text block;

[0132] After performing second text block deduplication on the target text block group, obtaining a target text block set;

[0133] Extracting feature information of a second text block in the target text block set, and performing score evaluation on the second text block based on the extracted feature information to obtain a first score corresponding to the second text block;

[0134] Based on the first scores corresponding to the second text blocks, N first text blocks are determined in the target text block set.

[0135] When deduplicating text blocks for a candidate text block set, the similarity between two second text blocks is calculated based on a strategy of combining the second text block with other second text blocks that are different from the current second text block in pairs. The two combined second text blocks constitute a text block group, and the combination of the second text block A and the second text block B, and the combination of the second text block B and the second text block A belong to the same text block group. For example, if the candidate text block set includes the second text block A, the second text block B, and the second text block C, then the following text block groups can be obtained based on the pairwise combination: a text block group including the second text block A and the second text block B, a text block group including the second text block A and the second text block C, and a text block group including the second text block B and the second text block C.

[0136] In the constructed text block group, according to the similarity calculation result, a target text block group in which the similarity of the two second text blocks is greater than a preset threshold is determined, and then for the target text block group, a second text block with a low correlation with the user request question is determined in the target text block group, and the second text block is deleted to perform text block deduplication for the target text block group. After deduplication of text blocks is performed for the target text block group, a target text block set is determined based on the target text block group that has completed deduplication and other text block groups, wherein the target text block set does not include repeated second text blocks, and if a second text block is retained multiple times, the target text block set only includes one such second text block.

[0137] After determining the target text block set based on deduplication, feature information is extracted for each second text block in the target text block set, and then the second text block is scored based on the extracted feature information to obtain a first score corresponding to the second text block.

[0138] Among them, when feature information is extracted from the second text block and the first score is obtained based on the extracted feature information, a first semantic similarity between the second text block and the user's request question, a second semantic similarity between the second text block and the previous text of the user's request question, and at least one of the text quality are obtained; a score evaluation is performed based on the first semantic similarity, the second semantic similarity, and at least one of the text quality to obtain the first score corresponding to the second text block.

[0139] In this embodiment, the feature information obtained by extracting feature information from the second text block includes at least one of the first semantic similarity, the second semantic similarity, and the text quality. The first similarity is used to measure the relevance of the second text block to the user's request question, and the second similarity is used to measure the relevance of the second text block to the historical question and answer record. The text quality can be evaluated based on evaluation indicators such as PPL (perplexity) and Distinct, where perplexity is used to measure whether a sentence is fluent, and the Distinct evaluation indicator is used to judge the diversity of replies. The definition of perplexity is as follows:

[0140] ,in, Indicates that the first The probability of a word, Represents sentence length. The smaller the PPL value, the more natural the text and the smoother the sentences. Evaluating text by PPL can avoid text out of order or inversion.

[0141] The Distinct evaluation index is specifically used to determine whether there is a large amount of common and repetitive content. The definition of Distinct is as follows:

[0142]

[0143] Among them, in the above formula, Indicates that the text is not repeated quantity, Indicates that the text The total number of words, The larger the value, the higher the diversity.

[0144] After obtaining at least one of the first semantic similarity, the second semantic similarity, and the text quality corresponding to the second text block based on the feature information extraction, a score evaluation is performed based on at least one of the first semantic similarity, the second semantic similarity, and the text quality to obtain a first score corresponding to the second text block. If the score evaluation is performed based on at least two of the above feature information, it is necessary to set parameters corresponding to each feature information to determine the first score based on the parameters and the feature information.

[0145] As an embodiment of the present application, the first semantic similarity of the second text block is obtained based on feature information extraction. , the second semantic similarity and text quality , and then determine the corresponding first score based on the scoring formula: , , , is the hyper-parameter coefficient, which is set according to the experimental results.

[0146] After obtaining the first scores corresponding to the second text blocks in the target text block set, when determining N first text blocks in the target text block set based on the first scores corresponding to the second text blocks, the method includes: sorting the second text blocks in the target text block set based on the first scores corresponding to the second text blocks, and determining a sorting result, wherein the arrangement order of the second text blocks is positively correlated with the correlation degrees corresponding to the second text blocks; and determining N second text blocks with top first scores in the target text block set based on the sorting result, and determining the N second text blocks as the N first text blocks.

[0147] After obtaining the first score corresponding to each second text block, the second text blocks in the target text block set are sorted based on the first score. At this time, the second text blocks are sorted in descending order according to the first score to obtain the sorting result. The higher the first score, the higher the relevance of the second text block to the user's request question and / or historical question and answer record, and / or the higher the text quality, that is, the higher the corresponding second text block with a higher relevance is, the closer it is to the front, and the higher the text quality is, the closer it is to the front. After the sorting is completed, determine the N second text blocks with the highest first scores in the target text block set to obtain N first text blocks, and filter out text blocks with high relevance to the user's request question and / or historical question and answer record and high text quality.

[0148] In the above implementation process, after determining the set of candidate text blocks, the candidate text block set is deduplicated to remove redundant information and achieve content streamlining; after deduplication is completed, score evaluation is performed through feature information extraction, and text blocks are filtered based on the scores, which can provide high-quality text blocks and optimize the query-related content while deduplicating.

[0149] As an embodiment of the present application, the process of determining the first text block N based on three requests to be searched is introduced below through a flowchart. Figure 4 As shown, the user request question is taken as the request to be searched 1, the target request question is taken as the request to be searched 2, and the keyword list is taken as the request to be searched 3. The request to be searched 1, the request to be searched 2, and the request to be searched 3 are input into the target coding model respectively to obtain the first text vector, the second text vector, and the third text vector. Based on the first text vector, the second text vector, and the third text vector, a search is performed in the target database to obtain q text blocks associated with the first text vector, q text blocks associated with the second text vector, and q text blocks associated with the third text vector to determine K second text blocks, wherein the q text blocks associated with the text vector are the screened text blocks with a higher degree of association.

[0150] Then, the candidate text block set including K second text blocks is deduplicated. After deduplication is completed, feature information is extracted from the remaining second text blocks, the first scores are calculated, and the second text blocks are sorted according to the first scores. Finally, N first text blocks are provided.

[0151] Figure 4 In the process shown, through a series of processes including retrieval, deduplication, scoring, and sorting, text blocks with high relevance are screened out, thereby providing high-quality text blocks and ensuring retrieval results.

[0152] The following is an introduction to an implementation scheme for determining the reply information matching the user's request question based on the first text block of N. The implementation scheme includes the process of obtaining a target text block, obtaining a candidate reply set, and screening matching candidate replies from the candidate reply set.

[0153] In the process of obtaining the target text block, when N first text blocks are evenly distributed to M pre-trained models for text rewriting, and N target text blocks are obtained, the process includes:

[0154] According to the principle of balanced distribution, the N first text blocks are divided into M parts, and the pre-trained model corresponding to each first text block is determined; based on the correspondence between the first text blocks and the pre-trained models, the M first text blocks are concurrently input into the corresponding pre-trained models for text rewriting to obtain N target text blocks after text rewriting.

[0155] In the embodiment of the present application, M pre-trained models are deployed on the server, and when the value of M is greater than 1, the M pre-trained models support concurrent calls. After determining the N first text blocks, based on the principle of balanced distribution, the N first text blocks are divided into M parts, the pre-trained model corresponding to each first text block is determined, and the corresponding relationship between the M first text blocks and the M pre-trained models is established.

[0156] As an embodiment of the present application, the value of N is 10, the value of M is 4, then the 10 first text blocks are divided into 4 parts, and the number of text blocks corresponding to the 4 parts of the first text blocks are 2, 2, 3, and 3, respectively, so as to perform relatively balanced text block division. Alternatively, the value of N is 15, the value of M is 3, then the 15 first text blocks are evenly divided into 3 parts, and the number of text blocks corresponding to each first text block is 5.

[0157] Among them, the pre-trained model corresponding to each first text block can be determined randomly or according to a preset strategy. For example, if the N first text blocks are divided in order of relevance from high to low, the obtained M first text blocks are arranged in order of priority from high to low, and the relevance is positively correlated with the priority, that is, the higher the corresponding relevance, the higher the priority. For the M pre-trained models, determine their corresponding priority order, and the priority of the pre-trained model is determined based on parameters such as the frequency of use and the degree of audience of the pre-trained model. According to the allocation strategy of the high-priority first text block corresponding to the high-priority pre-trained model, a corresponding relationship between the M first text blocks and the M pre-trained models is established, or, based on the allocation strategy of the high-priority first text block corresponding to the low-priority pre-trained model, a corresponding relationship between the M first text blocks and the M pre-trained models is established.

[0158] After establishing the correspondence between the first text block and the pre-trained model, M copies of the first text block are concurrently input into the corresponding pre-trained model, and the first text block is rewritten based on the text style of the pre-trained model to obtain N target text blocks, so as to efficiently obtain the required information based on a multi-threaded concurrent manner. And by rewriting the text style of the first text block, the problem of incoherent or unnatural responses generated for user request questions can be reduced or avoided.

[0159] Regarding the process of obtaining a candidate reply set, when N text prompt information is processed based on M pre-trained models to obtain a candidate reply set, it includes:

[0160] After generating N text prompt information based on N target text blocks, user request questions and the user's corresponding historical question and answer records, based on the correspondence between the first text block and the pre-trained model, the N text prompt information are concurrently input into the corresponding pre-trained model to obtain a set of candidate replies; each text prompt information corresponds to at least one candidate reply.

[0161] After rewriting the first text block using the pre-trained model to obtain N target text blocks, for each target text block, corresponding text prompt information is generated based on the combination of the current target text block, the user's request question, and the user's corresponding historical question and answer record, so as to obtain N text prompt information corresponding to the N target text blocks. Then, using the correspondence between the first text block and the pre-trained model, the N text prompt information is concurrently input into the corresponding pre-trained model, and the text prompt information is processed by the pre-trained model to obtain candidate replies determined based on the text prompt information, and then a candidate reply set is determined based on the aggregation of the candidate replies.

[0162] By concurrently inputting N text prompt information into M pre-trained models, the M pre-trained models can process the text prompt information concurrently, and efficiently output candidate replies based on multi-threaded concurrency; for any text prompt information, after it is input into the corresponding pre-trained model, the pre-trained model outputs at least one candidate reply, and the candidate replies corresponding to the N text prompt information are aggregated to determine a candidate reply set including at least N candidate replies.

[0163] The following describes the process of rewriting the first text block and determining the candidate reply set based on the rewritten target text block through an embodiment of the present application. Figure 5 As shown, N first text blocks are relatively evenly distributed to four pre-trained models (pre-trained model A, pre-trained model B, pre-trained model C, and pre-trained model D). The four pre-trained models concurrently perform text rewriting on the first text blocks and output N target text blocks, so as to efficiently provide target text blocks in a multi-threaded concurrent manner.

[0164] After obtaining N target text blocks, for each target text block, text prompt information is generated based on the target text block, the user request question and the user's corresponding historical question and answer records, and the N text prompt information is input into the corresponding pre-trained model. Four pre-trained models concurrently process and output candidate replies corresponding to the text prompt information, so as to efficiently determine the candidate reply set based on concurrent processing.

[0165] Figure 5 In the process shown, a set of candidate replies is determined through a series of processes including text rewriting, text prompt information generation, and output of candidate replies. This can provide a basis for screening replies that are suitable for the user's request question, and concurrent processing improves efficiency.

[0166] The process of screening matching candidate responses from the candidate response set includes evaluating the candidate responses in the candidate response set based on the evaluation strategy and selecting response information matching the user request question, including:

[0167] Evaluate at least one of reply fidelity, reply relevance, and context relevance on candidate replies to obtain at least one second score; determine a target score corresponding to the candidate reply based on the at least one second score; and select reply information that matches the user request question from the candidate replies corresponding to the candidate reply set based on the target score.

[0168] When screening candidate replies from a candidate reply set as reply information matching a user request question, each candidate reply in the candidate reply set is evaluated based on at least one of reply fidelity, reply relevance, and context relevance to determine at least one second score corresponding to the candidate reply.

[0169] When evaluating candidate replies based on reply fidelity, the candidate replies are semantically decomposed using the pre-trained model corresponding to the candidate replies to obtain multiple reference replies, and each reference reply is checked for consistency with the context to determine whether the reference reply is a reply that can support the user's request. The second score corresponding to the reply fidelity is determined based on the ratio of the number of reference replies that can support the user's request to the total number of reference replies.

[0170] When evaluating candidate replies based on reply relevance, we use the pre-trained model corresponding to the candidate replies to create possible questions that match the candidate replies, and analyze the similarity between these questions and the user's requested questions. The score corresponding to the reply relevance is obtained by calculating the average similarity between all generated questions and the user's requested questions. The specific calculation formula is:

[0171]

[0172] For a given candidate response , prompting the pre-trained model to generate Potential Problems , for each , calculation and user request problem (original problem) Similarity , the final result is determined based on the mean of the sum of n similarities, which is used as the second score corresponding to the response relevance.

[0173] When evaluating candidate responses based on contextual relevance, the pre-trained model corresponding to the candidate responses is used to filter out sentences directly related to the user's request question in the user's corresponding historical question and answer records, and the second score corresponding to the contextual relevance is determined by the proportion of these sentences to the total number of context sentences. The specific calculation formula is:

[0174]

[0175] By screening the sentences directly related to the user's request question in the historical question and answer records corresponding to the user, and determining the second score based on the ratio of the screened sentences to the total number of sentences, the context relevance is measured.

[0176] Among them, since the pre-trained model corresponding to the candidate reply is used for processing when performing reply fidelity evaluation, reply relevance evaluation, and context relevance evaluation on the candidate reply, it is necessary to determine the adapted pre-trained model in advance based on the correspondence between the candidate reply and the pre-trained model.

[0177] After determining at least one second score corresponding to any candidate reply, determine a target score corresponding to the candidate reply based on the at least one second score corresponding to the candidate reply, and finally select reply information for the user's request question from the candidate reply set based on the target scores corresponding to each candidate reply.

[0178] As an embodiment of the present application, based on reply fidelity, reply relevance and context relevance, the candidate reply is evaluated to obtain a second score corresponding to the reply fidelity. , the second score corresponding to the response relevance , the second score corresponding to the contextual relevance , and then determine the target score based on the scoring formula: ,in , , is the hyper-parameter coefficient, which is set according to the experimental results.

[0179] After determining the target score corresponding to each candidate reply, the candidate replies are sorted in descending order of the score, and the candidate reply with the highest ranking is determined as the reply information for the user's request question. This allows the best reply to be selected from multiple candidate replies through an automatic evaluation method after multiple candidate replies are generated, thereby further improving the accuracy of generated reply information.

[0180] After determining the reply information for the user's request question, the server returns the determined reply information to the client for display on the client, so that the user obtains high-quality reply information.

[0181] The following is an introduction to the overall implementation process of this application through a specific implementation process. Figure 6 As shown:

[0182] Before searching, determine the target encoding model and text block size, divide the input document into multiple text blocks according to the text block size, and build a target database based on the target encoding model and multiple text blocks. Based on the received user request question, obtain the user's corresponding historical question and answer records, and obtain the keyword list and the target request question after rewriting the user request question based on the user request question and the historical question and answer records.

[0183] Retrieval stage: Based on the user request question, target request question and keyword list, a set of candidate text blocks including K second text blocks is retrieved in multiple dimensions. The specific retrieval process is as follows: the user request question, target request question and keyword list are respectively input into the target encoding model to obtain multiple text vectors; the text blocks whose semantic relevance to each text vector meets the semantic relevance requirements are respectively retrieved in the target database to determine the K second text blocks.

[0184] Deduplication and sorting stage: deduplicate and sort the second text blocks in the candidate text block set, and select N first text blocks based on the sorting results. For the detailed process, please refer to the relevant introduction of the above embodiment, which will not be repeated here.

[0185] Generation phase: Use the pre-trained model to rewrite the N first text blocks to determine the target text block, determine the text prompt information based on the target text block and input it into the corresponding pre-trained model to obtain candidate replies corresponding to the text prompt information.

[0186] Screening stage: Score the candidate responses based on at least one evaluation indicator, and select the response information that matches the user's request question based on the score.

[0187] The above implementation process, through a series of operations such as target database construction, multi-dimensional retrieval, information deduplication, text block sorting, text block rewriting, candidate reply generation, and candidate reply screening, provides the client with reply information that matches the user's request question, thereby ensuring the reply quality of intelligent question and answer based on the pre-trained model.

[0188] The above is the overall implementation process of the text generation method provided in the embodiment of the present application. Based on the retrieval of multiple dimensions, N first text blocks related to the user's request question are obtained, so as to achieve relatively comprehensive collection of content related to the user's request question and improve the retrieval accuracy; after determining the N first text blocks, the N first text blocks are evenly distributed to M pre-trained models for text rewriting to obtain N target text blocks. Based on the pre-trained model, the text content that is adapted to the style of the pre-trained model, semantically coherent and natural can be output, so as to improve the quality of the text reply in the future; after determining the text prompt information, based on the correspondence between the pre-trained model and the first text block, the N text prompt information is distributed to the M pre-trained models for processing to obtain a candidate reply set, and an evaluation strategy is used to evaluate each candidate reply in the candidate reply set. The adapted pre-trained model can be used to output the candidate reply, and the candidate reply is evaluated to select the candidate reply that is most suitable for the user's request question, so as to provide reply information that matches the user's request question, which can improve the reply accuracy and ensure the quality of the intelligent reply.

[0189] After determining the set of candidate text blocks, the content in the candidate text block set is deduplicated and sorted, which can streamline the content and avoid information redundancy while providing text blocks that are highly relevant to the user's request questions; by adopting a multi-process concurrent processing method, the processing efficiency can be improved.

[0190] The present application also provides a text generation device, such as Figure 7 As shown, including:

[0191] An acquisition module 701 is used to acquire N first text blocks that are associated with the user's request question and meet a preset condition, wherein the N first text blocks are determined based on a search in multiple dimensions;

[0192] The allocation and acquisition module 702 is used to evenly allocate the N first text blocks to the M pre-trained models for text rewriting, and obtain N target text blocks, where M and N are both integers greater than or equal to 1;

[0193] A processing and obtaining module 703 is used for, after determining the N text prompt information corresponding to the N target text blocks, processing the N text prompt information based on the M pre-trained models to obtain a candidate reply set, wherein the text prompt information includes the target text block, the user request question and the user's corresponding historical question and answer record;

[0194] The evaluation and selection module 704 is used to evaluate the candidate replies in the candidate reply set based on the evaluation strategy, and select reply information that matches the user request question.

[0195] Optionally, the acquisition module includes:

[0196] A retrieval submodule is used to retrieve text information whose relevance to the user's question meets the semantic relevance requirements in multiple dimensions, and obtain a candidate text block set including K second text blocks;

[0197] The processing and obtaining submodule is used to perform text block deduplication and sorting processing on the candidate text block set to obtain the N first text blocks.

[0198] Optionally, the retrieval submodule includes:

[0199] A first acquisition unit is used to acquire a keyword list and a target request question rewritten from the user request question based on the user request question and the historical question and answer record corresponding to the user, wherein the keyword list and the target request question are acquired based on the corresponding model service;

[0200] The second acquisition unit is used to perform text information retrieval in multiple dimensions according to the user request question, the target request question and the keyword list to acquire the K second text blocks.

[0201] Optionally, the second acquiring unit includes:

[0202] An input acquisition subunit, used to input the user request question, the target request question and the keyword list into a target encoding model respectively to acquire a plurality of text vectors;

[0203] A search and determination subunit is used to search the target database for text blocks whose semantic relevance with each text vector meets the semantic relevance requirement, so as to determine the K second text blocks;

[0204] The target database stores vector indexes and corresponding text blocks.

[0205] Optionally, the device further comprises:

[0206] A construction module, used to construct a fine-tuning data set including a plurality of text data, wherein the text data includes question information and reply information, and the text data is data of a target domain;

[0207] An adjustment and determination module, configured to adjust an initial coding model based on the fine-tuning data set to determine the target coding model;

[0208] A block processing module, used for performing block processing on the input document according to the determined text block size, wherein the input document is generated based on the information collected in the target field;

[0209] The first determination module is used to input the multiple text blocks obtained by the block processing into the target coding model to determine the target database.

[0210] Optionally, the device further comprises:

[0211] A second determination module is used to determine a block adjustment range based on a maximum number of words supported by the initial coding model;

[0212] The third determination module is used to determine the text block size within the block adjustment range according to the constructed multiple test data sets.

[0213] Optionally, the processing acquisition submodule includes:

[0214] A calculation unit, used for traversing and calculating the similarity between any two second text blocks in the candidate text block set;

[0215] A determination unit, configured to determine a target text block group according to a similarity calculation result, wherein any two second text blocks constitute a text block group, and a text block group whose similarity of the two second text blocks is greater than a preset threshold is the target text block group;

[0216] a deduplication unit, configured to determine a second text block with a low relevance to the user request question in the target text block group, and delete the determined second text block to perform deduplication of the second text block;

[0217] A third acquisition unit is used to acquire a target text block set after performing second text block deduplication on the target text block group;

[0218] An evaluation acquisition unit, configured to extract feature information of a second text block in the target text block set, and to perform score evaluation on the second text block based on the extracted feature information to acquire a first score corresponding to the second text block;

[0219] The ranking determination unit is used to determine N first text blocks in the target text block set based on the first scores corresponding to the second text blocks.

[0220] Optionally, the ranking determination unit is further used for:

[0221] Based on the first score corresponding to the second text block, the second text blocks in the target text block set are sorted to determine a sorting result, wherein the sorting order of the second text blocks is positively correlated with the relevance corresponding to the second text blocks;

[0222] Based on the ranking result, N second text blocks with higher first scores in the target text block set are determined, and the N second text blocks are determined as the N first text blocks.

[0223] Optionally, the evaluation acquisition unit is further used for:

[0224] Extract feature information from the second text block to obtain at least one of a first semantic similarity between the second text block and the user's question, a second semantic similarity between the second text block and a preceding text of the user's question, and text quality;

[0225] A score evaluation is performed based on at least one of the first semantic similarity, the second semantic similarity, and the text quality to obtain a first score corresponding to the second text block.

[0226] Optionally, the allocation acquisition module includes:

[0227] A division determination submodule is used to divide the N first text blocks into M parts according to a balanced distribution principle, and determine a pre-trained model corresponding to each first text block;

[0228] The rewriting acquisition submodule is used to concurrently input M first text blocks into the corresponding pre-trained model for text rewriting based on the correspondence between the first text block and the pre-trained model, and obtain N target text blocks after text rewriting.

[0229] Optionally, the processing acquisition module is further used for:

[0230] After generating N text prompt information based on the N target text blocks, the user request question and the user's corresponding historical question and answer records, based on the correspondence between the first text block and the pre-trained model, the N text prompt information is concurrently input into the corresponding pre-trained model to obtain the candidate response set;

[0231] Each text prompt message corresponds to at least one candidate reply.

[0232] Optionally, the evaluation and selection module includes:

[0233] An evaluation acquisition submodule, configured to evaluate at least one of response fidelity, response relevance, and context relevance of the candidate response to obtain at least one second score;

[0234] a determination submodule, configured to determine a target score corresponding to the candidate response based on the at least one second score;

[0235] A selection submodule is configured to select, based on the target score, reply information matching the user request question from the candidate replies corresponding to the candidate reply set.

[0236] Optionally, when evaluating at least one of reply fidelity, reply relevance and context relevance of the candidate reply, the candidate reply is processed based on a pre-trained model corresponding to the candidate reply;

[0237] Among them, the pre-trained model corresponding to the candidate reply is determined based on the corresponding relationship between the first text block and the pre-trained model.

[0238] The embodiment of the present application also provides a computer program product, including a computer program / instruction, which, when executed by a processor, implements the various processes of the above-mentioned text generation method embodiment and can achieve the same technical effect. To avoid repetition, it will not be repeated here.

[0239] An embodiment of the present application also provides an electronic device, including a processor, a memory, and a computer program stored in the memory and capable of running on the processor. When the computer program is executed by the processor, the various processes of the above-mentioned text generation method embodiment are implemented and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.

[0240] The embodiment of the present application also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the various processes of the above-mentioned text generation method embodiment are implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.

[0241] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.

[0242] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, devices, computer program products, electronic devices, and storage media. Therefore, the embodiments of the present application may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the embodiments of the present application may take the form of a computer program product implemented on one or more computer-readable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0243] The embodiments of the present application are described with reference to the flowcharts and / or block diagrams of the methods, apparatuses, computer program products, electronic devices, and storage media according to the embodiments of the present application. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1These computer program instructions can also be stored in a computer-readable memory that can guide a computer or other programmable data processing terminal device to work in a specific way, so that the instructions stored in the computer-readable memory produce a product including an instruction device, which implements the functions specified in the process. Figure 1 A process or multiple processes and / or boxes Figure 1 These computer program instructions can also be loaded into a computer or other programmable data processing terminal device, so that a series of operation steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, so that the instructions executed on the computer or other programmable terminal device provide for implementing the process in the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0244] Although the preferred embodiments of the present application have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present application.

[0245] Finally, it should be noted that, in this article, relational terms such as first and second, etc. 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 term "comprise" or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, article or terminal 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 terminal device. In the absence of further restrictions, the elements defined by the sentence "comprise..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the elements.

[0246] The above is an introduction to a text generation method, device, computer program product, electronic device and medium provided by the present application. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea. At the same time, for a person skilled in the art, according to the idea of ​​the present application, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.

Claims

1. A text generation method, It is characterized in that include: Acquire N first text blocks that are associated with the user's request question and meet preset conditions, wherein the N first text blocks are determined based on retrieval of multiple dimensions; Evenly distribute the N first text blocks to M pre-trained models for text rewriting to obtain N target text blocks, where M and N are both integers greater than or equal to 1; After determining N text prompt information corresponding to the N target text blocks, the N text prompt information is processed based on the M pre-trained models to obtain a candidate reply set, the text prompt information includes the target text block, the user request question, and the historical question and answer record corresponding to the user, wherein the N text prompt information is evenly distributed to the M pre-trained models based on the correspondence between the first text block and the pre-trained model, and the text prompt information is generated based on a combination of the target text block, the user request question, and the historical question and answer record corresponding to the user; The candidate replies in the candidate reply set are evaluated based on the evaluation strategy, and reply information matching the user request question is selected.

2. The text generation method according to claim 1, It is characterized in that The obtaining of N first text blocks associated with the user's request question and satisfying a preset condition includes: Retrieving text information whose relevance to the user's question meets the semantic relevance requirement in multiple dimensions, and obtaining a candidate text block set including K second text blocks; The candidate text block set is subjected to text block deduplication and sorting processing to obtain the N first text blocks.

3. The text generation method according to claim 2, It is characterized in that The step of retrieving text information whose relevance to the user's question meets the semantic relevance requirement in multiple dimensions, and obtaining a candidate text block set including K second text blocks, includes: Based on the user request question and the historical question and answer records corresponding to the user, a keyword list and a target request question rewritten from the user request question are obtained, wherein the keyword list and the target request question are obtained based on the corresponding model service; Text information retrieval is performed in multiple dimensions according to the user request question, the target request question and the keyword list to obtain the K second text blocks.

4. The text generation method according to claim 3, It is characterized in that The performing text information retrieval in multiple dimensions according to the user request question, the target request question and the keyword list to obtain the K second text blocks includes: Inputting the user request question, the target request question and the keyword list into a target encoding model respectively to obtain a plurality of text vectors; Retrieve text blocks whose semantic relevance with each text vector meets the semantic relevance requirement in the target database respectively, so as to determine the K second text blocks; The target database stores vector indexes and corresponding text blocks.

5. The text generation method according to claim 4, It is characterized in that Also includes: Constructing a fine-tuning dataset including a plurality of text data, wherein the text data includes question information and answer information, and the text data is data in a target domain; Adjusting the initial coding model based on the fine-tuning data set to determine the target coding model; According to the determined text block size, the input document is divided into blocks, wherein the input document is generated based on the information collected in the target field; The multiple text blocks obtained by the block processing are input into the target coding model to determine the target database.

6. The text generation method according to claim 5, It is characterized in that Also includes: Determining a block adjustment range based on a maximum number of words supported by the initial coding model; According to the constructed multiple test data sets, the text block size is determined within the block adjustment range.

7. The text generation method according to claim 2, It is characterized in that The step of performing text block deduplication and sorting processing on the candidate text block set to obtain the N first text blocks includes: Traversing and calculating the similarity between any two second text blocks in the candidate text block set; Determine a target text block group according to the similarity calculation result, wherein any two second text blocks constitute a text block group, and a text block group whose similarity of the two second text blocks is greater than a preset threshold is the target text block group; Determine a second text block with a low relevance to the user request question in the target text block group, and delete the determined second text block to deduplicate the second text block; After performing second text block deduplication on the target text block group, obtaining a target text block set; Extracting feature information of a second text block in the target text block set, and performing score evaluation on the second text block based on the extracted feature information to obtain a first score corresponding to the second text block; Based on the first score corresponding to the second text block, N first text blocks are determined in the target text block set.

8. The text generation method according to claim 7, It is characterized in that The determining N first text blocks in the target text block set based on the first score corresponding to the second text block includes: Based on the first score corresponding to the second text block, the second text blocks in the target text block set are sorted to determine a sorting result, wherein the sorting order of the second text blocks is positively correlated with the relevance corresponding to the second text blocks; Based on the ranking result, N second text blocks with higher first scores in the target text block set are determined, and the N second text blocks are determined as the N first text blocks.

9. The text generation method according to claim 7, It is characterized in that The extracting feature information of the second text block in the target text block set, and performing score evaluation on the second text block based on the extracted feature information to obtain a first score corresponding to the second text block, includes: Extract feature information from the second text block to obtain at least one of a first semantic similarity between the second text block and the user's question, a second semantic similarity between the second text block and a preceding text of the user's question, and text quality; A score evaluation is performed based on at least one of the first semantic similarity, the second semantic similarity, and the text quality to obtain a first score corresponding to the second text block.

10. The text generation method according to claim 1, It is characterized in that The step of evenly distributing the N first text blocks to the M pre-trained models for text rewriting to obtain N target text blocks includes: According to the principle of balanced distribution, the N first text blocks are divided into M parts, and a pre-trained model corresponding to each first text block is determined; Based on the correspondence between the first text block and the pre-trained model, M copies of the first text block are concurrently input into the corresponding pre-trained model for text rewriting to obtain N target text blocks after text rewriting.

11. The text generation method according to claim 10, It is characterized in that The step of processing the N text prompt information based on the M pre-trained models to obtain a candidate reply set includes: After generating N text prompt information based on the N target text blocks, the user request question and the user's corresponding historical question and answer records, based on the correspondence between the first text block and the pre-trained model, the N text prompt information is concurrently input into the corresponding pre-trained model to obtain the candidate response set; Each text prompt message corresponds to at least one candidate reply.

12. The text generation method according to claim 10 or 11, It is characterized in that The step of evaluating the candidate responses in the candidate response set based on the evaluation strategy and selecting response information matching the user request question includes: Evaluate at least one of response fidelity, response relevance, and context relevance on the candidate response to obtain at least one second score; Determining a target score corresponding to the candidate response based on the at least one second score; Based on the target score, reply information matching the user request question is selected from the candidate replies corresponding to the candidate reply set.

13. The text generation method according to claim 12, It is characterized in that When evaluating at least one of reply fidelity, reply relevance, and context relevance for the candidate reply, processing the candidate reply based on a pre-trained model corresponding to the candidate reply; Among them, the pre-trained model corresponding to the candidate reply is determined based on the corresponding relationship between the first text block and the pre-trained model.

14. A text generation device, It is characterized in that include: An acquisition module, used to acquire N first text blocks associated with the user's request question and satisfying a preset condition, wherein the N first text blocks are determined based on a search in multiple dimensions; An allocation and acquisition module, used to evenly allocate the N first text blocks to M pre-trained models for text rewriting, and obtain N target text blocks, where M and N are both integers greater than or equal to 1; a processing and obtaining module, configured to, after determining N text prompt information corresponding to the N target text blocks, process the N text prompt information based on the M pre-trained models to obtain a candidate reply set, wherein the text prompt information includes the target text block, the user request question, and the historical question and answer record corresponding to the user, wherein the N text prompt information is evenly distributed to the M pre-trained models based on the correspondence between the first text block and the pre-trained model, and the text prompt information is generated based on a combination of the target text block, the user request question, and the historical question and answer record corresponding to the user; The evaluation and selection module is used to evaluate the candidate replies in the candidate reply set based on the evaluation strategy, and select reply information matching the user request question.

15. A computer program product comprising a computer program / instructions, It is characterized in that When the computer program / instructions are executed by a processor, the text generation method according to any one of claims 1 to 13 is implemented.

16. An electronic device, It is characterized in that The invention comprises a processor, a memory and a computer program stored in the memory and capable of running on the processor, wherein when the computer program is executed by the processor, the text generation method according to any one of claims 1 to 13 is implemented.

17. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the text generation method according to any one of claims 1 to 13 is implemented.