Training method for text similarity determination model and text similarity calculation method

Through the sentence vector comparison model and the weighted PageRank algorithm, combined with the loss function, the pre-training model is trained, which solves the problem of low accuracy in calculating the similarity of text data with large length differences in the existing technology, and improves the accuracy of the text similarity calculation. sex.

CN118520929BActive Publication Date: 2024-10-29NAT COMP NETWORK & INFORMATION SECURITY MANAGEMENT CENT
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411003497.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-25
Publication Date
2024-10-29
Estimated Expiration
2044-07-25

AI Technical Summary

Technical Problem

Existing text similarity calculation methods have low accuracy when processing text data with large differences in length, and fail to effectively consider the impact of text length and sentence position.

Method used

Using the sentence vector comparison model, we obtain the key expressions of the target text data and determine the sentence importance based on the weighted PageRank algorithm. We combine the cross-entropy loss function and the average variance loss function to train the pre-training model to obtain the text similarity determination model. To improve the accuracy of similarity calculation.

Benefits of technology

It improves the accuracy of text similarity calculation, especially in similarity matching between long and short text data, and improves the accuracy of model output results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118520929B_ABST
    Figure CN118520929B_ABST
Patent Text Reader

Abstract

The present invention provides a training method for a text similarity determination model and a text similarity calculation method, which belongs to the field of computer technology. The training method includes: obtaining a first data set and a second data set; the first data set includes at least one short text data pair; the second data set includes at least one target text data pair, and at least one of the two target text data in the target text data pair is long text data; based on a sentence vector comparison model, the key expressions of each target text data in the second data set are obtained; the sentence vector comparison model is obtained by training a first pre-training model based on the first data set and a first loss function; based on each key expression and a second loss function, the second pre-training model is trained to obtain a text similarity determination model. By introducing short text and long text in the determination process, the accuracy of the output result of the text similarity determination model is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a training method for a text similarity determination model and a text similarity calculation method. Background Art

[0002] In the field of natural language processing, text similarity calculation methods are mainly used to determine whether two documents are similar. In practical applications, text similarity calculation methods can be used for text clustering, information retrieval, question-answering systems, etc. Traditional methods are mainly divided into unsupervised methods and supervised methods. Existing text similarity calculation methods often ignore the impact of text length on the algorithm. The length of the text represents the amount of information contained in it, so the information contained in texts of different lengths needs to be comprehensively considered in the process of similarity matching. For example, in the public information evaluation system, a large number of news reports are merged and clustered as needed for Internet information. Among them, the length and content of the articles for the same event are often different. It is necessary to consider the content and differences of long and short texts in the process of calculating similarity.

[0003] In the prior art, the method of processing long texts is mainly to extract key sentences from long texts. However, in the training of relevant models, the extraction algorithm often only extracts key information from the text at the content level, without considering the similarity between the two texts. In addition, the existing text similarity determination model does not consider the influence of sentence position in the calculation process.

[0004] When the lengths of a pair of text data differ greatly, the accuracy of the results obtained by the traditional text similarity determination model is low. Summary of the invention

[0005] The present invention provides a text similarity model training method and a text similarity calculation method, which are used to solve the problem in the prior art that the similarity between text data with large length differences is difficult to accurately measure, and effectively improve the accuracy of similarity calculation between text data similarities.

[0006] The present invention provides a training method for a text similarity determination model, comprising:

[0007] Acquire a first data set and a second data set; the first data set includes at least one short text data pair; the second data set includes at least one target text data pair, and at least one of the two target text data in the target text data pair is long text data;

[0008] Based on the sentence vector comparison model, obtaining the key expressions of each of the target text data in the second data set; the sentence vector comparison model is obtained by training the first pre-training model based on the first data set and the first loss function;

[0009] Based on each of the key expressions and the second loss function, the second pre-trained model is trained to obtain a text similarity determination model; the text similarity determination model is used to determine the similarity between text data.

[0010] According to a text similarity determination model training method provided by the present invention, the sentence vector comparison model is based on which the key expressions of each target text data in the second data set are obtained, including:

[0011] Acquire a target text data pair in the second data set;

[0012] Based on punctuation marks, first target text data and second target text data in the target text data pair are segmented to obtain a first sub-sentence set of the first target text data and a second sub-sentence set of the second target text data;

[0013] Merging the first sub-sentence set and the second sub-sentence set to obtain a sentence set corresponding to the target text data pair; the sentence set includes at least two sentences;

[0014] Based on the sentence vector comparison model, obtaining the similarity between two sentences in the sentence set;

[0015] Constructing a weighted undirected graph with each sentence in the sentence set as a node, and determining the importance of each node based on a weighted PageRank algorithm;

[0016] Sort the sentences in the first sub-sentence set and the sentences in the second sub-sentence set based on the importance, select a first preset number of sentences in the first sub-sentence set as key expressions of the first target text data, and select a first preset number of sentences in the second sub-sentence set as key expressions of the second target text data;

[0017] Continue to execute the step of obtaining a target text data pair in the second data set to obtain a key expression of each target text data in the second data set.

[0018] According to a training method for a text similarity determination model provided by the present invention, the second pre-training model is trained based on each of the key expressions and the second loss function to obtain the text similarity determination model, including:

