Text clustering method, device, electronic device and computer storage medium
By extracting and filtering text keywords, constructing a global keyword matrix and performing dimensionality reduction processing, the problems of low text clustering efficiency and resource waste in the existing technology are solved, and efficient text clustering effects are achieved.
Patent Information
- Application Number
- CN202010628249.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-07-01
- Publication Date
- 2024-08-27
- Estimated Expiration
- 2040-07-01
AI Technical Summary
When processing large amounts of text, existing text clustering methods increase memory overhead due to the large number of word segments, which reduces clustering efficiency. They also fail to effectively reduce the dimensionality of text matrices, resulting in high sparsity and additional resource consumption.
By extracting text keywords and filtering them, global keywords are obtained, a text matrix is constructed based on the global keywords, and dimensionality reduction is performed to reduce the amount of data and memory overhead, thereby improving clustering efficiency.
It reduces memory overhead and the amount of data processed, improves the efficiency of text clustering, reduces sparsity, and avoids additional resource loss. It is suitable for scenarios such as network behavior management platforms.
Smart Images

Figure CN111930883B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of natural language processing, and in particular to a text clustering method, device, electronic device and computer storage medium. Background Art
[0002] Text clustering is one of the basic tasks in the field of natural language processing. It uses unsupervised algorithms to categorize texts with the same or similar content. The analysis results can be used for subsequent sensitive text recognition tasks.
[0003] In the related art, for text clustering methods, word segmentation is usually performed after reading the text content, and then the original word segmentation results of each text are directly aggregated, and then feature extraction and clustering calculations are performed; since the original number of word segments of each text is often very large, the number of word segments of all texts after aggregation will be even larger, which in turn increases memory overhead, resulting in an increase in data processing volume and reduces the efficiency of text clustering. Summary of the invention
[0004] The embodiment of the present invention provides a text clustering method, device, electronic device and computer storage medium. The method can reduce memory overhead, reduce the amount of data processed, and thus improve the efficiency of text clustering.
[0005] The technical solution of the embodiment of the present invention is achieved as follows:
[0006] The present invention provides a text clustering method, the method comprising:
[0007] Obtain N texts to be processed, and extract keywords from each of the N texts to be processed; wherein N is an integer greater than 1;
[0008] Screening the keywords of the N to-be-processed texts to obtain global keywords;
[0009] Based on the global keywords, the N texts to be processed are clustered.
[0010] Optionally, the filtering of keywords of the N to-be-processed texts to obtain global keywords includes:
[0011] The keywords of the N to-be-processed texts are screened according to the word frequencies and / or weights of the keywords of the N to-be-processed texts to obtain the global keywords.
[0012] Optionally, filtering the keywords of the N to-be-processed texts according to the word frequencies of the keywords of the N to-be-processed texts to obtain the global keywords includes:
[0013] When the word frequency of any keyword among the keywords of the N texts to be processed is less than or equal to the first threshold or greater than or equal to the second threshold, the any keyword is deleted from the keywords of the N texts to be processed to obtain the global keyword; the first threshold is less than the second threshold.
[0014] Optionally, filtering the keywords of the N to-be-processed texts according to the weights of the keywords of the N to-be-processed texts to obtain the global keywords includes:
[0015] Sorting the weights of the keywords of the N to-be-processed texts to obtain a first sorting result;
[0016] Based on the first sorting result, the first L keywords in the sorting result are used as the global keywords; wherein L is an integer greater than 0.
[0017] Optionally, the keywords of the N to-be-processed texts are screened according to the word frequencies and weights of the keywords of the N to-be-processed texts to obtain the global keywords, including:
[0018] When the frequency of any keyword among the keywords of the N to-be-processed texts is less than or equal to the first threshold or greater than or equal to the second threshold, the any keyword is deleted from the keywords of the N to-be-processed texts to obtain a candidate keyword set; the first threshold is less than the second threshold;
[0019] Sorting the weights of the keywords in the candidate keyword set to obtain a second sorting result;
[0020] Based on the second sorting result, the first M keywords in the sorting result are used as the global keywords; wherein M is an integer greater than 0.
[0021] Optionally, clustering the N to-be-processed texts based on the global keywords includes:
[0022] Determine, according to the global keywords, the text matrices corresponding to the N texts to be processed;
[0023] Performing dimensionality reduction processing on the text matrix to obtain a text matrix after dimensionality reduction processing;
[0024] Based on the text matrix after the dimensionality reduction process, the N texts to be processed are clustered.
[0025] Optionally, extracting keywords from each of the N texts to be processed includes:
[0026] The keywords of each of the N texts to be processed are extracted in parallel.
[0027] Optionally, the method is applied to a network behavior management platform.
[0028] The present invention provides a text clustering device, the device comprising:
[0029] An extraction module, used to obtain N texts to be processed, and extract keywords from each of the N texts to be processed; wherein N is an integer greater than 1;
[0030] A screening module, used for screening the keywords of the N to-be-processed texts to obtain global keywords;
[0031] A clustering module is used to cluster the N to-be-processed texts based on the global keywords.
[0032] Optionally, the screening module is used to screen the keywords of the N to-be-processed texts to obtain global keywords, including:
[0033] The keywords of the N to-be-processed texts are screened according to the word frequencies and / or weights of the keywords of the N to-be-processed texts to obtain the global keywords.
[0034] Optionally, the screening module is used to screen the keywords of the N to-be-processed texts according to the word frequencies of the keywords of the N to-be-processed texts to obtain the global keywords, including:
[0035] When the word frequency of any keyword among the keywords of the N texts to be processed is less than or equal to the first threshold or greater than or equal to the second threshold, the any keyword is deleted from the keywords of the N texts to be processed to obtain the global keyword; the first threshold is less than the second threshold.
[0036] Optionally, the screening module is used to screen the keywords of the N to-be-processed texts according to the weights of the keywords of the N to-be-processed texts to obtain the global keywords, including:
[0037] Sorting the weights of the keywords of the N to-be-processed texts to obtain a first sorting result;
[0038] Based on the first sorting result, the first L keywords in the sorting result are used as the global keywords; wherein L is an integer greater than 0.
[0039] Optionally, the screening module is used to screen the keywords of the N to-be-processed texts according to the word frequencies and weights of the keywords of the N to-be-processed texts to obtain the global keywords, including:
[0040] When the frequency of any keyword among the keywords of the N to-be-processed texts is less than or equal to the first threshold or greater than or equal to the second threshold, the any keyword is deleted from the keywords of the N to-be-processed texts to obtain a candidate keyword set; the first threshold is less than the second threshold;
[0041] Sorting the weights of the keywords in the candidate keyword set to obtain a second sorting result;
[0042] Based on the second sorting result, the first M keywords in the sorting result are used as the global keywords; wherein M is an integer greater than 0.
[0043] Optionally, the clustering module is used to cluster the N to-be-processed texts based on the global keywords, including:
[0044] Determine, according to the global keywords, the text matrices corresponding to the N texts to be processed;
[0045] Performing dimensionality reduction processing on the text matrix to obtain a text matrix after dimensionality reduction processing;
[0046] Based on the text matrix after the dimensionality reduction process, the N texts to be processed are clustered.
[0047] Optionally, the extraction module is used to extract keywords from each of the N texts to be processed, including:
[0048] The keywords of each of the N texts to be processed are extracted in parallel.
[0049] Optionally, the device is applied to a network behavior management platform.
[0050] The present invention provides an electronic device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, a text clustering method provided by one or more of the above-mentioned technical solutions is implemented.
[0051] The present invention provides a computer storage medium, wherein the computer storage medium stores a computer program; after the computer program is executed, the text clustering method provided by one or more of the above-mentioned technical solutions can be implemented.
[0052] The embodiment of the present invention provides a text clustering method, device, electronic device and computer storage medium, the method comprising: obtaining N to-be-processed texts, extracting keywords of each of the N to-be-processed texts; wherein N is an integer greater than 1; screening the keywords of the N to-be-processed texts to obtain global keywords; and clustering the N to-be-processed texts based on the global keywords. Thus, by screening the keywords of the extracted N to-be-processed texts, memory overhead can be reduced, the amount of data to be processed can be reduced, and thus the efficiency of text clustering can be improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0053] Figure 1 A flowchart of a text clustering method according to an embodiment of the present invention;
[0054] Figure 2 A schematic diagram of an application scenario of an embodiment of the present invention;
[0055] Figure 3 A schematic diagram of a flow chart of another text clustering method according to an embodiment of the present invention;
[0056] Figure 4 A schematic diagram of the composition structure of text clustering according to an embodiment of the present invention;
[0057] Figure 5 This is a schematic structural diagram of an electronic device provided by the present invention. DETAILED DESCRIPTION
[0058] The present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.
[0059] Text clustering is mainly based on the famous clustering hypothesis, that is, the texts of the same category are more similar, while the texts of different categories are less similar. As an unsupervised machine learning method, text clustering does not require a training process or manual pre-labeling of text categories, so it has certain flexibility and high automation processing capabilities. It has become an important means to effectively organize, summarize and navigate text information.
[0060] In the related art, the text clustering method has the following disadvantages:
[0061] 1) In the related art, for text clustering methods, word segmentation is usually performed after reading the text content, and then the original word segmentation results of each text are directly summarized, and then feature extraction and clustering calculations are performed. Since the original number of word segments of each text is often very large, the number of word segments of all texts after aggregation is even larger, resulting in an increase in the amount of data that needs to be processed, reducing the efficiency of text clustering.
[0062] 2) In the related art, although some text clustering methods extract keywords after word segmentation of the text content, they do not further extract keywords from all texts after aggregating all the texts, nor do they perform dimensionality reduction processing on the text matrix formed based on keywords, which makes the text matrix highly sparse; moreover, they need to rely on external word vectors. This step requires loading the word vector library, which will introduce additional memory overhead and increase resource loss.
[0063] Based on the above technical problems, the present invention provides a text clustering method. The technical solution of the present invention will be clearly and completely described below in conjunction with the accompanying drawings in the present invention.
[0064] In some embodiments of the present invention, the text clustering method can be implemented using a processor in a text clustering device, and the processor can be at least one of an application specific integrated circuit (ASIC), a digital signal processor (DSP), a digital signal processing device (DSPD), a programmable logic device (PLD), a field programmable gate array (FPGA), a central processing unit (CPU), a controller, a microcontroller, and a microprocessor.
[0065] Figure 1 Flow chart of a text clustering method according to an embodiment of the present invention. Figure 1 As shown, the method includes:
[0066] Step 100: Obtain N texts to be processed, and extract keywords from each of the N texts to be processed; wherein N is an integer greater than 1.
[0067] Exemplarily, the format of the text to be processed may include: text in Hyper Text Markup Language (HTML) format, text in Word format, text in Portable Document Format (PDF) format, etc., which is not limited in the embodiment of the present invention.
[0068] In one implementation, before extracting keywords from each text to be processed, each text to be processed needs to be segmented; the segmentation can reassemble a continuous character sequence into a word sequence according to certain specifications.
[0069] Exemplarily, the contents of the N to-be-processed texts may be composed of Chinese characters, English characters, or mixed characters of other different languages, which is not limited in the embodiment of the present invention.
[0070] In an embodiment of the present invention, a predetermined word segmentation algorithm can be used to segment each text to be processed; illustratively, English word segmentation can be implemented using StanfordNLP, which is open source from Stanford University, and Chinese word segmentation can be implemented using pkuseg, which is open source from Peking University; the specific word segmentation algorithm used can be set according to the actual application scenario, and the embodiment of the present invention does not limit it.
[0071] In the embodiment of the present invention, keywords can represent key information of the text to be processed; after the acquired N texts to be processed are segmented, word sequences corresponding to the N texts to be processed are obtained; and keywords of the word sequence of each text to be processed are extracted.
[0072] Exemplarily, a predetermined text keyword extraction method can be used to extract keywords for each text to be processed; for example, keyword extraction is performed using a term frequency-inverse document frequency (TF-IDF) text keyword extraction method, a TextRank text keyword extraction algorithm, or a Word2Vec text keyword extraction method; the specific text keyword extraction method used can be set according to the actual application scenario, and is not limited by the embodiments of the present invention.
[0073] In one implementation, the extracting the keywords of each of the N texts to be processed may include: performing parallel extraction on the keywords of each of the N texts to be processed.
[0074] In the embodiment of the present invention, since the keyword extraction processes between the various texts to be processed are unrelated, a multi-threaded execution method can be used to extract the keywords between the various texts to be processed in parallel to achieve a concurrent acceleration effect.
[0075] Exemplarily, when 1000 texts to be processed are obtained, that is, when N is 1000, keywords of the 1000 texts to be processed are extracted in parallel.
[0076] It can be seen that when the number N of texts to be processed is large, the keyword extraction speed can be optimized by extracting keywords of the texts to be processed in parallel, thereby improving the text clustering efficiency.
[0077] Step 101: Screen the keywords of the N texts to be processed to obtain global keywords.
[0078] In the embodiment of the present invention, after obtaining the keywords of N to-be-processed texts, the keywords of the N to-be-processed texts are screened, and the keywords obtained after the screening are used as global keywords.
[0079] In the embodiment of the present invention, since each text to be processed corresponds to a certain number of keyword extractions, when the number of texts to be processed N is large, the number of keyword extractions of all texts to be processed is still large; at this time, it is necessary to further screen the keywords of the N texts to be processed to reduce the number of keyword extractions and reduce memory overhead.
[0080] In one implementation, the screening of the keywords of the N texts to be processed to obtain global keywords may include: screening the keywords of the N texts to be processed according to the word frequencies and / or weights of the keywords of the N texts to be processed to obtain the global keywords.
[0081] In the embodiment of the present invention, the word frequency may represent the frequency of each keyword appearing in N texts to be processed; that is, the word frequency of each keyword is determined based on the number of times each keyword appears in the N texts to be processed and the total number of keywords in the N texts to be processed.
[0082] In an embodiment of the present invention, the weight can measure the importance of each keyword in N texts to be processed; illustratively, the TF-IDF method can be used to perform weighted processing on the keywords of the N texts to be processed; for example, if a keyword only appears in a few texts to be processed, it can be considered that the keyword can better represent the meaning of the current text to be processed, and thus, the weight of the keyword is greater; if a keyword appears in a large number of texts to be processed, it can be considered that the keyword is unclear about what it represents, and thus, the weight of the keyword is relatively small.
[0083] In the embodiment of the present invention, the keywords of the N texts to be processed are screened according to the frequency of occurrence of each keyword in the N texts to be processed and the importance of each keyword in the N texts to be processed to obtain global keywords.
[0084] In one embodiment, filtering the keywords of the N texts to be processed according to the word frequencies of the keywords of the N texts to be processed to obtain the global keywords may include: when the word frequency of any keyword of the keywords of the N texts to be processed is less than or equal to a first threshold or greater than or equal to a second threshold, deleting any keyword from the keywords of the N texts to be processed to obtain the global keywords; the first threshold is less than the second threshold.
[0085] In one implementation, the word frequencies of the keywords of N texts to be processed can be calculated, and the word frequency of each keyword can be compared with a first threshold and a second threshold; based on the comparison results, keywords with a word frequency less than or equal to the first threshold are deleted, and keywords with a word frequency greater than or equal to the second threshold are also deleted; the keywords obtained after deletion are used as global keywords.
[0086] Exemplarily, for the six keywords, keyword A1, keyword B1, keyword C1, keyword D1, keyword E1 and keyword F1, if their word frequencies are 0.3, 0.5, 0.9, 0.1, 0.7 and 0.8 respectively; when the first threshold is 0.3, keyword A1 and keyword D1 are deleted; when the second threshold is 0.8, keyword C1 and keyword F1 are deleted; it can be seen that after comparing the word frequencies of the above six keywords with the first threshold and the second threshold, the final global keywords obtained are: keyword B1 and keyword E1.
[0087] It should be noted that there is no restriction on the execution order of comparing the keyword frequency with the first threshold and the second threshold; that is, it can be compared with the first threshold first and then with the second threshold; it can also be compared with the second threshold first and then with the first threshold.
[0088] Here, since low-frequency keywords often belong to only a very small number of texts, they do not have enough commonality with other texts and easily cause the text matrix to be sparse, they should be deleted; in addition, the reason for deleting high-frequency keywords is that these keywords appear too frequently, and these keywords often appear in texts of different categories. They are of little help for text clustering and division, and should also be deleted.
[0089] It can be seen that the above screening method can delete low-frequency keywords and high-frequency keywords in the N to-be-processed texts. Since low-frequency keywords and high-frequency keywords have little effect on text clustering, after deletion, the number of keywords can be further reduced, reducing the sparsity of the text matrix.
[0090] In one embodiment, filtering the keywords of the N texts to be processed according to the weights of the keywords of the N texts to be processed to obtain the global keywords can include: sorting the weights of the keywords of the N texts to be processed to obtain a first sorting result; based on the first sorting result, taking the first L keywords in the sorting result as the global keywords; wherein L is an integer greater than 0.
[0091] In one implementation, the weights of the keywords of N to-be-processed texts may be calculated, the weights of all the keywords may be sorted, the first L keywords in the sorted results may be used as global keywords, and the keywords after the L keywords may be deleted.
[0092] Exemplarily, for the six keywords A2, B2, C2, D2, E2 and F2, if their weights are 0.3, 0.5, 0.9, 0.1, 0.7 and 0.8 respectively; the weights are sorted in descending order, and the sorting results are 0.9, 0.8, 0.7, 0.5, 0.3 and 0.1; when L is 3, C2, F2 and E2 are used as global keywords, and B, A2 and D2 are deleted; when L is 4, C2, F2, E2 and B2 are used as global keywords, and A2 and D2 are deleted.
[0093] Since high-weight keywords can well represent the meaning of the text to be processed, the meaning represented by low-weight keywords is unclear; therefore, the high-weight keywords in the N texts to be processed are retained and the low-weight keywords are deleted through the weight sorting results, which can greatly reduce memory overhead while deleting useless semantic information.
[0094] In one embodiment, the keywords of the N texts to be processed are screened according to the word frequencies and weights of the keywords of the N texts to be processed to obtain the global keywords, which may include: when the word frequency of any keyword of the keywords of the N texts to be processed is less than or equal to a first threshold or greater than or equal to a second threshold, deleting the any keyword from the keywords of the N texts to be processed to obtain a candidate keyword set; the first threshold is less than the second threshold; sorting the weights of the keywords in the candidate keyword set to obtain a second sorting result; based on the second sorting result, taking the first M keywords in the sorting result as the global keywords; wherein M is an integer greater than 0.
[0095] In an embodiment of the present invention, the word frequencies of keywords of N to-be-processed texts are first obtained, and the word frequency of each keyword is compared with a first threshold and a second threshold; based on the comparison result, keywords with a word frequency less than or equal to the first threshold are deleted, and keywords with a word frequency greater than or equal to the second threshold are also deleted; the keywords obtained after two deletions are used as a candidate keyword set; further, the weight of each keyword in the candidate keyword set is determined and sorted, and based on the sorting result, the first M keywords in the sorting result are used as global keywords, and the keywords ranked after M are deleted.
[0096] Exemplarily, for the six keywords, keyword A3, keyword B3, keyword C3, keyword D3, keyword E3 and keyword F3, if their word frequencies are respectively: 0.3, 0.5, 0.9, 0.1, 0.7, 0.8; when the first threshold is 0.1, keyword D3 is deleted; when the second threshold is 0.9, keyword C3 is deleted; according to the result after deletion, the candidate keyword set is obtained: [keyword A3 keyword B3 keyword E3 keyword F3]; if the weights corresponding to each keyword in the candidate set are: 0.5, 0.9, 0.3, 0.6; sort the weights in descending order, and the sorting results are: 0.9, 0.6, 0.5, 0.3; when M is 3, keyword B3, keyword F3 and keyword A3 are used as global keywords, and keyword E3 is deleted.
[0097] It can be seen that by screening keywords, the memory overhead can be greatly reduced and the data processing speed can be improved while sacrificing a small amount of semantic information.
[0098] Step 102: Clustering the N to-be-processed texts based on the global keywords.
[0099] In an embodiment of the present invention, after determining the global keywords, each global keyword is represented by a text vector; a text matrix corresponding to N texts to be processed is determined based on the text vector; and the text matrix corresponding to the N texts to be processed is clustered using a clustering algorithm.
[0100] Exemplarily, the K-Means (K-Means clustering algorithm), the hierarchical clustering algorithm and the density-based spatial clustering of applications with noise (DBSCAN) algorithm can be used to cluster the text matrices corresponding to N texts to be processed; wherein, the K-Means algorithm requires the user to specify the number of clusters when used; while the hierarchical clustering algorithm and the DBSCAN algorithm do not require the user to specify the number of clusters in advance; the specific clustering algorithm used can be set according to the actual scenario, and the embodiment of the present invention does not limit it.
[0101] In one embodiment, the above different clustering algorithm methods can be selected to cluster the text matrix according to the actual scene requirements. When the actual number of text categories is clear, the number of clusters T can be manually specified, and the K-Means algorithm method can be used for clustering; in actual situations, since users are often unclear about the actual number of text categories, it is necessary to cluster based on the algorithm of sample similarity or density. In this scenario, a hierarchical clustering algorithm or a DBSCAN algorithm can be used for clustering.
[0102] It can be seen that the embodiments of the present invention are compatible with different usage scenario requirements, that is, they can effectively meet the two specific demand scenarios of "knowing the actual number of text categories in advance" and "not knowing the actual number of text categories", and thus, have a wider range of applicability in practical applications.
[0103] In one embodiment, clustering the N texts to be processed based on the global keywords may include: determining a text matrix corresponding to the N texts to be processed based on the global keywords; performing dimensionality reduction processing on the text matrix to obtain a text matrix after dimensionality reduction processing; and clustering the N texts to be processed based on the text matrix after dimensionality reduction processing.
[0104] In one implementation, after determining text matrices corresponding to N to-be-processed texts according to the text vectors of each global keyword, the text matrices are subjected to dimensionality reduction and regularization; and the dimensionality-reduced text matrices are clustered using a clustering algorithm.
[0105] Exemplarily, the dimensionality reduction algorithms for performing dimensionality reduction processing on the text matrix may include: principal component analysis (PCA), singular value decomposition (SVD), auto encoder (AE) and other algorithms, which are not limited in the embodiments of the present invention.
[0106] For example, when the number of texts to be processed is 1000 and the number of global keywords is 2000, the determined text matrix size is 1000*2000. After dimensionality reduction processing, the text matrix size obtained is 1000*80. The clustering algorithm is used to cluster the 1000*80 text matrix.
[0107] It can be seen that the dimensionality reduction processing of the text matrix can further avoid the problem of sparse feature matrix, making the text matrix a low-dimensional dense matrix and improving the efficiency of text clustering.
[0108] The embodiment of the present invention provides a text clustering method, device, electronic device and computer storage medium, the method comprising: obtaining N to-be-processed texts, extracting keywords of each of the N to-be-processed texts; wherein N is an integer greater than 1; screening the keywords of the N to-be-processed texts to obtain global keywords; and clustering the N to-be-processed texts based on the global keywords. Thus, by screening the keywords of the extracted N to-be-processed texts, memory overhead can be reduced, the amount of data to be processed can be reduced, and thus the efficiency of text clustering can be improved.
[0109] The present invention is further described below in conjunction with an application scenario.
[0110] The text clustering method of the embodiment of the present invention can be applied to a network behavior management platform; Figure 2 is a schematic diagram of an application scenario of an embodiment of the present invention, such as Figure 2 As shown, it includes: a user terminal 200, a network side device 201 and a network behavior management platform 202; here, the network side device 201 can be a server, a router, a switch, etc.
[0111] The user terminal 200 sends the text to be processed to the network side device 201, and the network behavior management platform 202 clusters the text to be processed according to the restriction level of the text to be processed to obtain a clustering result; according to the clustering result, the corresponding keywords under different restriction levels are determined, and the keywords are used to extract and match the text to be processed that the user terminal 200 subsequently sends to the network side device 201; according to the keyword matching result, it is determined whether to restrict access to the text to be processed; thereby effectively preventing the leakage of files or the tracing of leaked files.
[0112] In order to better reflect the purpose of the present invention, further examples are given based on the above embodiments of the present invention.
[0113] Figure 3 FIG. 4 is a flow chart of another text clustering method according to an embodiment of the present invention. Figure 3 As shown in FIG. 1 , it mainly includes three steps: text keyword extraction, text vector representation and clustering. Through these three steps, the final text clustering result can be obtained; among them, the texts classified into the same cluster are considered to have similar contents and belong to the same category, and the texts in different clusters are considered to have certain differences in content and belong to different categories.
[0114] The following is an explanation of the above three steps:
[0115] Step 20: Text keyword extraction.
[0116] In one embodiment, the texts are first read one by one, and the texts are segmented using predetermined segmentation tools and methods. After segmentation, the TextRank text keyword extraction algorithm is used to extract text keywords to obtain a keyword set for each text; it is determined whether the text has been traversed. If the judgment result is yes, global keyword screening is performed; if the judgment result is no, the text reading continues.
[0117] In one embodiment, it is specified to obtain a set of the top n keywords in importance in each text. Among them, n represents the number of keywords, i represents the keyword number, x represents the text number, and w represents the keyword number. i represents the i-th keyword in text x, w i The corresponding weight coefficient is θ i ; Summarize and obtain the keyword set D of all texts, Wherein, m represents the number of texts, and x represents the text serial number; since the keyword extraction between the various texts is unrelated to each other, a multi-thread / process execution method can be used for concurrent acceleration.
[0118] After obtaining the keywords of all texts based on the above steps, all keywords are screened. The screening principles are as follows:
[0119] 1) Eliminate low-frequency keywords. Eliminate keywords that appear less frequently or account for a very low proportion of text. Such keywords often belong to only a very small number of texts, lack commonality, and easily cause matrix sparseness, so they should be removed first.
[0120] 2) Eliminate high-frequency keywords. Eliminate keywords that account for more than a certain threshold. These keywords appear too frequently and are often found in texts of different types. They are less helpful for clustering and should be removed first.
[0121] 3) Select high-weight keywords. Based on the filtering in steps 1) and 2), if the number of remaining keywords is still too large, you can use formula (1) to calculate the keyword w i Weight:
[0122]
[0123] In formula (1), λ i Indicates keyword w i The weight among all texts, t i Represents the keyword w i The frequency of occurrence in all texts, j represents the text number, y represents the number of texts, θ ij Indicates the occurrence of keyword w i The weight of text j; sort by weight and select the first k keywords as the final global keywords, where k is an integer greater than 0.
[0124] Step 21: Text vector representation.
[0125] In one embodiment, after k global keywords are selected, the global keywords are represented by a feature matrix; illustratively, the bag-of-words model is used in combination with the local weight λ of the global keywords. ij Construct text vector V i , where the local weight λ ij Indicates keyword w jThe weight of text i. In a specific example, for the j-th dimension feature of text i, its corresponding keyword w j If it appears in d i In the example, the j-th dimension feature is λ ij , otherwise it is 0; Based on this method, the vector representation V i , and finally construct the text matrix R.
[0126] Before the final clustering, the text matrix R can be reduced in dimension and regularized to obtain the final R d Text matrix. The dimensionality reduction algorithm can adopt common PCA, SVD, AE and other algorithms; the regularization can be L1, L2 norm regularization. After the above processing, the sparsity of the matrix can be reduced and the generalization ability can be improved.
[0127] Step 22: Clustering.
[0128] In one implementation, different clustering algorithms can be selected to perform clustering on the text matrix R according to actual scenario requirements. d Clustering. When the actual number of text categories is clear, the number of clusters Q can be manually specified and the K-Means algorithm can be used for clustering. In actual situations, people are often unclear about the actual number of text categories and need to cluster based on sample similarity or density. In this scenario, a hierarchical clustering algorithm or DBSCAN algorithm can be used for clustering.
[0129] R d After cluster analysis, the text clustering results are obtained. The similarity between text descriptions belonging to the same category is relatively large, and the similarity between text descriptions of different categories is relatively large.
[0130] It can be seen that the embodiment of the present invention uses multi-stage keyword extraction, and the memory overhead of the entire process from text keyword extraction to text vector representation to clustering is very small and controllable, which solves the dimensionality explosion problem of the traditional bag-of-words model, and does not need to introduce additional word vector library overhead like the word vector model method. In addition, the embodiment of the present invention can introduce different clustering algorithms according to the requirements of different usage scenarios during the clustering process, and can simultaneously meet the requirements of clustering tasks with and without a specified number of clusters, and has a wider scope of application in actual use.
[0131] Figure 4 Schematic diagram of the composition structure of text clustering according to an embodiment of the present invention. Figure 4 As shown, the device includes: an extraction module 300, a screening module 301 and a clustering module 302, wherein:
[0132] The extraction module 300 is used to obtain N texts to be processed and extract keywords from each of the N texts to be processed; wherein N is an integer greater than 1;
[0133] A screening module 301 is used to screen the keywords of the N to-be-processed texts to obtain global keywords;
[0134] The clustering module 302 is used to cluster the N to-be-processed texts based on the global keywords.
[0135] In one implementation, the screening module 301 is used to screen the keywords of the N to-be-processed texts to obtain global keywords, including:
[0136] The keywords of the N to-be-processed texts are screened according to the word frequencies and / or weights of the keywords of the N to-be-processed texts to obtain the global keywords.
[0137] In one implementation, the screening module 301 is used to screen the keywords of the N to-be-processed texts according to the word frequencies of the keywords of the N to-be-processed texts to obtain the global keywords, including:
[0138] When the word frequency of any keyword among the keywords of the N texts to be processed is less than or equal to the first threshold or greater than or equal to the second threshold, the any keyword is deleted from the keywords of the N texts to be processed to obtain the global keyword; the first threshold is less than the second threshold.
[0139] In one implementation, the screening module 301 is used to screen the keywords of the N to-be-processed texts according to the weights of the keywords of the N to-be-processed texts to obtain the global keywords, including:
[0140] Sorting the weights of the keywords of the N to-be-processed texts to obtain a first sorting result;
[0141] Based on the first sorting result, the first L keywords in the sorting result are used as the global keywords; wherein L is an integer greater than 0.
[0142] In one implementation, the screening module 301 is used to screen the keywords of the N to-be-processed texts according to the word frequencies and weights of the keywords of the N to-be-processed texts to obtain the global keywords, including:
[0143] When the frequency of any keyword among the keywords of the N to-be-processed texts is less than or equal to the first threshold or greater than or equal to the second threshold, the any keyword is deleted from the keywords of the N to-be-processed texts to obtain a candidate keyword set; the first threshold is less than the second threshold;
[0144] Sorting the weights of the keywords in the candidate keyword set to obtain a second sorting result;
[0145] Based on the second sorting result, the first M keywords in the sorting result are used as the global keywords; wherein M is an integer greater than 0.
[0146] In one implementation, the clustering module 302 is used to cluster the N to-be-processed texts based on the global keywords, including:
[0147] Determine, according to the global keywords, the text matrices corresponding to the N texts to be processed;
[0148] Performing dimensionality reduction processing on the text matrix to obtain a text matrix after dimensionality reduction processing;
[0149] Based on the text matrix after the dimensionality reduction process, the N texts to be processed are clustered.
[0150] In one implementation, the extraction module 300 is used to extract keywords from each of the N to-be-processed texts, including:
[0151] The keywords of each of the N texts to be processed are extracted in parallel.
[0152] In one embodiment, the device is applied in a network behavior management platform.
[0153] In practical applications, the extraction module 300, screening module 301 and clustering module 302 can all be implemented by a processor located in an electronic device, and the processor can be at least one of ASIC, DSP, DSPD, PLD, FPGA, CPU, controller, microcontroller, and microprocessor.
[0154] In addition, each functional module in this embodiment can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The above integrated unit can be implemented in the form of hardware or software functional modules.
[0155] If the integrated unit is implemented in the form of a software function module and is not sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this embodiment is essentially or the part that contributes to the relevant technology or the whole or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, server, or network device, etc.) or a processor to perform all or part of the steps of the method of this embodiment. The aforementioned storage medium includes: U disk, mobile hard disk, read only memory (ROM), random access memory (RAM), disk or optical disk and other media that can store program codes.
[0156] Specifically, a computer program instruction corresponding to a text clustering method in this embodiment can be stored on a storage medium such as a CD, a hard disk, or a USB flash drive. When the computer program instruction corresponding to a text clustering method in the storage medium is read or executed by an electronic device, any one of the text clustering methods in the aforementioned embodiments is implemented.
[0157] Based on the same technical concept as the above embodiments, see Figure 5 , which shows an electronic device 400 provided by an embodiment of the present invention, which may include: a memory 401 and a processor 402; wherein,
[0158] Memory 401, used for storing computer programs and data;
[0159] The processor 402 is configured to execute a computer program stored in the memory to implement any one of the text clustering methods in the foregoing embodiments.
[0160] In practical applications, the memory 401 may be a volatile memory, such as RAM; or a non-volatile memory, such as ROM, flash memory, hard disk drive (HDD) or solid-state drive (SSD); or a combination of the above types of memory, and provide instructions and data to the processor 402.
[0161] The processor 402 may be at least one of ASIC, DSP, DSPD, PLD, FPGA, CPU, controller, microcontroller, and microprocessor. It is understandable that for different augmented reality cloud platforms, the electronic device used to implement the processor function may also be other, which is not specifically limited in the embodiment of the present invention.
[0162] In some embodiments, the functions or modules included in the apparatus provided in the embodiments of the present invention can be used to execute the method described in the above method embodiment. The specific implementation can refer to the description of the above method embodiment. For the sake of brevity, it will not be repeated here.
[0163] The above description of the various embodiments tends to emphasize the differences between the various embodiments. The same or similar aspects can be referenced to each other. For the sake of brevity, this article will not repeat them.
[0164] The methods disclosed in the various method embodiments provided by the present invention can be arbitrarily combined without conflict to obtain new method embodiments.
[0165] The features disclosed in the various product embodiments provided by the present invention can be arbitrarily combined without conflict to obtain new product embodiments.
[0166] The features disclosed in the various method or device embodiments provided by the present invention can be arbitrarily combined without conflict to obtain new method embodiments or device embodiments.
[0167] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of hardware embodiments, software embodiments, or embodiments combining software and hardware. Furthermore, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage and optical storage, etc.) containing computer-usable program code.
[0168] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0169] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0170] The above are only preferred embodiments of the present invention and are not intended to limit the protection scope of the present invention.
Claims
1. A text clustering method, characterized in that: The method comprises: Obtain N texts to be processed, perform word segmentation on each of the N texts to be processed, and then extract keywords from each of the texts to be processed; wherein N is an integer greater than 1; The keywords of the N to-be-processed texts are screened according to the word frequencies and / or weights of the keywords of the N to-be-processed texts to obtain global keywords; wherein the word frequencies are determined based on the number of times each keyword appears in the N to-be-processed texts and the total number of keywords in the N to-be-processed texts, and the weights are determined by weighted processing of the keywords of the N to-be-processed texts using a word frequency-inverse document frequency TF-IDF method; Based on the global keywords, the N texts to be processed are clustered; wherein, based on the global keywords, the N texts to be processed are clustered, including: according to the global keywords, determining the text matrix corresponding to the N texts to be processed, and clustering the text matrix.
2. The method according to claim 1, characterized in that The keywords of the N to-be-processed texts are screened according to the word frequencies of the keywords of the N to-be-processed texts to obtain global keywords, including: When the word frequency of any keyword among the keywords of the N texts to be processed is less than or equal to the first threshold or greater than or equal to the second threshold, the any keyword is deleted from the keywords of the N texts to be processed to obtain the global keyword; the first threshold is less than the second threshold.
3. The method according to claim 1, characterized in that The keywords of the N to-be-processed texts are screened according to the weights of the keywords of the N to-be-processed texts to obtain global keywords, including: Sorting the weights of the keywords of the N to-be-processed texts to obtain a first sorting result; Based on the first sorting result, the first L keywords in the sorting result are used as the global keywords; wherein L is an integer greater than 0.
4. The method according to claim 1, characterized in that The keywords of the N to-be-processed texts are screened according to the word frequencies and weights of the keywords of the N to-be-processed texts to obtain global keywords, including: When the frequency of any keyword of the keywords of the N to-be-processed texts is less than or equal to the first threshold or greater than or equal to the second threshold, the any keyword is deleted from the keywords of the N to-be-processed texts to obtain a candidate keyword set; the first threshold is less than the second threshold; Sorting the weights of the keywords in the candidate keyword set to obtain a second sorting result; Based on the second sorting result, the first M keywords in the sorting result are used as the global keywords; wherein M is an integer greater than 0.
5. The method according to claim 1, characterized in that The clustering of the N to-be-processed texts based on the global keywords includes: Determine, according to the global keywords, a text matrix corresponding to the N texts to be processed; Performing dimensionality reduction processing on the text matrix to obtain a text matrix after dimensionality reduction processing; Based on the text matrix after the dimensionality reduction process, the N texts to be processed are clustered.
6. The method according to claim 1, characterized in that The step of extracting keywords from each of the texts to be processed includes: The keywords of each of the texts to be processed are extracted in parallel.
7. The method according to any one of claims 1 to 6, characterized in that: The method is applied in a network behavior management platform.
8. A text clustering device, characterized in that: The device comprises: An extraction module, used for obtaining N to-be-processed texts, performing word segmentation on each of the N to-be-processed texts, and then extracting keywords from each of the to-be-processed texts; wherein N is an integer greater than 1; A screening module, used for screening the keywords of the N to-be-processed texts according to the word frequencies and / or weights of the keywords of the N to-be-processed texts to obtain global keywords; wherein the word frequencies are determined based on the number of times each keyword appears in the N to-be-processed texts and the total number of keywords of the N to-be-processed texts, and the weights are determined by weighted processing the keywords of the N to-be-processed texts using the TF-IDF method; A clustering module is used to cluster the N texts to be processed based on the global keywords; wherein, clustering the N texts to be processed based on the global keywords includes: determining the text matrix corresponding to the N texts to be processed according to the global keywords, and clustering the text matrix.
9. An electronic device, characterized in that: The device comprises a memory, a processor and a computer program stored in the memory and executable on the processor, and the method according to any one of claims 1 to 7 is implemented when the processor executes the program.
10. A computer storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
