[go: up one dir, main page]

WO2026001792A1 - Text generation method and apparatus, computer program product, electronic device and medium - Google Patents

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

Info

Publication number
WO2026001792A1
WO2026001792A1 PCT/CN2025/101827 CN2025101827W WO2026001792A1 WO 2026001792 A1 WO2026001792 A1 WO 2026001792A1 CN 2025101827 W CN2025101827 W CN 2025101827W WO 2026001792 A1 WO2026001792 A1 WO 2026001792A1
Authority
WO
WIPO (PCT)
Prior art keywords
text
target
blocks
user
question
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
PCT/CN2025/101827
Other languages
French (fr)
Chinese (zh)
Inventor
刘红丽
吴韶华
王超
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Suzhou Metabrain Intelligent Technology Co Ltd
Original Assignee
Suzhou Metabrain Intelligent Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Suzhou Metabrain Intelligent Technology Co Ltd filed Critical Suzhou Metabrain Intelligent Technology Co Ltd
Publication of WO2026001792A1 publication Critical patent/WO2026001792A1/en
Pending legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N5/00Computing arrangements using knowledge-based models
    • G06N5/04Inference or reasoning models
    • G06N5/041Abduction
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/30Information retrieval; Database structures therefor; File system structures therefor of unstructured textual data
    • G06F16/33Querying
    • G06F16/332Query formulation
    • G06F16/3329Natural language query formulation
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/08Learning methods
    • G06N3/092Reinforcement learning
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Mathematical Physics (AREA)
  • Artificial Intelligence (AREA)
  • Computational Linguistics (AREA)
  • Data Mining & Analysis (AREA)
  • General Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • Computing Systems (AREA)
  • Software Systems (AREA)
  • Evolutionary Computation (AREA)
  • Biomedical Technology (AREA)
  • Molecular Biology (AREA)
  • General Health & Medical Sciences (AREA)
  • Biophysics (AREA)
  • Life Sciences & Earth Sciences (AREA)
  • Health & Medical Sciences (AREA)
  • Human Computer Interaction (AREA)
  • Databases & Information Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

Provided in the present application are a text generation method and apparatus, a computer program product, an electronic device and a medium. The method comprises: acquiring N first text blocks that are associated with a user request question, satisfy a preset condition and are determined on the basis of retrieval across multiple dimensions; evenly distributing the N first text blocks to M pre-trained models for text rewriting, so as to obtain N target text blocks; after N pieces of text prompt information corresponding to the N target text blocks are determined, processing the N pieces of text prompt information on the basis of the M pre-trained models, so as to obtain a candidate response set, the text prompt information comprising the target text blocks, the user request question and a historical question-answer record; and, on the basis of an evaluation strategy, evaluating candidate responses in the candidate response set, so as to select response information matching the user request question. The present application can improve the retrieval accuracy, provide semantically coherent and natural text content, and provide response information matching user request questions, thus ensuring the quality of intelligent responses.

Description

文本生成方法、装置、计算机程序产品、电子设备及介质Text generation methods, apparatus, computer program products, electronic devices and media

相关申请的交叉引用Cross-reference to related applications

本申请要求于2024年6月26日提交中国专利局,申请号为202410833500.7,申请名称为“文本生成方法、装置、计算机程序产品、电子设备及介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims priority to Chinese Patent Application No. 202410833500.7, filed on June 26, 2024, entitled “Text Generation Method, Apparatus, Computer Program Product, Electronic Device and Medium”, the entire contents of which are incorporated herein by reference.

技术领域Technical Field

本申请涉及人工智能技术领域,尤其涉及一种文本生成方法、装置、计算机程序产品、电子设备及介质。This application relates to the field of artificial intelligence technology, and in particular to a text generation method, apparatus, computer program product, electronic device and medium.

背景技术Background Technology

近年来,ChatGPT(Chat Generative Pre-trained Transformer,聊天生成预训练转换模型)等大型基础模型(例如LLM(Large Language Model,大语言模型))在文本生成、文本到图像生成等任务中表现出令人印象深刻的性能。然而,大语言模型存在固有的局限性,包括产生幻觉的倾向、答案缺乏可解释性等。为了充分利用大语言模型强大的总结能力,通过检索外部相关信息的方式来增强大语言模型的生成结果是当前解决上述问题的一种常用手段,即利用RAG(Retrieval-Augmented Generation,检索增强生成)技术提供更有依据、更依赖事实的信息。In recent years, large-scale foundational models such as ChatGPT (Chat Generative Pre-trained Transformer) (e.g., LLM (Large Language Model)) have demonstrated impressive performance in tasks such as text generation and text-to-image generation. However, large language models have inherent limitations, including a tendency to generate illusions and a lack of interpretability in their responses. To fully leverage the powerful summarizing capabilities of large language models, enhancing their generated results by retrieving relevant external information is a common approach to addressing these issues. This is achieved through RAG (Retrieval-Augmented Generation) techniques, which provide more evidence-based and fact-dependent information.

在基于RAG技术提供信息增强大语言模型的生成结果时,存在以下缺陷:1、检索低精度,即,检索集中的文档块并不都与查询内容相关,这可能导致信息错误或不连贯。其次是召回率低,即,未能检索到所有相关的文档块,使得大语言模型无法获取足够的背景信息来合成答案。2、多个检索到的文段包含相似信息时,冗余和重复成为问题,这可能导致生成内容的重复。一次向大语言模型提交所有相关文件可能会超出上下文窗口限制。将大量文档连接起来形成冗长的检索提示是无效的,会引入噪音并阻碍大语言模型对关键信息的关注。3、检索到的内容与查询内容可能具有不同的写作风格或语调,导致生成的语言结构变得不那么连贯或自然。The following drawbacks exist when using RAG technology to generate results for information-enhanced large language models: 1. Low retrieval precision: Not all document blocks in the retrieval set are relevant to the query content, potentially leading to erroneous or incoherent information. Secondly, low recall: Failure to retrieve all relevant document blocks prevents the large language model from acquiring sufficient background information to synthesize the answer. 2. Redundancy and repetition become problems when multiple retrieved texts contain similar information, potentially resulting in duplicate generated content. Submitting all relevant documents to the large language model at once may exceed the context window limit. Connecting a large number of documents to form lengthy search suggestions is ineffective, introducing noise and hindering the large language model's focus on key information. 3. The retrieved content may have a different writing style or tone than the query content, resulting in a less coherent or natural generated language structure.

由此可见,在RAG系统中,引入外部知识虽然可以丰富和具体化生成的文本内容,但同时也存在检索精度低、信息冗余、生成的语言结构不连贯或不自然等缺陷。It is evident that while introducing external knowledge into the RAG system can enrich and concretize the generated text content, it also presents drawbacks such as low retrieval accuracy, information redundancy, and inconsistent or unnatural generated language structures.

发明内容Summary of the Invention

鉴于上述问题,本申请实施例提供一种克服上述问题或者至少部分地解决上述问题的文本生成方法、装置、计算机程序产品、电子设备及介质。In view of the above problems, embodiments of this application provide a text generation method, apparatus, computer program product, electronic device and medium that overcomes or at least partially solves the above problems.

第一方面,本申请实施例提供一种文本生成方法,包括:In a first aspect, embodiments of this application provide a text generation method, including:

获取与用户请求问题关联且满足预设条件的N个第一文本块,N个第一文本块基于多个维度的检索确定;Obtain N first text blocks that are related to the user's request and meet preset conditions. The N first text blocks are determined based on retrieval from multiple dimensions.

将N个第一文本块均衡地分配至M个预训练模型进行文本改写,获取N个目标文本块,M、N均为大于或者等于1的整数;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;

在确定N个目标文本块对应的N个文本提示信息后,基于M个预训练模型对N个文本提示信息进行处理获取候选回复集合,文本提示信息包括目标文本块、用户请求问题和用户对应的历史问答记录;After determining the N text prompts corresponding to the N target text blocks, the N text prompts are processed based on M pre-trained models to obtain a candidate response set. The text prompts include the target text blocks, the user's 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 is selected.

在本申请的一些实施例中,获取与用户请求问题关联且满足预设条件的N个第一文本块,包括:In some embodiments of this application, obtaining N first text blocks that are associated with a user request and meet preset conditions includes:

在多个维度检索与用户请求问题的关联度符合语义相关要求的文本信息,获取包括K个第二文本块的候选文本块集合;Retrieve text information that meets the semantic relevance requirements of the user's request question across multiple dimensions, and obtain a candidate text block set including K second text blocks;

对候选文本块集合进行文本块去重、排序处理,获取N个第一文本块。Perform text block deduplication and sorting on the candidate text block set to obtain N first text blocks.

在本申请的一些实施例中,在多个维度检索与用户请求问题的关联度符合语义相关要求的文本信息,获取包括K个第二文本块的候选文本块集合,包括:In some embodiments of this application, text information whose relevance to the user's request question meets semantic relevance requirements is retrieved across multiple dimensions to obtain a candidate text block set including K second text blocks, including:

基于用户请求问题和用户对应的历史问答记录,获取关键词列表和对用户请求问题改写后的目标请求问题,关键词列表和目标请求问题基于对应的模型服务获取;Based on the user's request question and the user's corresponding historical Q&A records, obtain a keyword list and a target request question that is rewritten from the user's request question. The keyword list and the target request question are obtained based on the corresponding model service.

根据用户请求问题、目标请求问题和关键词列表在多个维度进行文本信息检索,获取K个第二文本块。Based on the user's request question, the target request question, and the keyword list, text information is retrieved from multiple dimensions to obtain K second text blocks.

在本申请的一些实施例中,根据用户请求问题、目标请求问题和关键词列表在多个维度进行文本信息检索,获取K个第二文本块,包括:In some embodiments of this application, text information retrieval is performed across multiple dimensions based on the user request question, the target request question, and a keyword list to obtain K second text blocks, including:

将用户请求问题、目标请求问题和关键词列表分别输入目标编码模型,获取多个文本向量;Input the user request question, the target request question, and the keyword list into the target encoding model to obtain multiple text vectors;

在目标数据库中分别检索与各文本向量的语义关联度符合语义相关要求的文本块,以确定K个第二文本块;In the target database, text blocks whose semantic relevance to each text vector meets the semantic relevance requirement are retrieved to determine K second text blocks;

其中,目标数据库中存储向量索引以及对应的文本块。The target database stores vector indexes and their corresponding text blocks.

在本申请的一些实施例中,方法还包括:In some embodiments of this application, the method further includes:

构建包括多个文本数据的微调数据集,文本数据包括问题信息和回复信息,且文本数据为目标领域的数据;Construct a fine-tuned dataset consisting of multiple text data, including question and response information, and the text data is data from the target domain;

基于微调数据集调整初始编码模型,确定目标编码模型;Adjust the initial coding model based on the fine-tuning dataset, and determine the target coding model;

根据所确定的文本块大小,对待输入文档进行分块处理,待输入文档基于在目标领域所收集的信息生成;Based on the determined text block size, the input document is divided into blocks, 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.

在本申请的一些实施例中,方法还包括:In some embodiments of this application, the method further includes:

基于初始编码模型所支持的最大词语数,确定块调整范围;The block adjustment range is determined based on the maximum number of words supported by the initial coding model;

根据所构建的多条测试数据集,在块调整范围中确定文本块大小。Based on the constructed multiple test datasets, determine the text block size within the block adjustment range.

在本申请的一些实施例中,对候选文本块集合进行文本块去重、排序处理,获取N个第一文本块,包括:In some embodiments of this application, the candidate text block set is deduplicated and sorted to obtain N first text blocks, including:

遍历计算候选文本块集合中的两两第二文本块之间的相似度;Iterate through the candidate text block set and calculate the similarity between each pair of second text blocks;

根据相似度计算结果,确定目标文本块组,其中,任意两个第二文本块构成一文本块组,两个第二文本块的相似度大于预设阈值的文本块组为目标文本块组;Based on the similarity calculation results, target text block groups are determined. Any two second text blocks constitute a text block group, and text block groups in which the similarity between two second text blocks is greater than a preset threshold are target text block groups.

在目标文本块组中确定与用户请求问题的关联度低的第二文本块,将所确定的第二文本块删除,以进行第二文本块去重;In the target text block group, identify the 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 second-level text block deduplication on the target text block group, obtain the target text block set;

对目标文本块集合中的第二文本块进行特征信息提取,并基于所提取的特征信息对第二文本块进行分数评估获取第二文本块对应的第一评分;Feature information is extracted from the second text block in the target text block set, and the second text block is scored based on the extracted feature information to obtain the first score corresponding to the second text block;

基于第二文本块对应的第一评分,在目标文本块集合中确定N个第一文本块。Based on the first score corresponding to the second text block, N first text blocks are determined in the target text block set.

在本申请的一些实施例中,基于第二文本块对应的第一评分,在目标文本块集合中确定N个第一文本块,包括:In some embodiments of this application, based on the first score corresponding to the second text block, N first text blocks are determined in the target text block set, including:

基于第二文本块对应的第一评分,对目标文本块集合中的第二文本块进行排序,确定排序结果,其中,第二文本块的排列次序与第二文本块对应的关联度正相关;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. The sorting order of the second text blocks is positively correlated with the relevance of the second text blocks.

基于排序结果,确定目标文本块集合中第一评分靠前的N个第二文本块,将N个第二文本块确定为N个第一文本块。Based on the sorting results, the N second text blocks with the highest first score in the target text block set are determined, and these N second text blocks are designated as N first text blocks.

在本申请的一些实施例中,对目标文本块集合中的第二文本块进行特征信息提取,并基于所提取的特征信息对第二文本块进行分数评估获取第二文本块对应的第一评分,包括:In some embodiments of this application, feature information is extracted from a second text block in a set of target text blocks, and a score is evaluated on the second text block based on the extracted feature information to obtain a first score corresponding to the second text block, including:

对第二文本块进行特征信息提取,获取第二文本块与用户请求问题的第一语义相似度、第二文本块与用户请求问题的前文的第二语义相似度以及文本质量中的至少一项;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's request question, the second semantic similarity between the second text block and the preceding text of the user's request question, and text quality.

基于第一语义相似度、第二语义相似度和文本质量中的至少一项进行分数评估,获取第二文本块对应的第一评分。The first score corresponding to the second text block is obtained by evaluating the score based on at least one of the first semantic similarity, the second semantic similarity, and the text quality.

在本申请的一些实施例中,将N个第一文本块均衡地分配至M个预训练模型进行文本改写,获取N个目标文本块,包括:In some embodiments of this application, N first text blocks are evenly distributed to M pre-trained models for text rewriting to obtain N target text blocks, including:

按照均衡分配原则,将N个第一文本块分为M份,确定每份第一文本块对应的预训练模型;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.

基于第一文本块与预训练模型的对应关系,将M份第一文本块并发输入对应的预训练模型进行文本改写,获取N个文本改写后的目标文本块。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.

在本申请的一些实施例中,基于M个预训练模型对N个文本提示信息进行处理获取候选回复集合,包括:In some embodiments of this application, a candidate response set is obtained by processing N text prompts based on M pre-trained models, including:

在基于N个目标文本块、用户请求问题和用户对应的历史问答记录生成N个文本提示信息之后,基于第一文本块与预训练模型的对应关系,将N个文本提示信息并发输入对应的预训练模型,获取候选回复集合;After generating N text prompts based on N target text blocks, user request questions, and the user's corresponding historical question and answer records, the N text prompts are concurrently input into the corresponding pre-trained models based on the correspondence between the first text block and the pre-trained model to obtain a candidate response set.

其中,每个文本提示信息对应至少一个候选回复。Each text prompt corresponds to at least one candidate response.

在本申请的一些实施例中,基于评估策略对候选回复集合中的候选回复进行评估,选择与用户请求问题匹配的回复信息,包括:In some embodiments of this application, candidate responses in the candidate response set are evaluated based on an evaluation strategy, and response information that matches the user's request is selected, including:

对候选回复进行回复忠实度、回复相关性和上下文相关性中的至少一项评估,获取至少一个第二评分;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 at least one second score, determine the target score corresponding to the candidate response;

基于目标评分在候选回复集合对应的候选回复中选择与用户请求问题匹配的回复信息。Based on the target score, select the response information that matches the user's requested question from the candidate responses in the candidate response set.

在本申请的一些实施例中,在对候选回复进行回复忠实度、回复相关性和上下文相关性中的至少一项进行评估时,基于候选回复对应的预训练模型对候选回复进行处理;In some embodiments of this application, when evaluating 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.

第二方面,本申请实施例提供一种文本生成装置,包括:Secondly, embodiments of this application provide a text generation apparatus, including:

获取模块,用于获取与用户请求问题关联且满足预设条件的N个第一文本块,N个第一文本块基于多个维度的检索确定;The acquisition module is used to acquire N first text blocks that are associated with the user's request and meet preset conditions. The N first text blocks are determined based on retrieval from multiple dimensions.

分配获取模块,用于将N个第一文本块均衡地分配至M个预训练模型进行文本改写,获取N个目标文本块,M、N均为大于或者等于1的整数;The allocation and acquisition module is used to evenly distribute N first text blocks to M pre-trained models for text rewriting and to acquire N target text blocks, where M and N are both integers greater than or equal to 1;

处理获取模块,用于在确定N个目标文本块对应的N个文本提示信息后,基于M个预训练模型对N个文本提示信息进行处理获取候选回复集合,文本提示信息包括目标文本块、用户请求问题和用户对应的历史问答记录;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.

评估选择模块,应用于基于评估策略对候选回复集合中的候选回复进行评估,选择与用户请求问题匹配的回复信息。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.

第三方面,本申请实施例提供一种计算机程序产品,包括计算机程序/指令,该计算机程序/指令被处理器执行时实现第一方面的文本生成方法。Thirdly, embodiments of this application provide a computer program product, including a computer program/instructions, which, when executed by a processor, implement the text generation method of the first aspect.

第四方面,本申请实施例提供一种电子设备,包括处理器、存储器及存储在存储器上并能够在处理器上运行的计算机程序,该计算机程序被处理器执行时实现第一方面的文本生成方法。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.

第五方面,本申请实施例提供一种计算机非易失性可读存储介质,计算机非易失性可读存储介质上存储计算机程序,计算机程序被处理器执行时实现第一方面的文本生成方法。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.

本申请实施例提供的技术方案至少带来以下有益效果:The technical solution provided in this application has at least the following beneficial effects:

基于多个维度的检索获取与用户请求问题相关的N个第一文本块,实现相对全面的收集与用户请求问题相关的内容,提升检索精度;在确定N个第一文本块之后将N个第一文本块均衡地分配至M个预训练模型进行文本改写,获取N个目标文本块,可以基于预训练模型输出与预训练模型风格适配、语义连贯且自然的文本内容,以便于后续可以提升文本回复的质量;在确定文本提示信息后,基于预训练模型与第一文本块的对应关系,将N个文本提示信息分配给M个预训练模型进行处理获取候选回复集合,采用评估策略对候选回复集合中的各个候选回复进行评估,可以利用适配的预训练模型输出候选回复,对候选回复进行评估选择出与用户请求问题最适配的候选回复,以提供与用户请求问题匹配的回复信息,可以提升回复精度、保证智能回复的质量。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

图1为本申请实施例提供的文本生成方法示意图;Figure 1 is a schematic diagram of the text generation method provided in an embodiment of this application;

图2为本申请实施例提供的确定3个待检索请求的示意图;Figure 2 is a schematic diagram illustrating the determination of three search requests according to an embodiment of this application;

图3为本申请实施例提供的构建与法律相关的目标数据库的流程图;Figure 3 is a flowchart of constructing a target database related to law provided in an embodiment of this application;

图4为本申请实施例提供的基于3个待检索请求确定N个第一文本块的流程图;Figure 4 is a flowchart of determining N first text blocks based on 3 retrieval requests provided in an embodiment of this application;

图5为本申请实施例提供的改写文本、确定候选回复集合的流程图;Figure 5 is a flowchart of rewriting text and determining a set of candidate responses provided in an embodiment of this application;

图6为本申请实施例提供的文本生成方法的整体实施过程示意图;Figure 6 is a schematic diagram of the overall implementation process of the text generation method provided in the embodiments of this application;

图7为本申请实施例提供的文本生成装置示意图。Figure 7 is a schematic diagram of the text generation device provided in an embodiment of this application.

具体实施方式Detailed Implementation

为使本申请实施例的目的、技术方案和优点更加清楚,下面将结合附图对本申请的各实施方式进行详细的阐述。然而,本领域的普通技术人员可以理解,在本申请各实施方式中,为了使读者更好地理解本申请而提出了许多技术细节。但是,即使没有这些技术细节和基于以下各实施方式的种种变化和修改,也可以实现本申请所要求保护的技术方案。以下各个实施例的划分是为了描述方便,不应对本申请的具体实现方式构成任何限定,各个实施例在不矛盾的前提下可以相互结合相互引用。To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the various embodiments of this application will be described in detail below with reference to the accompanying drawings. However, those skilled in the art will understand that many technical details have been presented in the various embodiments of this application to enable readers to better understand this application. However, even without these technical details and various changes and modifications based on the following embodiments, the technical solutions claimed in this application can be implemented. The division of the various embodiments below is for the convenience of description and should not constitute any limitation on the specific implementation of this application. The various embodiments can be combined with and referenced by each other without contradiction.

目前,在利用大语言模型进行智能回复时,通过引入RAG技术可以提供更有依据、更依赖事实的信息,但同时存在检索精度低、信息冗余、生成的语言结构不连贯或不自然等缺陷。为了减少引入RAG技术所带来的问题,本申请实施例提供一种文本生成方法,在诸如法律、医疗、旅游等需要问答的领域为智能回复提供有力支撑。Currently, when using large language models for intelligent responses, introducing RAG technology can provide more evidence-based and fact-dependent information. However, it also suffers from drawbacks such as low retrieval accuracy, information redundancy, and incoherent or unnatural generated language structures. To mitigate the problems associated with introducing RAG technology, this application provides a text generation method that offers strong support for intelligent responses in fields requiring question-and-answer interaction, such as law, medicine, and tourism.

如图1所示,本申请实施例提供的文本生成方法,包括:As shown in Figure 1, the text generation method provided in this application includes:

步骤101、获取与用户请求问题关联且满足预设条件的N个第一文本块,N个第一文本块基于多个维度的检索确定。Step 101: Obtain N first text blocks that are associated with the user's request and meet preset conditions. The N first text blocks are determined based on retrieval from multiple dimensions.

本申请实施例提供的文本生成方法应用于服务器,在智能问答场景下,用户在客户端提出问题,服务器接收客户端发送的用户请求问题,基于用户请求问题在多个维度进行检索确定与用户请求问题关联的文本内容,并对所检索到的文本内容进行处理确定N个第一文本块。N的取值大于或者等于1,以通过多维度检索、对检索结果进行处理确定与用户请求问题关联的至少一个第一文本块。且通过在多个维度检索与用户请求问题相关的内容,可以相对全面的收集与用户请求问题相关的内容,提升检索精度。The text generation method provided in this application is applied to a server. In an intelligent question-answering scenario, a user asks a question on the client side. The server receives the user's request question from the client, performs a multi-dimensional search to determine the text content associated with the user's 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 as to determine at least one first text block associated with the user's request question through multi-dimensional search and processing of the search results. Furthermore, by searching for content related to the user's request question in multiple dimensions, relatively comprehensive collection of content related to the user's request question can be achieved, improving search accuracy.

其中,客户端为支持智能问答的应用,服务器所获取的用户请求问题可以为某个特定领域的相关提问,如,用户请求问题为法律、医疗或者旅游领域的相关问题。作为本申请的一个实施例,在智能问答场景下,用户在客户端提出法律方面的相关问题,客户端将用户请求问题发送至服务器,服务器基于接收到的用户请求问题在多个维度进行相关内容检索,确定一个或者多个第一文本块。In this application, the client is an application that supports intelligent question answering. The user request question obtained by the server can be a question related to a specific field, such as a legal, medical, or travel-related question. As an embodiment of this application, in an intelligent question answering scenario, a user asks a legal-related question on the client. The client sends the user request question to the server. The server performs relevant content retrieval based on the received user request question across multiple dimensions to determine one or more first text blocks.

步骤102、将N个第一文本块均衡地分配至M个预训练模型进行文本改写,获取N个目标文本块。Step 102: Distribute the N first text blocks evenly to the M pre-trained models for text rewriting to obtain N target text blocks.

服务器在获取与用户请求问题相关的N个第一文本块之后,将N个第一文本块均衡地分配至服务器上部署的M个预训练模型,以通过预训练模型对第一文本块进行文本改写。通过预训练模型对第一文本块进行文本改写,可以输出与预训练模型风格适配、语义连贯且自然的文本内容,进而获取经过文本风格改写的N个目标文本块。After obtaining N first text blocks related to the user's request, the server evenly distributes these N first text blocks to M pre-trained models deployed on the server. These pre-trained models then rewrite the first text blocks. By rewriting the first text blocks using the pre-trained models, the server outputs text content that matches the style of the pre-trained models, is semantically coherent, and natural, thus obtaining N target text blocks that have undergone style rewriting.

N的取值大于或者等于1,相应的,M的取值大于或者等于1。在N和M的取值相同时,可以直接采用一一对应的方式将第一文本块分配至预训练模型;在N的取值大于M时,将N个第一文本块相对均衡地分配给M个预训练模型;在N的取值小于M时,将N个第一文本块均衡地分配至M个预训练模型中的部分模型。作为本申请的一个实施例,服务器在不同GPU(Graphics Processing Unit,图形处理器)上部署预训练模型A、预训练模型B、预训练模型C、预训练模型D,将8个第一文本块均衡地分配至上述4个预训练模型。The value of N is greater than or equal to 1, and correspondingly, the value of M is greater than or equal to 1. When the values of N and M are the same, the first text block can be directly assigned to the pre-trained model in a one-to-one correspondence manner; when the value of N is greater than M, the N first text blocks are relatively evenly distributed among the M pre-trained models; when the value of N is less than M, the N first text blocks are evenly distributed among some of the M pre-trained models. As an embodiment of this application, the server deploys pre-trained models A, B, C, and D on different GPUs (Graphics Processing Units), and evenly distributes the 8 first text blocks among the above 4 pre-trained models.

通过将第一文本块输入预训练模型进行文本改写,可以基于预训练模型输出适配风格的文本内容,以对第一文本块进行转换,提供语义连贯、自然的文本内容,以提升针对用户请求问题所生成的回复信息的语义连贯度。By inputting the first text block into a pre-trained model for text rewriting, the model can output text content with an adapted style to transform the first text block, providing semantically coherent and natural text content, thereby improving the semantic coherence of the response information generated in response to user requests.

步骤103、在确定N个目标文本块对应的N个文本提示信息后,基于M个预训练模型对N个文本提示信息进行处理获取候选回复集合,文本提示信息包括目标文本块、用户请求问题和用户对应的历史问答记录。Step 103: After determining the N text prompts corresponding to the N target text blocks, process the N text prompts based on M pre-trained models to obtain a candidate response set. The text prompts include the target text blocks, the user's request question, and the user's corresponding historical question and answer records.

在基于预训练模型的文本风格对第一文本块进行改写获取N个目标文本块之后,针对每个目标文本块,生成对应的文本提示信息,目标文本块对应的文本提示信息包括目标文本块、用户请求问题和用户对应的历史问答记录。然后基于目标文本块与预训练模型的对应关系,将N个文本提示信息分配至M个预训练模型,由M个预训练模型对N个文本提示信息进行处理,确定候选回复集合。After rewriting the first text block based on the text style of the pre-trained model to obtain N target text blocks, corresponding text prompts are generated for each target text block. These prompts include the target text block itself, the user's request question, and the user's corresponding historical question-and-answer records. Then, based on the correspondence between the target text blocks and the pre-trained models, the N text prompts are assigned to M pre-trained models. These M models then process the N text prompts to determine the candidate response set.

其中,文本提示信息可基于目标文本块、用户请求问题和用户对应的历史问答记录的组合生成。N个文本提示信息按照之前的分配策略提供给对应的预训练模型,以基于预训练模型对文本提示信息处理、输出与文本提示信息适配的候选回复,基于M个预训练模型分别提供的候选回复生成候选回复集合。The text prompts can be generated based on a combination of the target text block, the user's request question, and the user's corresponding historical question-and-answer records. N text prompts are provided to the corresponding pre-trained models according to the previous allocation strategy. The pre-trained models then process the text prompts and output candidate responses that match the prompts. A candidate response set is generated based on the candidate responses provided by the M pre-trained models.

步骤104、基于评估策略对候选回复集合中的候选回复进行评估,选择与用户请求问题匹配的回复信息。Step 104: Evaluate the candidate responses in the candidate response set based on the evaluation strategy, and select the response information that matches the user's request.

在基于预训练模型的处理获取候选回复集合之后,采用评估策略对候选回复集合中的各个候选回复进行评估,以通过候选回复的评估,选择出与用户请求问题最适配的候选回复,将选择出的候选回复作为与用户请求问题匹配的回复信息。After obtaining the candidate response set based on the pre-trained model, an evaluation strategy is used to evaluate each candidate response in the candidate response set. Through the evaluation of the candidate responses, the candidate response that best matches the user's request is selected, and the selected candidate response is used as the response information that matches the user's request.

在采用评估策略对候选回复集合中的各个候选回复进行评估时,可以基于一个或者多个评估指标对候选回复进行评估,针对采用多个评估指标进行评估的情况,设置每个评估指标对应的权重,然后基于权重以及评估指标对应的分数确定最终的评估结果。When evaluating each candidate response in the candidate response set using an evaluation strategy, the candidate responses can be evaluated based on one or more evaluation indicators. For the case of using multiple evaluation indicators, a weight is set for each evaluation indicator, and then the final evaluation result is determined based on the weight and the score corresponding to the evaluation indicator.

