Model training method, similarity calculation method, device, equipment and medium

By constructing training samples at the text feature vector level and iteratively training the neural network model, the problem of being unable to calculate edit distance similarity after text has been converted into feature vectors is solved, and accurate similarity calculation is achieved in business scenarios with high data security.

CN115600114BActive Publication Date: 2026-02-13CETC CYBERSPACE SECURITY TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202211208071.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-09-30
Publication Date
2026-02-13
Estimated Expiration
2042-09-30

AI Technical Summary

Technical Problem

When text data has been converted into feature vectors, existing technologies cannot directly calculate the edit distance similarity of the original text, which is especially unacceptable in business scenarios with high data security requirements.

Method used

By acquiring the first text and performing text editing operations, training samples are constructed. The initial neural network model is used to map the samples to the text editing vector space, the editing vector similarity is calculated, a loss function is constructed, and the neural network model is iteratively trained to obtain the similarity calculation model.

Benefits of technology

It enables the calculation of edit distance similarity of the original text at the text feature vector level, meeting the business requirements of high data security and improving the accuracy and efficiency of similarity calculation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115600114B_ABST
    Figure CN115600114B_ABST
Patent Text Reader

Abstract

The application discloses a similarity calculation model training method and device, equipment and medium, including: obtaining a first text and performing a text editing operation on the first text to obtain a second text; constructing corresponding training samples based on the feature vectors of the first text and the second text, and mapping the training samples to a preset text editing vector space through an initial neural network model to obtain corresponding first text editing vectors; calculating the similarity between different text editing vectors in the first text editing vectors, and constructing a loss function based on the similarity and a preset similarity label; training the initial neural network model using the loss function, and then jumping back to the step of obtaining the first text and performing the text editing operation on the first text until a preset iteration number is reached to obtain a similarity calculation model. The initial neural network is trained to obtain the similarity calculation model, so as to calculate the editing distance similarity of the text according to the text feature vector.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of computer, and particularly relates to a model training method and device, a similarity calculation method and device, equipment and a medium. BACKGROUND

[0002] With the development of computer and Internet technology, massive accumulation of electronic data, in these data, text data accounts for a high proportion, wide range, the mining and analysis of text data has become a widely concerned problem. At present, an important technical means for text data mining is text similarity calculation, which calculates the similarity between texts to meet the classification and retrieval requirements of texts. Commonly used text similarity measures include edit distance, Simhash, cosine distance, etc. Among them, the edit distance focuses on the literal structure similarity of the text. For a given two texts, calculate the minimum number of steps needed to transform one text into another, the allowed operations include inserting a word, deleting a word, replacing a word. The advantage of this calculation method is that it does not need to be segmented, and it has strong interpretability. Simhash is to convert the segmented text into hash value features, and calculate their Hamming distance. The calculation efficiency is high. Cosine distance is generally first segmented a text, convert words to word vectors through a word vector model, calculate the vector of the text through the word vector, and finally calculate the cosine distance between the text vectors. Its advantage is that it can reflect the semantic similarity. In actual business scenarios, we can flexibly combine and use different similarity calculation methods according to the characteristics of business data.

[0003] Currently, user text data is stored at the user end, template data used for calculating text similarity is stored at the server end, a similarity calculation model runs at the server end, and the user finds the most similar template to the given user text data by calling the model through the service. For the purpose of protecting the security of business data, when data is transmitted between the user end and the server end, the original text is not allowed to be transmitted, but the text needs to be converted into a certain feature at the user end before transmission, and it is necessary to ensure that the feature cannot be reversely restored to the text. In this scenario, a most direct processing method is to convert the text into a text vector feature at the user end using a word vector model and a neural network model, obtain the text vector feature of the template data at the server end using the same model, and then transmit the text vector feature at the user end to the server end for similarity calculation. This processing method naturally fits the calculation method of cosine distance similarity, but in actual scenarios, we find that the cosine similarity is not good enough, and other similarity features need to be combined, such as combining the edit distance feature to optimize the similarity calculation result. The existing edit distance similarity calculation method needs to be calculated according to the original texts of two texts, and when the text is converted into a feature vector, the edit distance similarity of the original text cannot be directly calculated according to the vector, that is, the original text of the user data and the original text of the template data need to be known to calculate. In some business scenarios with high requirements for data security, this cannot meet the needs.

[0004] In summary, in the case where the text has been converted into a text feature vector, how to calculate the edit distance similarity of the original text according to the text feature vector is a problem to be solved at present. SUMMARY

[0005] Therefore, the purpose of the present application is to provide a model training method, a similarity calculation method, an apparatus, a device and a medium, which can calculate the edit distance similarity of the original text according to the text feature vector in the case where the text has been converted into a text feature vector. The specific scheme is as follows:

[0006] In a first aspect, the present application discloses a similarity calculation model training method, comprising:

[0007] obtaining a first text and performing a text editing operation on the first text to obtain a second text;

