Method for calculating sentence similarity, related device, and computer storage medium

By obtaining the decay factor and dependency tree in the sentence and combining it with the word vector similarity to calculate the sentence similarity, the problem of inaccurate sentence similarity calculation is solved, achieving higher accuracy and simplicity.

CN116266264BActive Publication Date: 2025-09-12GUANGZHOU SHIYUAN ELECTRONICS CO LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111519892.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-13
Publication Date
2025-09-12
Estimated Expiration
2041-12-13

AI Technical Summary

Technical Problem

The sentence similarity calculation in the existing technology is inaccurate, especially for sentences with very similar word vectors, such as "I like picking apples" and "I like eating apples".

Method used

By obtaining two sentences to be compared and the decay factor, the phrases in the sentences are vectorized respectively, a dependency tree is generated, and the sentence similarity is calculated by combining the word vector similarity and the dependency tree.

Benefits of technology

It improves the accuracy of sentence similarity calculation, retains the information of sentence vectors, simplifies the number of nodes in the dependency tree, and facilitates the annotation of parts of speech, especially in the automatic annotation of corpus text.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116266264B_ABST
    Figure CN116266264B_ABST
Patent Text Reader

Abstract

The present application discloses a method for calculating sentence similarity, a related device and a computer storage medium, wherein the method includes: obtaining two sentences to be compared and a decay factor; vectorizing the phrases in the two sentences to be compared respectively to obtain the word vector of each phrase in the two sentences to be compared; determining the word vector similarity between the two sentences to be compared based on the word vector of each phrase in the two sentences to be compared; generating a dependency tree for each sentence to be compared according to a preset dependency syntactic rule; determining the sentence similarity between the two sentences to be compared based on the decay factor, the dependency tree of each sentence to be compared, and the word vector similarity between the two sentences to be compared. The dependency tree in the embodiment of the present application can directly process the relationship between words in a sentence, and the number of nodes is greatly reduced, which is convenient for directly marking parts of speech and has the advantage of being concise and clear.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer language processing, and in particular to a method for calculating sentence similarity, a related device, and a computer storage medium. Background Art

[0002] As electronic products become increasingly intelligent, the demand for text recognition accuracy is also increasing. Existing technologies typically use sentence vector models to calculate the similarity between texts. For example, models such as Onehot, Word2vector, BiLSTM, and Bert are used to input the sentences to be compared into the model, which outputs sentence similarity. However, if the sentence vectors between sentences are very similar, such as "I like picking apples," "I like eating apples," and "I don't like eating apples," the sentence similarity output from these sentence vector models is inaccurate. Summary of the Invention

[0003] The embodiments of the present application provide a method for calculating sentence similarity, a related device, and a computer storage medium to solve the problem of inaccurate sentence similarity calculation in the prior art.

[0004] In a first aspect, an embodiment of the present application provides a method for calculating sentence similarity, the method comprising:

[0005] Get two sentences to be compared and the decay factor;

[0006] Vectorizing the phrases in the two sentences to be compared respectively to obtain a word vector for each phrase in the two sentences to be compared;

[0007] Determining a word vector similarity between the two sentences to be compared based on the word vector of each phrase in the two sentences to be compared;

[0008] Generate a dependency tree for each sentence to be compared according to preset dependency syntax rules;

[0009] Based on the decay factor, the dependency tree of each sentence to be compared, and the word vector similarity between the two sentences to be compared, the sentence similarity between the two sentences to be compared is determined. In a second aspect, an embodiment of the present application provides an apparatus for calculating sentence similarity, the apparatus comprising:

[0010] An acquisition module, used to obtain two sentences to be compared and a decay factor;

[0011] A word vector obtaining module, configured to vectorize the phrases in the two sentences to be compared, respectively, to obtain a word vector for each phrase in the two sentences to be compared;

[0012] A word vector similarity determination module, configured to determine the word vector similarity between the two sentences to be compared based on the word vector of each phrase in the two sentences to be compared;

[0013] A generation module, configured to generate a dependency tree for each sentence to be compared according to a preset dependency syntax rule;

[0014] A sentence similarity determination module is used to determine the sentence similarity between the two sentences to be compared based on the decay factor, the dependency tree of each sentence to be compared, and the word vector similarity between the two sentences to be compared.

[0015] In a third aspect, an embodiment of the present application provides a computer storage medium, wherein the computer storage medium stores a plurality of instructions, wherein the instructions are suitable for being loaded by a processor and executing the above-mentioned method steps.

[0016] In a fourth aspect, an embodiment of the present application provides an electronic device, which may include: a processor and a memory;

[0017] The memory stores a computer program, and the computer program is suitable for being loaded by the processor and executing the above method steps.

[0018] The beneficial effects of the technical solutions provided by some embodiments of the present application include at least:

[0019] In an embodiment of the present application, the embodiment of the present application can obtain two sentences to be compared and a decay factor; respectively vectorize the phrases in the two sentences to be compared to obtain the word vector of each phrase in the two sentences to be compared; determine the word vector similarity between the two sentences to be compared based on the word vector of each phrase in the two sentences to be compared; generate a dependency tree for each sentence to be compared according to a preset dependency syntactic rule; determine the sentence similarity between the two sentences to be compared based on the decay factor, the dependency tree of each sentence to be compared, and the word vector similarity between the two sentences to be compared. Therefore, the embodiment of the present application further takes into account the similarity between similar words on the basis of sentence structure, and more accurately grasps the semantic relationship between the various components of the sentence by combining the two, and does not lose the information contained in the sentence vector. In addition, the dependency tree in the embodiment of the present application can directly process the relationship between words in a sentence, and the number of nodes is greatly reduced, which is convenient for direct marking of parts of speech. It has the advantages of being concise and clear, especially in the automatic annotation of corpus text. It is more convenient to use than the syntactic structure tree, and is more accurate than the prior art that only calculates the similarity between sentences based on the dependency tree. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0021] Figure 1 A schematic diagram of a dependency syntactic relationship of a sentence to be detected provided in an embodiment of the present application;

[0022] Figure 2 A flowchart of a method for calculating sentence similarity provided in an embodiment of the present application;

[0023] Figure 3a A schematic diagram of a dependency syntactic relationship of a sentence to be detected provided in an embodiment of the present application;

[0024] Figure 3b for Figure 3a Schematic diagram of the dependency tree of the sentence to be detected;

[0025] Figure 4 A flowchart of another method for calculating sentence similarity provided in an embodiment of the present application;

[0026] Figure 5a A schematic diagram of a dependency tree of a sentence to be detected provided in an embodiment of the present application;

[0027] Figure 5b A schematic diagram of a dependency tree of another sentence to be detected provided in an embodiment of the present application;

