Text similarity discrimination method, device, computer equipment and storage medium
By constructing a cost matrix and an optimal transfer matrix, removing some constraints on all-one vectors, and explicitly fusing the distance between token pairs, the problems of high computational complexity and misleading information in existing technologies are solved, achieving more accurate text similarity discrimination and improving the accuracy of intelligent question answering between doctors and patients.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-02
- Publication Date
- 2026-03-27
AI Technical Summary
Existing technologies have high computational complexity in text similarity discrimination and cannot explicitly perform semantic alignment at the token level, leading to calculation errors and misleading patient responses.
By constructing a cost matrix and an optimal transmission matrix, removing some constraints on all-one vectors, deriving the relaxed optimal transmission distance, and explicitly fusing the distance between token pairs, the calculation process is simplified and accuracy is improved.
It achieves more accurate and interpretable text similarity discrimination at the token-level, reduces computational complexity and the risk of misleading, and improves the accuracy of intelligent question answering between doctors and patients.
Smart Images

Figure CN116738244B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the medical field and can be applied to intelligent question-and-answer between doctors and patients. In particular, it relates to a text similarity discrimination method, device, computer equipment, and storage medium. Background Technology
[0002] Currently, many hospitals have online medical consultation programs, allowing patients to consult with doctors. To improve efficiency, AI is typically prioritized to provide intelligent answers to patient questions. These programs usually include a list of frequently asked questions for patient reference. Users can submit their questions following the prompts. However, user-submitted questions often differ from the standard questions. Therefore, it's necessary to determine the similarity between the patient's input and the program's frequently asked questions. The AI selects the most similar pre-set question and sends its answer to the patient. Currently, methods for capturing the similarity between sentence embeddings by fine-tuning pre-trained language models have achieved very effective results, such as the SimCSE (Simple Contrastive Learning of Sentence Embeddings) method. Specifically, these methods first define a similarity score for sentence embeddings, typically using cosine similarity. Then, they fine-tune the BERT (Bidirectional Encoder Representations from Transformer) model using NLI (Natural Language Inference) or STS (Sequence Tagged Sites) datasets. The sentence embeddings are often obtained through the last layer of BERT's average pooling or by directly taking the embeddings of [CLS] (Common Language Specification) tokens. However, finding cross-sentence alignment at the token level and calculating the importance of each aligned part is generally beneficial for analyzing sentence similarity. Current methods do not achieve this explicit cross-sentence alignment at the token level. Cross-sentence alignment can be simply understood as finding semantically matching token pairs between two sentences. Current methods use average token embedding to obtain sentence representations for calculating sentence similarity. This is sentence-level modeling and cannot explicitly fuse the distance between semantically aligned token pairs at the token-level. Moreover, the computational complexity of finding the optimal transfer matrix T in this process is very high, requiring a large investment of manpower and resources. In severe cases, calculation errors may even occur. If these erroneous results are used to answer patients' questions, it may mislead them.
[0003] Therefore, how to perform text similarity discrimination in a simpler, more efficient, and more accurate way with strong interpretability has become an urgent problem to be solved. Summary of the Invention
[0004] The main objective of this invention is to provide a text similarity discrimination method, apparatus, computer device, and storage medium, aiming to solve the technical problems that current text similarity discrimination methods are not simple enough, efficient enough, accurate enough, and have insufficient interpretability.
[0005] To achieve the aforementioned objectives, the first aspect of this invention proposes a text similarity determination method, comprising:
[0006] Obtain the token embeddings of two sentences to be judged, and construct a cost matrix based on the token embeddings of the two sentences to be judged; the optimal solution to the optimal problem of the cost matrix is the optimal transmission matrix, and the transmission distance corresponding to the optimal transmission matrix is the optimal transmission distance;
[0007] Construct a first mathematical relationship between the total cost, cost matrix, optimal transmission matrix, and optimal transmission distance during the transmission of the two sentences to be determined;
[0008] The state vectors of the two sentences to be determined are defined as all-1 vectors normalized to their own sentence lengths; the all-1 vectors include the first constraint and the second constraint.
[0009] By removing either the first constraint or the second constraint from the all-1 vector, the relaxation equation is obtained.
[0010] By combining the relaxation equations with the first mathematical relation, the optimal transmission distance after relaxation is derived, and the similarity between the two sentences to be judged is determined using the optimal transmission distance after relaxation.
[0011] Furthermore, the cost matrix has a dimension of L1*L2; where L1 is the token length of sentence 1 and L2 is the token length of sentence 2, and the cost matrix uses cosine distance to encode token similarity.
[0012] Furthermore, the expression for the first mathematical relation is:
[0013]
[0014]
[0015] in, For the total cost, The embedding of the i-th word in sentence 1. This represents the embedding of the j-th word in the second sentence. The optimal transmission matrix is... This is the optimal transmission distance.
[0016] Furthermore, the expression for the all-1 vector is:
[0017]
[0018] Where, d 1 and d 2 Both are all-one vectors; L1 is the token length of sentence 1, and L2 is the token length of sentence 2.
[0019] Further, the step of removing either the first constraint or the second constraint from the all-1 vector to obtain the relaxation equation includes:
[0020] Removing the first constraint from the all-1 vector yields the relaxation equation:
[0021]
[0022] or,
[0023] Removing the second constraint from the all-1 vector yields the relaxation equation:
[0024]
[0025] in This is the optimal transfer matrix after relaxation.
[0026] Further, the step of deriving the relaxed optimal transmission distance by combining the relaxation equations with the first mathematical relation, and then using the relaxed optimal transmission distance to determine the similarity between the two sentences to be determined, includes:
[0027] According to the preset conversion relationship, the relaxed optimal transmission distance of the two sentences to be judged is converted into a similarity score;
[0028] The degree of similarity between the two sentences to be judged is determined based on their similarity scores.
[0029] Furthermore, after the step of determining the degree of similarity between the two sentences based on their similarity scores, the method further includes:
[0030] A text similarity discrimination model is constructed based on the similarity scores of the two sentences to be judged;
[0031] The text similarity discrimination model is fine-tuned using preset rules.
[0032] A second aspect of the present invention provides a text similarity discrimination device, comprising:
[0033] The first construction module is used to obtain the token embeddings of two sentences to be judged, and construct a cost matrix based on the token embeddings of the two sentences to be judged; the optimal solution of the optimal problem of the cost matrix is the optimal transmission matrix, and the transmission distance corresponding to the optimal transmission matrix is the optimal transmission distance;
[0034] The second construction module is used to construct a first mathematical relationship between the total cost, cost matrix, optimal transmission matrix and optimal transmission distance during the transmission of the two sentences to be judged.
[0035] The normalization module is used to define the state vectors of the two sentences to be judged as all-1 vectors normalized by their own sentence lengths; the all-1 vectors include the first constraint and the second constraint.
[0036] The relaxation module is used to remove either the first constraint or the second constraint from the all-1 vector to obtain the relaxation equation;
[0037] The discrimination module is used to combine the relaxation equation with the first mathematical relation to derive the optimal transmission distance after relaxation, and use the optimal transmission distance after relaxation to determine the similarity between the two sentences to be judged.
[0038] A third aspect of the present invention provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps of the text similarity discrimination method described in any of the preceding claims.
[0039] A fourth aspect of the present invention provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of the text similarity discrimination method described in any of the preceding claims.
[0040] This invention relates to the medical field and can be applied to intelligent doctor-patient question answering. It discloses a text similarity discrimination method, a computer device, and a storage medium. The method includes a text similarity discrimination method comprising:
[0041] The method obtains the token embeddings of two sentences to be judged and constructs a cost matrix based on the token embeddings. The optimal solution to the optimal problem of the cost matrix is the optimal transmission matrix, and the transmission distance corresponding to the optimal transmission matrix is the optimal transmission distance. A first mathematical relationship is constructed between the total cost, cost matrix, optimal transmission matrix, and optimal transmission distance during the transmission process of the two sentences to be judged. The state vectors of the two sentences to be judged are defined as all-1 vectors normalized to their own sentence lengths. The all-1 vectors include a first constraint and a second constraint. Considering the very high computational complexity of directly finding the optimal transmission matrix T, this invention chooses to remove either the first constraint or the second constraint from the all-1 vector to obtain a relaxation equation. The relaxation equation is combined with the first mathematical relationship to derive the relaxed optimal transmission distance, and the similarity of the two sentences to be judged is determined using the relaxed optimal transmission distance, greatly simplifying the execution process of this method. Furthermore, the above method explicitly integrates semantically aligned tokens at the token-level. The distance between pairs has a more accurate and interpretable technical advantage compared to the existing sentence-level alignment. It can more accurately determine the similarity between the questions raised by patients and the questions in the system's question bank, thereby achieving accurate answers to patients' questions. Attached Figure Description
[0042] Figure 1 A flowchart of a text similarity determination method according to an embodiment of the invention;
[0043] Figure 2 A flowchart of a text similarity discrimination device according to an embodiment of the invention;
[0044] Figure 3 This is a schematic diagram of the structure of a computer device and storage medium according to an embodiment of the invention. Detailed Implementation
[0045] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0046] Those skilled in the art will understand that, unless specifically stated otherwise, the singular forms “a,” “an,” “the,” and “the” used herein may also include the plural forms. It should be further understood that the term “comprising” as used in this specification means the presence of features, integers, steps, operations, elements, modules, and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, modules, components, and / or groups thereof. It should be understood that when we say an element is “connected” or “coupled” to another element, it can be directly connected or coupled to the other element, or there may be intermediate elements. Furthermore, “connected” or “coupled” as used herein can include wireless connections or wireless coupling. The term “and / or” as used herein includes all or any modules and all combinations of one or more associated listed items.
[0047] It will be understood by those skilled in the art that, unless otherwise defined, all terms used herein (including technical and scientific terms) have the same meaning as commonly understood by one of ordinary skill in the art to which this invention pertains. It should also be understood that terms such as those defined in general dictionaries should be understood to have the same meaning as in the context of the prior art, and should not be interpreted in an idealized or overly formal sense unless specifically defined as herein.
[0048] Reference Figure 1 This application provides a text similarity determination method, including the following steps S1-S5:
[0049] S1: Obtain the token embeddings of the two sentences to be judged, and construct a cost matrix based on the token embeddings of the two sentences to be judged; the optimal solution of the optimal problem of the cost matrix is the optimal transmission matrix, and the transmission distance corresponding to the optimal transmission matrix is the optimal transmission distance.
[0050] The purpose of token embedding is to map human language into a geometric space. Token embeddings are low-dimensional floating-point vectors (i.e., dense vectors, as opposed to sparse vectors).
[0051] In this embodiment, word embeddings are learned simultaneously with the main task (i.e., sentence transmission). Initially, random word vectors are used, and these vectors are then learned in the same way as the weights of the neural network. Pre-computed word embeddings are used on a different machine learning task than the one being solved, and then loaded into the model. In this embodiment, the original text of the two sentences to be judged is converted into a format that the neural network can process, and then the embedding layer of the Keras model is used to learn task-specific labeled embeddings; using pre-trained word embeddings provides additional performance improvements on small natural language processing problems.
[0052] In this embodiment, the cost matrix has a dimension of L1*L2; where L1 is the token length of sentence 1 and L2 is the token length of sentence 2. The cost matrix uses cosine distance to encode token similarity, converting cosine similarity into cosine distance.
[0053] in This represents the embedding of the i-th word in the first sentence. This represents the embedding of the j-th word in the second sentence.
[0054] S2: Construct the first mathematical relationship between the total cost, cost matrix, optimal transmission matrix and optimal transmission distance during the transmission process of the two sentences to be judged.
[0055] In this embodiment, a preset transmission model is first used to transmit the two sentences to be judged, taking into account the three major components of the optimal transmission problem: the state d before transmission. 1 The state d after transmission 2 The cost matrix M. The optimal transport problem is to solve for the state d. 1 Transition to state d 2 The function T that minimizes the total cost is called the optimal transmission matrix. In this embodiment, the first mathematical relationship is as follows:
[0056]
[0057]
[0058] in, For the total cost, The embedding of the i-th word in sentence 1. This represents the embedding of the j-th word in the second sentence. The optimal transmission matrix is... This is the optimal transmission distance.
[0059] S3: Define the state vectors of the two sentences to be determined as all-1 vectors normalized to their own sentence lengths; the all-1 vectors include the first constraint and the second constraint.
[0060] In this embodiment, the state vectors of the two sentences to be determined are defined as all-one vectors normalized to their own sentence lengths, i.e., the state vector of sentence 1 is d. 1 The state vector for sentence 2 is d. 2 d 1 and d 2 The lengths of the tokens for sentences 1 and 2 are respectively, and the element M of the cost matrix is... i,j Let T represent the cosine distance between the token embeddings of token i in sentence 1 and token j in sentence 2. The optimal transfer matrix T to be solved is the contribution of each token pair to the sentence similarity, which is a weight matrix.
[0061] In this embodiment, the expression for the all-1 vector is:
[0062]
[0063] Where, d 1 and d 2 Both are all-one vectors; L1 is the token length of sentence 1, and L2 is the token length of sentence 2.
[0064] In this embodiment, the all-1 vector includes a first constraint and a second constraint. The first constraint restricts the sum of row vectors to 1, and the second constraint restricts the sum of column vectors to 1.
[0065] S4: Remove either the first constraint or the second constraint from the all-1 vector to obtain the relaxation equation.
[0066] In this embodiment, considering that the vocabulary involved in the doctor-patient intelligent question-and-answer is very large and the language used by patients may not be uniform, the computational complexity of finding the optimal transmission matrix T is very high. Therefore, it is possible to appropriately relax the two constraints of the optimal transmission problem (i.e., the first constraint and the second constraint) to obtain the relaxation equation, which provides technical simplification for subsequent discrimination, reduces the investment of manpower and material resources, and minimizes the probability of calculation errors.
[0067] S5: Combine the relaxation equation with the first mathematical relation to derive the optimal transmission distance after relaxation, and use the optimal transmission distance after relaxation to determine the similarity between the two sentences to be judged.
[0068] In this embodiment, the first mathematical relation is:
[0069]
[0070]
[0071] If the first constraint is removed from the all-1 vector, the resulting relaxation equation is:
[0072]
[0073] If the second constraint is removed from the all-1 vector, the resulting relaxation equation is:
[0074]
[0075] in This is the optimal transfer matrix after relaxation.
[0076] In this embodiment, the mathematical meaning of the relaxation equation is to find the minimum value in the row or column vector. If the first constraint condition in the all-1 vector is removed, the mathematical meaning of the relaxation equation is to find the minimum value in the row vector. If the second constraint condition in the all-1 vector is removed, the mathematical meaning of the relaxation equation is to find the minimum value in the column vector.
[0077] By removing some constraints, the complexity of solving all-one vectors is significantly reduced while still meeting the requirements for text similarity discrimination. This reduces the investment of human and material resources, effectively avoids potential computational errors, and prevents patients from being misled by responding to their questions based on these erroneous results.
[0078] This embodiment determines the similarity of two sentences to be judged by the optimal transmission distance after relaxation. It explicitly fuses the distance between semantically aligned token pairs at the token-level, which has more accurate and interpretable technical advantages compared to the existing sentence-level alignment. This helps to more accurately identify and intelligently respond to patients' questions.
[0079] In this embodiment, step S5, which involves sufficing the relaxation equation with the first mathematical relation to derive the relaxed optimal transmission distance and using the relaxed optimal transmission distance to determine the similarity between two sentences to be judged, includes:
[0080] S51. Based on the preset conversion relationship, convert the relaxed optimal transmission distance of the two sentences to be judged into a similarity score.
[0081] In this embodiment, the relaxed optimal transmission distance first needs to be converted into a similarity score. REMD1 and REMD2 are calculated in the same way:
[0082]
[0083]
[0084] in To constrain the first constraint, the similarity score is obtained. The similarity score is obtained after restricting the second constraint condition.
[0085] Average REMD1 and REMD2 to account for bidirectional semantic alignment between the two sentences; this provides different gradient signals during optimization. The final similarity is described as follows:
[0086]
[0087] S52. Based on the similarity scores of the two sentences to be judged, determine the degree of similarity between the two sentences to be judged.
[0088] Based on the similarity scores of the two sentences to be judged The similarity between the two sentences to be judged is rated by comparing them with a preset similarity score parameter table. In one embodiment, a similarity score of 0-0.33 is considered low similarity, a similarity score of 0.34-0.66 is considered medium similarity, and a similarity score of 0.67-1.00 is considered high similarity.
[0089] In another embodiment, after step S52 of determining the degree of similarity between the two sentences to be determined based on their similarity scores, the method further includes:
[0090] S521. Construct a text similarity discrimination model based on the similarity scores of the two sentences to be judged;
[0091] S522. Fine-tune the text similarity discrimination model using preset rules.
[0092] In this embodiment, considering that in the medical field, patients often ask multiple questions simultaneously during intelligent doctor-patient question-and-answer sessions, it is necessary to simultaneously judge multiple sentence pairs. These sentence pairs often have certain connections, and when calculating the similarity of a particular sentence pair, the influence of other sentence pairs being judged together needs to be considered. Therefore, it is necessary to fine-tune the text similarity judgment model using preset rules. In this embodiment, the text similarity judgment model is...
[0093] In one embodiment, a total of n sentence pairs are evaluated. After fine-tuning the text similarity evaluation model, the similarity of the i-th (i = 1, 2, 3, ..., n) sentence pair is:
[0094]
[0095] in Let be the similarity score of the i-th sentence after positive fine-tuning of the text similarity discrimination model. The similarity score of the i-th sentence after negative fine-tuning of the text similarity discrimination model.
[0096] As described above, in this application, the token embeddings of two sentences to be judged are obtained, and a cost matrix is constructed based on the token embeddings of the two sentences to be judged. The optimal solution to the optimal problem of the cost matrix is the optimal transmission matrix, and the transmission distance corresponding to the optimal transmission matrix is the optimal transmission distance. A first mathematical relationship is constructed between the total cost, cost matrix, optimal transmission matrix, and optimal transmission distance during the transmission process of the two sentences to be judged. The state vectors of the two sentences to be judged are defined as all-1 vectors normalized by their own sentence lengths. The all-1 vectors include a first constraint and a second constraint. Considering that the computational complexity of directly finding the optimal transmission matrix T is very high, this invention chooses to remove either the first constraint or the second constraint from the all-1 vector to obtain a relaxation equation. The relaxation equation is combined with the first mathematical relationship to derive the relaxed optimal transmission distance, and the similarity of the two sentences to be judged is determined using the relaxed optimal transmission distance, which greatly simplifies the execution process of this method. Moreover, the above method explicitly integrates semantically aligned tokens at the token-level. The distance between pairs has a more accurate and interpretable technical advantage compared to the existing sentence-level alignment.
[0097] Reference Figure 2 This invention also provides a text similarity discrimination device, comprising:
[0098] The first construction module 10 is used to obtain the token embeddings of two sentences to be judged, and construct a cost matrix based on the token embeddings of the two sentences to be judged; the optimal solution of the optimal problem of the cost matrix is the optimal transmission matrix, and the transmission distance corresponding to the optimal transmission matrix is the optimal transmission distance.
[0099] The second construction module 20 is used to construct a first mathematical relationship between the total cost, cost matrix, optimal transmission matrix and optimal transmission distance during the transmission of the two sentences to be judged.
[0100] The normalization module 30 is used to define the state vectors of the two sentences to be judged as all-1 vectors normalized by their own sentence lengths; the all-1 vectors include the first constraint and the second constraint.
[0101] The relaxation module 40 is used to remove either the first constraint or the second constraint from the all-1 vector to obtain the relaxation equation;
[0102] The discrimination module 50 is used to combine the relaxation equation with the first mathematical relation to derive the optimal transmission distance after relaxation, and use the optimal transmission distance after relaxation to determine the similarity between the two sentences to be judged.
[0103] As described above, the text similarity discrimination device can implement the text similarity discrimination method.
[0104] In one embodiment, the cost matrix has a dimension of L1*L2; where L1 is the token length of sentence 1 and L2 is the token length of sentence 2, and the cost matrix uses cosine distance to encode token similarity.
[0105] In one embodiment, the expression for the first mathematical relation is:
[0106]
[0107]
[0108] in, For the total cost, The embedding of the i-th word in sentence 1. This represents the embedding of the j-th word in the second sentence. The optimal transmission matrix is... This is the optimal transmission distance.
[0109] In one embodiment, the expression for the all-1 vector is:
[0110]
[0111] Where, d 1 and d 2 All are vectors consisting entirely of 1s.
[0112] In one embodiment, the relaxation module 40 includes:
[0113] Removing the first constraint from the all-1 vector yields the relaxation equation:
[0114]
[0115] or,
[0116] Removing the second constraint from the all-1 vector yields the relaxation equation:
[0117]
[0118] in This is the optimal transfer matrix after relaxation.
[0119] In one embodiment, the discrimination module 50 includes:
[0120] A conversion unit is used to convert the relaxed optimal transmission distance of the two sentences to be judged into a similarity score according to a preset conversion relationship;
[0121] The determination unit is used to determine the degree of similarity between the two sentences to be determined based on their similarity scores.
[0122] In one embodiment, the text similarity determination device further includes:
[0123] The construction unit is used to construct a text similarity discrimination model based on the similarity scores of the two sentences to be judged.
[0124] The adjustment unit is used to fine-tune the text similarity discrimination model using preset rules.
[0125] Reference Figure 3 The present invention also provides a computer device, the internal structure of which can be as follows: Figure 3As shown, this computer device includes a processor, memory, network interface, and database connected via a system bus. The processor is designed to provide computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores operating devices, computer programs, and a database. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The database stores valid lead signals, etc. The network interface allows external terminals to communicate via a network. Furthermore, the computer device may also include input devices and a display screen, etc. When the aforementioned computer program is executed by a processor to implement a text similarity discrimination method, it includes the following steps: obtaining the token embeddings of two sentences to be judged, and constructing a cost matrix based on the token embeddings of the two sentences to be judged; the optimal solution to the optimal problem of the cost matrix is the optimal transmission matrix, and the transmission distance corresponding to the optimal transmission matrix is the optimal transmission distance; constructing a first mathematical relationship between the total cost, cost matrix, optimal transmission matrix, and optimal transmission distance during the transmission process of the two sentences to be judged; defining the state vectors of the two sentences to be judged as all-1 vectors normalized to their own sentence lengths; the all-1 vectors include a first constraint and a second constraint; removing any one of the first constraint and the second constraint from the all-1 vectors to obtain a relaxation equation; combining the relaxation equation with the first mathematical relationship to derive the relaxed optimal transmission distance, and using the relaxed optimal transmission distance to determine the similarity of the two sentences to be judged. Those skilled in the art will understand that... Figure 3 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer equipment on which the present application is applied.
[0126] An embodiment of this application also provides a computer-readable storage medium storing a computer program thereon. When the computer program is executed by a processor, it implements a text similarity discrimination method, including the following steps: obtaining the token embeddings of two sentences to be judged, and constructing a cost matrix based on the token embeddings of the two sentences to be judged; the optimal solution of the optimal problem of the cost matrix is the optimal transmission matrix, and the transmission distance corresponding to the optimal transmission matrix is the optimal transmission distance; constructing a first mathematical relationship between the total cost, the cost matrix, the optimal transmission matrix, and the optimal transmission distance during the transmission process of the two sentences to be judged; defining the state vectors of the two sentences to be judged as all-1 vectors normalized by their own sentence lengths; the all-1 vectors include a first constraint and a second constraint; removing any one of the first constraint and the second constraint from the all-1 vectors to obtain a relaxation equation; combining the relaxation equation with the first mathematical relationship to derive the relaxed optimal transmission distance, and using the relaxed optimal transmission distance to determine the similarity of the two sentences to be judged.
[0127] It is understood that the computer-readable storage medium in this embodiment can be a volatile readable storage medium or a non-volatile readable storage medium.
[0128] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, or other media provided in this application and in the embodiments may include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual-speed SDRAM (SSRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), RAMbus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0129] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, apparatus, article, or method that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, apparatus, article, or method. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, apparatus, article, or method that includes that element.
[0130] The above description is merely a preferred embodiment of the present invention and does not limit the patent scope of the present invention. Any equivalent structural or procedural transformations made based on the content of the present invention's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the patent protection scope of the present invention.
Claims
1. A method of text similarity discrimination, characterized by, The method comprises: obtaining token embedding of two sentences to be determined, and constructing a cost matrix according to the token embedding of the two sentences to be determined; the optimal solution of the optimal problem of the cost matrix is an optimal transmission matrix, and the transmission distance corresponding to the optimal transmission matrix is an optimal transmission distance; constructing a first mathematical relationship between the total cost, the cost matrix, the optimal transmission matrix and the optimal transmission distance in the transmission process of the two sentences to be determined; defining state vectors of the two sentences to be determined as all-1 vectors normalized by lengths of the two sentences respectively; the all-1 vectors comprise a first constraint condition and a second constraint condition; removing any one of the first constraint condition and the second constraint condition in the all-1 vectors to obtain a relaxed equation; combining the relaxed equation with the first mathematical relationship to derive a relaxed optimal transmission distance, and determining the similarity of the two sentences to be determined by using the relaxed optimal transmission distance; the step of relaxing the equation comprises: removing the first constraint condition in the all-1 vectors to obtain a relaxed equation = or removing the second constraint condition in the all-1 vectors to obtain a relaxed equation = where L1 is the token length of sentence 1, is the total cost, is the relaxed optimal transmission matrix.
2. The text similarity discrimination method according to claim 1, characterized in that, the dimension of the cost matrix is L1*L2; wherein L2 is the token length of the second sentence, and the cost matrix encodes token similarity by using cosine distance.
3. The text similarity discrimination method according to claim 2, characterized in that, the expression of the first mathematical relationship is: = 1 - cos(2πfT) , ) = wherein, is an embedding for the i-th word in sentence 1, represents an embedding for the j-th word in the second sentence, is the optimal transmission matrix, is the optimal transmission distance.
4. The text similarity discrimination method according to claim 1, characterized in that, the expression of the all-1 vector is: = , = wherein, and are all ones vectors; is the token length of sentence 1, is the token length of sentence 2.
5. The text similarity discrimination method according to claim 1, characterized in that, the step of combining the relaxed equation with the first mathematical relationship to derive a relaxed optimal transmission distance, and determining the similarity of the two sentences to be determined by using the relaxed optimal transmission distance comprises: converting the relaxed optimal transmission distance of the two sentences to be determined into a similarity score according to a preset conversion relationship; determining the similarity degree of the two sentences to be determined according to the similarity score of the two sentences to be determined.
6. The text similarity discrimination method according to claim 5, characterized in that, after the step of determining the similarity degree of the two sentences to be determined according to the similarity score of the two sentences to be determined, the method further comprises: constructing a text similarity determination model according to the similarity score of the two sentences to be determined; fine-tuning the text similarity determination model by using a preset rule.
7. A text similarity discrimination apparatus characterized by comprising: comprise: a first construction module configured to obtain token embedding of two sentences to be determined, and construct a cost matrix according to the token embedding of the two sentences to be determined; the optimal solution of the optimal problem of the cost matrix is an optimal transmission matrix, and the transmission distance corresponding to the optimal transmission matrix is an optimal transmission distance; a second construction module configured to construct a first mathematical relationship between the total cost, the cost matrix, the optimal transmission matrix and the optimal transmission distance in the transmission process of the two sentences to be determined; a normalization module configured to define state vectors of the two sentences to be determined as all-1 vectors normalized by lengths of the two sentences respectively; the all-1 vectors comprise a first constraint condition and a second constraint condition; a relaxing module, configured to remove any one of the first constraint condition and the second constraint condition in the all-1 vector, to obtain a relaxed equation; a judging module, configured to derive a relaxed optimal transmission distance by combining the relaxed equation with the first mathematical relationship, and to judge the similarity between the two sentences to be judged by using the relaxed optimal transmission distance; the step of the relaxed equation comprises: the first constraint condition in the all-1 vector is removed, and the relaxed equation obtained is = or the second constraint condition in the all-1 vector is removed, and the relaxed equation obtained is = where L1 is the token length of sentence 1, is the total cost, is the relaxed optimal transmission matrix.
8. A computer device comprising a memory and a processor, the memory having stored therein a computer program, characterized in that, the processor executes the computer program to implement the steps of the text similarity judgment method in any one of claims 1 to 6.
9. A computer readable storage medium having stored thereon a computer program, characterized in that, the computer program is executed by the processor to implement the steps of the text similarity judgment method in any one of claims 1 to 6.
Citation Information
Patent Citations
Method and system for judging text similarity
CN107967255A
Statement equivalence judgment method and device
CN110633359A