Text query method and device, equipment and storage medium
By segmenting the text into blocks and building a text tree, combined with a pre-trained search model, the information processing problem in long document queries is solved, and more accurate text summary generation is achieved.
Patent Information
- Application Number
- CN202411453243.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-17
- Publication Date
- 2025-01-10
- Estimated Expiration
- 2044-10-17
AI Technical Summary
Existing text query methods are difficult to effectively process complex structures and information when processing long documents, resulting in inaccurate query results or missing key information.
By dividing text into multiple text blocks, clustering and constructing text trees, determining the identifiers of each text block, using a pre-trained search model to determine the index sequence of query problems in the text tree, and splicing text blocks to generate accurate text summary.
Improve the accuracy of text queries, ensure complete extraction and processing of information in long documents, and reduce the omission of query results.
Smart Images

Figure CN119293268A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present invention relate to the field of computer technology, and in particular to a text query method, apparatus, device and storage medium. Background Art
[0002] In the era of information explosion, facing massive amounts of data, effective ways are needed to help users retrieve, extract, and integrate information. Retrieval-Augmented Generation (RAG) is a model that combines retrieval and generation techniques. It retrieves relevant information from large document collections and uses this information to guide text generation.
[0003] In the prior art, the content required by the user can be searched in the document based on the RAG.
[0004] However, RAG often has difficulty in effectively processing the complex structure and information in long documents, which may lead to inaccurate query results or omission of key information. Summary of the invention
[0005] The present invention provides a text query method, device, equipment and storage medium to achieve the purpose of determining a text summary corresponding to a query question in a text and improve the query accuracy.
[0006] In a first aspect, an embodiment of the present invention provides a text query method, including:
[0007] After dividing the text into a plurality of text blocks, a text tree is constructed by clustering the text blocks, and an identifier of each text block in the text tree is determined;
[0008] Inputting a query question into a pre-trained retrieval model so that the retrieval model determines an index sequence corresponding to the query question in the text tree, wherein the retrieval model is trained based on multiple query questions corresponding to the text and index sequences of important sentences corresponding to the text;
[0009] A text summary corresponding to the query question is determined according to an index sequence corresponding to the query question in the text tree and the identifier of each text block in the text tree.
[0010] The technical solution of an embodiment of the present invention provides a text query method, comprising: after dividing a text into multiple text blocks, constructing a text tree by clustering the text blocks, and determining an identifier of each of the text blocks in the text tree; inputting a query question into a pre-trained retrieval model so that the retrieval model determines an index sequence corresponding to the query question in the text tree, wherein the retrieval model is trained based on multiple query questions corresponding to the text and index sequences of important sentences corresponding to the text; and determining a text summary corresponding to the query question based on the index sequence corresponding to the query question in the text tree and the identifier of each of the text blocks in the text tree. The above technical scheme can firstly divide the text into multiple text blocks by segmenting the text, and secondly cluster the text blocks, build a text tree according to the clustering results, and determine the identifier of each text block in the text tree. The text tree is constructed and the identifier of each text block in the text tree is determined according to the clustering results. The text tree retains the low-level details and high-level themes of the text. The identifier of each text block in the text tree provides a query basis for text query based on the text tree. The query question is input into a pre-trained retrieval model. The retrieval model can determine the index sequence corresponding to the query question in the text tree. By comparing the index sequence and the identifier of each text block in the text tree, the text block corresponding to the index sequence is determined at each layer in the text tree, and the text blocks are sequentially spliced to obtain a text summary, so as to achieve a more accurate text summary of the query question.
[0011] Furthermore, a text tree is constructed by clustering the text blocks, and an identifier of each text block in the text tree is determined, including:
[0012] The text blocks are clustered to divide the text blocks into at least two text block sets so that the aggregation loss of each text block set is minimized; when it is determined that the number of text blocks included in the text block set is greater than a quantity threshold, the text blocks included in the text block set are used as clustering objects, and the text blocks are clustered to divide the text blocks into at least two text block sets until the number of text blocks included in each text block set is no greater than the quantity threshold; the text tree is constructed according to the clustering result, and the identifier of each text block is determined in the text tree.
[0013] Furthermore, by clustering the text blocks, the text blocks are divided into at least two text block sets so as to minimize the aggregation loss of each text block set, including:
[0014] The text blocks are respectively divided into 2-N text block sets, and the aggregation losses corresponding to various division results are determined, wherein N is the number of the text blocks; and the division result corresponding to the minimum aggregation loss is determined as the target division result.
[0015] Furthermore, constructing the text tree according to the clustering result includes:
[0016] The first layer of the text tree is constructed according to the first clustering results of the text blocks, wherein the nodes of the text tree represent the sets of text blocks corresponding to the first clustering results; the next layer of the text tree is constructed in sequence according to the clustering results of the sets of text blocks containing a number of text blocks greater than the quantity threshold, until the number of text blocks contained in each set of text blocks is no greater than the quantity threshold, thereby obtaining the text tree.
[0017] Further, determining the identifier of each of the text blocks in the text tree includes:
[0018] A set number is assigned to each text block set at each layer in the text tree, a text number is assigned to each text block in each text block set, and the identifier of each text block is determined based on the text number of each text block and the set number of the text block set to which it belongs.
[0019] Furthermore, the training step of the retrieval model includes:
[0020] The texts used to construct the text tree are input multiple times into a pre-trained query question generation model so that the query question generation model determines multiple query questions corresponding to each of the texts; determines the important sentences corresponding to each of the texts, and determines the index sequence of the important sentences in the text tree; and performs model training using the query questions corresponding to each of the texts as training input and the index sequence corresponding to the important sentences corresponding to the texts as training output to obtain the retrieval model.
[0021] Further, determining a text summary corresponding to the query question according to the index sequence corresponding to the query question in the text tree and the identifier of each text block in the text tree includes:
[0022] Determine the text block corresponding to each index by comparing each index in the index sequence with the identifier of each text block in the text tree;
[0023] The text blocks corresponding to the indexes are sequentially spliced in the order of the indexes in the index sequence to obtain the text summary.
[0024] In a second aspect, an embodiment of the present invention further provides a text query device, including:
[0025] A segmentation module, used for segmenting the text into a plurality of text blocks, constructing a text tree by clustering the text blocks, and determining an index mark of each text block in the text tree;
[0026] A determination module, used for inputting a query question into a pre-trained retrieval model so that the retrieval model determines an index sequence corresponding to the query question in the text tree, wherein the retrieval model is trained based on multiple query questions corresponding to the text and index sequences of important sentences corresponding to the text;
[0027] The execution module is used to determine the text summary corresponding to the query question according to the index sequence corresponding to the query question in the text tree and the index identifier of each text block in the text tree.
[0028] In a third aspect, an embodiment of the present invention further provides an electronic device, the electronic device comprising:
[0029] at least one processor; and a memory communicatively coupled to the at least one processor;
[0030] The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the text query method as described in any one of the first aspects.
[0031] In a fourth aspect, an embodiment of the present invention further provides a storage medium comprising computer executable instructions, wherein the computer executable instructions are used to execute the text query method as described in any one of the first aspects when executed by a computer processor.
[0032] In a fifth aspect, the present application provides a computer program product, which includes computer instructions. When the computer instructions are executed on a computer, the computer executes the text query method provided in the first aspect.
[0033] It should be noted that the above computer instructions may be stored in whole or in part on a computer-readable storage medium, wherein the computer-readable storage medium may be packaged together with the processor of the text query device, or may be packaged separately from the processor of the text query device, which is not limited in this application.
[0034] The description of the second, third, fourth and fifth aspects in this application can refer to the detailed description of the first aspect; and the beneficial effects of the description of the second, third, fourth and fifth aspects can refer to the beneficial effect analysis of the first aspect, which will not be repeated here.
[0035] In this application, the name of the above-mentioned text query device does not limit the device or functional module itself. In actual implementation, these devices or functional modules may appear with other names. As long as the functions of each device or functional module are similar to those of this application, they fall within the scope of the claims of this application and their equivalent technologies.
[0036] These and other aspects of the present application will become more apparent from the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0038] Figure 1 A flowchart of a text query method provided by an embodiment of the present invention;
[0039] Figure 2 Generate a schematic diagram of the model structure for the query problem;
[0040] Figure 3 It is a schematic diagram of the structure of the model to be trained;
[0041] Figure 4 A schematic diagram of the structure of a text query device provided by an embodiment of the present invention;
[0042] Figure 5 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0043] The present invention will be further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are only used to explain the present invention, rather than to limit the present invention. It should also be noted that, for ease of description, only parts related to the present invention, rather than all structures, are shown in the accompanying drawings.
[0044] The term "and / or" in this article is merely a description of the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone.
[0045] The terms "first" and "second" and the like in the specification and drawings of this application are used to distinguish different objects, or to distinguish different processing of the same object, rather than to describe a specific order of objects.
[0046] In addition, the terms "including" and "having" and any variations thereof mentioned in the description of the present application are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but may optionally include other steps or units that are not listed, or may optionally include other steps or units that are inherent to these processes, methods, products or devices.
[0047] It should be mentioned before discussing exemplary embodiments in more detail that some exemplary embodiments are described as processes or methods depicted as flow charts. Although the flow charts describe various operations (or steps) as sequential processes, many operations therein can be implemented in parallel, concurrently or simultaneously. In addition, the order of various operations can be rearranged. The process can be terminated when its operation is completed, but can also have additional steps not included in the accompanying drawings. The process can correspond to methods, functions, procedures, subroutines, subprograms, etc. In addition, the embodiments in the present invention and the features in the embodiments can be combined with each other without conflict.
[0048] It should be noted that, in the embodiments of the present application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific way.
[0049] In the description of the present application, unless otherwise specified, “plurality” means two or more.
[0050] Natural Language Processing (NLP) is a branch of computer science that studies how to enable computers to understand and generate natural languages used by humans. The goal of natural language processing is to enable computers to communicate with humans fluently, accurately, and intelligently, thereby improving human life and work efficiency. Natural language processing involves many aspects, such as speech recognition, speech synthesis, text analysis, text generation, machine translation, question-and-answer systems, dialogue systems, etc. In terms of text generation, it is necessary to generate natural language text based on given information or goals, such as machine translation, text summarization, question-and-answer systems, dialogue systems, etc. In this way, text can be used for communication and expression, and new text content can also be created.
[0051] RAG is a model that combines retrieval and generation techniques. It generates answers or content by referencing information from an external knowledge base. It has strong interpretability and customization capabilities and is suitable for text generation. RAG works by retrieving relevant information from a large-scale document collection and then using this information to guide text generation, thereby improving the quality and accuracy of predictions. Specifically, RAG achieves text generation through three key parts: retrieval, utilization, and generation. In the retrieval stage, RAG retrieves relevant information from the document collection; in the utilization stage, RAG uses the retrieved information to fill in the text or answer questions; in the generation stage, RAG generates the final text content based on the retrieved knowledge.
[0052] However, RAG can only process shorter text fragments and has limitations when processing long documents. Text query based on RAG may lead to inaccurate query results or omission of key information.
[0053] Therefore, this application proposes a text query method to improve query accuracy.
[0054] The text query method proposed in this application will be described in detail below with reference to diagrams and embodiments.
[0055] Figure 1 A flowchart of a text query method provided by an embodiment of the present invention is provided. This embodiment can be applied to situations where it is necessary to determine a text summary corresponding to a query question in a text to improve query accuracy. The method can be executed by a text query device, such as Figure 1 As shown, the specific steps include:
[0056] Step 110: Segment the text into multiple text blocks.
[0057] The text can be understood as a text set, which is composed of a large number of long texts and short texts. The text block contains no more than Q words, where Q is a natural number. The specific value of Q can be set according to actual needs and is not specifically limited here.
[0058] Specifically, the text can be segmented to divide the text into continuous text blocks (chunks nodes). Specifically, first, each text can be segmented based on a word segmentation algorithm, and secondly, starting from the starting word of each text, Q words can be taken as a text block to achieve text segmentation while maintaining semantic coherence.
[0059] In the embodiment of the present invention, the text is segmented into a plurality of text blocks by segmenting the text.
[0060] Step 120: cluster the text blocks to divide the text blocks into at least two text block sets, so as to minimize the aggregation loss of each text block set.
[0061] In one implementation, step 120 may specifically include:
[0062] The text blocks are divided into 2-N text block sets respectively, and the aggregation loss corresponding to various division results is determined, where N is the number of text blocks; the division result corresponding to the minimum aggregation loss is determined as the target division result.
[0063] Specifically, firstly, the text blocks can be vectorized, that is, each text block can be embedded (a technology that maps discrete data to continuous vectors) based on an embedding algorithm to generate a text vector corresponding to each text block. Specifically, the text vector corresponding to each text block can be determined based on term frequency-inverse document frequency (TF-IDF), word to vector (Word2Vec) or bidirectional encoder representation (BERT). Secondly, the text blocks can be clustered based on the feature dimension of the text vector corresponding to each text block. The feature dimension is determined according to the embedding algorithm used for vectorizing the text blocks. Specifically, the text blocks are first divided into two text block sets, and the aggregation loss after being divided into two text block sets is calculated. Then, the text blocks are divided into three text block sets, and the aggregation loss after being divided into three text block sets is calculated. And so on, until the text blocks are divided into N text block sets, and the aggregation loss after being divided into N text block sets is calculated.
[0064] For example, if the text blocks are divided into two text block sets A and B, we can determine C = (A, B), where C represents the set of all text blocks, A∈C, B∈C, Calculate the aggregation loss after dividing into two text block sets A and B. Since the aggregation between the two text block sets A and B is lost after dividing the text block into two text block sets A and B, it can be determined in, Represents a text block X i Belongs to A, text block X j Belongs to B,u ij Represents a text block x i and the text block x j The degree of aggregation between ij It can be determined based on the aggregation degree matrix corresponding to the text block.
[0065] Divide the text block into m text block sets, and then determine C = (C1, C2, C3, C4, C5, ... Cm), where C1∈C, C2∈C, C3∈C, C4∈C, C5∈C, ..., Cm∈C, Calculate the aggregation loss after dividing into m text blocks, that is, to determine
[0066] It should be noted that the steps for determining the aggregation matrix corresponding to the text block are as follows: for N text blocks, firstly, an NxN matrix is constructed, and each element in the matrix represents the aggregation degree between each text block. Secondly, the Score matrix can be calculated based on the formula ij =V T tanh(W p p i +W t t j ) calculates the similarity between each text block, where V T is the transformation matrix, p i Represents a text block x i The corresponding text vector, t j Represents a text block x j The corresponding text vector, W p Represents a text block x i The corresponding transformation parameter, W t Represents a text block x j For the corresponding transformation parameters, if the similarity is greater than a preset threshold, this value is recorded based on the corresponding element in the matrix, otherwise, the corresponding element in the matrix is set to 0 or other values indicating low aggregation.
[0067] Furthermore, the aggregation losses corresponding to the division results are compared, and the division result corresponding to the minimum aggregation loss is determined as the target division result. The text block is divided according to the target division result, that is, the text block can be divided into at least two text block sets. At this time, the division method minimizes the aggregation loss.
[0068] In the embodiment of the present invention, the text blocks are clustered to divide the text blocks into at least two text block sets.
[0069] Step 130: Determine whether the number of text blocks included in each text block set is not greater than a quantity threshold.
[0070] If it is determined that the number of text blocks included in each text block set is not greater than the quantity threshold, step 140 is executed; otherwise, the text blocks included in the text block set are taken as clustering objects, and the process returns to step 120 .
[0071] Specifically, after dividing the text blocks into at least two text block sets, the number of text blocks contained in each text block set can be determined. If the number of text blocks contained in any text block set is greater than the quantity threshold, the text blocks contained in the text block set are used as clustering objects, and the process returns to step 120 until the number of text blocks contained in each text block set is no greater than the quantity threshold, thereby achieving clustering of the text blocks.
[0072] Step 140: construct a text tree according to the clustering results, and determine the identifier of each text block in the text tree.
[0073] In one implementation, step 140 may specifically include:
[0074] The first layer of the text tree is constructed according to the first clustering results of the text blocks, wherein the nodes of the text tree represent the text block sets corresponding to the first clustering results; the next layer of the text tree is constructed in turn according to the clustering results of the text block sets whose number of included text blocks is greater than the quantity threshold, until the number of text blocks included in each text block set is no greater than the quantity threshold, thereby obtaining a text tree; a set number is assigned to each text block set in each layer of the text tree, a text number is assigned to each text block in each text block set, and an identifier of each text block is determined according to the text number of each text block and the set number of the text block set to which it belongs.
[0075] Specifically, firstly, the first layer of the text tree can be constructed according to the text block sets divided by the first clustering results of the text blocks, that is, the text block sets corresponding to the first clustering results can be used as nodes of the text tree to construct the first layer. At this time, a set number can be assigned to each text block set corresponding to the first layer node, and a text number can be assigned to each text block in each text block set whose number of text blocks is not greater than the number threshold. Secondly, the next layer of the text tree can be constructed according to the clustering results of each text block set whose number of text blocks is greater than the number threshold. At this time, a set number can also be assigned to each text block set corresponding to the node of this layer, and a text number can be assigned to each text block in each text block set whose number of text blocks is not greater than the number threshold. Repeat the construction of the next layer of the text tree according to the clustering results of each text block set whose number of text blocks is greater than the number threshold, assign a set number to each text block set corresponding to the node of this layer, and assign a text number to each text block in each text block set whose number of text blocks is not greater than the number threshold, until all text blocks are added to the text tree.
[0076] In practical applications, a text tree can be constructed in the process of clustering text blocks, that is, after the first clustering is completed, the first layer of the text tree is constructed according to the first clustering result, and the remaining layers of the text tree are constructed in turn according to subsequent clustering results until all text blocks are added to the text tree.
[0077] Of course, when constructing the text tree, the identifier of each text block can be determined according to the set number of each text set and the text number of each text block. The identifier of the text block can indicate the location of the text block in the text tree, which is convenient for text retrieval. It can be understood that text blocks with high similarity have identifiers with the same prefix.
[0078] In an embodiment of the present invention, text blocks are clustered to divide the text blocks into at least two text block sets, and a text tree is constructed and an identifier of each text block in the text tree is determined based on the clustering results. The text tree retains the low-level details and high-level themes of the text, and the identifier of each text block in the text tree provides a query basis for text query based on the text tree.
[0079] Step 150: Input the query question into the pre-trained retrieval model so that the retrieval model determines the index sequence corresponding to the query question in the text tree.
[0080] Among them, the retrieval model is trained based on multiple query questions corresponding to the text and the index sequence of important sentences corresponding to the text.
[0081] In one implementation, the training step of the retrieval model includes:
[0082] The texts used to construct the text tree are input multiple times into a pre-trained query question generation model so that the query question generation model determines multiple query questions corresponding to each text; determines the important sentences corresponding to each text, and determines the index sequence corresponding to the important sentences in the text tree; uses the multiple query questions corresponding to each text as training input and the index sequence corresponding to the important sentences corresponding to the text as training output to train the model and obtain a retrieval model.
[0083] Figure 2 A schematic diagram of the model generated for the query problem, such as Figure 2 As shown, the query generation model consists of TransformerEncoder and TransformerDecoder. The input of TransformerEncoder is a document that hides a preset number of words (X1, X2 in the figure) based on random rules and hides a preset number of sentences (Y in the figure) based on high-scoring rules. The output is the hidden words. The input of TransformerDecoder is the document and the hidden words. The output is the hidden sentences, which are the query questions. The query generation model is trained based on the training documents and the query questions corresponding to the training documents, and can be used to determine the query questions corresponding to the documents.
[0084] Each text used to construct the text tree is input multiple times into a pre-trained query generation model. Since the decoding strategy of the query generation model is a random strategy, multiple different but related query vectors can be generated by inputting the same text multiple times into the query generation model.
[0085] The important sentences corresponding to the text can be understood as a preset number of sentences with the highest similarity to other sentences in the text. Specifically, a preset number of sentences are extracted from all the sentences in the text. The text includes n sentences. When the preset number is m, there are C N M For each extraction method, the similarity between the extracted sentence and the remaining sentences is calculated and summed, and the sentence extracted by the extraction method corresponding to the maximum sum value is determined as an important sentence. Furthermore, the index sequence of the important sentences corresponding to each text can be determined in the text tree.
[0086] Figure 3 is a schematic diagram of the model to be trained, such as Figure 3 As shown in the figure, the model to be trained consists of a Transformer Encoder and a Transformer Decoder. The Transformer Encoder uses a standard transformer layer, which consists of N transformer blocks. Its input is the query question corresponding to the text, and its output is the feature vector of the query question. The Transformer Decoder uses a standard transformer decode layer, which consists of M transformer blocks. Its input is the feature vector of the query question, and its output is the index sequence of the important sentences corresponding to the text, that is, it can be determined Among them, idx i Represents a text block x i The i-th word in the query, X represents the output of Transformer Encoder, that is, the feature vector of the query question; W represents all parameters; W i Represents the parameters of the i-th step.
[0087] In order to obtain a consistent regular representation, for two index sequences predicted for the same query problem, the minimum bidirectional KL divergence can be determined. Specifically, the minimum bidirectional KL divergence can be determined based on the following formula: Then, we can construct a loss function based on minimizing the bidirectional KL divergence. That is, we can determine the loss function as:
[0089]
[0090] in, The cross entropy loss used to determine the predicted index sequence, E(q) represents the probability of the index sequence of important sentences corresponding to the text output by the model when the query question corresponding to the text is used as the model input, γ∑ i Loss idx i A consistent regular representation of different index sequences predicted for the same query.
[0091] The query questions corresponding to each text are used as training inputs, and the index sequences corresponding to the important sentences of each text are used as training outputs to train the model to be trained. When the loss function converges, the retrieval model is obtained. The query questions are input into the retrieval model, and the retrieval model can output the index sequence corresponding to the query questions in the text tree.
[0092] It should be noted that each query question corresponding to the text and the index sequence corresponding to the corresponding important sentences can be used as positive samples, and each query question corresponding to the text and the random index sequence can be used as negative samples to train the model to be trained.
[0093] In the embodiment of the present invention, it is achieved to determine the index sequence corresponding to the query question in the text tree according to the retrieval model.
[0094] Step 160: Determine the text summary corresponding to the query question according to the index sequence corresponding to the query question in the text tree and the identifier of each text block in the text tree.
[0095] In one implementation, step 160 may specifically include:
[0096] By comparing the identifiers of each index in the index sequence and each text block in the text tree, the text block corresponding to each index is determined; the text blocks corresponding to each index are sequentially spliced in the order of each index in the index sequence to obtain a text summary.
[0097] The index sequence is composed of multiple indexes arranged in sequence.
[0098] Specifically, after determining the index sequence, for each index constituting the index sequence, the identifier of the text block corresponding to each node of the corresponding layer of the text tree can be compared, and the text block corresponding to the identifier consistent with the index is determined as the text block corresponding to the index, until the text blocks corresponding to all indexes are determined. Then, the text blocks corresponding to each index are sequentially spliced in the order of each index in the index sequence, and the text summary can be obtained.
[0099] In practical applications, the cosine similarity between the text block corresponding to each node in each layer and the query question can be determined at each layer, and the text block corresponding to the maximum cosine similarity can be determined as the target text block corresponding to the layer. Of course, the target text block corresponding to each layer can be determined starting from the root node of the text tree, or starting from the bottom layer of the text tree. The target text blocks corresponding to each layer are connected in hierarchical order to obtain the query result corresponding to the query question. If the query result corresponding to the query question is inconsistent with the text summary, the index sequence corresponding to the query result corresponding to the query question is used as a positive sample, and the index sequence corresponding to the text summary corresponding to the query question is used as a negative sample to continue to optimize the retrieval model.
[0100] In an embodiment of the present invention, by comparing the sequences of index sequences corresponding to the query question in the text tree and the identifiers of the text blocks in the text tree, the text blocks corresponding to the indexes are determined at each layer in the text tree, and the text blocks corresponding to the indexes are concatenated to obtain a text summary, thereby determining a more accurate text summary of the query question.
[0101] The text query method provided by the embodiment of the present invention includes: firstly, dividing the text into multiple text blocks by dividing the text, and secondly, dividing the text blocks into at least two text block sets by clustering the text blocks, and the aggregation loss of each text block set after the division is minimized, determining the number of text blocks contained in each text block set, if the number of text blocks contained in the text block set is greater than the number threshold, taking the text blocks contained in the text block set as clustering objects, returning to execute clustering of the text blocks, dividing the text blocks into at least two text block sets, until the number of text blocks contained in each text block set is no greater than the number threshold, constructing a text tree according to the clustering result, and determining each text block. The identifiers in the text tree are used to construct the text tree and determine the identifiers of each text block in the text tree based on the clustering results. The text tree retains the low-level details and high-level themes of the text. The identifiers of each text block in the text tree provide a query basis for text queries based on the text tree. The query question is input into a pre-trained retrieval model, and the retrieval model can determine the index sequence corresponding to the query question in the text tree. By comparing the sequences of the index sequences corresponding to the query question in the text tree and the identifiers of each text block in the text tree, the text blocks corresponding to each index are determined at each layer in the text tree, and the text blocks corresponding to each index are concatenated to obtain a text summary, thereby determining a more accurate text summary of the query question.
[0102] Figure 4This is a schematic diagram of the structure of a text query device provided by an embodiment of the present invention, which can be applied to situations where it is necessary to determine a text summary corresponding to a query question in a text to improve query accuracy. The device can be implemented by software and / or hardware and is generally integrated in an electronic device, such as a computer device.
[0103] like Figure 4 As shown, the device comprises:
[0104] A segmentation module 410 is used to segment the text into multiple text blocks, construct a text tree by clustering the text blocks, and determine an identifier of each text block in the text tree;
[0105] A determination module 420 is used to input a query question into a pre-trained retrieval model so that the retrieval model determines an index sequence corresponding to the query question in the text tree, wherein the retrieval model is trained based on multiple query questions corresponding to the text and index sequences of important sentences corresponding to the text;
[0106] The execution module 430 is used to determine the text summary corresponding to the query question according to the index sequence corresponding to the query question in the text tree and the identifier of each text block in the text tree.
[0107] The text query device provided in this embodiment divides the text into multiple text blocks, constructs a text tree by clustering the text blocks, and determines the identifier of each text block in the text tree; inputs the query question into a pre-trained retrieval model so that the retrieval model determines the index sequence corresponding to the query question in the text tree, wherein the retrieval model is trained based on multiple query questions corresponding to the text and the index sequence of important sentences corresponding to the text; and determines the text summary corresponding to the query question based on the index sequence corresponding to the query question in the text tree and the identifier of each text block in the text tree. The above technical scheme can firstly divide the text into multiple text blocks by segmenting the text, and secondly cluster the text blocks, build a text tree according to the clustering results, and determine the identifier of each text block in the text tree. The text tree is constructed and the identifier of each text block in the text tree is determined according to the clustering results. The text tree retains the low-level details and high-level themes of the text. The identifier of each text block in the text tree provides a query basis for text query based on the text tree. The query question is input into a pre-trained retrieval model. The retrieval model can determine the index sequence corresponding to the query question in the text tree. By comparing the index sequence and the identifier of each text block in the text tree, the text block corresponding to the index sequence is determined at each layer in the text tree, and the text blocks are sequentially spliced to obtain a text summary, so as to achieve a more accurate text summary of the query question.
[0108] Based on the above embodiment, the segmentation module 410 is specifically used for:
[0109] The text is divided into a plurality of text blocks; the text blocks are divided into at least two text block sets by clustering the text blocks, so that the aggregation loss of each text block set is minimized; when it is determined that the number of text blocks included in the text block set is greater than a quantity threshold, the text blocks included in the text block set are used as clustering objects, and the text blocks are returned to be clustered to divide the text blocks into at least two text block sets until the number of text blocks included in each text block set is no greater than the quantity threshold; the text tree is constructed according to the clustering result, and the identifier of each text block is determined in the text tree.
[0110] In one implementation, clustering the text blocks to divide the text blocks into at least two text block sets so as to minimize the aggregation loss of each text block set includes:
[0111] The text blocks are respectively divided into 2-N text block sets, and the aggregation losses corresponding to various division results are determined, wherein N is the number of the text blocks; and the division result corresponding to the minimum aggregation loss is determined as the target division result.
[0112] In one implementation, constructing the text tree according to the clustering results includes:
[0113] The first layer of the text tree is constructed according to the first clustering results of the text blocks, wherein the nodes of the text tree represent the sets of text blocks corresponding to the first clustering results; the next layer of the text tree is constructed in sequence according to the clustering results of the sets of text blocks containing a number of text blocks greater than the quantity threshold, until the number of text blocks contained in each set of text blocks is no greater than the quantity threshold, thereby obtaining the text tree.
[0114] In one implementation, determining the identifier of each text block in the text tree includes:
[0115] A set number is assigned to each text block set at each layer in the text tree, a text number is assigned to each text block in each text block set, and the identifier of each text block is determined based on the text number of each text block and the set number of the text block set to which it belongs.
[0116] Based on the above embodiment, the device further includes:
[0117] The training module is used to input the texts used to construct the text tree into a pre-trained query question generation model multiple times, so that the query question generation model determines multiple query questions corresponding to each of the texts; determines the important sentences corresponding to each of the texts, and determines the index sequence of the important sentences in the text tree; uses the query questions corresponding to each of the texts as training input and the index sequence corresponding to the important sentences corresponding to the texts as training output to perform model training to obtain the retrieval model.
[0118] Based on the above embodiment, the execution module 430 is specifically used for:
[0119] The text blocks corresponding to the indexes are determined by comparing the indexes in the index sequence with the identifiers of the text blocks in the text tree; the text blocks corresponding to the indexes are sequentially spliced in the order of the indexes in the index sequence to obtain the text summary.
[0120] The text query device provided in the embodiment of the present invention can execute the text query method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of executing the text query method.
[0121] It is worth noting that in the embodiment of the above-mentioned text query device, the various units and modules included are only divided according to functional logic, but are not limited to the above-mentioned division, as long as the corresponding functions can be achieved; in addition, the specific names of the functional units are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of the present invention.
[0122] Figure 5 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. Figure 5 A block diagram of an exemplary electronic device 5 suitable for implementing embodiments of the present invention is shown. Figure 5 The electronic device 5 shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0123] like Figure 5 As shown, the electronic device 5 is in the form of a general purpose computing electronic device. The components of the electronic device 5 may include, but are not limited to: one or more processors or processing units 16, a system memory 28, and a bus 18 connecting different system components (including the system memory 28 and the processing unit 16).
[0124] Bus 18 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor or a local bus using any of a variety of bus architectures. By way of example, these architectures include, but are not limited to, an Industry Standard Architecture (ISA) bus, a Micro Channel Architecture (MAC) bus, an Enhanced ISA bus, a Video Electronics Standards Association (VESA) local bus, and a Peripheral Component Interconnect (PCI) bus.
[0125] The electronic device 5 typically includes a variety of computer system readable media. These media can be any available media that can be accessed by the electronic device 5, including volatile and non-volatile media, removable and non-removable media.
[0126] The system memory 28 may include computer system readable media in the form of volatile memory, such as random access memory (RAM) 30 and / or cache memory 32. The electronic device 5 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, the storage system 34 may be used to read and write non-removable, non-volatile magnetic media ( Figure 5 not shown, usually called a "hard drive"). Although Figure 5 Not shown in the figure, a disk drive for reading and writing to a removable non-volatile disk (e.g., a "floppy disk"), and an optical disk drive for reading and writing to a removable non-volatile optical disk (e.g., a CD-ROM, a DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to the bus 18 via one or more data medium interfaces. The system memory 28 may include at least one program product having a set (e.g., at least one) of program modules that are configured to perform the functions of the various embodiments of the present invention.
[0127] A program / utility 40 having a set (at least one) of program modules 42 may be stored, for example, in system memory 28, such program modules 42 including, but not limited to, an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment. Program modules 42 generally perform the functions and / or methods of the embodiments described herein.
[0128] The electronic device 5 may also communicate with one or more external devices 14 (e.g., keyboards, pointing devices, displays 24, etc.), one or more devices that enable a user to interact with the electronic device 5, and / or any device that enables the electronic device 5 to communicate with one or more other computing devices (e.g., network cards, modems, etc.). Such communication may be performed via an input / output (I / O) interface 22. Furthermore, the electronic device 5 may also communicate with one or more networks (e.g., a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) via a network adapter 20. Figure 5 As shown, the network adapter 20 communicates with other modules of the electronic device 5 via the bus 18. It should be understood that although Figure 5 Not shown, other hardware and / or software modules may be used in conjunction with the electronic device 5, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0129] The processing unit 16 executes various functional applications and page displays by running the program stored in the system memory 28, for example, implementing the text query method provided by the embodiment of the present invention, which includes:
[0130] After dividing the text into a plurality of text blocks, a text tree is constructed by clustering the text blocks, and an identifier of each text block in the text tree is determined;
[0131] Inputting a query question into a pre-trained retrieval model so that the retrieval model determines an index sequence corresponding to the query question in the text tree, wherein the retrieval model is trained based on multiple query questions corresponding to the text and index sequences of important sentences corresponding to the text;
[0132] A text summary corresponding to the query question is determined according to an index sequence corresponding to the query question in the text tree and the identifier of each text block in the text tree.
[0133] Of course, those skilled in the art can understand that the processor can also implement the technical solution of the text query method provided by any embodiment of the present invention.
[0134] An embodiment of the present invention provides a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, for example, a text query method provided by an embodiment of the present invention is implemented. The method includes:
[0135] After dividing the text into a plurality of text blocks, a text tree is constructed by clustering the text blocks, and an identifier of each text block in the text tree is determined;
[0136] Inputting a query question into a pre-trained retrieval model so that the retrieval model determines an index sequence corresponding to the query question in the text tree, wherein the retrieval model is trained based on multiple query questions corresponding to the text and index sequences of important sentences corresponding to the text;
[0137] A text summary corresponding to the query question is determined according to an index sequence corresponding to the query question in the text tree and the identifier of each text block in the text tree.
[0138] The computer storage medium of the embodiment of the present invention can adopt any combination of one or more computer-readable media. The computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. The computer-readable storage medium can be, for example, but not limited to: an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples (non-exhaustive list) of computer-readable storage media include: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this document, a computer-readable storage medium can be any tangible medium containing or storing a program, which can be used by an instruction execution system, device or device or used in combination with it.
[0139] Computer-readable signal media may include data signals propagated in baseband or as part of a carrier wave, which carry computer-readable program code. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0140] The program code embodied on the computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
[0141] Computer program code for performing the operations of the present invention may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0142] It should be understood by those skilled in the art that the modules or steps of the present invention described above can be implemented by a general-purpose computing device, they can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices, optionally, they can be implemented by a program code executable by a computer device, so that they can be stored in a storage device and executed by the computing device, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. Thus, the present invention is not limited to any specific combination of hardware and software.
[0143] In addition, the acquisition, storage, use, and processing of data in the technical solution of the present invention are in compliance with the relevant provisions of national laws and regulations.
[0144] Note that the above are only preferred embodiments of the present invention and the technical principles used. Those skilled in the art will understand that the present invention is not limited to the specific embodiments herein, and that various obvious changes, readjustments and substitutions can be made by those skilled in the art without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in more detail through the above embodiments, the present invention is not limited to the above embodiments, and may include more other equivalent embodiments without departing from the concept of the present invention, and the scope of the present invention is determined by the scope of the appended claims.
Claims
1. A text query method, characterized in that: include: After dividing the text into a plurality of text blocks, a text tree is constructed by clustering the text blocks, and an identifier of each text block in the text tree is determined; Inputting a query question into a pre-trained retrieval model so that the retrieval model determines an index sequence corresponding to the query question in the text tree, wherein the retrieval model is trained based on multiple query questions corresponding to the text and index sequences of important sentences corresponding to the text; A text summary corresponding to the query question is determined according to an index sequence corresponding to the query question in the text tree and the identifier of each text block in the text tree.
2. The text query method according to claim 1, characterized in that: Constructing a text tree by clustering the text blocks and determining an identifier of each text block in the text tree, including: By clustering the text blocks, the text blocks are divided into at least two text block sets, so that the aggregation loss of each text block set is minimized; In the case where it is determined that the number of text blocks included in the text block set is greater than the number threshold, the text blocks included in the text block set are used as clustering objects, and the process returns to execute clustering of the text blocks to divide the text blocks into at least two text block sets until the number of text blocks included in each of the text block sets is no greater than the number threshold; The text tree is constructed according to the clustering result, and the identifier of each text block is determined in the text tree.
3. The text query method according to claim 2, characterized in that: The text blocks are clustered to divide the text blocks into at least two text block sets so as to minimize the aggregation loss of each text block set, including: Divide the text blocks into 2-N text block sets respectively, and determine the aggregation loss corresponding to various division results, where N is the number of the text blocks; The division result corresponding to the minimum aggregation loss is determined as the target division result.
4. The text query method according to claim 2, characterized in that: Constructing the text tree according to the clustering result includes: Constructing a first layer of the text tree according to the first clustering result of the text blocks, wherein the nodes of the text tree represent the sets of the text blocks corresponding to the first clustering result; The next layer of the text tree is constructed in sequence according to the clustering results of each of the text block sets containing text blocks whose number is greater than the number threshold, until the number of text blocks contained in each of the text block sets is no greater than the number threshold, thereby obtaining the text tree.
5. The text query method according to claim 4, characterized in that: Determining the identifier of each of the text blocks in the text tree includes: A set number is assigned to each text block set at each layer in the text tree, a text number is assigned to each text block in each text block set, and the identifier of each text block is determined based on the text number of each text block and the set number of the text block set to which it belongs.
6. The text query method according to claim 1, characterized in that: The training steps of the retrieval model include: Inputting each text used to construct the text tree into a pre-trained query generation model multiple times, so that the query generation model determines multiple query questions corresponding to each text; Determining important sentences corresponding to each of the texts, and determining index sequences of the important sentences in the text tree; The retrieval model is obtained by performing model training using query questions corresponding to the texts as training inputs and index sequences corresponding to important sentences in the texts as training outputs.
7. The text query method according to claim 1, characterized in that: Determining a text summary corresponding to the query question according to an index sequence corresponding to the query question in the text tree and the identifier of each text block in the text tree includes: Determine the text block corresponding to each index by comparing each index in the index sequence with the identifier of each text block in the text tree; The text blocks corresponding to the indexes are sequentially spliced in the order of the indexes in the index sequence to obtain the text summary.
8. A text query device, characterized in that: include: A segmentation module, configured to segment the text into a plurality of text blocks, construct a text tree by clustering the text blocks, and determine an identifier of each text block in the text tree; A determination module, used for inputting a query question into a pre-trained retrieval model so that the retrieval model determines an index sequence corresponding to the query question in the text tree, wherein the retrieval model is trained based on multiple query questions corresponding to the text and index sequences of important sentences corresponding to the text; An execution module is used to determine a text summary corresponding to the query question according to an index sequence corresponding to the query question in the text tree and the identifier of each text block in the text tree.
9. An electronic device, characterized in that: The electronic device comprises: at least one processor; and a memory communicatively coupled to the at least one processor; The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the text query method as described in any one of claims 1-7.
10. A storage medium containing computer executable instructions, characterized in that: When the computer executable instructions are executed by a computer processor, they are used to execute the text query method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Specification content query method and device, electronic equipment and storage medium
CN112579743A
Question and answer query method and device, computing equipment and computer readable storage medium
CN117094401A
Retrieval question and answer method, system and equipment and medium
CN117708309A
Method for improving answer accuracy for generative ai-based multiple questions
KR102711560B1
Method for recommending text content based on concern, and computer device
US20180373787A1
Cited By
Conference summary system and method based on KD tree fragmentation
CN120690204A