[0019] For each of the target text data pairs, concatenate the key expressions of the target text data in the target text data pair to obtain a first text corresponding to the target text data pair;

[0020] Inputting the first text corresponding to each of the target text data pairs into the second pre-training model to obtain the similarity corresponding to each of the first texts;

[0021] The second pre-trained model is trained with minimizing the second loss function as a constraint condition to obtain the text similarity determination model.

[0022] According to a training method for a text similarity determination model provided by the present invention, the second loss function is any one of a cross entropy loss function and a mean variance loss function.

[0023] According to a text similarity determination model training method provided by the present invention, the method further includes:

[0024] Inputting each short text data in each pair of the short text data in the first data set into the first pre-trained model to obtain a representation vector corresponding to each short text data;

[0025] Performing a whitening operation on each of the characterization vectors to obtain a whitened feature vector corresponding to each of the characterization vectors;

[0026] Determining the first loss function based on the cosine similarity of each of the whitened feature vectors and the similarity in the preset label;

[0027] The first pre-trained model is trained with minimizing the first loss function as a constraint to obtain the sentence vector comparison model.

[0028] According to a training method for a text similarity determination model provided by the present invention, the weighted undirected graph is constructed with each sentence in the sentence set as a node, and the importance of each node is determined based on a weighted PageRank algorithm, including:

[0029] Based on the number of nodes in the sentence set and the pre-weight of each node, the importance of each node is determined using formula (1):

[0030] (1)

[0031] in, Indicates The importance of a node, Indicates link to The node set of nodes, Indicates that from Nodes A collection of nodes, express The number of nodes in the is the damping coefficient, For the The pre-weight of the nodes, Indicates Nodes and The similarity between nodes.

[0032] The present invention also provides a text similarity calculation method, which is implemented based on any of the above-mentioned text similarity determination models, and comprises:

[0033] Acquire a text data pair whose similarity is to be determined; the text data pair includes long text data and set text data, and the set text data is long text data or short text data;

[0034] Segmenting the text data pair to obtain a first sentence set corresponding to the text data pair; the first sentence set includes at least two sentence units;

[0035] Based on the sentence vector comparison model, obtaining a first key expression corresponding to the long text data and a second key expression of the set text data;

[0036] The first key expression and the second key expression are concatenated and input into a text similarity determination model to obtain the similarity between the long text data and the set text data.

[0037] The present invention also provides a text similarity calculation device, comprising:

[0038] A first acquisition module is used to acquire a text data pair whose similarity is to be determined; the text data pair includes long text data and set text data, and the set text data is long text data or short text data;

[0039] A segmentation module, configured to segment the text data pair to obtain a first sentence set corresponding to the text data pair; the first sentence set includes at least two sentence units;

[0040] A second acquisition module, configured to acquire a first key expression corresponding to the long text data and a second key expression of the set text data based on a sentence vector comparison model;

[0041] The determination module is used to splice the first key expression and the second key expression and input them into a text similarity determination model to obtain the similarity between the long text data and the set text data.

[0042] The present invention also provides 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 training method for determining a text similarity model or the text similarity calculation method as described above is implemented.

[0043] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements any of the above-described text similarity determination model training methods or text similarity calculation methods.

[0044] The present invention also provides a computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the training method for determining a text similarity model or the text similarity calculation method as described above is implemented.

[0045] The training method of the text similarity determination model and the text similarity calculation method provided by the present invention are as follows: a first data set including at least one short text data pair and a second data set including at least one target text data pair are obtained, and at least one of the two target text data in the target text data pair is long text data; then based on the sentence vector comparison model, the key expression of each target text data in the second data set is obtained; the sentence vector comparison model is obtained by training the first pre-training model based on the first data set and the first loss function; based on the obtained key expressions and the second loss function, the second pre-training model is trained to obtain the text similarity determination model; the text similarity determination model is used to determine the similarity between text data. In the training process of the text similarity determination model of the present invention, the key expression of the target text data (including long text data) is obtained by the sentence vector comparison model trained based on the short text data, and then the training is performed based on the key expression, the similarity between the training data is considered, the key information of the long text data is improved, and the short text data and the long text data are taken into account, so as to improve the accuracy of the output result of the text similarity determination model. BRIEF DESCRIPTION OF THE DRAWINGS

[0046] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0047] Figure 1 This is one of the flow charts of the training method of the text similarity determination model provided by the present invention.

[0048] Figure 2 This is the second flow chart of the training method of the text similarity determination model provided by the present invention.

[0049] Figure 3 It is a data structure diagram of the training method of the text similarity determination model provided by the present invention.

[0050] Figure 4This is the third flow chart of the training method of the text similarity determination model provided by the present invention.

[0051] Figure 5 This is the fourth flow chart of the training method of the text similarity determination model provided by the present invention.

[0052] Figure 6 It is a flow chart of the text similarity calculation method provided by the present invention.

[0053] Figure 7 It is a structural schematic diagram of the text similarity calculation device provided by the present invention.

[0054] Figure 8 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION

[0055] Combine the following Figure 1-Figure 8 The present invention describes a text similarity determination model training method and a text similarity calculation method.