[0008] constructing a corresponding training sample based on the feature vector of the first text and the feature vector of the second text, and mapping the training sample to a preset text editing vector space through an initial neural network model to obtain a corresponding first text editing vector; the first text editing vector includes a text editing vector corresponding to the first text and a text editing vector corresponding to the second text;

[0009] calculate the similarity between different text edit vectors in the first text edit vector, and construct a loss function based on the similarity and a preset similarity label; wherein the preset similarity label includes the edit distance similarity between the first text and the second text;

[0010] train the initial neural network model using the loss function, and then jump back to the step of obtaining the first text and performing text edit operation on the first text until a preset iteration number is reached to obtain a similarity calculation model.

[0011] Optionally, the calculation of the similarity between different text edit vectors in the first text edit vector comprises:

[0012] Calculate the inner product between two text edit vectors in the first text edit vector set to obtain the corresponding similarity.

[0013] Optionally, before constructing the corresponding training sample based on the feature vector of the first text and the feature vector of the second text, the method further comprises:

[0014] performing text segmentation processing on the first text and the second text, and obtaining the corresponding word ID;

[0015] processing each word ID to obtain the corresponding word vector, and obtaining the feature vector corresponding to the first text and the feature vector corresponding to the second text based on the word vector.

[0016] Optionally, the training of the initial neural network model using the loss function comprises:

[0017] determining hyperparameter information and configuring the hyperparameter information; wherein the hyperparameter information includes learning rate, learning rate reduction strategy, and iteration number;

[0018] train the initial neural network model using the configured hyperparameter information and the loss function.

[0019] In a second aspect, the present application discloses an edit distance similarity calculation method, applied to a server, comprising:

[0020] obtaining the target text feature vector after the client sends the target text for feature vector extraction;

[0021] mapping the target text feature vector to a preset text edit vector space through a similarity calculation model to obtain a corresponding target text edit vector; then querying a number of template text edit vectors similar to the target text edit vector by using the similarity model; wherein the similarity calculation model is a model trained by using the disclosed similarity calculation model training method;

[0022] binding the target text edit vector with each of the template text edit vectors to construct a number of second text edit vectors, and calculating a target similarity between different text edit vectors in each of the second text edit vectors by using the similarity calculation model, so as to determine the target similarity as an edit distance similarity between the target text and a template text corresponding to each of the template text edit vectors.

[0023] Optionally, the edit distance similarity calculation method further comprises:

[0024] obtaining a template text set, and extracting a feature vector of each template text in the template text set to obtain a corresponding template text feature vector set;

[0025] mapping the template text feature vector set to a preset text edit vector space through the similarity calculation model to obtain a corresponding template text edit vector set;

[0026] constructing a tree-shaped data structure based on the template text edit vector set.

[0027] Optionally, the querying a number of template text edit vectors similar to the target text edit vector by using the similarity model comprises:

[0028] querying a number of template text edit vectors similar to the target text edit vector from the tree-shaped data structure by using the similarity model.

[0029] In a third aspect, the present application discloses a similarity calculation model training device, comprising:

[0030] a text acquisition module configured to acquire a first text and perform a text edit operation on the first text to obtain a second text;

[0031] a vector mapping module configured to construct a corresponding training sample based on a feature vector of the first text and a feature vector of the second text, and map the training sample to a preset text edit vector space through an initial neural network model to obtain a corresponding first text edit vector; the first text edit vector includes a text edit vector corresponding to the first text and a text edit vector corresponding to the second text;

[0032] The loss function construction module is configured to calculate similarities between different text edit vectors in the first text edit vectors, and construct a loss function based on the similarities and preset similarity labels; wherein the preset similarity labels include an edit distance similarity between the first text and the second text.

[0033] The model training module is configured to train the initial neural network model by using the loss function, and then jump back to the step of obtaining the first text and performing the text edit operation on the first text until a preset iteration number is reached, so as to obtain a similarity calculation model.

[0034] In a fourth aspect, the present application discloses an electronic device, comprising:

[0035] A memory for saving a computer program;

[0036] A processor for executing the computer program to implement the steps of the similarity calculation model training method disclosed above.

[0037] In a fifth aspect, the present application discloses a computer readable storage medium for storing a computer program; wherein the computer program is executed by a processor to implement the steps of the similarity calculation model training method disclosed above.

[0038] It can be seen that the application obtains a first text and performs a text editing operation on the first text to obtain a second text; constructs a corresponding training sample based on a feature vector of the first text and a feature vector of the second text, and maps the training sample to a preset text editing vector space through an initial neural network model to obtain a corresponding first text editing vector; the first text editing vector includes a text editing vector corresponding to the first text and a text editing vector corresponding to the second text; calculate the similarity between different text editing vectors in the first text editing vector, and construct a loss function based on the similarity and a preset similarity label; wherein the preset similarity label includes an edit distance similarity between the first text and the second text; train the initial neural network model using the loss function, and then jump back to the step of obtaining the first text and performing the text editing operation on the first text until a preset iteration number is reached to obtain a similarity calculation model. As can be seen, the application performs a text editing operation on the first text to obtain the second text, then extracts feature vectors of the first text and the second text to construct training samples, and takes the edit distance similarity between the first text and the second text as a preset similarity label, then maps the training sample to a preset text editing vector space through an initial neural network to obtain a first text editing vector, then calculates the similarity of different text editing vectors in the first text editing vector, constructs a loss function based on the similarity and the preset similarity label, and finally trains the initial neural network model using the loss function, repeatedly the above process to obtain a similarity calculation model. In this way, the edit distance similarity between text feature vectors can be calculated using the similarity calculation model as the edit distance similarity between original texts. BRIEF DESCRIPTION OF DRAWINGS