[0028] Figure 6 A schematic diagram of the structure of a device for calculating sentence similarity provided in an embodiment of the present application;

[0029] Figure 7 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0030] When the following description refers to the accompanying drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application. Instead, they are merely examples of devices and methods consistent with certain aspects of the present application, as detailed in the appended claims.

[0031] In the description of this application, it should be understood that the terms "first", "second", etc. are used for descriptive purposes only and should not be understood as indicating or implying relative importance. For those of ordinary skill in the art, the specific meanings of the above terms in this application can be understood according to specific circumstances. In addition, in the description of this application, unless otherwise specified, "multiple" refers to two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the previous and subsequent associated objects are in an "or" relationship.

[0032] In natural language, sentences can be divided into subject, predicate, and object representations. The way people speak (even drunken gibberish) has structures and rules. The goal of grammatical analysis in linguistics is to isolate these grammatical structures. The relationship between words is more than a simple sequence; it must describe how the words are connected. A comprehensible approach is to construct a tree structure for each sentence.

[0033] Syntactic parsing is a key technology in Natural Language Processing (NLP) that can help analyze the constituent structure of a sentence and the relationships between words. Syntactic analysis trees are mainly divided into two categories: the constituent tree and the dependency tree. Specifically, the constituent tree is used to express the syntactic structure of a sentence. Only its leaf nodes are associated with words in the input sentence, and the other intermediate nodes are all labeled phrase components. The dependency tree is used to express the dependency relationship between words in a sentence and is used to analyze and identify grammatical components such as "subject, predicate, object", "attributive, adverbial, complement" in a sentence. Each node is a word. The dependency tree is used to express the tree structure of the constituent words in a sentence and the dependency relationship between words. Compared with the grammar of the constituent tree, the dependency grammar does not have the phrase level. Each node corresponds to a word in the sentence.

[0034] It's understandable that dependency syntax considers the verb in the "predicate" to be the center of a sentence, with other components directly or indirectly connected to the verb. In dependency syntax theory, "dependency" refers to the dominant-subordinate relationship between words. This relationship is not reciprocal but rather directional. Specifically, the dominant component is called the dominant, while the subordinate component is called the subordinate. Dependency grammar itself does not require a categorization of dependency relationships. However, to enrich the syntactic information conveyed by dependency structures, in practical applications, different labels are generally assigned to the edges of dependency trees. In the syntax related to dependency trees, the common fundamental assumption is that syntactic structure essentially consists of relationships between words and word pairs. This relationship is called a dependency relationship. A dependency relationship connects two words: one is a core word, and the other is a modifier.

[0035] See also Figure 1 The following diagram shows the dependency syntax for the sentence "Xiao Wang buys a computer." The diagram shows a dependency relationship HED (core relationship) between Root (core word) and buy, indicating that "buy" is the core word in this sentence. Furthermore, a dependency relationship SBV (subject-verb relationship) exists between Xiao Wang (dependent word) and buy (core word), and a dependency relationship VOB (verb-object relationship) exists between buy (core word) and computer (dependent word).

[0036] Next, combine Figure 1 The method for calculating sentence similarity provided in an embodiment of the present application is introduced using a schematic diagram of a dependency tree in the related art.

[0037] S201, obtaining two sentences to be compared and a decay factor.

[0038] The decay factor is used to represent a preset coefficient, which is between 0 and 1. Specifically, the decay factor can be set according to user needs, for example, it can be determined according to the length of the sentence or the depth of the dependency tree.

[0039] S202 , respectively vectorizing the phrases in the two sentences to be compared to obtain a word vector for each phrase in the two sentences to be compared.

[0040] Among them, word vectors are used to represent vectors in which words or phrases from the vocabulary are mapped to real numbers.

[0041] Possibly, the embodiments of the present application can obtain word vectors through a long short-term memory model (Long Short-Term Memory, LSTM), a bidirectional long short-term memory model (Bi-directional Long Short-Term Memory, BiLSTM), etc.

[0042] Specifically, the phrases in the sentence are replaced with word vectors according to the second dimension (the index of each word) before entering the LSTM, so the input of the LSTM can be a 3-dimensional vector (number of samples x sentence length x word vector dimension).

[0043] Specifically, the BiLSTM model can be composed of four parts: input layer: used to receive input sentences, which for Chinese refers to the words that have been divided into sentences; embedding layer: maps each word in the sentence into a vector of fixed length; long short-term memory layer: uses a bidirectional long short-term memory network (Long Short-Term Memory, LSTM) to calculate the vectors in the embedding layer. In fact, the bidirectional LSTM calculates the word vectors to obtain higher-level sentence vectors; output layer: used to output the word vector results corresponding to the words.

[0044] S203 : Determine the word vector similarity between the two sentences to be compared based on the word vector of each phrase in the two sentences to be compared.

[0045] It can be understood that this application can construct a Euclidean space by converting text into word vectors. Comparing the word vector similarity between two sentences is converted into measuring the distance between word vectors. There are many indicators to choose from, such as Euclidean distance, Pearson coefficient, and cosine distance.

[0046] Specifically, the vectors of the two words are A and B, and the word vector similarity between them is This is the cosine of the angle between two vectors, and its value range is [-1, 1]. When a pair of texts differ significantly in length but have similar content, their Euclidean distance in feature space is typically large if word frequency or word vectors are used as features. However, if cosine similarity is used, the angle between them may be small, resulting in high similarity. It is understandable that cosine distance often has high feature dimensionality in objects such as text. Cosine similarity maintains the property of "1 for identical, 0 for orthogonal, and -1 for opposite" in high dimensions. However, the Euclidean distance is affected by dimensionality, has an unfixed range, and is more ambiguous in meaning.

[0047] S204: Generate a dependency tree for each sentence to be compared according to preset dependency syntax rules.

[0048] Among them, the dependency syntax rules preset in the embodiment of the present application are used to represent the rules for generating the dependency tree of the sentences to be compared.

[0049] Possibly, embodiments of the present application can use a deep learning-based method to establish a dependency tree for the sentences to be compared. Specifically, deep learning is to vectorize atomic features (words, parts of speech, category labels) and then use a multi-layer neural network to extract features. Among them, the deep learning method is based on large-scale manually annotated data and is based on massive data training to make text matching more accurate.

[0050] Specifically, embodiments of the present application can mine sentences based on graph-relationship triples, i.e., through dependency grammar analysis, a large number of triple relationships, such as subject, predicate, and object, can be constructed. For example, a graph-based dependency parser aims to find a maximum spanning tree to obtain a globally optimal solution for the overall dependency structure of a sentence.