[0056] Figure 1 This is one of the flow charts of the training method of the text similarity determination model provided by the present invention, such as Figure 1 As shown, the training method for the text similarity determination model provided by the present invention includes steps 101 to 103.

[0057] Step 101, obtaining a first data set and a second data set; the first data set includes at least one short text data pair; the second data set includes at least one target text data pair, and at least one of the two target text data in the target text data pair is a long text data.

[0058] Specifically, in this step, the first data set and the second data set are both pre-constructed. Specifically, the first data set and the second data set are constructed based on manual annotation. In order to meet the needs of subsequent model training, the content of manual annotation is a manually determined similarity label. In the first data set, at least one short text data pair is included, each short text data pair includes two short text data, and short text data is generally considered to be text data that is not segmented by punctuation marks or short text data generally refers to 1-2 sentences. By manually determining the similarity of the two short text data in each short text data pair, the format of each short text data pair can be expressed as [short text 1, short text 2, manual annotation similarity]. For the short text data pair, the manually marked similarity can be a value between 0-1. In the second data set, at least one target text data is included. In fact, each target text data can include a short text data and a long text data, that is, the target text data pair can be a combination of long and short texts, or each target text data can include two long text data, that is, the target text data pair can be a combination of long and long texts. The long text data can be a paragraph of text or an article of text. The similarity between the two target text data in each target text data pair is manually determined. The format of each long text data pair can be expressed as [long text 1, long text 2, manually annotated similarity] or [long text 1, short text 2, manually annotated similarity]. It should be noted that the similarity label for the long text data can be a value between 0 and 1, or it can be 0 or 1, which is related to the subsequent choice of the second loss function.

[0059] Specifically, there is no limit to the method of collecting the first data set and the second data set. Data can be collected manually according to actual business needs, or open source text similarity supervision training data sets, such as the Chinese SNLI data set, can be collected from the Internet. In the process of constructing the first data set and the second data set, a search engine can be used. For example, first crawl a batch of news data in different fields from a news website, and then search on the search engine according to the title, filter the search results, and filter out completely similar search results. The remaining results within 5 pages can be used as candidates, and then manually determine whether they are similar.

[0060] Step 102: Based on the sentence vector comparison model, obtain the key expressions of each target text data in the second data set; the sentence vector comparison model is obtained by training the first pre-trained model based on the first data set and the first loss function.

[0061] Specifically, in this step, each target text data pair in the second data set is input into the sentence vector comparison model. The sentence vector comparison model can output the key expressions corresponding to the two target text data in each text data pair, which can be understood as [key expression 1, key expression 2] based on [long text 1, short text 1]. The key expression corresponding to each long text data can be understood as the main meaning of the long text data. The first pre-trained model is trained based on multiple short text data pairs in the first data set and the first loss function to obtain a sentence vector comparison model. The first pre-trained model refers to an existing language model. Since the existing language model is relatively mature, it is not specifically limited here. The pre-trained model can select Bert, Roberta or NEZHA. Since the data in the first data set is at least one short text data pair, and its manually annotated similarity label is a value between 0-1, the first loss function selects the mean squared error loss function (Mean Squared Error, MSE).

[0062] Step 103: Based on each key expression and the second loss function, the second pre-trained model is trained to obtain a text similarity determination model; the text similarity determination model is used to determine the similarity between text data.

[0063] Specifically, based on the above step 102, the key expressions corresponding to each target text data in the second data set are obtained, and the key expressions corresponding to each target text data in each target text data pair are input into the second pre-trained model, and the second pre-trained model is trained based on the second loss function to obtain a text similarity determination model. Similar to the above discussion, the second pre-trained model is also based on an existing language model, namely Bert, Roberta or NEZHA. The second loss function is determined based on the manually annotated similarity parameter in the second data set. When the manually annotated similarity parameter is a value between 0 and 1, the second loss function selects the MSE loss function; when the manually annotated similarity parameter is 0 or 1, the second loss function selects the cross entropy loss function.

[0064] The training method of the text similarity determination model provided by the embodiment of the present invention is by obtaining a first data set including at least one short text data pair and a second data set including at least one target text data pair, wherein at least one of the two target text data in the target text data pair is long text data; then based on the sentence vector comparison model, the key expression of each target text data in the second data set is obtained; the sentence vector comparison model is obtained by training the first pre-training model based on the first data set and the first loss function; based on the obtained key expressions and the second loss function, the second pre-training model is trained to obtain the text similarity determination model; the text similarity determination model is used to determine the similarity between text data. During the training process of the text similarity determination model of the present invention, the key expression of the target text data (including long text data) is obtained by using the sentence vector comparison model trained based on the short text data, and then the training is performed based on the key expression, the similarity between the training data is considered, the key information of the long text data is improved, and both the short text data and the long text data are taken into account, thereby improving the accuracy of the output result of the text similarity determination model.

[0065] Optionally, the above step 102 specifically includes the following steps: Figure 2 This is a second flow chart of the training method of the text similarity determination model provided by the present invention. Figure 2 As shown, the training method of the text similarity determination model provided by the present invention, based on the sentence vector comparison model, obtains the key expressions of each target text data in the second data set and specifically includes the following steps 1021 to 1026.