[0039] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the drawings needed to be used in the embodiments or prior art description will be briefly introduced. Obviously, the drawings in the following description are only embodiments of the present application, and those skilled in the art can obtain other drawings according to the provided drawings without creative labor.

[0040] Figure 1 A similarity calculation model training method flowchart disclosed by the present application;

[0041] Figure 2 A specific similarity calculation model training method flowchart disclosed by the present application;

[0042] Figure 3 An edit distance similarity calculation method flowchart disclosed by the present application;

[0043] Figure 4A specific service scenario disclosed in the present application is shown in the figure.

[0044] Figure 5 A specific system component disclosed in the present application is shown in the figure.

[0045] Figure 6 A similarity calculation model training device structure disclosed in the present application is shown in the figure.

[0046] Figure 7 An electronic device structure disclosed in the present application is shown in the figure. DETAILED DESCRIPTION

[0047] The technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor fall within the scope of protection of the present application.

[0048] The existing edit distance similarity calculation method needs to be calculated according to the original texts of two texts. When the texts are converted into feature vectors, the edit distance similarity of the original texts cannot be directly calculated according to the vectors, that is, the original texts of the user data and the template data need to be known to perform the calculation. In some business scenarios with high requirements for data security, the requirement cannot be met. Therefore, the embodiments of the present application disclose a model training method, a similarity calculation method, a device, equipment and a medium, which can calculate the edit distance similarity of the original text according to the text feature vector when the text has been converted into a text feature vector.

[0049] Referring to Figure 1 the figure, the embodiments of the present application disclose a similarity calculation model training method, which comprises:

[0050] Step S11: obtaining a first text and performing a text editing operation on the first text to obtain a second text.

[0051] In the embodiments, it is assumed that there is a text data set Corpus T ={T1,T2,…T N}, which contains N texts, and each text T i =[c1,c2,…c n ], wherein c i represents a word, and n is the length of T i . In Corpus T , K texts are randomly selected, that is obtain a first text. Perform a text editing operation on each text in the first text according to a preset text editing simulation component, obtain a corresponding second text, denoted as It should be noted that the text editing operation is specifically a random simulation of the editing operation on an input text T, and the editing operation includes inserting a word, deleting a word, and replacing a word to obtain a new text T'. The specific text editing simulation algorithm of the text editing simulation component is shown in Table 1:

[0052] Table 1

[0053]

[0054]

[0055] Step S12: Construct a corresponding training sample based on the feature vector of the first text and the feature vector of the second text, and map the training sample to a preset text editing vector space through an initial neural network model to obtain a corresponding first text editing vector; the first text editing vector includes a text editing vector corresponding to the first text and a text editing vector corresponding to the second text.

[0056] In this embodiment, the training sample is constructed based on the feature vector of the first text and the feature vector of the second text. It can be understood that before the above-mentioned construction of the corresponding training sample based on the feature vector of the first text and the feature vector of the second text, it further includes: performing text segmentation processing on the first text and the second text, and obtaining a corresponding word ID; processing each word ID to obtain a corresponding word vector, and obtaining a feature vector corresponding to the first text and a feature vector corresponding to the second text based on the word vector. That is, a text T is converted into a text feature vector F by a preset text feature vector extraction component T , F T ∈ F d , where F d is a text feature vector space with a dimension of d. The specific steps are to first perform text segmentation processing on the first text and the second text, and convert the segmented words into corresponding word IDs, then process the word IDs to obtain a word vector, and integrate the word vector into a text feature vector. The specific text feature vector extraction algorithm of the text feature vector extraction component is shown in Table 2:

[0057] Table 2

[0058]

[0059] Among them, Embed in the above text feature vector extraction algorithm is a word vector layer, which converts word IDs into vector form. Its source can be a randomly initialized word vector, a Word2Vec word vector, and a word vector layer based on a pre-trained language model with a Transformers structure, etc. Layers is a text feature extraction layer, which integrates word vectors into text vectors. Its structure can be a network layer based on CNN, RNN, or Transformer, or a network layer containing only vector addition, vector splicing, and vector averaging operations. Specifically, the text feature vector extraction component is constructed based on the pre-trained ALBERT neural network model on the text dataset. The dictionary (Vocab), tokenizer (Tokenizer), word vector layer (Embedding Layer), and main network layer (Albert Model) provided by the ALBERT model are used to implement the functions of the text feature vector extraction algorithm.