[0051] In addition, the embodiment of the present application can also perform operations such as word segmentation on Chinese sentences, filtering stop words, and removing meaningless words based on the word segmentation model in the Language Technology Platform (LTP). Based on the word segmentation results, the part-of-speech tagging model in the LTP is used to tag the words after word segmentation. Based on the results of the part-of-speech tagging, the dependency syntax analysis model in the LTP is used to perform dependency syntax analysis on the sentences after the part-of-speech tagging to obtain a semantic dependency tree.

[0052] In embodiments of the present application, each node in the semantic dependency tree may include: the content of the sentence to be compared corresponding to the node, the node type, and the node attributes. Specifically, the node types may include: a core word, a first dependent word, and a second dependent word; wherein the first dependent word is used to represent the dependent word of the core word, and the second dependent word is used to represent the dependent word of the dependent word; and the node attributes may include: a noun subject, a supplementary word, and a direct object.

[0053] See also Figure 3a The dependency syntax of the sentence "I like picking apples" is as follows: Figure 3a It can be observed that there is a dependency relationship HED (core relationship) between ROOT (core word) and like, a dependency relationship SBV (subject-verb relationship) between I (dependent word) and like (core word), a dependency relationship CMP (verb-complement relationship) between like (core word) and pick (first dependent word), and a relationship VOB (verb-object relationship) between pick (first dependent word) and apple (second dependent word).

[0054] See also Figure 3b The dependency tree of the sentence "I like picking apples" starts from Figure 3bWe can observe the dependency tree with "like" as the core word (root). Among them, the content of the sentence corresponding to the ROOT node is the whole sentence: I like picking apples, the node type is the root node, and the node attribute is the clause. The first node below the ROOT node corresponds to the node content "I", the node type is the first dependent word node, and the node attribute is the noun subject nsubj. The second node below the ROOT node corresponds to the node content "like", the node type is the core word node, and the node attribute is the verb. The third node below the ROOT node corresponds to the node content "pick", the node type is the first dependent word node, and the node attribute is the main component of the complement clause ccomp. The fourth node below the ROOT node corresponds to the node content "apple", the node type is the second dependent word node, and the node attribute is the direct object dobj.

[0055] S205 , determining the sentence similarity between the two sentences to be compared based on the decay factor, the dependency tree of each sentence to be compared, and the word vector similarity between the two sentences to be compared.

[0056] It is understandable that the embodiment of the present application can use the decay factor to process each node in the dependency tree of each sentence to be compared, so as to reduce the redundancy caused by repeated calculation of nodes due to the dependency tree being too deep.

[0057] Specifically, the embodiment of the present application can determine the sentence similarity between the two sentences to be compared by combining the similarity between the dependency tree nodes of the two sentences to be compared with the similarity of the word vectors between the two sentences to be compared.

[0058] Alternatively, the embodiment of the present application may calculate the similarity E between two sentences to be compared using the following formula:

[0059]

[0060] Among them, K(T1, T2) represents the comparison value between the two sentences to be compared, which may include the similarity between the dependency tree nodes of the two sentences to be compared and the similarity of the word vectors between the two sentences to be compared; K(T1, T1) represents the comparison value of the first sentence to be compared itself, which may include the similarity between the dependency tree nodes of the first sentence to be compared itself and the similarity of the word vectors of the dependency tree nodes of the first sentence to be compared itself; K(T2, T2) represents the comparison value of the second sentence to be compared itself, which may include the similarity between the dependency tree nodes of the second sentence to be compared itself and the similarity of the word vectors of the dependency tree nodes of the second sentence to be compared itself.

[0061] Thus, the embodiment of the present application can obtain two sentences to be compared and a decay factor; respectively vectorize the phrases in the two sentences to be compared to obtain the word vector of each phrase in the two sentences to be compared; determine the word vector similarity between the two sentences to be compared based on the word vector of each phrase in the two sentences to be compared; generate a dependency tree for each sentence to be compared according to a preset dependency syntactic rule; determine the sentence similarity between the two sentences to be compared based on the decay factor, the dependency tree of each sentence to be compared, and the word vector similarity between the two sentences to be compared. Thus, the embodiment of the present application further takes into account the similarity between similar words on the basis of sentence structure, and more accurately grasps the semantic relationship between the various components of the sentence by combining the two, without losing the information contained in the sentence vector. In addition, the dependency tree in the embodiment of the present application can directly process the relationship between words in a sentence, and the number of nodes is greatly reduced, which is convenient for direct marking of parts of speech. It has the advantages of being concise and clear, especially in the automatic annotation of corpus text. It is more convenient to use than the syntactic structure tree, and is more accurate than the prior art that only calculates the similarity between sentences based on the dependency tree.

[0062] In some embodiments, Figure 4 The following is a flow chart showing a method for calculating sentence similarity provided by an embodiment of the present application. Figure 4 As shown, the method for calculating sentence similarity may include at least the following steps:

[0063] S401: Obtain two sentences to be compared and a decay factor.

[0064] Specifically, S401 is consistent with S201 and will not be repeated here.

[0065] S402 , respectively vectorizing the phrases in the two sentences to be compared to obtain a word vector for each phrase in the two sentences to be compared.

[0066] Specifically, S402 is consistent with S202 and will not be repeated here.

[0067] S403 : Determine the word vector similarity between the two sentences to be compared based on the word vector of each phrase in the two sentences to be compared.

[0068] Specifically, S403 is consistent with S203 and will not be repeated here.

[0069] S404: Generate a dependency tree for each sentence to be compared according to preset dependency syntax rules.

[0070] Specifically, S404 is consistent with S204 and will not be repeated here.

[0071] S405, traverse the dependency trees of the two sentences to be compared. If the dependency trees of the two sentences to be compared are generated in the same way, execute S406; if the dependency trees of the two sentences to be compared are generated in different ways, execute S407-S410.

[0072] It can be understood that traversal means starting from the root node and following a search route, visiting each node in the tree in turn to determine the node content, node type, and node attributes of each node.

[0073] Specifically, the embodiment of the present application can traverse the dependency tree of two sentences to be compared from top to bottom.

[0074] S406 , when the dependency trees of the two sentences to be compared are generated in the same manner, determining the sentence similarity between the two sentences to be compared based on the decay factor, the dependency tree of each sentence to be compared, and the word vector similarity between the two sentences to be compared.

[0075] It can be understood that the same generation method in the embodiment of the present application means that the node types and node attributes of each level in the dependency tree are the same.

[0076] See also Figure 3b The dependency tree for "I like picking apples" is shown below and Figure 5a The dependency tree of "I like to eat apples" shown in Figure 3b and Figure 5a The content of the nodes is different, but what is certain is that Figure 3b and Figure 5a The dependency tree in is generated in the same way, that is, the node attributes and node types are consistent.