[0066] Step 1021: Obtain a target text data pair in the second data set.

[0067] Specifically, the minimum unit for obtaining a key expression is a target text data pair, and therefore, each target text data pair in the second data set is processed in turn, and a target text data pair in the second data set is first obtained.

[0068] Step 1022: based on punctuation marks, the first target text data and the second target text data in the target text data pair are respectively segmented to obtain a first sub-sentence set of the first target text data and a second sub-sentence set of the second target text data; the first sub-sentence set and the second sub-sentence set are merged to obtain a sentence set corresponding to the target text data pair; the sentence set includes at least two sentences.

[0069] Specifically, based on the above step 1021, a target text data pair is obtained, and then based on punctuation marks, the two target text data in the target text data pair are segmented respectively, that is, the first target text data and the second target text data in the target text data pair are segmented respectively to obtain a first sub-sentence set corresponding to the first target text data and a second sub-sentence set of the second target text data. The two sub-sentence sets of the two target text data in the target text data pair after processing are spliced ​​to obtain a sentence set corresponding to the target text data pair.

[0070] Assume that the first target text data and the second target text data After segmentation, two sentence sets are obtained, namely the first sub-sentence set , and the second set of sub-sentences ,in and Respectively represent the number of sentences in the two sub-sentence sets. Further, the first sub-sentence set and the second set of sub-sentences Merge to get the sentence set corresponding to the target text data pair .

[0071] Step 1023: Based on the sentence vector comparison model, obtain the similarity between each pair of sentences in the sentence set.

[0072] Specifically, in this step, the sentence set is input into the sentence vector comparison model to obtain the similarity between every two sentences in the sentence set.

[0073] Step 1024, constructing a weighted undirected graph with each sentence in the sentence set as a node, and determining the importance of each node based on the weighted PageRank algorithm;

[0074] Based on the above step 1023, the similarity between the two sentences in the sentence set is determined, and each sentence is used as a node to construct a weighted undirected graph. The specific method for constructing the weighted undirected graph is to preset a similarity threshold. In an embodiment of the present invention, the similarity threshold can be set to 0.8. Based on the above step 1023, the similarity between the two sentences is determined, and the similarity is compared with the similarity threshold. If the similarity is greater than the similarity threshold, it is considered that there is an edge between the nodes corresponding to the two sentences, and the weight information of the edge is the similarity. Figure 3 is a data structure diagram of the training method of the text similarity determination model provided by the present invention, such as Figure 3As shown, assuming that the sentence set obtained in the above step 1023 includes 5 sentences, A, B, C, D, E, a weighted undirected graph and an adjacency matrix corresponding to the weighted undirected graph are determined based on the similarity between the 5 sentences. W . Then, the importance of each sentence in the above total sentence set is determined based on the PageRank algorithm.

[0075] Step 1025: Sort the sentences in the first sub-sentence set and the sentences in the second sub-sentence set based on importance, select the first preset number of sentences in the first sub-sentence set as key expressions of the first target text data, and select the first preset number of sentences in the second sub-sentence set as key expressions of the second target text data.

[0076] Specifically, based on the above steps, the importance of each sentence in a sentence set corresponding to a target text data is obtained, and then based on the importance of each sentence, the first sub-sentence set is and the second set of sentences Sort the sentences in the set, starting from the first sub-sentence set Select the top K sentences with the highest importance as the key expressions corresponding to the first target text data, and select the top K sentences with the highest importance from the second sentence set The first K sentences with the highest importance are selected as the key expressions corresponding to the second target text data, where K is a positive integer greater than 0, such as K is any one of 1, 2 and 3, and preferably, K is 2.

[0077] For example, select and The sentence with the highest importance is the one in the middle, and the two sentences with the highest importance are the key expressions corresponding to their corresponding target text data.

[0078] Continue to execute the above step of obtaining a target text data pair in the second data set to obtain the key expression of each target text data in the second data set.

[0079] Specifically, the above steps 1021 - 1025 are repeatedly executed to obtain the key expression corresponding to each target text data in the second data set.

[0080] The training method of the text similarity determination model provided by the embodiment of the present invention is through obtaining a first data set and a second data set; the first data set includes at least one short text data pair; the second data set includes at least one target text data pair, and at least one of the two target text data in the target text data pair is long text data; based on the sentence vector comparison model, the key expression of each target text data in the second data set is obtained; the sentence vector comparison model is obtained by training the first pre-training model based on the first data set and the first loss function; based on the sentence vector comparison model, the key expression of the target text data can be obtained, so that the input of the final text similarity determination model contains the key expression of the long text data, that is, the core meaning of the long text data, thereby improving the accuracy of the output result of the text similarity determination model.

[0081] Optionally, the above step 103 specifically includes the following steps: Figure 4 FIG. 3 is a flow chart of the training method of the text similarity determination model provided by the present invention. Figure 4 As shown, based on each key expression and the second loss function, the second pre-trained model is trained to obtain a text similarity determination model, which specifically includes steps 1031 to 1033.

[0082] Step 1031: For each target text data pair, concatenate the key expressions of each target text data in the target text data pair to obtain a first text corresponding to the target text data pair.

