Comment text classification method, device and equipment
By performing preset optimization and selection of initial points on a global scale for the feature vectors of classified text, the problem that the K-means clustering algorithm is easily trapped in local optimal solutions and improves the accuracy of text classification.
Patent Information
- Application Number
- CN202411670940.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-21
- Publication Date
- 2025-03-25
AI Technical Summary
In the prior art, the K-means clustering algorithm is prone to fall into the local optimal solution when selecting the center point of the initial cluster, resulting in a low accuracy of text data classification.
By preset optimization of the feature vectors of classified text, the initial points of clustering are selected globally to avoid local optimal solutions, and then cluster to obtain the text category.
It improves the accuracy of text data classification, avoids the problem of falling into local optimal solutions during clustering, and achieves more accurate text classification.
Smart Images

Figure CN119691171A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a method, device and equipment for classifying comment texts. Background Art
[0002] With the development of technology, many platforms have set up entrances for user feedback and messages. Then users can provide feedback on the platform about their experience of using a certain item, or consult about the progress of business processing, some exchange policies, some software upgrades and other data. However, after the user feedbacks the corresponding data, the customer service staff of the platform needs to check the feedback content one by one and solve them one by one after receiving the user feedback. This makes the whole process very time-consuming, thereby extending the problem handling cycle and making the user experience poor.
[0003] In the related art, text data is generally clustered by a K-means clustering algorithm, so that the text data fed back by users can be classified, and customer service personnel who subsequently handle different types of problems can handle the corresponding problems.
[0004] However, the K-means clustering algorithm relies on the selection of initial cluster center points. If an inappropriate cluster center point is selected, the algorithm may fall into a local optimal solution, resulting in low accuracy in text data classification. Summary of the invention
[0005] The present application provides a comment text classification method, device, equipment and storage medium, which can first select the initial point of clustering in the global scope through preset optimization, and then cluster the text to be classified based on the initial point selected in the global scope to obtain the category of the text to be classified. In this way, the initial point of clustering is determined based on the global scope, so that it can avoid falling into the local optimal solution later, and then classify the text to be classified more accurately. The technical solution includes the following contents.
[0006] In a first aspect, a comment text classification method is provided, the method comprising:
[0007] Extracting features of a plurality of texts to be classified to obtain a plurality of feature vectors, wherein the plurality of texts to be classified are comment texts received by the vehicle platform;
[0008] Preset optimization is performed on the multiple feature vectors to obtain k target feature vectors, where the k target feature vectors are feature vectors obtained by performing a global search, and k is the same as the number of all categories of the multiple texts to be classified;
[0009] Based on the k target feature vectors, the multiple texts to be classified are clustered to obtain the category of each of the texts to be classified.
[0010] In the present application, feature extraction is first performed on multiple texts to be classified to obtain multiple feature vectors, and then the multiple feature vectors are preset and optimized to obtain k target feature vectors determined based on a global search. Finally, based on the k target feature vectors, the multiple texts to be classified are clustered to obtain the category of each text to be classified. By pre-optimizing multiple feature vectors, the present application makes it possible to search for the initial point of clustering in the global scope, and obtain k target feature vectors based on global considerations, that is, the best initial point in the global scope when the k target feature vectors are clustered. Then, by subsequently clustering multiple texts to be classified based on the k target feature vectors, it is possible to avoid falling into a local optimal solution during the clustering process, thereby accurately obtaining the category of the text to be classified.
[0011] Optionally, performing preset optimization on the multiple feature vectors to obtain k target feature vectors includes:
[0012] Determine a first eigenvector and k second eigenvectors from the plurality of eigenvectors;
[0013] Determining k first distances between the first eigenvector and the k second eigenvectors;
[0014] Based on the average distance of the k first distances and the multiple feature vectors, performing multiple rounds of iterative updates on the first feature vector and the k second feature vectors to obtain multiple fitness function values and the k second feature vectors corresponding to the multiple rounds of iterative updates, wherein the fitness function value is used to measure the distance between the first feature vector and the second feature vector;
[0015] The k target feature vectors are determined based on the k second feature vectors corresponding to the multiple fitness function values and multiple rounds of iterative updates.
[0016] Optionally, the performing multiple rounds of iterative updating on the first feature vector and the k second feature vectors based on the average distance of the k first distances and the multiple feature vectors to obtain multiple fitness function values and the k second feature vectors corresponding to the multiple rounds of iterative updating includes:
[0017] For a first round of iterative updates in the multiple rounds of iterative updates, determine a third eigenvector of the first round of iterative updates from the k second eigenvectors, the third eigenvector being the eigenvector with the farthest distance from the average position among the k second eigenvectors; based on the average distance, the third eigenvector and the multiple eigenvectors, update the first eigenvector and the k second eigenvectors to obtain a first eigenvector and k second eigenvectors of the first round of iterative updates; determine a fitness function value of the first round of iterative updates based on the distance between the first eigenvector and the k second eigenvectors of the first round of iterative updates;
[0018] For the i-th round of iterative update in the multiple rounds of iterative updates, k second distances between the k second feature vectors of the i-1-th round of iterative update and the first feature vector are determined, and the average distance of the k second distances is determined; the third feature vector of the i-1-th round of iterative update is determined from the k second feature vectors of the i-1-th round of iterative update; based on the k second distances, the average distance of the k second distances, the third feature vector of the i-1-th round of iterative update, the fitness function value of the previous i-1 round of iterative update and the multiple feature vectors, the first feature vector and the k second feature vectors are updated to obtain the first feature vector and k second feature vectors of the i-th round of iterative update; based on the distance between the first feature vector and the k second feature vectors of the i-th round of iterative update, the fitness function value of the i-th round of iterative update is determined, where i is an integer greater than or equal to 2.
[0019] Optionally, the updating of the first feature vector and k second feature vectors based on the k second distances, the average distance of the k second distances, the third feature vector updated in the i-1th round of iterative update, the fitness function value updated in the previous i-1th round of iterative update, and the multiple feature vectors to obtain the first feature vector and k second feature vectors updated in the i-th round of iterative update includes:
[0020] Determine the iteration parameter based on the maximum number of iterations and the current number of iterations i;
[0021] For the i-th round of iterative update, randomly generate a first random number;
[0022] In the case where the first random number is greater than or equal to the iteration parameter, a fourth eigenvector is determined based on the fitness function value of the previous i-1 round of iterative updates; a distance between the fourth eigenvector and the k second eigenvectors updated in the i-1th round of iterative updates is determined; based on the fourth eigenvector and the distance between the fourth eigenvector and the k second eigenvectors, k eigenvectors are determined from the multiple eigenvectors as the k second eigenvectors updated in the i-th round of iterative updates, and the first eigenvector updated in the i-1th round of iterative updates is determined as the first eigenvector updated in the i-th round of iterative updates;
[0023] When the first random number is less than the iteration parameter, based on the average distance of the k second distances and the third feature vector updated in the i-1th round of iterative update, a feature vector is determined from the multiple feature vectors as the first feature vector updated in the i-th round of iterative update, and the k second feature vectors updated in the i-1th round of iterative update are determined as the k second feature vectors updated in the i-th round of iterative update.
[0024] Optionally, the determining the k target feature vectors based on the k second feature vectors corresponding to the multiple fitness function values and multiple rounds of iterative updates includes:
[0025] Determine the minimum fitness function value among the multiple fitness function values as the target fitness function value;
[0026] The k second feature vectors corresponding to the iterative update round in which the target fitness function value is located are determined as the k target feature vectors.
[0027] Optionally, clustering the plurality of to-be-classified texts based on the k target feature vectors to obtain a category of each of the to-be-classified texts includes:
[0028] Taking the k target feature vectors as k initial centroids, and determining k clusters based on distances between the k initial centroids and a plurality of fifth feature vectors, wherein the plurality of fifth feature vectors are other feature vectors in the plurality of feature vectors except the k target feature vectors;
[0029] Based on the distances between multiple feature vectors in the k clusters and the centroids of the k clusters, multiple rounds of iterative updates are performed on the centroids of the k clusters and the k clusters to obtain k target clusters, where the k target clusters correspond to k categories, and the text to be classified corresponding to the feature vector in any one of the k target clusters belongs to the same category.
[0030] Optionally, determining k clusters based on the distances between the k initial centroids and a plurality of fourth eigenvectors comprises:
[0031] For any one of the k initial centroids, determining a fourth distance between the plurality of fifth eigenvectors and the initial centroid;
[0032] The fifth eigenvectors of the plurality of fifth eigenvectors whose fourth distance is less than a preset distance threshold are allocated to the initial centroid, so as to obtain a cluster with the initial centroid as the center point.
[0033] Optionally, the performing multiple rounds of iterative updating on the centroids of the k clusters and the k clusters based on the distances between the multiple feature vectors of the k clusters and the centroids of the k clusters to obtain k target clusters includes:
[0034] For any one round of iterative updating in the multiple rounds of iterative updating, for any one cluster among the k clusters, based on the distances between a plurality of feature vectors in the cluster and the centroid of the cluster, re-determining the centroid of the cluster;
[0035] Based on the distances between the re-determined centroids of the k clusters and the multiple sixth eigenvectors, the eigenvectors within the k clusters are re-determined until the maximum number of iterations is reached, and the k clusters obtained by the last iteration update are the k target clusters, and the multiple sixth eigenvectors are the eigenvectors in the multiple eigenvectors except the centroids of the k clusters.
[0036] In a second aspect, a comment text classification device is provided, the device comprising:
[0037] A feature extraction module, used for extracting features from a plurality of texts to be classified to obtain a plurality of feature vectors, wherein the plurality of texts to be classified are comment texts received by the vehicle platform;
[0038] An optimization module, used for performing preset optimization on the multiple feature vectors to obtain k target feature vectors, wherein the k target feature vectors are feature vectors obtained by performing a global search, and k is the same as the number of all categories of the multiple texts to be classified;
[0039] The clustering module is used to cluster the multiple texts to be classified based on the k target feature vectors to obtain the category of each of the texts to be classified.
[0040] Optionally, the optimization module is used to:
[0041] Determine a first eigenvector and k second eigenvectors from the plurality of eigenvectors;
[0042] Determining k first distances between the first eigenvector and the k second eigenvectors;
[0043] Based on the average distance of the k first distances and the multiple feature vectors, performing multiple rounds of iterative updates on the first feature vector and the k second feature vectors to obtain multiple fitness function values and the k second feature vectors corresponding to the multiple rounds of iterative updates, wherein the fitness function value is used to measure the distance between the first feature vector and the second feature vector;
[0044] The k target feature vectors are determined based on the k second feature vectors corresponding to the multiple fitness function values and multiple rounds of iterative updates.
[0045] Optionally, the optimization module is used to:
[0046] For a first round of iterative updates in the multiple rounds of iterative updates, determine a third eigenvector of the first round of iterative updates from the k second eigenvectors, the third eigenvector being the eigenvector with the farthest distance from the average position among the k second eigenvectors; based on the average distance, the third eigenvector and the multiple eigenvectors, update the first eigenvector and the k second eigenvectors to obtain a first eigenvector and k second eigenvectors of the first round of iterative updates; determine a fitness function value of the first round of iterative updates based on the distance between the first eigenvector and the k second eigenvectors of the first round of iterative updates;
[0047] For the i-th round of iterative update in the multiple rounds of iterative updates, k second distances between the k second feature vectors of the i-1-th round of iterative update and the first feature vector are determined, and the average distance of the k second distances is determined; the third feature vector of the i-1-th round of iterative update is determined from the k second feature vectors of the i-1-th round of iterative update; based on the k second distances, the average distance of the k second distances, the third feature vector of the i-1-th round of iterative update, the fitness function value of the previous i-1 round of iterative update and the multiple feature vectors, the first feature vector and the k second feature vectors are updated to obtain the first feature vector and k second feature vectors of the i-th round of iterative update; based on the distance between the first feature vector and the k second feature vectors of the i-th round of iterative update, the fitness function value of the i-th round of iterative update is determined, where i is an integer greater than or equal to 2.
[0048] Optionally, the optimization module is used to:
[0049] Determine the iteration parameter based on the maximum number of iterations and the current number of iterations i;
[0050] For the i-th round of iterative update, randomly generate a first random number;
[0051] In the case where the first random number is greater than or equal to the iteration parameter, a fourth eigenvector is determined based on the fitness function value of the previous i-1 round of iterative updates; a distance between the fourth eigenvector and the k second eigenvectors updated in the i-1th round of iterative updates is determined; based on the fourth eigenvector and the distance between the fourth eigenvector and the k second eigenvectors, k eigenvectors are determined from the multiple eigenvectors as the k second eigenvectors updated in the i-th round of iterative updates, and the first eigenvector updated in the i-1th round of iterative updates is determined as the first eigenvector updated in the i-th round of iterative updates;
[0052] When the first random number is less than the iteration parameter, based on the average distance of the k second distances and the third feature vector updated in the i-1th round of iterative update, a feature vector is determined from the multiple feature vectors as the first feature vector updated in the i-th round of iterative update, and the k second feature vectors updated in the i-1th round of iterative update are determined as the k second feature vectors updated in the i-th round of iterative update.
[0053] Optionally, the optimization module is used to:
[0054] Determine the minimum fitness function value among the multiple fitness function values as the target fitness function value;
[0055] The k second feature vectors corresponding to the iterative update round in which the target fitness function value is located are determined as the k target feature vectors.
[0056] Optionally, the clustering module is used to:
[0057] Taking the k target feature vectors as k initial centroids, and determining k clusters based on distances between the k initial centroids and a plurality of fifth feature vectors, wherein the plurality of fifth feature vectors are other feature vectors in the plurality of feature vectors except the k target feature vectors;
[0058] Based on the distances between multiple feature vectors in the k clusters and the centroids of the k clusters, multiple rounds of iterative updates are performed on the centroids of the k clusters and the k clusters to obtain k target clusters, where the k target clusters correspond to k categories, and the text to be classified corresponding to the feature vector in any one of the k target clusters belongs to the same category.
[0059] Optionally, the clustering module is used to:
[0060] For any one of the k initial centroids, determining a fourth distance between the plurality of fifth eigenvectors and the initial centroid;
[0061] The fifth eigenvectors of the plurality of fifth eigenvectors whose fourth distance is less than a preset distance threshold are allocated to the initial centroid, so as to obtain a cluster with the initial centroid as the center point.
[0062] Optionally, the clustering module is used to:
[0063] For any one round of iterative updating in the multiple rounds of iterative updating, for any one cluster among the k clusters, based on the distances between a plurality of feature vectors in the cluster and the centroid of the cluster, re-determining the centroid of the cluster;
[0064] Based on the distances between the re-determined centroids of the k clusters and the multiple sixth eigenvectors, the eigenvectors within the k clusters are re-determined until the maximum number of iterations is reached, and the k clusters obtained by the last iteration update are the k target clusters, and the multiple sixth eigenvectors are the eigenvectors in the multiple eigenvectors except the centroids of the k clusters.
[0065] In a third aspect, a computer device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program implements the above-mentioned comment text classification method when executed by the processor.
[0066] In a fourth aspect, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the above-mentioned comment text classification method is implemented.
[0067] In a fifth aspect, a computer program product comprising instructions is provided, which, when executed on a computer, enables the computer to execute the steps of the above-mentioned comment text classification method.
[0068] It can be understood that the beneficial effects of the second, third, fourth and fifth aspects mentioned above can be found in the relevant description of the first aspect mentioned above, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0069] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0070] Figure 1 This is a flow chart of a comment text classification method provided in an embodiment of the present application;
[0071] Figure 2It is a structural schematic diagram of a comment text classification device provided in an embodiment of the present application;
[0072] Figure 3 It is a structural diagram of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0073] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below with reference to the accompanying drawings.
[0074] It should be understood that the "multiple" mentioned in this application refers to two or more. In the description of this application, unless otherwise specified, " / " means or, for example, A / B can mean A or B; "and / or" in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships, for example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, in order to facilitate the clear description of the technical solution of this application, the words "first" and "second" are used to distinguish between the same items or similar items with basically the same functions and effects. Those skilled in the art can understand that the words "first" and "second" do not limit the quantity and execution order, and the words "first" and "second" do not limit them to be different.
[0075] Before describing the review text classification method provided in the embodiment of the present application, the application scenario of the embodiment of the present application is described first.
[0076] For the vehicle platform, users can report vehicle failures, inquire about OTA (Over-The-Air) upgrades, inquire about additional purchase policies, and other comments on the vehicle platform. Therefore, the vehicle platform may receive the above data feedback from users at all times, that is, comment texts, which means that the vehicle platform will have a large number of comment texts collected in the background at any time. However, due to the large amount of comment text data, if it relies on manpower to carefully classify them one by one, it will be time-consuming, labor-intensive, and costly.
[0077] To this end, an embodiment of the present application provides a comment text classification method, which can be applied to the scenario of classifying comment texts on a vehicle platform.
[0078] Specifically, firstly, feature extraction is performed on multiple texts to be classified to obtain multiple feature vectors. Then, multiple feature vectors are preset and optimized to obtain k target feature vectors, that is, the best initial point of clustering is searched in the global scope, and the k target feature vectors are feature vectors that meet the global search conditions among multiple feature vectors. Finally, based on the best initial point of clustering (k target feature vectors) obtained by the search, multiple texts to be classified are clustered to obtain the category of each text to be classified.
[0079] By pre-optimizing multiple feature vectors, it is possible to search for the initial point of clustering in the global scope and obtain k target feature vectors based on global considerations, that is, the best initial point in the global scope when the k target feature vectors are clustered. Then, based on the k target feature vectors, clustering multiple texts to be classified can avoid falling into the local optimal solution during the clustering process, so that the category of each text to be classified can be accurately obtained.
[0080] The review text classification method provided in the embodiment of the present application is explained in detail below.
[0081] Figure 1 is a flowchart of a comment text classification method provided by an embodiment of the present application. Figure 1 , the method comprises the following steps.
[0082] Step 101: extracting features from a plurality of texts to be classified to obtain a plurality of feature vectors. The plurality of texts to be classified are comment texts received by a vehicle platform.
[0083] In an embodiment of the present application, the multiple texts to be classified may be comment texts about vehicle failures, comment texts about OTA upgrade conditions, comment texts about trade-in policies, and some other comment texts, etc. Of course, user feedback and comment data received on the vehicle platform may all be used as texts to be classified.
[0084] Optionally, the operation of step 101 may be implemented in the following three possible ways.
[0085] The first possible implementation method is to extract features of the multiple texts to be classified through a bag-of-words model to obtain multiple feature vectors.
[0086] The bag-of-words model is a commonly used natural language processing technique for converting text data into numerical form. The core idea of the bag-of-words model is to ignore the order of words in the text and only focus on the frequency of word occurrence. The extracted feature is the frequency of occurrence of all words in the text to be classified.
[0087] Specifically, the specific process of extracting features from the multiple texts to be classified through the bag-of-words model to obtain multiple feature vectors is as follows: for each text to be classified in the multiple texts to be classified, traverse the text to be classified, collect all words that appear in the text to be classified, and obtain multiple words; remove duplicates from the multiple words to obtain a target vocabulary, which includes multiple unique words; initialize a vector for the text to be classified, and the length of the vector is equal to the size of the vocabulary; for each word, count the frequency of occurrence of the word in the text to be classified, and fill the vector according to the frequency of occurrence of the word in the text to be classified to obtain the feature vector of the text to be classified, so as to obtain multiple feature vectors.
[0088] Since the bag-of-words model is relatively simple to implement, for large-scale data, the bag-of-words model can extract feature vectors more quickly, thereby improving the efficiency of feature extraction for classified texts.
[0089] A second possible implementation method is to perform feature extraction on the multiple texts to be classified through a TF-IDF (Term Frequency-Inverse Document Frequency) model to obtain multiple feature vectors.
[0090] The core idea of the TF-IDF model: If a word or phrase has a high probability of appearing in a certain text and rarely appears in other texts, it is considered that the word or phrase has good category distinction ability and is suitable for classification. The TF-IDF model evaluates the importance of a word to a text by combining the word frequency and inverse document frequency of a word. In an embodiment of the present application, the TF-IDF model characterizes the characteristics of the text to be classified by combining the word frequency and inverse document frequency of each word in the text to be classified, so that the category of the text to be classified can be better distinguished later.
[0091] Specifically, the TF-IDF model is used to extract features from the multiple texts to be classified to obtain multiple feature vectors. The specific process is as follows: traverse each text to be classified, collect all words that appear in each text to be classified, and obtain multiple words corresponding to each text to be classified; calculate the frequency of occurrence of multiple words in the corresponding texts to be classified, and obtain the word frequency corresponding to each word in each text to be classified; calculate the inverse document frequency for each word; multiply the word frequency of each word by the inverse document frequency of each word to obtain the TF-IDF value of each word in the corresponding text to be classified, that is, to obtain multiple feature vectors.
[0092] The inverse document frequency can reflect the prevalence of a word in all the texts to be classified. The more texts a word appears in, the more common it is. The lower its IDF value is, the lower the TF-IDF value of the corresponding word is. On the contrary, if a word appears in fewer texts to be classified, it can reflect that the word is not a common word and has the ability to distinguish. The higher its IDF value is, the higher the TF-IDF value of the corresponding word is.
[0093] The operation of calculating the occurrence frequencies of multiple words in the corresponding text to be classified and obtaining the word frequencies of each word in the corresponding text to be classified can be as follows: for any one of the multiple words, the occurrence frequency of this word in the corresponding text to be classified can be calculated by the following formula (1) to obtain the word frequency of this word.
[0094]
[0095] Among them, TF(l, d) is the word frequency corresponding to word l, m l is the number of times word l appears in the text to be classified d, and n is the total number of words in the text to be classified d.
[0096] The operation of calculating the inverse document frequency for each word may be as follows: for any one of the multiple words, the inverse document frequency of the word may be calculated using the following formula (2).
[0097]
[0098] Among them, IDF is the inverse document frequency of this word, P is the total number of texts to be classified, and q is the number of texts to be classified that contain word l among multiple texts to be classified.
[0099] A third possible implementation method is to extract features of the multiple texts to be classified through a word embedding model to obtain multiple feature vectors.
[0100] The word embedding model is a technology that maps words to a high-dimensional vector space. Through mapping, the semantic relationship (such as similarity, analogy) and syntactic relationship (such as the relationship between verbs and nouns) between words can be captured. In the embodiment of the present application, the Word2Vec word embedding model, the GloVe (Global Vectors for Word Representation, global word vector representation) word embedding model, the FastText word embedding model, etc. can be used to extract features of multiple texts to be classified to obtain multiple feature vectors, and the embodiment of the present application does not make a sole limitation on this.
[0101] Specifically, pre-train a word embedding model; for any one of the multiple texts to be classified, traverse this text to be classified, collect all the words that appear in this text to be classified, and obtain multiple words; convert the multiple words into dense vectors through the pre-trained word embedding model to obtain the feature vector corresponding to this text to be classified.
[0102] In this case, by directly using the pre-trained word embedding model to extract the features of the text to be classified, the feature vector of the text to be classified can be extracted more accurately and quickly.
[0103] Optionally, before step 101, the multiple texts to be classified can also be preprocessed, and then the features of the preprocessed multiple texts to be classified are extracted.
[0104] Specifically, the operations for preprocessing the multiple texts to be classified can include: for any one of the multiple texts to be classified, perform cleaning processing, word segmentation processing, stop word removal processing, and stemming or lemmatization on this text to be classified in sequence.
[0105] The cleaning process includes removing the noise, punctuation marks, and special characters of the text to be classified, etc.
[0106] Word segmentation processing refers to splitting the text to be classified into individual words or phrases.
[0107] Removing stop words means removing the words that do not carry important information in the text to be classified, such as "de", "shi", "zai", etc.
[0108] Stemming or lemmatization means reducing the words to their basic forms.
[0109] In this way, by performing the above operations on each text to be classified, the multiple texts to be classified can be preprocessed, so that the features of the text to be classified can be accurately extracted subsequently.
[0110] Optionally, after obtaining multiple feature vectors, feature selection or dimensionality reduction can also be performed.
[0111] Feature selection refers to selecting representative and discriminative features.
[0112] Dimensionality reduction refers to reducing the dimension of the feature space, which can usually be performed by means of PCA (Principal Component Analysis) or t-SNE (t-Distributed Stochastic Neighbor Embedding).
[0113] In this case, feature selection or feature dimensionality reduction can be used to reduce the feature dimension, thereby reducing the amount of calculation when the feature vector is subsequently processed, thereby saving computing resources and improving clustering efficiency.
[0114] Step 102: Preset optimization is performed on the multiple feature vectors to obtain k target feature vectors, where the k target feature vectors are feature vectors obtained by global search, and k is the same as the number of all categories of the multiple texts to be classified.
[0115] Preset optimization refers to the process of performing global search processing on the multiple feature vectors to obtain k target feature vectors, that is, the preset optimization can be the process of processing the multiple feature vectors through a global search algorithm. In an embodiment of the present application, the preset optimization can be hunter-prey optimization, that is, the multiple feature vectors are processed by a hunter-prey algorithm. In this way, by simulating the hunter's search behavior and the prey's avoidance behavior, the solution space is gradually optimized, and finally the global optimal solution or approximate optimal solution can be found from the multiple feature vectors.
[0116] The basic idea of hunter-prey optimization: When hunters are searching for prey, because prey often come in groups, hunters are likely to pick a prey from the farthest place (away from the average group position). After the hunter finds the desired prey, he will chase the prey. At the same time, the prey is also looking for food and escaping from the hunter's pursuit and attack to reach a safe place. These two processes are accompanied by the global update of the hunter's position and the prey's position. In this process, the safe position reached by the prey is the optimal solution.
[0117] In the embodiment of the present application, the number of all categories of the multiple texts to be classified can be determined by means of the silhouette coefficient method, the elbow rule and the interval quantity statistics.
[0118] In this case, by pre-optimizing the multiple feature vectors, the best initial point of clustering can be searched globally, thereby obtaining k target feature vectors based on global considerations. In this way, clustering can be performed accordingly to avoid falling into a local optimal solution.
[0119] Optionally, when the preset optimization is hunter-prey optimization, the operation of step 102 may include the following steps (1) to (4).
[0120] (1) Determine a first eigenvector and k second eigenvectors from the plurality of eigenvectors.
[0121] Optionally, a first eigenvector and k eigenvectors may be randomly selected from the multiple eigenvectors.
[0122] For hunter-prey optimization, it includes hunter search agents and prey search agents. Among them, determining a first feature and k second feature vectors from the multiple feature vectors is to initialize the initial positions of the hunter search agent and the prey search agent. The initial position of the hunter search agent is the first feature vector, and the initial positions of the k prey search agents are the k second feature vectors.
[0123] (2) Determine k first distances between the first eigenvector and the k second eigenvectors.
[0124] For any second eigenvector among the k second eigenvectors, the distance between the second eigenvector and the first eigenvector is determined. By performing this operation on the k second eigenvectors, k first distances can be determined.
[0125] According to the basic idea of hunter-prey optimization: when hunters are searching for prey, because prey often come in groups, hunters are likely to pick a prey from the farthest place (away from the average group position). After the hunter finds the desired prey, he will chase the prey. At the same time, the prey is also looking for food and escaping from the hunter's pursuit and attack to reach a safe place. These two processes are accompanied by the update of the hunter's position and the prey's position. It can be seen that in hunter-prey optimization, the positions of the hunter and the prey are updated according to the distance between the hunter and the prey. Therefore, the k first distances between the first eigenvector and the k second eigenvectors can be determined.
[0126] (3) Based on the average distance of the k first distances and the multiple feature vectors, the first feature vector and the k second feature vectors are iteratively updated for multiple rounds to obtain multiple fitness function values and k second feature vectors corresponding to the multiple rounds of iterative updates.
[0127] The fitness function value is used to measure the distance between the first eigenvector and the second eigenvector.
[0128] According to the basic idea of hunter-prey optimization mentioned above, the hunter-prey optimization process is accompanied by the update of the hunter's position and the prey's position. Therefore, the hunter search agent and the prey search agent continuously update their positions, so that the new first eigenvector and k second eigenvectors are continuously determined, that is, the optimal solution is continuously explored on a global scale.
[0129] Optionally, the operation of step (3) may include the following process (a)-process (b).
[0130] (a) For a first round of iterative update in multiple rounds of iterative update, a third eigenvector of the first round of iterative update is determined from k second eigenvectors; based on the average distance of the k first distances, the third eigenvector and the multiple eigenvectors, the first eigenvector and the k second eigenvectors are updated to obtain the first eigenvector and k second eigenvectors of the first round of iterative update; based on the distance between the first eigenvector and the k second eigenvectors of the first round of iterative update, the fitness function value of the first round of iterative update is determined.
[0131] The third eigenvector is the eigenvector farthest from the average position (ie, farthest from the average group position) among the k second eigenvectors.
[0132] Based on the basic idea of hunter-prey optimization, it is known that after the hunter finds the desired prey, he will chase the prey, and the prey is usually far away from the average group position. In addition, the prey will avoid the hunter's pursuit. Therefore, the third eigenvector can be determined, and the first eigenvector and k second eigenvectors can be updated according to the third eigenvector.
[0133] Among them, the operation of determining the third eigenvector of the first round of iterative update from the k second eigenvectors can be: based on the average distance of the k first distances, determining the eigenvector corresponding to the average position; calculating the k third distances between the k second eigenvectors and the eigenvector corresponding to the average position; and determining the eigenvector with the largest third distance among the k second eigenvectors as the third eigenvector of the first round of iterative update.
[0134] The eigenvector corresponding to the average position is the eigenvector whose distance to the first eigenvector is the average distance or close to the average distance among the k second eigenvectors.
[0135] In this case, by calculating k third distances, the distances between the k second eigenvectors and the eigenvector corresponding to the average position can be obtained, and thus the degree of outliers of the k second eigenvectors can be obtained. By determining the eigenvector with the largest third distance among the k second eigenvectors as the third eigenvector, that is, determining the eigenvector farthest from the group among the k second eigenvectors as the third eigenvector of the first round of iterative update, it is equivalent to finding the prey of the hunter in the first round.
[0136] Among them, based on the distance between the first eigenvector of the first round of iterative update and the k second eigenvectors, the operation of determining the fitness function value of the first round of iterative update can be: determining the Euclidean distance between the first eigenvector of the first round of iterative update and the k second eigenvectors, obtaining k Euclidean distances, and determining the sum of the k Euclidean distances as the fitness function value of the first round of iterative update.
[0137] The above specific operation is also achieved through the following formula (3).
[0138]
[0139] Among them, J is the fitness function value, X j is the jth eigenvector among the k second eigenvectors, and u is the first eigenvector.
[0140] (b) For the i-th round of iterative update in multiple rounds of iterative updates, determine the k second distances between the k second eigenvectors of the i-1-th round of iterative update and the first eigenvector, and determine the average distance of the k second distances; determine the third eigenvector of the i-1-th round of iterative update from the k second eigenvectors of the i-1-th round of iterative update; based on the k second distances, the average distance of the k second distances, the third eigenvector of the i-1-th round of iterative update, the fitness function value of the previous i-1 round of iterative update and the multiple eigenvectors, update the first eigenvector and the k second eigenvectors to obtain the first eigenvector and k second eigenvectors of the i-th round of iterative update; based on the distance between the first eigenvector and the k second eigenvectors of the i-th round of iterative update, determine the fitness function value of the i-th round of iterative update.
[0141] Here, i is an integer greater than or equal to 2.
[0142] Among them, the operation of determining the third eigenvector of the i-1th round of iterative update from the k second eigenvectors of the i-1th round of iterative update is similar to the operation of determining the third eigenvector of the first round of iterative update from the k second eigenvectors mentioned above, and will not be repeated here.
[0143] Among them, the operation of determining the fitness function value of the i-th round of iterative update based on the distance between the first eigenvector and the k second eigenvectors updated in the i-th round is similar to the operation of determining the fitness function value of the first round of iterative update based on the distance between the first eigenvector and the k second eigenvectors updated in the first round of iterative update, and will not be repeated here.
[0144] The following describes in detail the specific operation steps for updating the first eigenvector and the k second eigenvectors based on the k second distances, the average distance of the k second distances, the third eigenvector updated in the i-1th round of iterative update, the fitness function value updated in the first i-1th round of iterative update, and the multiple eigenvectors to obtain the first eigenvector and the k second eigenvectors updated in the i-th round of iterative update. Specifically, the following steps (I) to (IV) may be included.
[0145] Ⅰ. Determine the iteration parameters based on the maximum number of iterations and the current number of iterations i.
[0146] The maximum number of iterations refers to the maximum number of iterative updates of the first eigenvector and the k second eigenvectors.
[0147] Optionally, the operation of determining the iteration parameter based on the maximum number of iterations and the current number of iterations i may be: based on the maximum number of iterations and the current number of iterations i, determining the iteration parameter by the following formula (4).
[0148]
[0149] Among them, β is the iteration parameter and MAXIt is the maximum number of iterations.
[0150] For example, if the maximum number of iterations is 10 and the current number of iterations is 5, the calculated iteration parameter is 0.5.
[0151] II. For the i-th round of iterative update, a first random number is randomly generated.
[0152] The first random number is a random number within [0,1], and generation of the first random number obeys Gaussian distribution.
[0153] In hunter-prey optimization, the positions of the hunter search agent and the prey search agent need to be continuously updated, but in each update, the position of one party is fixed and the position of the other party is updated. However, in each iterative update, it becomes a problem which party's position should be updated to fully search for the optimal solution in the global scope. Therefore, in the embodiment of the present application, a first random number that obeys a Gaussian distribution is randomly generated, and then the position of which party is updated is determined based on the size relationship between the random number and the iteration parameter.
[0154] In addition, since the first random number obeys the Gaussian distribution, the updates of the positions of both parties can be balanced during subsequent iterative updates, so that the optimal solution can be fully searched globally.
[0155] III. When the first random number is greater than or equal to the iteration parameter, determine the fourth eigenvector based on the fitness function value of the previous i-1 rounds of iterative updates; determine the distance between the fourth eigenvector and the k second eigenvectors of the i-1th round of iterative updates; based on the fourth eigenvector and the distance between the fourth eigenvector and the k second eigenvectors, respectively determine k eigenvectors from the multiple eigenvectors as the k second eigenvectors of the i-th round of iterative updates, and determine the first eigenvector of the i-1th round of iterative updates as the first eigenvector of the i-th round of iterative updates.
[0156] From the perspective of the search agent, when the first random number is greater than or equal to the iteration parameter, it means that the current iteration parameter is small, that is, at the beginning of the iterative update, the position of the prey search agent can be updated more, thereby encouraging the exploration of the solution space and avoiding falling into the local optimal solution too early.
[0157] Among them, based on the fitness function values of the previous i-1 rounds of iterative updates, the operation of determining the fourth eigenvector can be: obtaining the minimum fitness function value from the fitness function values of the previous i-1 rounds of iterative updates; and determining the first eigenvector corresponding to the iterative update round where the minimum fitness function value is located as the fourth eigenvector.
[0158] It should be understood that the smaller the fitness function value is, the smaller the distance between the k second eigenvectors and the first eigenvector is. From the perspective of the search agent, the first eigenvector with the minimum fitness function value is the best position of the hunter search agent in the current global range.
[0159] In this case, by considering the fourth eigenvector that minimizes the fitness function value in the iterative process, the fourth eigenvector is also the eigenvector at the global optimal position. In this way, when the prey search agent is subsequently updated, the hunter search agent can be better avoided, so that a more accurate second eigenvector can be obtained by iterative update.
[0160] Among them, the operation of determining k eigenvectors from the multiple eigenvectors as k second eigenvectors for the i-th round of iterative update based on the fourth eigenvector and the distance between the fourth eigenvector and the k second eigenvectors can be: determining k first positions based on the fourth eigenvector and the distance between the fourth eigenvector and the k second eigenvectors; and determining the eigenvectors at the k first positions as k second eigenvectors for the i-th round of iterative update.
[0161] The operation of respectively determining the k first positions based on the fourth eigenvector and the distance between the fourth eigenvector and the k second eigenvectors can be implemented by the following formula (5).
[0162] X j (t+1)=T pos +CZ cos(2πR4)×(T pos -X j (t)), R5≥β (5)
[0163] Among them, X j (t+1) is the jth first position among the k first positions, that is, the position of the jth prey search agent at the next moment. pos is the fourth eigenvector, X j(t) is the position of the j-th prey search agent at the current moment, which is also the j-th second eigenvector among the k second eigenvectors updated in the i-1th round of iteration. pos -X j (t) is the distance between the fourth eigenvector and the jth second eigenvector. R5 is the first random number, R4 is the second random number, and the second random number is a number within [-1,1]. C is a balance parameter, which is used to balance exploration and solution, and Z is an adaptive parameter.
[0164] The balance parameter can be realized by the following formula (6).
[0165]
[0166] The adaptive parameters can be implemented by the following formula (7).
[0167]
[0168] Where R2 and R3 are random numbers in [0,1]. IDX is a vector satisfying R1>C.
[0169] By performing the above formula (5) operation on the k second feature vectors updated in the i-1th round of iteration, k first positions can be obtained. From the perspective of the search agent, it is equivalent to determining the positions of the k prey search agents at the next moment, that is, obtaining k first positions. Therefore, the feature vectors at the k first positions are the k second feature vectors updated in the i-th round of iteration.
[0170] IV. When the first random number is less than the iteration parameter, based on the average distance of the k second distances and the third eigenvector updated in the i-1th round of iteration, a eigenvector is determined from multiple eigenvectors as the first eigenvector updated in the i-th round of iteration, and the k second eigenvectors updated in the i-1th round of iteration are determined as the k second eigenvectors updated in the i-th round of iteration.
[0171] When the first random number is less than the iteration parameter, it means that the number of iterations is gradually increasing. At this time, the positions of the hunter search agents are updated more frequently, which helps to conduct more detailed searches in known potential areas to find more accurate optimal solutions.
[0172] Among them, the operation of determining a feature vector from multiple feature vectors as the first feature vector for the i-th round of iterative update based on the average distance of k second distances and the third feature vector for the i-1th round of iterative update can be: determining the average position for the i-1th round of iterative update based on the average distance of k second distances; determining the second position based on the first feature vector for the i-1th round of iterative update, the average position for the i-1th round of iterative update and the third feature vector for the i-1th round of iterative update; determining the feature vector at the second position as the first feature vector for the i-1th round of iterative update.
[0173] Among them, based on the first eigenvector updated in the i-1th round of iterative update, the average position updated in the i-1th round of iterative update, and the third eigenvector updated in the i-1th round of iterative update, the operation of determining the second position can be: based on the first eigenvector updated in the i-1th round of iterative update, the average position updated in the i-1th round of iterative update, and the third eigenvector updated in the i-1th round of iterative update, the second position is determined by the following formula (8).
[0174] y(t+1)=y(t)+0.5[(2CZP pos(i-1) -y(t))+(2(1-C)2μ i-1 -y(t))], R5<β (8)
[0175] Among them, y(t+1) is the second position, which is the position of the hunter search agent at the next moment from the perspective of the search agent. y(t) is the first eigenvector updated in the i-1th round of iteration. P pos(i-1) is the third eigenvector updated in the i-1th round of iteration, μ i-1 is the average position updated in the i-1th round of iteration.
[0176] It is worth noting that by executing the above steps (I) to (IV) in multiple rounds of iterations, the positions of the hunter search agent and the prey search agent can be continuously updated, so that the position of the hunter search agent is constantly close to the individual farthest from the average position of the population, and the position of the prey search agent is constantly close to the best position of the hunter search agent in the global scope, so that the hunter constantly approaches the prey closest to the population, and the prey constantly approaches the hunter. In this way, through continuous confrontation, the optimal solution in the global scope can eventually be obtained.
[0177] For ease of understanding, the above-mentioned multiple rounds of iterative update process are now illustrated by way of example.
[0178] For example, the maximum number of iterations is 5, k is 3, and there are 10 eigenvectors, namely eigenvector 1, eigenvector 2, eigenvector 3, eigenvector 4, eigenvector 5, eigenvector 6, eigenvector 7, eigenvector 8, eigenvector 9, and eigenvector 10. A first eigenvector is initialized from the 10 eigenvectors to be eigenvector 2, and the three second eigenvectors are eigenvector 3, eigenvector 6, and eigenvector 8. The distance between eigenvector 3 and eigenvector 2 is 10, the distance between eigenvector 6 and eigenvector 2 is 20, and the distance between eigenvector 8 and eigenvector 2 is 30. The average distance of the three first distances (10, 20, 30) is 20. It can be known that the eigenvector at the average position is eigenvector 6.
[0179] For the first round of iterative update, if the distances between eigenvector 3 and eigenvector 8 and eigenvector 6 are the same, then a eigenvector 3 is randomly selected as the third eigenvector. Then, a first random number is randomly generated, and if the first random number is greater than the number of iterations, then the three second eigenvectors are determined to be updated. By executing the above formula (5), the new second eigenvectors are updated to eigenvector 1, eigenvector 4, and eigenvector 7. In addition, the first eigenvector remains unchanged as eigenvector 2. Finally, based on the distances between eigenvector 1, eigenvector 4, eigenvector 7 and eigenvector 2, the fitness function value obtained in the first round of iterative update is determined.
[0180] For the second round of iterative update, determine the average distance of feature vector 1, feature vector 4, feature vector 7 from feature vector 2, and determine the average position at this time as feature vector 1 based on the average distance. Among feature vector 1, feature vector 4, and feature vector 7, feature vector 7 is the farthest from feature vector 1, so feature vector 7 is determined as the third feature vector of the first round of iterative update. Then, a first random number is randomly generated, and if the first random number is greater than the number of iterations, it is determined that the three second feature vectors are still updated. By executing the above formula (5), the new second feature vectors are updated to feature vector 8, feature vector 9, and feature vector 10. In addition, the first feature vector remains unchanged as feature vector 2. Finally, based on the distance between feature vector 8, feature vector 9, feature vector 10 and feature vector 2, determine the fitness function value obtained by the second round of iterative update.
[0181] For the third round of iterative update, determine the average distance of feature vector 8, feature vector 9, and feature vector 10 from feature vector 2, and determine the average position at this time as feature vector 9 based on the average distance. Among feature vectors 8, feature vector 9, and feature vector 10, feature vector 10 is the farthest from feature vector 9, so feature vector 10 is determined as the third feature vector of the second round of iterative update. Then, a first random number is randomly generated, and if the first random number is less than the number of iterations, it is determined that the first feature vector is updated. By executing the above formula (8), the new first feature vector is updated to feature vector 4, and the three second feature vectors (feature vector 8, feature vector 9, and feature vector 10) remain unchanged. Finally, based on the distance between feature vector 8, feature vector 9, feature vector 10 and feature vector 4, determine the fitness function value obtained by the third round of iterative update.
[0182] For the fourth round of iterative update, the average distance of feature vector 8, feature vector 9, and feature vector 10 from feature vector 4 is determined, and based on the average distance, the average position at this time is determined to be feature vector 9. Among feature vectors 8, feature vector 9, and feature vector 10, feature vector 8 is the farthest from feature vector 9, so feature vector 8 is determined as the third feature vector of the third round of iterative update. Then, a first random number is randomly generated, and if the first random number is greater than the number of iterations, it is determined that the three second feature vectors are updated. By executing the above formula (5), the new second feature vectors are updated to feature vector 3, feature vector 5, and feature vector 7. In addition, the first feature vector remains unchanged as feature vector 4. Finally, based on the distance between feature vector 3, feature vector 5, feature vector 7 and feature vector 4, the fitness function value obtained by the fourth round of iterative update is determined.
[0183] For the fifth round of iterative update, the average distance of feature vector 3, feature vector 5, and feature vector 7 from feature vector 4 is determined, and based on the average distance, the average position at this time is determined to be feature vector 5. Among feature vectors 3, feature vector 5, and feature vector 7, feature vector 3 is the farthest from feature vector 5, so feature vector 3 is determined as the third feature vector for the third round of iterative update. Then, a first random number is randomly generated, and if the first random number is less than the number of iterations, it is determined that the first feature vector is updated. By executing the above formula (8), the new first feature vector is updated to feature vector 6. In addition, the three second feature vectors are feature vector 3, feature vector 5, and feature vector 7, which remain unchanged. Finally, based on the distance between feature vector 3, feature vector 5, feature vector 7 and feature vector 6, the fitness function value obtained by the fifth round of iterative update is determined.
[0184] (4) Based on the multiple fitness function values and the k second eigenvectors corresponding to the multiple rounds of iterative updates, k target eigenvectors are determined.
[0185] Optionally, the operation of step (4) may be: determining the smallest fitness function value among the multiple fitness function values as the target fitness function value; and determining the k second feature vectors corresponding to the iterative update round where the target fitness function value is located as k target feature vectors.
[0186] Based on the basic idea of hunter-prey optimization, the purpose of optimization is to make the prey find a safe position. The hunter takes individuals far away from the average position of the population as prey, so the closer the prey is to the population, the safer it is. Therefore, the purpose of prey update is also to gradually approach the hunter's position. The safest position is also the global optimal solution.
[0187] Since the fitness function is used to measure the distance between the first eigenvector and the k second eigenvectors, in the process of multiple rounds of iterations, if the fitness function value determined by a round of iteration is the smallest, it means that the distance between the first eigenvector updated by this round of iteration and the k second eigenvectors is the smallest, so the k second eigenvectors are closer to the first eigenvector. From the perspective of the hunter and the prey, the distance between the prey and the hunter is relatively close, so the prey has reached a safe position, and the eigenvectors of the prey's position can be determined as the k target eigenvectors.
[0188] In this way, by comparing the fitness function values generated by iteration in the global scope, it is possible to fully find the k target feature vectors in the global scope, that is, to obtain the optimal solution and the best initial point for subsequent clustering.
[0189] Step 103: Based on the k target feature vectors, cluster the multiple texts to be classified to obtain the category of each text to be classified.
[0190] In an embodiment of the present application, the categories of text to be classified may include vehicle fault feedback type, OTA upgrade consultation type, exchange policy consultation type, etc., and the categories may be set specifically according to the services set by the vehicle platform.
[0191] Since the k target feature vectors are feature vectors determined by searching in a global scope, that is, the k feature vectors are feature vectors based on global considerations, the subsequent clustering of the multiple texts to be classified based on the k target feature vectors can avoid the problem of clustering falling into the optimal solution of the layout, so that the multiple texts to be classified can be accurately classified.
[0192] Optionally, the operation of step 103 may include the following steps (1) and (2).
[0193] (1) Taking k target feature vectors as k initial centroids, and determining k clusters based on the distances between the k initial centroids and a plurality of fifth feature vectors.
[0194] The plurality of fifth eigenvectors are other eigenvectors in the plurality of eigenvectors except the k target eigenvectors.
[0195] It should be understood that clustering is to group similar data together in a pile of data, thereby forming multiple clusters. There will be centroids in multiple clusters, and the similarity between the data in the cluster and the centroid is high, thus completing the clustering process.
[0196] In this case, after determining k target feature vectors, the k target feature vectors can be used as k initial centroids. The k initial centroids are used as the centers to preliminarily determine k clusters, which is the first clustering.
[0197] Optionally, the operation of step (1) can be: for any initial centroid among the k initial centroids, determine the fourth distance between multiple fifth eigenvectors and this initial centroid; assign the fifth eigenvector among the multiple fifth eigenvectors whose fourth distance is less than a preset distance threshold to this initial centroid, to obtain a cluster with this initial centroid as the center point.
[0198] The preset distance threshold may be set in advance, and the preset distance threshold may be set to be smaller.
[0199] In this case, that is, first determine the distances between multiple fifth eigenvectors and the initial centroid, and then assign eigenvectors to the initial centroid based on the determined distances between multiple fifth eigenvectors and the initial centroid, thereby forming a cluster centered on the initial centroid.
[0200] When a fourth distance is less than a preset distance threshold, it means that the distance between the fifth eigenvector corresponding to the fourth distance and the initial center of mass is small, that is, the fifth eigenvector is relatively close to the initial center of mass, which means that the fifth eigenvector is relatively similar to the initial center of mass, and the fifth eigenvector can be assigned to the initial center of mass.
[0201] In this way, by determining the magnitude relationship between each fourth distance and the preset distance threshold, all fifth eigenvectors that meet the conditions can be allocated to the initial centroid, thereby forming a cluster with the initial centroid as the center point.
[0202] It is worth noting that by performing the above operation on each of the k initial centroids, k clusters can be obtained respectively, and the center points of these k clusters are the k initial centroids respectively. In this way, the first clustering is completed.
[0203] (2) Based on the distances between multiple feature vectors of k clusters and the centroids of k clusters, the centroids of k clusters and k clusters are iteratively updated for multiple rounds to obtain k target clusters.
[0204] The k target clusters correspond to k categories, and the text to be classified corresponding to the feature vector in any of the k target clusters belongs to the same category.
[0205] In this case, by performing multiple rounds of iterative updates on the centroids of k clusters and k clusters, the feature vectors in the clusters can be continuously updated, and the feature vectors in each cluster are made more and more similar to the centroids of the clusters. In this way, the feature vectors in each of the k target clusters are relatively similar, so that the texts to be classified corresponding to the feature vectors in each target cluster have the same category, which means that the classification of the multiple texts to be classified is completed.
[0206] In addition, by further iteratively updating the k target feature vectors based on global search, the probability of the clustering task falling into the local optimal solution is reduced, so that more accurate k target clusters can be obtained. In turn, the clustering accuracy can be improved, that is, the multiple texts to be classified can be classified more accurately.
[0207] Specifically, the operation of step (2) may include the following steps (a) to (b).
[0208] (a) For any round of iterative updates in the multiple rounds of iterative updates, for any cluster among the k clusters, the centroid of the cluster is re-determined based on the distances between multiple feature vectors in the cluster and the centroid of the cluster.
[0209] Optionally, the operation of step (a) may be: determining the average value of the distances between multiple feature vectors within the cluster and the centroid of the cluster to obtain a target average distance; and determining the feature vector among the multiple feature vectors within the cluster whose distance to the centroid of the cluster is close to the target average distance as the centroid of the cluster.
[0210] It should be understood that determining the feature vector whose distance to the centroid of the cluster is close to the target average distance among the multiple feature vectors in the cluster as the centroid of the cluster means first determining the difference between the target average distance and the distance corresponding to the multiple feature vectors in the cluster to obtain multiple differences, and the multiple differences correspond one-to-one to the multiple feature vectors; then determining the feature vector with the smallest corresponding difference among the multiple feature vectors as the centroid of the cluster.
[0211] (b) Based on the distances between the re-determined centroids of the k clusters and the multiple sixth eigenvectors, the eigenvectors within the k clusters are re-determined until the maximum number of iterations is reached, and the k clusters obtained by the last iteration update are the k target clusters.
[0212] The plurality of sixth eigenvectors are eigenvectors other than the centroids of the k clusters among the plurality of eigenvectors.
[0213] It should be understood that when the centroid of a cluster changes, the feature vectors in the cluster will also change accordingly. Therefore, after updating the centroid of the cluster, the feature vectors can be reallocated to the centroid of the cluster to update the cluster and obtain a new cluster.
[0214] Among them, the operation of re-determining the eigenvectors within the k clusters based on the distances between the re-determined centroids of the k clusters and multiple sixth eigenvectors is similar to the operation of determining the k clusters based on the distances between the k initial centroids and multiple fourth eigenvectors, and will not be repeated here.
[0215] It is worth noting that by repeatedly executing the above steps (a) to (b) until the maximum number of iterations is reached, the centroid of the cluster and the feature vector within the cluster can be continuously updated, so that the feature vectors within the cluster are gradually similar, and k target clusters are obtained.
[0216] In an embodiment of the present application, a computer device first extracts features from a plurality of texts to be classified to obtain a plurality of feature vectors, and then performs preset optimization on the plurality of feature vectors to obtain k target feature vectors determined based on a global search. Finally, based on the k target feature vectors, the plurality of texts to be classified are clustered to obtain the category of each text to be classified. The present application performs preset optimization on a plurality of feature vectors so that the initial point of clustering can be searched in the global scope, and k target feature vectors based on global considerations can be obtained, that is, the optimal initial point in the global scope when the k target feature vectors are clustered. Then, based on the k target feature vectors, the plurality of texts to be classified are clustered subsequently, so that it is possible to avoid falling into a local optimal solution during the clustering process, thereby accurately obtaining the category of the text to be classified.
[0217] Figure 2 Schematic diagram of a review text classification device provided in an embodiment of the present application. The review text classification device can be implemented as part or all of a computer device by software, hardware, or a combination of both. The computer device can be as follows Figure 3 Computer equipment shown. Figure 2 The device includes: a feature extraction module 201, an optimization module 202 and a clustering module 203.
[0218] A feature extraction module 201 is used to extract features from a plurality of texts to be classified to obtain a plurality of feature vectors, wherein the plurality of texts to be classified are comment texts received by the vehicle platform;
[0219] An optimization module 202 is used to perform preset optimization on the multiple feature vectors to obtain k target feature vectors, where the k target feature vectors are feature vectors obtained by performing a global search, and k is the same as the number of all categories of the multiple texts to be classified;
[0220] The clustering module 203 is used to cluster the multiple texts to be classified based on k target feature vectors to obtain the category of each text to be classified.
[0221] Optionally, the optimization module 202 is used to:
[0222] Determine a first eigenvector and k second eigenvectors from the plurality of eigenvectors;
[0223] determining k first distances between the first eigenvector and the k second eigenvectors;
[0224] Based on the average distance of the k first distances and the multiple eigenvectors, the first eigenvector and the k second eigenvectors are iteratively updated for multiple rounds to obtain multiple fitness function values and the k second eigenvectors corresponding to the multiple rounds of iterative updates, wherein the fitness function value is used to measure the distance between the first eigenvector and the second eigenvector;
[0225] Based on multiple fitness function values and multiple rounds of iterative updates corresponding to k second eigenvectors, k target eigenvectors are determined.
[0226] Optionally, the optimization module 202 is used to:
[0227] For a first round of iterative updates in multiple rounds of iterative updates, a third eigenvector of the first round of iterative updates is determined from the k second eigenvectors, where the third eigenvector is the eigenvector with the farthest distance from the average position among the k second eigenvectors; based on the average distance, the third eigenvector and the multiple eigenvectors, the first eigenvector and the k second eigenvectors are updated to obtain the first eigenvector and the k second eigenvectors of the first round of iterative updates; based on the distance between the first eigenvector and the k second eigenvectors of the first round of iterative updates, a fitness function value of the first round of iterative updates is determined;
[0228] For the i-th round of iterative update in multiple rounds of iterative update, k second distances between the k second eigenvectors of the i-1-th round of iterative update and the first eigenvector are determined, and the average distance of the k second distances is determined; the third eigenvector of the i-1-th round of iterative update is determined from the k second eigenvectors of the i-1-th round of iterative update; based on the k second distances, the average distance of the k second distances, the third eigenvector of the i-1-th round of iterative update, the fitness function value of the previous i-1 round of iterative update and the multiple eigenvectors, the first eigenvector and the k second eigenvectors are updated to obtain the first eigenvector and k second eigenvectors of the i-th round of iterative update; based on the distance between the first eigenvector and the k second eigenvectors of the i-th round of iterative update, the fitness function value of the i-th round of iterative update is determined, where i is an integer greater than or equal to 2.
[0229] Optionally, the optimization module 202 is used to:
[0230] Determine the iteration parameter based on the maximum number of iterations and the current number of iterations i;
[0231] For the i-th round of iterative update, a first random number is randomly generated;
[0232] In the case where the first random number is greater than or equal to the iteration parameter, the fourth eigenvector is determined based on the fitness function value of the previous i-1 round of iterative updates; the distance between the fourth eigenvector and the k second eigenvectors updated in the i-1th round of iterative updates is determined; based on the fourth eigenvector and the distance between the fourth eigenvector and the k second eigenvectors, k eigenvectors are determined from the multiple eigenvectors as the k second eigenvectors updated in the i-th round of iterative updates, and the first eigenvector updated in the i-1th round of iterative updates is determined as the first eigenvector updated in the i-th round of iterative updates;
[0233] When the first random number is less than the iteration parameter, based on the average distance of the k second distances and the third eigenvector updated in the i-1th round of iterative update, a eigenvector is determined from the multiple eigenvectors as the first eigenvector updated in the i-th round of iterative update, and the k second eigenvectors updated in the i-1th round of iterative update are determined as the k second eigenvectors updated in the i-th round of iterative update.
[0234] Optionally, the optimization module 202 is used to:
[0235] Determine the minimum fitness function value among multiple fitness function values as the target fitness function value;
[0236] The k second eigenvectors corresponding to the iterative update round where the target fitness function value is located are determined as k target eigenvectors.
[0237] Optionally, the clustering module 203 is used to:
[0238] Taking the k target feature vectors as k initial centroids, and determining k clusters based on the distances between the k initial centroids and a plurality of fifth feature vectors, where the plurality of fifth feature vectors are feature vectors other than the k target feature vectors in the plurality of feature vectors;
[0239] Based on the distances between multiple feature vectors in k clusters and the centroids of k clusters, the centroids of k clusters and k clusters are iteratively updated for multiple rounds to obtain k target clusters. The k target clusters correspond to k categories, and the text to be classified corresponding to the feature vector in any of the k target clusters belongs to the same category.
[0240] Optionally, the clustering module 203 is used to:
[0241] For any one of the k initial centroids, determining fourth distances between a plurality of fifth eigenvectors and the initial centroid;
[0242] The fifth eigenvectors whose fourth distances are less than a preset distance threshold among the multiple fifth eigenvectors are allocated to the initial centroid, so as to obtain a cluster with the initial centroid as the center point.
[0243] Optionally, the clustering module 203 is used to:
[0244] For any round of iterative updates in the multiple rounds of iterative updates, for any cluster among the k clusters, the centroid of the cluster is re-determined based on the distances between the multiple feature vectors in the cluster and the centroid of the cluster;
[0245] Based on the distances between the re-determined centroids of the k clusters and the multiple sixth eigenvectors, the eigenvectors within the k clusters are re-determined until the maximum number of iterations is reached, and the k clusters obtained by the last iteration update are the k target clusters, and the multiple sixth eigenvectors are the eigenvectors in the multiple eigenvectors except the centroids of the k clusters.
[0246] In an embodiment of the present application, feature extraction is first performed on multiple texts to be classified to obtain multiple feature vectors, and then the multiple feature vectors are preset and optimized to obtain k target feature vectors determined based on a global search. Finally, based on the k target feature vectors, the multiple texts to be classified are clustered to obtain the category of each text to be classified. The present application performs preset optimization on multiple feature vectors, so that the initial point of clustering can be searched in the global scope, and k target feature vectors based on global considerations can be obtained, that is, the optimal initial point in the global scope when the k target feature vectors are clustered. Then, based on the k target feature vectors, the multiple texts to be classified are clustered subsequently, which can avoid falling into a local optimal solution during the clustering process, so that the category of the text to be classified can be accurately obtained.
[0247] It should be noted that: when the comment text classification device provided in the above embodiment classifies the comment text, it only uses the division of the above-mentioned functional modules as an example. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.
[0248] The functional units and modules in the above embodiments may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit, and the above integrated units may be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the protection scope of the embodiments of the present application.
[0249] The comment text classification device and the comment text classification method embodiment provided in the above embodiment belong to the same concept. The specific working process of the units and modules in the above embodiment and the technical effects brought about can be found in the method embodiment part and will not be repeated here.
[0250] Figure 3 This is a schematic diagram of the structure of a computer device provided in an embodiment of the present application. Figure 3 As shown, the computer device 3 includes: a processor 30, a memory 31, and a computer program 32 stored in the memory 31 and executable on the processor 30. When the processor 30 executes the computer program 32, the steps in the comment text classification method in the above embodiment are implemented.
[0251] The computer device 3 may be a general-purpose computer device or a special-purpose computer device. In a specific implementation, the computer device 3 may be a network server. Those skilled in the art will appreciate that Figure 3 It is only an example of computer device 3 and does not constitute a limitation on computer device 3. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components, such as input and output devices, network access devices, etc.
[0252] The processor 30 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor.
[0253] In some embodiments, the memory 31 may be an internal storage unit of the computer device 3, such as a hard disk or memory of the computer device 3. In other embodiments, the memory 31 may also be an external storage device of the computer device 3, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the computer device 3. Further, the memory 31 may also include both an internal storage unit and an external storage device of the computer device 3. The memory 31 is used to store an operating system, an application program, a boot loader, data, and other programs. The memory 31 may also be used to temporarily store data that has been output or is to be output.
[0254] An embodiment of the present application further provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments can be implemented.
[0255] An embodiment of the present application provides a computer program product, which, when executed on a computer, enables the computer to execute the steps in the above-mentioned method embodiments.
[0256] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present application implements all or part of the processes in the above method embodiments, which can be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium. When the computer program is executed by the processor, the steps of the above method embodiments can be implemented. Among them, the computer program includes computer program code, which can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may at least include: any entity or device that can carry the computer program code to the camera / terminal device, recording medium, computer memory, ROM (Read-Only Memory), RAM (Random Access Memory), CD-ROM (Compact Disc Read-Only Memory), magnetic tape, floppy disk and optical data storage device. The computer-readable storage medium mentioned in the present application can be a non-volatile storage medium, in other words, it can be a non-transient storage medium.
[0257] It should be understood that all or part of the steps to implement the above embodiments can be implemented by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. The computer instructions can be stored in the above-mentioned computer readable storage medium.
[0258] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0259] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0260] In the embodiments provided in the present application, it should be understood that the disclosed devices / computer equipment and methods can be implemented in other ways. For example, the device / computer equipment embodiments described above are only schematic, for example, the division of modules or units is only a logical function division, and there may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0261] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0262] The embodiments described above are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, a person skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.
Claims
1. A review text classification method, characterized in that: The method comprises: Extracting features of a plurality of texts to be classified to obtain a plurality of feature vectors, wherein the plurality of texts to be classified are comment texts received by the vehicle platform; Preset optimization is performed on the multiple feature vectors to obtain k target feature vectors, where the k target feature vectors are feature vectors obtained by performing a global search, and k is the same as the number of all categories of the multiple texts to be classified; Based on the k target feature vectors, the multiple texts to be classified are clustered to obtain the category of each of the texts to be classified.
2. The method according to claim 1, characterized in that The pre-optimizing the multiple feature vectors to obtain k target feature vectors includes: Determine a first eigenvector and k second eigenvectors from the plurality of eigenvectors; Determining k first distances between the first eigenvector and the k second eigenvectors; Based on the average distance of the k first distances and the multiple feature vectors, performing multiple rounds of iterative updates on the first feature vector and the k second feature vectors to obtain multiple fitness function values and the k second feature vectors corresponding to the multiple rounds of iterative updates, wherein the fitness function value is used to measure the distance between the first feature vector and the second feature vector; The k target feature vectors are determined based on the k second feature vectors corresponding to the multiple fitness function values and multiple rounds of iterative updates.
3. The method according to claim 2, characterized in that The step of performing multiple rounds of iterative updating on the first feature vector and the k second feature vectors based on the average distance of the k first distances and the multiple feature vectors to obtain multiple fitness function values and the k second feature vectors corresponding to the multiple rounds of iterative updating includes: For a first round of iterative updates in the multiple rounds of iterative updates, determine a third eigenvector of the first round of iterative updates from the k second eigenvectors, the third eigenvector being the eigenvector with the farthest distance from the average position among the k second eigenvectors; based on the average distance, the third eigenvector and the multiple eigenvectors, update the first eigenvector and the k second eigenvectors to obtain a first eigenvector and k second eigenvectors of the first round of iterative updates; determine a fitness function value of the first round of iterative updates based on the distance between the first eigenvector and the k second eigenvectors of the first round of iterative updates; For the i-th round of iterative update in the multiple rounds of iterative updates, k second distances between the k second feature vectors of the i-1-th round of iterative update and the first feature vector are determined, and the average distance of the k second distances is determined; the third feature vector of the i-1-th round of iterative update is determined from the k second feature vectors of the i-1-th round of iterative update; based on the k second distances, the average distance of the k second distances, the third feature vector of the i-1-th round of iterative update, the fitness function value of the previous i-1 round of iterative update and the multiple feature vectors, the first feature vector and the k second feature vectors are updated to obtain the first feature vector and k second feature vectors of the i-th round of iterative update; based on the distance between the first feature vector and the k second feature vectors of the i-th round of iterative update, the fitness function value of the i-th round of iterative update is determined, where i is an integer greater than or equal to 2.
4. The method according to claim 3, characterized in that The updating of the first feature vector and the k second feature vectors based on the k second distances, the average distance of the k second distances, the third feature vector updated in the i-1th round of iteration, the fitness function value updated in the previous i-1th round of iteration, and the multiple feature vectors to obtain the first feature vector and k second feature vectors updated in the i-th round of iteration includes: Determine the iteration parameter based on the maximum number of iterations and the current number of iterations i; For the i-th round of iterative update, randomly generate a first random number; In the case where the first random number is greater than or equal to the iteration parameter, a fourth eigenvector is determined based on the fitness function value of the previous i-1 round of iterative updates; a distance between the fourth eigenvector and the k second eigenvectors updated in the i-1th round of iterative updates is determined; based on the fourth eigenvector and the distance between the fourth eigenvector and the k second eigenvectors, k eigenvectors are determined from the multiple eigenvectors as the k second eigenvectors updated in the i-th round of iterative updates, and the first eigenvector updated in the i-1th round of iterative updates is determined as the first eigenvector updated in the i-th round of iterative updates; When the first random number is less than the iteration parameter, based on the average distance of the k second distances and the third feature vector updated in the i-1th round of iterative update, a feature vector is determined from the multiple feature vectors as the first feature vector updated in the i-th round of iterative update, and the k second feature vectors updated in the i-1th round of iterative update are determined as the k second feature vectors updated in the i-th round of iterative update.
5. The method according to claim 2, characterized in that The step of determining the k target feature vectors based on the k second feature vectors corresponding to the multiple fitness function values and multiple rounds of iterative updates includes: Determine the minimum fitness function value among the multiple fitness function values as the target fitness function value; The k second feature vectors corresponding to the iterative update round in which the target fitness function value is located are determined as the k target feature vectors.
6. The method according to claim 1, characterized in that The clustering of the plurality of to-be-classified texts based on the k target feature vectors to obtain the category of each of the to-be-classified texts includes: Taking the k target feature vectors as k initial centroids, and determining k clusters based on distances between the k initial centroids and a plurality of fifth feature vectors, wherein the plurality of fifth feature vectors are other feature vectors in the plurality of feature vectors except the k target feature vectors; Based on the distances between multiple feature vectors in the k clusters and the centroids of the k clusters, multiple rounds of iterative updates are performed on the centroids of the k clusters and the k clusters to obtain k target clusters, where the k target clusters correspond to k categories, and the text to be classified corresponding to the feature vector in any one of the k target clusters belongs to the same category.
7. The method according to claim 6, characterized in that The step of determining k clusters based on the distances between the k initial centroids and a plurality of fourth eigenvectors comprises: For any one of the k initial centroids, determining a fourth distance between the plurality of fifth eigenvectors and the initial centroid; The fifth eigenvectors of the plurality of fifth eigenvectors whose fourth distance is less than a preset distance threshold are allocated to the initial centroid, so as to obtain a cluster with the initial centroid as the center point.
8. The method according to claim 6, characterized in that The step of performing multiple rounds of iterative updates on the centroids of the k clusters and the k clusters based on the distances between the multiple feature vectors of the k clusters and the centroids of the k clusters to obtain k target clusters includes: For any one round of iterative updating in the multiple rounds of iterative updating, for any one cluster among the k clusters, based on the distances between a plurality of feature vectors in the cluster and the centroid of the cluster, re-determining the centroid of the cluster; Based on the distances between the re-determined centroids of the k clusters and the multiple sixth eigenvectors, the eigenvectors within the k clusters are re-determined until the maximum number of iterations is reached, and the k clusters obtained by the last iteration update are the k target clusters, and the multiple sixth eigenvectors are the eigenvectors in the multiple eigenvectors except the centroids of the k clusters.
9. A comment text classification device, characterized in that: The device comprises: A feature extraction module, used for extracting features from a plurality of texts to be classified to obtain a plurality of feature vectors, wherein the plurality of texts to be classified are comment texts received by the vehicle platform; An optimization module, used for performing preset optimization on the multiple feature vectors to obtain k target feature vectors, wherein the k target feature vectors are feature vectors obtained by performing a global search, and k is the same as the number of all categories of the multiple texts to be classified; The clustering module is used to cluster the multiple texts to be classified based on the k target feature vectors to obtain the category of each of the texts to be classified.
10. A computer device, characterized in that: The computer device comprises a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program implements the method according to any one of claims 1 to 8 when executed by the processor.