本申请上述实施方案,基于多个维度的检索获取与用户请求问题相关的N个第一文本块,实现相对全面的收集与用户请求问题相关的内容,提升检索精度;在确定N个第一文本块之后将N个第一文本块均衡地分配至M个预训练模型进行文本改写,获取N个目标文本块,可以基于预训练模型输出与预训练模型风格适配、语义连贯且自然的文本内容,以便于后续可以提升文本回复的质量;在确定文本提示信息后,基于预训练模型与第一文本块的对应关系,将N个文本提示信息分配给M个预训练模型进行处理获取候选回复集合,采用评估策略对候选回复集合中的各个候选回复进行评估,可以利用适配的预训练模型输出候选回复,对候选回复进行评估选择出与用户请求问题最适配的候选回复,以提供与用户请求问题匹配的回复信息,可以提升回复精度、保证智能回复的质量。The above-described implementation scheme of this application retrieves N first text blocks related to the user's request question based on multi-dimensional retrieval, achieving a relatively comprehensive collection of content related to the user's request question and improving retrieval accuracy. After determining the N first text blocks, the N first text blocks are evenly distributed to M pre-trained models for text rewriting to obtain N target text blocks. The output of text content that is adapted to the style of the pre-trained models, semantically coherent, and natural can be based on the pre-trained models, so as to improve the quality of subsequent text responses. After determining the text prompt information, based on the correspondence between the pre-trained models and the first text blocks, the N text prompt information is 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 adapted pre-trained models, and the candidate responses are evaluated to select the candidate responses that best match the user's request question, so as to provide response information that matches the user's request question, thereby improving response accuracy and ensuring the quality of intelligent responses.

下面对基于多个维度的检索获取与用户请求问题相关的N第一个文本块的具体过程进行介绍。作为本申请一可选实施例,在获取与用户请求问题关联且满足预设条件的N个第一文本块时,包括:The following describes the specific process of retrieving N first text blocks related to a user's request question based on multiple dimensions. As an optional embodiment of this application, retrieving N first text blocks that are associated with the user's request question and meet preset conditions includes:

在多个维度检索与用户请求问题的关联度符合语义相关要求的文本信息,获取包括K个第二文本块的候选文本块集合;Retrieve text information that meets the semantic relevance requirements of the user's request question across multiple dimensions, and obtain a candidate text block set including K second text blocks;

对候选文本块集合进行文本块去重、排序处理,获取N个第一文本块。Perform text block deduplication and sorting on the candidate text block set to obtain N first text blocks.

在获取用户请求问题之后,在多个维度检索与用户请求问题的关联度符合语义相关要求的文本信息,所检索到的文本信息可以是与用户请求问题的关联度大于预先设置的第一阈值的文本信息,或者,所检索到的文本信息可以是与用户请求问题的关联度排序靠前的预设数目个文本信息,其中,排序越靠前、关联度越高。在检索时,在预先生成的存储文本信息的数据库中进行检索。After obtaining the user's request question, text information that meets the semantic relevance requirement of the user's request question is retrieved across multiple dimensions. The retrieved text information can be text information whose relevance to the user's request question is greater than a pre-set first threshold, or it can be a preset number of text information items ranked high in relevance to the user's request question, where higher ranking indicates higher relevance. During the retrieval, the search is performed in a pre-generated database storing text information.

在通过多维度检索获取包括与用户请求问题相关的K个第二文本块的候选文本块集合之后,对候选文本块集合中的第二文本块进行去重处理,以通过文本块滤除对候选文本块集合中的内容进行精简,避免获取冗余信息、保留必要的文本内容。在通过去重处理对候选文本块集合中的第二文本块进行过滤之后,对候选文本块集合中的剩余第二文本块进行排序,通过排序确定候选文本块集合中满足设定条件的第二文本块,进而获取与用户请求问题相关的N个第一文本块。After obtaining a candidate text block set containing K second text blocks related to the user's request question through multi-dimensional retrieval, the second text blocks in the candidate text block set are deduplicated to streamline the content of the candidate text block set by filtering out redundant information and retaining only necessary text content. After filtering the second text blocks in the candidate text block set through deduplication, the remaining second text blocks in the candidate text block set are sorted. The sorting determines the second text blocks in the candidate text block set that meet the set conditions, thereby obtaining N first text blocks related to the user's request question.

上述实施过程,通过多维度的检索获取候选文本块集合,可以获取与用户请求问题相关的、相对全面的文本信息;在通过检索确定候选文本块集合之后,对候选文本块集合中的内容进行去重、排序处理,可以在精简内容、避免信息冗余的同时,提供与用户请求问题关联度高的文本块。The above implementation process obtains a set of candidate text blocks through multi-dimensional retrieval, which can acquire relatively comprehensive text information related to the user's request. After determining the set of candidate text blocks through retrieval, the content in the set of candidate text blocks is deduplicated and sorted, which can provide text blocks that are highly relevant to the user's request while simplifying the content and avoiding information redundancy.

在本申请的一些实施例中,在多个维度检索与用户请求问题的关联度符合语义相关要求的文本信息,获取包括K个第二文本块的候选文本块集合时,包括:In some embodiments of this application, when retrieving text information that meets the semantic relevance requirements to the user's request question across multiple dimensions to obtain a candidate text block set including K second text blocks, the process includes:

基于用户请求问题和用户对应的历史问答记录,获取关键词列表和对用户请求问题改写后的目标请求问题,关键词列表和目标请求问题基于对应的模型服务获取;Based on the user's request question and the user's corresponding historical Q&A records, obtain a keyword list and a target request question that is rewritten from the user's request question. The keyword list and the target request question are obtained based on the corresponding model service.

根据用户请求问题、目标请求问题和关键词列表在多个维度进行文本信息检索,获取K个第二文本块。Based on the user's request question, the target request question, and the keyword list, text information is retrieved from multiple dimensions to obtain K second text blocks.

在智能问答场景下用户与预训练模型进行多轮对话,可能会出现用户请求问题的表述不完整的情况,由于预训练模型在对话式稠密检索中表现出了出色的请求改写能力,因此可以对当前用户请求问题进行改写,以提供表述完整且符合要求的请求。对用户请求问题的改写可以理解为对用户请求问题的扩充,以通过内容扩充使得初始问题变得完整和清晰。In intelligent question-answering scenarios, users engage in multi-turn dialogues with pre-trained models. Sometimes, the user's request may be incomplete. Since pre-trained models demonstrate excellent request rewriting capabilities in conversational dense retrieval, they can rewrite the current user request to provide a complete and compliant response. Rewriting a user request can be understood as expanding upon it, making the initial question more complete and clearer through content enrichment.

预训练模型的请求改写能力基于预训练模型支持的请求改写模型服务实现,预训练模型在支持请求改写模型服务的同时,还支持关键词提取模型服务,且两个模型服务支持并发调用,因此,可以通过调用对应的模型服务对用户请求问题进行改写、获取关键词信息。The request rewriting capability of the pre-trained model is based on the request rewriting model service supported by the pre-trained model. While supporting the request rewriting model service, the pre-trained model also supports the keyword extraction model service, and the two model services support concurrent calls. Therefore, the user's request question can be rewritten and keyword information can be obtained by calling the corresponding model service.

即,在多个维度进行检索时,基于用户请求问题获取当前用户对应的历史问答记录,历史问答记录为智能问答场景下用户基于客户端与服务器部署的预训练模型的历史会话情况。然后调用两个模型服务,将用户请求问题和用户对应的历史问答记录作为输入,基于两个模型服务分别进行请求改写和关键词提取,以获取对用户请求问题改写后的目标请求问题和关键词列表。为了提高效率,可以采用多进程并发的方式调用两个模型服务同时进行请求改写和提取关键词操作。In other words, when performing searches across multiple dimensions, the system retrieves the user's historical question-and-answer records based on the user's request question. These historical records represent the user's past conversations within the intelligent question-and-answer scenario, using pre-trained models deployed on the client and server. Then, two model services are invoked, taking the user's request question and corresponding historical question-and-answer records as input. The two model services then perform request rewriting and keyword extraction respectively, yielding the rewritten target request question and a list of keywords. To improve efficiency, a multi-process concurrent approach can be used to simultaneously invoke the two model services for request rewriting and keyword extraction.

在本申请的一些实施例中,请求改写模型服务和关键词提取模型服务也可合并为一个模型服务,此时,通过一个模型服务实现两个功能;在本申请的一些实施例中,请求改写能力可以基于至少两个模型服务的配合实现,关键词提取能力可以基于至少两个模型服务的配合实现,这里不再过多阐述。In some embodiments of this application, the request rewriting model service and the keyword extraction model service can also be merged into one model service. In this case, two functions are implemented through one model service. In some embodiments of this application, the request rewriting capability can be implemented based on the cooperation of at least two model services, and the keyword extraction capability can be implemented based on the cooperation of at least two model services. This will not be elaborated further here.

需要说明的是,模型服务可以为服务器部署的任意一个预训练模型所支持的服务,也可以为特定的预训练模型所支持的服务。服务器可以采用调用模型服务的方式获取关键词列表、对用户请求问题进行改写,也可以采用其他手段提取关键词、获取改写后的请求。It should be noted that the model service can be a service supported by any pre-trained model deployed on the server, or it can be a service supported by a specific pre-trained model. The server can obtain the keyword list and rewrite the user request by calling the model service, or it can use other methods to extract keywords and obtain the rewritten request.

下面通过本申请的一个实施例对改写请求、提取关键词的过程进行介绍。如,采用如下模版组成输入文本、由对应的模型服务进行请求改写:作为一名法律问答助手,其工作是理解用户的真实意图,请根据上文情景把用户现在的请求问题补充完整。其中,上文情景是:{对话记录},用户现在的请求问题是:{当前问题},基于上述内容对用户请求问题进行改写,使其含义明确,最终请输出一个改写后的不同请求问题,不需要任何其他解释和中间过程。The following is an embodiment of this application illustrating the process of rewriting requests and extracting keywords. For example, the input text is composed of the following template, and the corresponding model service rewrites the request: As a legal Q&A assistant, my job is to understand the user's true intent. Please complete the user's current request question based on the above scenario. Here, the above scenario is: {dialogue record}, and the user's current request question is: {current question}. Based on the above content, the user's request question is rewritten to make its meaning clear. Finally, please output a rewritten request question without any further explanation or intermediate processes.

再如,采用如下模版组成输入文本、由对应的模型服务进行关键词提取:作为一名法律问答助手,其工作是理解用户的真实意图,请根据上下文情景提取关键词。其中,上下文情景是:{对话记录},{当前问题}。请输出最重要的3个关键词,不需要任何其他解释和中间过程。For example, consider the following template for input text, with keyword extraction performed by the corresponding model service: "As a legal question-and-answer assistant, your job is to understand the user's true intent. Please extract keywords based on the context. The context is: {dialogue history}, {current question}. Please output the three most important keywords, without any further explanation or intermediate steps."

在获取关键词列表和对用户请求问题改写后确定的目标请求问题之后,为了保证检索精度,保留用户请求问题作为待检索请求1(Q1表示),将目标请求问题作为待检索请求2(Q2表示),将关键词列表作为待检索请求3(Q3表示)。根据Q1、Q2、Q3在多个维度进行文本信息检索,获取K个第二文本块,以基于混合检索的策略适应不同的查询类型和信息需求,确保一致地检索关联度高和上下文丰富的信息。After obtaining the keyword list and determining the target request question by rewriting the user request question, to ensure retrieval accuracy, the user request question is retained as retrieval request 1 (represented by Q1), the target request question is retained as retrieval request 2 (represented by Q2), and the keyword list is retained as retrieval request 3 (represented by Q3). Based on Q1, Q2, and Q3, text information is retrieved across multiple dimensions to obtain K second text blocks. This is achieved using a hybrid retrieval strategy to adapt to different query types and information needs, ensuring consistent retrieval of highly relevant and context-rich information.

作为本申请的一个实施例,基于用户请求问题和用户对应的历史问答记录确定待检索请求1、待检索请求2、待检索请求3的过程可参见图2。用户请求问题和用户对应的历史问答记录输入模型服务1,获取模型服务1输出的对用户请求问题进行改写后的目标请求问题;用户请求问题和用户对应的历史问答记录输入模型服务2,获取模型服务2输出的关键词列表。将用户请求问题作为待检索请求1、目标请求问题作为待检索请求2、关键词列表作为待检索请求3,实现基于用户请求问题和用户对应的历史问答记录确定3个待检索请求。As an embodiment of this application, the process of determining the three requests to be retrieved—request 1, request 2, and request 3—based on the user's request question and the corresponding historical question-and-answer records is shown in Figure 2. The user's request question and the corresponding historical question-and-answer records are input into model service 1, which outputs a rewritten target request question. The user's request question and the corresponding historical question-and-answer records are input into model service 2, which outputs a keyword list. By using the user's request question as request 1, the target request question as request 2, and the keyword list as request 3, three requests to be retrieved are determined based on the user's request question and the corresponding historical question-and-answer records.

上述实施过程,通过对用户请求问题进行改写、基于对话记录和当前用户请求问题提取关键词,可以获取完整清晰的改写后目标请求问题、提取出关键信息点,且通过采用多进程并发的方式调用两个模型服务同时进行请求改写和提取关键词操作,可以提升处理效率;基于用户请求问题、目标请求问题和提取的关键词在多个维度进行文本信息检索,可以通过混合检索适应不同的查询类型和信息需求。The above implementation process, by rewriting the user request question and extracting keywords based on the dialogue record and the current user request question, can obtain a complete and clear rewritten target request question and extract key information points. Furthermore, by using a multi-process concurrent approach to call two model services to perform request rewriting and keyword extraction operations simultaneously, processing efficiency can be improved. Based on the user request question, the target request question, and the extracted keywords, text information retrieval can be performed in multiple dimensions, and mixed retrieval can adapt to different query types and information needs.

在本申请的一些实施例中,根据用户请求问题、目标请求问题和关键词列表在多个维度进行文本信息检索,获取K个第二文本块时,包括:In some embodiments of this application, when retrieving K second text blocks by performing text information retrieval across multiple dimensions based on the user request question, the target request question, and a keyword list, the process includes:

将用户请求问题、目标请求问题和关键词列表分别输入目标编码模型,获取多个文本向量;Input the user request question, the target request question, and the keyword list into the target encoding model to obtain multiple text vectors;

在目标数据库中分别检索与各文本向量的语义关联度符合语义相关要求的文本块,以确定K个第二文本块,目标数据库中存储向量索引以及对应的文本块。In the target database, text blocks that meet the semantic relevance requirements with each text vector are retrieved to determine K second text blocks. The target database stores the vector index and the corresponding text block.