[0083] Specifically, in this step, for each target text data pair, the key expressions corresponding to each target text data in the target text data pair are spliced, and the splicing method is as follows: [key expression 1][SEP][key expression 2], and the first text corresponding to the target text data pair is obtained. Each target text data pair is traversed to obtain the first text corresponding to each target text data pair in the second data set.

[0084] Step 1032: input the first texts corresponding to each target text data pair into the second pre-training model to obtain the similarities corresponding to each first text.

[0085] Specifically, the first text corresponding to each target text data is input into the second pre-trained model. Then, the first hidden layer vector and the last hidden layer vector of the second pre-trained model are average pooled and then input into the fully connected layer to output the similarity value of the two target text data in the target text data pair.

[0086] Step 1033: Train the second pre-trained model with minimizing the second loss function as a constraint condition to obtain a text similarity determination model.

[0087] Specifically, in this step, the second loss function is determined based on the manually annotated similarity labels of the second data set, and the optimization algorithm is selected, that is, when the manually annotated similarity parameter is a value between 0 and 1, the second loss function selects the MSE loss function; when the manually annotated similarity parameter is 0 or 1, the second loss function selects the cross entropy loss function. The above steps 1031-1032 are sequentially performed on the key expressions corresponding to each target text data in each target text data pair in the second data set, and the second preset model is trained with minimizing the second loss function as a constraint condition, and finally a text similarity determination model is obtained.

[0088] The training method for the text similarity determination model provided in the embodiment of the present invention trains the second pre-trained model based on the key expressions of the target text data and the second loss function, thereby improving the accuracy of the output results of the text similarity determination model.

[0089] Optionally, the second loss function can be any one of a cross entropy loss function and a mean square error loss function. That is, according to the manually annotated similarity labels of the second data set, the second loss function is determined and the optimization algorithm is selected, that is, when the manually annotated similarity parameter is a value between 0 and 1, the second loss function selects the MSE loss function; when the manually annotated similarity parameter is 0 or 1, the second loss function selects the cross entropy loss function.

[0090] Optionally, the training method of the sentence vector comparison model includes the following steps: Figure 5 FIG. 4 is a flow chart of the training method of the text similarity determination model provided by the present invention. Figure 5 As shown, the training steps of the sentence vector comparison model include steps 201 to 205.

[0091] Step 201: Input each short text data in each short text data pair in the first data set into the first pre-training model to obtain a representation vector corresponding to each short text data.

[0092] Specifically, the first pre-trained model uses an existing language model as a basic model, namely, Bert, Roberta or NEZHA. A single piece of data in the first data set, namely, a pair of short text data in a short text data pair, is respectively input into the first pre-trained model, and an average pooling operation is performed on the first layer and the last hidden layer of the first pre-trained model to obtain representation vectors u and v corresponding to short text 1 and short text 2, respectively.

[0093] Step 202: perform a whitening operation on each characterization vector to obtain a whitened feature vector corresponding to each characterization vector.

[0094] Specifically, in this step, the whitening operation is performed on the representation vectors u and v, that is, the bert-whitening technique, to obtain the whitened feature vector corresponding to the representation vector and .

[0095] Step 203: Determine a first loss function based on the cosine similarity of each whitened feature vector and the similarity in the preset label.

[0096] Specifically, in this step, the whitened feature vector is calculated and The pre-similarity between the two and the manually annotated similarity corresponding to the initial short text data corresponding to the whitened feature vector are used to calculate the average variance loss to determine the first loss function.

[0097] Step 204: Train the first pre-trained model with minimizing the first loss function as a constraint to obtain a sentence vector comparison model.

[0098] Specifically, based on the first loss function determined in step 203 above, the first pre-trained model is trained with minimizing the first loss function as a constraint condition to obtain a sentence vector comparison model.

[0099] The training method for the text similarity determination model provided in an embodiment of the present invention performs corresponding processing on short text data, trains a first pre-trained model based on a first loss function, and the obtained sentence vector comparison model is applied to subsequent steps to lay the foundation for the training of the text similarity determination model.

[0100] Optionally, the specific method of the above step 1024, i.e., constructing a weighted undirected graph with each sentence in each sentence set as a node and determining the importance of each node based on the weighted PageRank algorithm is as follows:

[0101] First, the pre-weight of each node needs to be determined. In fact, each node corresponds to each sentence in the sentence set, and the pre-weight is determined according to the position of the sentence in the article. Generally speaking, the article follows the format of "total-specific" or "total-specific-total". The position of the sentence in an article can indicate the importance of the sentence. For example, in news reports, the title is often a summary of the main content or viewpoint of an article, while the first and last sentences in a paragraph are often a summary of the paragraph. Therefore, a method for determining the pre-weight according to the nature or position of the sentence is proposed. In the specific implementation, for an article, the title of the article is set to have the highest weight, such as 3; the first sentence of each paragraph has the second highest weight, such as 2; and the weight of the sentences other than this is the lowest, such as 1. It may be adjusted according to different actual business. For example, the titles of some entertainment articles may just be eye-catching expressions without any actual meaning, so they can be set to 1 at this time. Further, after the pre-weight is determined, the importance of the sentence is calculated according to the PageRank algorithm. The specific calculation formula is:

[0102]

[0103] in, Indicates The importance of a node, Indicates link to The node set of nodes, Indicates that from The set of nodes that the node goes out of, express The number of nodes in the is the damping coefficient, generally taken as 0.85, For the The pre-weight of the nodes, Indicates Nodes and The similarity between nodes.

[0104] So far, we have obtained the importance of each sentence. Generally speaking, according to the importance of the sentence, we take and Among the preset number of sentences with the highest importance, in this embodiment of the present invention, the two sentences with the highest importance can be removed, thereby obtaining the key expressions of the two target text data.

[0105] The training method for the text similarity determination model provided by the embodiment of the present invention takes the position of the target text data in the corresponding article as the pre-weight of the sentence vector corresponding to the target text data, takes into account the importance of the content at different positions of the target text data, and is conducive to extracting the core meaning of long text data, so as to improve the accuracy of the output results of the text similarity determination model.

[0106] The present invention also provides a text similarity calculation method. The text similarity calculation method of the embodiment of the present invention is implemented based on any of the above-mentioned text similarity determination models. Figure 6 It is a flow chart of the text similarity calculation method provided by the present invention, such as Figure 6 As shown, the text similarity calculation method includes steps 301 to 304.

[0107] Step 301: Obtain a text data pair whose similarity is to be determined; the text data pair includes long text data and set text data, and the set text data is long text data or short text data.

[0108] Specifically, in this step, a pair of text data to be processed, that is, a text data pair, is obtained. The text data pair includes a long text data and a short text data, or the text data pair includes two long text data.

[0109] Step 302: segment the text data pair to obtain a first sentence set corresponding to the text data pair; the first sentence set includes at least two sentence units.

[0110] Specifically, in this step, based on punctuation marks, two text data in the text data pair, namely the long text data and the set text data, are segmented respectively to obtain a first sentence set corresponding to the text data pair, wherein the first sentence set includes a plurality of sentence units;

[0111] Step 303: Based on the sentence vector comparison model, obtain the first key expression corresponding to the long text data and the second key expression of the set text data.

[0112] Specifically, in this step, based on the sentence vector comparison model, the key expressions corresponding to the two text data in the text data pair are obtained, that is, the first key expression corresponding to the long text data and the second key expression corresponding to the set text data.

[0113] Step 304: splice the first key expression and the second key expression and input them into the text similarity determination model to obtain the similarity between the long text data and the set text data.

[0114] Specifically, in this step, it is necessary to first splice the two key expressions (the first key expression and the second key expression) obtained in the above step 303, and then input the spliced ​​key expressions into the text similarity determination model to obtain the similarity between the two text data in the text data pair, that is, the similarity between the long text data and the set text data.

[0115] The text similarity calculation method provided by the embodiment of the present invention divides the acquired text data pairs, inputs the first sentence set corresponding to the text data pairs obtained after the division into the sentence vector comparison model, obtains the key expressions corresponding to each text data in the text data pair, splices the key expressions, inputs them into the text similarity determination model, and obtains the similarity of the two text data in the text data pair. The accuracy of similarity calculation between long text data and long text data or between long text data and short text data is improved.

[0116] The text similarity calculation device provided by the present invention is described below. The text similarity calculation device described below and the text similarity calculation method described above can be referred to each other. Figure 7 is a schematic diagram of the structure of the text similarity calculation device provided by the present invention, such as Figure 7 As shown, the text similarity calculation device includes:

[0117] The first acquisition module 701 is used to acquire a text data pair whose similarity is to be determined; the text data pair includes long text data and set text data, and the set text data is long text data or short text data;

[0118] A segmentation module 702 is used to segment the text data pair to obtain a first sentence set corresponding to the text data pair; the first sentence set includes at least two sentence units;

[0119] A second acquisition module 703 is used to acquire a first key expression corresponding to the long text data and a second key expression of the set text data based on a sentence vector comparison model;

[0120] The determination module 704 is used to concatenate the first key expression and the second key expression and input the concatenated ...

[0121] The text similarity calculation device provided by the embodiment of the present invention, through the mutual cooperation between various modules, segments the acquired text data pairs, inputs the first sentence set corresponding to the text data pairs obtained after segmentation into the sentence vector comparison model, obtains the key expressions corresponding to each text data in the text data pair, splices the key expressions, inputs them into the text similarity determination model, and obtains the similarity between the long text data and the set text data in the text data pair. The accuracy of similarity calculation between long text data and long text data or between long text data and short text data is improved.

