An adaptive dynamic word segmentation method
Through the adaptive dynamic word segmentation method, combined with domain-specific word matching, pattern matching and deep learning, the problem of data segmentation dimensions in different fields is solved, better word segmentation generalization and classification effects are achieved, and word segmentation can be intelligently selected according to the data field. dimensions.
Patent Information
- Application Number
- CN202210441833.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-25
- Publication Date
- 2024-10-18
- Estimated Expiration
- 2042-04-25
AI Technical Summary
Existing word segmentation technology has insufficient generalization in different fields and cannot adapt to the data segmentation dimensions of different fields, resulting in poor word segmentation effects.
Adopting an adaptive dynamic word segmentation method, the word segmentation dictionary is dynamically adjusted through a combination of domain-specific word matching, pattern matching and deep learning, and domain-specific dictionaries are generated using domain corpus and non-domain corpus. Combined with the double array Tire tree word segmentation method, domain classification and Participle.
It improves the generalization effect of word segmentation, automatically mines more domain-specific vocabulary, enriches the dictionary, dynamically calculates pattern matching scores, improves the field classification effect, and can intelligently select word segmentation dimensions.
Smart Images

Figure CN114881017B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of word segmentation systems, and in particular to an adaptive dynamic word segmentation method. Background Art
[0002] With the popularization of computers, the importance of information is increasing day by day. Faced with a variety of data on the Internet, how to mine the implicit information and maximize the value of the data is a hot topic for everyone to explore. Typical applications include search engines, intelligent question and answer, knowledge graphs, etc., and the basis of all applications is word segmentation technology. If word segmentation is done well, it is equivalent to taking over the first baton perfectly. Currently, the more well-known word segmentation systems include Jieba, Harbin Institute of Technology LTP, HanLP, Stanford's CoreNLP, etc. The word segmentation technologies used include dictionary matching, statistics, deep learning and other methods.
[0003] However, in actual application, data in different fields should have different segmentation dimensions. For example, the word "K powder" will be segmented into two words "K / powder" in the general field, but in the chemical field, it should be segmented into one word, ketamine, which is a narcotic drug and is often used as a drug. It plays an important role in drug arrests. However, the word segmentation method based on dictionary matching in the industry is mostly to put the words in a file and directly segment them according to a single dictionary, or to set up multiple dictionaries, but search the dictionaries in a fixed order when segmenting. This will result in the same data segmentation dimensions in different fields, and the word segmentation for special fields is not general enough.
[0004] In order to improve the generalization effect of word segmentation, we need to design a domain classification technology that combines domain-specific vocabulary, pattern matching and deep learning to dynamically adjust the dictionary that word segmentation relies on, so as to adaptively select the appropriate segmentation dimension according to different domain data. Therefore, we make improvements on this and propose an adaptive dynamic word segmentation method. Summary of the invention
[0005] In order to solve the above technical problems, the present invention provides the following technical solutions:
[0006] The present invention provides an adaptive dynamic word segmentation method, comprising the following steps:
[0007] S1. Input the original text directly into the domain-specific word matching module. If it matches the domain-specific dictionary, it directly enters the word segmentation of that domain.
[0008] S2. If the domain-specific vocabulary fails to match, the domain pattern matching module is entered, in which all preset domain patterns are matched, and the matching effect is finally evaluated. If the match is successful, the word segmentation module is directly entered to complete the word segmentation;
[0009] S3. If the domain pattern matching fails, the domain classification module is entered, and the deep learning model is used to integrate the pattern matching effect for domain classification, and finally the word segmentation is completed according to the classification results.
[0010] As a preferred technical solution of the present invention, the domain-specific word matching module in step S1 includes two processes: domain-specific vocabulary generation and domain-specific vocabulary matching. The specific steps of the domain-specific vocabulary generation are:
[0011] S1.1. Prepare domain corpus and non-domain corpus;
[0012] S1.2, perform preliminary word segmentation on the domain corpus and non-domain corpus respectively, and directly use jieba word segmentation to obtain the domain word set and non-domain dictionary;
[0013] S1.3, filter stop words from the domain word set;
[0014] S1.4. For Jieba, the general word segmentation granularity is usually very small. Several adjacent words can be combined into new words, including the following three methods:
[0015] Method 1: T test model:
[0016] in, is the sample mean, s 2 is the sample variance, N is the sample size, and u is the mean of the distribution. At this point, our null hypothesis is that n-grams appear independently. We traverse and calculate the t statistics of all 1-grams to 4-grams. At the confidence level of α = 0.005, for n-grams with t>2.576, we can reject the null hypothesis with 99.5% confidence, that is, we believe that the word is true with 99.5% confidence.
[0017] Method 2: Solidification model:
[0018] If the probability of word X and word Y appearing together divided by the probability of their respective occurrences is larger, it means that the probability of word XY appearing together is the highest;
[0019] Method 3: Degree of freedom model: H(U) = -∑ i p i logp i
[0020] If the words on both sides of words X and Y are more and more complex, that is, the degree of freedom of the words on both sides is higher, the word XY is more independent. If the degree of freedom on one side is very low, it means that word XY does not appear alone, and may be part of word XYZ.
[0021] S1.5. Using the ranking results of the three methods in S1.4, select a certain number of words from high to low confidence levels and add them to the Jieba word segmentation custom dictionary, re-segment the corpus data, and use the word2vec model to calculate the spatial vector of each word;
[0022] S1.6, take the intersection of the results of the three methods in S1.4 as the seed words, and the remaining words as candidate new words;
[0023] S1.7. For each seed word, sort the candidate new words by similarity and select the words with higher similarity, then vote and sort by the voting results to obtain the domain keywords;
[0024] S1.8. Take the difference between the domain keywords and the non-domain dictionary, and finally get the domain dictionary.
[0025] As a preferred technical solution of the present invention, the specific process of the field-specific vocabulary matching is as follows:
[0026] If only a single domain-specific word is matched, the dictionary of that domain is directly loaded and combined with the common dictionary to complete the word segmentation;
[0027] If multiple domain-specific dictionaries are matched at the same time, the text is segmented. If each segment of text only has a specific domain dictionary, word segmentation is completed in segments;
[0028] If there are still multiple domain dictionaries in a single paragraph, enter the domain matching mode.
[0029] As a preferred technical solution of the present invention, the domain pattern matching module in step S2 includes domain matching mode and pattern matching, and the domain matching mode is used to preset some matching modes for each domain and limit the distance between the preceding word and the succeeding word to be less than 15.
[0030] As a preferred technical solution of the present invention, the specific process of pattern matching is as follows:
[0031] S2.1. Load the preset domain matching pattern and perform pattern matching on the input text;
[0032] S2.2, matching with exclusive vocabulary, if only a pattern of a single field is matched, the input text is directly judged to be in that field;
[0033] S2.3. If the patterns of multiple fields are matched at the same time, they are processed in sections, and the pattern matching is performed separately on each section of text;
[0034] S2.4. If there are still domain conflicts in a certain text, this scheme designs a domain scoring function as follows: Assume that the domain with the largest number of successful matching patterns is recorded as matchmax , the one with the most times is recorded as match sec , the shortest is recorded as match min , then the score function score is:
[0035]
[0036] score is dynamically adjusted according to the result of pattern matching. max and match sec 、match min The greater the difference, the greater the score, that is, the more prominent the pattern characteristics of a certain field are; conversely, the smaller the score, the less obvious the pattern characteristics are;
[0037] S2.5. If the score value is above 0.85, the input text is determined to be in the corresponding field. Otherwise, the pattern that successfully matches each field is recorded, added to the pattern feature list, and enters the field classification module.
[0038] As a preferred technical solution of the present invention, the domain classification module in step S3 is used to classify texts that do not contain relevant domain-specific words and patterns, as well as to correct and supplement the pattern matching results. According to the characteristics of the input text, the HAN network is adopted. Its multi-layer attention mechanism can not only pay attention to "words" and find out the important word components in the sentence, but also pay attention to "sentences" and find out the important sentence components in the text.
[0039] As a preferred technical solution of the present invention, the word segmentation module in step S2 adopts a word segmentation method based on a dual array Tire tree, specifically including:
[0040] a) Double array Tire tree construction, the construction process is:
[0041] ⅰ. Receiving the transfer of character c from state s to t, the improved saving condition in the double array is: base[s]+c=t, check[t]=base[s];
[0042] ⅱ. Create the root node root, and set base[root] = 1;
[0043] ⅲ. Find the set of child nodes of root {root.children i}(i=1...n), so that check[root.children i ] = base[root] = 1;
[0044] ⅳ. Perform the following operations on each element element in root.children:
[0045] Find {element.children i}(i=1...n), if a character is at the end of the sequence, its child nodes include an empty node, whose code value is set to 0, find a value begin so that each check[begin i +element.children i .code]=0;
[0046] Set base[element.children i ]=begin i ;
[0047] Element.children i Recursively execute step iv. If an element has no leaf node children, then set base[element] to a negative value.
[0048] b) Participle:
[0049] Read the text to be segmented, traverse it backwards in sequence, and perform calculations based on the condition of i in the double array construction process. When base[s]=t, it means c=0. Record the position index, and Dic[index] is the word in the matched domain dictionary.
[0050] The beneficial effects of the present invention are:
[0051] This adaptive dynamic word segmentation method automatically mines more domain-specific vocabulary through multi-model fusion, enriches the domain dictionary, dynamically calculates the pattern matching score effect, and combines the features extracted by pattern matching with text semantics to improve the domain classification effect; finally, it adaptively adjusts the dependent dictionary according to the domain, so that the model is no longer restricted to one segmentation method, and can intelligently select the word segmentation dimension according to the data domain. BRIEF DESCRIPTION OF THE DRAWINGS
[0052] The accompanying drawings are used to provide a further understanding of the present invention and constitute a part of the specification. Together with the embodiments of the present invention, they are used to explain the present invention and do not constitute a limitation of the present invention. In the accompanying drawings:
[0053] Figure 1 It is an overall flow chart of an adaptive dynamic word segmentation method of the present invention;
[0054] Figure 2 It is a flow chart of domain-specific vocabulary generation of an adaptive dynamic word segmentation method of the present invention;
[0055] Figure 3 It is a schematic diagram of combining new words by an adaptive dynamic word segmentation method of the present invention;
[0056] Figure 4 It is a schematic diagram of the algorithm network structure of an adaptive dynamic word segmentation method of the present invention. Specific embodiments
[0057] The preferred embodiments of the present invention will be described below with reference to the accompanying drawings. It should be understood that the preferred embodiments described herein are only for explaining and understanding the present invention, and are not used to limit the present invention.
[0058] Embodiment: As Figure 1 shown, an adaptive dynamic word segmentation method of the present invention includes the following steps:
[0059] S1. Directly input the original text into the domain-specific word matching module. If a domain-specific dictionary of a certain domain is matched, directly enter the word segmentation of that domain;
[0060] S2. If the domain-specific word matching fails, enter the domain pattern matching module. In this module, all preset domain patterns are matched, and the matching effect is finally evaluated. If the matching is successful, directly enter the word segmentation module to complete the word segmentation;
[0061] S3. If the domain pattern matching fails, enter the domain classification module, use the deep learning model to fuse the pattern matching effect for domain classification, and finally complete the word segmentation according to the classification result.
[0062] Among them, in step S1, the domain-specific word matching module includes two processes: domain-specific word generation and domain-specific word matching. The flow chart of the domain-specific word generation is as Figure 2 shown, and the specific steps are:
[0063] S1.1. Prepare the domain corpus and the non-domain corpus;
[0064] S1.2. Perform preliminary word segmentation on the domain corpus and the non-domain corpus respectively. Jieba word segmentation can be directly used to obtain the domain word set and the non-domain dictionary;
[0065] S1.3. Filter stop words from the domain word set, such as "le", "de", etc.;
[0066] S1.4. For the general word segmentation granularity of Jieba, it is usually very small. As Figure 3 shown, several adjacent words can be combined into new words, including the following three methods:
[0067] Method 1: T-test model:
[0068] Among them, is the sample mean, s 2is the sample variance, N is the sample size, and u is the mean of the distribution. At this point, our null hypothesis is that n-grams appear independently. We traverse and calculate the t statistics of all 1-grams to 4-grams. At the confidence level of α = 0.005, for n-grams with t>2.576, we can reject the null hypothesis with 99.5% confidence, that is, we believe that the word is true with 99.5% confidence.
[0069] Method 2: Solidification model:
[0070] If the probability of word X and word Y appearing together divided by the probability of their respective occurrences is larger, it means that the probability of word XY appearing together is the highest;
[0071] Method 3: Degree of freedom model: H(U) = -∑ i p i logp i
[0072] If the words on both sides of words X and Y are more and more complex, that is, the degree of freedom of the words on both sides is higher, the word XY is more independent. If the degree of freedom on one side is very low, it means that word XY does not appear alone, and may be part of word XYZ.
[0073] S1.5. Using the ranking results of the three methods in S1.4, select a certain number of words from high to low confidence levels and add them to the Jieba word segmentation custom dictionary, re-segment the corpus data, and use the word2vec model to calculate the spatial vector of each word;
[0074] S1.6, take the intersection of the results of the three methods in S1.4 as the seed words, and the remaining words as candidate new words;
[0075] S1.7. For each seed word, sort the candidate new words by similarity and select the words with higher similarity, then vote and sort by the voting results to obtain the domain keywords;
[0076] S1.8. Take the difference between the domain keywords and the non-domain dictionary, and finally get the domain dictionary.
[0077] The specific process of domain-specific vocabulary matching is as follows:
[0078] If only a single domain-specific word is matched, the dictionary of that domain is directly loaded and combined with the common dictionary to complete the word segmentation;
[0079] If multiple domain-specific dictionaries are matched at the same time, the text is segmented. If each segment of text only has a specific domain dictionary, word segmentation is completed in segments;
[0080] If there are still multiple domain dictionaries in a single paragraph, enter the domain matching mode.
[0081] Among them, the domain pattern matching module in step S2 includes domain matching mode and pattern matching. The domain matching mode is used to preset some matching modes for each domain and limit the distance between the preceding word and the succeeding word to be less than 15. For example, the matching mode in the traffic accident domain can be: *** traffic accident occurs, *** traffic accident is caused, *** traffic accident is caused, etc.
[0082] The specific process of pattern matching is as follows:
[0083] S2.1. Load the preset domain matching pattern and perform pattern matching on the input text;
[0084] S2.2, matching with exclusive vocabulary, if only a pattern of a single field is matched, the input text is directly judged to be in that field;
[0085] S2.3. If the patterns of multiple fields are matched at the same time, they are processed in sections, and the pattern matching is performed separately on each section of text;
[0086] S2.4. If there are still domain conflicts in a certain text, this scheme designs a domain scoring function as follows: Assume that the domain with the largest number of successful matching patterns is recorded as match max , the one with the most times is recorded as match sec , the shortest is recorded as match min , then the score function score is:
[0087]
[0088] score is dynamically adjusted according to the result of pattern matching. max and match sec 、match min The greater the difference, the greater the score, that is, the more prominent the pattern characteristics of a certain field are; conversely, the smaller the score, the less obvious the pattern characteristics are;
[0089] S2.5. If the score value is above 0.85, the input text is determined to be in the corresponding field. Otherwise, the pattern that successfully matches each field is recorded, added to the pattern feature list, and enters the field classification module.
[0090] The domain classification module in step S3 is used to classify texts that do not contain domain-specific words and patterns, as well as to correct and supplement the pattern matching results. The HAN network is used for the characteristics of the input text. Its multi-layer attention mechanism can not only pay attention to "words" and find important word components in sentences, but also pay attention to "sentences" and find important sentence components in texts. It can not only be used to classify short texts, but also solve the problem of decreased accuracy of general classification methods for long texts. The algorithm network structure is as follows: Figure 4 As shown in the figure, this scheme concatenates the pattern features obtained by the pattern matching module with the input text representation to obtain the embedding input HAN network, captures the feature information of the text through pattern matching, and enhances the classification effect of the model.
[0091] The word segmentation module in step S2 adopts a word segmentation method based on a dual-array Tire tree. The basic concept of the dual-array Tire tree is to compress the Tire tree. It has all the advantages of the Tire tree, not only has high query efficiency, but also can save storage space and has a wide range of applications.
[0092] a) Double array Tire tree construction:
[0093] 1) Several important concepts in the Tire tree:
[0094] state: status;
[0095] code: state transition value;
[0096] base: An array representing the base address of successor nodes. Leaf nodes have no successors.
[0097] Marks the end of a character sequence;
[0098] check: identifies the address of the predecessor node.
[0099] 2) The construction process is:
[0100] ⅰ. Receiving the transfer of character c from state s to t, the improved saving condition in the double array is: base[s]+c=t, check[t]=base[s];
[0101] ⅱ. Create the root node root, and set base[root] = 1;
[0102] ⅲ. Find the set of child nodes of root {root.children i}(i=1...n), so that check[root.children i ] = base[root] = 1;
[0103] ⅳ. Perform the following operations on each element element in root.children:
[0104] Find {element.children i}(i=1...n), if a character is at the end of the sequence, its child nodes include an empty node, whose code value is set to 0, find a value begin so that each check[begin i +element.children i .code]=0;
[0105] Set base[element.children i ]=begin i ;
[0106] Element.children i Recursively execute step iv. If an element has no leaf node children, then set base[element] to a negative value.
[0107] b) Participle:
[0108] Read the text to be segmented, traverse it backwards in sequence, and perform calculations based on the condition of i in the double array construction process. When base[s]=t, it means c=0 (a leaf node is encountered). Record the position index, and Dic[index] is the word in the matched domain dictionary.
[0109] In summary, the technical solution provided by the present invention automatically mines more domain-specific vocabulary through multi-model fusion, enriches the domain dictionary, dynamically calculates the pattern matching score effect, and combines the features extracted by pattern matching with text semantics to improve the domain classification effect; finally, the dictionary relied on is adaptively adjusted according to the domain, so that the model is no longer restricted to one segmentation method, and can intelligently select the word segmentation dimension according to the data domain.
[0110] 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 is 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. An adaptive dynamic word segmentation method, characterized in that: The steps include: S1. Input the original text directly into the domain-specific word matching module. If it matches the domain-specific dictionary, it directly enters the word segmentation of that domain. S2. If the domain-specific vocabulary fails to match, the domain pattern matching module is entered, in which all preset domain patterns are matched, and the matching effect is finally evaluated. If the match is successful, the word segmentation module is directly entered to complete the word segmentation; S3. If the domain pattern matching fails, the module enters the domain classification module, and uses the deep learning model to integrate the pattern matching effect for domain classification, and finally completes the word segmentation based on the classification results; The domain-specific word matching module in step S1 includes two processes: domain-specific word generation and domain-specific word matching. The specific steps of domain-specific word generation are: S1.
1. Prepare domain corpus and non-domain corpus; S1.2, perform preliminary word segmentation on the domain corpus and non-domain corpus respectively, and directly use jieba word segmentation to obtain the domain word set and non-domain dictionary; S1.3, filter stop words from the domain word set; S1.4, for Jieba general word segmentation, the granularity is small, and several adjacent words are combined into new words, including the following three methods: Method 1: T test model: in, is the sample mean, s 2 is the sample variance, N is the sample size, and u is the mean of the distribution. At this point, our null hypothesis is that n-grams appear independently. We traverse and calculate the t statistics for all 1-grams to 4-grams. At the confidence level of α = 0.005, for n-grams with t>2.576, we have 99.5% confidence to reject the null hypothesis, that is, we have 99.5% confidence that the word is true. Method 2: Solidification model: If the probability of word X and word Y appearing together divided by the probability of their respective occurrences is larger, it means that the probability of word XY appearing together is the highest; Method 3: Degree of freedom model: H(U) = -∑ i p i logp i If the words on both sides of words X and Y are more complex, that is, the degree of freedom of the words on both sides is higher, the word XY is more independent. If the degree of freedom on one side is low, it means that word XY does not appear alone, but is part of word XYZ. S1.
5. Use the ranking results of the three methods in S1.4, add the words selected from high to low confidence levels into the Jieba word segmentation custom dictionary, re-segment the corpus data, and use the word2vec model to calculate the spatial vector of each word; S1.6, take the intersection of the results of the three methods in S1.4 as the seed words, and the remaining words as candidate new words; S1.
7. For each seed word, sort the candidate new words by similarity and select the words with high similarity, then vote and sort by the voting results to obtain the domain keywords; S1.8, taking the difference between the domain keywords and the non-domain dictionary, and finally obtaining the domain dictionary; The domain pattern matching module in step S2 includes domain matching mode and pattern matching, wherein the domain matching mode is used to preset some matching modes for each domain and limit the distance between the preceding word and the succeeding word to be less than 15; The domain classification module in step S3 is used to classify texts that do not contain domain-specific words and patterns, and to correct and supplement the pattern matching results. The HAN network is used for the characteristics of the input text. Its multi-layer attention mechanism can not only pay attention to "words" and find out the important word components in the sentence, but also pay attention to "sentences" and find out the important sentence components in the text; The word segmentation module in step S2 adopts a word segmentation method based on a dual array Tire tree, specifically including: a) Double array Tire tree construction, the construction process is: ⅰ. Receiving the transfer of character c from state s to t, the improved saving condition in the double array is: base[s]+c=t, check[t]=base[s]; ⅱ. Create the root node root, and set base[root] = 1; ⅲ. Find the set of child nodes of root {root.children i }(i=1...n), so that check[root.children i ] = base[root] = 1; ⅳ. Perform the following operations on each element element in root.children: Find {element.children i }(i=1...n), if a character is at the end of the sequence, its child nodes include an empty node, whose code value is set to 0, find a value begin so that each check[begin i +element.children i .code]=0; Set base[element.children i ]=begin i ; Element.children i Recursively execute step iv. If an element has no leaf node children, then set base[element] to a negative value. b) Participle: Read the text to be segmented, traverse it backwards in sequence, and perform calculations based on the condition of i in the double array construction process. When base[s]=t, it means c=0. Record the position index, and Dic[index] is the word in the matched domain dictionary.
2. The adaptive dynamic word segmentation method according to claim 1, characterized in that: The specific process of matching domain-specific vocabulary is as follows: If only a single domain-specific word is matched, the dictionary of that domain is directly loaded and combined with the common dictionary to complete the word segmentation; If multiple domain-specific dictionaries are matched at the same time, the text is segmented. If each segment of text only has a specific domain dictionary, word segmentation is completed in segments; If there are still multiple domain dictionaries in a single paragraph, enter the domain matching mode.
3. The adaptive dynamic word segmentation method according to claim 1, characterized in that: The specific process of pattern matching is as follows: S2.
1. Load the preset domain matching pattern and perform pattern matching on the input text; S2.2, matching with exclusive vocabulary, if only a pattern of a single field is matched, the input text is directly judged to be in that field; S2.
3. If the patterns of multiple fields are matched at the same time, they are processed in sections, and the pattern matching is performed separately on each section of text; S2.
4. If there are still domain conflicts in a certain text, this scheme designs a domain scoring function as follows: Assume that the domain with the largest number of successful matching patterns is recorded as match max , the one with the most times is recorded as match sec , the shortest is recorded as match min , then the score function score is: score is dynamically adjusted according to the result of pattern matching. max and match sec 、match min The greater the difference, the greater the score, that is, the more prominent the pattern characteristics of a certain field are; conversely, the smaller the score, the less obvious the pattern characteristics are; S2.
5. If the score value is above 0.85, the input text is determined to be in the corresponding field. Otherwise, the pattern that successfully matches each field is recorded, added to the pattern feature list, and enters the field classification module.
Citation Information
Patent Citations
Self-adaptive Chinese word segmentation method and system for power industry and medium
CN110413998A
Text data word segmentation method and device and electronic equipment
CN111241833A