[0077] Furthermore, embodiments of the present application can determine the comparison value of each sentence to be compared based on the decay factor, the dependency tree of each sentence to be compared, and the word vector similarity of each sentence to be compared. The comparison value between the two sentences to be compared is determined based on the number of nodes at each level in the dependency tree of the two sentences to be compared, the content similarity of nodes of the same node type and node attribute, and the word vector similarity between the two sentences to be compared. The sentence similarity between the two sentences to be compared is determined based on the comparison value of each sentence to be compared and the comparison value between the two sentences to be compared.

[0078] Specifically, the embodiment of the present application can determine the comparison value of each sentence to be compared based on the decay factor, the number of node types at each level in the dependency tree of each sentence to be compared, and the word vector similarity of each sentence to be compared.

[0079] Possibly, the embodiment of the present application may use the following formula to calculate the comparison value of each sentence to be compared:

[0080]

[0081] Among them, T1 represents the dependency tree of the first sentence to be compared, N1 represents the node set of the dependency tree of the first sentence to be compared, n1 represents the node in the dependency tree of the first sentence to be compared, #ch(n1) represents the number of first dependency word nodes with second dependency word nodes, ch(n1,k) is the kth first dependency word node with a second dependency word node, VSP is the similarity between the word vector obtained by the BiLSTM model of ch(n1,k) and the word vector obtained by the BiLSTM model of ch(n1,k), and λ(0<λ<1) is the decay factor.

[0082] Possibly, an embodiment of the present application can determine the content similarity of nodes in each level based on the word vectors and decay factors corresponding to the content of the nodes in each level; determine the comparison value between the two sentences to be compared based on the number of nodes in each level in the dependency tree of the two sentences to be compared, the content similarity of nodes with the same node type and node attributes, and the word vector similarity between the two sentences to be compared.

[0083] Possibly, the embodiment of the present application may use the following formula to calculate the comparison value between two sentences to be compared:

[0084]

[0085] Wherein, T1 represents the dependency tree of the first sentence to be compared, T2 represents the dependency tree of the second sentence to be compared, N1 represents the node set of the dependency tree of the first sentence to be compared, N2 represents the node set of the dependency tree of the second sentence to be compared, n1 represents the node in the dependency tree of the first sentence to be compared, n2 represents the node in the dependency tree of the second sentence to be compared, #ch(n) represents the number of first dependency word nodes and second dependency word nodes with the same connection relationship in the two trees, ch(n1,k) is the kth first dependency word node with the second dependency word node in the dependency tree of the first sentence to be compared, ch(n2,k) is the kth first dependency word node with the second dependency word node in the dependency tree of the second sentence to be compared, VSP is the similarity between the word vector obtained by the BiLSTM model of ch(n1,k) and the word vector obtained by the BiLSTM model of ch(n2,k), and λ(0<λ<1) is the decay factor.

[0086] Specifically, the content similarity of the nodes at each level of the dependency tree of the two sentences to be compared in the embodiment of the present application can be obtained by calculating λVS, where VS is the similarity of the BiLSTM word vectors of the nodes.

[0087] For a specific example, see Figure 3b and Figure 5a Assuming the decay factor λ = 0.5, the first sentence to be compared is "I like picking apples" and the second sentence to be compared is "I like eating apples". First, according to the above formula, the comparison value of each sentence to be compared can be calculated separately. Starting from the root node of the dependency tree, traversing the entire dependency tree, we get: 1 root node (ROOT), 1 core word node (root), 2 first dependency nodes (nsubj and ccomp), 1 second dependency word node (dobj), and a total of 5 nodes; traversing the nodes in the second level (ccomp), we get: 1 first dependency node (ccomp), 1 second dependency word node (dobj), and a total of 2 nodes. Further, assuming that the first sentence to be compared is "I like picking apples" and its word vector is 10011, and the second sentence to be compared is "I like eating apples" and its word vector is 11011, then the similarity of the nodes at each level in the dependency tree of the first sentence to be compared can be obtained according to λVS: 0.5*(1+1+1)=1.5, and the word vector similarity VSP of the first sentence to be compared is VSP=1+1+1=3; the similarity of the leaf nodes at each level in the second dependency tree can be obtained according to λVS: 0.5*(1+1+1+1)=2, and the word vector similarity VSP of the second sentence to be compared is VSP=1+1+1+1=4; the similarity of the leaf nodes at each level in the two dependency trees can be obtained according to λVS: 0.5*(1+1+1)=1.5. Thus, the comparison value K(T1, T1) of the first sentence to be compared is 0.5*(5+2+1.5+3)=5.75; the comparison value K(T2, T2) of the second sentence to be compared is 0.5*(5+2+2+4)=6.5; the comparison value K(T1, T2) between the two sentences to be compared is [0.5*(5+2+1.5+3)] 2 =5.75 2 =33.06; further, the similarity between the two sentences to be compared can be determined

[0088] Therefore, the present application can compare the node similarity between the components in the two sentences based on the dependency tree, and further determine the similarity between the two sentences to be compared based on the similarity between similar words. In this way, the information contained in the sentence vector is not lost and the relationship between the dependency structures is compared, making the similarity between the sentences more accurate.

[0089] S407: When the dependency trees of the two sentences to be compared are generated in different ways, determine a first dependent word and a second dependent word in the dependency trees of the two sentences to be compared that have the same node type and node attributes and have the same node attributes and are mutually dependent.

[0090] It can be understood that the different generation methods in the embodiments of the present application refer to the differences in node types and / or node attributes at each level in the dependency tree.

[0091] See also Figure 5a The dependency tree of the sentence to be compared "I like to eat apples" is shown below and Figure 5b The dependency tree of the sentence to be compared is shown in . Figure 5a and Figure 5b It is observed that the third node type and node attributes from top to bottom are different, so the dependency trees of the two compared sentences are generated differently.

[0092] S408 , determining the comparison value of each sentence to be compared based on the decay factor, the number of node types at each level in the dependency tree of each sentence to be compared, and the similarity of the word vectors of each sentence to be compared.

[0093] Possibly, the embodiment of the present application may use the following formula to calculate the comparison value of each sentence to be compared:

[0094]

[0095] Among them, T1 represents the dependency tree of the first sentence to be compared, N1 represents the node set of the dependency tree of the first sentence to be compared, n1 represents the node in the dependency tree of the first sentence to be compared, #ch(n1) represents the number of first dependency word nodes with second dependency word nodes, ch(n1,k) is the kth first dependency word node with a second dependency word node, VSP is the similarity between the word vector obtained by the BiLSTM model of ch(n1,k) and the word vector obtained by the BiLSTM model of ch(n1,k), and λ(0<λ<1) is the decay factor.

