Text generation method and apparatus, computer program product, electronic device and medium
By combining multi-dimensional retrieval and pre-trained model rewriting, the problems of low retrieval accuracy and inconsistent generation in text generation of large language models are solved, and high-quality text responses are achieved, which are applicable to intelligent question answering fields such as law, medicine and tourism.
Patent Information
- Application Number
- PCT/CN2025/101827
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2024-06-26
- Filing Date
- 2025-06-18
- Publication Date
- 2026-01-02
AI Technical Summary
Large language models suffer from problems such as low retrieval accuracy, information redundancy, and inconsistent or unnatural generated language structures in text generation. In particular, in the RAG system, the retrieved content is irrelevant or redundant to the query content, affecting the accuracy and coherence of the generated results.
The system retrieves N first text blocks related to the user's request question through multi-dimensional retrieval, and distributes them evenly to M pre-trained models for text rewriting. It then generates text prompts by combining the user's request question with historical question-and-answer records. Finally, it uses an evaluation strategy to select the most suitable response information to ensure that the generated text content matches the user's request question.
It improves the accuracy of text generation and the quality of responses, providing semantically coherent, natural, and stylistically appropriate text content to ensure the accuracy and quality of responses.
Smart Images

Figure CN2025101827_02012026_PF_FP_ABST
Abstract
Description
Text generation method and device, computer program product, electronic device, and medium
[0001] Cross-reference to Related Applications
[0002] This application claims priority to the Chinese patent application No. 202410833500.7, filed on June 26, 2024, entitled “Text generation method and device, computer program product, electronic device, and medium”, the entire content of which is incorporated herein by reference. TECHNICAL FIELD
[0003] The present application relates to the field of artificial intelligence, and in particular to a text generation method and device, a computer program product, an electronic device, and a medium. BACKGROUND
[0004] In recent years, large basic models such as ChatGPT (Chat Generative Pre-trained Transformer) (e.g., LLM (Large Language Model)) have shown impressive performance in text generation, text-to-image generation, and other tasks. However, large language models have inherent limitations, including a tendency to produce hallucinations and a lack of explainability in answers. In order to fully utilize the strong summarization ability of large language models, retrieving external relevant information to enhance the generation results of large language models is a common means to solve the above problems, that is, using RAG (Retrieval-Augmented Generation) technology to provide more reliable and fact-based information.
[0005] When providing information-enhanced generation results of large language models based on RAG technology, the following defects exist: 1. Low retrieval accuracy, that is, not all document blocks in the retrieval set are related to the query content, which may lead to information errors or incoherence. The second is low recall rate, that is, not all relevant document blocks are retrieved, so that the large language model cannot obtain enough background information to synthesize answers. 2. When multiple retrieved text segments contain similar information, redundancy and repetition become a problem, which may lead to repetition of the generated content. Submitting all relevant files 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 may introduce noise and hinder the attention of the large language model to key information. 3. The retrieved content and the query content may have different writing styles or tones, which may lead to the generated language structure becoming less coherent or natural.
[0006] Therefore, in the RAG system, although the introduction of external knowledge can enrich and specify the generated text content, there are also defects such as low retrieval accuracy, information redundancy, and incoherent or unnatural language structure of the generated text. SUMMARY
[0007] In view of the above problems, the embodiments of the present application provide a text generation method, device, computer program product, electronic equipment and medium which overcome the above problems or at least partially solve the above problems.
[0008] In the first aspect, the embodiments of the present application provide a text generation method, comprising:
[0009] Obtaining N first text blocks associated with the user request question and satisfying a preset condition, the N first text blocks being determined based on retrieval in multiple dimensions;
[0010] Equally distributing the N first text blocks to M pre-trained models for text rewriting to obtain N target text blocks, M and N being integers greater than or equal to 1;
[0011] After determining 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 corresponding to the user;
[0012] Evaluating the candidate replies in the candidate reply set based on an evaluation strategy, and selecting reply information matching the user request question.
[0013] In some embodiments of the present application, obtaining N first text blocks associated with the user request question and satisfying a preset condition comprises:
[0014] Retrieving text information associated with the user request question in multiple dimensions in accordance with semantic correlation requirements to obtain a candidate text block set including K second text blocks;
[0015] Performing text block deduplication and sorting processing on the candidate text block set to obtain the N first text blocks.
[0016] In some embodiments of the present application, retrieving text information associated with the user request question in multiple dimensions in accordance with semantic correlation requirements to obtain a candidate text block set including K second text blocks comprises:
[0017] Based on the user request question and the historical question and answer record corresponding to the user, obtaining a keyword list and a target request question rewritten from the user request question, the keyword list and the target request question being obtained based on a corresponding model service;
[0018] 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.
[0019] In some embodiments of the present application, 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, including:
[0020] The user request question, the target request question and the keyword list are respectively input into the target encoding model to obtain a plurality of text vectors;
[0021] In the target database, text blocks with a semantic correlation degree meeting a semantic correlation requirement are respectively retrieved according to the semantic correlation of each text vector to determine K second text blocks;
[0022] The target database stores vector indexes and corresponding text blocks.
[0023] In some embodiments of the present application, the method further includes:
[0024] A fine-tuning data set including a plurality of text data is constructed, the text data including question information and reply information, and the text data being data of a target field;
[0025] The initial encoding model is adjusted based on the fine-tuning data set to determine the target encoding model;
[0026] According to the determined text block size, the input document is processed by block, and the input document is generated based on information collected in the target field;
[0027] The plurality of text blocks obtained by the block processing are input into the target encoding model to determine the target database.
[0028] In some embodiments of the present application, the method further includes:
[0029] Based on the maximum number of words supported by the initial encoding model, a block adjustment range is determined;
[0030] According to the plurality of test data sets constructed, the text block size is determined in the block adjustment range.
[0031] In some embodiments of the present application, the candidate text block set is processed by text block deduplication and sorting to obtain N first text blocks, including:
[0032] The similarity between each two second text blocks in the candidate text block set is calculated;
[0033] According to the similarity calculation result, a target text block group is determined, wherein any two second text blocks form a text block group, and a text block group in which the similarity between two second text blocks is greater than a preset threshold is a target text block group;
[0034] determine a second text block with low relevance to the user request question in the target text block group, and delete the determined second text block to perform second text block deduplication;
[0035] obtain a target text block set after performing the second text block deduplication on the target text block group;
[0036] extract feature information of the second text block in the target text block set, and perform score evaluation on the second text block based on the extracted feature information to obtain a first score corresponding to the second text block;
[0037] determine N first text blocks in the target text block set based on the first score corresponding to the second text block.
[0038] In some embodiments of the present application, determining N first text blocks in the target text block set based on the first score corresponding to the second text block includes:
[0039] sorting the second text blocks in the target text block set based on the first score corresponding to the second text block to determine a sorting result, wherein the arrangement order of the second text blocks is positively correlated with the relevance corresponding to the second text blocks;
[0040] determining N second text blocks with higher 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.
[0041] In some embodiments of the present application, 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:
[0042] extracting feature information of the second text block to obtain at least one of a first semantic similarity between the second text block and the user request question, a second semantic similarity between the second text block and a previous text of the user request question, and a text quality;
[0043] performing score evaluation based on at least one of the first semantic similarity, the second semantic similarity, and the text quality to obtain the first score corresponding to the second text block.
[0044] In some embodiments of the present application, evenly distributing the N first text blocks to M pre-trained models to perform text rewriting to obtain N target text blocks includes:
[0045] dividing the N first text blocks into M parts according to an even distribution principle to determine a pre-trained model corresponding to each part of the first text blocks;
[0046] 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.
[0047] In some embodiments of the present application, the N text prompt information is processed based on the M pre-trained models to obtain a candidate reply set, including:
[0048] After generating the N text prompt information based on the N target text blocks, the user request question and the corresponding historical question and answer record of the user, the N text prompt information is concurrently input into the corresponding pre-trained models based on the correspondence between the first text blocks and the pre-trained models to obtain a candidate reply set;
[0049] Each text prompt information corresponds to at least one candidate reply.
[0050] In some embodiments of the present application, the candidate replies in the candidate reply set are evaluated based on an evaluation strategy, and a reply information matching the user request question is selected, including:
[0051] The candidate reply is evaluated in at least one of reply fidelity, reply relevance and context relevance to obtain at least one second score;
[0052] Based on the at least one second score, a target score corresponding to the candidate reply is determined;
[0053] Based on the target score, a reply information matching the user request question is selected from the candidate replies corresponding to the candidate reply set.
[0054] In some embodiments of the present application, when the candidate reply is evaluated in at least one of reply fidelity, reply relevance and context relevance, the candidate reply is processed based on the pre-trained model corresponding to the candidate reply;
[0055] The pre-trained model corresponding to the candidate reply is determined based on the correspondence between the first text blocks and the pre-trained models.
[0056] In a second aspect, the embodiments of the present application provide a text generation device, including:
[0057] The acquisition module is configured to acquire N first text blocks associated with a user request question and satisfying a preset condition, and the N first text blocks are determined based on retrieval in multiple dimensions;
[0058] The distribution acquisition module is configured to evenly distribute the N first text blocks to M pre-trained models for text rewriting to obtain N target text blocks, and M and N are both integers greater than or equal to 1;
[0059] The processing and acquisition module is used to process the N text prompts corresponding to N target text blocks and obtain a set of candidate responses based on M pre-trained models after determining the N text prompts. The text prompts include the target text blocks, the user's request question, and the user's corresponding historical question and answer records.
[0060] The evaluation and selection module is used to evaluate candidate responses in the candidate response set based on the evaluation strategy and select the response information that matches the user's request.
[0061] Thirdly, embodiments of this application provide a computer program product, including a computer program / instruction, which, when executed by a processor, implements the text generation method of the first aspect.
[0062] Fourthly, embodiments of this application provide an electronic device, including 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 of the first aspect.
[0063] Fifthly, embodiments of this application provide a computer non-volatile readable storage medium storing a computer program, which, when executed by a processor, implements the text generation method of the first aspect.
[0064] The technical solution provided in this application has at least the following beneficial effects:
[0065] This process involves retrieving N first text blocks related to the user's request from multiple dimensions, achieving a relatively comprehensive collection of content relevant to the user's request and improving retrieval accuracy. After determining the N first text blocks, they are evenly distributed to M pre-trained models for text rewriting, resulting in N target text blocks. The output of these target text blocks can be based on the pre-trained models, producing text content that is stylistically compatible, semantically coherent, and natural, thus improving the quality of subsequent text responses. After determining the text prompts, based on the correspondence between the pre-trained models and the first text blocks, the N text prompts are distributed to the M pre-trained models for processing to obtain a candidate response set. An evaluation strategy is used to evaluate each candidate response in the candidate response set. The candidate responses can be output using the appropriate pre-trained models, and the evaluation selects the candidate response that best matches the user's request, providing response information that matches the user's request, improving response accuracy, and ensuring the quality of intelligent responses. Attached Figure Description
[0066] Figure 1 is a schematic diagram of the text generation method provided in an embodiment of this application;
[0067] Figure 2 is a schematic diagram illustrating the determination of three search requests provided in an embodiment of this application;
[0068] FIG. 3 is a flowchart of constructing a target database related to law according to an embodiment of the present application;
[0069] FIG. 4 is a flowchart of determining N first text blocks based on three to-be-retrieved requests according to an embodiment of the present application;
[0070] FIG. 5 is a flowchart of rewriting a text and determining a candidate reply set according to an embodiment of the present application;
[0071] FIG. 6 is a schematic diagram of an overall implementation process of a text generation method according to an embodiment of the present application;
[0072] FIG. 7 is a schematic diagram of a text generation apparatus according to an embodiment of the present application. DETAILED DESCRIPTION
[0073] To make the objectives, technical solutions, and advantages of the embodiments of the present application clearer, the embodiments of the present application will be described in detail below with reference to the drawings. However, those skilled in the art can understand that, in the embodiments of the present application, many technical details are presented in order to make the readers better understand the present application. However, the technical solutions claimed by the present application can be implemented even without these technical details and based on various changes and modifications of the following embodiments. The division of the following embodiments is for the convenience of description, and should not constitute any limitation on the specific implementation of the present application. The embodiments can be combined and referenced with each other on the premise of not contradicting.
[0074] At present, when using a large language model for intelligent reply, the RAG technology can be introduced to provide more reliable and fact-based information. However, there are defects such as low retrieval accuracy, information redundancy, and incoherent or unnatural language structure. In order to reduce the problems caused by the introduction of the RAG technology, the embodiments of the present application provide a text generation method to provide strong support for intelligent reply in fields such as law, medicine, tourism, and the like.
[0075] As shown in FIG. 1, the text generation method provided by the embodiments of the present application comprises:
[0076] In step 101, N first text blocks associated with a user request question and satisfying a preset condition are obtained, and the N first text blocks are determined based on retrieval in multiple dimensions.
[0077] The text generation method provided by the embodiments of the present application is applied to a server. In an intelligent question answering scenario, a user proposes a question on a client. The server receives a user request question sent by the client, performs retrieval in multiple dimensions based on the user request question to determine text content associated with the user request question, and processes the retrieved text content 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 request question is determined through multi-dimensional retrieval and processing of the retrieval result. Moreover, by retrieving content related to the user request question in multiple dimensions, the content related to the user request question can be relatively comprehensively collected, and the retrieval accuracy can be improved.
[0078] The client is an application supporting intelligent question answering. The user request question obtained by the server can be a question related to a specific field, for example, a question related to the fields of law, medicine or travel. As an embodiment of the present application, in an intelligent question answering scenario, a user proposes a question related to law on a client. The client sends the user request question to a server. The server performs retrieval of related content in multiple dimensions based on the received user request question, and determines one or more first text blocks.
[0079] In step 102, the N first text blocks are evenly distributed to M pre-trained models for text rewriting to obtain N target text blocks.
[0080] After the server obtains the N first text blocks related to the user request question, the N first text blocks are evenly distributed to M pre-trained models deployed on the server, so that the first text blocks are rewritten by the pre-trained models. By rewriting the first text blocks by the pre-trained models, text content that is adapted to the style of the pre-trained model, semantically coherent and natural can be output, and then N target text blocks rewritten in the text style are obtained.
[0081] The value of N is greater than or equal to 1, and the value of M is greater than or equal to 1. When the values of N and M are the same, the first text blocks can be directly distributed to the pre-trained models in a one-to-one correspondence. When the value of N is greater than the value of M, the N first text blocks are relatively evenly distributed to the M pre-trained models. When the value of N is less than the value of M, the N first text blocks are evenly distributed to part 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 Unit, GPU), and evenly distributes 8 first text blocks to the above four pre-trained models.
[0082] By inputting the first text block into the pre-trained model for text rewriting, text content of an adapted style can be output based on the pre-trained model to convert the first text block, and provide semantic coherent and natural text content to improve the semantic coherence of the generated reply information for the user request question.
[0083] In step 103, after determining the N target text blocks corresponding to the N text prompt information, 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.
[0084] After rewriting the first text block based on the text style of the pre-trained model to obtain N target text blocks, for each target text block, a corresponding text prompt information is generated. The text prompt information corresponding to the target text block includes the target text block, the user request question, and the historical question and answer record corresponding to the user. Then, based on the correspondence between the target text block and the pre-trained model, the N text prompt information is assigned to the M pre-trained models, and the N text prompt information is processed by the M pre-trained models to determine a candidate reply set.
[0085] The text prompt information can be generated based on the combination of the target text block, the user request question, and the 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 assignment strategy, and the pre-trained model processes and outputs candidate replies adapted to the text prompt information. The candidate reply set is generated based on the candidate replies provided by the M pre-trained models.
[0086] In step 104, the candidate replies in the candidate reply set are evaluated based on an evaluation strategy, and the reply information matching the user request question is selected.
[0087] After obtaining the candidate reply set based on the pre-trained model, each candidate reply in the candidate reply set is evaluated using an evaluation strategy. Through the evaluation of the candidate reply, the most suitable candidate reply for the user request question is selected as the reply information matching the user request question.
[0088] When each candidate reply in the candidate reply set is evaluated using the evaluation strategy, the candidate reply can be evaluated based on one or more evaluation indicators. For the case of using multiple evaluation indicators for evaluation, the 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.
[0089] The above embodiments of the present application obtain N first text blocks related to the user request question based on multi-dimensional retrieval, realize relatively comprehensive collection of content related to the user request question, and improve retrieval precision; after determining the N first text blocks, the N first text blocks are evenly distributed to the M pre-trained models for text rewriting to obtain N target text blocks, so that the pre-trained model can output text content that is adapted to the style of the pre-trained model and is semantically coherent and natural, so as to improve the quality of the text reply in the subsequent process; after determining the text prompt information, the N text prompt information is distributed to the M pre-trained models based on the correspondence between the pre-trained models and the first text blocks to obtain a candidate reply set, and each candidate reply in the candidate reply set is evaluated by using an evaluation strategy, so that the pre-trained model can output a candidate reply, the candidate reply is evaluated, and the candidate reply that is most suitable for the user request question is selected, so as to provide reply information that matches the user request question, and the reply precision and the quality of the intelligent reply can be improved.
[0090] The specific process of obtaining N first text blocks related to the user request question based on multi-dimensional retrieval will be introduced below. As an optional embodiment of the present application, when obtaining N first text blocks associated with the user request question and meeting the preset conditions, the following steps are included:
[0091] Retrieving text information associated with the user request question in multiple dimensions and meeting the semantic correlation requirements, to obtain a candidate text block set including K second text blocks;
[0092] Text block deduplication and sorting processing are performed on the candidate text block set to obtain N first text blocks.
[0093] After obtaining the user request question, text information associated with the user request question and meeting the semantic correlation requirements is retrieved in multiple dimensions. The retrieved text information can be text information with an association degree greater than a first threshold set in advance with the user request question, or it can be a preset number of text information with a high association degree and ranked in the front. The higher the ranking, the higher the association degree. Retrieval is performed in a pre-generated database storing text information.
[0094] After obtaining the candidate text block set including K second text blocks related to the user request question through multi-dimensional retrieval, the second text blocks in the candidate text block set are subjected to deduplication processing to refine the content in the candidate text block set through text block filtering, so as to avoid obtaining redundant information and retain necessary text content. After filtering the second text blocks in the candidate text block set through deduplication processing, the remaining second text blocks in the candidate text block set are sorted to determine the second text blocks in the candidate text block set that meet the set condition, and then N first text blocks related to the user request question are obtained.
[0095] The above implementation process can obtain relatively comprehensive text information related to the user request question through multi-dimensional retrieval to obtain the candidate text block set. After determining the candidate text block set through retrieval, the content in the candidate text block set is subjected to deduplication and sorting processing, so as to provide text blocks with high relevance to the user request question while refining the content and avoiding information redundancy.
[0096] In some embodiments of the present application, when retrieving text information related to the user request question in multiple dimensions to obtain a candidate text block set including K second text blocks, the following steps are included:
[0097] 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, and the keyword list and the target request question are obtained based on the corresponding model service;
[0098] According to the user request question, the target request question and the keyword list, text information is retrieved in multiple dimensions to obtain K second text blocks.
[0099] In the intelligent question and answer scenario, the user may have an incomplete expression of the user request question in the multi-round dialogue with the pre-trained model. Since the pre-trained model has excellent request rewriting capability in the dialogue dense retrieval, the current user request question can be rewritten to provide a complete and required request. Rewriting the user request question can be understood as expanding the user request question, so that the initial question becomes complete and clear through content expansion.
[0100] The request rewriting capability of the pre-trained model is realized based on the request rewriting model service supported by the pre-trained model. The pre-trained model supports the keyword extraction model service while supporting the request rewriting model service, and the two model services support concurrent invocation. Therefore, the user request question can be rewritten and keyword information can be obtained by invoking the corresponding model service.
[0101] That is, when searching in multiple dimensions, the historical question and answer record corresponding to the current user is obtained based on the user request question, and the historical question and answer record is the historical conversation condition of the user based on the pre-trained model deployed on the client and the server in the intelligent question and answer scenario. Then two model services are called, and the user request question and the historical question and answer record corresponding to the user are taken as inputs, and the target request question after the request rewriting and the keyword list are obtained based on the two model services respectively. In order to improve the efficiency, the two model services can be called simultaneously by using the multi-process concurrent mode to perform the request rewriting and keyword extraction operations.
[0102] In some embodiments of the present application, the request rewriting model service and the keyword extraction model service can also be combined into one model service, at which time the two functions are realized by one model service; in some embodiments of the present application, the request rewriting capability can be realized based on the cooperation of at least two model services, and the keyword extraction capability can be realized based on the cooperation of at least two model services, which will not be described in more detail here.
[0103] It should be noted that the model service can be a service supported by any pre-trained model deployed on the server, or a service supported by a specific pre-trained model. The server can use the model service to obtain the keyword list and rewrite the user request question, or use other means to extract the keyword and obtain the rewritten request.
[0104] The process of rewriting the request and extracting the keyword will be introduced below through an embodiment of the present application. For example, the input text is composed of the following template, and the corresponding model service is used for request rewriting: As a legal question and answer assistant, its work is to understand the real intention of the user, please complete the user's current request question according to the above context. Among them, the above context is: {dialog record}, the user's current request question is: {current question}, the user request question is rewritten based on the above content, so that its meaning is clear, and finally an rewritten different request question is output, without any other explanation and intermediate process.
[0105] For another example, the input text is composed of the following template, and the corresponding model service is used for keyword extraction: As a legal question and answer assistant, its work is to understand the real intention of the user, please extract the keywords according to the context. Among them, the context is: {dialog record}, {current question}. Output the most important 3 keywords, without any other explanation and intermediate process.
[0106] After obtaining the keyword list and the target request question determined after rewriting the user request question, in order to ensure the retrieval accuracy, the user request question is retained as a to-be-retrieved request 1 (denoted as Q1), the target request question is retained as a to-be-retrieved request 2 (denoted as Q2), and the keyword list is retained as a to-be-retrieved request 3 (denoted as Q3). According to Q1, Q2 and Q3, text information retrieval is performed in multiple dimensions, K second text blocks are obtained, and different query types and information requirements are adapted based on a mixed retrieval strategy, so as to ensure that information with high correlation and rich context is retrieved consistently.
[0107] As an embodiment of the present application, the process of determining the to-be-retrieved request 1, the to-be-retrieved request 2 and the to-be-retrieved request 3 based on the user request question and the historical question and answer record corresponding to the user can be referred to FIG. 2. The user request question and the historical question and answer record corresponding to the user are input into a model service 1, and a target request question rewritten based on the user request question is obtained from the output of the model service 1. The user request question and the historical question and answer record corresponding to the user are input into a model service 2, and a keyword list is obtained from the output of the model service 2. The user request question is taken as the to-be-retrieved request 1, the target request question is taken as the to-be-retrieved request 2, and the keyword list is taken as the to-be-retrieved request 3, so as to determine the three to-be-retrieved requests based on the user request question and the historical question and answer record corresponding to the user.
[0108] The above implementation process can obtain a complete and clear rewritten target request question and extract key information points by rewriting the user request question and extracting keywords based on the dialogue record and the current user request question. Moreover, the processing efficiency can be improved by calling two model services simultaneously for request rewriting and keyword extraction in a multi-process concurrent manner. The text information retrieval is performed in multiple dimensions based on the user request question, the target request question and the extracted keywords, so as to adapt to different query types and information requirements through mixed retrieval.
[0109] In some embodiments of the present application, when the text information retrieval is performed in multiple dimensions based on the user request question, the target request question and the keyword list to obtain K second text blocks, the process includes:
[0110] The user request question, the target request question and the keyword list are respectively input into a target encoding model to obtain a plurality of text vectors.
[0111] Text blocks with semantic correlation meeting semantic correlation requirements are respectively retrieved in a target database according to the semantic correlation of each text vector, so as to determine K second text blocks. The target database stores vector indexes and corresponding text blocks.
[0112] After determining the target request question and the keyword list, the user request question, the target request question and the keyword list are respectively input into the target coding model to obtain a plurality of text vectors, for example, a corresponding first text vector E1 is obtained based on the user request question, a corresponding second text vector E2 is obtained based on the target request question, and a corresponding third text vector E3 is obtained based on the keyword list. Then, in the target database for storing vector indexes and corresponding text blocks, a text block semantically related to the first text vector E1 is retrieved, a text block semantically related to the second text vector E2 is retrieved, and a text block semantically related to the third text vector E3 is retrieved. Based on the retrieved text blocks, a candidate text block set including K second text blocks is determined.
[0113] In some embodiments of the present application, the text vectors obtained based on the target coding model can also be other numbers, for example, 4 text vectors are obtained, and the keyword list corresponds to two text vectors; or, 2 text vectors are obtained, 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.
[0114] The text blocks semantically related to the text vectors retrieved in the target database can be text blocks with an association degree greater than a threshold value with the text vectors, or can be a specific number of text blocks with a high association degree with the text vectors. At this time, the higher the text block is, the higher the association degree with the text vector is.
[0115] The target coding model is a model determined by adjusting the initial coding model, and the size of the text block in the target database is the best block size determined by testing. When determining the size of the text block, the following steps are included: determining a block adjustment range based on the maximum number of words supported by the initial coding model; and determining the size of the text block in the block adjustment range according to the plurality of test data sets constructed.
[0116] When constructing the RAG system, the block size is a key parameter. Generally, it is desired to retain some overlap between blocks to ensure that the semantic context is not lost between blocks. In most cases, fixed-size blocking is the best path, and compared with other forms of blocking, fixed-size blocking has low computational cost and is easy to use because it does not need to use any NLP (Natural Language Processing) library. The embodiments of the present application perform block adjustment in a small-to-large manner. After selecting the initial coding model, the maximum number of words supported by the initial coding model is determined to determine the block adjustment range. Then, according to the plurality of test data sets constructed, the block size is tested in the block adjustment range in a small-to-large order to determine the best block size.
[0117] As an embodiment of the present application, bge (BAAI General Embedding)-base-zh-v1.5 (Zhixiyuan general embedding model-base model-Chinese-version 1.5) is used as an initial encoding model, the model supports a maximum of 512 tokens, therefore the block adjustment range is designed as [128, 256, 384, 512], and for example, 100 test sets are constructed, according to the 100 test sets constructed, the block size test is performed in ascending order, and the best block size is determined through the test.
[0118] The embodiments of the present application can also determine the best block size in other ways, such as reinforcement learning. After determining the block adjustment range, a plurality of encodings corresponding to a plurality of block sizes in the block adjustment range are determined, each encoding corresponding to a block size. The core of searching for the best block size based on reinforcement learning is: using a policy network to obtain the encoding of the text block size, calculating the accuracy of text retrieval based on the block size, and taking the accuracy as the reward for updating the reinforcement learning policy network. That is, when text retrieval is performed based on the block size in the block adjustment range, the accuracy is determined, and the policy network is updated based on the determined accuracy to continuously optimize the policy network, and the best block size is determined when the policy network optimization is completed.
[0119] In the case of determining the text block size, the text generation method provided by the embodiments of the present application further comprises:
[0120] A fine-tuning data set including a plurality of text data is constructed, the text data includes question information and reply information, and the text data is data of a target field;
[0121] The initial encoding model is adjusted based on the fine-tuning data set to determine a target encoding model;
[0122] According to the determined text block size, the to-be-input document is processed by block, and the to-be-input document is generated based on information collected in the target field;
[0123] The plurality of text blocks obtained by the block processing are input into the target encoding model to determine a target database.
[0124] In the embodiments, in order to improve the retrieval quality and ensure that the obtained content is highly related to the query content, the initial encoding model is fine-tuned to determine a target encoding model, and after the target encoding model is determined, a target database for storing vector indexes and corresponding text blocks is constructed based on the target encoding model and the to-be-input document corresponding to the target field, so as to store 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.
[0125] Before fine-tuning the initial encoding model, a fine-tuning dataset including a plurality of text data is constructed, each text data being data corresponding to the target field and including question information and reply information, and the text data being generated based on the pre-training model, and the size of the text data not being specifically limited. Then, the initial encoding model is adjusted based on the fine-tuning dataset to determine a target encoding model. For example, a fine-tuning dataset including 10,000 text data is constructed, the bge-base-zh-v1.5 model is fine-tuned based on the constructed fine-tuning dataset, and a target encoding model is determined, which is used to output a text vector based on input text content.
[0126] After the target encoding model is determined by fine-tuning the initial encoding model, the input document is processed in blocks according to the determined text block size to obtain a plurality of text blocks, and the plurality of text blocks are input into the target encoding model to determine text vectors corresponding to the plurality of text blocks, set vector indexes corresponding to the text vectors, and construct a target database based on the correspondence between the vector indexes and the text blocks. The input document is generated based on the collected information of the target field, and the collected information can include information in the form of text, audio and / or video. For information in the form of audio and / or video, it needs to be converted into text form to constitute the input document.
[0127] The above implementation process can provide text blocks adapted to multiple dimensions respectively by selecting the optimal block size, constructing the target database based on the optimal block size, and searching in the target database based on the text vectors corresponding to the user request question, the target request question and the keyword list respectively, and further generating a candidate text block set including K second text blocks.
[0128] 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 questions related to law raised by the user are answered based on the constructed database. As shown in FIG. 3, the implementation process of constructing the target database related to law. The legal related documents are composed of legal related books, official website related links, related regulations details, etc., which are input documents. The input documents are processed in blocks based on the determined text block size (optimal text block size) to obtain a plurality of text blocks, the plurality of text blocks are input into the target encoding model to obtain text vectors and set vector indexes, and the target database related to law is constructed based on the vector indexes and the corresponding text blocks. The constructed target database related to law can include a plurality of legal knowledge to ensure the comprehensiveness of the target database.
[0129] After the target database related to the law is constructed, the adapted text content can be retrieved in the database for the user's question related to the law, so as to give a reply to the user's question based on the constructed target database.
[0130] The process of determining N first text blocks from the candidate text block set will be introduced below. In some embodiments of the present application, after the candidate text block set including K text blocks is generated, the candidate text block set is subjected to text block deduplication and sorting processing to obtain N first text blocks, including:
[0131] The similarity between two second text blocks in the candidate text block set is calculated.
[0132] According to the similarity calculation result, a target text block group is determined, wherein any two second text blocks constitute a text block group, and the text block group in which the similarity between the two second text blocks is greater than a preset threshold is the target text block group.
[0133] The second text block with low relevance to the user's request question is determined in the target text block group, and the determined second text block is deleted for second text block deduplication.
[0134] After the target text block group is subjected to second text block deduplication, a target text block set is obtained.
[0135] The feature information of the second text block in the target text block set is extracted, and the second text block is scored based on the extracted feature information to obtain a first score corresponding to the second text block.
[0136] Based on the first score corresponding to the second text block, N first text blocks are determined in the target text block set.
[0137] When the candidate text block set is subjected to text block deduplication, the similarity between two second text blocks is calculated based on the strategy of two-by-two combination of the second text block and other second text blocks different from the current second text block. The two second text blocks combined 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, the candidate text block set includes the second text block A, the second text block B and the second text block C, and based on the two-by-two combination, the following text block groups can be obtained: 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.
[0138] In the constructed text block group, according to the similarity calculation result, a target text block group in which the similarity of 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 low relevance to the user request question is determined in the target text block group, and the second text block is deleted to perform text block deduplication on the target text block group. After the text block deduplication is performed on the target text block group, the target text block set is determined based on the target text block group after deduplication and other text block groups, and the target text block set does not include duplicate second text blocks, for example, a certain second text block is retained multiple times, and the target text block set only includes one of the second text blocks.
[0139] After the target text block set is determined based on the deduplication, feature information extraction is performed on each second text block in the target text block set, and then score evaluation is performed on the second text block based on the extracted feature information to obtain a first score corresponding to the second text block.
[0140] In the feature information extraction on the second text block and the first score obtained based on the extracted feature information, at least one of a first semantic similarity between the second text block and the user request question, a second semantic similarity between the second text block and the context of the user request question, and a text quality is obtained; 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.
[0141] In the embodiment, the feature information obtained by the feature information extraction on 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 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 PPL (perplexity, perplexity), Distinct (diversity), etc. evaluation indicators, wherein the perplexity is used to measure whether a sentence is smooth, and the Distinct evaluation indicator is used to judge the diversity of the reply. The definition of perplexity is as follows:
[0142] wherein P(x i |x1,x2,…,x i-1 ) represents the probability of predicting the i-th word according to the previous words, and N represents the length of the sentence. The smaller the PPL value, the more natural the text and the smoother the sentence. By evaluating the text by PPL, the situation of out-of-order, front-back reversal of the text can be avoided.
[0143] The Distinct evaluation indicator is specifically used to judge whether there is a large amount of general and repetitive content. The definition of Distinct is as follows:
[0144] wherein, in the above formula, Count(uniquengram) represents the number of non-repeated ngrams in the text, Count(word) represents the total number of ngram words in the text, and the larger Distinct(n) represents the higher diversity.
[0145] After obtaining at least one of the first semantic similarity, the second semantic similarity and the text quality of the second text block based on the feature information extraction, score evaluation is performed based on at least one of the first semantic similarity, the second semantic similarity and the text quality to obtain the first score corresponding to the second text block. If score evaluation is performed based on at least two of the above feature information, parameters corresponding to each feature information need to be set to determine the first score based on the parameters and the feature information.
[0146] As an embodiment of the present application, the first semantic similarity Score1, the second semantic similarity Score2 and the text quality Score PPL of the second text block are obtained based on feature information extraction Distinct , and then the corresponding first score is determined based on a score formula: Score = a1Score1 + b1Score2 + g1(Score PPL + Score Distinct ), a1, b1 and g1 are hyperparameter coefficients, which are set according to experimental results.
[0147] After obtaining the first score corresponding to each second text block in the target text block set, when determining N first text blocks in the target text block set based on the first score corresponding to the second text block, the following steps are included: sorting the second text blocks in the target text block set based on the first score corresponding to the second text block to determine a sorting result, wherein the arrangement order of the second text blocks is positively correlated with the relevance of the second text blocks; determining N second text blocks with higher 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.
[0148] 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 the order from high to low of the first score to obtain a sorting result. The higher the first score is, the higher the relevance of the second text block to the user request question and / or the historical question and answer record is, and / or the higher the text quality is, i.e., the second text block with a higher corresponding relevance is arranged earlier and the second text block with a higher text quality is arranged earlier. After the sorting is completed, N second text blocks with higher first scores in the target text block set are determined to obtain N first text blocks, so as to filter out text blocks with high relevance to the user request question and / or the historical question and answer record and high text quality.
[0149] The implementation process described above, after determining the candidate text block set, de-duplicates the candidate text block set to delete redundant information and achieve content simplification; after completing de-duplication, score evaluation is performed through feature information extraction, and text blocks of high quality are provided based on the score screening, so as to achieve de-duplication while optimizing the content related to the query.
[0150] As an embodiment of the present application, the process of determining the Nth first text block based on three to-be-retrieved requests is introduced below through a flowchart, as shown in FIG. 4. The user request question is taken as the to-be-retrieved request 1, the target request question is taken as the to-be-retrieved request 2, and the keyword list is taken as the to-be-retrieved request 3. The to-be-retrieved request 1, the to-be-retrieved request 2, and the to-be-retrieved request 3 are input into the target coding model 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, retrieval 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, so as to determine K second text blocks. The q text blocks associated with the text vector are text blocks with higher correlation degree screened out.
[0151] Then, de-duplication is performed on the candidate text block set including the K second text blocks. After completing de-duplication, feature information extraction is performed on the remaining second text blocks, the first score is calculated, and the second text blocks are sorted according to the first score. Finally, N first text blocks are provided.
[0152] In the flowchart shown in FIG. 4, through a series of processes such as retrieval, de-duplication, scoring, and sorting, text blocks with high correlation degree are screened out, so as to provide high-quality text blocks and ensure the retrieval effect.
[0153] The implementation scheme of determining the reply information matched with the user request question based on the Nth first text block is introduced below. The implementation scheme includes the processes of obtaining target text blocks, obtaining a candidate reply set, and screening matched candidate replies in the candidate reply set.
[0154] Among them, for the process of obtaining target text blocks, when the N first text blocks are evenly distributed to M pre-training models for text rewriting to obtain N target text blocks, the process includes:
[0155] According to the principle of even distribution, the N first text blocks are divided into M parts, and the pre-training model corresponding to each part of the first text block is determined. Based on the correspondence between the first text block and the pre-training model, the M parts of the first text block are concurrently input into the corresponding pre-training model for text rewriting to obtain N target text blocks after text rewriting.
[0156] In the embodiments of the present application, M pre-trained models are deployed on the server, and when M is greater than 1, the M pre-trained models support concurrent calls. After determining the N first text blocks, the N first text blocks are divided into M parts based on the principle of balanced distribution, the pre-trained model corresponding to each part of the first text block is determined, and the correspondence between the M parts of the first text block and the M pre-trained models is established.
[0157] As an embodiment of the present application, the value of N is 10 and 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 block is 2, 2, 3 and 3 respectively, so as to relatively evenly divide the text blocks. Alternatively, the value of N is 15 and 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 part of the first text block is 5.
[0158] Among them, the pre-trained model corresponding to each part of the first text block can be determined randomly or according to a preset strategy. For example, the N first text blocks are divided according to the order of the correlation degree from high to low, the M parts of the first text block are arranged according to the order of the priority from high to low, and the correlation degree and the priority are positively correlated, that is, the higher the corresponding correlation degree, the higher the priority. For the M pre-trained models, the priority order thereof is determined, and the priority of the pre-trained model is determined based on the usage frequency, audience degree and other parameters of the pre-trained model. According to the allocation strategy that the first text block with high priority corresponds to the pre-trained model with high priority, the correspondence between the M parts of the first text block and the M pre-trained models is established, or according to the allocation strategy that the first text block with high priority corresponds to the pre-trained model with low priority, the correspondence between the M parts of the first text block and the M pre-trained models is established.
[0159] After establishing the correspondence between the first text block and the pre-trained model, the M parts of the first text block are concurrently input into the corresponding pre-trained model to rewrite the first text block based on the text style of the pre-trained model to obtain N target text blocks, thereby realizing efficient acquisition of required information based on multi-thread concurrent mode. And by rewriting the text style of the first text block, the problem that the reply generated for the user request question is incoherent or unnatural can be reduced or avoided.
[0160] For the process of obtaining the candidate reply set, when the N text prompt information is processed based on the M pre-trained models to obtain the candidate reply set, the process includes:
[0161] After generating the N text prompt information based on the N target text blocks, the user request question and the historical question and answer record corresponding to the user, the N text prompt information is concurrently input into the corresponding pre-trained model based on the correspondence between the first text block and the pre-trained model to obtain the candidate reply set; each text prompt information corresponds to at least one candidate reply.
[0162] After the N target text blocks are obtained by text rewriting of the first text blocks using the pre-trained model, for each target text block, a corresponding text prompt information is generated based on the combination of the current target text block, the user request question and the user's corresponding historical question and answer record, to obtain N text prompt information corresponding to the N target text blocks. Then, the N text prompt information is input into the corresponding pre-trained model in parallel using the corresponding relationship between the first text block and the pre-trained model, the pre-trained model processes the text prompt information, and a candidate reply determined based on the text prompt information is obtained, and then a candidate reply set is determined based on the aggregation of the candidate replies.
[0163] By inputting the N text prompt information into the M pre-trained models in parallel, the M pre-trained models can process the text prompt information in parallel to efficiently output candidate replies in a multi-thread concurrent manner. For any text prompt information, at least one candidate reply is output by the corresponding pre-trained model after inputting the text prompt information into the corresponding pre-trained model. The candidate reply set including at least N candidate replies is determined after aggregating the candidate replies corresponding to the N text prompt information.
[0164] The process of rewriting the first text block and determining the candidate reply set based on the rewritten target text block will be introduced below through an embodiment of the present application. As shown in FIG. 5, the N first text blocks are evenly distributed to four pre-trained models (pre-trained model A, pre-trained model B, pre-trained model C and pre-trained model D), and the first text blocks are processed in parallel by the four pre-trained models for text rewriting, and N target text blocks are output to efficiently provide the target text blocks in a multi-thread concurrent manner.
[0165] After obtaining the N target text blocks, for each target text block, a text prompt information is generated based on the target text block, the user request question and the user's corresponding historical question and answer record, and the N text prompt information is input into the corresponding pre-trained model, and the candidate replies corresponding to the text prompt information are output by the four pre-trained models in parallel processing to efficiently determine the candidate reply set in a parallel processing manner.
[0166] In the process shown in FIG. 5, the candidate reply set is determined through a series of processes such as text rewriting, text prompt information generation and candidate reply output, which can provide a basis for screening replies adapted to the user request question, and the parallel processing manner improves the efficiency.
[0167] For the process of screening the matched candidate reply in the candidate reply set, when the candidate reply in the candidate reply set is evaluated based on the evaluation strategy, and the reply information matched with the user request question is selected, it includes:
[0168] The candidate reply is evaluated in at least one of reply fidelity, reply relevance and context relevance to obtain at least one second score; based on the at least one second score, a target score corresponding to the candidate reply is determined; and based on the target score, reply information matching the user request question is selected from the candidate replies in the candidate reply set.
[0169] In the screening of the candidate reply set as the reply information matching the user request question, each candidate reply in the candidate reply set is evaluated based on at least one of the reply fidelity, the reply relevance and the context relevance to determine at least one second score corresponding to the candidate reply.
[0170] In the evaluation of the candidate reply based on the reply fidelity, the candidate reply is semantically decomposed by using a pre-trained model corresponding to the candidate reply to obtain a plurality of reference replies, and the consistency of each reference reply with the context is verified to determine whether the reference reply is a reply that can support the user request question. 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 request question to the total number of reference replies.
[0171] In the evaluation of the candidate reply based on the reply relevance, a pre-trained model corresponding to the candidate reply is used to generate possible questions adapted to the candidate reply, and the similarity of these questions to the user request question is analyzed. The score corresponding to the reply relevance is obtained by calculating the average of the similarity of all generated questions to the user request question. The specific calculation formula is:
[0172] For a given candidate reply as(q), the pre-trained model is prompted to generate n potential questions q i For each q i , the similarity sim(q, q i ) to the user request question (original question) q is calculated, and the average of the sum of the n similarities is determined as the final result, which is taken as the second score corresponding to the reply relevance.
[0173] In the evaluation of the candidate reply based on the context relevance, a pre-trained model corresponding to the candidate reply is used to screen out sentences directly related to the user request question from the historical question and answer records corresponding to the user, and the proportion of these sentences to the total number of sentences in the context is used to determine the second score corresponding to the context relevance. The specific calculation formula is: CR = number of screened sentences / total number of sentences in the context
[0174] By screening the sentences directly related to the user request question from the historical question and answer records corresponding to the user, the ratio of the screened sentences to the total number of sentences is used to determine the second score, thereby realizing the measurement of the context relevance.
[0175] In the reply fidelity evaluation, the reply relevance evaluation, and the context relevance evaluation, the pre-trained model corresponding to the candidate reply is used for processing. Therefore, the corresponding pre-trained model needs to be determined in advance according to the correspondence between the candidate reply and the pre-trained model.
[0176] After determining the at least one second score corresponding to each candidate reply, a target score corresponding to the candidate reply is determined based on the at least one second score corresponding to the candidate reply. Finally, the reply information for the user request question is selected from the candidate reply set based on the target score corresponding to each candidate reply.
[0177] As an embodiment of the present application, the candidate reply is evaluated based on the reply fidelity, the reply relevance, and the context relevance to obtain a second score Score F corresponding to the reply fidelity, a second score Score AR corresponding to the reply relevance, and a second score Score CR corresponding to the context relevance. Then, a target score Score = a2Score F + b2Score AR + g2Score CR is determined based on a score formula, where a2, b2, and g2 are hyperparameter coefficients set according to experimental results.
[0178] After determining the target score corresponding to each candidate reply, the candidate replies are sorted in descending order of the scores. The candidate reply with the highest score is determined as the reply information for the user request question, so that the best reply is selected from the multiple candidate replies through the automatic evaluation method after generating the multiple candidate replies, and the accuracy of generating the reply information is further improved.
[0179] After determining the reply information for the user 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.
[0180] The overall implementation process of the present application will be introduced below through a specific implementation process, as shown in FIG. 6:
[0181] Before retrieval, a target coding model and a text block size are determined. The input document is divided into multiple text blocks according to the text block size, and a target database is constructed based on the target coding model and the multiple text blocks. Based on the received user request question, the historical question and answer records corresponding to the user are obtained, and a keyword list and a target request question rewritten based on the user request question are obtained based on the user request question and the historical question and answer records.
[0182] The retrieval stage: based on the user request question, the target request question and the keyword list, retrieval is performed in multiple dimensions to obtain a candidate text block set including K second text blocks. The specific retrieval process is: inputting the user request question, the target request question and the keyword list into the target coding model respectively to obtain multiple text vectors; and respectively retrieving text blocks with a semantic correlation degree meeting semantic correlation requirements from the target database according to the semantic correlation degree of each text vector to determine the K second text blocks.
[0183] The deduplication and sorting stage: the second text blocks in the candidate text block set are deduplicated and sorted, and N first text blocks are selected based on the sorting result. For details, refer to the related description in the above embodiments, which will not be repeated here.
[0184] The generation stage: a target text block is determined by using a pre-training model to rewrite the N first text blocks, and the candidate reply corresponding to the target text block is obtained by inputting the target text block into the corresponding pre-training model.
[0185] The screening stage: the candidate reply is scored based on at least one evaluation index, and the reply information matching the user request question is selected based on the scoring result.
[0186] The above implementation process provides the client with reply information matching the user request question 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, thereby ensuring the reply quality of intelligent question answering based on the pre-training model.
[0187] The above is the overall implementation process of the text generation method provided by the embodiments of the present application. N first text blocks related to the user request question are obtained based on multi-dimensional retrieval, which realizes relatively comprehensive collection of content related to the user request question and improves the retrieval accuracy. After the N first text blocks are determined, the N first text blocks are evenly distributed to M pre-training models for text rewriting to obtain N target text blocks. The pre-training model can output text content that is adapted to the style of the pre-training model and is semantically coherent and natural, so as to improve the quality of the text reply in the subsequent process. After the text prompt information is determined, the N text prompt information is distributed to the M pre-training models based on the corresponding relationship between the pre-training model and the first text block to obtain a candidate reply set. Each candidate reply in the candidate reply set is evaluated by using an evaluation strategy. The pre-training model that is adapted to the candidate reply can be used to output the candidate reply, and the candidate reply that is most adapted to the user request question is selected by evaluating the candidate reply, so as to provide reply information matching the user request question, thereby improving the reply accuracy and ensuring the quality of the intelligent reply.
[0188] After determining the candidate text block set, the contents in the candidate text block set are de-duplicated and sorted, so that text blocks with high relevance to the user request question can be provided while avoiding information redundancy; and by using a multi-process concurrent processing manner, the processing efficiency can be improved.
[0189] The embodiments of the present application also provide a text generation apparatus, as shown in FIG. 7, which comprises:
[0190] The obtaining module 701 is configured to obtain N first text blocks associated with the user request question and meeting preset conditions, the N first text blocks being determined based on retrieval in multiple dimensions;
[0191] The distribution obtaining module 702 is configured to evenly distribute the N first text blocks to M pre-trained models for text rewriting, and obtain N target text blocks, M and N being integers greater than or equal to 1;
[0192] The processing obtaining module 703 is 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, the text prompt information comprising the target text block, the user request question and the historical question and answer record corresponding to the user;
[0193] The evaluation and selection module 704 is configured to evaluate candidate replies in the candidate reply set based on an evaluation strategy, and select reply information matching the user request question.
[0194] In some embodiments of the present application, the obtaining module comprises:
[0195] The retrieval obtaining sub-module is configured to retrieve text information meeting semantic correlation requirements in terms of relevance to the user request question in multiple dimensions, and obtain a candidate text block set comprising K second text blocks;
[0196] The processing obtaining sub-module is configured to perform text block de-duplication and sorting on the candidate text block set, and obtain N first text blocks.
[0197] In some embodiments of the present application, the retrieval obtaining sub-module comprises:
[0198] The first obtaining unit is configured to, based on the user request question and the historical question and answer record corresponding to the user, obtain a keyword list and a target request question rewritten from the user request question, the keyword list and the target request question being obtained based on corresponding model services;
[0199] The second obtaining unit is configured to retrieve text information in multiple dimensions according to the user request question, the target request question and the keyword list, and obtain K second text blocks.
[0200] In some embodiments of the present application, the second acquisition unit comprises:
[0201] The input acquisition subunit is configured to input the user request question, the target request question, and the keyword list into the target coding model respectively to obtain a plurality of text vectors.
[0202] The search determination subunit is configured to search for text blocks with a semantic correlation degree meeting a semantic correlation requirement in the target database respectively according to the semantic correlation degree of each text vector to determine K second text blocks.
[0203] The target database stores vector indexes and corresponding text blocks.
[0204] In some embodiments of the present application, the device further comprises:
[0205] The construction module is configured to construct a fine-tuning data set comprising a plurality of text data, the text data comprising question information and reply information, and the text data being data of the target field;
[0206] The adjustment determination module is configured to adjust the initial coding model based on the fine-tuning data set to determine the target coding model.
[0207] The block processing module is configured to perform block processing on a to-be-input document according to the determined text block size, the to-be-input document being generated based on information collected in the target field.
[0208] The first determination module is configured to input a plurality of text blocks obtained by the block processing into the target coding model to determine the target database.
[0209] In some embodiments of the present application, the device further comprises:
[0210] The second determination module is configured to determine a block adjustment range based on a maximum number of words supported by the initial coding model.
[0211] The third determination module is configured to determine the text block size in the block adjustment range according to the plurality of test data sets constructed.
[0212] In some embodiments of the present application, the processing acquisition sub-module comprises:
[0213] The calculation unit is configured to calculate the similarity between two second text blocks in the candidate text block set.
[0214] The determination unit is configured to determine a target text block group according to the similarity calculation result, wherein any two second text blocks form a text block group, and a text block group in which the similarity between two second text blocks is greater than a preset threshold is a target text block group.
[0215] The de-duplication unit is configured to determine second text blocks with low relevance to the user request question in the target text block group, and delete the determined second text blocks to perform second text block de-duplication.
[0216] The third acquisition unit is configured to acquire the target text block set after performing the second text block de-duplication on the target text block group.
[0217] The evaluation acquisition unit is configured to perform feature information extraction on the second text blocks in the target text block set, and perform score evaluation on the second text blocks based on the extracted feature information to acquire first scores corresponding to the second text blocks.
[0218] The sorting determination unit is configured to determine N first text blocks in the target text block set based on the first scores corresponding to the second text blocks.
[0219] In some embodiments of the present application, the sorting determination unit is further configured to:
[0220] sort the second text blocks in the target text block set based on the first scores corresponding to the second text blocks, and determine a sorting result, wherein the arrangement order of the second text blocks is positively correlated with the relevance corresponding to the second text blocks;
[0221] determine N second text blocks with higher first scores in the target text block set based on the sorting result, and determine the N second text blocks as the N first text blocks.
[0222] In some embodiments of the present application, the evaluation acquisition unit is further configured to:
[0223] perform feature information extraction on the second text blocks, and acquire at least one of a first semantic similarity between the second text blocks and the user request question, a second semantic similarity between the second text blocks and the context of the user request question, and a text quality;
[0224] perform score evaluation based on at least one of the first semantic similarity, the second semantic similarity, and the text quality to acquire the first scores corresponding to the second text blocks.
[0225] In some embodiments of the present application, the allocation acquisition module comprises:
[0226] The division determination submodule is configured to divide the N first text blocks into M parts according to an equal allocation principle, and determine a pre-training model corresponding to each part of the first text blocks.
[0227] The rewriting acquisition submodule is configured to input the M parts of the first text blocks into corresponding pre-training models for text rewriting in a concurrent manner based on the correspondence between the first text blocks and the pre-training models, and acquire N target text blocks after text rewriting.
[0228] In some embodiments of the present application, the processing acquisition module is further configured to:
[0229] After generating the N text prompt information based on the N target text blocks, the user request question and the corresponding historical question and answer records of the user, the N text prompt information is input into the corresponding pre-trained model based on the correspondence between the first text block and the pre-trained model, and a candidate reply set is acquired;
[0230] Each text prompt information corresponds to at least one candidate reply.
[0231] In some embodiments of the present application, the evaluation selection module comprises:
[0232] The evaluation acquisition submodule is configured to evaluate at least one of the reply fidelity, the reply relevance and the context relevance of the candidate reply, and acquire at least one second score;
[0233] The determination submodule is configured to determine the target score corresponding to the candidate reply based on the at least one second score;
[0234] The selection submodule is configured to select the reply information matching the user request question from the candidate reply corresponding to the candidate reply set based on the target score.
[0235] In some embodiments of the present application, when at least one of the reply fidelity, the reply relevance and the context relevance of the candidate reply is evaluated, the candidate reply is processed based on the pre-trained model corresponding to the candidate reply;
[0236] The pre-trained model corresponding to the candidate reply is determined based on the correspondence between the first text block and the pre-trained model.
[0237] Embodiments of the present application also provide a computer program product, which comprises computer programs / instructions, and the computer programs / instructions are executed by a processor to implement various processes of the above-mentioned text generation method embodiments and achieve the same technical effects. To avoid repetition, details are not described herein.
[0238] Embodiments of the present application also provide an electronic device, which comprises a processor, a memory, and a computer program stored on the memory and capable of running on the processor. The computer program is executed by the processor to implement various processes of the above-mentioned text generation method embodiments and achieve the same technical effects. To avoid repetition, details are not described herein.
[0239] Embodiments of the present application also provide a computer non-volatile readable storage medium, which stores a computer program. The computer program is executed by a processor to implement various processes of the above-mentioned text generation method embodiments and achieve the same technical effects. To avoid repetition, details are not described herein.
[0240] The various embodiments in the specification are described in progressive manner, each embodiment focusing on the differences from other embodiments, and the same or similar parts between the embodiments can be mutually referred to.
[0241] Those skilled in the art understand that the embodiments of the present application can be provided as methods, apparatuses, computer program products, electronic devices and storage media. Therefore, the embodiments of the present application can adopt a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Moreover, the embodiments of the present application can adopt the form of a computer program product implemented on one or more computer non-volatile readable storage media (including but not limited to disk memory, CD-ROM, optical memory, etc.) containing computer usable program codes.
[0242] The embodiments of the present application are described with reference to flowcharts and / or block diagrams according to the methods, apparatuses, computer program products, electronic devices and storage media of the embodiments of the present application. It should be understood that each flow and / or block in the flowcharts and / or block diagrams, and the combination of the flows and / or blocks in the flowcharts and / or block diagrams can be implemented by computer program instructions. These computer program instructions can be provided to a general-purpose computer, a special-purpose computer, an embedded processor or other programmable data processing terminal equipment to produce a machine, so that the instructions executed by the computer or other programmable data processing terminal equipment produce a device for implementing the functions specified in one or more flows in the flowcharts and / or one or more blocks in the block diagrams. These computer program instructions can also be stored in a computer readable memory that can cause the computer or other programmable data processing terminal equipment to work in a specific way, so that the instructions stored in the computer readable memory produce a product including instruction devices, which implement the functions specified in one or more flows in the flowcharts and / or one or more blocks in the block diagrams. These computer program instructions can also be loaded into a computer or other programmable data processing terminal equipment, so that a series of operation steps are performed on the computer or other programmable terminal equipment to produce a computer implemented process, so that the instructions executed on the computer or other programmable terminal equipment provide steps for implementing the functions specified in one or more flows in the flowcharts and / or one or more blocks in the block diagrams.
[0243] Although the preferred embodiments of the present application have been described, those skilled in the art can make further changes and modifications to the embodiments once they know the basic inventive concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications falling within the scope of the embodiments of the present application.
[0244] Finally, it is to be understood that the phraseology or terminology such as "comprising", "including", "containing", "consisting of", "consisting essentially of", or the like, used in the specification and in claims (if any) is only intended to denote any entity, including any product, composition, structure, method, transformation, or process, that might under any circumstance be encompassed by the disclosure, and is not intended to limit or narrow the scope of the disclosure to only include what customarily might be presented with that terminology. It is also to be understood that the terminology "one or more of the" or "at least one of the" is only intended to denote any entity, including any product, composition, structure, method, transformation, or process, that might under any circumstance be encompassed by the disclosure, and is not intended to limit or narrow the scope of the disclosure to only include what customarily might be presented with that terminology.
[0245] The above introduces a text generation method, device, computer program product, electronic device and medium provided by the present application. The principles and implementation manners of the present application are described by applying specific examples in the present article. The above example is only used to help understand the method and core idea of the present application. Meanwhile, for those skilled in the art, the specific implementation manners and application ranges will be changed according to the idea of the present application. In summary, the content of the specification should not be understood as a limitation of the present application.
Claims
1. A text generation method, characterized in that, include: Obtain N first text blocks that are associated with the user's request and meet preset conditions, wherein the N first text blocks are determined based on retrieval from multiple dimensions; The N first text blocks are evenly distributed 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 the N text prompts corresponding to the N target text blocks, the N text prompts are processed based on the M pre-trained models to obtain a candidate response set. The text prompts include the target text blocks, the user request question, and the user's corresponding historical question and answer records. The candidate responses in the candidate response set are evaluated based on the evaluation strategy, and the response information that matches the user's request question is selected.
2. The text generation method according to claim 1, characterized in that, The acquisition of N first text blocks that are associated with the user's request and meet preset conditions includes: Retrieve text information that meets the semantic relevance requirement to the user's request question across multiple dimensions, and obtain 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, characterized in that, The step of retrieving text information that meets the semantic relevance requirement to the user's request question across multiple dimensions, and obtaining a candidate text block set including K second text blocks, includes: Based on the user's request question and the user's corresponding historical question and answer records, a keyword list and a target request question rewritten from the user's request question are obtained. The keyword list and the target request question are obtained based on the corresponding model service. Based on the user request question, the target request question, and the keyword list, text information is retrieved across multiple dimensions to obtain the K second text blocks.
4. The text generation method according to claim 3, characterized in that, The step of retrieving text information across multiple dimensions based on the user request question, the target request question, and the keyword list to obtain the K second text blocks includes: Input the user request question, the target request question, and the keyword list into the target encoding model to obtain multiple text vectors; The K second text blocks are determined by retrieving text blocks from the target database that meet the semantic relevance requirements of each text vector. The target database stores vector indexes and corresponding text blocks.
5. The text generation method according to claim 4, characterized in that, Also includes: Construct a fine-tuning dataset comprising multiple text data, including question information and response information, and the text data being data from the target domain; The initial coding model is adjusted based on the fine-tuning dataset, and the target coding model is determined. The input document is divided into blocks based on the determined text block size, and the input document is generated based on information collected in the target domain. The multiple text blocks obtained from the block processing are input into the target encoding model to determine the target database.
6. The text generation method according to claim 5, characterized in that, Also includes: The block adjustment range is determined based on the maximum number of words supported by the initial encoding model. Based on the constructed multiple test datasets, determine the text block size within the block adjustment range.
7. The text generation method according to claim 2, characterized in that, The step of performing text block deduplication and sorting on the candidate text block set to obtain the N first text blocks includes: The similarity between each pair of second text blocks in the candidate text block set is calculated by iterating through the set. Based on the similarity calculation results, target text block groups are determined, wherein any two second text blocks constitute a text block group, and the text block group in which the similarity between two second text blocks is greater than a preset threshold is the target text block group. In the target text block group, identify a second text block that has a low relevance to the user's request question, and delete the identified second text block to perform deduplication of the second text block; After performing a second text block deduplication on the target text block group, a target text block set is obtained; Feature information is extracted from the second text block in the target text block set, and a score is evaluated on the second text block based on the extracted feature information to obtain the 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, characterized in that, The step of 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 the sorting result, wherein the sorting order of the second text blocks is positively correlated with the relevance of the second text block; Based on the sorting results, the N second text blocks with the highest first scores in the target text block set are determined, and the N second text blocks are identified as the N first text blocks.
9. The text generation method according to claim 7, characterized in that, The step of extracting feature information from the second text block in the target text block set and evaluating the score of the second text block based on the extracted feature information to obtain the first score corresponding to the second text block includes: Feature information is extracted from the second text block to obtain at least one of the following: the first semantic similarity between the second text block and the user request question, the second semantic similarity between the second text block and the preceding text of the user request question, and text quality. A score is evaluated based on at least one of the first semantic similarity, the second semantic similarity, and the text quality to obtain the first score corresponding to the second text block.
10. The text generation method according to claim 1, characterized in that, The step of evenly distributing the N first text blocks to M pre-trained models for text rewriting to obtain N target text blocks includes: According to the principle of balanced allocation, the N first text blocks are divided into M parts, and the pre-trained model corresponding to each part of the 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, resulting in N rewritten target text blocks.
11. The text generation method according to claim 10, characterized in that, The process of processing the N text prompts based on the M pre-trained models to obtain a candidate response set includes: After generating N text prompts based on N target text blocks, the user's request question, and the user's corresponding historical question and answer records, the N text prompts are concurrently input into the corresponding pre-trained model based on the correspondence between the first text block and the pre-trained model to obtain the candidate response set. Each text prompt corresponds to at least one candidate response.
12. The text generation method according to claim 10 or 11, characterized in that, The step of evaluating candidate responses in the candidate response set based on the evaluation strategy and selecting response information that matches the user's request includes: The candidate responses are evaluated based on at least one of response fidelity, response relevance, and contextual relevance to obtain at least one second score; Based on the at least one second score, determine the target score corresponding to the candidate response; Based on the target score, the response information that matches the user's requested question is selected from the candidate responses corresponding to the candidate response set.
13. The text generation method according to claim 12, characterized in that, When evaluating the candidate responses based on at least one of response fidelity, response relevance, and contextual relevance, the candidate responses are processed based on the pre-trained model corresponding to the candidate responses. The pre-trained model corresponding to the candidate response is determined based on the correspondence between the first text block and the pre-trained model.
14. The text generation method according to claim 13, characterized in that, The method further includes: When evaluating candidate responses based on the response fidelity, the candidate responses are semantically decomposed based on the pre-trained model corresponding to the candidate responses to obtain several reference responses. The consistency between any reference response and the context is checked to determine whether any reference response is a response that matches the user's request question. The proportion of the number of reference responses that match the user's request question to the total number of reference responses is used as the second score corresponding to the response fidelity. When evaluating the candidate responses based on the response relevance, a potential question that matches the candidate response is generated based on the pre-trained model corresponding to the candidate response, and the average similarity between the potential question and the user request question is used as the second score corresponding to the response relevance; When evaluating the candidate responses based on the context relevance, the pre-trained model corresponding to the candidate responses filters out statements related to the user's request question from the user's historical question-and-answer records, and uses the proportion of statements related to the user's request question to the total number of context statements as the second score corresponding to the context relevance.
15. The text generation method according to claim 1, characterized in that, The N text prompts are evenly distributed among the M pre-trained models based on the correspondence between the first text block and the pre-trained model.
16. The text generation method according to claim 1, characterized in that, The text prompt information is generated based on a combination of the target text block, the user's requested question, and the user's corresponding historical question and answer records.
17. A text generation device, characterized in that, include: The acquisition module is configured to acquire N first text blocks that are associated with the user's request question and meet preset conditions. The N first text blocks are determined based on retrieval from multiple dimensions. The allocation and acquisition module is configured to evenly distribute the N first text blocks to M pre-trained models for text rewriting, and acquire N target text blocks, where M and N are both integers greater than or equal to 1; The processing and acquisition module is configured to, after determining the N text prompts corresponding to the N target text blocks, process the N text prompts based on the M pre-trained models to obtain a candidate response set, wherein the text prompts include the target text blocks, the user request question, and the user's corresponding historical question and answer records; The evaluation and selection module is configured to evaluate the candidate responses in the candidate response set based on an evaluation strategy, and select the response information that matches the user's request question.
18. A computer program product comprising a computer program / instructions, characterized in that, When the computer program / instruction is executed by the processor, it implements the text generation method according to any one of claims 1 to 16.
19. An electronic device, characterized in that, It includes 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 as described in any one of claims 1 to 16.
20. A computer-defined non-volatile readable storage medium, characterized in that, The computer program is stored on the non-volatile readable storage medium, and when the computer program is executed by a processor, it implements the text generation method as described in any one of claims 1 to 16.
Citation Information
Patent Citations
Response text generation method, electronic equipment and storage medium
CN117033613A
Information processing method and device based on large language model, equipment and storage medium
CN117521675A
Prompt text generation method and device, electronic equipment and storage medium
CN117689027A
Text generation method and device, computer program product, electronic equipment and medium
CN118396123A
Online question answering, using reading comprehension with an ensemble of models
US20230023958A1