Method, device, storage medium and electronic device for obtaining sentence similarity

By obtaining the high-dimensional Euclidean distance calculation of character weights and multi-dimensional vectors in the statement, the problem of low statement similarity calculation efficiency in the prior art is solved, and fast and accurate statement similarity calculation is achieved, which improves the efficiency of human-computer dialogue.

CN115114423BActive Publication Date: 2025-08-15阳光保险集团股份有限公司
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202210813915.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-07-11
Publication Date
2025-08-15
Estimated Expiration
2042-07-11

AI Technical Summary

Technical Problem

The prior art requires designing different optimization functions for different task scenarios when training text models. The process is complicated and it is difficult to determine which adjustments will have a positive impact on the model output results, resulting in low computational efficiency of statement similarity.

Method used

By obtaining the character weights of each character in the first and second statements, and using multi-dimensional vectors and high-dimensional Euclidean distances to calculate the similarity value, combining character weights as constraints, the statement similarity is quickly and accurately calculated.

Benefits of technology

It realizes fast and accurate calculation of statement similarity without being restricted by task scenarios, improves the efficiency of human-computer dialogue and reduces calculation costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115114423B_ABST
    Figure CN115114423B_ABST
Patent Text Reader

Abstract

Some embodiments of the present application provide a method, apparatus, storage medium, and electronic device for obtaining sentence similarity. The method includes: obtaining a character weight for each character in a first sentence, and obtaining a character weight for each character in a second sentence; obtaining a sentence vector for the first sentence to obtain a first vector, and obtaining a sentence vector for the second sentence to obtain a second vector, wherein the first vector and the second vector are both multidimensional vectors; using the character weight as a constraint, obtaining a similarity value between the first sentence and the second sentence based on the first vector and the second vector. Some embodiments of the present application can calculate the similarity of any two sentences, quickly and accurately obtaining the similarity value of the two sentences.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of text processing technology, and in particular to a method, device, storage medium, and electronic device for obtaining sentence similarity. Background Art

[0002] With the development of human-computer dialogue technology, sentence similarity calculation has important applications in question-answering scenarios.

[0003] Currently, existing techniques typically use text model training to find sentences similar to the target sentence. However, training text models requires designing different optimization functions for different task scenarios, which is a complex process. Furthermore, during model tuning, it can be difficult to determine which adjustments during training will positively impact the model's final output.

[0004] Therefore, how to provide a technical solution for a method of efficiently obtaining sentence similarity has become a technical problem that needs to be solved urgently. Summary of the Invention

[0005] The purpose of some embodiments of the present application is to provide a method, device, storage medium and electronic device for obtaining sentence similarity. Through the technical solutions of the embodiments of the present application, the similarity of any two sentences can be calculated, and the similarity values of the two sentences can be obtained quickly and accurately, thereby improving the efficiency of obtaining sentence similarity values.

[0006] In a first aspect, some embodiments of the present application provide a method for obtaining sentence similarity, including: obtaining the character weight of each character in a first sentence, and obtaining the character weight of each character in a second sentence; obtaining the sentence vector of the first sentence to obtain a first vector, and obtaining the sentence vector of the second sentence to obtain a second vector, wherein the first vector and the second vector are both multidimensional vectors; using the character weight as a constraint condition, obtaining the similarity value of the first sentence and the second sentence according to the first vector and the second vector.

[0007] Some embodiments of the present application obtain the similarity value between the first sentence and the second sentence through the sentence vectors of the first sentence and the second sentence and the character weights of each character, which can accurately calculate the similarity value of the two sentences without being constrained by the task scenario, thereby improving the acquisition efficiency and thus improving the efficiency of human-computer dialogue.

[0008] In some embodiments, obtaining the similarity value between the first sentence and the second sentence based on the first vector and the second vector includes: obtaining a first eigenvalue corresponding to the first sentence; obtaining a target distance between the first vector and the second vector; and obtaining the similarity value based on the first eigenvalue and the target distance.