[0122] Figure 8 is a schematic diagram of the structure of the electronic device provided by the present invention, Figure 8 An example of a physical structure diagram of an electronic device is shown in FIG. Figure 8As shown, the electronic device may include: a processor 810, a communication interface 820, a memory 830 and a communication bus 840, wherein the processor 810, the communication interface 820 and the memory 830 communicate with each other through the communication bus 840. The processor 810 may call the logic instructions in the memory 830 to execute the training method of the above-mentioned text similarity determination model, the method comprising: obtaining a first data set and a second data set; the first data set includes at least one short text data pair; the second data set includes at least one target text data pair, at least one of the two target text data in the target text data pair is a long text data; based on the sentence vector comparison model, the key expression of each target text data in the second data set is obtained; the sentence vector comparison model is obtained by training the first pre-training model based on the first data set and the first loss function; based on each of the key expressions and the second loss function, the second pre-training model is trained to obtain a text similarity determination model; the text similarity determination model is used to determine the similarity between text data. Or execute the above-mentioned text similarity calculation method, including: obtaining a text data pair whose similarity is to be determined; the text data pair includes long text data and set text data, and the set text data is long text data or short text data; segmenting the text data pair to obtain a first sentence set corresponding to the text data pair; the first sentence set includes at least two sentence units; based on a sentence vector comparison model, obtaining a first key expression corresponding to the long text data and a second key expression of the set text data; splicing the first key expression and the second key expression and inputting them into a text similarity determination model to obtain the similarity between the long text data and the set text data.

[0123] In addition, the logic instructions in the above-mentioned memory 830 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art or the part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.

[0124] On the other hand, the present invention also provides a computer program product, which includes a computer program, and the computer program can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the training method of the text similarity determination model provided by the above-mentioned methods, and the method includes: obtaining a first data set and a second data set; the first data set includes at least one short text data pair; the second data set includes at least one target text data pair, and at least one of the two target text data in the target text data pair is a long text data; based on a sentence vector comparison model, obtaining a key expression of each of the target text data in the second data set; the sentence vector comparison model is obtained by training a first pre-trained model based on the first data set and a first loss function; based on each of the key expressions and the second loss function, training the second pre-trained model to obtain a text similarity determination model; the text similarity determination model is used to determine the similarity between text data. Or execute the above-mentioned text similarity calculation method, including: obtaining a text data pair whose similarity is to be determined; the text data pair includes long text data and set text data, and the set text data is long text data or short text data; segmenting the text data pair to obtain a first sentence set corresponding to the text data pair; the first sentence set includes at least two sentence units; based on a sentence vector comparison model, obtaining a first key expression corresponding to the long text data and a second key expression of the set text data; splicing the first key expression and the second key expression and inputting them into a text similarity determination model to obtain the similarity between the long text data and the set text data.

[0125] On the other hand, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to execute the training method of the text similarity determination model provided by the above-mentioned methods, the method comprising: obtaining a first data set and a second data set; the first data set includes at least one short text data pair; the second data set includes at least one target text data pair, at least one of the two target text data in the target text data pair is a long text data; based on a sentence vector comparison model, obtaining key expressions of each of the target text data in the second data set; the sentence vector comparison model is obtained by training a first pre-trained model based on the first data set and a first loss function; based on each of the key expressions and the second loss function, training the second pre-trained model to obtain a text similarity determination model; the text similarity determination model is used to determine the similarity between text data. Or execute the above-mentioned text similarity calculation method, including: obtaining a text data pair whose similarity is to be determined; the text data pair includes long text data and set text data, and the set text data is long text data or short text data; segmenting the text data pair to obtain a first sentence set corresponding to the text data pair; the first sentence set includes at least two sentence units; based on a sentence vector comparison model, obtaining a first key expression corresponding to the long text data and a second key expression of the set text data; splicing the first key expression and the second key expression and inputting them into a text similarity determination model to obtain the similarity between the long text data and the set text data.

[0126] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.

[0127] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.

[0128] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A training method for a text similarity determination model, characterized in that: include: Acquire a first data set and a second data set; the first data set includes at least one short text data pair; the second data set includes at least one target text data pair, and at least one of the two target text data in the target text data pair is long text data; Based on the sentence vector comparison model, obtaining the key expressions of each of the target text data in the second data set; the sentence vector comparison model is obtained by training the first pre-training model based on the first data set and the first loss function; The acquiring, based on the sentence vector comparison model, a key expression of each of the target text data in the second data set includes: Acquire a target text data pair in the second data set; Based on punctuation marks, first target text data and second target text data in the target text data pair are segmented to obtain a first sub-sentence set of the first target text data and a second sub-sentence set of the second target text data; Merging the first sub-sentence set and the second sub-sentence set to obtain a sentence set corresponding to the target text data pair; the sentence set includes at least two sentences; Based on the sentence vector comparison model, obtaining the similarity between two sentences in the sentence set; Constructing a weighted undirected graph with each sentence in the sentence set as a node, and determining the importance of each node based on a weighted PageRank algorithm; Sort the sentences in the first sub-sentence set and the sentences in the second sub-sentence set based on the importance, select a first preset number of sentences in the first sub-sentence set as key expressions of the first target text data, and select a first preset number of sentences in the second sub-sentence set as key expressions of the second target text data; Continue to execute the step of acquiring a target text data pair in the second data set to obtain a key expression of each target text data in the second data set; Based on each of the key expressions and the second loss function, the second pre-trained model is trained to obtain a text similarity determination model; the text similarity determination model is used to determine the similarity between text data; The second pre-training model is trained based on each of the key expressions and the second loss function to obtain a text similarity determination model, including: For each of the target text data pairs, concatenate the key expressions of the target text data in the target text data pair to obtain a first text corresponding to the target text data pair; Inputting the first text corresponding to each of the target text data pairs into the second pre-training model to obtain the similarity corresponding to each of the first texts; The second pre-trained model is trained with minimizing the second loss function as a constraint condition to obtain the text similarity determination model.