在确定目标请求问题和关键词列表之后,分别将用户请求问题、目标请求问题和关键词列表输入目标编码模型获取多个文本向量,如,基于用户请求问题获取对应的第一文本向量E1、基于目标请求问题获取对应的第二文本向量E2、基于关键词列表获取对应的第三文本向量E3,然后在用于存储向量索引以及对应的文本块的目标数据库中,检索与第一文本向量E1语义相关的文本块、检索与第二文本向量E2语义相关的文本块、检索与第三文本向量E3语义相关的文本块,基于所检索出的文本块确定包括K个第二文本块的候选文本块集合。After determining the target request question and keyword list, the user request question, target request question, and keyword list are input into the target encoding model to obtain multiple text vectors. For example, the first text vector E1 is obtained based on the user request question, the second text vector E2 is obtained based on the target request question, and the third text vector E3 is obtained based on the keyword list. Then, in the target database used to store vector indexes and corresponding text blocks, text blocks semantically related to the first text vector E1, text blocks semantically related to the second text vector E2, and text blocks semantically related to the third text vector E3 are retrieved. Based on the retrieved text blocks, a candidate text block set including K second text blocks is determined.

在本申请的一些实施例中,基于目标编码模型所获取的文本向量也可以为其他数目,如,获取4个文本向量,关键词列表对应于两个文本向量;或者,获取2个文本向量,用户请求问题和目标请求问题对应同一个文本向量;还可以获取其他数目的文本向量,这里不再列举。In some embodiments of this application, the number of text vectors obtained based on the target encoding model can also be other, such as obtaining 4 text vectors, with the keyword list corresponding to two text vectors; or obtaining 2 text vectors, with the user request question and the target request question corresponding to the same text vector; other numbers of text vectors can also be obtained, which will not be listed here.

在目标数据库中所检索出的与文本向量语义相关的文本块可以是与文本向量的关联度大于一阈值的文本块,也可以是与文本向量的关联度排序靠前的特定数目个文本块,此时,文本块越靠前与文本向量的关联度越高。The text blocks retrieved from the target database that are semantically related to the text vector can be text blocks with a correlation degree greater than a threshold, or a specific number of text blocks that rank highly in terms of correlation degree with the text vector. In this case, the higher the ranking of the text block, the higher its correlation degree with the text vector.

其中,目标编码模型为在初始编码模型的基础上经过调整所确定的模型,目标数据库中文本块的大小为经过测试确定的最佳块大小。在确定文本块大小时,包括:基于初始编码模型所支持的最大词语数,确定块调整范围;根据所构建的多条测试数据集,在块调整范围中确定文本块大小。The target encoding model is a model determined by adjusting the initial encoding model, and the size of the text blocks in the target database is the optimal block size determined through testing. Determining the text block size includes: determining the block adjustment range based on the maximum number of words supported by the initial encoding model; and determining the text block size within the block adjustment range based on multiple constructed test datasets.

在构建RAG系统时,块大小是一个关键参数。一般来说,希望在块之间保留一些重叠,以确保语义上下文不会在块之间丢失。在大多情况下,固定大小的分块是最佳路径,与其他形式的分块相比,固定大小的分块计算成本低且易于使用,因为它不需要使用任何NLP(Natural Language Processing,自然语言处理)库。本申请实施例采用从小到大的方式进行块调整,在选定初始编码模型之后,基于初始编码模型所支持的最大词语数,确定块调整范围,然后根据所构建的多条测试数据集,在块调整范围中按照由小到大的顺序进行块大小测试,以确定出最佳块大小。When building a RAG system, chunk size is a key parameter. Generally, it's desirable to retain some overlap between chunks to ensure semantic context isn't lost. In most cases, fixed-size chunking is the optimal approach. Compared to other forms of chunking, fixed-size chunking is computationally inexpensive and easy to use because it doesn't require any NLP (Natural Language Processing) libraries. This application's embodiment adjusts chunks from smallest to largest. After selecting an initial encoding model, the chunk adjustment range is determined based on the maximum number of words supported by the initial encoding model. Then, based on multiple constructed test datasets, chunk sizes are tested within this adjustment range in ascending order to determine the optimal chunk size.

作为本申请的一个实施例,采用bge(BAAI General Embedding)-base-zh-v1.5(智源通用嵌入模型-基础模型-中文-版本1.5)作为初始编码模型,该模型最大支持512个词语(token),因此将块调整范围设计为[128,256,384,512],并构建例如100条测试集,根据所构建的100条测试数据集,按照由小到大的顺序进行块大小测试,通过测试确定出最佳块大小。As an embodiment of this application, bge (BAAI General Embedding)-base-zh-v1.5 (智源一般嵌模-基本模型-中文-版1.5) is used as the initial encoding model. This model supports a maximum of 512 words (tokens). Therefore, the block adjustment range is designed as [128, 256, 384, 512], and for example, 100 test sets are constructed. Based on the constructed 100 test sets, the block size is tested in ascending order, and the optimal block size is determined through testing.

本申请实施例还可以采用其他方式,如强化学习的方式确定最佳块大小。在确定块调整范围之后,基于块调整范围对应的多个块大小确定对应的多个编码,每个编码对应于一块大小。基于强化学习搜索最佳块大小的核心为:使用策略网络来得到文本块大小的编码,计算基于块大小进行文本检索的准确度,将准确度作为更新强化学习策略网络的奖励。即,在基于块调整范围中的块大小进行文本检索时,确定准确度,基于所确定的准确度更新策略网络,以不断优化策略网络,在策略网络优化完成时确定最佳块大小。This application embodiment can also employ other methods, such as reinforcement learning, to determine the optimal block size. After determining the block adjustment range, multiple codes are determined based on the multiple block sizes corresponding to the block adjustment range, with each code corresponding to a block size. The core of searching for the optimal block size based on reinforcement learning is: using a policy network to obtain the code for the text block size, calculating the accuracy of text retrieval based on the block size, and using the accuracy as the reward for updating the reinforcement learning policy network. That is, when performing text retrieval based on the block size within the block adjustment range, the accuracy is determined, the policy network is updated based on the determined accuracy to continuously optimize the policy network, and the optimal block size is determined when the policy network optimization is complete.

其中,在确定文本块大小的情况下,本申请实施例提供的文本生成方法还包括:Wherein, given a determined text block size, the text generation method provided in this application embodiment further includes:

构建包括多个文本数据的微调数据集,文本数据包括问题信息和回复信息,且文本数据为目标领域的数据;Construct a fine-tuned dataset consisting of multiple text data, including question and response information, and the text data is data from the target domain;

基于微调数据集调整初始编码模型,确定目标编码模型;Adjust the initial coding model based on the fine-tuning dataset, and determine the target coding model;

根据所确定的文本块大小,对待输入文档进行分块处理,待输入文档基于在目标领域所收集的信息生成;Based on the determined text block size, the input document is divided into blocks, 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.

本实施例中,为了提升检索质量,确保获取内容与查询内容高度相关,对初始编码模型进行微调,确定目标编码模型,并在确定目标编码模型后,基于目标编码模型和目标领域对应的待输入文档,构建用于存储向量索引以及对应的文本块的目标数据库,以将目标领域不断发展或罕见的术语存储于目标数据库中,进而保证目标数据库存储数据的全面性,提升检索质量。In this embodiment, in order to improve retrieval quality and ensure that the retrieved content is highly relevant to the query content, the initial encoding model is fine-tuned to determine the target encoding model. After determining the target encoding model, a target database is constructed based on the target encoding model and the input documents corresponding to the target domain to store vector indexes and corresponding text blocks. This allows for the storage of evolving or rare terms in the target domain in the target database, thereby ensuring the comprehensiveness of the data stored in the target database and improving retrieval quality.

在微调初始编码模型之前,构建包括多个文本数据的微调数据集,每个文本数据为目标领域对应的包括问题信息和回复信息的数据,且文本数据可以基于预训练模型生成,文本数据的大小不做具体限制。然后基于微调数据集对初始编码模型进行模型参数调整,确定目标编码模型。例如,构建包括1万个文本数据的微调数据集,基于所构建的微调数据集微调bge-base-zh-v1.5模型,确定目标编码模型,目标编码模型用于基于输入的文本内容输出文本向量。Before fine-tuning the initial encoding model, a fine-tuning dataset consisting of multiple text data points is constructed. Each text data point represents the target domain and includes both question and response information. The text data can be generated based on a pre-trained model, and its size is not specifically limited. Then, the model parameters of the initial encoding model are adjusted based on the fine-tuning dataset to determine the target encoding model. For example, a fine-tuning dataset of 10,000 text data points is constructed. The bge-base-zh-v1.5 model is fine-tuned based on this dataset to determine the target encoding model, which outputs text vectors based on the input text content.

在通过微调初始编码模型确定目标编码模型之后,根据所确定的文本块大小,对待输入文档进行分块处理,得到多个文本块,并将多个文本块输入目标编码模型确定多个文本块对应的文本向量,设置文本向量对应的向量索引,基于向量索引与文本块的对应关系构建目标数据库。待输入文档基于所收集的目标领域的信息生成,且所收集的信息可以在包括文本形式的信息的同时,还包括音频形式和/或视频形式的信息,对于音频、视频形式的信息需要将其转化为文本形式,以构成待输入文档。After determining the target encoding model by fine-tuning the initial encoding model, the input document is divided into blocks according to the determined text block size, resulting in multiple text blocks. These multiple text blocks are then input into the target encoding model to determine the corresponding text vectors. Vector indices are set for the text vectors, and a target database is constructed based on the correspondence between vector indices and text blocks. The input document is generated based on information collected from the target domain. This collected information may include text, audio, and/or video information. Audio and video information needs to be converted into text to form the input document.

上述实施过程,通过选择最佳块大小,基于最佳块大小构建目标数据库,基于用户请求问题、目标请求问题和关键词列表分别对应的文本向量在目标数据库中进行检索,可以提供与多个维度分别适配的文本块,进而生成包括K个第二文本块的候选文本块集合。The above implementation process involves selecting the optimal block size, constructing a target database based on the optimal block size, and retrieving text vectors corresponding to the user request question, the target request question, and the keyword list from the target database. This can provide text blocks that are adapted to multiple dimensions, thereby generating a candidate text block set including K second text blocks.

作为本申请一可选实施例,目标领域为法律领域,所构建的目标数据库为与法律相关的目标数据库,基于所构建的数据库对用户提出的与法律相关的问题进行解答。如图3所示,为构建与法律相关的目标数据库的实施过程。收集法律相关书籍、官方网站相关链接、相关条例明细等组成法律相关文档,所组成的法律相关文档即为待输入文档。基于所确定的文本块大小(最佳文本块大小)对待输入文档进行分块处理,获取多个文本块,将多个文本块输入目标编码模型,获取文本向量并设置向量索引,基于向量索引和对应的文本块构建与法律相关的目标数据库。其中,所构建的与法律相关的目标数据库可以包括多方面的法律知识,以保证目标数据库涵盖信息的全面性。As an optional embodiment of this application, the target field is the legal field, and the constructed target database is a law-related target database. Based on the constructed database, answers are provided to law-related questions raised by users. Figure 3 shows the implementation process of constructing the law-related target database. Law-related books, official website links, and detailed regulations are collected to form law-related documents, which serve as the input document. Based on a determined text block size (optimal text block size), the input document is divided into blocks to obtain multiple text blocks. These multiple text blocks are input into the target encoding model to obtain text vectors and set vector indices. The law-related target database is constructed based on the vector indices and the corresponding text blocks. The constructed law-related target database can include various aspects of legal knowledge to ensure the comprehensiveness of the information covered by the target database.

在构建与法律相关的目标数据库之后,可以针对用户提出的与法律相关的问题,在该数据库中检索适配的文本内容,以基于构建的目标数据库针对用户的提问给出回复依据。After constructing a target database related to law, appropriate text content can be retrieved from this database for users' legal-related questions, and responses can be provided based on the constructed target database.

下面对在候选文本块集合确定N个第一文本块的过程进行介绍。在本申请的一些实施例中,在生成包括K个文本块的候选文本块集合之后,对候选文本块集合进行文本块去重、排序处理,获取N个第一文本块,包括:The process of determining N first text blocks from a candidate text block set is described below. In some embodiments of this application, after generating a candidate text block set including K text blocks, the candidate text block set is subjected to text block deduplication and sorting processing to obtain N first text blocks, including:

遍历计算候选文本块集合中的两两第二文本块之间的相似度;Iterate through the candidate text block set and calculate the similarity between each pair of second text blocks;

根据相似度计算结果,确定目标文本块组,其中,任意两个第二文本块构成一文本块组,两个第二文本块的相似度大于预设阈值的文本块组为目标文本块组;Based on the similarity calculation results, target text block groups are determined. Any two second text blocks constitute a text block group, and text block groups in which the similarity between two second text blocks is greater than a preset threshold are target text block groups.

在目标文本块组中确定与用户请求问题的关联度低的第二文本块,将所确定的第二文本块删除,以进行第二文本块去重;In the target text block group, identify the 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 second-level text block deduplication on the target text block group, obtain the target text block set;

对目标文本块集合中的第二文本块进行特征信息提取,并基于所提取的特征信息对第二文本块进行分数评估获取第二文本块对应的第一评分;Feature information is extracted from the second text block in the target text block set, and the score of the second text block is evaluated based on the extracted feature information to obtain the first score corresponding to the second text block;

基于第二文本块对应的第一评分,在目标文本块集合中确定N个第一文本块。Based on the first score corresponding to the second text block, N first text blocks are determined in the target text block set.

在对候选文本块集合进行文本块去重时,基于第二文本块与区别于当前第二文本块的其他第二文本块分别进行两两组合的策略,计算两个第二文本块之间的相似度。相组合的两个第二文本块构成一文本块组,且第二文本块A与第二文本块B的组合、第二文本块B与第二文本块A的组合属于同一个文本块组。如,候选文本块集合中包括第二文本块A、第二文本块B以及第二文本块C,则基于两两组合可以得到如下文本块组:包括第二文本块A和第二文本块B的文本块组,包括第二文本块A和第二文本块C的文本块组,包括第二文本块B和第二文本块C的文本块组。When deduplicating text blocks in a candidate text block set, the similarity between two second text blocks is calculated based on a strategy of pairwise combination of each second text block with other second text blocks that are distinct from the current second text block. Two combined second text blocks form a text block group, and combinations of second text block A and second text block B, and combinations of second text block B and second text block A, belong to the same text block group. For example, if the candidate text block set includes second text block A, second text block B, and second text block C, then based on pairwise combinations, the following text block groups can be obtained: a text block group including second text block A and second text block B, a text block group including second text block A and second text block C, and a text block group including second text block B and second text block C.