[0009] Some embodiments of the present application can quickly obtain a similarity value between the first sentence and the second sentence with high accuracy through the first feature value corresponding to the first sentence and the obtained target distance, thereby improving acquisition efficiency.

[0010] In some embodiments, when the i-th character of the first sentence moves to the j-th character position in the second sentence, obtaining the first eigenvalue corresponding to the first sentence includes: taking the i-th character weight as the first eigenvalue; obtaining the target distance between the first vector and the second vector includes: obtaining the target distance between the i-th character vector in the first vector and the j-th character vector in the second vector; obtaining the similarity value based on the first eigenvalue and the target distance includes: multiplying the i-th character weight by the target distance to obtain the i-th similarity initial value; and taking the minimum value of all similarity initial values as the similarity value.

[0011] Some embodiments of the present application move the i-th character to obtain the initial similarity value when the i-th character is moved to the j-th character position in the second sentence, and then obtain multiple initial similarity values when the i-th character is moved to each character position in the second sentence. Then, the similarity value between the first sentence and the second sentence is filtered out from the multiple initial similarity values, which can improve the computing efficiency and thus improve the working efficiency of the smart device during human-computer dialogue.

[0012] In some embodiments, obtaining the target distance between the i-th character vector in the first vector and the j-th character vector in the second vector includes: obtaining the vector differences of each dimension between the i-th character vector and the j-th character vector; and obtaining the target distance based on the vector differences of each dimension, wherein the target distance is related to the vector differences of each dimension.

[0013] Since the first vector and the second vector in some embodiments of the present application are multidimensional vectors, the target distance can be obtained by the difference between the vectors of each dimension of the i-th character vector and the j-th character vector in the first vector, which can provide valid data for the subsequent calculation of the similarity value.

[0014] In some embodiments, obtaining the character weight of each character in the first sentence includes: segmenting the first sentence by character to obtain each character in the first sentence; using each character in the first sentence as input to a text algorithm to obtain the character weight; obtaining the character weight of each character in the second sentence includes: segmenting the second sentence by character to obtain each character in the second sentence; using each character in the second sentence as input to the text algorithm to obtain the character weight.

[0015] Some embodiments of the present application can improve the convenience and efficiency of calculation by segmenting the first sentence and the second sentence by characters and using a text algorithm to calculate the character weights.

[0016] In some embodiments, obtaining the sentence vector of the first sentence to obtain a first vector, and obtaining the sentence vector of the second sentence to obtain a second vector, include: inputting the first sentence into a target language model to obtain the first vector; and inputting the second sentence into the target language model to obtain the second vector.

[0017] Some embodiments of the present application obtain a multi-dimensional first vector and a second vector through a target language model, which can improve the efficiency of obtaining the similarity value of the first sentence and the second sentence, reduce the computing cost, and thus improve the efficiency of processing business.

[0018] In a second aspect, some embodiments of the present application provide a device for obtaining sentence similarity, including: a character weight acquisition module, configured to obtain the character weight of each character in a first sentence, and obtain the character weight of each character in a second sentence; a sentence vector acquisition module, configured to obtain the sentence vector of the first sentence to obtain a first vector, and obtain the sentence vector of the second sentence to obtain a second vector, wherein the first vector and the second vector are both multidimensional vectors; a similarity acquisition module, configured to obtain the similarity value of the first sentence and the second sentence according to the first vector and the second vector with the character weight as a constraint condition.

[0019] In a third aspect, some embodiments of the present application provide a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, can implement the method described in any embodiment of the first aspect.

[0020] In a fourth aspect, some embodiments of the present application provide an electronic device comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein the processor can implement a method as described in any embodiment of the first aspect when executing the program.

[0021] In a fifth aspect, some embodiments of the present application provide a computer program product, comprising a computer program, wherein the computer program, when executed by a processor, can implement the method described in any embodiment of the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] In order to more clearly illustrate the technical solutions of some embodiments of the present application, the following is a brief introduction to the drawings required for use in some embodiments of the present application. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other relevant drawings can be obtained based on these drawings without paying any creative work.