2. The training method for determining a text similarity model according to claim 1, characterized in that: The second loss function is any one of a cross entropy loss function and a mean square error loss function.

3. The training method for determining a text similarity model according to claim 1, characterized in that: The method further comprises: Inputting each short text data in each pair of the short text data in the first data set into the first pre-trained model to obtain a representation vector corresponding to each short text data; Performing a whitening operation on each of the characterization vectors to obtain a whitened feature vector corresponding to each of the characterization vectors; Determining the first loss function based on the cosine similarity of each of the whitened feature vectors and the similarity in the preset label; The first pre-trained model is trained with minimizing the first loss function as a constraint to obtain the sentence vector comparison model.

4. The training method for determining a text similarity model according to claim 1, characterized in that: The step of constructing a weighted undirected graph with each sentence in the sentence set as a node and determining the importance of each node based on a weighted PageRank algorithm includes: Based on the number of nodes in the sentence set and the pre-weight of each node, the importance of each node is determined using formula (1): (1) in, Indicates The importance of a node, Indicates link to The node set of nodes, Indicates that from The set of nodes that the node goes out of, express The number of nodes in the is the damping coefficient, For the The pre-weight of the nodes, Indicates Nodes and The similarity between nodes.

5. A method for calculating text similarity, implemented based on the text similarity determination model described in any one of claims 1 to 4, characterized in that: include: Acquire a text data pair whose similarity is to be determined; the text data pair includes long text data and set text data, and the set text data is long text data or short text data; Segmenting the text data pair to obtain a first sentence set corresponding to the text data pair; the first sentence set includes at least two sentence units; Based on the sentence vector comparison model, obtaining a first key expression corresponding to the long text data and a second key expression of the set text data; The first key expression and the second key expression are concatenated and input into a text similarity determination model to obtain the similarity between the long text data and the set text data.

6. A text similarity calculation device, characterized in that: include: A first acquisition module is used to acquire a text data pair whose similarity is to be determined; the text data pair includes long text data and set text data, and the set text data is long text data or short text data; A segmentation module, configured to segment the text data pair to obtain a first sentence set corresponding to the text data pair; the first sentence set includes at least two sentence units; A second acquisition module, configured to acquire a first key expression corresponding to the long text data and a second key expression of the set text data based on a sentence vector comparison model; A determination module, configured to concatenate the first key expression and the second key expression and input the concatenated expression into a text similarity determination model to obtain a similarity between the long text data and the set text data; The training method of the text similarity determination model comprises the following steps: Acquire a first data set and a second data set; the first data set includes at least one short text data pair; the second data set includes at least one target text data pair, and at least one of the two target text data in the target text data pair is long text data; Based on the sentence vector comparison model, obtaining the key expressions of each of the target text data in the second data set; the sentence vector comparison model is obtained by training the first pre-training model based on the first data set and the first loss function; The acquiring, based on the sentence vector comparison model, a key expression of each of the target text data in the second data set includes: Acquire a target text data pair in the second data set; Based on punctuation marks, first target text data and second target text data in the target text data pair are segmented to obtain a first sub-sentence set of the first target text data and a second sub-sentence set of the second target text data; Merging the first sub-sentence set and the second sub-sentence set to obtain a sentence set corresponding to the target text data pair; the sentence set includes at least two sentences; Based on the sentence vector comparison model, obtaining the similarity between two sentences in the sentence set; Constructing a weighted undirected graph with each sentence in the sentence set as a node, and determining the importance of each node based on a weighted PageRank algorithm; Sort the sentences in the first sub-sentence set and the sentences in the second sub-sentence set based on the importance, select a first preset number of sentences in the first sub-sentence set as key expressions of the first target text data, and select a first preset number of sentences in the second sub-sentence set as key expressions of the second target text data; Continue to execute the step of acquiring a target text data pair in the second data set to obtain a key expression of each target text data in the second data set; Based on each of the key expressions and the second loss function, the second pre-trained model is trained to obtain a text similarity determination model; the text similarity determination model is used to determine the similarity between text data; The second pre-training model is trained based on each of the key expressions and the second loss function to obtain a text similarity determination model, including: For each of the target text data pairs, concatenate the key expressions of the target text data in the target text data pair to obtain a first text corresponding to the target text data pair; Inputting the first text corresponding to each of the target text data pairs into the second pre-training model to obtain the similarity corresponding to each of the first texts; The second pre-trained model is trained with minimizing the second loss function as a constraint condition to obtain the text similarity determination model.

7. 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 training method for determining a text similarity model according to any one of claims 1 to 4 or the text similarity calculation method according to claim 5 is implemented.

8. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the training method for determining a text similarity model according to any one of claims 1 to 4 or the text similarity calculation method according to claim 5 is implemented.

Citation Information

Patent Citations

  • Short text similarity calculating method

    CN106484664A

  • Chinese text abstract extraction method and device based on BERT pre-training model

    CN114428852A