Question answering method, device, storage medium and electronic device based on model knowledge base
By combining the single-channel algorithm and the K-means clustering algorithm to segment and recall documents, the problems of segmentation efficiency and recall accuracy of the generative intelligent question-answering system in specific fields are solved, achieving more efficient semantic understanding and accurate question-answering effects.
Patent Information
- Application Number
- CN202411705779.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-26
- Publication Date
- 2025-09-30
- Estimated Expiration
- 2044-11-26
AI Technical Summary
Existing generative intelligent question-answering systems based on pre-trained models have problems with low segmentation efficiency, low precision, and inaccurate context recall when dealing with specific fields, resulting in low question-answering accuracy.
A method combining a single-channel algorithm and a K-means clustering algorithm is used to perform preliminary segmentation and fine-grained semantic matching on documents, build a model knowledge base, use a multi-way recall mechanism to obtain candidate content, and generate answers by integrating relevance ranking.
It improves the semantic understanding and accuracy of the generative intelligent question-answering system when processing complex documents, ensures the comprehensiveness and accuracy of information recall, and improves the accuracy and efficiency of question-answering.
Smart Images

Figure CN119719276B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of natural language processing technology, and in particular to a question-answering method, device, storage medium and electronic device based on a model knowledge base. Background Art
[0002] With the rapid development of artificial intelligence technology, intelligent question-answering systems have been widely used in various fields. Traditional intelligent question-answering systems mainly rely on predefined rules or retrieval methods to provide feedback on questions in order to improve the feedback accuracy when dealing with complex and diverse questions. In recent years, generative question-answering systems based on pre-trained models, such as the Generative Pre-Trained Transformer (GPT) model and the Bidirectional Encoder Representations from Transformers (BERT) model, have demonstrated stronger language understanding and generation capabilities, significantly improving the accuracy of intelligent question-answering. However, for generative intelligent question-answering systems based on pre-trained models, since the pre-trained model needs to be trained based on large-scale existing data (training data), for specific fields with less training data, the pre-trained model will not be able to provide accurate answers for the specific field based on the less training data in the specific field. Therefore, in the related art, a knowledge base of a specific field is introduced into the generative intelligent question-answering system to form a model knowledge base, thereby reducing the risk of incorrect answers by the generative question-answering system and improving the accuracy of questions and answers.
[0003] In generative intelligent question-answering systems (model knowledge bases) that incorporate knowledge bases, uploading documents to the knowledge base for processing is a critical step. This is especially true when documents contain a large amount of complex information. Effectively segmenting the document's content into semantic chunks and accurately determining the semantic chunk boundaries directly impacts the accuracy and efficiency of the generative intelligent question-answering system. Existing chunking methods, typically based on fixed paragraph or sentence lengths or predefined rules, often fail to achieve optimal results when processing documents with poor semantic coherence or frequent topic transitions, resulting in low accuracy in question-answering using model knowledge bases based on chunked content. Summary of the Invention
[0004] In view of this, the present invention provides a question-answering method, device, storage medium and electronic device based on a model knowledge base.
[0005] Specifically, the present invention is achieved through the following technical solutions:
[0006] According to a first aspect of the present invention, a question-answering method based on a model knowledge base is provided. The question-answering method based on the model knowledge base includes:
[0007] For each sample document in the sample document set, read the content of the sample document in sequence according to a preset reading strategy, build a block list of the sample document, and in the block list, build a first block containing the first content read according to the preset reading strategy;
[0008] Based on a single-channel algorithm, sequentially calculating the similarity between the content currently read according to the reading strategy and the block to which the content previously read according to the reading strategy belongs; if the similarity is greater than or equal to a preset first similarity threshold, placing the currently read content in the block to which the previously read content belongs; if the similarity is less than the first similarity threshold, creating a new block and placing the currently read content in the newly created block;
[0009] For each block list, traverse the content in each block in the block list, use the k-means clustering algorithm to calculate the similarity between the content and all blocks that do not contain the content, and when the calculated similarity is greater than or equal to a preset second similarity threshold, redistribute the content to the block corresponding to the calculated similarity to obtain clustered blocks, which are stored in the knowledge base of the model knowledge base;
[0010] Receive a question statement input by a user, and based on the question statement, obtain from the knowledge base of the model knowledge base a keyword recall cluster block set, a semantic recall cluster block set, and a topic recall cluster block set that match the question statement;
[0011] Obtain candidate content included in the keyword recall cluster block set, the semantic recall cluster block set, and the topic recall cluster block set, and for each candidate content, obtain the fusion relevance of the candidate content based on the frequency of occurrence of the candidate content in each recall cluster block set;
[0012] The candidate contents are sorted according to their fusion relevance, the sorted candidate contents are spliced together to obtain a spliced paragraph, and the spliced paragraph is input into the generative intelligent question-answering system in the model knowledge base to obtain an answer corresponding to the question statement.
[0013] The model knowledge base-based question-answering method in this technical solution constructs a block list of adjacent paragraph semantics through the similarity based on the single-channel algorithm, and then uses the k-means clustering algorithm to calculate the similarity of the block list to construct clustered blocks of separated paragraph semantics. After recall based on the multi-way recall mechanism, the blocks are input into the generative intelligent question-answering system. This can effectively solve the block segmentation problem of complex documents and the limitations of information recall, and improve the accuracy of the generative intelligent question-answering system.
[0014] According to a second aspect of the present invention, a question-answering device based on a model knowledge base is provided. The question-answering device based on the model knowledge base includes:
[0015] A block list building module is used to read the content of each sample document in the sample document set in sequence according to a preset reading strategy, build a block list of the sample document, and build a first block containing the first content read according to the preset reading strategy in the block list;
[0016] a block processing module configured to sequentially calculate, based on a single-channel algorithm, the similarity between the content currently being read according to the reading strategy and the block to which the content previously read according to the reading strategy belongs; if the similarity is greater than or equal to a preset first similarity threshold, place the currently read content in the block to which the previously read content belongs; and if the similarity is less than the first similarity threshold, create a new block and place the currently read content in the newly created block;
[0017] A block clustering module is used to traverse the content of each block in each block list, use the k-means clustering algorithm to calculate the similarity between the content and all blocks that do not contain the content, and when the calculated similarity is greater than or equal to a preset second similarity threshold, the content is redistributed to the block corresponding to the calculated similarity to obtain clustered blocks, which are stored in the knowledge base of the model knowledge base;
[0018] A block recall module is configured to receive a question statement input by a user, and based on the question statement, obtain a keyword recall cluster block set, a semantic recall cluster block set, and a topic recall cluster block set that match the question statement from the knowledge base of the model knowledge base;
[0019] A fusion processing module is used to obtain candidate content included in the keyword recall cluster block set, the semantic recall cluster block set, and the theme recall cluster block set, and for each candidate content, obtain the fusion relevance of the candidate content based on the frequency of the candidate content appearing in each recall cluster block set;
[0020] The answer acquisition module is used to sort the candidate contents according to their fusion relevance, splice the sorted candidate contents to obtain a spliced paragraph, input the spliced paragraph into the generative intelligent question-answering system in the model knowledge base, and obtain the answer corresponding to the question statement.
[0021] According to a third aspect of the present invention, there is provided a storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the question-answering method based on the model knowledge base in any possible implementation of the first aspect.
[0022] According to a fourth aspect of the present invention, there is provided an electronic device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps of the question-answering method based on the model knowledge base in any possible implementation of the first aspect are implemented. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.
[0024] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or related technical descriptions. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0025] Figure 1 A flowchart of a question-answering method based on a model knowledge base provided by an embodiment of the present invention;
[0026] Figure 2 Another schematic diagram of a process for obtaining a semantic recall clustering block set in a question-answering method based on a model knowledge base provided by an embodiment of the present invention;
[0027] Figure 3 A schematic diagram of a question-answering device based on a model knowledge base provided by an embodiment of the present invention;
[0028] Figure 4 A schematic structural diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0029] To make the objectives, technical solutions, and advantages of the embodiments of the present invention more clear, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts shall fall within the scope of protection of the present invention.
[0030] In related technologies, generative intelligent question-answering systems based on pre-trained models and knowledge bases (model knowledge bases) have the following two main problems:
[0031] First, when uploading segmented documents, the segmentation efficiency and accuracy of the document content are low. Before updating the knowledge base with document content, the uploaded document must be parsed. The parsed document content is then segmented according to pre-set logical rules. The resulting segments are converted into vectors and stored in the vector database within the knowledge base. The segment size, or rather, the segment accuracy, significantly impacts the accuracy of the generative intelligent question-answering system. Appropriate segmentation ensures efficient semantic understanding and accurate responses when processing complex documents. However, inappropriate segmentation can lead to semantic loss or confusion. For example, if the segments are too large, a single segment may contain multiple topics or complex semantic structures, making it difficult for the generative intelligent question-answering system to extract the most relevant parts of the question, resulting in ambiguous or inaccurate responses. If the segments are too small, the semantic context may be destroyed and dispersed across multiple segments. This can prevent the generative intelligent question-answering system from obtaining sufficient semantic information when answering questions, thus affecting the accuracy and coherence of the responses. Therefore, how to aggregate semantically coherent and similar paragraphs into one chunk is the key to processing document chunking.
[0032] 2. Contextual block recall is inaccurate and incomplete. Generative intelligent question answering systems have been widely used in information retrieval, knowledge question answering and other fields. However, when dealing with diverse and complex questions, traditional single recall strategies often cannot fully utilize the rich information in the knowledge base, resulting in low accuracy of question and answer results. In the existing technology, single recall strategies only rely on keyword matching or semantic similarity to recall text blocks. Therefore, it is difficult to meet the needs of different users and multi-level information needs in complex contexts. Among them, the recall calculated by the relevance between the question and the text block has a great impact on the final answer. A single path may not be able to accurately and comprehensively capture all relevant information in the question and document, resulting in some valid information being omitted. Different recall paths have different definitions of relevance. A single path may not be able to fully meet the user's intentions, resulting in inaccurate retrieval results.
[0033] In this embodiment, it is proposed to combine the Single-Pass algorithm with the K-means clustering algorithm. After the document is preliminarily segmented into blocks using the Single-Pass algorithm, the K-means clustering algorithm is used to perform fine-grained semantic matching and clustering on the block content obtained after each preliminary segmentation. Thus, based on the preliminary segmentation, the content of each block is updated, and the semantically similar but non-continuous and cross-document paragraphs in each block content are aggregated into one block, thereby obtaining more accurate semantic segmentation content.
[0034] See also Figure 1The embodiment of the present invention provides a question-answering method based on a model knowledge base, which may include the following steps:
[0035] S101: For each sample document in the sample document set, sequentially read the content of the sample document according to a preset reading strategy, construct a block list of the sample document, and construct a first block in the block list containing the first content read according to the preset reading strategy;
[0036] In this embodiment, as an optional embodiment, the pre-set reading strategy includes but is not limited to: reading by sentence, reading by paragraph, reading by chapter, etc. Taking the pre-set reading strategy of reading by paragraph as an example, for each sample document, starting from the beginning of the document, the document is read sequentially in units of paragraphs, that is, starting from the beginning of the document, the content in the document is read paragraph by paragraph.
[0037] In this embodiment, as an optional embodiment, an empty block list is created, that is, an empty list (blocks) is initialized to store each block of the document. Each sample document (document) corresponds to a block list.
[0038] In this embodiment, as an optional embodiment, if the sample document contains non-text content, such as a picture or video, the method further includes:
[0039] For the pictures in the sample documents, the cogvlm2-llama3-chinese-chat-19B model is used to generate picture-based text descriptions. Each picture name contains a paragraph of picture descriptions corresponding to each picture.
[0040] S102: Based on a single-channel algorithm, sequentially calculate the similarity between the content currently read according to the read strategy and the block to which the content previously read according to the read strategy belongs; if the similarity is greater than or equal to a preset first similarity threshold, place the currently read content in the block to which the previously read content belongs; if the similarity is less than the first similarity threshold, create a new block and place the currently read content in the newly created block;
[0041] In this embodiment, a similarity threshold is set. The similarity threshold is used to determine whether two paragraphs should be classified into the same block or different blocks. By adjusting the size of the similarity threshold, the size of the block can be adjusted.
[0042] In this embodiment, taking the pre-set reading strategy of reading by paragraph as an example, the Single-Pass algorithm is used to perform preliminary block division of the document, and the paragraphs in the document are processed sequentially, so that the paragraphs in the document are assigned to different blocks. Specifically, based on the similarity-based Single-Pass algorithm, the paragraphs in the document are sequentially scanned, and the similarity between the scanned paragraphs and each block in the block list is calculated. According to the preset first similarity threshold, if the similarity is greater than or equal to the first similarity threshold, the scanned paragraph is classified into the block corresponding to the similarity, that is, the scanned content is classified into the existing block. If the similarity is less than the first similarity threshold, a new block is dynamically created, and the scanned paragraph is classified into the dynamically created block. As another optional embodiment, the document can also be divided into blocks based on sentences, which is not limited in this embodiment.
[0043] In this embodiment, assuming that the sample document set contains two sample documents, two corresponding block lists are constructed. The first sample document uses the Single-Pass algorithm and is divided into two blocks through the similarity algorithm and placed in the first block list. The second document uses the Single-Pass algorithm and is divided into three blocks through the similarity algorithm and placed in the second block list.
[0044] In this embodiment, as an optional embodiment, based on a single-channel algorithm, the similarity between the content currently read according to the reading strategy and the blocks to which the content previously read according to the reading strategy belongs is sequentially calculated, including:
[0045] Input the currently read content into the text vector representation model to obtain the text vector corresponding to the currently read content;
[0046] Extracting each read content in the block to which the previously read content belongs, inputting the content into the text vector representation model, and obtaining a block vector of the block to which the previously read content belongs;
[0047] Using a single-channel algorithm, the cosine similarity between the text vector and the block vector is calculated.
[0048] In this embodiment, the similarity calculation of paragraphs in a document is performed by taking paragraphs as an example. As an optional embodiment, based on the paragraphs read sequentially, the similarity between the paragraph and the block to which the previous paragraph belongs in the block list is calculated.
[0049] In this embodiment, as an optional embodiment, for the currently read paragraph, record it as paragraph S, and calculate the similarity between paragraph S and the block to which the previous paragraph of the current paragraph in the block list belongs.
[0050] In this embodiment, as an optional embodiment, the text vector representation model includes but is not limited to: a large Chinese corpus (text2vec-large-chinese) model.
[0051] In this embodiment, segmentation is performed based on cosine similarity and a first similarity threshold. As an optional embodiment, the cosine similarity between the current paragraph S and the segment B to which the previous paragraph belongs is calculated. If the cosine similarity is greater than or equal to the first similarity threshold, the current paragraph S is placed in segment B. If the cosine similarity is less than the first similarity threshold, a new segment C is created in the segment list and the current paragraph S is placed in segment C.
[0052] In this embodiment, as an optional embodiment, the method further includes:
[0053] After placing the currently read content in the block to which the previously read content belongs, updating the block vector of the block based on the text vector representation model;
[0054] After the currently read content is placed in the newly created block, the text vector of the currently read content is written into the newly created block as a block vector.
[0055] In this embodiment, taking a paragraph as an example, the content stored in the block is updated based on the inserted paragraph: If paragraph S is included in an existing block B, the vector representation (vector) of the block is updated based on the text vector representation model to reflect the newly added paragraph content. If paragraph S is included in a new block, for example, a newly created block C, the new block C is added to the block list blocks, and the vector representation of the new block C is obtained.
[0056] In this embodiment, after processing the current paragraph, the next paragraph in the document is processed, repeating the similarity calculation and grouping of paragraphs into blocks until all paragraphs in the document have been processed. After processing all paragraphs in the document, the corresponding block list (blocks) contains the document's blocks, each of which represents a certain degree of semantic or thematic consistency in the document's paragraph content.
[0057] In this embodiment, after the document is initially segmented using the Single-Pass algorithm, each segment includes several adjacent paragraphs. These paragraphs are considered semantically related and are therefore grouped into the same segment. Each segment represents a semantic unit or topic segment in the document.
[0058] S103: For each block list, traverse the content in each block in the block list, use the k-means clustering algorithm to calculate the similarity between the content and all blocks that do not contain the content, and when the calculated similarity is greater than or equal to a preset second similarity threshold, redistribute the content to the block corresponding to the calculated similarity to obtain clustered blocks, and store them in the knowledge base of the model knowledge base;
[0059] In this embodiment, each content contained in a block is a content unit read according to the content of the reading strategy. After preliminary block segmentation using the Single-Pass algorithm, adjacent semantically similar paragraphs can be grouped into one block, but non-adjacent but semantically related paragraphs cannot be placed in one block. Therefore, in this embodiment, after preliminary block segmentation of the document using the Single-Pass algorithm, the k-means algorithm is used to fine-tune clustering of the above blocks based on the sentences or paragraphs in the preliminary blocks, so that non-adjacent semantically related paragraphs can be clustered in one block.
[0060] In this embodiment, as an optional embodiment, the content in each block in the block list is traversed, and the similarity between the content and all blocks that do not contain the content is calculated using the k-means clustering algorithm, including:
[0061] A11, determining the number of clusters according to the number of blocks included in the block list;
[0062] In this embodiment, the number of clusters K is selected, where the value of K is the number of blocks (number of blocks) obtained based on the Single-Pass algorithm.
[0063] A12, construct several initial clusters, each block corresponds to an initial cluster center;
[0064] In this embodiment, K initialization clusters are constructed, and K blocks are used as cluster centers of the initialization clusters.
[0065] A13 traverses the initialization clusters, extracts target content from the initialization clusters, and uses the k-means clustering algorithm to calculate the similarity between the target content and all initialization clusters that do not contain the target content.
[0066] In this embodiment, for each paragraph, the similarity between the paragraph and all initialization clusters that do not contain the paragraph is calculated. Based on a preset second similarity threshold, if the calculated similarity is greater than or equal to the second similarity threshold, the paragraph is reallocated to the initialization cluster corresponding to the calculated similarity while keeping the block corresponding to the paragraph unchanged, until all paragraphs are involved in the similarity calculation.
[0067] In this embodiment, if three initial blocks are obtained based on the Single-Pass algorithm, namely initial block A, initial block B, and initial block C, K-means clustering is performed with the three initial blocks as cluster centers. The similarity between the paragraphs in initial block A and initial blocks B and C is calculated. If the similarity is greater than a second similarity threshold, the paragraph is placed in the corresponding block. If the similarity is less than the threshold, no change is made.
[0068] In this embodiment, in order to focus the content theme within a block as much as possible, as an optional embodiment, after redistributing the content to the blocks corresponding to the calculated similarities, the method further includes:
[0069] In the case of reallocating the content to the block corresponding to the calculated similarity, the block vector corresponding to the block remains unchanged until the initialization cluster is traversed, and then the block vector corresponding to the block is updated based on the content contained in each block.
[0070] In this embodiment, when performing K-means clustering, the block center is not updated. After the current paragraph in the initial block A is processed, the block vectors corresponding to the three updated cluster centers are respectively the same as the block vectors corresponding to the initial block A, initial block B and initial block C. The next paragraph in the initial block A is read and the same processing is performed until the paragraph in the initial block C is read. After clustering is completed, the block vector is updated according to the clustered blocks.
[0071] In this example, the initial segmentation results obtained using the Single-Pass algorithm are used as cluster centers for the k-means algorithm, which clusters all paragraphs in the document. The k-means algorithm can cluster paragraphs that are not in the same document but have semantically similar content, thereby enabling cross-document semantic connectivity analysis.
[0072] In this embodiment, the Single-Pass algorithm is combined with the k-means algorithm to semantically segment the paragraph content of a document. This approach not only considers the semantic coherence of the paragraph sequence, but also takes into account the semantic relevance between non-adjacent paragraphs. By grouping together non-adjacent, semantically related paragraphs, more accurate responses can be generated for large-scale knowledge base question-answering scenarios involving large recall content spans.
[0073] In this embodiment, it should be noted that, for the question-answering method based on the model knowledge base in this embodiment, steps S101 to S103 only need to be performed once.
[0074] In this embodiment, in the knowledge base, each document corresponds to a block list. As an optional embodiment, when the blocks obtained by K-means clustering are transferred to the knowledge base for storage, the same or similar documents can be processed according to a pre-set storage strategy, which will not be repeated in this embodiment.
[0075] S104, receiving a question statement input by a user, and based on the question statement, obtaining a keyword recall cluster block set, a semantic recall cluster block set, and a topic recall cluster block set that match the question statement from the knowledge base of the model knowledge base;
[0076] In this embodiment, as an optional embodiment, obtaining a keyword recall cluster block set matching the question sentence includes:
[0077] A21, for each cluster block in the knowledge base of the model knowledge base, extracting the content corresponding to the cluster block, removing stop words and performing word segmentation processing to obtain a text block corresponding to the cluster block;
[0078] A22, based on word frequency-inverse document frequency, extracts keywords from the text block, vectorizes the extracted keywords, and obtains the candidate keyword vector representation of the text block;
[0079] A23, after removing stop words and performing word segmentation processing on the question sentence, extracting keywords, and vectorizing the extracted keywords to obtain a question keyword vector representation;
[0080] A24 , based on the similarity between the question keyword vector representation and the candidate keyword vector representation of each text block, recall the text blocks that meet the similarity strategy to obtain the sorted keyword recall cluster block set.
[0081] In this embodiment, the cluster blocks are firstly removed from stop words, and the Jieba word segmenter is used to perform word segmentation to obtain text blocks. The term frequency-inverse document frequency (TF-IDF) method is used to extract keywords from the text blocks, and a candidate keyword vector representation of the text block is generated.
[0082] For the question sentences (user query sentences) submitted by the user, stop words are removed, and the words are segmented using the Jieba word segmenter. The part-of-speech tags are added to the segmented words, and nouns, verbs, adjectives and numerals are extracted as keywords to obtain the question keyword vector representation of the question sentence.
[0083] The question keyword vector representation of the question statement is used to calculate the cosine similarity with the candidate keyword vector representation of each text block to obtain the correlation between the question statement and each text block.
[0084] In this embodiment, text blocks with similarity greater than a third similarity threshold are recalled. In this embodiment, as an optional embodiment, the third similarity threshold is set to 0.7, thereby completing the recall of keyword text blocks. Multiple recalled text blocks form a keyword recall cluster block set.
[0085] In this embodiment, as an optional embodiment, obtaining a semantic recall clustering block set matching the question sentence includes:
[0086] A31, for each cluster block in the knowledge base of the model knowledge base, using a pre-trained large-scale first text vector model, calculates the semantic similarity between the cluster block and the question sentence, obtains cluster blocks that meet a first semantic similarity threshold, and obtains a first set of related text blocks;
[0087] A32, for each cluster block in the knowledge base of the model knowledge base, using a pre-trained large-scale second text vector model, calculates the semantic similarity between the cluster block and the question sentence, obtains cluster blocks that meet a second semantic similarity threshold, and obtains a second set of related text blocks, wherein the number of cluster blocks included in the first set of related text blocks is the same as the number of cluster blocks included in the second set of related text blocks;
[0088] In this embodiment, cluster blocks that meet the requirements are sorted in descending order of similarity to obtain a first set of relevant text blocks and a second set of relevant text blocks.
[0089] A33, using a pre-trained first re-ranked text vector representation model, re-ranking the clustered blocks in the first set of related text blocks to obtain a first set of related re-ranked text blocks;
[0090] A34, using a pre-trained second re-ranked text vector representation model, re-ranking the sorted clustered blocks in the second set of relevant text blocks to obtain a second set of relevant re-ranked text blocks;
[0091] A35, cross-calculating semantic relevance based on the difference between the first relevant re-ordered text block set and the second relevant re-ordered text block set, and re-ranking the union of the first relevant re-ordered text block set and the difference based on the cross-calculated semantic relevance to obtain a first relevant re-ordered text block set, and re-ranking the union of the second relevant re-ordered text block set and the difference to obtain a second relevant re-ordered text block set;
[0092] A36 , according to a preset overall sorting strategy, the first relevant re-sorted text block set and the second relevant re-sorted text block set are overall sorted to obtain a sorted semantic recall clustered block set.
[0093] In this embodiment, semantic recall adopts a multi-path and multi-level semantic cross-recall strategy to achieve more accurate semantic recall. Two pre-trained large-scale text vector models are used to calculate the semantic similarity between the user query statement and the cluster blocks in the knowledge base, respectively, and obtain the first n relevant text blocks, namely the first relevant text block set and the second relevant text block set. Then, the corresponding pre-trained two rearranged text vector representation models are used to perform secondary correlation calculation and sorting on the vector corresponding to the user query statement and the n relevant text blocks obtained above, to achieve precise sorting, and obtain the first relevant re-sorted text block set and the second relevant re-sorted text block set. The semantic correlation of the difference set of the two recalled re-sorted text block sets is then cross-calculated and sorted as a whole. Finally, the text block correlation scores obtained by the two-way calculation are averaged and sorted to obtain the semantic recall cluster block set.
[0094] In this embodiment, as an optional embodiment, the pre-trained large-scale first text vector model includes but is not limited to: the bge-large-zh text vector representation model, the pre-trained large-scale second text vector model includes but is not limited to: the bce-embedding-base text vector representation model, the pre-trained first re-ranked text vector representation model includes but is not limited to: the bge_reranker text vector representation model, and the pre-trained second re-ranked text vector representation model includes but is not limited to: the bce_reranker text vector representation model. Specifically, the bge-large-zh text vector representation model and the bce-embedding-base text vector representation model are used to perform a first semantic relevance calculation and ranking, respectively. Then, the bge_reranker text vector representation model and the bce_reranker text vector representation model are used to perform a second semantic relevance calculation and ranking, respectively. The semantic relevance of the difference sets in the two recalled text blocks is then cross-calculated and ranked as a whole. Finally, the text block relevance scores obtained from the two calculations are averaged and ranked.
[0095] Figure 2 Another flow chart of obtaining semantic recall clustering block sets in a question answering method based on a model knowledge base provided by an embodiment of the present invention. Figure 2 As shown, the method includes:
[0096] S201, using bge, calculate the semantic similarity between each cluster block in the knowledge base and the question statement;
[0097] In this embodiment, the bge-large-zh text vector representation model is abbreviated as bge.
[0098] S202: Acquire cluster blocks A, B, C, and D that meet a first semantic similarity threshold to obtain a first set of related text blocks;
[0099] In this embodiment, as an optional embodiment, the number of cluster blocks that meet the first semantic similarity threshold is 4, which are cluster block A (abbreviated as A), cluster block B (abbreviated as B), cluster block C (abbreviated as C) and cluster block D (abbreviated as D) arranged in sequence, forming the first related text block set.
[0100] S203, using bge_reranker, calculating the second semantic similarity between each cluster block in the first relevant text block set and the question sentence;
[0101] S204, reordering the clustered blocks in the first related text block set according to the second semantic similarity;
[0102] In this embodiment, the order of the reordered first related text block set is: B, A, D, C.
[0103] S205, using bce, calculating the second semantic similarity between each cluster block in the knowledge base and the question sentence;
[0104] In this embodiment, the bce-large-zh text vector representation model is abbreviated as bce.
[0105] S206, obtaining cluster blocks A, cluster blocks B1, cluster blocks C, and cluster blocks D1 that meet a first semantic similarity threshold, to obtain a second set of related text blocks;
[0106] S207, using bce_reranker, calculating the third semantic similarity between each cluster block in the second relevant text block set and the question sentence;
[0107] S208, reordering the clustered blocks in the second related text block set based on the third semantic similarity;
[0108] In this embodiment, the order of the reordered second related text block set is: C, D1, A, B1.
[0109] S209: performing cross-calculation of semantic relevance based on the difference between the first relevant reordered text block set and the second relevant reordered text block set, and reordering the union of the first relevant reordered text block set and the difference based on the cross-calculated semantic relevance to obtain the first relevant reordered text block set.
[0110] In this embodiment, the first set of relevant re-ordered text blocks includes sorted cluster blocks and the relevance scores corresponding to the cluster blocks. As an optional embodiment, the first set of relevant re-ordered text blocks includes:
[0111] B 0.7
[0112] A 0.6
[0113] D 0.5
[0114] C 0.4
[0115] D1 0.3
[0116] B1 0.2
[0117] S210: Based on the semantic relevance of the cross calculation, reorder the union of the second relevant reordered text block set and the difference set to obtain a second relevant reordered text block set.
[0118] In this embodiment, as an optional embodiment, the second set of relevant re-ordered text blocks includes:
[0119] C 0.6
[0120] D1 0.5
[0121] A 0.4
[0122] B1 0.3
[0123] B 0.2
[0124] D 0.1
[0125] S211, merging and sorting the first relevant re-ordered text block set and the second relevant re-ordered text block set;
[0126] S212: Obtain a sorted semantic recall clustering block set.
[0127] In this embodiment, as an optional embodiment, the semantic recall clustering block set includes:
[0128] A 0.5
[0129] C 0.5
[0130] B 0.45
[0131] D1 0.4
[0132] D 0.3
[0133] B1 0.25
[0134] In this embodiment, as an optional embodiment, obtaining a topic recall cluster block set matching the question sentence includes:
[0135] A41, for each cluster block in the knowledge base of the model knowledge base, extracting the content corresponding to the cluster block, removing stop words and performing word segmentation processing, and representing the result as a candidate word pair;
[0136] A42 uses the word pair topic model to learn the topic distribution based on the candidate word pairs and represents the cluster blocks as the topic probability distribution of each topic in the pre-set topic group;
[0137] A43, using a word pair topic model, represents the question sentence as a topic probability distribution of each topic in the topic group;
[0138] A44, based on the topic probability distribution of each cluster block and the topic probability distribution of the question sentence, obtain the topic recall cluster block set.
[0139] In this embodiment, the word pair topic model (BTM) is applied to topic recall, which can more accurately match documents or paragraphs related to user queries in a large-scale knowledge question-answering system. First, the text blocks (clustered blocks) are preprocessed, such as word segmentation and stop word removal, and then represented as word pairs. Then, the BTM topic model is used to model the preprocessed text blocks. The BTM topic model learns the topic distribution based on the word pairs in the text blocks and represents each text block as a probability distribution of a group of topics. That is, for each word pair corresponding to each text block, the text block is represented as the topic probability distribution of each topic in a pre-set topic group. The BTM is then used to convert the query text corresponding to the user query statement into the topic probability distribution of each topic in the topic group. By calculating the cosine similarity between the topic distribution probability of the user query statement and the topic distribution probability of the text block, the text blocks with cosine similarity greater than a pre-set cosine similarity threshold are recalled to obtain the topic recall clustered block set. In this embodiment, as an optional embodiment, the cosine similarity threshold is set to 0.7, thereby completing topic recall.
[0140] In this embodiment, a multi-path recall fusion strategy is proposed to address the technical problem that a single path may not accurately and comprehensively capture all relevant information in the question and document, resulting in the omission of some valid information and inaccurate model answers. This strategy can simultaneously perform information retrieval and recall from multiple dimensions and multiple strategies when the user asks a question, ensuring the diversity and accuracy of the question and answer results. As an optional embodiment, three recall strategies are proposed: keyword recall, semantic recall, and topic recall based on term frequency-inverse document frequency (TF-IDF). The three recall strategies are integrated to achieve multi-path recall, thereby overcoming the problem of information omission in single-path recall.
[0141] S105: Obtain candidate content included in the keyword recall cluster block set, the semantic recall cluster block set, and the topic recall cluster block set, and for each candidate content, obtain the fusion relevance of the candidate content based on the frequency of occurrence of the candidate content in each recall cluster block set;
[0142] In this embodiment, for the keyword-based recall, semantic recall, and topic recall in the above-mentioned multi-path recall, it is possible that the same text block (cluster block) is recalled by multiple paths at the same time, or a text block is only recalled by one of the paths, or a text block is not recalled by any path. Therefore, in order to effectively fuse the repeated and non-repeated text blocks in the recall, this embodiment adopts a fusion processing method of weighted fusion and deduplication strategy to ensure that the repeated recalled text blocks will not lead to redundant answers, thereby affecting the question-answering experience. Therefore, as an optional embodiment, the candidate content contained in the keyword recall cluster block set, the semantic recall cluster block set, and the topic recall cluster block set is obtained, including:
[0143] Construct a candidate paragraph set and write the contents of the keyword recall cluster block set into the candidate paragraph set;
[0144] Traverse the contents contained in the semantic recall cluster block set and the topic recall cluster block set;
[0145] If the traversed content exists in the candidate paragraph set, traverse the next paragraph. If the traversed content does not exist in the candidate paragraph set, write the traversed content into the candidate paragraph set and traverse the next paragraph.
[0146] In this embodiment, as an optional embodiment, obtaining the fusion relevance of the candidate paragraph based on the frequency of occurrence of the candidate paragraph in each recall cluster block set includes:
[0147] Query whether the candidate paragraph exists in the keyword recall cluster block set, semantic recall cluster block set, and topic recall cluster block set respectively. If so, increase the frequency by 1.
[0148] A weighted calculation is performed based on the fusion relevance strategy corresponding to the frequency to obtain the fusion relevance of the candidate paragraph.
[0149] In this embodiment, the frequency ranges from 1 to 3. A frequency value of 2 or 3 indicates that there are repeated recalled cluster blocks, i.e., repeated text blocks, in the keyword recall cluster block set, the semantic recall cluster block set, and the topic recall cluster block set.
[0150] In this embodiment, there are four situations for recalled repeated text blocks:
[0151] The first case is that the same text block is recalled by three methods at the same time. The second case is that the same text block is recalled by keywords and semantics at the same time. The third case is that the same text block is recalled by keywords and topics at the same time. The fourth case is that the same text block is recalled by semantics and topics at the same time.
[0152] For the first case where the same text block is recalled simultaneously in three paths, as an optional embodiment, the fusion relevance (score) of the text block is the weighted sum of the relevance scores of the three paths, expressed as follows:
[0153] S combined =α×S keyword +β×S semantic +γ×S topic
[0154] Among them, S combined To fuse the correlation, S keyword is the keyword recall relevance, S semantic is the semantic recall relevance, S topic is the topic recall relevance. α, β, and γ are the keyword recall weight, semantic recall weight, and topic recall weight, respectively, satisfying:
[0155] α+β+γ=1
[0156] In this embodiment, as an optional embodiment, the keyword recall weight, semantic recall weight and topic recall weight are respectively 0.2, 0.6 and 0.2. Taking semantic recall relevance as an example, the semantic recall relevance of a text block can be the similarity of the text block in the semantic recall clustering block set.
[0157] For the second case where the same text block is recalled by both keywords and semantics, the fusion relevance score of the text block is the weighted sum of the keyword recall relevance score and the semantic recall relevance score, which is expressed as follows:
[0158] S combined =α×S keyword +β×S semantic
[0159] Wherein, α and β satisfy α+β=1. As an optional embodiment, the values of α and β are 0.4 and 0.6 respectively.
[0160] For the third case where the same text block is recalled by both keywords and topics, the fusion relevance score of the text block is the weighted sum of the keyword recall relevance score and the topic recall relevance score, expressed as follows:
[0161] S combined =α×S keyword +γ×S topic
[0162] Wherein, α and γ satisfy α+γ=1. As an optional embodiment, the values of α and γ are 0.6 and 0.4 respectively.
[0163] For the fourth case where the same text block is recalled by both semantic and thematic recall, the fusion relevance score of the text block is the weighted sum of the semantic recall relevance score and the thematic recall relevance score, expressed as follows:
[0164] S combined =β×S semantic +γ×S topic
[0165] Wherein, β and γ satisfy β+γ=1. In this embodiment, as an optional embodiment, the values are 0.7 and 0.3 respectively.
[0166] In this embodiment, if a text block is only recalled by one path, the relevance score calculated for that path is the fusion relevance score of the text block.
[0167] S106 , sorting the candidate contents according to their fusion relevance, concatenating the sorted candidate contents to obtain a concatenated paragraph, and inputting the concatenated paragraph into the generative intelligent question-answering system in the model knowledge base to obtain an answer corresponding to the question statement.
[0168] In this embodiment, all recalled text blocks are sorted according to their fusion relevance scores, and the sorted text blocks are concatenated with line breaks to form a string. The string is input into a generative intelligent question-answering system (large model), and the large model generates an answer based on the input string.
[0169] In this embodiment, as an optional embodiment, the generative intelligent question answering system includes but is not limited to: the Qwen-14B-Chat large model.
[0170] The following describes a specific embodiment in detail.
[0171] In this embodiment, local PDF, txt, and Word documents are uploaded and parsed, and the documents are read in the order of their paragraphs. As an optional embodiment, for images in the document, the cogvlm2-llama3-chinese-chat-19B model is used to generate image-based text descriptions. The image text descriptions are represented as vectors using the text2vec-large-chinese vector representation model and stored in a vector database. For text paragraphs in the document, the text2vec-large-chinese vector representation model is used to represent each paragraph as a vector.
[0172] Then, the Single-Pass algorithm is used to perform preliminary segmentation based on the vectors. As an optional embodiment, assume that the document contains 9 paragraphs. The Single-Pass algorithm is used to perform preliminary segmentation based on the vectors corresponding to the 9 paragraphs. The similarity threshold is set to 0.7. The vectors corresponding to paragraphs 1 to 9 are read sequentially. The vector corresponding to the first paragraph is read first, and a segment is created for the first paragraph. The vector corresponding to the text of the first paragraph is represented as Then read the corresponding vector of the second paragraph text, expressed as Then calculate the cosine similarity of the two paragraph vectors. If the cosine similarity is greater than the similarity threshold of 0.7, the second paragraph is assigned to the block represented by the first paragraph, and the block vector representation is updated. The block vector representation is the sum and average of the two paragraph vectors. Otherwise, a new block is created for the second paragraph. For the third paragraph, if the second paragraph is assigned to an existing block, that is, no new block is formed, the block is divided based on the cosine similarity between the vector corresponding to the third paragraph and the vector corresponding to the existing block. If the second paragraph forms a new block, the block is divided based on the cosine similarity between the vector corresponding to the third paragraph and the vector corresponding to the new block. And so on, the document is initially divided into several blocks, each block contains multiple paragraphs. Assuming that it is finally divided into three blocks, the block results are as follows:
[0173] Block 1 contains three paragraphs 1, 2, and 3, and the vector represents
[0174] Block 2 contains three paragraphs 4, 5, and 6, and the vector represents
[0175] Block 3 contains three paragraphs 7, 8, and 9, and the vector represents
[0176] In this example, the Single-Pass algorithm was used for segmentation, which took into account the semantic coherence of paragraph order. However, it failed to connect the content of multiple semantically related paragraphs that spanned a large area within the document. This prevented the model from providing better context for summarizing questions, resulting in suboptimal answers to these questions. Therefore, this example used the K-means clustering algorithm to fine-tune the segmentation, allowing for the connection of semantically related paragraphs that spanned a large area.
[0177] In this embodiment, the number of blocks obtained based on the Single-Pass algorithm is used as the cluster number K of the k-means clustering algorithm. All paragraphs of the document are clustered based on the K-means clustering algorithm, where the cluster center is the vector representation of the block. Calculate the similarity between the paragraph vector and the block vector of the block that does not contain the paragraph. If the similarity is greater than the similarity threshold of 0.8, the paragraph is assigned to the block again. At the same time, the original block corresponding to the paragraph is retained, and so on. Assume that the final block result is as follows:
[0178] Block 1 contains three paragraphs 1, 2, and 3, and the vector represents
[0179] Block 2 contains three paragraphs 4, 5, and 6, and the vector represents
[0180] Block 3 contains three paragraphs: 3, 7, 8, and 9. The vector represents
[0181] Then, the blocks formed based on the K-means clustering algorithm are stored in the vector database.
[0182] In this embodiment, the user input sentence is converted into a query vector using the text2vec-large-chinese vector representation model, and the correlation is calculated with the block vectors of each block in the vector database. The first 50 blocks are recalled to complete the keyword text block recall.
[0183] Then, based on the 50 recalled blocks, the 50 blocks are represented as vectors using the bge-large-zh model and the bce-embedding-base model respectively. The user input sentences are also represented as vectors using the bge-large-zh model and the bce-embedding-base model respectively. Then, the correlations are calculated respectively. Based on the calculated correlations, the top 20 blocks are recalled respectively. For the top 20 recalled blocks, the bge_reranker model and the bce_reranker model are used to rerank the 20 blocks respectively.
[0184] The 20 re-sorted blocks are cross-fused and sorted to obtain the final semantic recall result.
[0185] Then, we get the recall results based on keyword recall and topic recall, and fuse the three recall results to get the final relevance block sorting result, forming a prompt according to the following format:
[0186] prompt_template="""Answer the user's question comprehensively and professionally based on the following known information.
[0187] If you cannot get the answer from it, please say "The question cannot be answered based on the known information" or "Not enough relevant information is provided". It is not allowed to add fabricated elements to the answer. Please use Chinese to answer.
[0188] Known Content:
[0189] {context}
[0190] question:
[0191] {question}"""
[0192] In this embodiment, context refers to the recalled block, and question refers to the query input by the user.
[0193] The prompt is input to the big model (generative intelligent question-answering system), and the big model generates the answer and returns it to the user. As an optional embodiment, the big model used is the Qwen-72B-Chat big model.
[0194] In this embodiment, by combining a large-scale pre-trained model and a knowledge base, an improved chunking algorithm and a multi-way recall mechanism are used to solve the chunking problem of complex documents and the limitations of information recall, which can significantly improve the accuracy of the generative intelligent question-answering system.
[0195] Based on the same inventive concept, Figure 3 As shown, an embodiment of the present invention further provides a question-answering device based on a model knowledge base, the device comprising:
[0196] The block list construction module 301 is configured to sequentially read the content of each sample document in the sample document set according to a preset reading strategy, construct a block list for the sample document, and construct a first block in the block list containing the first content read according to the preset reading strategy;
[0197] In this embodiment, if the sample document contains non-text content, as an optional embodiment, the block list construction module 301 is further configured to:
[0198] For the pictures in the sample documents, the cogvlm2-llama3-chinese-chat-19B model is used to generate picture-based text descriptions. Each picture name contains a paragraph of picture descriptions corresponding to each picture.
[0199] The block processing module 302 is configured to sequentially calculate, based on a single-channel algorithm, the similarity between the content currently being read according to the read strategy and the block to which the content previously read according to the read strategy belongs. If the similarity is greater than or equal to a preset first similarity threshold, the currently read content is placed in the block to which the previously read content belongs. If the similarity is less than the first similarity threshold, a new block is created and the currently read content is placed in the newly created block.
[0200] In this embodiment, as an optional embodiment, the block processing module 302 is specifically configured to:
[0201] Input the currently read content into the text vector representation model to obtain the text vector corresponding to the currently read content;
[0202] Extracting each read content in the block to which the previously read content belongs, inputting the content into the text vector representation model, and obtaining a block vector of the block to which the previously read content belongs;
[0203] Using a single-channel algorithm, the cosine similarity between the text vector and the block vector is calculated.
[0204] In this embodiment, as another optional embodiment, the block processing module 302 is further configured to:
[0205] After placing the currently read content in the block to which the previously read content belongs, updating the block vector of the block based on the text vector representation model;
[0206] After the currently read content is placed in the newly created block, the text vector of the currently read content is written into the newly created block as a block vector.
[0207] The block clustering module 303 is configured to, for each block list, traverse the content in each block in the block list, and use a k-means clustering algorithm to calculate the similarity between the content and all blocks that do not contain the content. When the calculated similarity is greater than or equal to a preset second similarity threshold, the content is redistributed to the block corresponding to the calculated similarity to obtain clustered blocks, which are stored in the knowledge base of the model knowledge base.
[0208] In this embodiment, as an optional embodiment, the block clustering module 303 is specifically configured to:
[0209] Determine the number of clusters based on the number of blocks contained in the block list;
[0210] Construct several initial clusters for clustering, with each block corresponding to an initial cluster center;
[0211] Traverse the initialization clusters, extract the target content from the initialization clusters, and use the k-means clustering algorithm to calculate the similarity between the target content and all the initialization clusters that do not contain the target content.
[0212] In this embodiment, as another optional embodiment, the block clustering module 303 is further configured to:
[0213] In the case of reallocating the content to the block corresponding to the calculated similarity, the block vector corresponding to the block remains unchanged until the initialization cluster is traversed, and then the block vector corresponding to the block is updated based on the content contained in each block.
[0214] The block recall module 304 is configured to receive a question statement input by a user and, based on the question statement, obtain a keyword recall cluster block set, a semantic recall cluster block set, and a topic recall cluster block set that match the question statement from the knowledge base of the model knowledge base;
[0215] In this embodiment, as an optional embodiment, the block recall module 304 is specifically configured to:
[0216] For each cluster block in the knowledge base of the model knowledge base, using a pre-trained large-scale first text vector model, calculate the semantic similarity between the cluster block and the question sentence, obtain the cluster block that meets the first semantic similarity threshold, and obtain a first related text block set;
[0217] For each cluster block in the knowledge base of the model knowledge base, using a pre-trained large-scale second text vector model, calculate the semantic similarity between the cluster block and the question sentence, obtain the cluster block that meets the second semantic similarity threshold, and obtain a second related text block set, wherein the number of cluster blocks included in the first related text block set is the same as the number of cluster blocks included in the second related text block set;
[0218] Reordering the sorted clustered blocks in the first set of related text blocks using a pre-trained first reordered text vector representation model to obtain a first set of related reordered text blocks;
[0219] Reordering the sorted clustered blocks in the second set of relevant text blocks using a pre-trained second reordered text vector representation model to obtain a second set of relevant reordered text blocks;
[0220] Cross-calculating semantic relevance based on the difference between the first relevant re-ordered text block set and the second relevant re-ordered text block set, and re-ranking the union of the first relevant re-ordered text block set and the difference based on the cross-calculated semantic relevance to obtain a first relevant re-ordered text block set, and re-ranking the union of the second relevant re-ordered text block set and the difference to obtain a second relevant re-ordered text block set;
[0221] According to a preset overall sorting strategy, the first relevant re-sorted text block set and the second relevant re-sorted text block set are sorted as a whole to obtain a sorted semantic recall clustering block set.
[0222] In this embodiment, as another optional embodiment, the block recall module 304 is further configured to:
[0223] For each cluster block in the knowledge base of the model knowledge base, extract the content corresponding to the cluster block, remove stop words and perform word segmentation processing to obtain a text block corresponding to the cluster block;
[0224] Based on word frequency-inverse document frequency, keywords are extracted from the text block, and the extracted keywords are vectorized to obtain the candidate keyword vector representation of the text block;
[0225] After removing stop words and performing word segmentation processing on the question sentence, keywords are extracted, and the extracted keywords are vectorized to obtain a question keyword vector representation;
[0226] Based on the similarity between the question keyword vector representation and the candidate keyword vector representation of each text block, the text blocks that meet the similarity strategy are recalled to obtain the sorted keyword recall cluster block set.
[0227] In this embodiment, as another optional embodiment, the block recall module 304 is further configured to:
[0228] For each cluster block in the knowledge base of the model knowledge base, extract the content corresponding to the cluster block, remove stop words and perform word segmentation processing, and represent it as a candidate word pair;
[0229] Using the word pair topic model, we learn the topic distribution based on the candidate word pairs and represent the cluster blocks as the topic probability distribution of each topic in the pre-set topic group;
[0230] Using a word pair topic model, the question sentence is represented as a topic probability distribution of each topic in the topic group;
[0231] Based on the topic probability distribution of each cluster block and the topic probability distribution of the question sentence, the topic recall cluster block set is obtained.
[0232] The fusion processing module 305 is used to obtain candidate content included in the keyword recall cluster block set, the semantic recall cluster block set, and the theme recall cluster block set, and for each candidate content, obtain the fusion relevance of the candidate content based on the frequency of the candidate content appearing in each recall cluster block set;
[0233] In this embodiment, as an optional embodiment, the fusion processing module 305 is specifically configured to:
[0234] Construct a candidate paragraph set and write the contents of the keyword recall cluster block set into the candidate paragraph set;
[0235] Traverse the contents contained in the semantic recall cluster block set and the topic recall cluster block set;
[0236] If the traversed content exists in the candidate paragraph set, traverse the next paragraph. If the traversed content does not exist in the candidate paragraph set, write the traversed content into the candidate paragraph set and traverse the next paragraph.
[0237] In this embodiment, as another optional embodiment, the fusion processing module 305 is further configured to:
[0238] Based on the frequency of occurrence of the candidate paragraph in each recall cluster block set, the fusion relevance of the candidate paragraph is obtained, including:
[0239] Query whether the candidate paragraph exists in the keyword recall cluster block set, semantic recall cluster block set, and topic recall cluster block set respectively. If so, increase the frequency by 1.
[0240] A weighted calculation is performed based on the fusion relevance strategy corresponding to the frequency to obtain the fusion relevance of the candidate paragraph.
[0241] The answer acquisition module 306 is used to sort the candidate contents according to their fusion relevance, splice the sorted candidate contents to obtain a spliced paragraph, input the spliced paragraph into the generative intelligent question-answering system in the model knowledge base, and obtain the answer corresponding to the question statement.
[0242] Based on the same inventive concept, an embodiment of the present invention further provides a storage medium on which a computer program is stored. When the program is executed by a processor, the steps of the question-answering method based on the model knowledge base in any possible implementation manner described above are implemented.
[0243] Alternatively, the storage medium may be a non-transitory computer-readable storage medium, for example, a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, and the like.
[0244] Based on the same inventive concept, see Figure 4 An embodiment of the present invention further provides an electronic device, including a memory 101 (e.g., a non-volatile memory), a processor 102, and a computer program stored in the memory 101 and executable on the processor 102. When the processor 102 executes the program, it implements the steps of the model knowledge base-based question-answering method described in any of the possible implementations described above, which may be equivalent to the aforementioned model knowledge base-based question-answering device. Of course, the processor may also be used to process other data or perform other operations. The electronic device may be a PC, server, terminal, or other device.
[0245] like Figure 4As shown, the electronic device may also generally include: a memory 103, a network interface 104, and an internal bus 105. In addition to these components, other hardware may also be included, which will not be described in detail.
[0246] It should be pointed out that the above-mentioned question-answering device based on the model knowledge base can be implemented through software. As a device in a logical sense, it is formed by the processor 102 of the electronic device in which it is located reading the computer program instructions stored in the non-volatile memory into the memory 103 for execution.
[0247] Embodiments of the subject matter and functional operations described in this specification may be implemented in the following: digital electronic circuits, tangibly embodied computer software or firmware, computer hardware including the structures disclosed in this specification and their structural equivalents, or a combination of one or more of them. Embodiments of the subject matter described in this specification may be implemented as one or more computer programs, i.e., one or more modules of computer program instructions encoded on a tangible, non-transitory program carrier to be executed by a data processing device or to control the operation of the data processing device. Alternatively or additionally, the program instructions may be encoded on an artificially generated propagation signal, such as a machine-generated electrical, optical, or electromagnetic signal, which is generated to encode information and transmit it to a suitable receiver device for execution by the data processing device. The computer storage medium may be a machine-readable storage device, a machine-readable storage substrate, a random or serial access memory device, or a combination of one or more of them.
[0248] The processes and logic flows described in this specification can be performed by one or more programmable computers executing one or more computer programs to perform the corresponding functions by operating on input data and generating output. The processes and logic flows can also be performed by, and apparatus can be implemented as, special purpose logic circuitry, such as an FPGA (field programmable gate array) or an ASIC (application-specific integrated circuit).
[0249] Computers suitable for executing computer programs include, for example, general-purpose and / or special-purpose microprocessors, or any other type of central processing unit. Typically, the central processing unit will receive instructions and data from a read-only memory and / or random access memory. The basic components of a computer include a central processing unit for implementing or executing instructions and one or more memory devices for storing instructions and data. Typically, a computer will also include one or more mass storage devices for storing data, such as magnetic disks, magneto-optical disks, or optical disks, or the computer will be operably coupled to such mass storage devices to receive data from them or to transmit data to them, or both. However, a computer does not necessarily have such devices. In addition, a computer can be embedded in another device, such as a mobile phone, a personal digital assistant (PDA), a mobile audio or video player, a game console, a global positioning system (GPS) receiver, or a portable storage device such as a universal serial bus (USB) flash drive, to name a few.
[0250] Computer-readable media suitable for storing computer program instructions and data include all forms of non-volatile memory, media, and storage devices, including, for example, semiconductor memory devices (e.g., EPROM, EEPROM, and flash memory devices), magnetic disks (e.g., internal hard disks or removable disks), magneto-optical disks, and CD-ROM and DVD-ROM disks. The processor and memory can be supplemented by, or incorporated in, special purpose logic circuitry.
[0251] Although this specification contains many specific implementation details, these should not be interpreted as limiting the scope of any invention or the scope of protection claimed, but are mainly used to describe the features of specific embodiments of specific inventions. Certain features described in multiple embodiments within this specification can also be implemented in combination in a single embodiment. On the other hand, the various features described in a single embodiment can also be implemented separately in multiple embodiments or in any suitable sub-combination. In addition, although the features can work in certain combinations as above and even initially claim protection, one or more features from the claimed combination can be removed from the combination in some cases, and the claimed combination can point to a sub-combination or a variation of the sub-combination.
[0252] Similarly, although operations are depicted in a particular order in the accompanying drawings, this should not be understood as requiring that these operations be performed in the particular order shown or performed sequentially, or that all illustrated operations be performed to achieve the desired results. In some cases, multitasking and parallel processing may be advantageous. In addition, the separation of various system modules and components in the above-described embodiments should not be understood as requiring such separation in all embodiments, and it should be understood that the described program components and systems can generally be integrated together in a single software product, or packaged into multiple software products.
[0253] Thus, specific embodiments of the subject matter have been described. Other embodiments are within the scope of the following claims. In some cases, the actions recited in the claims can be performed in a different order and still achieve the desired results. Furthermore, the processes depicted in the accompanying drawings do not necessarily require the particular order shown or sequential sequence to achieve the desired results. In some implementations, multitasking and parallel processing may be advantageous.
[0254] 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 entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article, or device that includes a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, method, article, or device that includes the element.
[0255] The foregoing is merely a detailed description of the present invention, intended to enable those skilled in the art to understand and implement the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention is not limited to the embodiments shown herein, but is to be construed in the widest manner consistent with the principles and novel features claimed herein.
Claims
1. A question-answering method based on a model knowledge base, characterized in that: include: For each sample document in the sample document set, read the content of the sample document in sequence according to a preset reading strategy, build a block list of the sample document, and in the block list, build a first block containing the first content read according to the preset reading strategy; Based on a single-channel algorithm, sequentially calculating the similarity between the content currently read according to the reading strategy and the block to which the content previously read according to the reading strategy belongs; if the similarity is greater than or equal to a preset first similarity threshold, placing the currently read content in the block to which the previously read content belongs; if the similarity is less than the first similarity threshold, creating a new block and placing the currently read content in the newly created block; For each block list, traverse the content in each block in the block list, use the k-means clustering algorithm to calculate the similarity between the content and all blocks that do not contain the content, and when the calculated similarity is greater than or equal to a preset second similarity threshold, redistribute the content to the block corresponding to the calculated similarity to obtain clustered blocks, which are stored in the knowledge base of the model knowledge base; Receive a question statement input by a user, and based on the question statement, obtain from the knowledge base of the model knowledge base a keyword recall cluster block set, a semantic recall cluster block set, and a topic recall cluster block set that match the question statement; Obtain candidate content included in the keyword recall cluster block set, the semantic recall cluster block set, and the topic recall cluster block set, and for each candidate content, obtain the fusion relevance of the candidate content based on the frequency of occurrence of the candidate content in each recall cluster block set; The candidate contents are sorted according to their fusion relevance, the sorted candidate contents are spliced together to obtain a spliced paragraph, and the spliced paragraph is input into the generative intelligent question-answering system in the model knowledge base to obtain an answer corresponding to the question statement.
2. The question-answering method based on the model knowledge base according to claim 1, characterized in that: The sequential calculation of the similarity between the content currently read according to the reading strategy and the blocks to which the content previously read according to the reading strategy belongs based on the single-channel algorithm includes: Input the currently read content into the text vector representation model to obtain the text vector corresponding to the currently read content; Extracting each read content in the block to which the previously read content belongs, inputting the content into the text vector representation model, and obtaining a block vector of the block to which the previously read content belongs; Using a single-channel algorithm, the cosine similarity between the text vector and the block vector is calculated.
3. The question-answering method based on the model knowledge base according to claim 2, characterized in that: The method further comprises: After placing the currently read content in the block to which the previously read content belongs, updating the block vector of the block based on the text vector representation model; After the currently read content is placed in the newly created block, the text vector of the currently read content is written into the newly created block as a block vector.
4. The question-answering method based on the model knowledge base according to claim 1, characterized in that: The traversing of the content in each block in the block list and using the k-means clustering algorithm to calculate the similarity between the content and all blocks that do not contain the content includes: Determine the number of clusters based on the number of blocks contained in the block list; Construct several initial clusters for clustering, with each block corresponding to an initial cluster center; Traverse the initialization clusters, extract the target content from the initialization clusters, and use the k-means clustering algorithm to calculate the similarity between the target content and all the initialization clusters that do not contain the target content.
5. The question-answering method based on the model knowledge base according to claim 4, characterized in that: After redistributing the content to the blocks corresponding to the calculated similarities, the method further includes: In the case of reallocating the content to the block corresponding to the calculated similarity, the block vector corresponding to the block remains unchanged until the initialization cluster is traversed, and then the block vector corresponding to the block is updated based on the content contained in each block.
6. The question-answering method based on a model knowledge base according to any one of claims 1 to 5, characterized in that: The step of obtaining a semantic recall clustering block set matching the question statement includes: For each cluster block in the knowledge base of the model knowledge base, using a pre-trained large-scale first text vector model, calculate the semantic similarity between the cluster block and the question sentence, obtain the cluster block that meets the first semantic similarity threshold, and obtain a first related text block set; For each cluster block in the knowledge base of the model knowledge base, using a pre-trained large-scale second text vector model, calculate the semantic similarity between the cluster block and the question sentence, obtain the cluster block that meets the second semantic similarity threshold, and obtain a second related text block set, wherein the number of cluster blocks included in the first related text block set is the same as the number of cluster blocks included in the second related text block set; Reordering the sorted clustered blocks in the first set of related text blocks using a pre-trained first reordered text vector representation model to obtain a first set of related reordered text blocks; Reordering the sorted clustered blocks in the second set of relevant text blocks using a pre-trained second reordered text vector representation model to obtain a second set of relevant reordered text blocks; Cross-calculating semantic relevance based on the difference between the first relevant re-ordered text block set and the second relevant re-ordered text block set, and re-ranking the union of the first relevant re-ordered text block set and the difference based on the cross-calculated semantic relevance to obtain a first relevant re-ordered text block set, and re-ranking the union of the second relevant re-ordered text block set and the difference to obtain a second relevant re-ordered text block set; According to a preset overall sorting strategy, the first relevant re-sorted text block set and the second relevant re-sorted text block set are sorted as a whole to obtain a sorted semantic recall clustering block set.
7. The question-answering method based on a model knowledge base according to any one of claims 1 to 5, characterized in that: The step of obtaining candidate content included in the keyword recall cluster block set, the semantic recall cluster block set, and the topic recall cluster block set includes: Construct a candidate paragraph set and write the contents of the keyword recall cluster block set into the candidate paragraph set; Traverse the contents contained in the semantic recall cluster block set and the topic recall cluster block set; If the traversed content exists in the candidate paragraph set, traverse the next paragraph. If the traversed content does not exist in the candidate paragraph set, write the traversed content into the candidate paragraph set and traverse the next paragraph.
8. A question-answering device based on a model knowledge base, characterized in that: The question-answering device based on the model knowledge base includes: A block list building module is used to read the content of each sample document in the sample document set in sequence according to a preset reading strategy, build a block list of the sample document, and build a first block containing the first content read according to the preset reading strategy in the block list; a block processing module configured to sequentially calculate, based on a single-channel algorithm, the similarity between the content currently being read according to the reading strategy and the block to which the content previously read according to the reading strategy belongs; if the similarity is greater than or equal to a preset first similarity threshold, place the currently read content in the block to which the previously read content belongs; and if the similarity is less than the first similarity threshold, create a new block and place the currently read content in the newly created block; A block clustering module is used to traverse the content of each block in each block list, use the k-means clustering algorithm to calculate the similarity between the content and all blocks that do not contain the content, and when the calculated similarity is greater than or equal to a preset second similarity threshold, the content is redistributed to the block corresponding to the calculated similarity to obtain clustered blocks, which are stored in the knowledge base of the model knowledge base; A block recall module is configured to receive a question statement input by a user, and based on the question statement, obtain a keyword recall cluster block set, a semantic recall cluster block set, and a topic recall cluster block set that match the question statement from the knowledge base of the model knowledge base; A fusion processing module is used to obtain candidate content included in the keyword recall cluster block set, the semantic recall cluster block set, and the theme recall cluster block set, and for each candidate content, obtain the fusion relevance of the candidate content based on the frequency of the candidate content appearing in each recall cluster block set; The answer acquisition module is used to sort the candidate contents according to their fusion relevance, splice the sorted candidate contents to obtain a spliced paragraph, input the spliced paragraph into the generative intelligent question-answering system in the model knowledge base, and obtain the answer corresponding to the question statement.
9. A storage medium, characterized in that: The storage medium stores a program or instruction, and when the program or instruction is executed by a processor, the steps of the question-answering method based on the model knowledge base as described in any one of claims 1 to 7 are implemented.
10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the steps of the question-answering method based on the model knowledge base according to any one of claims 1 to 7 are implemented.