[0023] Figure 1 A system diagram for obtaining sentence similarity provided in some embodiments of the present application;

[0024] Figure 2 One of the flow charts of the method for obtaining sentence similarity provided in some embodiments of the present application;

[0025] Figure 3 Flowchart 2 of the method for obtaining sentence similarity provided in some embodiments of the present application;

[0026] Figure 4 A block diagram of an apparatus for obtaining sentence similarity provided in some embodiments of the present application;

[0027] Figure 5 A schematic diagram of an electronic device is provided for some embodiments of the present application. DETAILED DESCRIPTION

[0028] The technical solutions in some embodiments of the present application will be described below in conjunction with the drawings in some embodiments of the present application.

[0029] It should be noted that similar reference numerals and letters represent similar items in the following drawings. Therefore, once an item is defined in one drawing, it does not need to be further defined or explained in subsequent drawings. At the same time, in the description of this application, the terms "first", "second", etc. are only used to distinguish the description and should not be understood as indicating or implying relative importance.

[0030] In the related art, the development of natural language technology has made it possible to calculate sentence similarity, so natural language technology has been widely used in the field of human-computer dialogue (for example, insurance customer service). In the field of human-computer dialogue, by calculating the similarity between the real-time questions of online users (as a specific example of the first text) and the questions configured in the background database (as a specific example of the second text), the questions most similar to the real-time questions are obtained, and the answers corresponding to the most similar questions are returned to the user. There are two main methods for calculating sentence similarity. One is to use cosine similarity to calculate the similarity of two sentences. This method does not take into account the order of each character and the semantic information of each character. Therefore, the similarity values of the two sentences obtained by this method are less accurate. The other is to use a training model method, but the training model needs to set different optimization functions for different tasks, and tuning is more difficult.

[0031] In view of this, some embodiments of the present application provide a method, apparatus, storage medium, and electronic device for obtaining sentence similarity. The method can obtain the similarity value between the first and second sentences based on the character weights of each character in the first and second sentences and the corresponding first and second vectors. Some embodiments of the present application can quickly and accurately calculate the similarity value between the first and second sentences without being restricted by the task scenario, thereby improving the efficiency of human-computer dialogue and reducing computational costs.

[0032] like Figure 1 As shown, some embodiments of the present application provide a system for obtaining sentence similarity, which includes a terminal 100 and an intelligent interactive terminal 200, wherein the terminal 100 is used to send the collected voice of the user 101 to the intelligent interactive terminal 200, and the intelligent interactive terminal 200 searches the database for a second sentence similar to the first sentence based on the first sentence corresponding to the voice of the user 101, and then returns the reply information corresponding to the second sentence to the terminal 100, and finally the terminal 100 broadcasts the voice corresponding to the reply information to the user 101.

[0033] In some embodiments of the present application, the terminal 100 is a device with communication capabilities, which can be a mobile terminal (e.g., a mobile phone) or a non-portable computer terminal, etc. The intelligent interactive terminal 200 can be a server device or intelligent device with communication capabilities, such as a voice robot. It should be noted that the present application does not specifically limit the types of the terminal 100 and the intelligent interactive terminal 200.

[0034] The following is combined with Figure 2 The implementation process of a method for obtaining sentence similarity performed by the intelligent interactive terminal 200 provided in some embodiments of the present application is exemplified.

[0035] Please see the attached Figure 2 , Figure 2 A flow chart of a method for obtaining sentence similarity is provided for some embodiments of the present application. The method for obtaining sentence similarity includes: S210, obtaining the character weight of each character in the first sentence, and obtaining the character weight of each character in the second sentence. S220, obtaining the sentence vector of the first sentence to obtain a first vector, and obtaining the sentence vector of the second sentence to obtain a second vector, wherein the first vector and the second vector are both multidimensional vectors. S230, using the character weight as a constraint condition, obtaining the similarity value of the first sentence and the second sentence based on the first vector and the second vector.

[0036] It should be noted that, in some embodiments of the present application, S220 may be executed first and then S210, and in other embodiments of the present application, S210 and S220 may be executed simultaneously.