在构成的文本块组中,根据相似度计算结果,确定两个第二文本块的相似度大于预设阈值的目标文本块组,然后针对目标文本块组,在目标文本块组中确定与用户请求问题的关联度低的第二文本块,将该第二文本块删除,以针对目标文本块组进行文本块去重。在针对目标文本块组进行文本块去重之后,基于完成去重的目标文本块组和其他文本块组确定目标文本块集合,其中目标文本块集合不包括重复的第二文本块,如某个第二文本块被多次保留,目标文本块集合中仅包括一个该第二文本块。Within the constructed text block group, based on the similarity calculation results, target text block groups are identified where the similarity between two second text blocks exceeds a preset threshold. Then, for each target text block group, second text blocks with low relevance to the user's request are identified and deleted to perform text block deduplication. After deduplication of the target text block group, a target text block set is determined based on the deduplicated target text block group and other text block groups. This target text block set does not include duplicate second text blocks; if a second text block is retained multiple times, the target text block set includes only one instance of that second text block.

在基于去重确定目标文本块集合后,对目标文本块集合中的每个第二文本块进行特征信息提取,然后基于所提取的特征信息对第二文本块进行分数评估,获取第二文本块对应的第一评分。After determining the target text block set based on deduplication, feature information is extracted from each second text block in the target text block set. Then, the second text block is evaluated based on the extracted feature information to obtain the first score corresponding to the second text block.

其中,在对第二文本块进行特征信息提取、基于提取的特征信息获取第一评分时,获取第二文本块与用户请求问题的第一语义相似度、第二文本块与用户请求问题的前文的第二语义相似度以及文本质量中的至少一项;基于第一语义相似度、第二语义相似度和文本质量中的至少一项进行分数评估,获取第二文本块对应的第一评分。Specifically, when extracting feature information from the second text block and obtaining a first score based on the extracted feature information, at least one of the following is obtained: the first semantic similarity between the second text block and the user's request question, the second semantic similarity between the second text block and the preceding text of the user's request question, and the text quality; a score evaluation is performed based on at least one of the first semantic similarity, the second semantic similarity, and the text quality to obtain the first score corresponding to the second text block.

本实施例中,对第二文本块进行特征信息提取所获取的特征信息包括第一语义相似度、第二语义相似度以及文本质量中的至少一项。第一相似度用于衡量第二文本块与用户请求问题的关联度,第二相似度用于衡量第二文本块与历史问答记录的关联度。文本质量可基于PPL(perplexity,困惑度)、Distinct(多样性)等评价指标进行评价,其中,困惑度用于衡量一句话是否通顺,Distinct评价指标用于判断回复的多样性。困惑度的定义如下:In this embodiment, the feature information obtained by extracting feature information from the second text block includes at least one of first semantic similarity, second semantic similarity, and text quality. The first similarity measures the relevance of the second text block to the user's request question, and the second similarity measures the relevance of the second text block to historical question-and-answer records. Text quality can be evaluated based on metrics such as PPL (perplexity) and Distinct. Perplexity measures whether a sentence is fluent, and Distinct measures the diversity of responses. The definition of perplexity is as follows:

其中,P(xi|x1,x2,…,xi-1)表示根据上文词语预测第i个词的概率,N代表句子长度。PPL值越小,说明文本越自然、语句越通顺。通过PPL来评价文本,可以避免文本有乱序、前后颠倒的情形。 Where P(x <sub>i </sub> | x<sub> 1 </sub>, x <sub>2</sub> , ..., x <sub>i-1</sub> ) represents the probability of predicting the i-th word based on the preceding words, and N represents the sentence length. The smaller the PPL value, the more natural and fluent the text. Evaluating text using PPL can avoid situations where the text is out of order or has inverted sentences.

Distinct评价指标具体用于判断是否出现大量的通用性、重复性内容。Distinct的定义如下:
The Distinct metric is specifically used to determine whether there is a large amount of generic or repetitive content. The definition of Distinct is as follows:

其中,上述公式中,Count(uniquengram)表示文本中不重复的ngram数量,Count(word)表示文本中ngram词语的总数量,Distinct(n)越大表示多样性越高。In the above formula, Count(uniquengram) represents the number of unique ngrams in the text, Count(word) represents the total number of ngram words in the text, and the larger Distinct(n) is, the higher the diversity.

在基于特征信息提取获取第二文本块对应的第一语义相似度、第二语义相似度以及文本质量中的至少一项之后,基于第一语义相似度、第二语义相似度以及文本质量中的至少一项进行分数评估,获取第二文本块对应的第一评分。若基于上述特征信息中的至少两项进行分数评估,需要设置每个特征信息对应的参数,以基于参数和特征信息确定第一评分。After extracting at least one of the following based on feature information—first semantic similarity, second semantic similarity, and text quality—a score is evaluated based on at least one of these features to obtain a first score for the second text block. If the score evaluation is based on at least two of the aforementioned feature information, parameters for each feature information need to be set to determine the first score based on the parameters and feature information.

作为本申请的一个实施例,基于特征信息提取获取第二文本块的第一语义相似度Score1、第二语义相似度Score2以及文本质量ScorePPL、ScoreDistinct,然后基于评分公式确定对应的第一评分:Score=α1Score1+β1Score2+γ1(ScorePPL+ScoreDistinct),α1、β1、γ1为超参系数,根据实验效果设置。As an embodiment of this application, the first semantic similarity Score 1 , the second semantic similarity Score 2 , and the text quality Score PPL and Score Distinct of the second text block are obtained based on feature information extraction. Then, the corresponding first score is determined based on the scoring formula: Score = α1Score 1 + β1Score 2 + γ1(Score PPL + Score Distinct ), where α1, β1, and γ1 are hyperparameter coefficients and are set according to the experimental results.

在获取目标文本块集合中的各第二文本块对应的第一评分之后,基于第二文本块对应的第一评分,在目标文本块集合中确定N个第一文本块时,包括:基于第二文本块对应的第一评分,对目标文本块集合中的第二文本块进行排序,确定排序结果,其中,第二文本块的排列次序与第二文本块对应的关联度正相关;基于排序结果,确定目标文本块集合中第一评分靠前的N个第二文本块,将N个第二文本块确定为N个第一文本块。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 blocks, the process includes: sorting the second text blocks in the target text block set based on the first score corresponding to the second text blocks, and determining the sorting result, wherein the order of the second text blocks is positively correlated with the relevance of the second text blocks; and based on the sorting result, determining the N second text blocks with the highest first scores in the target text block set, and defining the N second text blocks as N first text blocks.

在获取各第二文本块对应的第一评分之后,基于第一评分,对目标文本块集合中的第二文本块进行排序,此时,按照第一评分由高到低的顺序对第二文本块进行排序获取排序结果,第一评分越高则表征第二文本块与用户请求问题和/或历史问答记录的关联度越高,和/或,文本质量越高,即,对应的关联度越高的第二文本块越靠前、文本质量越高的第二文本块越靠前。在排序完成之后,确定目标文本块集合中第一评分靠前的N个第二文本块,以获取N个第一文本块,实现筛选出与用户请求问题和/或历史问答记录相关度高、文本质量高的文本块。After obtaining the first score for each second text block, the second text blocks in the target text block set are sorted based on the first score. The second text blocks are sorted from highest to lowest first score to obtain the sorting result. A higher first score indicates a higher relevance between the second text block and the user's request question and/or historical Q&A records, and/or higher text quality. That is, the second text block with higher relevance and higher text quality appears earlier. After sorting, the top N second text blocks with the highest first scores in the target text block set are determined to obtain N first text blocks, thus filtering out text blocks with high relevance and high text quality to the user's request question and/or historical Q&A records.

上述实施过程,在确定候选文本块集合之后,对候选文本块集合进行去重,以删除冗余信息,实现内容精简;在完成去重后,通过特征信息提取进行分数评估,基于评分筛选文本块,可以提供高质量的文本块,实现在去重的同时优化与查询相关的内容。The above implementation process involves determining a set of candidate text blocks, then deduplicating the set to remove redundant information and simplify the content. After deduplication, feature information is extracted for score evaluation, and text blocks are selected based on the scores. This provides high-quality text blocks and optimizes content related to the query while deduplicating.

作为本申请的一个实施例,下面通过一流程图对基于三个待检索请求确定N第一个文本块的过程进行介绍,如图4所示,将用户请求问题作为待检索请求1、将目标请求问题作为待检索请求2、将关键词列表作为待检索请求3,将待检索请求1、待检索请求2、待检索请求3分别输入目标编码模型,获取第一文本向量、第二文本向量以及第三文本向量。基于第一文本向量、第二文本向量和第三文本向量在目标数据库中检索,获取与第一文本向量关联的q个文本块、与第二文本向量关联的q个文本块、与第三文本向量关联的q个文本块,以确定K个第二文本块,其中,与文本向量关联的q个文本块为筛选出的关联度较高的文本块。As an embodiment of this application, the process of determining the first N text blocks based on three search requests is described below using a flowchart, as shown in Figure 4. The user request question is taken as search request 1, the target request question as search request 2, and the keyword list as search request 3. Search request 1, search request 2, and search request 3 are respectively input into the target encoding model to obtain a first text vector, a second text vector, and a third text vector. Based on the first, second, and third text vectors, a search is performed in the target database to obtain q text blocks associated with the first text vector, q text blocks associated with the second text vector, and q text blocks associated with the third text vector, thus determining K second text blocks. The q text blocks associated with the text vectors are the selected text blocks with high relevance.

然后对包括K个第二文本块的候选文本块集合进行文本块去重,在完成去重之后,对剩余的第二文本块进行特征信息提取、计算第一评分并按照第一评分进行第二文本块排序,最后提供N个第一文本块。Then, text block deduplication is performed on the candidate text block set including K second text blocks. After deduplication, feature information is extracted from the remaining second text blocks, a first score is calculated, and the second text blocks are sorted according to the first score. Finally, N first text blocks are provided.

图4所示的流程中,通过检索、去重、评分、排序一系列流程,筛选出关联度高的文本块,可以实现提供高质量的文本块,保证检索效果。As shown in Figure 4, the process of searching, deduplication, scoring, and sorting filters out highly relevant text blocks, thus providing high-quality text blocks and ensuring search results.

下面对基于N的第一文本块确定与用户请求问题匹配的回复信息的实施方案进行介绍。该实施方案包括获取目标文本块、获取候选回复集合、在候选回复集合中筛选匹配的候选回复的过程。The following describes an implementation scheme for determining the response information matching the user's request based on the first text block N. This implementation scheme includes the processes of obtaining the target text block, obtaining a candidate response set, and filtering matching candidate responses from the candidate response set.

其中,针对获取目标文本块的过程,在将N个第一文本块均衡地分配至M个预训练模型进行文本改写,获取N个目标文本块时,包括:Specifically, the process of obtaining target text blocks, in which N first text blocks are evenly distributed to M pre-trained models for text rewriting to obtain N target text blocks, includes:

按照均衡分配原则,将N个第一文本块分为M份,确定每份第一文本块对应的预训练模型;基于第一文本块与预训练模型的对应关系,将M份第一文本块并发输入对应的预训练模型进行文本改写,获取N个文本改写后的目标文本块。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 blocks and the pre-trained model, the M parts of the first text blocks are concurrently input into the corresponding pre-trained model for text rewriting, and N rewritten target text blocks are obtained.

本申请实施例中,服务器上部署有M个预训练模型,在M的取值大于1时,M个预训练模型支持并发调用。在确定N个第一文本块之后,基于均衡分配原则,将N个第一文本块划分为M份,确定每份第一文本块对应的预训练模型,建立M份第一文本块与M个预训练模型的对应关系。In this embodiment, M pre-trained models are deployed on the server. When the value of M is greater than 1, the M pre-trained models support concurrent invocation. After determining N first text blocks, based on 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 blocks is determined, thus establishing a correspondence between the M parts of the first text blocks and the M pre-trained models.

作为本申请的一个实施例,N的取值为10,M的取值为4,则将10个第一文本块划分为4份,4份第一文本块对应的文本块数量分别为2、2、3、3,以相对均衡地进行文本块划分。或者,N的取值为15,M的取值为3,则将15个第一文本块平均划分为3份,每份第一文本块对应的文本块数量均为5。In one embodiment of this application, if N is 10 and M is 4, the 10 first text blocks are divided into 4 parts, with the number of text blocks in each part being 2, 2, 3, and 3 respectively, to achieve a relatively balanced division of text blocks. Alternatively, if N is 15 and M is 3, the 15 first text blocks are divided into 3 equal parts, with the number of text blocks in each part being 5.

其中,每份第一文本块对应的预训练模型可以随机确定,也可以按照预设策略确定。如N个第一文本块按照关联度由高到低的顺序划分,得到的M份第一文本块按照优先级由高到低的顺序排列,且关联度与优先级正相关,即,对应的关联度越高则优先级越高。对于M个预训练模型,确定其对应的优先级次序,预训练模型的优先级基于预训练模型的使用频次、受众程度等参数确定。按照优先级高的第一文本块对应优先级高的预训练模型的分配策略,建立M份第一文本块与M个预训练模型的对应关系,或者,基于优先级高的第一文本块对应优先级低的预训练模型的分配策略,建立M份第一文本块与M个预训练模型的对应关系。The pre-trained model corresponding to each first text block can be randomly determined or determined according to a preset strategy. For example, if N first text blocks are divided in descending order of relevance, the resulting M first text blocks are arranged in descending order of priority, with relevance being positively correlated with priority; that is, the higher the relevance, the higher the priority. For the M pre-trained models, their corresponding priority order is determined based on parameters such as usage frequency and audience reach. The correspondence between the M first text blocks and the M pre-trained models is established either by assigning higher-priority first text blocks to higher-priority pre-trained models, or by assigning higher-priority first text blocks to lower-priority pre-trained models.

在建立第一文本块与预训练模型的对应关系之后,将M份第一文本块并发地输入对应的预训练模型中,以基于预训练模型的文本风格对第一文本块进行改写获取N个目标文本块,实现基于多线程并发的方式高效地获取所需信息。且通过对第一文本块进行文本风格改写,可以减少或者避免针对用户请求问题生成的回复不连贯或不自然的问题。After establishing the correspondence between the first text block and the pre-trained model, M copies of the first text block are concurrently input into the corresponding pre-trained model. The first text blocks are then rewritten based on the text style of the pre-trained model to obtain N target text blocks. This achieves efficient acquisition of the required information through multi-threaded concurrency. Furthermore, by rewriting the text style of the first text block, issues such as incoherent or unnatural responses generated for user requests can be reduced or avoided.

针对获取候选回复集合的过程,在基于M个预训练模型对N个文本提示信息进行处理获取候选回复集合时,包括:The process of obtaining a candidate response set, when processing N text prompts based on M pre-trained models to obtain the candidate response set, includes:

在基于N个目标文本块、用户请求问题和用户对应的历史问答记录生成N个文本提示信息之后,基于第一文本块与预训练模型的对应关系,将N个文本提示信息并发输入对应的预训练模型,获取候选回复集合;每个文本提示信息对应至少一个候选回复。After generating N text prompts based on N target text blocks, user request questions, and corresponding historical question-and-answer records, the N text prompts are concurrently input into the corresponding pre-trained models based on the correspondence between the first text block and the pre-trained model to obtain a set of candidate responses; each text prompt corresponds to at least one candidate response.