[0096] S409: Determine a comparison value between the two sentences to be compared based on the number of first dependent words and second dependent words that have the same node attributes and are mutually dependent, the content similarity of each node, and the word vector similarity between the two sentences to be compared.

[0097] Specifically, the embodiments of the present application can determine the content similarity of each node based on the word vector and decay factor of each sentence to be compared; determine the comparison value between two sentences to be compared based on the number of first dependent words and second dependent words that have the same node attributes and have mutual dependence, the content similarity of each node, and the word vector similarity between the two sentences to be compared.

[0098] Possibly, the embodiment of the present application may use the following formula to calculate the comparison value between two sentences to be compared:

[0099]

[0100] Wherein, T1 represents the dependency tree of the first sentence to be compared, T2 represents the dependency tree of the second sentence to be compared, N1 represents the node set of the dependency tree of the first sentence to be compared, N2 represents the node set of the dependency tree of the second sentence to be compared, n1 represents the node in the dependency tree of the first sentence to be compared, n2 represents the node in the dependency tree of the second sentence to be compared, #ch(n) represents the number of first dependency word nodes and second dependency word nodes with the same connection relationship in the two trees, ch(n1,k) is the kth first dependency word node with the second dependency word node in the dependency tree of the first sentence to be compared, ch(n2,k) is the kth first dependency word node with the second dependency word node in the dependency tree of the second sentence to be compared, VSP is the similarity between the word vector obtained by the BiLSTM model of ch(n1,k) and the word vector obtained by the BiLSTM model of ch(n2,k), and λ(0<λ<1) is the decay factor.

[0101] Possibly, the content similarity of each node in the dependency tree of two sentences to be compared in the embodiment of the present application can be obtained by calculating λVS, where VS is the similarity of the BiLSTM word vectors of the nodes.

[0102] S410 , determining the sentence similarity between the two sentences to be compared based on the comparison value of each sentence to be compared and the comparison value between the two sentences to be compared.

[0103] For a specific example, see Figure 5a and Figure 5bAssuming the decay factor λ = 0.5, the first sentence to be compared is "I like to eat apples", and the second sentence to be compared is "I don't like to eat apples". First, according to the above formula, the comparison value of each sentence to be compared can be calculated separately. Starting from the dependency tree of the first sentence to be compared, traversing the entire dependency tree, we get: 1 root node (ROOT), 1 core word node (root), 2 first dependency nodes (subj, ccomp), 1 second dependency node (dobj), and a total of 5 nodes; traversing the nodes of the second level: 2 first dependency nodes (ccomp), 1 second dependency node (dobj), and a total of 2 nodes. Starting from the dependency tree of the second sentence to be compared, traversing the entire dependency tree, we get: 1 root node (ROOT), 1 core word node (root), 3 first dependency nodes (subj, neg, ccomp), 1 second dependency node (dobj), and a total of 6 nodes; traversing the nodes of the second level: 1 first dependency node (ccomp), 1 second dependency node (dobj), and a total of 2 nodes. Furthermore, assuming that the first sentence to be compared is "I like eating apples" with a word vector of 11011, and the second sentence to be compared is "I don't like eating apples" with a word vector of 11111, then the similarity of each node in the dependency tree of the first sentence to be compared can be obtained according to λVS: 0.5*(1+1+1+1)=2, and the word vector similarity of the first sentence to be compared is VSP=1+1+1+1=4; the similarity of each node in the second dependency tree can be obtained according to λVS: 0.5*(1+1+1+1+1)=2.5, and the word vector similarity of the second sentence to be compared is VSP=1+1+1+1+1=5. Furthermore, the similarity of each node in the two dependency trees can be obtained according to λVS: 0.5*(1+1+1+1)=2, and the word vector similarity of the two sentences to be compared is VSP=1+1+1+1=4. Furthermore, the two nodes with the same dependency relationship between the two sentences to be compared are "eat" and "apple". Therefore, the comparison value K(T1, T1) of the first sentence to be compared is 0.5*(5+2+4)=5.5; the comparison value K(T2, T2) of the second sentence to be compared is 0.5*(6+2+2.5+5)=7.75; the comparison value K(T1, T2) between the two sentences to be compared is [0.5*(2+4+2)] 2 =4 2 =8; further, the similarity between the two sentences to be compared can be determined

[0104] Thus, the embodiment of the present application can determine the similarity between the two sentences to be compared by determining the first dependency word and the second dependency word node that have the same node attributes and node types in the two sentences to be compared and have a mutual dependency relationship. In this way, not only the similarity of the same nodes is compared, but also the word vectors of the two sentences to be compared are compared. Compared with the embodiment with the same dependency tree generation method, it can be observed that when the dependency tree is generated in a different way and a negative word appears, the similarity between the two sentences to be compared is significantly reduced. Therefore, it can be determined that the embodiment of the present application can significantly improve the accuracy of the similarity between the compared sentences.

[0105] Figure 6 This is a schematic diagram of a device for calculating sentence similarity provided by an exemplary embodiment of the present application. The device for calculating sentence similarity can be set in a device such as a server to execute the method for calculating sentence similarity of any of the above embodiments of the present application. Figure 6 As shown, the device for calculating sentence similarity may include:

[0106] An acquisition module 61 is used to acquire two sentences to be compared and a decay factor;

[0107] A word vector obtaining module 62 is used to vectorize the phrases in the two sentences to be compared respectively to obtain a word vector for each phrase in the two sentences to be compared;

[0108] A word vector similarity determination module 63 is configured to determine the word vector similarity between the two sentences to be compared based on the word vector of each phrase in the two sentences to be compared;

[0109] A generating module 64, configured to generate a dependency tree for each sentence to be compared according to a preset dependency syntax rule;

[0110] The sentence similarity determination module 65 is configured to determine the sentence similarity between the two sentences to be compared based on the decay factor, the dependency tree of each sentence to be compared, and the word vector similarity between the two sentences to be compared.

[0111] Thus, the embodiment of the present application can obtain two sentences to be compared and a decay factor; respectively vectorize the phrases in the two sentences to be compared to obtain the word vector of each phrase in the two sentences to be compared; determine the word vector similarity between the two sentences to be compared based on the word vector of each phrase in the two sentences to be compared; generate a dependency tree for each sentence to be compared according to a preset dependency syntactic rule; determine the sentence similarity between the two sentences to be compared based on the decay factor, the dependency tree of each sentence to be compared, and the word vector similarity between the two sentences to be compared. Thus, the embodiment of the present application further takes into account the similarity between similar words on the basis of sentence structure, and more accurately grasps the semantic relationship between the various components of the sentence by combining the two, without losing the information contained in the sentence vector. In addition, the dependency tree in the embodiment of the present application can directly process the relationship between words in a sentence, and the number of nodes is greatly reduced, which is convenient for direct marking of parts of speech. It has the advantages of being concise and clear, especially in the automatic annotation of corpus text. It is more convenient to use than the syntactic structure tree, and is more accurate than the prior art that only calculates the similarity between sentences based on the dependency tree.