[0037] The above process is described below as an example.

[0038] In some embodiments of the present application, S210 may include: segmenting the first sentence by character to obtain each character in the first sentence; using each character in the first sentence as input to a text algorithm to obtain a character weight of the first sentence; segmenting the second sentence by character to obtain each character in the second sentence; using each character in the second sentence as input to the text algorithm to obtain a character weight of the second sentence.

[0039] For example, in some embodiments of the present application, after segmenting a first sentence by character, the TF-IDF (Term Frequency–Inverse Document Frequency) algorithm can be used to obtain the character weight of the first sentence. Similarly, the character weight of the second sentence can be obtained. It should be understood that the TF-IDF algorithm is a specific example of the text algorithm of the present application, and in actual application scenarios, different text algorithms can be selected based on the type of sentence.

[0040] To improve computing efficiency, in some embodiments of the present application, S220 may include: inputting the first sentence into a target language model to obtain the first vector; and inputting the second sentence into the target language model to obtain the second vector.

[0041] For example, in some embodiments of the present application, a first sentence can be input into a pre-trained language model (as a specific example of a target language model) to obtain a multi-dimensional first vector representing the first sentence. Similarly, a second sentence can be input into the pre-trained language model to obtain a multi-dimensional second vector for the second sentence. The pre-trained language model can be a BERT model or a derivative model of the BERT class.

[0042] In some embodiments of the present application, using the character weight as a constraint condition in S230 includes: obtaining the constraint condition by the following formula: Among them, W i is the weight of the i-th character in the first sentence, n is the number of characters in the first sentence, W j is the weight of the jth character in the second sentence, n' is the number of characters in the second sentence, T i,j is the weight matrix, T i,j So W i and W j Obtained for the constraints.

[0043] in, It is used to represent that when the i-th character in the first sentence moves to the j-th character position in the second sentence, a third sentence is obtained (that is, the third sentence includes: the second sentence plus the i-th character). At this time, the weight of the i-th character is equal to the sum of the weights of each character in the third sentence. It is used to indicate that the weight of the jth character is equal to the sum of the weights of all characters in the third sentence.

[0044] It can be understood that the values of i and j are both positive integers, the i-th character is any character in the first statement, and the j-th character is any character in the second statement. The value ranges of i and j are determined by the character data of the first statement and the second statement, respectively. For example, if the number of characters in the first statement is n, the value range of i is [1, n], the number of characters in the second statement is n', and the value range of j is [1, n'].

[0045] In some embodiments of the present application, S230 may include: S231, obtaining a first eigenvalue corresponding to the first sentence; S232, obtaining a target distance between the first vector and the second vector; S233, obtaining the similarity value based on the first eigenvalue and the target distance.

[0046] For example, in some embodiments of the present application, the first eigenvalue can be obtained based on the correlation between the character weight of the first sentence and the character weight of the second sentence. Then, the target distance between the first vector and the second vector is obtained using the calculation formula of the high-dimensional Euclidean distance. It should be noted that the traditional Euclidean distance calculation formula can only calculate the distance between one-dimensional vectors, while in some embodiments of the present application, a multi-dimensional vector, that is, a high-dimensional vector, is obtained. Therefore, it is necessary to obtain the target distance according to the calculation formula of the high-dimensional Euclidean distance provided in some embodiments of the present application.

[0047] The implementation process of S230 is described below by way of example.

[0048] In some embodiments of the present application, when the i-th character of the first sentence moves to the j-th character position in the second sentence,

[0049] S231 may include: obtaining the i-th character weight; and weighting the i-th character weight to obtain the first feature value.

[0050] For example, in some embodiments of the present application, when the i-th character is moved to the j-th character position in the second sentence, the first eigenvalue can be obtained by the following formula: in That is the weight of the i-th character.

[0051] S232 may include: obtaining a target distance between the i-th character vector in the first vector and the j-th character vector in the second vector.

[0052] In some embodiments of the present application, S232 may further include: obtaining the vector differences of each dimension between the i-th character vector and the j-th character vector; obtaining the target distance based on the vector differences of each dimension, wherein the target distance is related to the vector differences of each dimension.