在利用预训练模型对第一文本块进行文本改写获取N个目标文本块之后,针对每个目标文本块,基于当前目标文本块、用户请求问题和用户对应的历史问答记录的组合生成对应的文本提示信息,以获取N个目标文本块对应的N个文本提示信息。然后利用第一文本块与预训练模型的对应关系,将N个文本提示信息并发输入至对应的预训练模型,通过预训练模型对文本提示信息进行处理,获取基于文本提示信息确定的候选回复,进而基于候选回复的聚合确定候选回复集合。After rewriting the first text block using a pre-trained model to obtain N target text blocks, for each target text block, corresponding text prompts are generated based on the combination of the current target text block, the user's request question, and the user's corresponding historical question-and-answer records, resulting in N text prompts for the N target text blocks. Then, using the correspondence between the first text block and the pre-trained model, the N text prompts are concurrently input into the corresponding pre-trained models. The pre-trained models process the text prompts to obtain candidate responses determined based on the text prompts, and then aggregate these candidate responses to determine a candidate response set.

通过将N个文本提示信息并发输入至M个预训练模型,可以使得M个预训练模型并发对文本提示信息进行处理,以基于多线程并发的方式高效输出候选回复;针对任意一文本提示信息,其输入对应的预训练模型之后,由预训练模型输出至少一个候选回复,将N个文本提示信息对应的候选回复进行聚合后确定包括至少N个候选回复的候选回复集合。By concurrently inputting N text prompts into M pre-trained models, the M pre-trained models can process the text prompts concurrently, efficiently outputting candidate responses in a multi-threaded concurrent manner. For any text prompt, after it is input into the corresponding pre-trained model, the pre-trained model outputs at least one candidate response. The candidate responses corresponding to the N text prompts are aggregated to determine a candidate response set including at least N candidate responses.

下面通过本申请的一个实施例对改写第一文本块、基于改写后的目标文本块确定候选回复集合的过程进行介绍。如图5所示,将N个第一文本块相对均衡地分配至4个预训练模型(预训练模型A、预训练模型B、预训练模型C、预训练模型D),由4个预训练模型对第一文本块进行文本改写的并发处理,输出N个目标文本块,以基于多线程并发的方式高效地提供目标文本块。The following describes an embodiment of this application illustrating the process of rewriting the first text block and determining the candidate response set based on the rewritten target text block. As shown in Figure 5, N first text blocks are relatively evenly distributed among four pre-trained models (pre-trained model A, pre-trained model B, pre-trained model C, and pre-trained model D). The four pre-trained models concurrently process the text rewriting of the first text blocks, outputting N target text blocks, thus efficiently providing the target text blocks in a multi-threaded concurrent manner.

在获取N个目标文本块之后,针对每个目标文本块,基于目标文本块、用户请求问题和用户对应的历史问答记录生成文本提示信息,将N个文本提示信息输入对应的预训练模型,由4个预训练模型并发处理输出文本提示信息对应的候选回复,以基于并发处理的方式高效确定候选回复集合。After obtaining N target text blocks, for each target text block, text prompt information is generated based on the target text block, the user's request question, and the user's corresponding historical question and answer records. The N text prompt information are input into the corresponding pre-trained model, and the four pre-trained models process the text prompt information concurrently to output the candidate responses corresponding to the text prompt information, so as to efficiently determine the candidate response set in a concurrent processing manner.

图5所示的流程中,通过文本改写、文本提示信息生成、输出候选回复一系列流程,确定候选回复集合,可以为筛选与用户请求问题适配的回复提供依据,且并发处理的方式提升了效率。In the process shown in Figure 5, a series of steps, including text rewriting, text prompt generation, and output of candidate responses, determine the set of candidate responses. This provides a basis for filtering responses that match the user's request, and the concurrent processing method improves efficiency.

针对在候选回复集合中筛选匹配的候选回复的过程,在基于评估策略对候选回复集合中的候选回复进行评估,选择与用户请求问题匹配的回复信息时,包括:The process of filtering matching candidate responses from a candidate response set, when evaluating candidate responses based on an evaluation strategy and selecting the 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, the target score corresponding to the candidate response is determined; and based on the target score, the response information that matches the user's request question is selected from the candidate responses corresponding to the candidate response set.

在候选回复集合中筛选候选回复作为与用户请求问题匹配的回复信息时,基于回复忠实度、回复相关性和上下文相关性中的至少一项,对候选回复集合中的各个候选回复进行评估,确定候选回复对应的至少一个第二评分。When selecting candidate responses from the candidate response set as responses that match the user's request, each candidate response in the candidate response set is evaluated based on at least one of response fidelity, response relevance, and contextual relevance to determine at least one second score corresponding to the candidate response.

在基于回复忠实度对候选回复进行评估时,利用候选回复对应的预训练模型将候选回复进行语义分解,得到多个参考回复,检验每个参考回复与上下文的一致性,以确定参考回复是否为可支持用户请求问题的回复。基于可支持用户请求问题的参考回复的数量与参考回复总数量之比确定回复忠实度对应的第二评分。When evaluating candidate responses based on response fidelity, a pre-trained model corresponding to each candidate response is used to perform semantic decomposition, resulting in multiple reference responses. The consistency of each reference response with the context is then examined to determine whether each reference response supports the user's requested question. A second score corresponding to the response fidelity is determined based on the ratio of the number of reference responses that support the user's requested question to the total number of reference responses.

在基于回复相关性对候选回复进行评估时,利用候选回复对应的预训练模型创造与候选回复适配的可能问题,并分析这些问题与用户请求问题的相似度,回复相关性对应的评分是通过计算所有生成问题与用户请求问题相似度的平均值来得出的。具体的计算公式为:
When evaluating candidate responses based on their relevance, a pre-trained model corresponding to each candidate response is used to create potential questions that fit the candidate response. The similarity between these questions and the user's requested question is then analyzed. The score corresponding to the response relevance is obtained by calculating the average similarity between all generated questions and the user's requested question. The specific calculation formula is as follows:

对于给定的候选回复as(q),促使预训练模型根据as(q)生成n个潜在问题qi,对于每个qi,计算与用户请求问题(原始问题)q的相似度sim(q,qi),基于n个相似度之和的均值确定最终结果,将其作为回复相关性对应的第二评分。For a given candidate response as(q), the pre-trained model is prompted to generate n potential questions q i based on as(q). For each q i , the similarity sim(q,q i ) with the user's request question (original question) q is calculated. The final result is determined based on the mean of the sum of the n similarities and is used as the second score corresponding to the relevance of the response.

在基于上下文相关性对候选回复进行评估时,利用候选回复对应的预训练模型在用户对应的历史问答记录中筛选出直接与用户请求问题相关的语句,以这些语句占上下文总语句数量的比例来确定上下文相关性对应的第二评分。具体计算公式为:
CR=筛选的语句数目/上下文总语句数量
When evaluating candidate responses based on contextual relevance, a pre-trained model corresponding to the candidate response is used to filter statements directly related to the user's request from the user's historical question-and-answer records. The second score corresponding to contextual relevance is determined by the proportion of these statements to the total number of statements in the context. The specific calculation formula is as follows:
CR = Number of filtered statements / Total number of context statements

通过在用户对应的历史问答记录中筛选直接与用户请求问题相关的语句,基于筛选出的语句与总的语句数量的比值确定第二评分,实现衡量上下文相关性。By filtering statements directly related to the user's question from the user's historical question and answer records, a second score is determined based on the ratio of the filtered statements to the total number of statements, thus measuring contextual relevance.

其中,由于在对候选回复进行回复忠实度评估、回复相关性评估、上下文相关性评估时,利用候选回复对应的预训练模型进行处理,因此,需要预先根据候选回复与预训练模型的对应关系确定适配的预训练模型。Since the pre-trained model corresponding to the candidate response is used to process the candidate response when evaluating response fidelity, response relevance and context relevance, it is necessary to determine the appropriate pre-trained model in advance based on the correspondence between the candidate response and the pre-trained model.

在针对任一候选回复确定其对应的至少一个第二评分之后,基于候选回复对应的至少一个第二评分,确定候选回复对应的目标评分,最后基于各个候选回复对应的目标评分,在候选回复集合中选择针对用户请求问题的回复信息。After determining at least one second score for any candidate response, a target score for the candidate response is determined based on the at least one second score. Finally, based on the target scores for each candidate response, response information for the user's requested question is selected from the candidate response set.

作为本申请的一个实施例,基于回复忠实度、回复相关性和上下文相关性,对候选回复进行评估,获取回复忠实度对应的第二评分ScoreF、回复相关性对应的第二评分ScoreAR、上下文相关性对应的第二评分ScoreCR,然后基于评分公式确定目标评分:Score=α2ScoreF+β2ScoreAR+γ2ScoreCR,其中α2、β2、γ2为超参系数,根据实验效果设置。As an embodiment of this application, candidate responses are evaluated based on response fidelity, response relevance, and contextual relevance to obtain a second score Score F corresponding to response fidelity, a second score AR corresponding to response relevance, and a second score CR corresponding to contextual relevance. Then, the target score is determined based on the scoring formula: Score = α²Score F + β²Score AR + γ²Score CR , where α², β², and γ² are hyperparameter coefficients set according to experimental results.

在确定各个候选回复对应的目标评分之后,按照评分由高到低的顺序对候选回复进行排序,将排序最靠前的候选回复确定为针对用户请求问题的回复信息,以实现在生成多个候选回复后,通过自动评估方法从多个候选回复中选出最佳回复,进一步提高生成回复信息的精度。After determining the target score for each candidate response, the candidate responses are sorted in descending order of score. The candidate response with the highest score is selected as the response to the user's request. This allows for the automatic evaluation of multiple candidate responses to select the best response, thereby improving the accuracy of the generated response information.

服务器在确定针对用户请求问题的回复信息之后,将所确定的回复信息返回给客户端,以在客户端展示,使得用户获取高质量的回复信息。After determining the response information for the user's request, the server returns the determined response information to the client for display, so that the user can obtain high-quality response information.

下面通过一具体实施流程对本申请的整体实施过程进行介绍,如图6所示:The overall implementation process of this application is described below through a specific implementation procedure, as shown in Figure 6:

检索前,确定目标编码模型以及文本块大小,根据文本块大小,对待输入文档进行分块处理得到多个文本块,基于目标编码模型和多个文本块构建目标数据库。基于接收到的用户请求问题,获取用户对应的历史问答记录,基于用户请求问题和历史问答记录获取关键词列表和对用户请求问题改写后的目标请求问题。Before retrieval, the target encoding model and text block size are determined. Based on the text block size, the input document is divided into multiple text blocks. A target database is constructed based on the target encoding model and the multiple text blocks. Based on the received user request question, the corresponding historical question and answer records are obtained. Based on the user request question and historical question and answer records, a keyword list and a target request question rewritten from the user request question are obtained.

检索阶段:基于用户请求问题、目标请求问题和关键词列表在多个维度进行检索获取包括K个第二文本块的候选文本块集合。具体检索过程为:将用户请求问题、目标请求问题和关键词列表分别输入目标编码模型,获取多个文本向量;在目标数据库中分别检索与各文本向量的语义关联度符合语义相关要求的文本块,以确定K个第二文本块。Retrieval Phase: Based on the user request question, target request question, and keyword list, a multi-dimensional search is performed to obtain a set of candidate text blocks, including K second text blocks. Specifically, the retrieval process involves inputting the user request question, target request question, and keyword list into the target encoding model to obtain multiple text vectors; then, text blocks whose semantic relevance to each text vector meets the semantic relevance requirement are retrieved from the target database to determine the K second text blocks.

去重排序阶段:对候选文本块集合中的第二文本块进行去重并排序,基于排序结果筛选出N个第一文本块,详细过程参见上述实施例的相关介绍,这里不再赘述。Deduplication and sorting stage: The second text block in the candidate text block set is deduplicated and sorted. Based on the sorting results, N first text blocks are selected. For details, please refer to the relevant descriptions in the above embodiments, which will not be repeated here.

生成阶段:利用预训练模型对N个第一文本块进行文本改写确定目标文本块,基于目标文本块确定文本提示信息输入至对应的预训练模型,获取文本提示信息对应的候选回复。Generation phase: The pre-trained model is used to rewrite the text of N first text blocks to determine the target text block. Based on the target text block, the text prompt information is determined and input into the corresponding pre-trained model to obtain the candidate response corresponding to the text prompt information.

筛选阶段:基于至少一个评估指标对候选回复进行评分,基于评分情况筛选出与用户请求问题匹配的回复信息。Screening phase: Score candidate responses based on at least one evaluation metric, and select responses that match the user's question based on the scores.

上述实施流程,通过目标数据库构建、多维度检索、信息去重、文本块排序、文本块改写、候选回复生成、候选回复筛选一系列操作,为客户端提供与用户请求问题匹配的回复信息,保证了基于预训练模型进行智能问答的回复质量。The above implementation process, through a series of operations including target database construction, multi-dimensional retrieval, information deduplication, text block sorting, text block rewriting, candidate response generation, and candidate response filtering, provides the client with response information that matches the user's request question, ensuring the response quality of intelligent question answering based on the pre-trained model.

以上为本申请实施例提供的文本生成方法的整体实施过程,基于多个维度的检索获取与用户请求问题相关的N个第一文本块,实现相对全面的收集与用户请求问题相关的内容,提升检索精度;在确定N个第一文本块之后将N个第一文本块均衡地分配至M个预训练模型进行文本改写,获取N个目标文本块,可以基于预训练模型输出与预训练模型风格适配、语义连贯且自然的文本内容,以便于后续可以提升文本回复的质量;在确定文本提示信息后,基于预训练模型与第一文本块的对应关系,将N个文本提示信息分配给M个预训练模型进行处理获取候选回复集合,采用评估策略对候选回复集合中的各个候选回复进行评估,可以利用适配的预训练模型输出候选回复,对候选回复进行评估选择出与用户请求问题最适配的候选回复,以提供与用户请求问题匹配的回复信息,可以提升回复精度、保证智能回复的质量。The above describes the overall implementation process of the text generation method provided in this application. Based on multi-dimensional retrieval, N first text blocks related to the user's request are obtained, achieving a relatively comprehensive collection of content related 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 to obtain N target text blocks. Based on the pre-trained models, text content that is style-adapted, semantically coherent, and natural can be output, thus improving the quality of subsequent text responses. After determining the text prompt information, based on the correspondence between the pre-trained models and the first text blocks, the N text prompt information is 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. Adapted pre-trained models can be used to output candidate responses, and the candidate responses are evaluated to select the most suitable candidate response to the user's request, providing response information that matches the user's request, thus improving response accuracy and ensuring the quality of intelligent responses.

在确定候选文本块集合之后,对候选文本块集合中的内容进行去重、排序处理,可以在精简内容、避免信息冗余的同时,提供与用户请求问题关联度高的文本块;通过采用多进程并发的处理方式,可以提升处理效率。After determining the candidate text block set, the content in the candidate text block set is deduplicated and sorted. This can reduce the amount of content and avoid information redundancy while providing text blocks that are highly relevant to the user's request. By adopting a multi-process concurrent processing method, processing efficiency can be improved.