[0112] In some embodiments, each node in the dependency tree includes: the content of the sentence to be compared corresponding to the node, the node type, and the node attributes; wherein,

[0113] The node type includes: a core word, a first dependent word, and a second dependent word; wherein the first dependent word is used to represent a dependent word of the core word, and the second dependent word is used to represent a dependent word of the dependent word;

[0114] The node attributes include: a noun subject, a supplementary word, and a direct object.

[0115] In some implementations, the sentence similarity determination module includes:

[0116] A first traversal unit, configured to traverse the dependency tree of the two sentences to be compared;

[0117] The first determination unit is used to determine the sentence similarity between the two sentences to be compared based on the decay factor, the dependency tree of each sentence to be compared, and the word vector similarity between the two sentences to be compared, when the dependency trees of the two sentences to be compared are generated in the same way.

[0118] In some embodiments, the first determining unit includes:

[0119] A first determining subunit, configured to determine a comparison value of each sentence to be compared based on the decay factor, the dependency tree of each sentence to be compared, and the word vector similarity of each sentence to be compared;

[0120] a second determining subunit, configured to determine a comparison value between the two sentences to be compared based on the number of nodes at each level in the dependency tree of the two sentences to be compared, the content similarity of nodes of the same node type and node attribute, and the word vector similarity between the two sentences to be compared;

[0121] The third determining subunit is configured to determine the sentence similarity between the two sentences to be compared based on the comparison value of each sentence to be compared and the comparison value between the two sentences to be compared.

[0122] In some embodiments, the second determination subunit is specifically used to: determine the content similarity of nodes with the same node type and node attributes in the dependency trees of the two sentences to be compared based on the word vectors corresponding to the contents of the nodes with the same node type and node attributes in the dependency trees of the two sentences to be compared and the decay factor; determine the comparison value between the two sentences to be compared based on the number of nodes at each level in the dependency trees of the two sentences to be compared, the content similarity of nodes with the same node type and node attributes, and the word vector similarity between the two sentences to be compared.

[0123] In some implementations, the sentence similarity determination module includes:

[0124] A second traversal unit, configured to traverse the dependency tree of the two sentences to be compared;

[0125] a fifth determining subunit, configured to determine, when the dependency trees of the two to-be-compared sentences are generated in different ways, a first dependent word and a second dependent word having the same node attributes and having a mutual dependency relationship in the dependency trees of the two to-be-compared sentences;

[0126] a sixth determining subunit, configured to determine a comparison value of each sentence to be compared based on the decay factor, the dependency tree of each sentence to be compared, and the word vector similarity of each sentence to be compared;

[0127] a seventh determining subunit, configured to determine a comparison value between the two sentences to be compared based on the number of the first dependent words and the second dependent words that have the same node attributes and are in a mutual dependence relationship, the content similarity of each node, and the word vector similarity between the two sentences to be compared;

[0128] An eighth determining subunit is configured to determine the sentence similarity between the two sentences to be compared based on the comparison value of each sentence to be compared and the comparison value between the two sentences to be compared.

[0129] In some implementations, the sixth determining subunit is specifically configured to:

[0130] Based on the word vector of each sentence to be compared and the decay factor, the content similarity of each node is determined; based on the number of first dependent words and second dependent words that have the same node attributes and are mutually dependent, the content similarity of each node, and the word vector similarity between the two sentences to be compared, the comparison value between the two sentences to be compared is determined.

[0131] In some embodiments, the first determination subunit or the fifth determination subunit is specifically used to determine the comparison value of each sentence to be compared based on the decay factor, the number of node types in the dependency tree of each sentence to be compared, and the word vector similarity of each sentence to be compared.

[0132] It should be noted that the apparatus for calculating sentence similarity provided in the above embodiment only uses the division of the above functional modules as an example when executing the method for calculating sentence similarity. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. In addition, the apparatus for calculating sentence similarity provided in the above embodiment and the embodiment of the method for calculating sentence similarity belong to the same concept. The implementation process thereof is detailed in the method embodiment and will not be repeated here.

[0133] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.

[0134] See Figure 7 , is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Figure 7 As shown, the electronic device 70 may include: at least one processor 71 , at least one network interface 74 , a user interface 73 , a memory 75 , and at least one communication bus 72 .

[0135] The communication bus 72 is used to realize the connection and communication between these components.

[0136] The user interface 73 may include a display screen (Display) and a camera (Camera). Optionally, the user interface 73 may also include a standard wired interface and a wireless interface.

[0137] The network interface 74 may optionally include a standard wired interface or a wireless interface (such as a WI-FI interface).

[0138] The processor 71 may include one or more processing cores. The processor 71 utilizes various interfaces and circuits to connect various components within the electronic device 70. It executes instructions, programs, code sets, or instruction sets stored in the memory 75, and accesses data stored in the memory 75 to perform various functions and process data within the electronic device 70. Optionally, the processor 71 may be implemented using at least one of the following hardware forms: a digital signal processing (DSP), a field-programmable gate array (FPGA), or a programmable logic array (PLA). The processor 71 may integrate one or a combination of a central processing unit (CPU), a graphics processing unit (GPU), and a modem. The CPU primarily processes the operating system, user interface, and application programs; the GPU is responsible for rendering and drawing the content displayed on the display; and the modem handles wireless communications. It is understood that the modem may not be integrated into the processor 71 but implemented as a separate chip.

[0139] Among them, the memory 75 may include a random access memory (RAM) or a read-only memory (Read-Only Memory). Optionally, the memory 75 includes a non-transitory computer-readable storage medium. The memory 75 can be used to store instructions, programs, codes, code sets or instruction sets. The memory 75 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for at least one function (such as a touch function, a sound playback function, an image playback function, etc.), instructions for implementing the above-mentioned various method embodiments, etc.; the data storage area may store data involved in the above-mentioned various method embodiments, etc. The memory 75 may also be optionally at least one storage device located away from the aforementioned processor 71. As Figure 7 As shown, the memory 85 as a computer storage medium may include an operating system, a network communication module, a user interface module, and an application program for calculating sentence similarity.

[0140] exist Figure 7In the electronic device 70 shown, the user interface 73 is mainly used to provide an input interface for the user and obtain data input by the user; and the processor 71 can be used to call the sentence similarity calculation application stored in the memory 75 and specifically perform the following operations:

[0141] Get two sentences to be compared and the decay factor;

[0142] Vectorizing the phrases in the two sentences to be compared respectively to obtain a word vector for each phrase in the two sentences to be compared;

[0143] Determining a word vector similarity between the two sentences to be compared based on the word vector of each phrase in the two sentences to be compared;

[0144] Generate a dependency tree for each sentence to be compared according to preset dependency syntax rules;

[0145] Determine the sentence similarity between the two sentences to be compared based on the decay factor, the dependency tree of each sentence to be compared, and the word vector similarity between the two sentences to be compared.

[0146] In some embodiments, each node in the dependency tree includes: the content of the sentence to be compared corresponding to the node, the node type, and the node attributes; wherein,

[0147] The node type includes: a core word, a first dependent word, and a second dependent word; wherein the first dependent word is used to represent a dependent word of the core word, and the second dependent word is used to represent a dependent word of the dependent word;

[0148] The node attributes include: a noun subject, a supplementary word, and a direct object.

[0149] In some implementations, when the processor 71 determines the sentence similarity between the two sentences to be compared based on the decay factor, the dependency tree of each sentence to be compared, and the word vector similarity between the two sentences to be compared, specifically performs:

[0150] Traversing the dependency tree of the two sentences to be compared;

[0151] When the dependency trees of the two sentences to be compared are generated in the same manner, the sentence similarity between the two sentences to be compared is determined based on the decay factor, the dependency tree of each sentence to be compared, and the word vector similarity between the two sentences to be compared.

[0152] In some implementations, when the processor 71 determines the sentence similarity between the two sentences to be compared based on the decay factor, the dependency tree of each sentence to be compared, and the word vector similarity between the two sentences to be compared when the dependency trees of the two sentences to be compared are generated in the same manner, the processor 71 specifically performs:

[0153] Determining a comparison value of each sentence to be compared based on the decay factor, the dependency tree of each sentence to be compared, and the word vector similarity of each sentence to be compared;

[0154] Determine a comparison value between the two sentences to be compared based on the number of nodes at each level in the dependency tree of the two sentences to be compared, the content similarity of nodes of the same node type and node attribute, and the word vector similarity between the two sentences to be compared;

[0155] The sentence similarity between the two sentences to be compared is determined based on the comparison value of each sentence to be compared and the comparison value between the two sentences to be compared.

[0156] In some embodiments, when determining the comparison value between the two sentences to be compared based on the number of nodes at each level in the dependency tree of the two sentences to be compared, the content similarity of nodes of the same node type and node attributes, and the word vector similarity between the two sentences to be compared, the processor 71 specifically performs:

[0157] Determining the content similarity of the nodes of the same node type and node attributes in the dependency trees of the two sentences to be compared based on the word vectors corresponding to the contents of the nodes of the same node type and node attributes in the dependency trees of the two sentences to be compared and the decay factor;

[0158] The comparison value between the two sentences to be compared is determined based on the number of nodes at each level in the dependency tree of the two sentences to be compared, the content similarity of nodes with the same node type and node attributes, and the word vector similarity between the two sentences to be compared.

[0159] In some implementations, when the processor 71 determines the sentence similarity between the two sentences to be compared based on the dependency tree of each sentence to be compared and the word vector similarity between the two sentences to be compared, the processor 71 specifically performs:

[0160] Traversing the dependency tree of the two sentences to be compared;

[0161] When the dependency trees of the two to-be-compared sentences are generated in different ways, determining a first dependent word and a second dependent word in the dependency trees of the two to-be-compared sentences that have the same node attributes and are mutually dependent;

[0162] Determining a comparison value of each sentence to be compared based on the decay factor, the dependency tree of each sentence to be compared, and the word vector similarity of each sentence to be compared;

[0163] Determining a comparison value between the two sentences to be compared based on the number of the first dependent words and the second dependent words that have the same node attributes and are in a mutual dependence relationship, the content similarity of each node, and the word vector similarity between the two sentences to be compared;

[0164] The sentence similarity between the two sentences to be compared is determined based on the comparison value of each sentence to be compared and the comparison value between the two sentences to be compared.

[0165] In some embodiments, when determining the comparison value between the two sentences to be compared based on the number of the first dependent words and the second dependent words that have the same node attributes and are interdependent, the content similarity of each node, and the word vector similarity between the two sentences to be compared, the processor 71 specifically performs:

[0166] Determining the content similarity of each node based on the word vector of each sentence to be compared and the decay factor;

[0167] Based on the number of the first dependent words and the second dependent words that have the same node attributes and are mutually dependent, the content similarity of each node, and the word vector similarity between the two sentences to be compared, the comparison value between the two sentences to be compared is determined.

[0168] In some implementations, when the processor 71 determines the comparison value of each sentence to be compared based on the decay factor, the dependency tree of each sentence to be compared, and the word vector similarity of each sentence to be compared, the processor 71 specifically performs:

[0169] The comparison value of each sentence to be compared is determined based on the decay factor, the number of node types in the dependency tree of each sentence to be compared, and the word vector similarity of each sentence to be compared.

[0170] The embodiment of the present application also provides a computer-readable storage medium, which stores instructions, which, when executed on a computer or processor, enable the computer or processor to execute the above-mentioned Figure 2 One or more steps in the embodiment shown. If the components of the apparatus for calculating sentence similarity are implemented in the form of software functional units and sold or used as independent products, they can be stored in the computer-readable storage medium.