[0060] Then, for each of the first text and the second text , the text feature vector extraction algorithm is used to obtain the feature vector of the first text and the feature vector of the second text, denoted as and respectively. Then, the training sample P is constructed based on the feature vector in and the feature vector in . The pseudo code for constructing the training sample is as follows:

[0061]

[0062]

[0063] P.append((F Ti ,F Tj ))

[0064] Next, the training sample P is input into the initial neural network model, denoted as M, to obtain the corresponding first text editing vector. It should be noted that the main network component M is a neural network, which aims to establish a mapping from the definition domain F d to the value domain F' d' : F d → F' d' , where F d is a d-dimensional text feature space constructed based on the text feature vector extraction algorithm, and F' d ' is a d'-dimensional text editing vector space. The vectors in F' d' have been L2 normalized. The structure of M can be based on CNN, RNN, or Transformer, etc. The network is formulated as follows:

[0065]

[0066] in, For the text feature vector F Ti Given the corresponding text edit vectors, the resulting set P' of the first text edit vectors is: The first text editing vector includes the text editing vector corresponding to the first text and the text editing vector corresponding to the second text.

[0067] Step S13: Calculate the similarity between different text edit vectors in the first text edit vector, and construct a loss function based on the similarity and a preset similarity label; wherein, the preset similarity label includes the edit distance similarity between the first text and the second text.