本申请实施例还提供一种文本生成装置,如图7所示,包括:This application embodiment also provides a text generation apparatus, as shown in FIG7, including:

获取模块701,用于获取与用户请求问题关联且满足预设条件的N个第一文本块,N个第一文本块基于多个维度的检索确定;The acquisition module 701 is used to acquire N first text blocks that are associated with the user's request and meet preset conditions. The N first text blocks are determined based on retrieval from multiple dimensions.

分配获取模块702,用于将N个第一文本块均衡地分配至M个预训练模型进行文本改写,获取N个目标文本块,M、N均为大于或者等于1的整数;The allocation and acquisition module 702 is used to evenly distribute N first text blocks to M pre-trained models for text rewriting and to acquire N target text blocks, where M and N are both integers greater than or equal to 1;

处理获取模块703,用于在确定N个目标文本块对应的N个文本提示信息后,基于M个预训练模型对N个文本提示信息进行处理获取候选回复集合,文本提示信息包括目标文本块、用户请求问题和用户对应的历史问答记录;The processing and acquisition module 703 is used to process the N text prompts based on M pre-trained models after determining the N text prompts corresponding to the N target text blocks to obtain a set of candidate responses. The text prompts include the target text blocks, the user's request question, and the user's corresponding historical question and answer records.

评估选择模块704,用于基于评估策略对候选回复集合中的候选回复进行评估,选择与用户请求问题匹配的回复信息。The evaluation and selection module 704 is used to evaluate the candidate responses in the candidate response set based on the evaluation strategy and select the response information that matches the user's request question.

在本申请的一些实施例中,获取模块包括:In some embodiments of this application, the acquisition module includes:

检索获取子模块,用于在多个维度检索与用户请求问题的关联度符合语义相关要求的文本信息,获取包括K个第二文本块的候选文本块集合;The retrieval submodule is used to retrieve text information that meets the semantic relevance requirements of the user's request question across multiple dimensions, and to obtain a candidate text block set including K second text blocks;

处理获取子模块,用于对候选文本块集合进行文本块去重、排序处理,获取N个第一文本块。The processing and acquisition submodule is used to perform text block deduplication and sorting on the candidate text block set to obtain N first text blocks.

在本申请的一些实施例中,检索获取子模块包括:In some embodiments of this application, the retrieval submodule includes:

第一获取单元,用于基于用户请求问题和用户对应的历史问答记录,获取关键词列表和对用户请求问题改写后的目标请求问题,关键词列表和目标请求问题基于对应的模型服务获取;The first acquisition unit is used to acquire a keyword list and a target request question rewritten from the user's request question, based on the user's request question and the user's corresponding historical question and answer records. The keyword list and the target request question are acquired based on the corresponding model service.

第二获取单元,用于根据用户请求问题、目标请求问题和关键词列表在多个维度进行文本信息检索,获取K个第二文本块。The second acquisition unit is used to retrieve text information across multiple dimensions based on the user request question, the target request question, and the keyword list, and to acquire K second text blocks.

在本申请的一些实施例中,第二获取单元包括:In some embodiments of this application, the second acquisition unit includes:

输入获取子单元,用于将用户请求问题、目标请求问题和关键词列表分别输入目标编码模型,获取多个文本向量;The input acquisition subunit is used to input the user request question, the target request question, and the keyword list into the target encoding model to obtain multiple text vectors;

检索确定子单元,用于在目标数据库中分别检索与各文本向量的语义关联度符合语义相关要求的文本块,以确定K个第二文本块;The retrieval determines the sub-unit, which is used to retrieve text blocks in the target database that meet the semantic relevance requirements of each text vector, so as to determine K second text blocks;

其中,目标数据库中存储向量索引以及对应的文本块。The target database stores vector indexes and their corresponding text blocks.

在本申请的一些实施例中,装置还包括:In some embodiments of this application, the apparatus further includes:

构建模块,用于构建包括多个文本数据的微调数据集,文本数据包括问题信息和回复信息,且文本数据为目标领域的数据;The building module is used to construct a fine-tuning dataset that includes multiple text data, including question and response information, and the text data is data from the target domain;

调整确定模块,用于基于微调数据集调整初始编码模型,确定目标编码模型;The adjustment and determination module is used to adjust the initial coding model based on the fine-tuning dataset and determine the target coding model.

分块处理模块,用于根据所确定的文本块大小,对待输入文档进行分块处理,待输入文档基于在目标领域所收集的信息生成;The block processing module is used to block the input document according to the determined text block size. The input document is generated based on information collected in the target domain.

第一确定模块,用于将分块处理所得到的多个文本块输入目标编码模型,确定目标数据库。The first determining module is used to input the multiple text blocks obtained from the block processing into the target encoding model to determine the target database.

在本申请的一些实施例中,装置还包括:In some embodiments of this application, the apparatus further includes:

第二确定模块,用于基于初始编码模型所支持的最大词语数,确定块调整范围;The second determining module is used to determine the block adjustment range based on the maximum number of words supported by the initial encoding model;

第三确定模块,用于根据所构建的多条测试数据集,在块调整范围中确定文本块大小。The third determination module is used to determine the text block size within the block adjustment range based on the multiple test datasets constructed.

在本申请的一些实施例中,处理获取子模块包括:In some embodiments of this application, the processing acquisition submodule includes:

计算单元,用于遍历计算候选文本块集合中的两两第二文本块之间的相似度;The calculation unit is used to iterate through and calculate the similarity between each pair of second text blocks in the candidate text block set;

确定单元,用于根据相似度计算结果,确定目标文本块组,其中,任意两个第二文本块构成一文本块组,两个第二文本块的相似度大于预设阈值的文本块组为目标文本块组;The determining unit is used to determine the target text block group based on the similarity calculation result. 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.

去重单元,用于在目标文本块组中确定与用户请求问题的关联度低的第二文本块,将所确定的第二文本块删除,以进行第二文本块去重;The deduplication unit is used to identify a second text block in the target text block group 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;

第三获取单元,用于在对目标文本块组进行第二文本块去重之后,获取目标文本块集合;The third acquisition unit is used to acquire the target text block set after performing the second text block deduplication on the target text block group;

评估获取单元,用于对目标文本块集合中的第二文本块进行特征信息提取,并基于所提取的特征信息对第二文本块进行分数评估获取第二文本块对应的第一评分;The evaluation and acquisition unit is used to extract feature information from the second text block in the target text block set, and to evaluate the score of the second text block based on the extracted feature information to obtain the first score corresponding to the second text block;

排序确定单元,用于基于第二文本块对应的第一评分,在目标文本块集合中确定N个第一文本块。The sorting determination unit is used to determine N first text blocks in the target text block set based on the first score corresponding to the second text block.

在本申请的一些实施例中,排序确定单元进一步用于:In some embodiments of this application, the sorting determination unit is further configured to:

基于第二文本块对应的第一评分,对目标文本块集合中的第二文本块进行排序,确定排序结果,其中,第二文本块的排列次序与第二文本块对应的关联度正相关;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. The sorting order of the second text blocks is positively correlated with the relevance of the second text blocks.

基于排序结果,确定目标文本块集合中第一评分靠前的N个第二文本块,将N个第二文本块确定为N个第一文本块。Based on the sorting results, the N second text blocks with the highest first score in the target text block set are determined, and these N second text blocks are designated as N first text blocks.

在本申请的一些实施例中,评估获取单元进一步用于:In some embodiments of this application, the evaluation acquisition unit is further used for:

对第二文本块进行特征信息提取,获取第二文本块与用户请求问题的第一语义相似度、第二文本块与用户请求问题的前文的第二语义相似度以及文本质量中的至少一项;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's request question, the second semantic similarity between the second text block and the preceding text of the user's request question, and text quality.

基于第一语义相似度、第二语义相似度和文本质量中的至少一项进行分数评估,获取第二文本块对应的第一评分。The first score corresponding to the second text block is obtained by evaluating the score based on at least one of the first semantic similarity, the second semantic similarity, and the text quality.

在本申请的一些实施例中,分配获取模块包括:In some embodiments of this application, the allocation and acquisition module includes:

划分确定子模块,用于按照均衡分配原则,将N个第一文本块分为M份,确定每份第一文本块对应的预训练模型;The division and determination submodule is used to divide the N first text blocks into M parts according to the principle of balanced distribution, and determine the pre-trained model corresponding to each part of the first text block.

改写获取子模块,用于基于第一文本块与预训练模型的对应关系,将M份第一文本块并发输入对应的预训练模型进行文本改写,获取N个文本改写后的目标文本块。The rewrite acquisition submodule is used to rewrite the text by concurrently inputting M copies of the first text block into the corresponding pre-trained model based on the correspondence between the first text block and the pre-trained model, and obtaining N rewritten target text blocks.

在本申请的一些实施例中,处理获取模块进一步用于:In some embodiments of this application, the processing acquisition module is further used for:

在基于N个目标文本块、用户请求问题和用户对应的历史问答记录生成N个文本提示信息之后,基于第一文本块与预训练模型的对应关系,将N个文本提示信息并发输入对应的预训练模型,获取候选回复集合;After generating N text prompts based on N target text blocks, user request questions, and the user's corresponding historical question and answer records, the N text prompts are concurrently input into the corresponding pre-trained models based on the correspondence between the first text block and the pre-trained model to obtain a candidate response set.

其中,每个文本提示信息对应至少一个候选回复。Each text prompt corresponds to at least one candidate response.

在本申请的一些实施例中,评估选择模块包括:In some embodiments of this application, the evaluation selection module includes:

评估获取子模块,用于对候选回复进行回复忠实度、回复相关性和上下文相关性中的至少一项评估,获取至少一个第二评分;The evaluation acquisition submodule is used to evaluate candidate responses for at least one of response fidelity, response relevance, and contextual relevance, and to obtain at least one second score.

确定子模块,用于基于至少一个第二评分,确定候选回复对应的目标评分;The determination submodule is used to determine the target score corresponding to the candidate response based on at least one second score;

选择子模块,用于基于目标评分在候选回复集合对应的候选回复中选择与用户请求问题匹配的回复信息。The selection submodule is used to select the response information that matches the user's requested question from the candidate responses in the candidate response set based on the target score.

在本申请的一些实施例中,在对候选回复进行回复忠实度、回复相关性和上下文相关性中的至少一项进行评估时,基于候选回复对应的预训练模型对候选回复进行处理;In some embodiments of this application, when evaluating 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.

本申请实施例还提供了一种计算机程序产品,包括计算机程序/指令,该计算机程序/指令被处理器执行时实现上述文本生成方法实施例的各个过程,且能达到相同的技术效果,为避免重复,这里不再赘述。This application also provides a computer program product, including a computer program/instruction. When the computer program/instruction is executed by a processor, it implements the various processes of the above-described text generation method embodiments and can achieve the same technical effect. To avoid repetition, it will not be described again here.

本申请实施例还提供了一种电子设备,包括处理器、存储器及存储在存储器上并能够在处理器上运行的计算机程序,该计算机程序被处理器执行时实现上述文本生成方法实施例的各个过程,且能达到相同的技术效果,为避免重复,这里不再赘述。This application also provides an electronic device, including a processor, a memory, and a computer program stored in the memory and capable of running on the processor. When the computer program is executed by the processor, it implements the various processes of the above-described text generation method embodiments and achieves the same technical effect. To avoid repetition, it will not be described again here.

本申请实施例还提供了一种计算机非易失性可读存储介质,计算机非易失性可读存储介质上存储计算机程序,计算机程序被处理器执行时实现上述文本生成方法实施例的各个过程,且能达到相同的技术效果,为避免重复,这里不再赘述。This application also provides a computer non-volatile readable storage medium on which a computer program is stored. When the computer program is executed by a processor, it implements the various processes of the above-described text generation method embodiments and can achieve the same technical effect. To avoid repetition, it will not be described again here.

本说明书中的各个实施例均采用递进的方式描述,每个实施例重点说明的都是与其它实施例的不同之处,各个实施例之间相同相似的部分互相参见即可。The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other.

本领域内的技术人员应明白,本申请的实施例可提供为方法、装置、计算机程序产品、电子设备及存储介质。因此,本申请实施例可采用完全硬件实施例、完全软件实施例、或结合软件和硬件方面的实施例的形式。而且,本申请实施例可采用在一个或多个其中包含有计算机可用程序代码的计算机非易失性可读存储介质(包括但不限于磁盘存储器、CD-ROM、光学存储器等)上实施的计算机程序产品的形式。Those skilled in the art will understand that embodiments of this application can be provided as methods, apparatus, computer program products, electronic devices, and storage media. Therefore, embodiments of this application can take the form of entirely hardware embodiments, entirely software embodiments, or embodiments combining software and hardware aspects. Furthermore, embodiments of this application can take the form of computer program products embodied on one or more computer-non-volatile readable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

本申请实施例是参照根据本申请实施例方法、装置、计算机程序产品、电子设备及存储介质的流程图和/或方框图来描述的。应理解可由计算机程序指令实现流程图和/或方框图中的每一流程和/或方框、以及流程图和/或方框图中的流程和/或方框的结合。可提供这些计算机程序指令到通用计算机、专用计算机、嵌入式处理机或其它可编程数据处理终端设备的处理器以产生一个机器,使得通过计算机或其它可编程数据处理终端设备的处理器执行的指令产生用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的装置。这些计算机程序指令也可存储在能引导计算机或其它可编程数据处理终端设备以特定方式工作的计算机可读存储器中,使得存储在该计算机可读存储器中的指令产生包括指令装置的制造品,该指令装置实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能。这些计算机程序指令也可装载到计算机或其它可编程数据处理终端设备上,使得在计算机或其它可编程终端设备上执行一系列操作步骤以产生计算机实现的处理,从而在计算机或其它可编程终端设备上执行的指令提供用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的步骤。This application describes embodiments of methods, apparatus, computer program products, electronic devices, and storage media according to embodiments of this application using flowcharts and/or block diagrams. It should be understood that each block of the flowcharts and/or block diagrams, and combinations of blocks in the flowcharts and/or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing terminal equipment to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing terminal equipment, create means for implementing the functions specified in one or more flowchart blocks and/or one or more block diagrams. These computer program instructions can also be stored in a computer-readable storage medium capable of directing a computer or other programmable data processing terminal equipment to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means that implement the functions specified in one or more flowchart blocks and/or one or more block diagrams. These computer program instructions may also be loaded onto a computer or other programmable data processing terminal equipment to cause a series of operational steps to be performed on the computer or other programmable terminal equipment to produce a computer-implemented process, thereby providing steps for implementing the functions specified in one or more flowcharts and/or one or more block diagrams.

尽管已描述了本申请实施例的优选实施例,但本领域内的技术人员一旦得知了基本创造性概念,则可对这些实施例做出另外的变更和修改。所以,所附权利要求意欲解释为包括优选实施例以及落入本申请实施例范围的所有变更和修改。Although preferred embodiments of the present application have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments as well as all changes and modifications falling within the scope of the embodiments of the present application.

