Text similarity recognition method, device and electronic device
Through the combination of feature encoding and semantic signature, the problem in the existing technology that semantic signature cannot guarantee the similarity of similar sentence tags is solved, and the similarity effect of text similarity recognition is improved.
Patent Information
- Application Number
- CN201910425307.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-05-21
- Publication Date
- 2024-10-22
- Estimated Expiration
- 2039-05-21
AI Technical Summary
In text similarity analysis in the existing technology, it is difficult to ensure the similarity of semantic tags generated for similar sentences through semantic signatures, resulting in poor similarity results for similar sentences.
The pre-learned feature encoder is used to encode the sentence vector to generate a sentence feature vector, and a semantic signature is generated based on the positive and negative features of the sentence feature vector, and an inverted index from the semantic signature to the sentence is constructed to determine similar sentences.
Through the combination of feature encoding and semantic signature, it is ensured that semantically similar sentences generate similar sentence feature vectors and semantic signatures, thereby improving the similarity effect between similar sentences.
Smart Images

Figure CN112069790B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computers, and in particular to a text similarity recognition method, device and electronic equipment. Background Art
[0002] A good machine learning algorithm usually relies on a large amount of high-quality labeled training data. Obtaining this high-quality labeled data has always been a labor-intensive problem in the field of machine learning. For massive amounts of text data, it would be extremely time-consuming and laborious for business personnel to directly label it.
[0003] In the prior art, similar text data is generally labeled in batches by analyzing the similarity between texts, thereby improving the efficiency of obtaining labeled data. The following methods are mainly used for similarity analysis of massive texts:
[0004] First, for each sentence vector in a given sentence set, the sentence vector is converted into a 0 / 1 digital semantic signature with a fixed dimension according to the numerical positive or negative value of its dimension; then, based on the index of the semantic signature, it is preliminarily determined that the sentences indexed by the same semantic signature (or semantic signature fragment) constitute a candidate similar sentence group, and then the similar sentences corresponding to each sentence in each candidate similar sentence group are determined respectively.
[0005] In the above process, the role of semantic signature is to decompose the process of finding similar sentences from the above sentence set into finding similar sentences of each sentence in each candidate similar sentence group, so as to reduce the complexity of similarity calculation. However, this method cannot guarantee that the semantic signatures obtained by actually similar sentences are also relatively similar when forming semantic signatures, thus affecting the similarity effect of the similar sentences finally determined. Summary of the invention
[0006] The present invention provides a text similarity recognition method, device and electronic equipment, which can effectively improve the similarity effect between recognized similar sentences.
[0007] To achieve the above object, the embodiments of the present invention adopt the following technical solutions:
[0008] In a first aspect, a text similarity recognition method is provided, comprising:
[0009] Get the sentence vector corresponding to each sentence in the given sentence set;
[0010] Encoding each of the sentence vectors using a feature encoder obtained by pre-learning to generate a corresponding sentence feature vector; wherein the sentence feature vector includes a plurality of vector segments, and the feature encoder is used to make the sentence feature vectors generated by the semantically similar sentence vectors correspond to each other in each vector segment, and vice versa;
[0011] Based on the positive and negative features of each dimension value in the sentence feature vector, a semantic signature of the corresponding sentence is generated, and an inverted index from the semantic signature to the corresponding sentence is constructed;
[0012] According to the inverted index of each semantic signature, a similar sentence corresponding to each sentence in the sentence set is determined.
[0013] In a second aspect, a text similarity recognition device is provided, comprising:
[0014] A sentence vector acquisition module is used to obtain the sentence vector corresponding to each sentence in a given sentence set;
[0015] A sentence vector encoding module, used to encode each of the sentence vectors using a feature encoder obtained by pre-learning to generate a corresponding sentence feature vector; wherein the sentence feature vector includes a plurality of vector segments, and the feature encoder is used to make the sentence feature vectors generated by the semantically similar sentence vectors correspond to each vector segment similar, and vice versa;
[0016] A signature index building module, used to generate a semantic signature of the corresponding sentence based on the positive and negative features of each dimension value in the sentence feature vector, and to build an inverted index from the semantic signature to the corresponding sentence;
[0017] The similar sentence determination module is used to determine the similar sentence corresponding to each sentence in the sentence set according to the inverted index of each semantic signature.
[0018] In a third aspect, a text vectorization processing method is provided, comprising:
[0019] Perform word vector conversion on the sentence to be processed to obtain the word vector matrix corresponding to the sentence;
[0020] Processing the word vector matrix through the model algorithm in the attention model to obtain a sentence vector corresponding to the sentence;
[0021] The attention model includes a global context vector and a domain context vector of at least one domain, and the model algorithm is formed based on the global context vector or one of the domain context vectors.
[0022] In a fourth aspect, a text vectorization processing device is provided, comprising:
[0023] The word vector acquisition module is used to convert the word vector of the sentence to be processed and obtain the word vector matrix corresponding to the sentence;
[0024] A sentence vector acquisition module is used to process the word vector matrix through the model algorithm in the attention model to obtain the sentence vector corresponding to the sentence;
[0025] The attention model includes a global context vector and a domain context vector of at least one domain, and the model algorithm is formed based on the global context vector or one of the domain context vectors.
[0026] In a fifth aspect, an electronic device is provided, including:
[0027] Memory, used to store programs;
[0028] The processor is coupled to the memory and is used to execute the program. When the program is running, the text similarity recognition method provided by the present invention is executed.
[0029] In a sixth aspect, an electronic device is provided, including:
[0030] Memory, used to store programs;
[0031] A processor is coupled to the memory and is used to execute the program. When the program is running, the text vectorization processing method provided by the present invention is executed.
[0032] The present invention provides a text similarity recognition method, device and electronic device. By performing feature encoding on the sentence vectors of each sentence in a given sentence set, sentence feature vectors generated by semantically similar sentence vectors are similar in correspondence on each vector segment, and vice versa. When generating the semantic signature of the sentence based on the positive and negative features of each dimension value in the sentence feature vector, since the segmental similarity of the semantically similar sentence feature vectors, the semantic signature generated by the semantically similar sentence feature vectors can also achieve segmental similarity as much as possible, and then achieve overall similarity. When constructing the inverted index of the semantic signature to the corresponding sentence, since the semantic signatures corresponding to the semantically similar sentences are also similar, when determining the similar sentences corresponding to each sentence in the sentence set according to the inverted index of each semantic signature, the similarity between the determined similar sentences can be effectively guaranteed.
[0033] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0034] Various other advantages and benefits will become apparent to those of ordinary skill in the art by reading the detailed description of the preferred embodiments below. The accompanying drawings are only for the purpose of illustrating the preferred embodiments and are not to be considered as limiting the present application. Also, the same reference symbols are used throughout the accompanying drawings to represent the same components. In the accompanying drawings:
[0035] Figure 1 A schematic diagram of a training model according to an embodiment of the present invention;
[0036] Figure 2 Schematic diagram of a loss function model according to an embodiment of the present invention;
[0037] Figure 3 A flow chart of a text similarity recognition method according to an embodiment of the present invention;
[0038] Figure 4 Flowchart of the method for generating sentence vectors;
[0039] Figure 5 The text similarity recognition device structure of the embodiment of the present invention is Figure 1 ;
[0040] Figure 6 The text similarity recognition device structure of the embodiment of the present invention is Figure 2 ;
[0041] Figure 7 The structure of the electronic device according to the embodiment of the present invention is shown in FIG. Figure 1 ;
[0042] Figure 8 A flowchart of a text vectorization processing method according to an embodiment of the present invention;
[0043] Fig. 9 The text vectorization processing device structure of the embodiment of the present invention is Figure 1 ;
[0044] Fig.10 The text vectorization processing device structure of the embodiment of the present invention is Figure 2 ;
[0045] Fig.11 The structure of the electronic device according to the embodiment of the present invention is shown in FIG. Figure 2 . DETAILED DESCRIPTION
[0046] The exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided to enable a more thorough understanding of the present disclosure and to fully convey the scope of the present disclosure to those skilled in the art.
[0047] The embodiments of the present invention improve the defect in the prior art that, when determining the similarity of sentences through semantic tags, the existing hash function cannot guarantee that the semantic tags generated by the semantically similar sentence vectors are also similar, thus making it difficult to guarantee the similarity effect of similar sentences determined after inverted indexing through the semantic tags. The core idea is that, in the process of forming semantic tags based on sentence vectors, the sentence vectors are firstly re-encoded through a feature encoder to generate corresponding sentence feature vectors. The feature encoder can be obtained through learning, and can make the sentence feature vectors generated by the semantically similar sentence vectors correspond to each feature vector segment similar, and vice versa. In this way, when generating the semantic signature of the corresponding sentence based on the positive and negative features of each dimensional value in the sentence feature vector, the semantic signatures corresponding to the semantically similar sentence feature vectors are also relatively similar in the corresponding vector segments. By constructing an inverted index from the semantic signature to the corresponding sentence, the sentences indexed by the similar semantic signatures are also relatively similar, so that the similarity between the similar sentences determined according to the inverted index of each semantic signature can be better guaranteed.
[0048] When training the feature encoder, this solution can integrate the feature encoder (hereinafter referred to as "fc") and the existing semantic signature algorithm into an overall hash function model for training. By training fc, the sentence vector is converted into a sentence feature vector through fc encoding, and the sentence feature vector is then passed through the existing hash function to obtain the semantic signature with the following specific characteristics: semantically similar sentence vectors have similar corresponding semantic signatures.
[0049] Among them, the hash function model structure is as follows:
[0050] hash(x)=sgn(fc(x)), where
[0051] Among them, fc is used as the fully connected layer.
[0052] Loss function: Construct a sentence triple (q1, q2, q3), where: q1 and q2 are semantically similar; q1 and q3 are semantically dissimilar. After the sentence triple is passed through the sentence encoder to obtain the sentence vector, it is calculated through fc to obtain the corresponding sentence feature vector (x1, x2, x3); xi is a D-dimensional vector, and now xi is divided into B segments, each of which contains a D / B-dimensional vector, recorded as:
[0053] xij(i=1,2,3;j=1,2,...,B). The loss function calculation process is as follows:
[0054] Segment loss:
[0055] segment_loss(j)=-log(exp(x[1][j]*x[2][j]) / (exp(x[1][j]*x[2][j])+(exp(x[1][j]*x[3][j])))
[0056] Hash loss:
[0057]
[0058] The hash function model adds the following two key pieces of information to the loss function:
[0059] After the hash function is binarized (forming a 0 / 1 digital semantic signature), the semantic signature segments corresponding to similar sentences are similar, and the semantic signature segments corresponding to dissimilar sentences are dissimilar;
[0060] After the hash function is binarized (forming a 0 / 1 digital semantic signature), the original distance information of the sentence vector is maintained (i.e., two similar values are avoided as much as possible, one is binarized as 1 and the other is binarized as 0).
[0061] Referring to the loss function formula of the hash function, the segmented classification ensures the first point: the semantic signatures corresponding to similar sentences are segmentally similar, and the semantic signatures corresponding to dissimilar sentences are segmentally dissimilar; the segmented classification uses the form of dot product (*), which ensures the second point that the sentence vector still maintains the original distance information of the sentence vector after being binarized by the hash function.
[0062] In addition, when obtaining sentence vectors, this solution can also use machine learning methods to obtain a sentence encoder, which can make the corresponding sentence vectors of semantically similar sentences relatively similar.
[0063] Figure 1 It is a joint training model of sentence encoder and hash function model.
[0064] Learning process for sentence encoder:
[0065] like Figure 1 In the training data, there are massive text data from various industries. Each industry has multiple application scenarios, and each scenario corresponds to a set of sentences. The learning process of the sentence encoder is to use these labeled text data to learn the vector representation of sentences so that the sentence vectors corresponding to semantically similar sentences are also similar.
[0066] Data preprocessing: Group by industry and convert the text data of each industry into a set of triples of sentences. For example, (q1, q2, q3); q1, q2 and q3 are all sentences from the same industry, q1 and q2 are sentences from the same scenario, and q1 and q3 are sentences from different scenarios.
[0067] Model structure: The model mainly consists of two parts: sentence vector extraction and sentence similarity loss function. The input sentence (each sentence contains multiple words wi, i-1, 2..., n) is passed through a bidirectional LSTM (Long Short-Term Memory) network to obtain a word vector matrix; then the attention layer (algorithm) formed by the independent context vector (ui, i = 1, 2, ..., n) of the corresponding industry (field) is processed by the context-attention mechanism to obtain the final vector representation, that is, the sentence vector. The model that converts sentences into sentence vectors is called a sentence encoder, and the function is expressed as f(x). The sentence similarity loss function is calculated by industry classification.
[0068] Sentence similarity loss:
[0069]
[0070] Model training process: The same model is used for data from multiple industries. Different industries have their own independent domain context vectors. In addition to the independent context vectors for each industry, the model also includes a global context vector. For each training batch, the independent domain context vectors for each industry can be used for training once, and then the global context vector can be used for training once.
[0071] Figure 1 In this paper, multi-task learning is adopted to learn the sentence encoder through sentence similarity, and the fc function in the hash function model is learned through hash similarity.
[0072] In addition, if Figure 2 As shown, when calculating the model loss function of the sentence encoder, the sentence encoder can be comprehensively optimized and trained by combining the sentence similarity loss function based on the sentence vector obtained by processing the model of the sentence encoder and the hash similarity loss function based on the sentence feature vector obtained by the feature encoder fc.
[0073] Model prediction process: First determine the industry type of the sentence to be processed. Then, for sentences in industries that already exist in the model, select the industry-independent domain context vector to perform attention mechanism processing to obtain the sentence vector representation. For sentences in new industries, select the global context vector to perform attention mechanism processing to obtain the sentence vector representation.
[0074] In this scheme, by training the hash function model, after the hash function is calculated based on the sentence vector, the corresponding binary vectors (semantic signatures) of semantically similar sentence vectors are segmentally similar, so that the similarity effect of determining the similar sentences corresponding to each sentence based on the inverted index of each semantic signature is guaranteed, and no additional interference is made to the process of generating sentence vectors.
[0075] Furthermore, in order to further ensure the similar effect of similar sentences obtained in the end, this solution also proposes that the sentence encoder that generates sentence vectors can also be obtained through learning, and the sentence encoder generated by learning can make the sentence vectors generated by semantically similar sentences also relatively similar. In the model of constructing the sentence encoder, the global context vector and the domain context vectors of different industries are introduced to realize the construction of the attention model. Based on these context vectors, it is possible to complete the process of realizing sentence vectorization for texts in different fields by building an attention model.
[0076] The technical solution of the present application is further illustrated below through multiple embodiments.
[0077] Embodiment 1
[0078] Figure 3 The flowchart of the text similarity recognition method provided by the embodiment of the present invention includes the following steps:
[0079] S310, obtaining a sentence vector corresponding to each sentence in a given sentence set.
[0080] Get the set of sentences to be processed, remove meaningless symbols and punctuation marks, normalize numbers and URL links, and remove duplicates; segment each sentence, and pass the segmented words through the sentence encoder to form a sentence vector for each sentence.
[0081] In principle, this scheme does not limit the encoding principle of the sentence encoder, but in order to further ensure the similar effect of the similar sentences finally determined, this scheme preferably Figure 1 The model structure of the encoder shown in is used to calculate the sentence vector, specifically including Figure 4 The processing process shown.
[0082] S410, processing each sentence in the given sentence set through LSTM to obtain a word vector matrix corresponding to the sentence.
[0083] For example, you can first obtain the vector of each word in the sentence (the word vector can be pre-trained through technologies such as WordVec or FastText); then pass the word vector through the LSTM network to obtain the word vector matrix of each sentence.
[0084] However, for new industry data, there may be a large number of industry words, which are likely not in the preset vocabulary, and there are a large number of out-of-vocabulary (OOV) cases, which affects the expression of sentence vectors. This solution can use word-level input to effectively solve the OOV problem and word frequency imbalance problem.
[0085] S420, processing the word vector matrix through the model algorithm in the attention model to obtain a sentence vector corresponding to the sentence; wherein the attention model includes a global context vector and a domain context vector of at least one domain, and the model algorithm is formed based on the global context vector or a domain context vector.
[0086] For example, a context vector can be first determined from the global context vector or the domain context vector according to the industry field to which the sentence to be processed belongs, and a model algorithm in the attention model is formed based on the context vector.
[0087] The independent domain context vector of each industry (domain) includes: the attention weight setting information of each target word in the sentence of the corresponding domain. The global context vector includes: the attention weight setting information of each target word in the sentence of the unknown domain.
[0088] In actual application scenarios, the amount of data in different industries varies greatly, and some industries only have a few thousand labeled data. Therefore, if a model is trained separately for each industry, the model effect of some industries with small existing data will be poor. In this solution, multiple industry data are learned with one model, and the domain context vector and global context vector are set for each industry to introduce the attention mechanism, which can effectively transfer the information of other industries to the target industry.
[0089] Correspondingly, the processing process of the above-mentioned model formation algorithm can be specifically as follows: first determine whether the attention model contains the domain context vector corresponding to the domain to which the current sentence to be processed belongs; if so, select the corresponding domain context vector to form the model algorithm; if not, select the global context vector to form the model algorithm.
[0090] Then, the word vector matrix is processed with the model algorithm formed by the independent domain context vector or the global context vector based on the industry (field) to which the sentence belongs, and the final vector representation, namely the sentence vector, is obtained.
[0091] S320, encode each sentence vector using a pre-learned feature encoder to generate a corresponding sentence feature vector; wherein the sentence feature vector includes multiple vector segments, and the feature encoder is used to make the sentence feature vectors generated by semantically similar sentence vectors correspond to each vector segment similar, otherwise they are not similar.
[0092] Among them, the model structure of the feature encoder in this scheme is not limited, and can be represented by a function fc, such as a hash encoder based on a hash algorithm, which can reduce the dimension of the encoded vector to better meet the requirements of the data to be processed in the subsequent vector calculation. After the sentence vector is fc encoded, a sentence feature vector of a specified dimension can be formed. These sentence feature vectors satisfy: the sentence feature vectors generated by semantically similar sentence vectors are similar in correspondence on each vector segment, and vice versa. In this way, by ensuring overall similarity through segmented similarity, in step S330, when generating a semantic signature based on the dimensional values of the sentence feature vector, the semantic signatures generated by the semantically similar sentence feature vectors are also similar in the corresponding vector segments.
[0093] S330, based on the positive and negative features of each dimension value in the sentence feature vector, generate a semantic signature of the corresponding sentence, and construct an inverted index from the semantic signature to the corresponding sentence.
[0094] For the sentence feature vector corresponding to each sentence in a given sentence set, the sentence vector can be converted into a semantic signature of a fixed dimension of 0 / 1 numbers according to the positive or negative value of the dimension. For example, dimension values greater than or equal to 0 are converted to 1, and those less than 0 are converted to 0, thereby forming a semantic signature. For example, the sentence feature vector is (3, 5, -4, -2, 1, 6), and its corresponding semantic signature is (1, 1, 0, 0, 1, 1). Then, an inverted index of the semantic signature to the corresponding sentence is constructed.
[0095] When constructing a semantic signature index, the semantic signature can be segmented according to the segmentation standard of the sentence feature vector, and an inverted index of each semantic signature segment to the corresponding sentence can be constructed. This can increase the size of the sentence set indexed by the same semantic signature segment, thereby increasing the possibility of finding similar sentences later.
[0096] S340, determining similar sentences corresponding to each sentence in the sentence set according to the inverted index of each semantic signature.
[0097] For example, based on the similarity between semantic signatures, sentences indexed by similar semantic signatures may be formed into similar sentence groups, and in each similar sentence group, a similar sentence corresponding to each sentence may be determined.
[0098] For another example, based on the segmentation of the semantic signature in step S330, sentences with the same vector segment index on the corresponding vector segment may be formed into similar sentence groups, and in each similar sentence group, similar sentences corresponding to each sentence are determined. That is, according to a given semantic signature segment and a sentence set indexed therein, for each sentence in the sentence set, a corresponding similar sentence is selected from the remaining sentences in the sentence set.
[0099] Furthermore, when selecting similar sentences of each sentence in a sentence set indexed by semantic signatures, the cosine value of the sentence vector corresponding to each sentence in the sentence set and each remaining sentence can be calculated, and the corresponding similar sentences can be selected from the remaining sentences according to the cosine value. For example, the top-K remaining sentences with the smallest cosine value are selected as the similar sentences of the current sentence.
[0100] The text similarity recognition method provided by the present invention performs feature encoding on the sentence vectors of each sentence in a given sentence set, so that the sentence feature vectors generated by the semantically similar sentence vectors are similar in correspondence on each vector segment, and vice versa; when generating the semantic signature of the sentence based on the positive and negative features of each dimension value in the sentence feature vector, since the semantically similar sentence feature vectors are segmentally similar, the semantic signatures generated by the semantically similar sentence feature vectors can also achieve segmental similarity as much as possible, and then achieve overall similarity; when constructing the inverted index of the semantic signature to the corresponding sentence, since the semantic signatures corresponding to the semantically similar sentences are also similar, when determining the similar sentences corresponding to each sentence in the sentence set according to the inverted index of each semantic signature, the similarity between the determined similar sentences can be effectively guaranteed.
[0101] Furthermore, when obtaining the sentence vector corresponding to each sentence in a given sentence set, this solution adopts a sentence vectorization model that combines LSTM and an attention model, and introduces a global context vector and a domain context vector into the attention model to ensure that the sentence vectors generated by semantically similar sentences are as similar as possible, thereby assisting in the subsequent formation of sentence feature vectors to better achieve the consistency between semantic similarity and sentence feature vector similarity.
[0102] Embodiment 2
[0103] like Figure 5 As shown in FIG. 1 , a structural diagram of a text similarity recognition device according to an embodiment of the present invention can be controlled to execute the following steps: Figure 3 The method steps shown in , which include:
[0104] A sentence vector acquisition module 510 is used to acquire a sentence vector corresponding to each sentence in a given sentence set;
[0105] The sentence vector encoding module 520 is used to encode each sentence vector using a feature encoder obtained by pre-learning to generate a corresponding sentence feature vector; wherein the sentence feature vector includes multiple vector segments, and the feature encoder is used to make the sentence feature vectors generated by the semantically similar sentence vectors correspond to each vector segment, and vice versa;
[0106] The signature index building module 530 is used to generate a semantic signature of the corresponding sentence based on the positive and negative features of each dimension value in the sentence feature vector, and to build an inverted index from the semantic signature to the corresponding sentence;
[0107] The similar sentence determination module 540 is used to determine the similar sentence corresponding to each sentence in the sentence set according to the inverted index of each semantic signature.
[0108] Furthermore, the signature index building module 530 can be used to segment the semantic signature according to the segmentation standard of the sentence feature vector, and build an inverted index from each semantic signature segment to the corresponding sentence.
[0109] Furthermore, the similar sentence determination module 540 may be used to select a corresponding similar sentence from the remaining sentences in the sentence set for each sentence in the sentence set according to a given semantic signature fragment and a sentence set indexed therein.
[0110] Furthermore, the similar sentence determination module 540 can be used to calculate the cosine value of the sentence vector corresponding to each sentence in the sentence set and each remaining sentence, and select the corresponding similar sentence from the remaining sentences according to the cosine value.
[0111] Furthermore, if Figure 6 As shown, in Figure 5 In the text similarity recognition device shown, the sentence vector acquisition module 510 may include:
[0112] A word vector acquisition unit 610 is used to process each sentence in a given sentence set through LSTM to obtain a word vector matrix corresponding to the sentence;
[0113] A sentence vector acquisition unit 620 is used to process the word vector matrix through the model algorithm in the attention model to obtain a sentence vector corresponding to the sentence;
[0114] Among them, the attention model includes a global context vector and a domain context vector of at least one domain, and the model algorithm is formed based on the global context vector or a domain context vector.
[0115] Furthermore, the sentence vector acquisition module 510 may also include:
[0116] A model algorithm building unit 630 is used to determine whether the attention model contains a domain context vector corresponding to the domain to which the current sentence to be processed belongs;
[0117] If yes, then select the corresponding domain context vector to form the model algorithm;
[0118] If not, the global context vector is selected to form the model algorithm.
[0119] Furthermore, the feature encoder may be a hash encoder.
[0120] The text similarity recognition device provided by the present invention performs feature encoding on the sentence vectors of each sentence in a given sentence set, so that the sentence feature vectors generated by the semantically similar sentence vectors are similar in correspondence on each vector segment, and vice versa; when generating the semantic signature of the sentence based on the positive and negative features of each dimensional value in the sentence feature vector, since the semantically similar sentence feature vectors are segmentally similar, the semantic signatures generated by the semantically similar sentence feature vectors can also achieve segmental similarity as much as possible, and then achieve overall similarity; when constructing the inverted index of the semantic signature to the corresponding sentence, since the semantic signatures corresponding to the semantically similar sentences are also similar, when determining the similar sentences corresponding to each sentence in the sentence set according to the inverted index of each semantic signature, the similarity between the determined similar sentences can be effectively guaranteed.
[0121] Furthermore, when obtaining the sentence vector corresponding to each sentence in a given sentence set, this solution adopts a sentence vectorization model that combines LSTM and an attention model, and introduces a global context vector and a domain context vector into the attention model to ensure that the sentence vectors generated by semantically similar sentences are as similar as possible, thereby assisting in the subsequent formation of sentence feature vectors to better achieve the consistency between semantic similarity and sentence feature vector similarity.
[0122] Embodiment 3
[0123] The above embodiments describe the overall structure of a text similarity recognition device. The functions of the device can be realized by means of an electronic device, such as Figure 7 As shown, it is a schematic diagram of the structure of an electronic device according to an embodiment of the present invention, which specifically includes: a memory 710 and a processor 720.
[0124] The memory 710 is used to store programs.
[0125] In addition to the above-mentioned programs, the memory 710 may also be configured to store various other data to support operations on the electronic device. Examples of such data include instructions for any application or method operating on the electronic device, contact data, phone book data, messages, pictures, videos, etc.
[0126] The memory 710 may be implemented by any type of volatile or nonvolatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.
[0127] The processor 720 is coupled to the memory 710 and is used to execute the program in the memory 710. When the program is running, the operation steps of the text similarity recognition method described in the above embodiments are executed.
[0128] In addition, the processor 720 may also include various modules described in the above embodiments to perform text similarity recognition operations, and the memory 710 may be used, for example, to store data required for these modules to perform operations and / or data outputted.
[0129] The above-mentioned specific processing operations have been described in detail in the previous embodiments and will not be repeated here.
[0130] Further, if Figure 7 As shown, the electronic device may further include: a communication component 730 , a power component 740 , an audio component 750 , a display 760 and other components. Figure 7 Only some components are shown schematically, which does not mean that the electronic device only includes Figure 7 Components shown.
[0131] The communication component 730 is configured to facilitate wired or wireless communication between the electronic device and other devices. The electronic device can access a wireless network based on a communication standard, such as WiFi, 2G or 3G, or a combination thereof. In an exemplary embodiment, the communication component 730 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 730 also includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology and other technologies.
[0132] The power supply component 740 provides power to various components of the electronic device. The power supply component 740 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to the electronic device.
[0133] The audio component 750 is configured to output and / or input audio signals. For example, the audio component 750 includes a microphone (MIC), and when the electronic device is in an operating mode, such as a call mode, a recording mode, and a voice recognition mode, the microphone is configured to receive an external audio signal. The received audio signal can be further stored in the memory 710 or sent via the communication component 730. In some embodiments, the audio component 750 also includes a speaker for outputting audio signals.
[0134] The display 760 includes a screen, which may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from a user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundaries of a touch or slide action, but also detect the duration and pressure associated with the touch or slide operation.
[0135] Embodiment 4
[0136] Figure 8 The flowchart of the text vectorization processing method provided by the embodiment of the present invention includes the following steps:
[0137] S810, performing word vector conversion on the sentence to be processed to obtain a word vector matrix corresponding to the sentence.
[0138] When the sentence is converted into a word vector, the word vector matrix can be obtained through the above-mentioned LSTM processing. In actual application scenarios, other models trained by deep learning algorithms can also be used to perform word vector conversion processing.
[0139] S820, processing the word vector matrix through the model algorithm in the attention model to obtain a sentence vector corresponding to the sentence;
[0140] Among them, the attention model includes a global context vector and a domain context vector of at least one domain, and the model algorithm is formed based on the global context vector or a domain context vector.
[0141] For example, a context vector can be first determined from the global context vector or the domain context vector according to the industry field to which the sentence to be processed belongs, and a model algorithm in the attention model is formed based on the context vector.
[0142] The independent domain context vector of each industry (domain) includes: the attention weight setting information of each target word in the sentence of the corresponding domain. The global context vector includes: the attention weight setting information of each target word in the sentence of the unknown domain.
[0143] In actual application scenarios, the amount of data in different industries varies greatly, and some industries only have a few thousand labeled data. Therefore, if a model is trained separately for each industry, the model effect of some industries with small existing data will be poor. In this solution, multiple industry data are learned with one model, and the domain context vector and global context vector are set for each industry to introduce the attention mechanism, which can effectively transfer the information of other industries to the target industry.
[0144] Correspondingly, the processing process of the above-mentioned model formation algorithm can be specifically as follows: first determine whether the attention model contains the domain context vector corresponding to the domain to which the current sentence to be processed belongs; if so, select the corresponding domain context vector to form the model algorithm; if not, select the global context vector to form the model algorithm.
[0145] Then, the word vector matrix is processed with the model algorithm formed by the independent domain context vector or the global context vector based on the industry (field) to which the sentence belongs, and the final vector representation, namely the sentence vector, is obtained.
[0146] The text vectorization processing method provided by the present invention introduces the domain contexts of different industries and an attention mechanism of a global context, so that sentences in different fields can be vectorized through the same sentence vectorization model without having to conduct model training separately for different fields. This effectively reduces the complexity of model training in the sentence vectorization processing process, while improving the practicability and efficiency of text vectorization processing.
[0147] Embodiment 5
[0148] Fig. 9 A schematic diagram of the structure of a text vectorization processing device provided in an embodiment of the present invention can be used to perform the following steps: Figure 8 The method steps shown include:
[0149] A word vector acquisition module 910 is used to perform word vector conversion on the sentence to be processed to obtain a word vector matrix corresponding to the sentence;
[0150] The sentence vector acquisition module 920 is used to process the word vector matrix through the model algorithm in the attention model to obtain the sentence vector corresponding to the sentence;
[0151] Among them, the attention model includes a global context vector and a domain context vector of at least one domain, and the model algorithm is formed based on the global context vector or one of the domain context vectors.
[0152] Furthermore, if Fig.10 As shown, in Fig. 9 The text vectorization processing device shown may also include:
[0153] A model algorithm building module 101 is used to determine whether the attention model contains a domain context vector corresponding to the domain to which the sentence to be processed belongs;
[0154] If yes, then select the corresponding domain context vector to form the model algorithm;
[0155] If not, a global context vector is selected to form the model algorithm.
[0156] The text vectorization processing device provided by the present invention introduces the domain contexts of different industries and an attention mechanism of a global context, so that sentences in different fields can be vectorized through the same sentence vectorization model without having to conduct model training for different fields separately. This effectively reduces the complexity of model training in the sentence vectorization processing process, while improving the practicability and efficiency of text vectorization processing.
[0157] Embodiment 6
[0158] The above embodiments describe the overall architecture of a text vectorization processing device. The functions of the device can be implemented by means of an electronic device, such as Fig.11 As shown, it is a schematic diagram of the structure of an electronic device according to an embodiment of the present invention, which specifically includes: a memory 111 and a processor 112.
[0159] The memory 111 is used to store programs.
[0160] In addition to the above-mentioned programs, the memory 111 may also be configured to store various other data to support operations on the electronic device. Examples of such data include instructions for any application or method operating on the electronic device, contact data, phone book data, messages, pictures, videos, etc.
[0161] The memory 111 may be implemented by any type of volatile or nonvolatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.
[0162] The processor 112 is coupled to the memory 111 and is used to execute the program in the memory 111. When the program is running, the operation steps of the text vectorization processing method described in the above embodiments are executed.
[0163] In addition, the processor 112 may also include the various modules described in the aforementioned embodiments to perform text vectorization processing operations, and the memory 111 may be used, for example, to store data required for these modules to perform operations and / or output data.
[0164] The above-mentioned specific processing operations have been described in detail in the previous embodiments and will not be repeated here.
[0165] Further, if Fig.11 As shown, the electronic device may also include: a communication component 113, a power component 114, an audio component 115, a display 116 and other components. Fig.11Only some components are shown schematically, which does not mean that the electronic device only includes Fig.11 Components shown.
[0166] The communication component 113 is configured to facilitate wired or wireless communication between the electronic device and other devices. The electronic device can access a wireless network based on a communication standard, such as WiFi, 2G or 3G, or a combination thereof. In an exemplary embodiment, the communication component 113 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 113 also includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology and other technologies.
[0167] The power supply component 114 provides power to various components of the electronic device. The power supply component 114 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to the electronic device.
[0168] The audio component 115 is configured to output and / or input audio signals. For example, the audio component 115 includes a microphone (MIC), and when the electronic device is in an operating mode, such as a call mode, a recording mode, and a voice recognition mode, the microphone is configured to receive an external audio signal. The received audio signal can be further stored in the memory 111 or sent via the communication component 113. In some embodiments, the audio component 115 also includes a speaker for outputting audio signals.
[0169] The display 116 includes a screen, which may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from a user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundaries of a touch or slide action, but also detect the duration and pressure associated with the touch or slide operation.
[0170] Those skilled in the art can understand that all or part of the steps of implementing the above-mentioned method embodiments can be completed by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, the steps of the above-mentioned method embodiments are executed; and the aforementioned storage medium includes: ROM, RAM, disk or optical disk and other media that can store program codes.
[0171] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.
Claims
1. A text similarity recognition method, comprising: Get the sentence vector corresponding to each sentence in the given sentence set; Each of the sentence vectors is encoded using a feature encoder obtained by pre-learning to generate a corresponding sentence feature vector; wherein the sentence feature vector includes multiple vector segments, and the feature encoder is used to make the sentence feature vectors generated by semantically similar sentence vectors correspond to each other in each vector segment, and vice versa; the feature encoder is trained by integrating the existing semantic signature algorithm into a hash function model as a whole; Based on the positive and negative features of each dimension value in the sentence feature vector, a semantic signature of the corresponding sentence is generated, and an inverted index from the semantic signature to the corresponding sentence is constructed; According to the inverted index of each semantic signature, a similar sentence corresponding to each sentence in the sentence set is determined.
2. The method according to claim 1, wherein: The generating of the semantic signature of the corresponding sentence based on the positive and negative features of each dimension value in the sentence feature vector and constructing an inverted index of the semantic signature to the corresponding sentence includes: The semantic signature is segmented according to the segmentation standard of the sentence feature vector, and an inverted index from each semantic signature segment to the corresponding sentence is constructed.
3. The method according to claim 2, wherein: Determining similar sentences corresponding to each sentence in the sentence set according to the inverted index of each semantic signature includes: According to a given semantic signature fragment and a sentence set indexed therein, for each sentence in the sentence set, a corresponding similar sentence is selected from the remaining sentences in the sentence set.
4. The method according to claim 3, wherein: For each sentence in the sentence set, selecting a corresponding similar sentence from the remaining sentences in the sentence set includes: For each sentence in the sentence set, the cosine value of the sentence vector corresponding to the sentence and each remaining sentence is calculated, and the corresponding similar sentence is selected from the remaining sentences according to the cosine value.
5. The method according to claim 1, wherein: The step of obtaining the sentence vector corresponding to each sentence in the given sentence set includes: Perform word vector conversion on each sentence in the given sentence set to obtain the word vector matrix corresponding to the sentence; Processing the word vector matrix through the model algorithm in the attention model to obtain a sentence vector corresponding to the sentence; The attention model includes a global context vector and a domain context vector of at least one domain, and the model algorithm is formed based on the global context vector or one of the domain context vectors; The step of converting each sentence in a given sentence set into a word vector to obtain a word vector matrix corresponding to the sentence includes: processing each sentence in the given sentence set through an LSTM to obtain a word vector matrix corresponding to the sentence.
6. The method according to claim 5, wherein: The process of forming the model algorithm includes: Determine whether the attention model contains a domain context vector corresponding to the domain to which the current sentence to be processed belongs; If yes, then select the corresponding domain context vector to form the model algorithm; If not, the global context vector is selected to form the model algorithm.
7. The method according to claim 1, wherein: The feature encoder is a hash encoder.
8. A text similarity recognition device, comprising: A sentence vector acquisition module is used to obtain the sentence vector corresponding to each sentence in a given sentence set; A sentence vector encoding module, used to encode each of the sentence vectors using a feature encoder obtained by pre-learning to generate a corresponding sentence feature vector; wherein the sentence feature vector includes multiple vector segments, and the feature encoder is used to make the sentence feature vectors generated by semantically similar sentence vectors correspond to each other in each vector segment, and vice versa; the feature encoder is trained by integrating the existing semantic signature algorithm into a hash function model as a whole; A signature index building module, used to generate a semantic signature of the corresponding sentence based on the positive and negative features of each dimension value in the sentence feature vector, and to build an inverted index from the semantic signature to the corresponding sentence; The similar sentence determination module is used to determine the similar sentence corresponding to each sentence in the sentence set according to the inverted index of each semantic signature.
9. An electronic device, comprising: Memory, used to store programs; A processor is coupled to the memory and is used to execute the program. When the program is running, the text similarity recognition method according to any one of claims 1 to 7 is executed.