[0053] For example, in some embodiments of the present application, the target distance c(i, j) between the i-th character vector and the j-th character vector is obtained by the following method:

[0054]

[0055] Among them, h is the dimension of the vector, E i1 is the one-dimensional vector of the i-th character, E i2 is the second-dimensional vector of the i-th character, E ih is the h-th dimension vector of the i-th character, E' j1 is the first dimension vector of the jth character, E' j2 is the second-dimensional vector of the j-th character, E' jh is the h-th dimension vector of the j-th character.

[0056] S232 may include: multiplying the i-th character weight by the target distance to obtain the i-th initial similarity value; and taking the minimum value of all the initial similarity values as the similarity value.

[0057] For example, in some embodiments of the present application, the i-th similarity initial value sim is obtained by the following method: i :

[0058]

[0059] Since there are n characters in the first sentence, we can get n initial similarity values. The minimum value among the n initial similarity values is used as the similarity value simiarity between the first sentence and the second sentence, that is:

[0060]

[0061] Among them, s is the first statement and s' is the second statement.

[0062] The following is combined with Figure 3 The specific implementation process of a method for obtaining sentence similarity provided by some embodiments of the present application is exemplified.

[0063] Please see the attached Figure 3 , attached Figure 3 The flowchart of the method for obtaining sentence similarity provided in some embodiments of the present application is as follows. The specific implementation process of the method for obtaining sentence similarity is exemplified below.

[0064] S310: Obtain a first statement and a second statement.

[0065] For example, as a specific example of the present application, the first statement s=(t1, t2, ..., t n ), the second statement s'=(t'1,t'2,…,t' n' ), where t1, t2, t n , t'1, t'2, t' n' Used to represent a single character.

[0066] S320, using each character in the first sentence as an input to a text algorithm to obtain a character weight of the first sentence; using each character in the second sentence as an input to a text algorithm to obtain a character weight of the second sentence.

[0067] For example, as a specific example of the present application, s=(t1, t2, ..., t n ) and s'=(t'1,t'2,…,t' n' ) are input into the TF-IDF algorithm to obtain the character weights in sentence s and the character weights in s'.

[0068] S330 , inputting the first sentence and the second sentence into the target language model respectively to obtain a first vector and a second vector.

[0069] For example, as a specific example of the present application, s=(t1, t2, ..., t n ) and s'=(t'1,t'2,…,t' n' ) are input into the pre-trained language Bert model, and the first vector E=(E1,E2,…,E i ,…,En ), the second vector E'=(E'1, E'2, ..., E' j ,…,E' n ), where each character vector in E and E' has a dimension of 768, and E i is the i-th character vector, E' j is the j-th character vector.

[0070] S340, obtaining a similarity value using a high-dimensional linear programming algorithm.

[0071] With the character weights as constraints, the similarity value between the first sentence and the second sentence is obtained according to the first vector and the second vector.

[0072] For example, as a specific example of the present application, a high-dimensional linear programming algorithm is used to obtain the similarity value of s and s' according to the above-mentioned target distance and similarity calculation formula. The degree of similarity between the first sentence and the second sentence can be determined based on the similarity value. To avoid repetition, the detailed description is appropriately omitted here. It should be understood that the principle of the high-dimensional linear programming algorithm is to use character weights as constraints and obtain the similarity value of the first sentence and the second sentence based on the first vector and the second vector.

[0073] Please refer to Figure 4 , Figure 4 The following is a block diagram illustrating the components of an apparatus for obtaining sentence similarity provided in some embodiments of the present application. It should be understood that the apparatus for obtaining sentence similarity corresponds to the aforementioned method embodiment and is capable of executing each step involved in the aforementioned method embodiment. The specific functions of the apparatus for obtaining sentence similarity can be found in the description above, and a detailed description is omitted here to avoid repetition.