最后,还需要说明的是,在本文中,诸如第一和第二等之类的关系术语仅仅用来将一个实体或者操作与另一个实体或操作区分开来,而不一定要求或者暗示这些实体或操作之间存在任何这种实际的关系或者顺序。而且,术语“包括”或者其任何其它变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者终端设备不仅包括那些要素,而且还包括没有明确列出的其它要素,或者是还包括为这种过程、方法、物品或者终端设备所固有的要素。在没有更多限制的情况下,由语句“包括……”限定的要素,并不排除在包括要素的过程、方法、物品或者终端设备中还存在另外的相同要素。Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the term "comprising" or any other variations thereof is intended to cover non-exclusive inclusion, such that a process, method, article, or terminal device that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or terminal device. Without further limitations, an element defined by the phrase "comprising..." does not exclude the presence of other identical elements in the process, method, article, or terminal device that includes the element.

以上对本申请所提供的一种文本生成方法、装置、计算机程序产品、电子设备及介质进行了介绍,本文中应用了具体个例对本申请的原理及实施方式进行了阐述,以上实施例的说明只是用于帮助理解本申请的方法及其核心思想;同时,对于本领域的一般技术人员,依据本申请的思想,在具体实施方式及应用范围上均会有改变之处,综上,本说明书内容不应理解为对本申请的限制。The foregoing has described a text generation method, apparatus, computer program product, electronic device, and medium provided by this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.

Claims (20)

一种文本生成方法,其特征在于,包括:A text generation method, characterized by comprising: 获取与用户请求问题关联且满足预设条件的N个第一文本块,所述N个第一文本块基于多个维度的检索确定;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; 将所述N个第一文本块均衡地分配至M个预训练模型进行文本改写,获取N个目标文本块,M、N均为大于或者等于1的整数;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; 在确定所述N个目标文本块对应的N个文本提示信息后,基于所述M个预训练模型对所述N个文本提示信息进行处理获取候选回复集合,所述文本提示信息包括所述目标文本块、所述用户请求问题和用户对应的历史问答记录;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. 根据权利要求1所述的文本生成方法,其特征在于,所述获取与用户请求问题关联且满足预设条件的N个第一文本块,包括:The text generation method according to claim 1, characterized in that, obtaining N first text blocks associated with the user's request question and satisfying preset conditions includes: 在多个维度检索与所述用户请求问题的关联度符合语义相关要求的文本信息,获取包括K个第二文本块的候选文本块集合;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; 对所述候选文本块集合进行文本块去重、排序处理,获取所述N个第一文本块。The candidate text block set is subjected to text block deduplication and sorting processing to obtain the N first text blocks. 根据权利要求2所述的文本生成方法,其特征在于,所述在多个维度检索与所述用户请求问题的关联度符合语义相关要求的文本信息,获取包括K个第二文本块的候选文本块集合,包括:The text generation method according to claim 2, characterized in that, the step of retrieving text information whose relevance to the user request question meets the semantic relevance requirement in multiple dimensions, and obtaining a candidate text block set including K second text blocks, includes: 基于所述用户请求问题和用户对应的历史问答记录,获取关键词列表和对所述用户请求问题改写后的目标请求问题,所述关键词列表和所述目标请求问题基于对应的模型服务获取;Based on the user'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. 根据所述用户请求问题、所述目标请求问题和所述关键词列表在多个维度进行文本信息检索,获取所述K个第二文本块。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. 根据权利要求3所述的文本生成方法,其特征在于,所述根据所述用户请求问题、所述目标请求问题和所述关键词列表在多个维度进行文本信息检索,获取所述K个第二文本块,包括:The text generation method according to claim 3, characterized in that, the step of retrieving text information from 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; 在目标数据库中分别检索与各文本向量的语义关联度符合语义相关要求的文本块,以确定所述K个第二文本块;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. 根据权利要求4所述的文本生成方法,其特征在于,还包括:The text generation method according to claim 4, characterized in that it further 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. 根据权利要求5所述的文本生成方法,其特征在于,还包括:The text generation method according to claim 5, characterized in that it further 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. 根据权利要求2所述的文本生成方法,其特征在于,所述对所述候选文本块集合进行文本块去重、排序处理,获取所述N个第一文本块,包括:According to claim 2, the text generation method is characterized in that, the step of performing text block deduplication and sorting processing on the candidate text block set to obtain the N first text blocks includes: 遍历计算所述候选文本块集合中的两两第二文本块之间的相似度;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; 基于所述第二文本块对应的第一评分,在所述目标文本块集合中确定N个第一文本块。Based on the first score corresponding to the second text block, N first text blocks are determined in the target text block set. 根据权利要求7所述的文本生成方法,其特征在于,所述基于所述第二文本块对应的第一评分,在所述目标文本块集合中确定N个第一文本块,包括:The text generation method according to claim 7, characterized in that, 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; 基于所述排序结果,确定所述目标文本块集合中第一评分靠前的N个第二文本块,将所述N个第二文本块确定为所述N个第一文本块。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. 根据权利要求7所述的文本生成方法,其特征在于,所述对所述目标文本块集合中的第二文本块进行特征信息提取,并基于所提取的特征信息对所述第二文本块进行分数评估获取所述第二文本块对应的第一评分,包括: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 a 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. 根据权利要求1所述的文本生成方法,其特征在于,所述将所述N个第一文本块均衡地分配至M个预训练模型进行文本改写,获取N个目标文本块,包括:According to claim 1, the text generation method is 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: 按照均衡分配原则,将所述N个第一文本块分为M份,确定每份第一文本块对应的预训练模型;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. 基于第一文本块与预训练模型的对应关系,将M份第一文本块并发输入对应的预训练模型进行文本改写,获取N个文本改写后的目标文本块。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. 根据权利要求10所述的文本生成方法,其特征在于,所述基于所述M个预训练模型对所述N个文本提示信息进行处理获取候选回复集合,包括:According to the text generation method of claim 10, the step of processing the N text prompts based on the M pre-trained models to obtain a candidate response set includes: 在基于N个目标文本块、所述用户请求问题和用户对应的历史问答记录生成N个文本提示信息之后,基于第一文本块与预训练模型的对应关系,将所述N个文本提示信息并发输入对应的预训练模型,获取所述候选回复集合;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. 根据权利要求10或11所述的文本生成方法,其特征在于,所述基于评估策略对所述候选回复集合中的候选回复进行评估,选择与所述用户请求问题匹配的回复信息,包括:The text generation method according to claim 10 or 11, characterized in that, the step of evaluating the candidate responses in the candidate response set based on the evaluation strategy and selecting the response information that matches the user's request question 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. 根据权利要求12所述的文本生成方法,其特征在于,The text generation method according to claim 12 is 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. 根据权利要求13所述的文本生成方法,其特征在于,所述方法还包括: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. 根据权利要求1所述的文本生成方法,其特征在于,所述N个文本提示信息基于所述第一文本块与所述预训练模型的对应关系被均衡地分配至所述M个预训练模型。The text generation method according to claim 1 is characterized in that the N text prompts are evenly distributed to the M pre-trained models based on the correspondence between the first text block and the pre-trained model. 根据权利要求1所述的文本生成方法,其特征在于,所述文本提示信息基于所述目标文本块、所述用户请求问题和用户对应的历史问答记录的组合生成。The text generation method according to claim 1 is characterized in that the text prompt information is generated based on a combination of the target text block, the user request question, and the user's corresponding historical question and answer records. 一种文本生成装置,其特征在于,包括:A text generation device, characterized in that it comprises: 获取模块,被配置为获取与用户请求问题关联且满足预设条件的N个第一文本块,所述N个第一文本块基于多个维度的检索确定;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. 分配获取模块,被配置为将所述N个第一文本块均衡地分配至M个预训练模型进行文本改写,获取N个目标文本块,M、N均为大于或者等于1的整数;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; 处理获取模块,被配置为在确定所述N个目标文本块对应的N个文本提示信息后,基于所述M个预训练模型对所述N个文本提示信息进行处理获取候选回复集合,所述文本提示信息包括所述目标文本块、所述用户请求问题和用户对应的历史问答记录;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. 一种计算机程序产品,包括计算机程序/指令,其特征在于,该计算机程序/指令被处理器执行时实现权利要求1至16任一项所述的文本生成方法。A computer program product comprising a computer program/instructions, characterized in that, when executed by a processor, the computer program/instructions implement the text generation method according to any one of claims 1 to 16. 一种电子设备,其特征在于,包括处理器、存储器及存储在所述存储器上并能够在所述处理器上运行的计算机程序,该计算机程序被处理器执行时实现如权利要求1至16任一项所述的文本生成方法。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. 一种计算机非易失性可读存储介质,其特征在于,所述计算机非易失性可读存储介质上存储计算机程序,计算机程序被处理器执行时实现如权利要求1至16中任一项所述的文本生成方法。A computer non-volatile readable storage medium, characterized in that a computer program is stored on the computer non-volatile readable storage medium, and the computer program, when executed by a processor, implements the text generation method as described in any one of claims 1 to 16.
PCT/CN2025/101827 2024-06-26 2025-06-18 Text generation method and apparatus, computer program product, electronic device and medium Pending WO2026001792A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202410833500.7A CN118396123B (en) 2024-06-26 2024-06-26 Text generation method, device, computer program product, electronic device and medium
CN202410833500.7 2024-06-26

Publications (1)

Publication Number Publication Date
WO2026001792A1 true WO2026001792A1 (en) 2026-01-02

Family

ID=91995911

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2025/101827 Pending WO2026001792A1 (en) 2024-06-26 2025-06-18 Text generation method and apparatus, computer program product, electronic device and medium

Country Status (2)

Country Link
CN (1) CN118396123B (en)
WO (1) WO2026001792A1 (en)

Families Citing this family (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN118396123B (en) * 2024-06-26 2024-10-01 苏州元脑智能科技有限公司 Text generation method, device, computer program product, electronic device and medium
CN118966198A (en) * 2024-07-30 2024-11-15 南京新一代人工智能研究院有限公司 A low-cost retrieval enhancement generation evaluation method based on branch-joining
CN118733712B (en) * 2024-09-02 2024-11-22 安徽博诺思信息科技有限公司 Intelligent search method based on retrieval enhancement generation
US12367353B1 (en) 2024-12-06 2025-07-22 U.S. Bancorp, National Association Control parameter feedback protocol for adapting to data stream response feedback
CN119917634A (en) * 2025-01-24 2025-05-02 蚂蚁区块链科技(上海)有限公司 A method and device for generating an answer
CN120256623B (en) * 2025-03-17 2025-09-16 北京深言科技有限责任公司 Method and device for screening instruction-following data for large language model hallucination phenomenon

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20230023958A1 (en) * 2021-07-23 2023-01-26 International Business Machines Corporation Online question answering, using reading comprehension with an ensemble of models
CN117033613A (en) * 2023-08-18 2023-11-10 中航信移动科技有限公司 A method for generating response text, electronic device and storage medium
CN117521675A (en) * 2023-11-06 2024-02-06 腾讯科技(深圳)有限公司 Information processing method, device, equipment and storage medium based on large language model
CN117689027A (en) * 2023-12-25 2024-03-12 浙江清华长三角研究院 Prompt text generation method, device, electronic device and storage medium
US20240126795A1 (en) * 2022-10-14 2024-04-18 Oracle International Corporation Conversational document question answering
CN118396123A (en) * 2024-06-26 2024-07-26 苏州元脑智能科技有限公司 Text generation method, apparatus, computer program product, electronic device, and medium

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112765306B (en) * 2020-12-30 2024-06-07 金蝶软件(中国)有限公司 Intelligent question-answering method, intelligent question-answering device, computer equipment and storage medium
CN114416927B (en) * 2022-01-24 2024-04-02 招商银行股份有限公司 Intelligent question-answering method, device, equipment and storage medium
KR20230171234A (en) * 2022-06-13 2023-12-20 에스케이텔레콤 주식회사 Method for Providing Question-and-Answer Service Based on User Participation And Apparatus Therefor
CN117591639A (en) * 2023-10-20 2024-02-23 北京猎户星空科技有限公司 Question answering method, device, equipment and medium

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20230023958A1 (en) * 2021-07-23 2023-01-26 International Business Machines Corporation Online question answering, using reading comprehension with an ensemble of models
US20240126795A1 (en) * 2022-10-14 2024-04-18 Oracle International Corporation Conversational document question answering
CN117033613A (en) * 2023-08-18 2023-11-10 中航信移动科技有限公司 A method for generating response text, electronic device and storage medium
CN117521675A (en) * 2023-11-06 2024-02-06 腾讯科技(深圳)有限公司 Information processing method, device, equipment and storage medium based on large language model
CN117689027A (en) * 2023-12-25 2024-03-12 浙江清华长三角研究院 Prompt text generation method, device, electronic device and storage medium
CN118396123A (en) * 2024-06-26 2024-07-26 苏州元脑智能科技有限公司 Text generation method, apparatus, computer program product, electronic device, and medium

Also Published As

Publication number Publication date
CN118396123B (en) 2024-10-01
CN118396123A (en) 2024-07-26

Similar Documents

Publication Publication Date Title
WO2026001792A1 (en) Text generation method and apparatus, computer program product, electronic device and medium
CN112800170B (en) Question matching method and device, question answering method and device
CN112417846B (en) Text automatic generation method and device, electronic equipment and storage medium
CN118069815B (en) Large language model feedback information generation method and device, electronic equipment and medium
CN111159359A (en) Document retrieval method, apparatus, and computer-readable storage medium
CN120873195A (en) System and method for map-based dynamic information retrieval and synthesis
CN111666770B (en) Semantic matching method and device
CN120407737A (en) A multi-round dialogue generation method, device and medium based on RAG
Gupta et al. A novel approach to perform context‐based automatic spoken document retrieval of political speeches based on wavelet tree indexing
CN119357318A (en) Document retrieval method, device and storage medium
CN118643130A (en) Search method, device and medium based on vertical domain big model
CN118228824A (en) Knowledge question-answering method, knowledge question-answering device, electronic equipment and storage medium
CN112949293A (en) Similar text generation method, similar text generation device and intelligent equipment
CN114969001B (en) Database metadata field matching method, device, equipment and medium
US11194850B2 (en) Natural language query system
CN117593410A (en) Report generation method, device, electronic equipment and storage medium
CN119128117B (en) Intelligent reply method and device integrating large language model and knowledge graph
US12541543B2 (en) Large language model-based information retrieval for large datasets
CN119293196B (en) Question and answer method based on large language model and electronic equipment
US20250086215A1 (en) Large language model-based information retrieval for large datasets
CN110929527B (en) Method and device for determining semantic similarity
CN119106119A (en) Answering method and system based on question answering system
CN114579601A (en) Data generation method and device, computing equipment and medium
CN119961442A (en) An adaptive retrieval enhancement generation method based on topic filtering and iterative reasoning
CN119621902A (en) Question answering method and device based on large language model