A text similarity calculation method based on Cilin and word vector
By constructing a related word forest and integrating it with a synonymous word forest, the problem of failing to consider word correlation in the existing technology is solved, a more accurate text similarity calculation is achieved, and the analysis effect is improved.
Patent Information
- Application Number
- CN202210362462.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-08
- Publication Date
- 2024-08-23
- Estimated Expiration
- 2042-04-08
AI Technical Summary
The existing technology fails to effectively consider the correlation between words when calculating text similarity, resulting in inaccurate calculation results.
By constructing a related word forest and integrating it with synonymous word forests and word vectors, the weight coefficient is used to sum up the similarities and calculate the similarity of the text. Specific steps include preprocessing the wordsim-240 and wordsim-297 data sets, generating related word forests, and selecting appropriate word forest algorithms based on word categories when calculating similarity.
The accuracy and effectiveness of text similarity calculation are improved, and the similarity between texts can be better analyzed.
Smart Images

Figure CN114881022B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of text analysis, and in particular to a text similarity calculation method based on word forest and word vector. Background Art
[0002] With the rapid development of computer networks, text similarity calculation has been widely used in many fields. For example, in machine translation, semantic similarity measures the quality of machine translation by measuring the equivalence between the reference translation and the machine translation output. In addition, text similarity calculation is a basic and important task in information retrieval, sentiment analysis, text classification, text clustering, automatic question answering, semantic disambiguation and other fields. When calculating text similarity, the existing technology generally uses semantic-based synonyms, word vectors and other calculations. This method does not take into account the correlation between words in the text. Correlation reflects the degree of correlation between two words. It can be measured by the possibility of the two words co-occurring in the same context. Word correlation is also a real number between [0, 1]. For example, the two words "doctor" and "disease" have very low similarity, but high correlation. Summary of the invention
[0003] In order to overcome the deficiencies of the above technologies, the present invention provides a method for more accurately and effectively analyzing the similarity between texts by constructing a related word forest and fusing it with a synonym word forest and a word vector.
[0004] The technical solution adopted by the present invention to overcome the technical problems is:
[0005] A text similarity calculation method based on Cilin and word vectors includes the following steps:
[0006] a) Perform word segmentation on the two texts to be processed and obtain two word lists. The first word list contains words, and the second vocabulary list has words;
[0007] b) calculating the similarity between the first word in the first vocabulary list and all the words in the second vocabulary list, and taking the maximum value of the similarity as the similarity between the first word in the first vocabulary list and the second vocabulary list;
[0008] c) Repeat step b) times until the rest of the first vocabulary list is calculated The similarity between each word and all words in the second vocabulary list is calculated. The average of the similarities is taken as the similarity sim1 between the first vocabulary list and the second vocabulary list;
[0009] d) calculating the similarity between the first word in the second vocabulary list and all the words in the first vocabulary list, and taking the maximum similarity as the similarity between the first word in the first vocabulary list and the second vocabulary list;
[0010] e) Repeat step d) times until the rest of the second vocabulary list is calculated. The similarity between each word and all the words in the first vocabulary list is calculated. The average of the similarities is taken as the similarity sim2 between the second vocabulary list and the first vocabulary list;
[0011] f) Calculate the average of similarity sim1 and similarity sim2 to obtain the similarity between the two texts.
[0012] Furthermore, the step of calculating the similarity in step b) is:
[0013] b-1) determining whether the first word in the first vocabulary list and the corresponding word in the second vocabulary list belong to the same category, if so, using the similarity calculation algorithm based on the synonym word forest to calculate the similarity of the two words, if not, using the similarity calculation algorithm based on the related word word forest to calculate the similarity of the two words;
[0014] b-2) Using the weight coefficient, the similarity between two words calculated using the algorithm for calculating similarity based on the synonym word forest and the similarity between two words calculated using the algorithm for calculating similarity based on the related word forest are summed to obtain the similarity between the first word in the first vocabulary list and all the words in the second vocabulary list.
[0015] Furthermore, the step of calculating the similarity in step d) is:
[0016] d-1) determining whether the first word in the second vocabulary list and the corresponding word in the first vocabulary list belong to the same general category, if so, using the similarity calculation algorithm based on the synonym word forest to calculate the similarity of the two words, if not, using the similarity calculation algorithm based on the related word word forest to calculate the similarity of the two words;
[0017] d-2) using the weight coefficient, the similarity between two words calculated using the algorithm for calculating similarity based on the synonym word forest and the similarity between two words calculated using the algorithm for calculating similarity based on the related word forest are summed to obtain the similarity between the first word in the second vocabulary list and all the words in the first vocabulary list.
[0018] Furthermore, the steps of constructing the related word forest in step b-1) and step d-1) are:
[0019] b-1) Preprocess the two data sets of wordsim-240 and wordsim-297. The score of wordsim-240 is 0-10 and the score of wordsim-297 is 0-5. Read the wordsim-240 data set and the wordsim-297 data set, adjust the score range of the wordsim-240 data set and the wordsim-297 data set to 0-1, merge the wordsim-240 data set and the wordsim-297 data set, retain the word pairs with similarity greater than 0.2, and generate data set 1;
[0020] b-2) Find the codes of the words in Dataset 1 in the synonym dictionary. If the same word has multiple codes, only the codes with the highest similarity between the two words are selected to generate Dataset 2. The format of each row in Dataset 2 is: code of word 1 - code of word 2 - similarity;
[0021] b-3) Expand the encoding and similarity of the first layer to the fourth layer of dataset 2 to generate dataset 3;
[0022] b-4) Remove all codes and similarities of words in each row belonging to the same category in data set 3, retain data of different categories, merge repeated word pairs, take the average of similarities, and generate data set 4;
[0023] b-5) Sort the word pairs in data set 4 in coding order, remove the word pairs with similarity lower than 0.1, and generate data set 5. Data set 5 is the final generated related word forest.
[0024] The beneficial effects of the present invention are as follows: using the synonym word forest and two data sets of wordsim-240 and wordsim-297, a related word forest similarity table is created, and based on the two word forests, the text similarity based on the word forest is calculated. Then, the weights are added with the word vector to calculate the similarity of the text. By constructing a related word forest and fusing it with the synonym word forest and the word vector, the similarity between texts can be analyzed more accurately and effectively. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] Figure 1 It is a structural block diagram of the method of the present invention;
[0026] Figure 2 Construct a flow chart for the related word vocabulary of the present invention. DETAILED DESCRIPTION
[0027] The following is combined with Figure 1 To Attachment Figure 2 The present invention is further described.
[0028] A text similarity calculation method based on Cilin and word vectors includes the following steps:
[0029] a) Perform word segmentation on the two texts to be processed and obtain two word lists. The first word list contains words, and the second vocabulary list has word.
[0030] b) Calculate the similarity between the first word in the first vocabulary list and all the words in the second vocabulary list, and take the maximum similarity as the similarity between the first word in the first vocabulary list and the second vocabulary list.
[0031] c) Repeat step b) times until the rest of the first vocabulary list is calculated. The similarity between each word and all the words in the second vocabulary list is calculated. The average of the similarities is taken as the similarity sim1 between the first vocabulary list and the second vocabulary list.
[0032] d) Calculate the similarity between the first word in the second vocabulary list and all the words in the first vocabulary list, and take the maximum similarity as the similarity between the first word in the first vocabulary list and the second vocabulary list.
[0033] e) Repeat step d) times until the rest of the second vocabulary list is calculated. The similarity between each word and all the words in the first vocabulary list is calculated. The average of the similarities is taken as the similarity sim2 between the second vocabulary list and the first vocabulary list.
[0034] f) Calculate the average of similarity sim1 and similarity sim2 to obtain the similarity between the two texts.
[0035] Using the synonym word forest and two data sets, wordsim-240 and wordsim-297, the related word forest similarity table was created, and based on these two word forests, the text similarity based on the word forest was calculated. Then the weights were added to the word vector to calculate the similarity of the text. By constructing the related word forest and fusing it with the synonym word forest and word vector, a more accurate and effective analysis of the similarity between texts can be achieved.
[0036] The steps of calculating the similarity in step b) are:
[0037] b-1) determining whether the first word in the first vocabulary list and the corresponding word in the second vocabulary list belong to the same category, if so, using the similarity calculation algorithm based on the synonym word forest to calculate the similarity of the two words, if not, using the similarity calculation algorithm based on the related word word forest to calculate the similarity of the two words;
[0038] b-2) Using the weight coefficient, the similarity between two words calculated using the algorithm for calculating similarity based on the synonym word forest and the similarity between two words calculated using the algorithm for calculating similarity based on the related word forest are summed to obtain the similarity between the first word in the first vocabulary list and all the words in the second vocabulary list.
[0039] The steps of calculating the similarity in step d) are:
[0040] d-1) determining whether the first word in the second vocabulary list and the corresponding word in the first vocabulary list belong to the same general category, if so, using the similarity calculation algorithm based on the synonym word forest to calculate the similarity of the two words, if not, using the similarity calculation algorithm based on the related word word forest to calculate the similarity of the two words;
[0041] d-2) using the weight coefficient, the similarity between two words calculated using the algorithm for calculating similarity based on the synonym word forest and the similarity between two words calculated using the algorithm for calculating similarity based on the related word forest are summed to obtain the similarity between the first word in the second vocabulary list and all the words in the first vocabulary list.
[0042] The steps of constructing the related word forest in step b-1) and step d-1) are:
[0043] b-1) Preprocess the wordsim-240 and wordsim-297 datasets. Both datasets use scores to calculate similarity. The scores of wordsim-240 are 0-10 and the scores of wordsim-297 are 0-5. Read the wordsim-240 and wordsim-297 datasets, adjust the score range of the wordsim-240 and wordsim-297 datasets to 0-1, merge the wordsim-240 and wordsim-297 datasets, retain word pairs with similarity greater than 0.2, and generate dataset 1;
[0044] b-2) Find the codes of the words in Dataset 1 in the synonym dictionary. If the same word has multiple codes, only the codes with the highest similarity between the two words are selected to generate Dataset 2. The format of each row in Dataset 2 is: code of word 1 - code of word 2 - similarity;
[0045] b-3) The codes in data 2 are all detailed codes of atomic word groups in the fifth layer. According to the given weight parameters of each layer, the codes and similarities of the first layer to the fourth layer of data set 2 are expanded to generate data set 3;
[0046] b-4) Remove all codes and similarities of words in each row belonging to the same category in data set 3, retain data of different categories, merge repeated word pairs, take the average of similarities, and generate data set 4;
[0047] b-5) Sort the word pairs in data set 4 in coding order, remove the word pairs with similarity lower than 0.1, and generate data set 5. Data set 5 is the final generated related word forest.
[0048] Finally, it should be noted that the above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art can still modify the technical solutions described in the aforementioned embodiments or replace some of the technical features therein by equivalents. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A text similarity calculation method based on Cilin and word vectors, It is characterized in that The steps include: a) performing word segmentation operations on the two texts to be processed respectively, and obtaining two vocabulary lists, the first vocabulary list contains N words, and the second vocabulary list contains M words; b) calculating the similarity between the first word in the first vocabulary list and all the words in the second vocabulary list, and taking the maximum value of the similarity as the similarity between the first word in the first vocabulary list and the second vocabulary list; c) Repeat step b) N-1 times until the similarities between the remaining N-1 words in the first vocabulary list and all the words in the second vocabulary list are calculated, and the average of the N similarities is taken as the similarity sim1 between the first vocabulary list and the second vocabulary list; d) calculating the similarity between the first word in the second vocabulary list and all the words in the first vocabulary list, and taking the maximum similarity as the similarity between the first word in the first vocabulary list and the second vocabulary list; e) Repeat step d) M-1 times until the similarities between the remaining M-1 words in the second vocabulary list and all the words in the first vocabulary list are calculated, and the average of the M similarities is taken as the similarity sim2 between the second vocabulary list and the first vocabulary list; f) Calculate the average of similarity sim1 and similarity sim2 to obtain the similarity of the two texts; The steps of calculating the similarity in step b) are: b-1) determining whether the first word in the first vocabulary list and the corresponding word in the second vocabulary list belong to the same category, if so, using the similarity calculation algorithm based on the synonym word forest to calculate the similarity of the two words, if not, using the similarity calculation algorithm based on the related word word forest to calculate the similarity of the two words; b-2) using the weight coefficient, summing the similarity of two words calculated using the algorithm for calculating similarity based on the synonym word forest and the similarity of two words calculated using the algorithm for calculating similarity based on the related word forest to obtain the similarity between the first word in the first vocabulary list and all the words in the second vocabulary list; The steps of calculating the similarity in step d) are: d-1) determining whether the first word in the second vocabulary list and the corresponding word in the first vocabulary list belong to the same general category, if so, using the similarity calculation algorithm based on the synonym word forest to calculate the similarity of the two words, if not, using the similarity calculation algorithm based on the related word word forest to calculate the similarity of the two words; d-2) using the weight coefficient, summing the similarity of the two words calculated using the algorithm for calculating similarity based on the synonym word forest and the similarity of the two words calculated using the algorithm for calculating similarity based on the related word forest to obtain the similarity between the first word in the second vocabulary list and all the words in the first vocabulary list; The steps of constructing the related word forest in step b-1) and step d-1) are: b-1) Preprocess the two data sets of wordsim-240 and wordsim-297. The score of wordsim-240 is 0-10 and the score of wordsim-297 is 0-5. Read the wordsim-240 data set and the wordsim-297 data set, adjust the score range of the wordsim-240 data set and the wordsim-297 data set to 0-1, merge the wordsim-240 data set and the wordsim-297 data set, retain the word pairs with similarity greater than 0.2, and generate data set 1; b-2) Find the codes of the words in Dataset 1 in the synonym dictionary. If the same word has multiple codes, only the codes with the highest similarity between the two words are selected to generate Dataset 2. The format of each row in Dataset 2 is: code of word 1 - code of word 2 - similarity; b-3) Expand the encoding and similarity of the first layer to the fourth layer of dataset 2 to generate dataset 3; b-4) Remove all codes and similarities of words in each row belonging to the same category in data set 3, retain data of different categories, merge repeated word pairs, take the average of similarities, and generate data set 4; b-5) Sort the word pairs in data set 4 in coding order, remove the word pairs with similarity lower than 0.1, and generate data set 5. Data set 5 is the final generated related word forest.
Citation Information
Patent Citations
Micro-blog short text classification method based on lexical chain feature extension and LDA (latent Dirichlet allocation) model
CN108920482A
A question similarity calculation method combining a synonym dictionary and a word embedding vector
CN109597992A
Chinese word similarity calculation method based on fusion strategy
CN109960786A
Text similarity calculation method and device, electronic equipment and storage medium
CN112131341A