[0074] Figure 4 The device for obtaining sentence similarity includes at least one software functional module that can be stored in a memory in the form of software or firmware or solidified in the device for obtaining sentence similarity, and the device for obtaining sentence similarity includes: a character weight acquisition module 410, configured to obtain the character weight of each character in the first sentence, and obtain the character weight of each character in the second sentence; a sentence vector acquisition module 420, configured to obtain the sentence vector of the first sentence to obtain a first vector, and obtain the sentence vector of the second sentence to obtain a second vector, wherein the first vector and the second vector are both multidimensional vectors; a similarity acquisition module 430, configured to use the character weight as a constraint condition and obtain the similarity value of the first sentence and the second sentence according to the first vector and the second vector.

[0075] In some embodiments of the present application, the similarity acquisition module 430 can also be configured to obtain a first eigenvalue corresponding to the first sentence; obtain a target distance between the first vector and the second vector; and obtain the similarity value based on the first eigenvalue and the target distance.

[0076] In some embodiments of the present application, the similarity acquisition module 430 can also be configured to, when the i-th character of the first sentence moves to the j-th character position in the second sentence, obtain the first eigenvalue corresponding to the first sentence, including: obtaining the i-th character weight; weighting the i-th character weight to obtain the first eigenvalue; obtaining the target distance between the first vector and the second vector, including: obtaining the target distance between the i-th character vector in the first vector and the j-th character vector in the second vector; obtaining the similarity value based on the first eigenvalue and the target distance, including: multiplying the i-th character weight by the target distance to obtain the i-th similarity initial value; and taking the minimum value of all similarity initial values as the similarity value.

[0077] In some embodiments of the present application, the similarity acquisition module 430 can also be configured to obtain the difference between the vectors of each dimension between the i-th character vector and the j-th character vector; and obtain the target distance based on the difference between the vectors of each dimension, wherein the target distance is related to the difference between the vectors of each dimension.

[0078] In some embodiments of the present application, the character weight acquisition module 410 can also be configured to segment the first sentence by character to obtain each character in the first sentence; use each character in the first sentence as input to the text algorithm to obtain the character weight; segment the second sentence by character to obtain each character in the second sentence; use each character in the second sentence as input to the text algorithm to obtain the character weight.

[0079] In some embodiments of the present application, the sentence vector acquisition module 420 may also be configured to input the first sentence into a target language model to obtain the first vector; and input the second sentence into the target language model to obtain the second vector.

[0080] Some embodiments of the present application further provide a computer-readable storage medium having a computer program stored thereon. When the program is executed by a processor, the operations corresponding to any of the methods for obtaining sentence similarity provided in the above embodiments can be implemented.

[0081] Some embodiments of the present application further provide a computer program product, which includes a computer program. When the computer program is executed by a processor, it can implement the operations corresponding to any embodiment of the method for obtaining sentence similarity provided in the above embodiments.

[0082] like Figure 5 As shown, some embodiments of the present application provide an electronic device 500, which includes: a memory 510, a processor 520, and a computer program stored in the memory 510 and executable on the processor 520, wherein the processor 520 reads the program from the memory 510 via a bus 530 and executes the program to implement a method of any embodiment included in the above-mentioned method for obtaining sentence similarity.

[0083] Processor 520 can process digital signals and can include various computing architectures, such as a complex instruction set computer architecture, a reduced instruction set computer architecture, or an architecture that implements a combination of multiple instruction sets. In some examples, processor 520 can be a microprocessor.

[0084] The memory 510 can be used to store instructions executed by the processor 520 or data related to the execution of instructions. These instructions and / or data may include code for implementing some or all functions of one or more modules described in the embodiments of this application. The processor 520 of the embodiment of the present disclosure can be used to execute the instructions in the memory 510 to implement the method shown above. The memory 510 includes dynamic random access memory, static random access memory, flash memory, optical memory, or other memory known to those skilled in the art.

[0085] The foregoing is merely an embodiment of the present application and is not intended to limit the scope of protection of the present application. Various modifications and variations are possible for those skilled in the art. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application shall be included within the scope of protection of the present application. It should be noted that similar reference numerals and letters represent similar items in the following figures. Therefore, once an item is defined in one figure, it does not need to be further defined or explained in subsequent figures.

