A text similarity analysis method and system based on NLP
Through the text similarity analysis method based on NLP, combined with word frequency and position weight, using the Word2vec model and CRF word segmenter, the problem of low text similarity detection accuracy and inability to locate similar fragments in the existing technology has been solved, and a higher level has been achieved Detection accuracy and visualizing results.
Patent Information
- Application Number
- CN202410904610.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-08
- Publication Date
- 2024-09-17
- Estimated Expiration
- 2044-07-08
AI Technical Summary
Existing text similarity detection methods have problems in terms of low accuracy and inability to obtain the positions of similar fragments, and semantic-based methods fail to effectively consider the semantic correlation between words and text structure information.
Adopt an NLP-based method and establish a standard vocabulary library to perform text feature extraction, vectorization processing and feature vector splicing. The Word2vec model and CRF word segmenter are used to combine word frequency and position weight to perform feature vector replacement and machine coding to extract common sub-words. sequences and mark their positions to calculate textual similarity and locate similar segments.
It improves the accuracy and precision of text similarity detection, can clearly reflect the position of similar fragments in the original text, and displays the similarity comparison results in a visual way.
Smart Images

Figure CN118446203B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of text processing, and in particular to a method and system for analyzing text similarity based on NLP. Background Art
[0002] Text similarity detection is a key technology in the field of text processing. It calculates the similarity between two or more texts by comparing them. It is widely used in tasks in the field of natural language processing (NLP), such as information retrieval, text classification, machine translation, and automatic question answering. At present, the commonly used text similarity detection methods include statistical-based text similarity detection methods and semantic-based text similarity detection methods. However, the statistical-based text similarity detection method only measures the surface similarity of the text, but does not consider the semantic similarity of the text, resulting in a lack of accuracy in the text similarity detection results; the semantic-based text similarity detection method uses a vector space model. For feature word extraction, most methods only rely on the word frequency information, without considering the structural information of the text; at the same time, the text vector representation does not consider the semantic relevance between words, resulting in a low accuracy rate of the similarity detection results. In addition, the existing text similarity detection methods simply obtain the text similarity value, but cannot obtain the position of similar fragments in the original text through text similarity detection. Summary of the invention
[0003] The purpose of the present invention is to provide a text similarity analysis method and system based on NLP, so as to solve the problem that the detection results obtained by the existing text similarity detection methods have low accuracy and the positions of similar fragments in the original text cannot be obtained through the detection results.
[0004] The present invention is achieved through the following technical solutions:
[0005] In a first aspect, a method for analyzing text similarity based on NLP is provided, comprising the following steps: establishing a standard vocabulary; performing text feature vectorization processing on each phrase in the standard vocabulary to obtain a standard feature vector set; performing text processing on a first text to obtain a first feature vector sequence; performing text processing on a second text to obtain a second feature vector sequence; the text processing comprises: text feature extraction, text feature vectorization and feature vector concatenation; performing feature vector replacement on the first feature vector sequence using the standard feature vector set to obtain a first equivalent feature vector sequence; performing feature vector replacement on the second feature vector sequence using the standard feature vector set to obtain a second equivalent feature vector sequence; performing machine encoding on the first equivalent feature vector sequence to obtain a first encoding sequence; performing machine encoding on the second equivalent feature vector sequence to obtain a second encoding sequence; extracting a common subsequence of the first encoding sequence and the second encoding sequence; marking the position of the common subsequence in the first encoding sequence and the second encoding sequence respectively; obtaining a first text similarity and a second text similarity according to the position marking; the first text similarity=common subsequence length / first encoding sequence length, the second text similarity=common subsequence length / second encoding sequence length.
[0006] Furthermore, a method for establishing a standard vocabulary is to use a crawler tool to crawl multiple phrases with different semantics from a network database.
[0007] Furthermore, the semantic feature extraction includes the following steps: using a CRF-based HanLP word segmenter to segment the text content into multiple phrases; calculating the total weight of each phrase by setting position weights and calculating word frequency weights; sorting all total weights in descending order, and screening out multiple feature phrases from multiple phrases according to the sorting results and a preset number of feature words to obtain a feature word set.
[0008] Furthermore, the text feature vectorization includes the following steps: using the Word2vec model to convert each feature phrase in the feature word set into a corresponding text feature vector to obtain a text feature vector set.
[0009] Furthermore, the feature vector concatenation comprises the following steps: S1: obtaining the Pearson correlation coefficient between each text feature vector in the text feature vector set and each other text feature vector, and obtaining a Pearson correlation coefficient set corresponding to each text feature vector; S2: creating a new spare vector set; initializing the spare vector set to an empty set; S3: selecting a text feature vector from the text feature vector set as the free end of the feature vector sequence; taking the selected text feature vector from the text feature vector set and adding it to the spare vector set; finding the Pearson correlation coefficient set corresponding to the selected text feature vector; n maximum value of correlation coefficient; S4: determine whether the text feature vector set is empty; if not, execute S5; if empty, execute S7; S5: select the text feature vector corresponding to the maximum value of the Pearson correlation coefficient from the text feature vector set as the associated feature vector; take the associated feature vector from the text feature vector set and add it to the spare vector set; S6: in the spare vector set, associate the associated feature vector with the free end of the feature vector sequence to obtain a new feature vector sequence; use the associated feature vector as the free end of the new feature vector sequence; return to S4; S7: take the feature vector sequence from the spare vector set.
[0010] Furthermore, the feature vector replacement includes the following steps: obtaining the cosine similarity between each feature vector in the feature vector sequence and each standard feature vector in the standard feature vector set, and obtaining a cosine similarity set corresponding to each feature vector in the feature vector sequence; executing S8-S10 for each feature vector in the feature vector sequence, and obtaining an equivalent feature vector sequence; wherein, S8: finding the maximum cosine similarity from the corresponding cosine similarity set; S9: selecting the standard feature vector corresponding to the maximum cosine similarity from the standard feature vector set; S10: replacing the corresponding feature vector in the feature vector sequence with the standard feature vector selected in S9.
[0011] Furthermore, before dividing the text content into a plurality of phrases, the method further includes the following steps: using a regular expression to delete blank content in the text content.
[0012] Furthermore, before obtaining the total weight of each phrase, the following steps are also included: using a stop word list to clean the multiple phrases obtained by segmentation.
[0013] Furthermore, the method for setting position weights is: according to the structural characteristics of the text, a first weight is set for the phrases segmented from the text title, a second weight is set for the phrases segmented from the keywords, a third weight is set for the phrases segmented from the abstract, and a fourth weight is set for the phrases segmented from the text.
[0014] Furthermore, the total weight = A × word frequency weight + B × position weight; where A is the custom coefficient of the word frequency weight, and B is the custom coefficient of the position weight.
[0015] Furthermore, the machine encoding method includes: using Unicode encoding, using LabelEncoder function encoding and using one-hot encoding.
[0016] Furthermore, the NLP-based text similarity analysis method also includes the following steps: converting the first coding sequence into a first binary sequence; converting the second coding sequence into a second binary sequence; generating a corresponding first pulse sequence based on the first binary sequence; generating a corresponding second pulse sequence based on the second binary sequence; generating a corresponding first pulse waveform diagram based on the first pulse sequence; generating a corresponding second pulse waveform diagram based on the second pulse sequence; comparing the waveforms of the first pulse waveform diagram with the second pulse waveform diagram, and marking the overlapping parts; and obtaining a first similarity and a second similarity based on the overlapping parts.
[0017] In a second aspect, a text similarity analysis system based on NLP is provided, comprising: a standard word library establishment module, used to establish a standard word library; a first text processing module, used to perform text feature vectorization processing on each phrase in the standard word library to obtain a standard feature vector set; a second text processing module, used to perform text processing on the first text to obtain a first feature vector sequence; perform text processing on the second text to obtain a second feature vector sequence; the text processing includes: text feature extraction, text feature vectorization and feature vector concatenation; a feature vector replacement module, used to perform feature vector replacement on the first feature vector sequence using the standard feature vector set to obtain a first equivalent feature vector sequence; perform feature vector replacement on the second feature vector sequence using the standard feature vector set to obtain a second equivalent feature vector sequence;
[0018] A vector sequence encoding module is used to perform machine encoding on the first equivalent feature vector sequence to obtain a first encoding sequence; and to perform machine encoding on the second equivalent feature vector sequence to obtain a second encoding sequence; a common sequence extraction module is used to extract a common subsequence of the first encoding sequence and the second encoding sequence; a sequence position marking module is used to mark the position of the common subsequence in the first encoding sequence and the second encoding sequence respectively; and a similarity calculation module is used to obtain a first text similarity and a second text similarity according to the position marking; the first text similarity = common subsequence length / first encoding sequence length, and the second text similarity = common subsequence length / second encoding sequence length.
[0019] Compared with the prior art, the present invention has the following advantages and beneficial effects:
[0020] 1. This application uses a natural language processing method to process the text to be analyzed - by extracting phrases from the content of the text to be analyzed, and combining the semantic relationship between the phrases and the text structure features to extract text features and vectorize the phrases, so as to combine text semantic analysis in feature word extraction, the accuracy of feature word extraction results can be improved, and then help improve the comparison accuracy of text similarity; in addition, this application uses the feature vector obtained after feature vectorization processing to concatenate the feature vector sequence, and use the feature vector sequence to represent the original text, and use the feature vector sequence to generate the corresponding coding sequence through machine coding, and use the common subsequence of the two coding sequences as the similar fragments between the two texts to be analyzed, and based on the common subsequence, the position is marked in the original coding sequence, and the position of the similar fragment in the original text can be obtained; in addition, by calculating the ratio of the length of the common subsequence to the length of the coding sequence, the similarity of the text can be obtained simply and quickly. 2. The position weight and word frequency weight of the phrase are extracted in the process of text feature extraction. Among them, the position weight can reflect the relationship between the phrase and the text structure feature, the word frequency weight can reflect the semantic importance of the phrase in the text, and the total weight of the phrase obtained by the position weight and the word frequency weight is used as the basis for extracting feature words, which improves the accuracy of the feature word extraction results. 3. The text feature vectorization adopts the Word2vec model, which deeply mines the semantic relationship between phrases and the association relationship between phrases and texts by learning semantic knowledge in an unsupervised manner, and can be well applied to the word representation in text similarity. 4. Through the cosine similarity calculation, the feature vector of the text to be analyzed is replaced by the standard feature vector, so that the feature vector sequences of the two texts to be analyzed are unified, thereby improving the comparability between the two feature vector sequences, and then improving the accuracy of the similarity comparison results. 5. The feature vector sequence is converted into a binary sequence by encoding conversion, and then further converted into a pulse sequence. Finally, by generating a pulse waveform diagram, the similarity comparison visualization is realized, which can clearly reflect the position of similar fragments. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] In order to more clearly illustrate the technical solutions of the exemplary embodiments of the present invention, the drawings required for use in the embodiments will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present invention and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0022] Figure 1 A flow chart of a text similarity analysis method based on NLP provided in an embodiment of the present invention;
[0023] Figure 2 A flow chart of a method for feature vector splicing provided by an embodiment of the present invention;
[0024] Figure 3 A schematic diagram of a method for concatenating feature vectors provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0025] In order to make the objectives, technical solutions and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with embodiments and drawings. The exemplary embodiments of the present invention and their description are only used to explain the present invention and are not intended to limit the present invention.
[0026] Embodiment 1: In view of the problem that the detection results obtained by the existing text similarity detection method have low accuracy and the position of similar fragments in the original text cannot be obtained through the detection results, this embodiment provides a text similarity analysis method based on NLP, such as Figure 1 As shown, the method comprises the following steps:
[0027] Step 1: Establish a standard vocabulary; perform text feature vectorization on each phrase in the standard vocabulary to obtain a standard feature vector set.
[0028] This embodiment uses a crawler tool to crawl multiple phrases with different semantics from a network database. The content and number of phrases can be selected according to the actual application scenario of this method. For example, the content of the phrase can be professional vocabulary, general vocabulary, etc. in a certain industry field, and the number of phrases can be determined in combination with the volume of the text to be analyzed and the richness of the vocabulary.
[0029] Text feature vectorization is to convert text-type phrases into computer-recognizable and computable word vectors. This method uses the Word2vec model to perform text feature vectorization on each feature phrase in the feature word set.
[0030] Step 2: Perform text processing on the first text to obtain a first feature vector sequence; perform text processing on the second text to obtain a second feature vector sequence.
[0031] Among them, text processing includes: text feature extraction, text feature vectorization and feature vector splicing.
[0032] It should be noted that, in order to illustrate the basic principle of this method, this embodiment only takes two texts to be analyzed as an example, one of which is called the first text, and the other is called the second text. Of course, this aspect is also applicable to similarity analysis of multiple texts to be analyzed. The following is a detailed description of how to extract text features, how to vectorize text features, and how to splice feature vectors in the text processing process.
[0033] 1. Text feature extraction
[0034] Since the text content may have defects such as incomplete expression and inconsistent structure, directly performing similarity analysis on the two original texts to be analyzed will be affected by the inherent defects of the text and reduce the accuracy of the similarity results. Therefore, it is necessary to first perform text feature extraction on the first text and the second text, and express the original text content as multiple independent phrases. Specifically, text feature extraction includes the following steps:
[0035] Step 2.1.1: Use regular expressions to remove blank spaces in the text content.
[0036] Since the text may have incomplete expressions and inconsistent structures, the recognition effect will be reduced if the original text is directly used for similarity analysis. Therefore, regular expressions can be used to delete blank content in the text.
[0037] Step 2.1.2: Use the CRF-based HanLP tokenizer to segment the text content into multiple phrases.
[0038] Since the CRF algorithm can consider both word frequency and context, and can better identify ambiguous words and new words, this method uses the CRF-based HanLP word segmenter to segment power grid customer service work orders. It should be added that in view of the problems that the HanLP word segmenter cannot recognize some professional vocabulary and excessive segmentation of place names, the external knowledge dictionary is crawled through the crawler tool and embedded into the word segmenter through the designed scoring rules.
[0039] Step 2.1.3: Use the stop word list to clean the multiple phrases obtained by segmentation.
[0040] Since there may be words and symbols in the multiple words after segmentation that have no semantic impact on the text expression but will affect the feature word extraction results, a stop word list is used to delete these words and symbols from the word set.
[0041] Step 2.1.4: Calculate the total weight of each phrase by setting the position weight and calculating the word frequency weight; sort all the total weights in descending order, and select multiple feature phrases from multiple phrases according to the sorting results and the preset number of feature words to obtain a feature word set.
[0042] Setting the position permission of a phrase can handle the situation where there are many phrases of the same type in the text and obtain the position information of the phrase; calculating the frequency weight of the phrase can obtain the importance of the phrase in the text. This method calculates the total weight of the phrase from the two aspects of the position weight and frequency weight of the phrase as the basis for extracting text feature words.
[0043] The first step is to use the TF-IWF algorithm to calculate the frequency weight of the phrase. The TF-IWF algorithm can effectively reduce the impact of a small number of phrases and a large number of similar phrases in the text on the frequency weight of the phrase.
[0044] The second step is to set the position weight of the words according to the structural characteristics of the text. Specifically, the first weight is set for the phrases segmented from the text title, the second weight is set for the phrases segmented from the keywords, the third weight is set for the phrases segmented from the abstract, and the fourth weight is set for the phrases segmented from the text. It should be noted that the specific weight values of the first weight, the second weight, the third weight and the fourth weight can be customized. For example, the position weight values of 3, 2 and 1 are respectively given to the materials appearing in the text title, keywords and abstracts.
[0045] The third step is to add the word frequency weight and word position weight to get the total word weight. Total weight = A × word frequency weight + B × position weight; where A is the custom coefficient of word frequency weight and B is the custom coefficient of position weight.
[0046] In the fourth step, all total weights are sorted in descending order, and multiple feature phrases are selected from multiple phrases according to the sorting results and the preset number of feature words to obtain a feature word set. The preset number of feature words is a custom phrase extraction ratio, which can be manually determined according to the importance and position of the phrase in the text. The extracted feature word set can represent the text.
[0047] 2. Text feature vectorization
[0048] Since text data cannot be directly recognized by computers, it is necessary to perform feature vectorization on the text to convert it into structured data that can be recognized by computers.
[0049] Similar to the text feature vectorization processing of the standard word library, the text vectorization processing of the phrases in the feature word set also uses the Word2vec model to convert each feature phrase in the feature word set into a corresponding text feature vector to obtain a text feature vector set. The Word2vec model can learn semantic knowledge from a large amount of text predictions in an unsupervised manner, and train to obtain semantic, low-dimensional, dense word vectors, which can be well applied to word representation in text similarity.
[0050] 3. Feature vector concatenation
[0051] After the above-mentioned feature text feature extraction and text feature graph quantization processing, the first text and the second text are converted to be represented by multiple text feature vectors. However, the multiple text feature vectors after conversion exist independently and cannot reflect the meaning of the text, that is, the converted text feature vectors do not have a semantic association relationship. The feature vector concatenation described in this step is to associate multiple independent text feature vectors based on their semantic relevance to form a feature vector sequence with expressive meaning, and use this feature vector sequence to represent the corresponding text. The specific implementation steps are as follows: Figure 2As shown, including:
[0052] Step 2.2.1: Obtain the Pearson correlation coefficient between each text feature vector in the text feature vector set and each other text feature vector, and obtain the Pearson correlation coefficient set corresponding to each text feature vector.
[0053] Assume that the text feature vector set contains 6 text feature vectors. For any text feature vector A1, obtain the Pearson correlation coefficients P2-P6 between the text feature vector A1 and the text feature vectors A2-A6 respectively, and obtain the Pearson correlation coefficient set corresponding to the text feature vector A1. For any one of the text feature vectors A2-A6, perform the same operation as the text feature vector A1 to obtain the corresponding Pearson correlation coefficient set.
[0054] Step 2.2.2: Create a new spare vector set; initialize the spare vector set to an empty set.
[0055] Step 2.2.3: Select a text feature vector from the text feature vector set as the free end of the feature vector sequence; take the selected text feature vector out of the text feature vector set and add it to the spare vector set; find the maximum value of the Pearson correlation coefficient from the Pearson correlation coefficient set corresponding to the selected text feature vector.
[0056] Assuming that a text feature vector A3 is selected from the text feature vector set, the text feature vector A3 is regarded as the free end of the feature vector sequence, and the text feature vector A3 is taken out of the text feature vector set and added into the spare vector set.
[0057] Step 2.2.4: Determine whether the text feature vector set is empty; if not, execute step 2.2.5; if empty, execute step 2.2.7;
[0058] Step 2.2.5: Select the text feature vector corresponding to the maximum value of the Pearson correlation coefficient from the text feature vector set as the associated feature vector; take the associated feature vector from the text feature vector set and add it to the backup vector set.
[0059] Assuming that after finding the maximum Pearson correlation coefficient from the Pearson correlation coefficient set corresponding to the text feature vector A3, the text feature vector corresponding to the maximum Pearson correlation coefficient is A6, then the text feature vector A6 is regarded as the associated feature vector, and the text feature vector A6 is taken out from the text feature vector set and added to the spare vector set.
[0060] Step 2.2.6: In the spare vector set, associate the associated feature vector with the free end of the feature vector sequence to obtain a new feature vector sequence; use the associated feature vector as the free end of the new feature vector sequence; return to step 2.2.4;
[0061] Step 2.2.7: Take out the feature vector sequence from the backup vector set.
[0062] The principles of steps 2.2.1 to 2.2.7 above can be found in Figure 3 .
[0063] Step 3: Use the standard feature vector set to replace the feature vectors of the first feature vector sequence to obtain a first equivalent feature vector sequence; use the standard feature vector set to replace the feature vectors of the second feature vector sequence to obtain a second equivalent feature vector sequence.
[0064] Due to the content differences between the two texts to be analyzed, the text expressions of the feature phrases corresponding to the two texts to be analyzed are different after text feature extraction. Therefore, it is possible that the two feature phrases have the same meaning but correspond to different text expressions. For example, the feature phrase "like" is extracted from the first text, and the feature phrase "favorite" is extracted from the second text. The two have the same meaning, but there are differences in text expressions. Therefore, in order to make the first feature vector sequence and the second feature vector sequence comparable, the two need to be assimilated. The purpose of establishing a standard vocabulary is to assimilate the feature vector sequence of the text to be analyzed, so as to improve the comparability between the two. The first feature vector sequence and the second feature vector sequence are represented by the same text feature vector, and the difference between the two is only reflected in the different positions of the text feature vectors in the sequence, representing different semantics. This method uses a standard feature vector to replace the feature vectors in the first feature vector sequence and the second feature vector sequence, and includes the following steps:
[0065] Step 3.1: Obtain the cosine similarity between each feature vector in the feature vector sequence and each standard feature vector in the standard feature vector set, and obtain the cosine similarity set corresponding to each feature vector in the feature vector sequence. The principle can be referred to step 2.2.1.
[0066] Step 3.2: Execute steps 3.2.1 to 3.2.3 for each feature vector in the feature vector sequence to obtain an equivalent feature vector sequence.
[0067] Step 3.2.1: Find the maximum cosine similarity from the corresponding cosine similarity set.
[0068] Step 3.2.2: Select the standard feature vector corresponding to the maximum cosine similarity from the standard feature vector set.
[0069] Step 3.2.3: Replace the corresponding eigenvectors in the eigenvector sequence with the standard eigenvectors selected in Step 3.2.2.
[0070] Step 4: Perform machine encoding on the first equivalent eigenvector sequence to obtain a first encoded sequence; perform machine encoding on the second equivalent eigenvector sequence to obtain a second encoded sequence.
[0071] The machine encoding described in this step can be: using Unicode encoding, using the LabelEncoder function for encoding, and using one-hot encoding.
[0072] The purpose of machine encoding is to facilitate similarity comparison and positioning of similar segments. For example, the encoding range of the Unicode character set is 0x0000 - 0x10FFFF, which can accommodate more than one million characters. Each character has a unique encoding, that is, each character corresponds to a binary value, which is also called a code point here. For example, the code point of the Chinese character "中" is 0x4E2D, and the code point of the capital letter A is 0x41. The specific Unicode encoding corresponding to a character can be queried in the Unicode character encoding table.
[0073] Step 5: Extract the common subsequence of the first encoded sequence and the second encoded sequence.
[0074] The common subsequence is the encoded sequence jointly owned by the first encoded sequence and the second encoded sequence, and can be used to represent the same segment between the two.
[0075] Step 6: Mark the positions of the common subsequence in the first encoded sequence and the second encoded sequence respectively.
[0076] By marking the positions, the positions of the same segments can be obtained, and after decoding, the positioning of the similar segments of the text can be realized.
[0077] Step 7: Obtain the first text similarity and the second text similarity according to the position marks.
[0078] Among them, the first text similarity = the length of the common subsequence / the length of the first encoded sequence, and the second text similarity = the length of the common subsequence / the length of the second encoded sequence.
[0079] In this step, the ratio of the length of the common subsequence to the length of the所属 encoded sequence is used to represent the text similarity. For example, if the length of the common subsequence accounts for 50% of the length of the first encoded sequence, it means that 50% of the text content in the first text is similar to the text content in the second text. This method can simply and quickly calculate the similarity of two texts to be analyzed.
[0080] In addition, in order to realize the visualization of similarity comparison and clearly reflect the position of similar segments, the method also intuitively reflects the similar segments and the positions of similar segments of the first text and the second message by comparing the pulse waveform graph. The specific implementation method is as follows:
[0081] Step 8: Convert the first coded sequence into a first binary sequence; and convert the second coded sequence into a second binary sequence.
[0082] Step 9: Generate a corresponding first pulse sequence according to the first binary sequence; and generate a corresponding second pulse sequence according to the second binary sequence.
[0083] Step 10: Generate a corresponding first pulse waveform diagram according to the first pulse sequence; generate a corresponding second pulse waveform diagram according to the second pulse sequence.
[0084] Step 11: Compare the first pulse waveform diagram with the second pulse waveform diagram, and mark the overlapping part.
[0085] Step 12: Obtain the first similarity and the second similarity according to the overlapping part.
[0086] Embodiment 2: Corresponding to the NLP-based text similarity analysis method provided in Embodiment 1, this embodiment provides an NLP-based text similarity analysis system, including:
[0087] A standard word library building module is used to build a standard word library;
[0088] A first text processing module, configured to perform text feature vectorization processing on each phrase in the standard vocabulary to obtain a standard feature vector set;
[0089] A second text processing module is used to perform text processing on the first text to obtain a first feature vector sequence; and to perform text processing on the second text to obtain a second feature vector sequence; the text processing includes: text feature extraction, text feature vectorization and feature vector splicing;
[0090] A feature vector replacement module, used to perform feature vector replacement on the first feature vector sequence using the standard feature vector set to obtain a first equivalent feature vector sequence; and perform feature vector replacement on the second feature vector sequence using the standard feature vector set to obtain a second equivalent feature vector sequence;
[0091] A vector sequence encoding module, configured to perform machine encoding on the first equivalent feature vector sequence to obtain a first encoding sequence; and perform machine encoding on the second equivalent feature vector sequence to obtain a second encoding sequence;
[0092] A common sequence extraction module, used to extract a common subsequence of the first coding sequence and the second coding sequence;
[0093] A sequence position marking module, used for marking the position of the common subsequence in the first coding sequence and the second coding sequence respectively;
[0094] The similarity calculation module is used to obtain the first text similarity and the second text similarity according to the position mark; the first text similarity=common subsequence length / first encoding sequence length, and the second text similarity=common subsequence length / second encoding sequence length.
[0095] The specific implementation methods described above further illustrate the objectives, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above description is only a specific implementation method of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.
Claims
1. A text similarity analysis method based on NLP, It is characterized in that The following steps are involved: Establishing a standard word library; performing text feature vectorization processing on each phrase in the standard word library to obtain a standard feature vector set; Performing text processing on the first text to obtain a first feature vector sequence; Performing text processing on the second text to obtain a second feature vector sequence; the text processing includes: text feature extraction, text feature vectorization and feature vector splicing; Using the standard feature vector set to perform feature vector replacement on the first feature vector sequence to obtain a first equivalent feature vector sequence; using the standard feature vector set to perform feature vector replacement on the second feature vector sequence to obtain a second equivalent feature vector sequence; Performing machine encoding on the first equivalent feature vector sequence to obtain a first encoding sequence; performing machine encoding on the second equivalent feature vector sequence to obtain a second encoding sequence; extracting a common subsequence of the first coding sequence and the second coding sequence; Marking the positions of the common subsequences in the first coding sequence and the second coding sequence respectively; Obtaining the first text similarity and the second text similarity according to the position mark; the first text similarity = common subsequence length / first coding sequence length, the second text similarity = common subsequence length / second coding sequence length; The feature vector splicing includes the following steps: S1: Obtain the Pearson correlation coefficient between each text feature vector in the text feature vector set and each other text feature vector, and obtain a Pearson correlation coefficient set corresponding to each text feature vector, wherein the text feature vector set is composed of text feature vectors obtained after text feature vectorization; S2: Create a new spare vector set; initialize the spare vector set to an empty set; S3: selecting a text feature vector from the text feature vector set as the free end of the feature vector sequence; taking the selected text feature vector from the text feature vector set and adding it to the spare vector set; finding the maximum value of the Pearson correlation coefficient from the Pearson correlation coefficient set corresponding to the selected text feature vector; S4: Determine whether the text feature vector set is empty; if not, execute S5; if empty, execute S7; S5: Selecting a text feature vector corresponding to the maximum value of the Pearson correlation coefficient from the text feature vector set as an associated feature vector; taking the associated feature vector from the text feature vector set and adding it to the spare vector set; S6: in the spare vector set, associating the associated feature vector with the free end of the feature vector sequence to obtain a new feature vector sequence; using the associated feature vector as the free end of the new feature vector sequence; and returning to S4; S7: Extract a feature vector sequence from the backup vector set.
2. According to the NLP-based text similarity analysis method of claim 1, It is characterized in that The method for establishing a standard vocabulary is to use a crawler tool to crawl multiple phrases with different semantics from a network database.
3. According to the NLP-based text similarity analysis method of claim 1, It is characterized in that The text feature extraction comprises the following steps: Use CRF-based HanLP word segmenter to segment text content into multiple phrases; The total weight of each phrase is calculated by setting the position weight and calculating the word frequency weight; All total weights are sorted in descending order, and multiple feature phrases are screened out from multiple phrases according to the sorting result and a preset number of feature words to obtain a feature word set.
4. According to the NLP-based text similarity analysis method of claim 3, It is characterized in that The text feature vectorization includes the following steps: using the Word2vec model to convert each feature phrase in the feature word set into a corresponding text feature vector to obtain a text feature vector set.
5. According to the NLP-based text similarity analysis method of claim 1, It is characterized in that The feature vector replacement comprises the following steps: Obtaining the cosine similarity between each feature vector in the feature vector sequence and each standard feature vector in the standard feature vector set, and obtaining a cosine similarity set corresponding to each feature vector in the feature vector sequence; Execute S8-S10 for each feature vector in the feature vector sequence to obtain an equivalent feature vector sequence; wherein, S8: find the maximum cosine similarity from the corresponding cosine similarity set; S9: select the standard feature vector corresponding to the maximum cosine similarity from the standard feature vector set; S10: use the standard feature vector selected in S9 to replace the corresponding feature vector in the feature vector sequence.
6. According to the NLP-based text similarity analysis method of claim 3, It is characterized in that Before dividing the text content into a plurality of phrases, the following steps are also included: using a regular expression to delete blank content in the text content; Before obtaining the total weight of each phrase, the following steps are also included: using a stop word list to clean the multiple phrases obtained by segmentation; The method of setting the position weight is: according to the structural characteristics of the text, a first weight is set for the phrases segmented from the text title, a second weight is set for the phrases segmented from the keywords, a third weight is set for the phrases segmented from the abstract, and a fourth weight is set for the phrases segmented from the text; Total weight = A × word frequency weight + B × position weight; where A is the custom coefficient of word frequency weight and B is the custom coefficient of position weight.
7. The method for analyzing text similarity based on NLP according to claim 1, It is characterized in that The machine encoding method includes: using Unicode encoding, using LabelEncoder function encoding and using one-hot encoding.
8. A text similarity analysis method based on NLP according to any one of claims 1 to 7, It is characterized in that The following steps are also included: Converting the first coded sequence into a first binary sequence; converting the second coded sequence into a second binary sequence; generating a corresponding first pulse sequence according to the first binary sequence; generating a corresponding second pulse sequence according to the second binary sequence; Generate a corresponding first pulse waveform diagram according to the first pulse sequence; Generate a corresponding second pulse waveform diagram according to the second pulse sequence; Compare the first pulse waveform diagram with the second pulse waveform diagram and mark the overlapping part; The first similarity and the second similarity are acquired according to the overlapping part.
9. A text similarity analysis system based on NLP, It is characterized in that include: A standard word library building module is used to build a standard word library; A first text processing module, configured to perform text feature vectorization processing on each phrase in the standard vocabulary to obtain a standard feature vector set; A second text processing module is used to perform text processing on the first text to obtain a first feature vector sequence; and to perform text processing on the second text to obtain a second feature vector sequence; the text processing includes: text feature extraction, text feature vectorization and feature vector splicing; A feature vector replacement module, configured to perform feature vector replacement on the first feature vector sequence using the standard feature vector set to obtain a first equivalent feature vector sequence; and perform feature vector replacement on the second feature vector sequence using the standard feature vector set to obtain a second equivalent feature vector sequence; A vector sequence encoding module, configured to perform machine encoding on the first equivalent feature vector sequence to obtain a first encoding sequence; and perform machine encoding on the second equivalent feature vector sequence to obtain a second encoding sequence; A common sequence extraction module, used to extract a common subsequence of the first coding sequence and the second coding sequence; A sequence position marking module, used for marking the position of the common subsequence in the first coding sequence and the second coding sequence respectively; A similarity calculation module, used for obtaining a first text similarity and a second text similarity according to the position mark; the first text similarity = common subsequence length / first coding sequence length, the second text similarity = common subsequence length / second coding sequence length; The feature vector splicing includes the following steps: S1: Obtain the Pearson correlation coefficient between each text feature vector in the text feature vector set and each other text feature vector, and obtain a Pearson correlation coefficient set corresponding to each text feature vector, wherein the text feature vector set is composed of text feature vectors obtained after text feature vectorization; S2: Create a new spare vector set; initialize the spare vector set to an empty set; S3: selecting a text feature vector from the text feature vector set as the free end of the feature vector sequence; taking the selected text feature vector from the text feature vector set and adding it to the spare vector set; finding the maximum value of the Pearson correlation coefficient from the Pearson correlation coefficient set corresponding to the selected text feature vector; S4: Determine whether the text feature vector set is empty; if not, execute S5; if empty, execute S7; S5: Selecting a text feature vector corresponding to the maximum value of the Pearson correlation coefficient from the text feature vector set as an associated feature vector; taking the associated feature vector from the text feature vector set and adding it to the spare vector set; S6: in the spare vector set, associating the associated feature vector with the free end of the feature vector sequence to obtain a new feature vector sequence; using the associated feature vector as the free end of the new feature vector sequence; and returning to S4; S7: Extract a feature vector sequence from the backup vector set.
Citation Information
Patent Citations
Element information extraction method and device based on text recognition, equipment and medium
CN113536771A
Method and system for identifying NFT data rights and interests of distributed AI system
CN116340386A
Video retrieval method and device based on multiple modes, electronic equipment and storage medium
CN116628263A
Multi-modal article content processing system and control method thereof
CN117893862A
Automatic discovery of code and data stores that populate a user interface element
US20160162527A1