[0171] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When software is used for implementation, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in a computer-readable storage medium or transmitted by the computer-readable storage medium. The computer instructions can be transmitted from a website, computer, server or data center to another website, computer, server or data center by wired (such as coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (such as infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrations. The available medium may be a magnetic medium (eg, a floppy disk, a hard disk, a magnetic tape), an optical medium (eg, a digital versatile disc (DVD)), or a semiconductor medium (eg, a solid state disk (SSD)).

[0172] Those skilled in the art will appreciate that all or part of the processes in the above-described embodiments can be implemented by instructing the relevant hardware through a computer program. The program can be stored in a computer-readable storage medium. When executed, the program can include the processes of the above-described embodiments. The aforementioned storage medium includes various media capable of storing program code, such as read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks. Unless there is a conflict, the technical features of this embodiment and the implementation scheme can be combined in any manner.

[0173] The embodiments described above are merely preferred embodiments of the present application and are not intended to limit the scope of the present application. Without departing from the design spirit of the present application, various modifications and improvements made to the technical solutions of the present application by ordinary technicians in this field should fall within the scope of protection determined by the claims of the present application.

Claims

1. A method for calculating sentence similarity, characterized in that: The method comprises: Get two sentences to be compared and the decay factor; Vectorizing the phrases in the two sentences to be compared respectively to obtain a word vector for each phrase in the two sentences to be compared; Determining a word vector similarity between the two sentences to be compared based on the word vector of each phrase in the two sentences to be compared; Generate a dependency tree for each sentence to be compared according to preset dependency syntax rules; Determining sentence similarity between the two sentences to be compared based on the decay factor, the dependency tree of each sentence to be compared, and the word vector similarity between the two sentences to be compared; Determining the sentence similarity between the two sentences to be compared based on the decay factor, the dependency tree of each sentence to be compared, and the word vector similarity between the two sentences to be compared includes: Traversing the dependency tree of the two sentences to be compared; When the dependency trees of the two to-be-compared sentences are generated in different ways, determining a first dependent word and a second dependent word in the dependency trees of the two to-be-compared sentences that have the same node attributes and are mutually dependent; Determining a comparison value of each sentence to be compared based on the decay factor, the dependency tree of each sentence to be compared, and the word vector similarity of each sentence to be compared; Determining a comparison value between the two sentences to be compared based on the number of the first dependent words and the second dependent words that have the same node attributes and are in a mutual dependence relationship, the content similarity of each node, and the word vector similarity between the two sentences to be compared; The sentence similarity between the two sentences to be compared is determined based on the comparison value of each sentence to be compared and the comparison value between the two sentences to be compared.

2. The method according to claim 1, characterized in that Each node in the dependency tree includes: the content of the sentence to be compared corresponding to the node, the node type, and the node attribute; wherein, The node type includes: a core word, a first dependent word, and a second dependent word; wherein the first dependent word is used to represent a dependent word of the core word, and the second dependent word is used to represent a dependent word of the dependent word; The node attributes include: a noun subject, a supplementary word, and a direct object.

3. The method according to claim 2, characterized in that Determining the sentence similarity between the two sentences to be compared based on the decay factor, the dependency tree of each sentence to be compared, and the word vector similarity between the two sentences to be compared includes: Traversing the dependency tree of the two sentences to be compared; When the dependency trees of the two sentences to be compared are generated in the same manner, the sentence similarity between the two sentences to be compared is determined based on the decay factor, the dependency tree of each sentence to be compared, and the word vector similarity between the two sentences to be compared.

4. The method according to claim 3, characterized in that The determining of the sentence similarity between the two sentences to be compared based on the decay factor, the dependency tree of each sentence to be compared, and the word vector similarity between the two sentences to be compared, when the dependency trees of the two sentences to be compared are generated in the same manner, includes: Determining a comparison value of each sentence to be compared based on the decay factor, the dependency tree of each sentence to be compared, and the word vector similarity of each sentence to be compared; Determine a comparison value between the two sentences to be compared based on the number of nodes at each level in the dependency tree of the two sentences to be compared, the content similarity of nodes of the same node type and node attribute, and the word vector similarity between the two sentences to be compared; The sentence similarity between the two sentences to be compared is determined based on the comparison value of each sentence to be compared and the comparison value between the two sentences to be compared.

5. The method according to claim 4, characterized in that The determining of the comparison value between the two sentences to be compared based on the number of nodes at each level in the dependency tree of the two sentences to be compared, the content similarity of nodes of the same node type and node attribute, and the word vector similarity between the two sentences to be compared includes: Determining the content similarity of the nodes of the same node type and node attributes in the dependency trees of the two sentences to be compared based on the word vectors corresponding to the contents of the nodes of the same node type and node attributes in the dependency trees of the two sentences to be compared and the decay factor; The comparison value between the two sentences to be compared is determined based on the number of nodes at each level in the dependency tree of the two sentences to be compared, the content similarity of nodes with the same node type and node attributes, and the word vector similarity between the two sentences to be compared.

6. The method according to claim 1, characterized in that The determining of a comparison value between the two sentences to be compared based on the number of the first dependent words and the second dependent words having the same node attributes and having a mutual dependency relationship, the content similarity of each node, and the word vector similarity between the two sentences to be compared includes: Determining the content similarity of each node based on the word vector of each sentence to be compared and the decay factor; Based on the number of the first dependent words and the second dependent words that have the same node attributes and are mutually dependent, the content similarity of each node, and the word vector similarity between the two sentences to be compared, the comparison value between the two sentences to be compared is determined.

7. The method according to claim 1 or 4, characterized in that Determining the comparison value of each sentence to be compared based on the decay factor, the dependency tree of each sentence to be compared, and the word vector similarity of each sentence to be compared includes: The comparison value of each sentence to be compared is determined based on the decay factor, the number of node types in the dependency tree of each sentence to be compared, and the word vector similarity of each sentence to be compared.

8. A device for calculating sentence similarity, characterized in that: The device comprises: An acquisition module, used to obtain two sentences to be compared and a decay factor; A word vector obtaining module, configured to vectorize the phrases in the two sentences to be compared, respectively, to obtain a word vector for each phrase in the two sentences to be compared; A word vector similarity determination module, configured to determine the word vector similarity between the two sentences to be compared based on the word vector of each phrase in the two sentences to be compared; A generation module, configured to generate a dependency tree for each sentence to be compared according to a preset dependency syntax rule; A sentence similarity determination module is configured to determine the sentence similarity between the two sentences to be compared based on the decay factor, the dependency tree of each sentence to be compared, and the word vector similarity between the two sentences to be compared; traverse the dependency tree of the two sentences to be compared; determine, when the dependency trees of the two sentences to be compared are generated in different ways, first dependent words and second dependent words that have the same node attributes and are mutually dependent in the dependency trees of the two sentences to be compared; determine the comparison value of each sentence to be compared based on the decay factor, the dependency tree of each sentence to be compared, and the word vector similarity of each sentence to be compared; determine the comparison value between the two sentences to be compared based on the number of first dependent words and second dependent words that have the same node attributes and are mutually dependent, the content similarity of each node, and the word vector similarity between the two sentences to be compared; and determine the sentence similarity between the two sentences to be compared based on the comparison value of each sentence to be compared and the comparison value between the two sentences to be compared.

9. A computer storage medium, characterized in that The computer storage medium stores a plurality of instructions, which are suitable for being loaded by a processor and executing the method steps according to any one of claims 1 to 7.

10. An electronic device, characterized in that: include: A processor and a memory; wherein the memory stores a computer program, and the computer program is suitable for being loaded by the processor and executing the method steps according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Computer network defensive strategy conversion-oriented semantic similarity detection system

    CN101950340A

  • Mixed multi-feature sentence similarity calculation method and system, and storage medium

    CN110705612A