[0086] The above description is merely a specific embodiment of the present application, but the scope of protection of the present application is not limited thereto. Any changes or substitutions that can be easily conceived by a person skilled in the art within the technical scope disclosed in the present application should be included in the scope of protection of the present application. Therefore, the scope of protection of the present application should be based on the scope of protection of the claims.

[0087] It should be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. In the absence of further limitations, an element defined by the text "comprising a ..." does not exclude the presence of other identical elements in the process, method, article, or device comprising the element.

Claims

1. A method for obtaining sentence similarity, characterized in that: include: Obtaining a character weight for each character in the first sentence, and obtaining a character weight for each character in the second sentence; Obtaining a sentence vector of the first sentence to obtain a first vector, and obtaining a sentence vector of the second sentence to obtain a second vector, wherein both the first vector and the second vector are multidimensional vectors; Using the character weight as a constraint condition, obtaining a similarity value between the first sentence and the second sentence based on the first vector and the second vector; the similarity is obtained by a first eigenvalue corresponding to the first sentence and a target distance; When the i-th character of the first sentence moves to the j-th character position in the second sentence, the first feature value is obtained by the following method: obtaining the i-th character weight; weighting the i-th character weight to obtain the first feature value; The target distance is obtained by the following method: obtaining the vector difference of each dimension between the i-th character vector and the j-th character vector; obtaining the target distance according to the vector difference of each dimension, wherein the target distance is related to the vector difference of each dimension; The target distance c ( i , j ) is calculated as: in, h is the dimension of the vector, E i1 For the i A one-dimensional vector of characters, E i2 For the i The second dimension vector of the character, E ih For the i Character h dimensional vector, E' j1 For the j The first dimension of the character vector, E' j2 For the j The second dimension vector of the character, E' jh For the j Character h dimensional vector; The obtaining a similarity value between the first sentence and the second sentence according to the first vector and the second vector includes: Obtain a first eigenvalue corresponding to the first sentence; obtain a target distance between the first vector and the second vector; multiply the i-th character weight by the target distance to obtain an i-th similarity initial value; and use the minimum value of all similarity initial values as the similarity value.

2. The method according to claim 1, wherein The obtaining of the character weight of each character in the first sentence includes: Splitting the first sentence by characters to obtain the characters in the first sentence; Using each character in the first sentence as an input to a text algorithm to obtain the character weight; The obtaining of the character weight of each character in the second sentence includes: Splitting the second sentence by characters to obtain the characters in the second sentence; Each character in the second sentence is used as input to the text algorithm to obtain the character weight.

3. The method according to claim 1, wherein The acquiring of the sentence vector of the first sentence to obtain a first vector, and acquiring of the sentence vector of the second sentence to obtain a second vector, includes: Inputting the first sentence into a target language model to obtain the first vector; The second sentence is input into the target language model to obtain the second vector.

4. A device for obtaining sentence similarity, characterized in that: The apparatus is configured to execute the method according to claim 1, comprising: a character weight acquisition module configured to acquire a character weight of each character in the first sentence and acquire a character weight of each character in the second sentence; a sentence vector acquisition module, configured to acquire the sentence vector of the first sentence to obtain a first vector, and acquire the sentence vector of the second sentence to obtain a second vector, wherein the first vector and the second vector are both multidimensional vectors; The similarity acquisition module is configured to obtain a similarity value between the first sentence and the second sentence according to the first vector and the second vector, with the character weight as a constraint condition.

5. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, wherein when the program is executed by a processor, the method according to any one of claims 1 to 3 is implemented.

6. A computer program product, characterized in that The computer program product comprises a computer program, wherein when the computer program is executed by a processor, the method according to any one of claims 1 to 3 is implemented.

7. An electronic device, characterized in that: The method comprises a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the method according to any one of claims 1 to 3 is implemented.

Citation Information

Patent Citations

  • Response determination method, device, equipment, medium and system

    CN110019715A