Document search model training method, document search method, and related apparatuses
By building document index and extracting statement groups, the document search model is trained to output document indexes, solving the problem of low recall in complex semantic search scenarios, achieving higher recall and more accurate document index matching.
Patent Information
- Application Number
- PCT/CN2023/134765
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-09-27
- Filing Date
- 2023-11-28
- Publication Date
- 2025-04-03
AI Technical Summary
The prior art has low recall in complex semantic search scenarios, and it is impossible to search documents containing the same semantics as the search keywords.
By building the document index of the training document, extracting multiple groups of statements, determining the target statement group and vectorizing it, building training samples, and using neural network models to train the document search model so that it can output the document index.
It improves the recall rate of complex semantic search, and can search documents with the same semantics as search keywords, which are suitable for complex semantic search scenarios.
Smart Images

Figure CN2023134765_03042025_PF_FP_ABST
Abstract
Description
Document search model training method, document search method and related devices
[0001] This application claims priority to the Chinese patent application filed with the China Patent Office on September 27, 2023, with application number 202311260327.8, the entire contents of which are incorporated by reference into this application. Technical Field
[0002] The present application relates to the field of information retrieval technology, for example, to a document search model training method, a document search method and related devices. Background Art
[0003] When a government system uses a robot to respond to users' government business inquiries, it usually searches for relevant documents based on the user's question words and responds to the user.
[0004] In related technologies, the search engine ElasticSearch is often used for document search. ElasticSearch is mainly an inverted index, which specifically sets a document ID for each document. The content of the document is represented as a collection of keywords. For example, the document is segmented, and several keywords are extracted. The number of times and positions of each keyword appear in the document are recorded. The inverted index is constructed by mapping keywords to document IDs. Each keyword is mapped to multiple document IDs, and the documents corresponding to the mapped document IDs all include the keyword.
[0005] By mapping keywords to document IDs, only documents containing the keyword can be found during searches. This can only be used for simple semantic keyword string matching search scenarios. Documents containing the same semantics as the search keyword cannot be searched, making it difficult to apply to complex semantic search scenarios, resulting in low recall rates during complex semantic searches.
[0006] Summary of the Invention
[0007] The present application provides a document search model training method, a document search method and related devices to avoid the situation where related document searches cannot find documents containing the same semantics as the search keywords, making it difficult to apply to complex semantic search scenarios, resulting in low recall rates during complex semantic searches.
[0008] In a first aspect, the present application provides a document search model training method, comprising:
[0009] Build a document index of training documents;
[0010] For each document, extracting multiple sentence groups from the document, each sentence group including at least one sentence;
[0011] Determining a target sentence group from the multiple sentence groups, and vectorizing sentences in the target sentence group to serve as keyword vectors of search keywords for the document, wherein the target sentence group is a sentence group in which at least one sentence has the highest semantic relevance;
[0012] Constructing a training sample using the keyword vector of the document and the document index;
[0013] The training samples are used to train a document search model, wherein the document search model outputs a document index when a search keyword is input.
[0014] In a second aspect, the present application provides a document search method, comprising:
[0015] Receiving search information input on a user terminal;
[0016] Inputting the search information into a document search model to obtain a document index;
[0017] Searching for a target document matching the document index in a preset document database;
[0018] sending the target document to the user terminal;
[0019] Wherein, the document search model is trained by the document search model training method described in the first aspect.
[0020] In a third aspect, the present application provides a document search model training device, comprising:
[0021] A document index building module configured to build a document index for training documents;
[0022] A document sentence group extraction module is configured to extract a plurality of sentence groups from each document, each sentence group including at least one sentence;
[0023] a keyword vector acquisition module configured to determine a target sentence group from the plurality of sentence groups and vectorize sentences in the target sentence group to serve as keyword vectors of search keywords for the document, wherein the target sentence group is a sentence group having at least one sentence with the highest semantic relevance;
[0024] A training sample construction module, configured to construct a training sample using the keyword vector of the document and the document index;
[0025] The training module is configured to train a document search model using the training samples, wherein the document search model outputs a document index when a search keyword is input.
[0026] In a fourth aspect, the present application provides a document search device, comprising:
[0027] A search information receiving module configured to receive search information input on a user terminal;
[0028] a document index prediction module configured to input the search information into a document search model to obtain a document index;
[0029] A target document search module is configured to search a preset document database for a target document that matches the document index;
[0030] A target document sending module, configured to send the target document to the user terminal;
[0031] Wherein, the document search model is trained by the document search model training method described in the first aspect.
[0032] In a fifth aspect, the present application provides an electronic device, comprising:
[0033] at least one processor; and
[0034] a memory communicatively connected to the at least one processor; wherein,
[0035] The memory stores a computer program that can be executed 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 document search model training method described in the first aspect of this application, and / or the document search method described in the second aspect.
[0036] In a sixth aspect, the present application provides a computer-readable storage medium, which stores computer instructions, and the computer instructions are used to enable a processor to implement the document search model training method described in the first aspect of the present application, and / or the document search method described in the second aspect when executed. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] FIG1 is a flowchart of a document search model training method provided by an embodiment of the present application;
[0038] FIG2A is a flowchart of a document search model training method provided by another embodiment of the present application;
[0039] FIG2B is a schematic diagram of various matrices in an embodiment of the present application;
[0040] FIG2C is a schematic diagram of an undirected acyclic graph in an embodiment of the present application;
[0041] FIG2D is a schematic diagram of the document collection hierarchy in an embodiment of the present application;
[0042] FIG3 is a flowchart of a document search method provided by an embodiment of the present application;
[0043] FIG4 is a schematic diagram of the structure of a document search model training device provided in one embodiment of the present application;
[0044] FIG5 is a schematic structural diagram of a document search device provided by an embodiment of the present application;
[0045] FIG6 is a schematic structural diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0046] Figure 1 is a flow chart of a document search model training method provided by an embodiment of the present application. This embodiment can be applied to training a document search model to predict the situation of finding a target document by using a document search model. The method can be performed by a document search model training device, which can be implemented in the form of hardware and / or software and can be configured in an electronic device. As shown in Figure 1, the document search model training method includes:
[0047] S101: Build a document index for training documents.
[0048] In this embodiment, the documents used for training can be documents used to train the document search model. In one example, the documents can be a variety of documents in government scenarios, such as various rules and regulations, government processing documents, question and answer files of government question and answer systems, etc. Different documents can be obtained as training documents in different application scenarios.
[0049] The document index can be information indicating the search for a document. For example, the document index can be the storage path of the document, or the structural path of the document in structured data, or the classification number of the document, the position in the classification, and other information. This embodiment does not impose any restrictions on the document index, nor does it impose any restrictions on the method of constructing the document index.
[0050] S102 : For each document, extract multiple sentence groups from the document, each sentence group including at least one sentence.
[0051] For example, this embodiment can filter out sentences that are not semantically related to the content of the entire document from a document, obtaining the remaining m sentences, and then randomly extract n sentences from the m sentences to obtain multiple groups of sentences in various combinations, each of which includes at least one sentence, that is, n is greater than or equal to 1.
[0052] Of course, in another embodiment, m sentences may be randomly extracted from the document, and then n sentences may be randomly extracted from the m sentences to obtain multiple sentence groups including n sentences in various combinations.
[0053] S103. Determine a target sentence group from the multiple sentence groups, and vectorize the sentences in the target sentence group to serve as keyword vectors of the search keywords of the document, wherein the target sentence group is a sentence group with at least one sentence having the highest semantic relevance.
[0054] In one embodiment, for each group of sentences, each sentence in the sentence group can be segmented to obtain multiple segmentations for each sentence, and then the similarity between the target segmentation of each sentence and the segmentations of the remaining sentences is calculated, and the number of segmentations whose similarity with the target segmentation is greater than a threshold is counted, and the ratio of this number to the total number of all segmentations in the sentence group is calculated as the score of the target segmentation, and the sum of the scores of all segmentations in the sentence group is calculated as the score of the sentence group. The higher the score of the sentence group, the higher the similarity of different segmentations of the multiple sentences in the sentence group can be determined, and the more segmentations have the same semantics. Therefore, the sentence group with the highest score can be determined as the target sentence, and the multiple sentences in the sentence group can be converted into vectors to obtain multiple vectors. The multiple vectors are used as multiple keyword vectors of the document, and there are semantic associations between the multiple keyword vectors.
[0055] S104: Construct training samples using the document's keyword vector and document index.
[0056] In one embodiment, multiple keyword vectors and document indexes of the same document may be used to construct positive samples, and multiple keyword vectors and document indexes of different documents may be used to construct negative samples, thereby obtaining positive and negative samples for training.
[0057] S105: Use training samples to train a document search model, wherein the document search model outputs a document index when a search keyword is input.
[0058] Among them, the document search model can be a variety of neural networks, and exemplarily, it can be a neural network including encoding and decoding structures. After initializing the network structure and model parameters of the document search model, the keyword vectors in the training sample can be randomly extracted and input into the document search model to obtain a predicted document index. Then, the document index in the training sample and the predicted document index are combined with a preset loss function to calculate the loss value, and the model parameters are adjusted according to the loss value until the loss value is less than the loss threshold or the number of training iterations reaches a preset number, thereby obtaining a trained document search model. After inputting the user's search information, the document search model outputs a document index, and uses the document index to find the target document and return it to the user.
[0059] The embodiment of the present application extracts multiple groups of sentence groups from a document, each group of sentence groups includes at least one sentence, further determines a target sentence group from the multiple groups of sentence groups, and vectorizes the sentences in the target sentence group to serve as the keyword vector of the document's search keyword, wherein the target sentence group is a sentence group with at least one sentence having the highest semantic relevance, uses the document's keyword vector and document index to construct a training sample, and uses the training sample to train a document search model, wherein the document search model outputs a document index when a search keyword is input. In this embodiment, the vectors of multiple semantically related sentences in the target sentence group are used as the keyword vector of the document's search keyword, and the training sample is constructed by using the keyword vector and document index to train the document search model, so that the document search model learns to match the document index according to the search keyword input by the user and the vector of words and sentences with the same semantics as the search keyword. The method is suitable for search scenarios with complex semantics, can improve the recall rate of complex semantic searches, and recall accurate document indexes for complex semantic searches to find target documents through document indexes.
[0060] FIG2A is a flowchart of a document search model training method provided by another embodiment of the present application. The present embodiment is refined based on the above embodiment. As shown in FIG2A , the document search model training method includes:
[0061] S201. Vectorize the training documents to obtain a document vector for each document.
[0062] In one embodiment, documents applied to a certain business can be determined as training documents. For example, documents used for multiple businesses in a government system can be determined as training documents, and the documents can be vectorized to obtain document vectors. In one example, the documents can be input into multiple language processing models such as Bert and Wenxin Yiyan to vectorize the documents to obtain a document vector for each document.
[0063] S202: Construct an aggregation matrix based on the document vectors, where each element in the aggregation matrix is the similarity between two documents.
[0064] In one embodiment, the similarity of the document vectors of two documents can be calculated, and an association matrix can be constructed based on the similarity. A degree matrix can be further constructed based on the association matrix. The aggregation degree of the two documents can be calculated based on the similarity of the document vectors of the two documents and the degrees of the two documents in the degree matrix to generate an aggregation degree matrix.
[0065] For example, the cosine similarity, Euclidean similarity, Pearson correlation coefficient, etc. of the document vectors of two documents can be calculated. When the similarity of the two documents is less than a threshold, the two documents are determined to be unrelated. Conversely, when the similarity of the two documents is greater than or equal to the threshold, the two documents are determined to be related. For example, when the similarity of the document vectors of two documents is less than a preset threshold, the correlation between the two documents is marked as 0 to indicate that the two documents are unrelated. When the similarity of the document vectors of the two documents is greater than or equal to the preset threshold, it is marked as 1 to indicate that the two documents are associated, thereby generating the correlation matrix R shown in Figure 2B. In the correlation matrix R, an element of 0 indicates that the corresponding two documents are unrelated, and an element of 1 indicates that the two documents are associated.
[0066] After generating the association matrix R, an undirected acyclic graph can be generated based on the association matrix R. Figure 2C is a schematic diagram of the undirected acyclic graph. Each node in the undirected acyclic graph is a document, and the edge of the node indicates that there is an association between documents. The number of edges of each document can be counted as the degree of the document, and the degree matrix is generated through the degree of the document. As shown in Figure 2B, the diagonal line in the degree matrix D is the degree of each document. The degree of a document indicates the number of documents associated with the document, that is, the number of edges of the node in the undirected acyclic graph.
[0067] The aggregation degree matrix can be a matrix composed of the aggregation degrees of two documents. The aggregation degrees of two documents can be calculated based on the similarity of the document vectors of the two documents and the degrees of multiple documents in the degree matrix to generate an aggregation degree matrix. In one example, the product of the similarity of two documents and the aggregation degrees of the two documents can be calculated as the aggregation degree of the two documents. In another example, the degrees of the two documents can be normalized and then the sum value can be calculated. The sum value is used as a weight, and the product of the similarity of the two documents and the weight is calculated as the aggregation degree of the two documents, thereby obtaining the aggregation degree matrix U as shown in Figure 2B.
[0068] This embodiment constructs an association matrix R through the similarity of the document vectors of two documents, and further constructs a degree matrix based on the association matrix R. The degree matrix and the similarity of the two documents are further combined to calculate the aggregation degree of the two documents to construct an aggregation degree matrix. The aggregation degree represents the degree of possibility that two documents are divided into the same document set when multiple documents are divided into multiple document sets, thereby providing a basis for dividing the document sets, so that the documents in the same document set are documents with high semantic relevance.
[0069] S203 : Divide the plurality of documents for training into a preset number of document sets according to the aggregation degree matrix.
[0070] In one embodiment, an objective function can be constructed, which is used to calculate the aggregation loss after multiple documents are divided into a preset number of document sets. The aggregation loss is used to represent the aggregation loss after related documents are divided into different document sets. A document set division scheme that minimizes the function value of the objective function is solved to obtain a preset number of divided document sets. The number of documents in each document set is further counted to determine whether there is a target document set with a document number greater than a document number threshold. If so, the documents in the target document set are divided according to the aggregation matrix to obtain a sub-document set of the target document set, wherein the number of documents included in the sub-document set is less than the document number threshold.
[0071] For example, suppose the training document is x i , i = n, the training documents are divided into m document sets, that is, divided into C = (C1, C2, C3, C4, C5, ..., Cm), assuming that the documents include x1, x2, x3, x4, x5, m = 2, that is, divided into two document sets, set A = {x1, x3}, B = {x2, x4, x5}, then the objective function is as follows: U(A, B) = ∑ i∈A,j∈B u ij (1)
[0072] In the above formula (1), u ij is the aggregation degree between document i and document j in the aggregation degree matrix U. Taking the document set A = {x1, x3}, B = {x2, x4, x5} as an example, since x1, x2, x3, x4, x5 are divided into two document sets A and B, the aggregation degrees between documents x1 and x2, x1 and x4, x1 and x5, x3 and x2, x3 and x4, x3 and x5 are lost. The above formula (1) calculates the aggregation degrees u between documents x1 and x2, x1 and x4, x1 and x5, x3 and x2, x3 and x4, x3 and x5 ij The sum of the values is the total degree of polymerization loss.
[0073] The above example illustrates the aggregation loss using documents including x1, x2, x3, x4, and x5, divided into two document sets A and B. When more documents are divided into m document sets, the objective function of the aggregation loss is:
[0074] In formula (2), U(x i , C) is divided into multiple document sets, document x i The aggregation loss of documents in multiple document collections, U(x i , x i ) is a document collection with document x i The polymerization loss is calculated repeatedly. The sum of the aggregation degrees can normalize the aggregation loss. By continuously optimizing the documents in multiple document sets in C, the final document set C = (C1, C2, C3, C4, C5, ..., Cm) is obtained when the J(C) function value is minimized.
[0075] When the number of documents in the document set obtained by division is greater than a preset number, for example, greater than 10 documents, the document set with the number of documents greater than 10 is further divided to obtain multiple sub-document sets until the number of sub-document sets is less than or equal to the preset number. For example, assuming that the number of documents in document set C5 is greater than 10, the documents in document set C5 are further divided according to the above-mentioned document division method to obtain sub-document sets C51, C52, etc. of document set C5.
[0076] FIG2D is a schematic diagram of the document collection hierarchy. As shown in FIG2D , the first-level document collection L01 includes m document collections, namely C1, C2, C3, C4, C5, ..., Cm, and the second-level L02 includes sub-document collections C51 and C52 of the document collection C5.
[0077] S204: Determine the document index of the document according to the position of the document in the document collection.
[0078] In one embodiment, the level of the document collection where the document is located, the level position of the document collection in the level, and the document position of the document in the document collection can be determined, and the level, level position, and document position can be encoded to obtain a document index of the document.
[0079] As shown in Figure 2D, the document collection includes the first level L01 and the second level L02, and each level is set with a position. The level, level position, and document position can be encoded to obtain the document index of the document. In an example, the encoding rule can be: level + level position + document position. Taking document x2 as an example, its document index can be 010102, indicating that document x2 is the 01st level and the second document in the first document collection C1. Taking document x10 as an example, its document index can be 020207, indicating that document x10 is the 02nd level and the seventh document in the second document collection C52. Of course, the encoding rules can also refer to the encoding method of the root node and child node in the tree structure, and there is no restriction on the encoding rules here.
[0080] This embodiment divides documents into multiple document sets according to the aggregation degree matrix. The documents in each document set are documents with high semantic relevance. The path of the document is constructed through the hierarchy of the document set, the position of the document set in the hierarchy, and the position of the document in the document set to generate a document index. This realizes the structuring of unstructured documents through the hierarchy, the position of the document set in the hierarchy, and the position of the document in the document set to obtain a document index, thereby improving the efficiency of document search.
[0081] S205 . For each document, extract multiple sentence groups from the document, each sentence group including at least one sentence.
[0082] For example, for each document, we can filter out sentences that have no semantic relevance to the entire document to obtain the remaining m sentences, and then randomly extract n sentences from the m sentences to obtain Group statement groups, each statement group includes n statements.
[0083] S206: For each sentence group, perform word segmentation on each sentence in the sentence group to obtain a word segmentation for each sentence.
[0084] Each sentence in the sentence group is composed of multiple characters and words. Each sentence can be segmented by a segmentation algorithm such as a string matching-based segmentation algorithm, an understanding-based segmentation algorithm, a tree-based segmentation algorithm, and a statistics-based segmentation algorithm to obtain the segmentation of each sentence.
[0085] In another embodiment, a word segmentation model may be pre-trained to input a sentence into the word segmentation model to obtain multiple word segments of the sentence.
[0086] S207: Calculate the matching degree between each target word of each sentence in the sentence group and the word segments of other sentences.
[0087] For example, for each sentence in the sentence group, each word segment of the sentence can be traversed, the traversed word segment can be determined as the target word segment, and the similarity between the vector of the target word segment and the word segment of other sentences can be calculated as the matching degree.
[0088] S208: When the matching degree is greater than a preset matching degree threshold, the counter of the target word segmentation is incremented by 1.
[0089] When the matching degree between the target word and the rest of the sentence is greater than a threshold (such as 0.9), the counter of the target word is incremented by 1, indicating that the number of words in the rest of the sentence that match the target word increases by 1.
[0090] S209: After the calculation of the matching degree between the target word segment and the word segment of other sentences is completed, the ratio of the counted number of the counter to the total number of word segment in the sentence group is calculated as the score of the target word segment.
[0091] After the matching degree of the target word and other sentences is calculated and it is determined whether the matching degree is greater than the matching degree threshold, the count number can be read from the counter. The count number is the number of word segmentations in all sentences in the sentence group that match the target word segmentation, that is, the number of word segmentations whose semantic similarity with the target word segmentation is greater than the threshold. The ratio of the count number to the total number of word segmentations in all sentences in the sentence group is calculated as the score of the target word segmentation.
[0092] For example, assuming that the statement group includes statement 1, statement 2 and statement 3, statement 1 includes segmentation 11, segmentation 12 and segmentation 13, statement 2 includes segmentation 21 and segmentation 22, and statement 3 includes segmentation 31, segmentation 32, segmentation 33 and segmentation 34, then for statement 1, the similarity of the vectors of segmentation 11 and segmentation 21, segmentation 22, segmentation 31, segmentation 32, segmentation 33 and segmentation 34 is calculated respectively. Each time a similarity is determined to be greater than the threshold, the counter is incremented by 1. If the final count number of the counter of segmentation 11 is k, the ratio of k to p can be calculated as the score of segmentation 11, where p is the total number of segmentations of the statements included in the statement group, that is, p = 9, that is, there are 9 segmentations, and so on to calculate the score of each segmentation.
[0093] S210: Calculate the sum of the scores of all the word segments in the sentence group as the score of the sentence group.
[0094] After calculating the score of each word in each sentence in the sentence group, the sum of the scores of all words in the sentence group is calculated as the score of the sentence group.
[0095] S211. Determine the sentence group with the highest score as the target sentence group.
[0096] For example, after calculating the scores of multiple statement groups, they can be sorted from high to low according to the scores, and the statement group ranked first is determined as the target statement group.
[0097] S212: Input the sentences in the target sentence group into the pre-trained keyword vector generation model multiple times to obtain multiple keyword vectors.
[0098] In this embodiment, when inputting a sentence, the keyword vector generation model randomly masks the word segmentation of the input sentence according to a preset ratio, and generates a vector of the sentence after masking the preset ratio of word segmentation as a keyword vector. Since the keyword vector generation model randomly masks the word segmentation of the input sentence according to a preset ratio, multiple sentences in the target sentence group are input into the keyword vector generation model in a loop multiple times to obtain multiple different keyword vectors, but there is a semantic relationship between the multiple different keyword vectors.
[0099] S213. Construct training samples using the document's keyword vector and document index.
[0100] This embodiment constructs the document index docidx of each document through S201-S204, and constructs multiple keyword vectors queryvec of each document through S205-S212. The keyword vector and document index of the same document can be used to construct positive samples, and the keyword vectors and document indexes of different documents can be used to construct negative samples. For example, the document index of document A is docidx_A, the keyword vector queryvec_A, and the document index of document B is docidx_B, the keyword vector queryvec_B. Then, positive samples (queryvec_A, docidx_A) and (queryvec_B, docidx_B) can be constructed, and negative samples (queryvec_B, docidx_A) and (queryvec_B, docidx_B) can be constructed.
[0101] S214: Use training samples to train the document search model, wherein the document search model outputs a document index when a search keyword is input.
[0102] In one embodiment, a document search model can be initialized, samples can be randomly extracted and input into the document search model to obtain a predicted document index, and a loss value can be calculated using the predicted document index and the document index in the training sample to determine whether the loss value is less than a preset loss threshold. If so, training of the document search model is stopped to obtain a trained document search model. If not, the model parameters of the document search model are adjusted according to the loss value, and the process returns to the step of randomly extracting samples and inputting them into the document search model to obtain a predicted document index.
[0103] The document search model of this embodiment includes an encoding network and a decoding network. The input of the encoding network is the keyword vector queryvec in the training sample. The encoding network outputs a feature vector X, which is input into the decoding network to predict the document index docidx through the decoding network. The decoding network can be expressed by the following formula:
[0104] In the above formula, X represents the output of the encoder, W is the model parameter, Wi represents the model parameter of the i-th step, idx i Document index sequence, idoc is the document sequence, and N is the length of the document index sequence.
[0105] Among them, the loss value can be calculated by the following loss function:
[0106] in,
[0107] In the above formulas (4) and (5), q is a keyword, E(q) is a keyword vector, D is a set consisting of the keyword vector E(q) and the document index docidx, P(docidx|E(q),W) is the probability of generating docidx when the keyword vector E(q) is used as input, and P(idx1|E(q),idx1,2,3,……,i-1,W) is the probability of generating docidx when the keyword vector E(q) is used as input. i ) is the probability of getting the document index idx1 when the keyword vector E(q) is input for the first time, Q(idx1|E(q),idx1,2,3,……,i-1,W i ) is the probability of obtaining the document index idx1 when the keyword vector E(q) input for the first time is input for the second time, is the cross entropy loss of the document index docidx, A regularization term is generated for the consistency of different document indexes docidx for the same keyword vector. That is, the document search model can output multiple document indexes and the probabilities of multiple document indexes, and then the loss value is calculated using the above formula.
[0108] After the loss value is calculated by the above loss function, the model parameters can be adjusted according to the loss value. In one example, the gradient can be calculated according to the loss value, and the model parameters can be adjusted by gradient descent.
[0109] This embodiment constructs an aggregation matrix based on the document vectors of the training documents, where each element in the aggregation matrix is the similarity between two documents, and divides multiple documents for training into a preset number of document sets according to the aggregation matrix, determines the document index of the document according to the position of the document in the document set, extracts multiple sentence groups from each document and determines a target sentence group, where the target sentence group is a sentence group with at least one sentence having the highest semantic relevance, inputs the sentences in the target sentence group into a pre-trained keyword vector generation model for multiple times to obtain multiple keyword vectors, and uses the keyword vectors and document indexes of the documents to construct training samples to train the document search model. On the one hand, the vectors of multiple semantically related sentences in the target sentence group are used as keyword vectors of the document's search keywords, and the training sample training document is constructed using the keyword vectors and document indexes. The document search model enables the document search model to learn to match document indexes based on the search keywords entered by the user and the vectors of words and sentences with the same semantics as the search keywords. It is suitable for search scenarios with complex semantics, can improve the recall rate of complex semantic searches, and recall accurate document indexes for complex semantic searches, so as to find target documents through document indexes. On the other hand, the documents are divided into multiple document sets according to the aggregation matrix. The documents in each document set are documents with high semantic relevance, and the path of the document is constructed through the hierarchy of the document set, the position of the document set in the hierarchy, and the position of the document in the document set to generate a document index. It realizes the structuring of unstructured documents through the hierarchy, the position of the document set in the hierarchy, and the position of the document in the document set to obtain a document index, thereby improving the efficiency of document search.
[0110] For example, each sentence in the sentence group is segmented, and the matching degree of each target segmentation of each sentence in the sentence group with the segmentations of other sentences is calculated. The ratio of the number of segmentations whose matching degree with the target segmentation is greater than a threshold to the total number of segmentations is calculated to obtain the score of the target segmentation. The scores of all segmentations in the sentence group are calculated as the score of the sentence group. The sentence group with the highest score is determined as the target sentence group. The vectors of the target sentence group are used as multiple keyword vectors of the document. The multiple keyword vectors are different but semantically related. The document search model is trained by multiple keyword vectors and document indexes, so that the document search model can search for vector matching document indexes of words and sentences with the same semantics as the search keywords.
[0111] Figure 3 is a flow chart of a document search method provided by an embodiment of the present application. This embodiment is applicable to searching for target documents based on search information input by a user. The method can be performed by a document search device, which can be implemented in the form of hardware and / or software and can be configured in an electronic device. As shown in Figure 3, the document search method includes:
[0112] S301: Receive search information input on a user terminal.
[0113] In one embodiment, the user terminal can be a self-service terminal in a government system, such as a government business consultation terminal. The user can enter the business information that needs to be consulted on the self-service terminal, and the business information is the search information. In another embodiment, the user can inquire about the business through voice on the self-service terminal, and the search information will be obtained after the user's voice is converted into text.
[0114] S302: Input the search information into the document search model to obtain a document index.
[0115] In this embodiment, the document search model may be a model trained by the document search model training method provided in the aforementioned embodiment, and the document search model outputs one or more document indexes after inputting search information.
[0116] S303: Search for a target document that matches the document index in a preset document database.
[0117] This embodiment can pre-construct a document database, which includes a document index of a document. For example, in constructing the document database, multiple documents can be vectorized to obtain a document vector for each document, and an aggregation matrix can be constructed based on the document vector. Each element in the aggregation matrix is the similarity between two documents. According to the aggregation matrix, multiple documents are divided into a preset number of document sets, and the document index of the document is determined according to the position of the document in the document set. The construction of the document index can refer to S201-S204 in the embodiment and will not be described in detail here.
[0118] S304: Send the target document to the user terminal.
[0119] After predicting the document index through the document search model, the target document can be found in the database through the document index, and the target document can be sent to the user terminal to display the target document on the user terminal. For example, the text of the target document can be displayed on the display screen of the user terminal. In another example, the target document can be converted into voice data and the voice data can be played through the user terminal.
[0120] The text search method of this embodiment obtains a document index by inputting search information into a pre-trained document search model, so as to find the target document through the document index. Since the document search model is trained by using the vectors of multiple semantically related sentences in the target sentence group of the document as the keyword vectors of the document's search keyword and the training samples constructed by the document index, the document search model learns to match the document index according to the search keyword input by the user and the vectors of words and sentences with the same semantics as the search keyword. It is suitable for complex semantic search scenarios, can improve the recall rate of complex semantic search, and recall accurate document indexes for complex semantic search, so as to find the target document through the document index.
[0121] FIG4 is a schematic diagram of the structure of a document search model training device provided in an embodiment of the present application. As shown in FIG4 , the document search model training device includes:
[0122] A document index building module 401 is configured to build a document index of training documents;
[0123] A document sentence group extraction module 402 is configured to extract multiple sentence groups from each document, each sentence group including at least one sentence;
[0124] a keyword vector acquisition module 403 configured to determine a target sentence group from the plurality of sentence groups and vectorize the sentences in the target sentence group to serve as the keyword vector of the search keyword of the document, wherein the target sentence group is a sentence group having at least one sentence with the highest semantic relevance;
[0125] A training sample construction module 404 is configured to construct a training sample using a keyword vector and a document index of a document;
[0126] The training module 405 is configured to train the document search model using training samples, wherein the document search model outputs a document index when a search keyword is input.
[0127] For example, the document index building module 401 includes:
[0128] A document vectorization unit is configured to vectorize the training documents to obtain a document vector for each document;
[0129] An aggregation matrix construction unit is configured to construct an aggregation matrix based on document vectors, where each element in the aggregation matrix is the similarity between two documents;
[0130] A document division unit, configured to divide a plurality of training documents into a preset number of document sets according to an aggregation matrix;
[0131] The document index generating unit is configured to determine the document index of a document according to the position of the document in the document collection.
[0132] For example, the aggregation degree matrix construction unit includes:
[0133] A similarity calculation subunit is configured to calculate the similarity of the document vectors of two documents;
[0134] The association matrix construction subunit is configured to construct an association matrix based on similarity. Each element in the association matrix indicates whether two documents are associated. When the similarity between the document vectors of two documents is less than a preset threshold, the element value is 0, indicating that the two documents are not associated. When the similarity between the document vectors of two documents is greater than or equal to the preset threshold, the element value is 1, indicating that the two documents are associated.
[0135] The degree matrix construction subunit is configured to construct a degree matrix based on the correlation matrix, where each element on the diagonal of the degree matrix represents the number of documents associated with each document;
[0136] The aggregation degree matrix generating subunit is configured to calculate the aggregation degree of two documents according to the similarity of the document vectors of the two documents and the degrees of the two documents in the degree matrix to generate an aggregation degree matrix.
[0137] For example, the document division unit includes:
[0138] An objective function construction subunit is configured to construct an objective function. The objective function is used to calculate the aggregation loss after a plurality of documents are divided into a preset number of document sets. The aggregation loss is used to represent the aggregation loss after associated documents are divided into different document sets.
[0139] The solving subunit is configured to solve a document set that minimizes the function value of the objective function, thereby obtaining a preset number of divided document sets.
[0140] For example, the document division unit further includes:
[0141] The document number counting subunit is configured to count the number of documents in each document collection;
[0142] A document quantity judgment subunit is configured to judge whether there is a target document set with a document quantity greater than a document quantity threshold;
[0143] The document division subunit is configured to divide the documents in the target document set according to the aggregation degree matrix to obtain sub-document sets of the target document set, wherein the number of documents included in the sub-document sets is less than a document number threshold.
[0144] For example, the document collection has multiple levels, and the document index generation unit includes:
[0145] a document position determination subunit configured to determine the level of the document collection in which the document is located, the level position of the document collection in the level, and the document position of the document in the document collection;
[0146] The document index encoding subunit is configured to encode the level, level position, and document position to obtain a document index of the document.
[0147] For example, the keyword vector acquisition module 403 includes:
[0148] The word segmentation unit is set to segment each sentence in each sentence group to obtain the word segmentation of each sentence;
[0149] A word segmentation matching degree calculation unit is configured to calculate the matching degree between each target word segmentation of each sentence in the sentence group and the word segmentations of other sentences;
[0150] The counter counting unit is configured to increment the target word counter by 1 when the matching degree is greater than a preset matching degree threshold;
[0151] a word segmentation score calculation unit configured to calculate, after the calculation of the matching degree between the target word segmentation and the word segmentations of other sentences is completed, calculate the ratio of the number of counts in the counter to the total number of word segmentations in the sentence group as the score of the target word segmentation;
[0152] a sentence group score calculation unit, configured to calculate the sum of scores of all the word segments in the sentence group as the score of the sentence group;
[0153] The target sentence group determination unit is configured to determine the sentence group with the highest score as the target sentence group.
[0154] For example, the keyword vector acquisition module 403 includes:
[0155] The sentence input unit is configured to input the sentences in the target sentence group into the pre-trained keyword vector generation model multiple times to obtain multiple keyword vectors.
[0156] For example, the training sample construction module 404 includes:
[0157] A positive sample construction unit is configured to construct positive samples using the keyword vector and document index of the same document;
[0158] The negative sample construction unit is configured to construct negative samples using keyword vectors and document indexes of different documents.
[0159] For example, the training module 405 includes:
[0160] Model initialization unit, set to initialize the document search model;
[0161] The prediction unit is set to randomly extract samples and input them into the document search model to obtain the predicted document index;
[0162] A loss value calculation unit is configured to calculate a loss value using a predicted document index and a document index in a training sample;
[0163] A loss value judgment unit, configured to judge whether the loss value is less than a preset loss threshold;
[0164] Stop training unit, set to stop training the document search model and obtain the trained document search model;
[0165] A model parameter adjustment unit is configured to adjust the model parameters of the document search model according to the loss value.
[0166] The document search model training device provided in the embodiment of the present application can execute the document search model training method provided in any embodiment of the present application, and has the corresponding functional modules and beneficial effects of the execution method.
[0167] FIG5 is a schematic diagram of the structure of a document search device provided in an embodiment of the present application. As shown in FIG5 , the document search device includes:
[0168] A search information receiving module 501 is configured to receive search information input on a user terminal;
[0169] The document index prediction module 502 is configured to input the search information into the document search model to obtain a document index;
[0170] A target document search module 503 is configured to search for a target document that matches a document index in a preset document database;
[0171] A target document sending module 504 is configured to send the target document to a user terminal;
[0172] The document search model is trained using the document search model training method provided in the aforementioned embodiment.
[0173] For example, a document database is built using the following modules:
[0174] A document vectorization module configured to vectorize multiple documents to obtain a document vector for each document;
[0175] The aggregation matrix construction module is configured to construct an aggregation matrix based on the document vector, where each element in the aggregation matrix is the similarity between two documents;
[0176] A document partitioning module is configured to partition multiple documents into a preset number of document sets according to an aggregation degree matrix;
[0177] The document index generation module is configured to determine a document index of a document according to a position of the document in the document collection.
[0178] The document search device provided in the embodiment of the present application can execute the document search method provided in any embodiment of the present application, and has the corresponding functional modules and beneficial effects of the execution method.
[0179] FIG6 shows a block diagram of an electronic device 40 that can be used to implement an embodiment of the present application. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present application described and / or required herein.
[0180] As shown in Figure 6, the electronic device 40 includes at least one processor 41 and a memory connected to the at least one processor 41, such as a read-only memory (ROM) 42, a random access memory (RAM) 43, etc., wherein the memory stores a computer program that can be executed by the at least one processor, and the processor 41 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 42 or the computer program loaded from the storage unit 48 into the random access memory (RAM) 43. In the RAM 43, various programs and data required for the operation of the electronic device 40 can also be stored. The processor 41, ROM 42 and RAM 43 are connected to each other via a bus 44. An input / output (I / O) interface 45 is also connected to the bus 44.
[0181] Multiple components in the electronic device 40 are connected to the I / O interface 45, including an input unit 46, such as a keyboard, a mouse, etc.; an output unit 47, such as various types of displays, speakers, etc.; a storage unit 48, such as a magnetic disk, an optical disk, etc.; and a communication unit 49, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 49 allows the electronic device 40 to exchange information / data with other devices via a computer network such as the Internet and / or various telecommunication networks.
[0182] Processor 41 can be a variety of general-purpose and / or specialized processing components with processing and computing capabilities. Some examples of processor 41 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various specialized artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, digital signal processors (DSPs), and any suitable processor, controller, microcontroller, etc. Processor 41 executes the various methods and processes described above, such as the document search model training method and / or the document search method.
[0183] In some embodiments, the document search model training method and / or the document search method may be implemented as a computer program that is tangibly contained in a computer-readable storage medium, such as a storage unit 48. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 40 via the ROM 42 and / or the communication unit 49. When the computer program is loaded into the RAM 43 and executed by the processor 41, one or more steps of the document search model training method and / or the document search method described above may be performed. In other embodiments, the processor 41 may be configured to execute the document search model training method and / or the document search method by any other appropriate means (e.g., by means of firmware).
[0184] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), system-on-chip systems (SOCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments can include being implemented in one or more computer programs that are executable and / or interpreted on a programmable system that includes at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0185] Computer programs for implementing the methods of the present application may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when the computer program is executed by the processor, the functions / operations specified in the flowcharts and / or block diagrams are implemented. The computer program may be executed entirely on the machine, partially on the machine, as a stand-alone software package, partially on the machine and partially on a remote machine, or entirely on a remote machine or server.
[0186] In the context of the present application, a computer-readable storage medium can be a tangible medium that can contain or store a computer program for use by an instruction execution system, device or equipment or used in combination with an instruction execution system, device or equipment. A computer-readable storage medium can include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium can be a machine-readable signal medium. A more specific example of a machine-readable storage medium can include an electrical connection based on one or more lines, 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 foregoing.
[0187] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0188] The systems and techniques described herein can be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0189] A computing system may include clients and servers. The clients and servers are generally remote from each other and typically interact via a communication network. This client-server relationship arises through computer programs running on the respective computers, creating a client-server relationship. The server may be a cloud server, also known as a cloud computing server or cloud host. This server is a host product within a cloud computing service ecosystem that improves the management difficulties and limited scalability of physical hosting and VPS services in related technologies.
[0190] It should be understood that the various forms of the processes shown above can be used to reorder, add, or delete steps. For example, the multiple steps described in this application can be performed in parallel, sequentially, or in a different order, as long as the desired results of the technical solution of this application can be achieved. This is not limited herein.
Claims
1. A document search model training method, comprising: Build a document index of training documents; For each document, extracting multiple sentence groups from the document, each sentence group including at least one sentence; Determining a target sentence group from the multiple sentence groups, and vectorizing the sentences in the target sentence group to serve as a keyword vector of the search keyword of the document, wherein the target sentence group is a sentence group with the highest semantic relevance of the at least one sentence; Constructing a training sample using the keyword vector of the document and the document index; The training samples are used to train a document search model, wherein the document search model outputs a document index when a search keyword is input.
2. The document search model training method according to claim 1, wherein: The step of constructing a document index for training documents includes: Vectorize the training documents to obtain the document vector for each document; Constructing a degree of aggregation matrix based on the document vector, wherein each element in the degree of aggregation matrix is the similarity between two documents; Dividing a plurality of documents for training into a preset number of document sets according to the aggregation degree matrix; A document index of the document is determined according to a position of the document in the document collection.
3. The document search model training method according to claim 2, wherein: The constructing of an aggregation degree matrix based on the document vector comprises: Calculate the similarity of the document vectors of two documents; Constructing an association matrix according to the similarity, wherein each element in the association matrix indicates whether two documents are associated, wherein when the similarity of the document vectors of the two documents is less than a preset threshold, the element value is 0, indicating that the two documents are not associated, and when the similarity of the document vectors of the two documents is greater than or equal to the preset threshold, the element value is 1, indicating that the two documents are associated; Constructing a degree matrix according to the association matrix, wherein each element on the diagonal of the degree matrix represents the number of documents associated with each document; The aggregation degree of the two documents is calculated according to the similarity of the document vectors of the two documents and the degrees of the two documents in the degree matrix to generate an aggregation degree matrix.
4. The document search model training method according to claim 2, wherein: The step of dividing the plurality of documents for training into a preset number of document sets according to the aggregation degree matrix includes: Constructing an objective function, wherein the objective function is used to calculate the aggregation loss after the plurality of documents are divided into a preset number of document sets, wherein the aggregation loss is used to represent the aggregation loss after the associated documents are divided into different document sets; The document set that minimizes the function value of the objective function is solved to obtain a preset number of divided document sets.
5. The document search model training method according to claim 4, after solving the document set that minimizes the function value of the objective function and obtaining the divided preset number of document sets, further comprises: Count the number of documents in each document collection; Determine whether there is a target document set with a document quantity greater than a document quantity threshold; Based on the judgment result that there is a target document set in which the number of documents is greater than the document number threshold, the documents in the target document set are divided according to the aggregation degree matrix to obtain a sub-document set of the target document set, wherein the number of documents included in the sub-document set is less than the document number threshold.
6. The document search model training method according to claim 2, wherein: The document collection has multiple levels, and determining the document index of the document according to the position of the document in the document collection includes: Determine the level of the document set in which the document is located, the level position of the document set in the level, and the document position of the document in the document set; The level, the level position, and the document position are encoded to obtain a document index of the document.
7. The document search model training method according to claim 1, wherein: Determining a target sentence group from the plurality of sentence groups includes: For each sentence group, segment each sentence in the sentence group to obtain the segmentation of each sentence; Calculate the matching degree between each target word of each sentence in the sentence group and the word of other sentences; When the matching degree is greater than a preset matching degree threshold, the counter of the target word segmentation is incremented by 1; After the calculation of the matching degree between the target participle and the participles of other sentences is completed, the ratio of the counted number of the counter to the total number of participles in the sentence group is calculated as the score of the target participle; Calculating the sum of the scores of all the participles in the sentence group as the score of the sentence group; The sentence group with the highest score is determined as the target sentence group.
8. The document search model training method according to claim 1, wherein: The vectorizing the sentences in the target sentence group includes: The sentences in the target sentence group are input into a pre-trained keyword vector generation model multiple times to obtain multiple keyword vectors.
9. The document search model training method according to any one of claims 1 to 8, wherein: The step of constructing a training sample using the keyword vector of the document and the document index includes: Use the keyword vector and document index of the same document to construct positive samples; Negative samples are constructed using keyword vectors and document indexes of different documents.
10. The document search model training method according to any one of claims 1 to 8, wherein: The adopting the training sample to train the document search model includes: Initializing the document search model; Randomly extract samples and input them into the initialized document search model to obtain the predicted document index; Calculating a loss value using the predicted document index and the document index in the training sample; Determining whether the loss value is less than a preset loss threshold; Based on the judgment result that the loss value is less than the preset loss threshold, stop training the document search model to obtain a trained document search model; Based on the judgment result that the loss value is greater than or equal to the preset loss threshold, the model parameters of the document search model are adjusted according to the loss value, and the step of obtaining the predicted document index in the document search model initialized by randomly extracting sample input is returned.
11. A document search method, comprising: Receiving search information input on a user terminal; Inputting the search information into a document search model to obtain a document index; Searching for a target document matching the document index in a preset document database; Sending the target document to the user terminal; Wherein, the document search model is trained by the document search model training method described in any one of claims 1-10.
12. The document search method according to claim 11, wherein: The document database is established in the following way: Vectorize multiple documents to obtain the document vector of each document; Constructing a degree of aggregation matrix based on the document vector, wherein each element in the degree of aggregation matrix is the similarity between two documents; Dividing the plurality of documents into a preset number of document sets according to the aggregation degree matrix; A document index of the document is determined according to a position of the document in the document collection.
13. A document search model training device, comprising: A document index building module, configured to build a document index of training documents; A document sentence group extraction module is configured to extract multiple sentence groups from each document, each sentence group including at least one sentence; a keyword vector acquisition module, configured to determine a target sentence group from the plurality of sentence groups, and vectorize sentences in the target sentence group to serve as the keyword vector of the search keyword of the document, wherein the target sentence group is the sentence group with the highest semantic relevance of the at least one sentence; A training sample construction module, configured to construct a training sample using the keyword vector of the document and the document index; The training module is configured to use the training samples to train the document search model, wherein the document search model outputs a document index when a search keyword is input.
14. A document search device, comprising: A search information receiving module, configured to receive search information input on a user terminal; A document index prediction module, configured to input the search information into a document search model to obtain a document index; A target document search module, configured to search a preset document database for a target document that matches the document index; A target document sending module, configured to send the target document to the user terminal; Wherein, the document search model is trained by the document search model training method described in any one of claims 1-10.
15. An electronic device, comprising: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, 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 document search model training method described in any one of claims 1-10, and / or the document search method described in any one of claims 11-12.
16. A computer-readable storage medium storing computer instructions, wherein the computer instructions are used to enable a processor to implement the document search model training method described in any one of claims 1-10 and / or the document search method described in any one of claims 11-12 when executed.
Citation Information
Patent Citations
Search recall method and device, server and storage medium
CN107491518A
Method and device for determining similar word set, and electronic device
CN109388801A
Retrieval method, retrieval device, computer readable medium and electronic equipment
CN112445959A
Airline event-based keyword extraction method and device and medium
CN114692619A
Sentence similarity-based polysemy database expansion apparatus and method therefor
KR1020170073354A
Cited By
Book review generation method, system and equipment based on multi-modal data and medium
CN120296162A
Method, device and equipment for checking duplicate of product standard document
CN120523889A
Retrieval method and device, electronic equipment, storage medium and computer program product
CN120873173A
Data analysis method and device in natural gas field, medium, equipment and product
CN120950557A