[0068] In this embodiment, it is necessary to calculate the similarity between different text edit vectors in the first text edit vector, denoted as S'. Based on the similarity S' and the preset similarity label S, a loss function is constructed using a preset loss calculation component. The expression for the loss function is: loss = LossFunction(S, S'). The preset similarity label includes the edit distance similarity between the first text and the second text; that is, the edit distance similarity in the first text is calculated using the preset similarity label calculation component. i Second text T i The edit distance similarity is calculated and used as a similarity label to train the initial neural network model. Let T be the value of T. i =[c1,c2,…c n ], T i '=[c'1,c'2,…c' m ], where c i and c' i Representing a single character, n and m are T i and T i The length of ' is first calculated by T. i and T i The edit distance EditDist is calculated, and then the edit distance similarity EditDistSim is calculated based on EditDist. The specific edit distance similarity calculation algorithm is shown in Table 3.

[0069] Table 3

[0070]

[0071]

[0072] Step S14: training the initial neural network model using the loss function, and then jumping back to the step of obtaining the first text and performing text editing operation on the first text until a preset iteration number is reached to obtain a similarity calculation model.

[0073] In this embodiment, the initial neural network model is trained using the loss function, and in addition, the loss is input into an optimizer Optimizer in a preset optimizer component for gradient back propagation and model parameter optimization: Optimizer(loss). The above step is a batch training, and for the entire text data set Corpus T = {T1, T2, … T N}, the above steps need to be repeated for data traversal and iterative training of the model until a preset iteration number is reached, and finally a similarity calculation model is obtained.

[0074] It can be seen that the first text is obtained and text editing operation is performed on the first text to obtain a second text; a corresponding training sample is constructed based on the feature vector of the first text and the feature vector of the second text, and the training sample is mapped to a preset text editing vector space through an initial neural network model to obtain a corresponding first text editing vector; the first text editing vector includes a text editing vector corresponding to the first text and a text editing vector corresponding to the second text; the similarity between different text editing vectors in the first text editing vector is calculated, and a loss function is constructed based on the similarity and a preset similarity label; wherein the preset similarity label includes an edit distance similarity between the first text and the second text; the initial neural network model is trained using the loss function, and then jumping back to the step of obtaining the first text and performing text editing operation on the first text until a preset iteration number is reached to obtain a similarity calculation model. It can be seen that the first text is edited to obtain a second text, and then the feature vectors of the first text and the second text are extracted to construct a training sample, and the edit distance similarity between the first text and the second text is taken as a preset similarity label, and then the training sample is mapped to a preset text editing vector space through an initial neural network to obtain a first text editing vector, and the similarity between different text editing vectors in the first text editing vector is calculated, and a loss function is constructed based on the similarity and a preset similarity label, and finally the initial neural network model is trained using the loss function, and the above process is repeated to obtain a similarity calculation model. In this way, the edit distance similarity between text feature vectors can be calculated using the similarity calculation model as the edit distance similarity between original texts.

[0075] Referring to Figure 2As shown, the embodiment of the present application discloses a specific similarity calculation model training method. Compared with the previous embodiment, the embodiment further describes and optimizes the technical solution. Specifically, it includes:

[0076] Step S21: Obtain the first text and perform a text editing operation on the first text to obtain the second text.

[0077] Step S22: Based on the feature vector of the first text and the feature vector of the second text, construct a corresponding training sample, and map the training sample to a preset text editing vector space through an initial neural network model to obtain a corresponding first text editing vector; the first text editing vector includes a text editing vector corresponding to the first text and a text editing vector corresponding to the second text.

[0078] Step S23: Calculate the inner product between two text editing vectors in the first text editing vector set to obtain the corresponding similarity, and construct a loss function based on the similarity and a preset similarity label; wherein the preset similarity label includes the edit distance similarity between the first text and the second text.

[0079] In this embodiment, when calculating the similarity between two text editing vectors in the first text editing vector set, the inner product between the two text editing vectors can be calculated using a preset similarity measurement component to obtain the corresponding similarity. For example, for any two text editing vectors in the text editing vector space and The similarity S' between them ij is where · is used to calculate the inner product.

[0080] Step S24: Determine the hyperparameter information and configure the hyperparameter information; wherein the hyperparameter information includes the learning rate, the learning rate reduction strategy, and the iteration number.

[0081] In this embodiment, the appropriate hyperparameter information is determined and configured. The hyperparameter information can include but is not limited to the learning rate (i.e. learning rate), the learning rate reduction strategy, the iteration number, the training round number, etc.

[0082] Step S25: Use the configured hyperparameter information and the loss function to train the initial neural network model, and then jump back to the step of obtaining the first text and performing a text editing operation on the first text until the preset iteration number is reached to obtain a similarity calculation model.

[0083] In this embodiment, the initial neural network model is iteratively trained using the configured hyperparameters and loss function, and the parameters are adjusted to optimize the model based on the training results, resulting in a trained similarity calculation model. It should be noted that the aforementioned loss function can specifically be the mean loss function (MSE loss), and the AdamW optimizer can be used when optimizing the model.

[0084] For more detailed processing procedures of steps S21 and S22, please refer to the relevant content disclosed in the foregoing embodiments, which will not be repeated here.

[0085] As can be seen, in this embodiment of the application, when calculating the similarity between two text edit vectors in the first text edit vector set, the inner product between the two text edit vectors can be calculated to obtain the corresponding similarity. Furthermore, when training the initial neural network model using the loss function, it is also necessary to determine the hyperparameter information used to train the initial neural network model and configure it accordingly. Then, the configured hyperparameter information and the loss function are used to iteratively train the initial neural network model to obtain a higher-performance similarity calculation model.

[0086] The technical solution of this application will be explained below using an open, general-purpose dataset—the Sogou News dataset—as an example.

[0087] For this dataset, the text is segmented using the Chinese period "." as the delimiter, and each segmented sentence is used as the Corpus text dataset. T A text T in Corpus. T Taking two texts randomly as an example, we get the first text. Furthermore, T1 = [Image shows a highlight of this event], T2 = [Image shows a highlight of the competition], based on the text editing simulation algorithm, the first text... Perform text editing operations to obtain the second text. Where T1' = [the highlight moment of this live set], T2' = [the highlight moment of the competition]. Then, T1 and T2 from the first text and T1' and T2' from the second text are converted into text feature vectors. The shape of each text feature vector is consistent with the output shape of the ALBERT model, resulting in... and The training sample P constructed based on the feature vectors of the first text and the feature vectors of the second text is: The preset similarity labels corresponding to the training samples are calculated, for example, for T1 and T1', the calculated edit distance EditDist is 3, the length n of T1 is 11, the length m of T1' is 11, and the edit distance similarity EditDistSim is 0.72. Finally, S = [0.72, 0.27, 0.27, 0.67] is obtained. After the above steps, a batch of samples P and the preset similarity labels S used to construct the loss function are formed. The initial neural network model is then iteratively trained using the loss function to obtain the similarity calculation model.

[0088] Referring to Figure 3 As shown in the drawings, the embodiment of the present application discloses an edit distance similarity calculation method applied to a server, which comprises the following steps:

[0089] Step S31: obtaining the target text feature vector extracted by the client from the target text.

[0090] In the embodiment of the present application, the target text feature vector extracted by the client from the target text is obtained. Since it is the text feature vector instead of the original target text, the user data original text of the client is invisible to the server side, which has higher security. In addition, the above-mentioned edit distance similarity calculation method further comprises: obtaining a template text set, and extracting the feature vector of each template text in the template text set to obtain a corresponding template text feature vector set; mapping the template text feature vector set to a preset text edit vector space through the similarity calculation model to obtain a corresponding template text edit vector set; and constructing a tree-shaped data structure based on the template text edit vector set.

[0091] It can be understood that, in the client, there is a target text T q and a text feature vector extraction component, and in the server side, there is a template text set The text feature vector extraction component, the similarity calculation component, the text feature vector query component, and the trained neural network model M, i.e., the main network component M. In the server side, the text feature vector extraction component is used to convert each template text in A into a text feature vector to obtain a corresponding template text feature vector set F A , The text feature vector in the set F A is mapped to a preset text edit vector space through the network model M in the similarity calculation model to obtain a corresponding template text edit vector set F EA , Furthermore, based on the template text editing vector set, a tree-like data structure capable of efficient retrieval is constructed using a text feature vector query component to provide an efficient vector query mechanism. This tree structure can be a kd-tree (k-dimensional tree) or a ball-tree.

[0092] Further, see Figure 4 As shown, the embodiments of this application are applicable to the following business scenarios: the client has target text and target text feature vector after feature vector extraction of the target text; the server has template text and template text feature vector after feature vector extraction of the template text; the edit distance similarity between the target text and the template text is obtained by using the text feature vectors of the target text and the template text and the trained similarity calculation model.

[0093] Step S32: Map the target text feature vector to a preset text editing vector space using a similarity calculation model to obtain the corresponding target text editing vector; then use the similarity model to query a number of template text editing vectors that are similar to the target text editing vector; wherein the similarity calculation model is a model trained using the aforementioned publicly disclosed similarity calculation model training method.

[0094] In this embodiment, the server obtains the target text feature vector. Then, the target text feature vector is mapped to a preset text editing vector space through the network model M in the similarity calculation model to obtain the corresponding target text editing vector. Then, a similarity model is used to query and match the edit vector of the target text. The process involves retrieving a number of similar template text edit vectors from the tree data structure using the similarity model. Specifically, this can be achieved by querying a number of template text edit vectors that are similar to the target text edit vector from the tree data structure. In other words, it involves querying based on the tree data structure... We obtain a subset of template text edit vectors from the k closest template text edit vectors.

[0095] Step S33: Bind the target text edit vector to each of the template text edit vectors to construct several sets of second text edit vectors, and use the similarity calculation model to calculate the target similarity between different text edit vectors in each set of second text edit vectors, so as to determine the target similarity as the edit distance similarity between the target text and the template text corresponding to each of the template text edit vectors.

[0096] In this embodiment, the target text edit vector is bound to each template text edit vector in the subset of template text edit vectors to construct several groups of second text edit vectors, i.e., each element in the target text edit vector is combined with each element in the template text edit vector to form a second text edit vector. and Then, the similarity calculation model is used to calculate the target similarity between different text edit vectors in each group of second text edit vectors, specifically, each group of is input into the similarity calculation component to obtain a target similarity set S' = {S1, S2, …, Sk}. Then, the target similarity S' is determined as the edit distance similarity between the target text and the template text corresponding to each template text edit vector. The corresponding template is the k closest matches, and the target text T q has an edit distance similarity S' with the template text in . That is, the target similarity is determined as the edit distance similarity between the target text and the template text corresponding to each template text edit vector.

[0097] As can be seen, in the embodiments of the present application, the target text feature vector extracted by the client from the target text is obtained, the target text feature vector is mapped to a preset text edit vector space by a similarity calculation model to obtain a corresponding target text edit vector, and then a number of template text edit vectors similar to the target text edit vector are queried by using the similarity model, wherein the similarity calculation model is a model trained by using the similarity calculation model training method disclosed above. The target text edit vector is bound to each template text edit vector to construct several groups of second text edit vectors, and the target similarity between different text edit vectors in each group of second text edit vectors is calculated by using the similarity calculation model, so as to determine the target similarity as the edit distance similarity between the target text and the template text corresponding to each template text edit vector. As can be seen, in the embodiments of the present application, the text feature vector of the target text is obtained at the user end, the text feature vector of the template text is obtained at the server end, the text feature vector of the target text is transmitted to the server end, and the edit distance similarity between the target text and the template text is obtained by using the text feature vectors of the target text and the template text and the trained similarity calculation model.

[0098] Referring to Figure 5 ​As shown, the embodiment of the present application discloses a specific system component schematic diagram, and the embodiment of the present application mainly includes three parts, which are a data preprocessing part, a neural network model part and a text feature vector query part. Among them, the data preprocessing part includes a text editing simulation component, a text feature vector extraction component and a similarity label calculation component; the neural network model part includes a main network component M, a similarity calculation component, a loss calculation component and an optimizer component; the text feature vector query part includes a text feature vector query component. The specific use of each component and module can refer to the corresponding content disclosed in the foregoing embodiments, and will not be described here.

[0099] Referring to Figure 6 As shown, the embodiment of the present application discloses a similarity calculation model training device, which comprises:

[0100] The text acquisition module 11 is configured to acquire a first text and perform a text editing operation on the first text to obtain a second text.

[0101] The vector mapping module 12 is configured to construct a corresponding training sample based on a feature vector of the first text and a feature vector of the second text, and map the training sample to a preset text editing vector space through an initial neural network model to obtain a corresponding first text editing vector; the first text editing vector includes a text editing vector corresponding to the first text and a text editing vector corresponding to the second text.

[0102] The loss function construction module 13 is configured to calculate the similarity between different text editing vectors in the first text editing vector, and construct a loss function based on the similarity and a preset similarity label; wherein the preset similarity label includes an edit distance similarity between the first text and the second text.

[0103] The model training module 14 is configured to train the initial neural network model using the loss function, and then jump back to the step of acquiring the first text and performing the text editing operation on the first text until a preset iteration number is reached to obtain a similarity calculation model.

[0104] As can be seen, this application obtains a first text and performs text editing operations on the first text to obtain a second text; constructs corresponding training samples based on the feature vectors of the first text and the second text, and maps the training samples to a preset text editing vector space through an initial neural network model to obtain a corresponding first text editing vector; the first text editing vector includes a text editing vector corresponding to the first text and a text editing vector corresponding to the second text; calculates the similarity between different text editing vectors in the first text editing vector, and constructs a loss function based on the similarity and a preset similarity label; wherein, the preset similarity label includes the edit distance similarity between the first text and the second text; trains the initial neural network model using the loss function, and then jumps back to the step of obtaining the first text and performing text editing operations on the first text until a preset number of iterations is reached to obtain a similarity calculation model. Therefore, this application performs text editing operations on the first text to obtain the second text, then extracts the feature vectors of the first and second texts to construct training samples, and uses the edit distance similarity between the first and second texts as a preset similarity label. Next, an initial neural network maps the training samples to a preset text edit vector space to obtain the first text edit vector. Then, the similarity between different text edit vectors in the first text edit vector is calculated. Based on this similarity and the preset similarity label, a loss function is constructed. Finally, the initial neural network model is trained using the loss function, and the above process is repeated continuously to obtain a similarity calculation model. In this way, the edit distance similarity between text feature vectors can be calculated using this similarity calculation model, which can then be used as the edit distance similarity between the original texts.

[0105] Figure 7 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Specifically, it may include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 stores a computer program, which is loaded and executed by the processor 21 to implement the relevant steps in the similarity calculation model training method performed by the electronic device as disclosed in any of the foregoing embodiments.

[0106] In this embodiment, the power supply 23 is used to provide operating voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and external devices, and the communication protocol it follows can be any communication protocol applicable to the technical solution of this application, and is not specifically limited here; the input / output interface 25 is used to acquire external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs, and is not specifically limited here.

[0107] The processor 21 can include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 21 can be implemented in at least one of a hardware form of a DSP (Digital Signal Processing), an FPGA (Field-Programmable Gate Array), a PLA (Programmable Logic Array). The processor 21 can also include a main processor and a coprocessor. The main processor is a processor for processing data in a wake-up state, also known as a CPU (Central Processing Unit). The coprocessor is a low-power processor for processing data in a standby state. In some embodiments, the processor 21 can be integrated with a GPU (Graphics Processing Unit) that is responsible for rendering and drawing the content required to be displayed on the display screen. In some embodiments, the processor 21 can further include an AI (Artificial Intelligence) processor for processing machine learning-related computing operations.

[0108] In addition, the memory 22, as a carrier for storing resources, can be a read-only memory, a random access memory, a magnetic disk or an optical disk, etc. The resources stored thereon include an operating system 221, a computer program 222, and data 223, etc. The storage mode can be temporary storage or permanent storage.

[0109] The operating system 221 is used to manage and control each hardware device on the electronic device 20 and the computer program 222, so as to realize the operation and processing of the processor 21 on the mass data 223 in the memory 22. It can be Windows, Unix, Linux, etc. In addition to including the computer program capable of completing the similarity calculation model training method executed by the electronic device 20 disclosed in any of the preceding embodiments, the computer program 222 can further include a computer program capable of completing other specific work. The data 223 can include data received by the electronic device from an external device, as well as data collected by the self input / output interface 25, etc.

[0110] Further, the embodiments of the present application also disclose a computer readable storage medium, the storage medium stores a computer program, and the computer program is loaded and executed by the processor to realize the method steps executed in the similarity calculation model training process disclosed in any of the preceding embodiments.

[0111] The various embodiments described in this specification are presented by way of example, and each embodiment is not necessarily composed of all features described with respect to other embodiments. Each embodiment described in this specification can be implemented in software, firmware, hardware, or any combination thereof. The various embodiments described in this specification can be implemented in any combination of the following technologies: software defined radio, code division multiple access (CDMA) networks, time division multiple access (TDMA) networks, frequency division multiple access (FDMA) networks, orthogonal frequency division multiplexing (OFDM) networks, orthogonal frequency division multiple access (OFDMA) networks, global system for mobile communications (GSM) networks, 3rd Generation (3G) networks, 4th Generation (4G) networks, and draft 5th Generation (5G) networks.

[0112] Those skilled in the art will further appreciate that the units and algorithms described in connection with the examples disclosed herein can be implemented in electronic hardware, computer software, or any combination thereof. To clearly illustrate this interchangeability of hardware and software, various examples disclosed herein have been described in general terms that are applicable to both hardware and software implementations.

[0113] Instructions for the operating system, applications, and / or programs can be located in storage media in a computer readable storage medium device. Furthermore, the instructions can be downloaded over the network for execution by the machine. Thus, a machine can include a processor, a storage medium, for example, a computer readable storage medium device, and a computer program product, for example, a computer program embedded on a computer readable storage medium device.

[0114] Finally, it should be noted that the terms "comprises", "comprising", or other variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but can include other elements not expressly listed or inherent to such process, method, article, or apparatus. An element proceeded by "comprises... a" does not, without more constraints, exclude the presence of additional identical elements in the process, method, article, or apparatus that comprises the element. In other words, a process, method, article, or apparatus that comprises at least one element does not exclude the presence of additional identical elements in the process, method, article, or apparatus.

[0115] The model training method, the similarity calculation method, the device, the equipment and the storage medium provided by the application are described in detail above, the principle and the implementation mode of the application are described in this paper, and the above example is only used to help understand the method and the core idea of the application; at the same time, for the general technical personnel in the art, according to the idea of the application, the specific implementation mode and the application range will be changed, and the above description should not be understood as the limitation of the application.

Claims

1. A method for training a similarity calculation model, characterized in that, The application comprises the following steps: obtaining a first text and performing a text editing operation on the first text to obtain a second text; constructing a corresponding training sample based on a feature vector of the first text and a feature vector of the second text, and mapping the training sample to a preset text editing vector space through an initial neural network model to obtain a corresponding first text editing vector; the first text editing vector includes a text editing vector corresponding to the first text and a text editing vector corresponding to the second text, and an edit distance similarity is calculated based on an edit distance between the first text and the second text, a text length of the first text, and a text length of the second text; calculating the similarity between different text editing vectors in the first text editing vector, and constructing a loss function based on the similarity and a preset similarity label; wherein the preset similarity label includes an edit distance similarity between the first text and the second text; training the initial neural network model using the loss function, and then jumping back to the step of obtaining the first text and performing a text editing operation on the first text until a preset iteration number is reached to obtain a similarity calculation model; wherein performing a text editing operation on the first text to obtain a second text comprises: performing an editing operation of inserting, deleting, or replacing characters on the first text to obtain a second text. 2.The similarity calculation model training method of claim 1, wherein, The calculation of the similarity between different text editing vectors in the first text editing vector comprises: calculating the inner product between two text editing vectors in the first text editing vector set to obtain the corresponding similarity. 3.The similarity calculation model training method of claim 1, wherein, Before constructing a corresponding training sample based on the feature vector of the first text and the feature vector of the second text, the method further comprises: performing text segmentation processing on the first text and the second text, and obtaining corresponding word IDs; processing each word ID to obtain a corresponding word vector, and obtaining a feature vector corresponding to the first text and a feature vector corresponding to the second text based on the word vector. 4.The method of any one of claims 1-3, wherein, The training of the initial neural network model using the loss function comprises: determining hyperparameter information and configuring the hyperparameter information; wherein the hyperparameter information includes a learning rate, a learning rate reduction strategy, and an iteration number; training the initial neural network model using the configured hyperparameter information and the loss function.

5. An edit distance similarity computation method characterized by, The application is applied to a server and comprises the following steps: obtaining a target text feature vector extracted from a target text by a client; mapping the target text feature vector to a preset text editing vector space through a similarity calculation model to obtain a corresponding target text editing vector, and then querying a number of template text editing vectors similar to the target text editing vector using the similarity model; wherein the similarity calculation model is a model trained using the similarity calculation model training method of any one of claims 1 to 4. The target text edit vector is bound to each of the template text edit vectors respectively to construct a plurality of groups of second text edit vectors, and a target similarity between different text edit vectors in each of the groups of second text edit vectors is calculated by using the similarity calculation model, so as to determine the target similarity as an edit distance similarity between the target text and a template text corresponding to each of the template text edit vectors.

6. The edit distance similarity computation method of claim 5, wherein, Further comprising: obtaining a set of template texts, and extracting a feature vector of each template text in the set of template texts to obtain a corresponding set of template text feature vectors; mapping the set of template text feature vectors to a preset text edit vector space by using the similarity calculation model to obtain a corresponding set of template text edit vectors; constructing a tree data structure based on the set of template text edit vectors.

7. The edit distance similarity computation method of claim 6, wherein, The step of querying a plurality of template text edit vectors similar to the target text edit vector by using the similarity model includes: querying a plurality of template text edit vectors similar to the target text edit vector from the tree data structure by using the similarity model. 8.A similarity calculation model training apparatus, comprising: Comprising: a text obtaining module configured to obtain a first text and perform a text edit operation on the first text to obtain a second text; a vector mapping module configured to construct a corresponding training sample based on a feature vector of the first text and a feature vector of the second text, and map the training sample to a preset text edit vector space by using an initial neural network model to obtain a corresponding first text edit vector; the first text edit vector includes a text edit vector corresponding to the first text and a text edit vector corresponding to the second text, and an edit distance similarity is calculated based on an edit distance between the first text and the second text, a text length of the first text, and a text length of the second text; a loss function constructing module configured to calculate a similarity between different text edit vectors in the first text edit vector, and construct a loss function based on the similarity and a preset similarity label; wherein the preset similarity label includes the edit distance similarity between the first text and the second text; a model training module configured to train the initial neural network model by using the loss function, and then jump back to the step of obtaining the first text and performing the text edit operation on the first text until a preset number of iterations is reached to obtain a similarity calculation model; wherein performing the text edit operation on the first text to obtain the second text includes: performing an edit operation of inserting, deleting, or replacing characters on the first text to obtain the second text.

9. An electronic device, comprising: Comprising: a memory configured to save a computer program; a processor configured to execute the computer program to implement the steps of the similarity calculation model training method according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that, a memory configured to save a computer program; wherein the computer program is executed by a processor to implement the steps of the similarity calculation model training method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Text matching method and device, equipment, medium and computer program product

    CN114281931A