Text clustering method, device, electronic device and storage medium
By combining the semantic recognition model with clustering operations and adjusting the model parameters to meet the preset conditions, the low accuracy problem caused by the differences in semantic space between deep learning models and text clustering algorithms is solved, and the accuracy of text clustering is improved.
Patent Information
- Application Number
- CN202310381393.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-04-04
- Publication Date
- 2025-09-09
- Estimated Expiration
- 2043-04-04
AI Technical Summary
In the existing technology, large-scale language pre-training models and text clustering algorithms based on deep learning have low accuracy when clustering text due to the differences in semantic space.
The semantic recognition model is used to perform semantic recognition on the clustering data set, calculate the semantic vector set and perform clustering operations, adjust the semantic recognition model parameters, and exit the operation when the preset conditions are met to obtain the clustering results.
The accuracy of text clustering is improved by optimizing semantic recognition and clustering operations in the same semantic space, thereby improving the accuracy of clustering results.
Smart Images

Figure CN116521867B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a text clustering method, device, electronic device and storage medium. Background Art
[0002] Text clustering is a common method widely used in the cold start phase of conversational robot projects. During this phase, a large amount of unlabeled data in natural language processing tasks needs to be analyzed and organized to improve work efficiency. It is especially widely used in summarizing conversation intentions and sorting out scenario scripts.
[0003] In the existing technology, text is usually processed using a large-scale language pre-training model based on deep learning, and then analyzed and sorted using a text clustering algorithm to improve the efficiency of text clustering. However, when this method processes text based on a large-scale language pre-training model based on deep learning and a text clustering algorithm, the semantic space represented by the language pre-training model and the text clustering algorithm is different, resulting in low accuracy of text clustering. Summary of the Invention
[0004] The present invention provides a text clustering method, device, electronic device and storage medium, the main purpose of which is to improve the accuracy of text clustering.
[0005] To achieve the above object, the present invention provides a text clustering method, comprising:
[0006] Acquire a data set to be clustered, and perform a semantic recognition operation on the data set to be clustered using a preset semantic recognition model to obtain a semantic vector set;
[0007] Performing a clustering operation on the semantic vector set to obtain a cluster set;
[0008] Calculating the distance between each semantic vector and the corresponding cluster center in each cluster in the cluster set in sequence;
[0009] When the distance does not meet the preset clustering distance condition, adjusting the parameters of the preset semantic recognition model, and using the adjusted semantic recognition model to perform a semantic recognition operation on the data set to be clustered to obtain an adjusted semantic vector set;
[0010] Performing a clustering operation on the adjusted semantic vector set to obtain an adjusted cluster cluster set, and calculating a cluster data difference between the adjusted cluster cluster set and the cluster cluster set;
[0011] When the sample difference does not meet the preset sample difference condition, return to the above step of performing clustering operation on the semantic vector set to obtain a cluster cluster set, until the cluster data difference between the cluster cluster sets obtained after two adjacent clustering operations meets the preset cluster data difference condition, or the distance meets the preset cluster distance condition, exit the above semantic recognition operation and clustering operation, and use the cluster cluster set obtained by the last clustering operation as the clustering result of the data set to be clustered.
[0012] Optionally, the using a preset semantic recognition model to perform a semantic recognition operation on the data set to be clustered to obtain a semantic vector set includes:
[0013] Adding a text start symbol before each data to be clustered in the data set to be clustered;
[0014] According to the text start symbol, the data set to be clustered is received using the preset semantic recognition model, and the data set to be clustered is subjected to text vector mapping in the preset semantic recognition model to obtain a plurality of text vector mapping results;
[0015] The multiple text vector mapping results are aggregated to obtain the semantic vector set.
[0016] Optionally, performing a clustering operation on the semantic vector set to obtain a cluster set includes:
[0017] Randomly selecting a preset number of semantic vectors from the semantic vector set as cluster centers;
[0018] According to the distance between each semantic vector in the semantic vector set and the cluster center, clustering is performed on the remaining semantic vectors in the semantic vector set to obtain the cluster cluster set.
[0019] Optionally, sequentially calculating the distance between each semantic vector of each cluster in the cluster set and the corresponding cluster center includes:
[0020] The MSE distance formula is used to calculate the distance from each semantic vector to the corresponding cluster center in each cluster in the cluster set:
[0021]
[0022] Among them, the is the distance from the i-th semantic vector to the corresponding cluster center in each cluster in the cluster set, γ is the hyperparameter for adjusting the contribution of the MSE function, f(x i ) is the vector representation of the i-th semantic vector, M i is the semantic vector of the cluster center of the cluster corresponding to the i-th semantic vector.
[0023] Optionally, the calculating the cluster data difference between the adjusted cluster set and the cluster set includes:
[0024] Counting the number of difference semantic vectors between the adjusted cluster set and the cluster set;
[0025] The ratio of the number of the difference semantic vectors to the total number of semantic vectors is calculated to obtain the cluster data difference degree.
[0026] Optionally, before performing a semantic recognition operation on the data set to be clustered using a preset semantic recognition model to obtain a semantic vector set, the method further includes:
[0027] Obtain intent-labeled samples, and extract samples with the same labeling category from the intent-labeled samples to obtain a batch intent-labeled sample set;
[0028] Randomly select one labeled sample from the batch of intent labeled samples as the intent labeled positive sample, and use the remaining labeled samples in the batch of intent labeled samples as the intent labeled negative sample set;
[0029] Reconstructing and pre-training the preset semantic recognition model using the intention-labeled positive samples and the intention-labeled negative sample set as training corpus to obtain positive sample semantic vectors and negative sample semantic vector sets;
[0030] Calculating a loss value between each negative sample semantic vector in the negative sample semantic vector set and the positive sample semantic vector;
[0031] When the loss value satisfies a preset loss condition, the sequence reconstruction pre-training process of the preset semantic recognition model is ended.
[0032] Optionally, calculating the loss value between the negative sample semantic vector corresponding to the intention-labeled negative sample and the positive sample semantic vector corresponding to the intention-labeled positive sample includes:
[0033] The following loss function formula is used:
[0034]
[0035] Among them, L reqa is the loss value between the negative sample semantic vector corresponding to the negative sample labeled with the intent and the positive sample semantic vector corresponding to the positive sample labeled with the intent, B is the total number of intent labeled samples in the batch, τ is the temperature parameter, The semantic vector of the i-th intention-labeled positive sample in the batch of intention-labeled samples, is the semantic vector of the jth intention-labeled negative sample in the batch of intention-labeled samples, q is the intention-labeled positive sample in the batch of intention-labeled samples, and a is the intention-labeled negative sample in the batch of intention-labeled samples.
[0036] In order to solve the above problems, the present invention further provides a text clustering device, which includes:
[0037] The module for processing the data set to be clustered is used to obtain the data set to be clustered, perform semantic recognition operations on the data set to be clustered using a preset semantic recognition model, and obtain a semantic vector set;
[0038] An initial clustering module, configured to perform a clustering operation on the semantic vector set to obtain a cluster set;
[0039] A model optimization module is used to sequentially calculate the distance between each semantic vector under each cluster in the cluster set and the corresponding cluster center; when the distance does not meet the preset cluster distance condition, adjust the parameters of the preset semantic recognition model, and use the adjusted semantic recognition model to perform a semantic recognition operation on the data set to be clustered to obtain an adjusted semantic vector set; perform a clustering operation on the adjusted semantic vector set to obtain an adjusted cluster cluster set, and calculate the cluster data difference between the adjusted cluster cluster set and the cluster cluster set;
[0040] The text clustering result generation module is used to return to the above-mentioned step of performing clustering operation on the semantic vector set to obtain a cluster cluster set when the sample difference does not meet the preset sample difference condition, until the cluster data difference between the cluster cluster sets obtained after two adjacent clustering operations meets the preset cluster data difference condition, or the distance meets the preset cluster distance condition, then exit the above-mentioned semantic recognition operation and clustering operation, and use the cluster cluster set obtained by the last clustering operation as the clustering result of the data set to be clustered.
[0041] In order to solve the above problem, the present invention further provides an electronic device, comprising:
[0042] at least one processor; and,
[0043] a memory communicatively connected to the at least one processor; wherein,
[0044] The memory stores a computer program that can be executed by the at least one processor. The computer program is executed by the at least one processor to enable the at least one processor to perform the above-mentioned text clustering method.
[0045] In order to solve the above problem, the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores at least one computer program, and the at least one computer program is executed by a processor in an electronic device to implement the above-mentioned text clustering method.
[0046] The embodiment of the present invention performs semantic recognition operations on a clustering data set through a semantic recognition model, and performs clustering operations on the recognized semantic vector set. The semantic recognition model is adjusted according to the distance between each semantic vector in the cluster cluster and the corresponding cluster center, and the semantic recognition operation is repeated. The newly generated semantic vector set is clustered again, and the clustering operation is repeated according to the clustering data difference between the cluster clusters obtained by two adjacent clustering operations. Compared with the traditional situation of first performing a semantic recognition operation and then performing multiple clustering operations, the above-mentioned semantic recognition operation is combined with the clustering operation, so that the language pre-training model and the text clustering algorithm both use the data represented in the same semantic space to perform semantic recognition operations and clustering operations, and continuously adjust and optimize the results of the semantic recognition operation and clustering operation, thereby improving the accuracy of text clustering. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] Figure 1 A flowchart of a text clustering method provided by one embodiment of the present invention;
[0048] Figure 2 A detailed flowchart of a step in a text clustering method provided by one embodiment of the present invention;
[0049] Figure 3 A functional module diagram of a text clustering device provided by an embodiment of the present invention;
[0050] Figure 4 A schematic structural diagram of an electronic device for implementing the text clustering method provided by an embodiment of the present invention.
[0051] The purpose, features and advantages of the present invention will be further described with reference to the accompanying drawings and in conjunction with the embodiments. DETAILED DESCRIPTION
[0052] It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.
[0053] The embodiment of the present application provides a text clustering method. The execution subject of the text clustering method includes but is not limited to at least one of the electronic devices such as a server, a terminal, etc. that can be configured to execute the method provided by the embodiment of the present application. In other words, the text clustering method can be executed by software or hardware installed on a terminal device or a server device, and the software can be a blockchain platform. The server includes but is not limited to: a single server, a server cluster, a cloud server or a cloud server cluster, etc. The server can be an independent server, or it can be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms.
[0054] Reference Figure 1 FIG. 1 is a flow chart of a text clustering method provided by an embodiment of the present invention.
[0055] In this embodiment, the text clustering method includes the following steps S1-S6:
[0056] S1. Obtain a data set to be clustered, and perform a semantic recognition operation on the data set to be clustered using a preset semantic recognition model to obtain a semantic vector set;
[0057] In an embodiment of the present invention, the data set to be clustered refers to a large amount of unlabeled log data set that needs to be analyzed and organized. For example, the data set to be clustered includes conversation intention data, scenario script data, etc.
[0058] In an embodiment of the present invention, the preset semantic recognition model refers to a semantic recognition model obtained by using the Bert model as a basic model and then reconstructing and pre-training the basic model, wherein the semantic recognition model can achieve the purpose of inputting the entire sentence sequence and outputting a semantic vector that represents the semantic information of the entire sentence through the reconstruction pre-training.
[0059] In the embodiment of the present invention, before performing a semantic recognition operation on the data set to be clustered using a preset semantic recognition model to obtain a semantic vector set, the method further includes:
[0060] Obtain intent-labeled samples, and extract samples with the same labeling category from the intent-labeled samples to obtain a batch intent-labeled sample set;
[0061] Randomly select one labeled sample from the batch of intent labeled samples as the intent labeled positive sample, and use the remaining labeled samples in the batch of intent labeled samples as the intent labeled negative sample set;
[0062] Reconstructing and pre-training the preset semantic recognition model using the intention-labeled positive samples and the intention-labeled negative sample set as training corpus to obtain positive sample semantic vectors and negative sample semantic vector sets;
[0063] Calculating a loss value between each negative sample semantic vector in the negative sample semantic vector set and the positive sample semantic vector;
[0064] When the loss value satisfies a preset loss condition, the sequence reconstruction pre-training process of the preset semantic recognition model is ended.
[0065] The embodiment of the present invention is based on the principle that semantically similar sentences also have similar semantic vector representations. By randomly selecting one labeled sample from the batch of intent-labeled samples as an intent-labeled positive sample, and using the remaining labeled samples in the batch of intent-labeled samples as intent-labeled negative samples, the intent-labeled positive sample and the intent-labeled negative sample are simultaneously involved in model training, so that the preset semantic recognition model can achieve the effect of concentrated distribution of positive sample vectors and away from negative sample vectors.
[0066] The embodiment of the present invention calculates the loss value between the negative sample semantic vector corresponding to the intention-labeled negative sample and the positive sample semantic vector corresponding to the intention-labeled positive sample, using the following loss function formula:
[0067]
[0068] Among them, L reqa is the loss value between the negative sample semantic vector corresponding to the negative sample labeled with the intent and the positive sample semantic vector corresponding to the positive sample labeled with the intent, B is the total number of intent labeled samples in the batch, τ is the temperature parameter, The semantic vector of the i-th intention-labeled positive sample in the batch of intention-labeled samples, is the semantic vector of the jth intention-labeled negative sample in the batch of intention-labeled samples, q is the intention-labeled positive sample in the batch of intention-labeled samples, and a is the intention-labeled negative sample in the batch of intention-labeled samples.
[0069] In the embodiment of the present invention, the complete semantic information of the entire data to be clustered cannot be reflected through the keywords in the data to be clustered. Therefore, it is necessary to perform semantic extraction on the entire data to be clustered and convert it into a vector format to obtain a semantic vector of the data to be clustered.
[0070] For details, refer to Figure 2 As shown, the method of performing semantic recognition operation on the data set to be clustered using a preset semantic recognition model to obtain a semantic vector set includes the following steps S100-S102:
[0071] S100, adding a text start symbol before each data to be clustered in the data set to be clustered;
[0072] S101, receiving the data set to be clustered using the preset semantic recognition model according to the text start symbol, and performing text vector mapping on the data set to be clustered in the preset semantic recognition model to obtain multiple text vector mapping results;
[0073] S102: Summarize the multiple text vector mapping results to obtain the semantic vector set.
[0074] In the embodiment of the present invention, the text start character refers to adding an identification character in front of the text to facilitate semantic recognition and semantic vector conversion of multiple text data.
[0075] S2. performing a clustering operation on the semantic vector set to obtain a cluster set;
[0076] In the embodiment of the present invention, the semantic vectors are clustered using the K-Means clustering method.
[0077] In detail, the clustering operation is performed on the semantic vector set to obtain a cluster set, including:
[0078] Randomly selecting a preset number of semantic vectors from the semantic vector set as cluster centers;
[0079] According to the distance between each semantic vector in the semantic vector set and the cluster center, clustering is performed on the remaining semantic vectors in the semantic vector set to obtain the cluster cluster set.
[0080] In an embodiment of the present invention, the clustering operation is a data processing method. For example, the data can be split into multiple clusters according to the intrinsic properties of the data based on the principle that the data blocks in each cluster have as similar characteristics as possible and the characteristics of different clusters are as different as possible. After performing cluster analysis, the data objects in a cluster can be treated as a whole data.
[0081] S3, sequentially calculating the distance between each semantic vector under each cluster in the cluster set and the corresponding cluster center;
[0082] The embodiment of the present invention uses the MSE distance formula to sequentially calculate the distance between each semantic vector in each cluster in the cluster set and the corresponding cluster center:
[0083]
[0084] Among them, the is the distance from the i-th semantic vector to the corresponding cluster center in each cluster in the cluster set, γ is the hyperparameter for adjusting the contribution of the MSE function, f(x i ) is the vector representation of the i-th semantic vector, M i is the semantic vector of the cluster center of the cluster corresponding to the i-th semantic vector.
[0085] S4. When the distance does not meet the preset clustering distance condition, adjust the parameters of the preset semantic recognition model, and use the adjusted semantic recognition model to perform a semantic recognition operation on the data set to be clustered to obtain an adjusted semantic vector set;
[0086] In the embodiment of the present invention, the preset cluster distance condition refers to a distance threshold from each semantic vector to the corresponding cluster center.
[0087] The embodiment of the present invention adjusts the parameters of the semantic model that does not meet the preset clustering distance condition, so that the semantic model can adaptively change the applicability of the model according to the change of the scene, thereby meeting the needs of scene change.
[0088] In the embodiment of the present invention, when the distance satisfies the preset clustering distance condition, the cluster set obtained by the last clustering operation is used as the clustering result of the data set to be clustered.
[0089] S5. performing a clustering operation on the adjusted semantic vector set to obtain an adjusted cluster cluster set, and calculating a cluster data difference between the adjusted cluster cluster set and the cluster cluster set;
[0090] In the embodiment of the present invention, the method of performing a clustering operation on the adjusted semantic vector set to obtain an adjusted cluster set is consistent with the above-mentioned method of performing a clustering operation on the semantic vector set to obtain a cluster set, which will not be repeated here.
[0091] In the embodiment of the present invention, the difference degree refers to the difference rate between the cluster set and the adjusted cluster set, and the measurement standard can be represented by the number of samples changed in the two cluster sets.
[0092] As an embodiment of the present invention, the calculating of the cluster data difference between the adjusted cluster set and the cluster set includes:
[0093] Counting the number of difference semantic vectors between the adjusted cluster set and the cluster set;
[0094] The ratio of the number of the difference semantic vectors to the total number of semantic vectors is calculated to obtain the cluster data difference degree.
[0095] S6. When the sample difference does not meet the preset sample difference condition, return to the above step of performing clustering operation on the semantic vector set to obtain a cluster cluster set, until the cluster data difference between the cluster cluster sets obtained after two adjacent clustering operations meets the preset cluster data difference condition, or the distance meets the preset cluster distance condition, exit the above semantic recognition operation and clustering operation, and use the cluster cluster set obtained by the last clustering operation as the clustering result of the data set to be clustered.
[0096] In the embodiment of the present invention, the preset clustering data difference condition refers to a ratio threshold of the number of different semantic vectors between cluster sets obtained from two adjacent clustering operations to all semantic vectors. For example, the ratio threshold can be set to 5%.
[0097] The embodiment of the present invention performs semantic recognition operations on a clustering data set through a semantic recognition model, and performs clustering operations on the recognized semantic vector set. The semantic recognition model is adjusted according to the distance between each semantic vector in the cluster cluster and the corresponding cluster center, and the semantic recognition operation is repeated. The newly generated semantic vector set is clustered again, and the clustering operation is repeated according to the clustering data difference between the cluster clusters obtained by two adjacent clustering operations. Compared with the traditional situation of first performing a semantic recognition operation and then performing multiple clustering operations, the above-mentioned semantic recognition operation is combined with the clustering operation, so that the language pre-training model and the text clustering algorithm both use the data represented in the same semantic space to perform semantic recognition operations and clustering operations, and continuously adjust and optimize the results of the semantic recognition operation and clustering operation, thereby improving the accuracy of text clustering.
[0098] like Figure 3 FIG. 1 is a functional module diagram of a text clustering device provided by an embodiment of the present invention.
[0099] The text clustering device 100 of the present invention can be installed in an electronic device. Depending on the functionality to be implemented, the text clustering device 100 may include a to-be-clustered dataset processing module 101, an initial clustering module 102, a model optimization module 103, and a text clustering result generation module 104. A module, also referred to as a unit, is a series of computer program segments that can be executed by an electronic device processor and perform a fixed function, and is stored in the electronic device's memory.
[0100] In this embodiment, the functions of each module / unit are as follows:
[0101] The to-be-clustered dataset processing module 101 is configured to obtain a to-be-clustered dataset, perform semantic recognition operations on the to-be-clustered dataset using a preset semantic recognition model, and obtain a semantic vector set;
[0102] In an embodiment of the present invention, the data set to be clustered refers to a large amount of unlabeled log data set that needs to be analyzed and organized. For example, the data set to be clustered includes conversation intention data, scenario script data, etc.
[0103] In an embodiment of the present invention, the preset semantic recognition model refers to a semantic recognition model obtained by using the Bert model as a basic model and then reconstructing and pre-training the basic model through sequence-to-sequence. The semantic recognition model can achieve the purpose of inputting the entire sentence sequence and outputting a semantic vector that represents the semantic information of the entire sentence through the reconstruction training.
[0104] In the embodiment of the present invention, before performing a semantic recognition operation on the data set to be clustered using a preset semantic recognition model to obtain a semantic vector set, the method further includes:
[0105] Obtain intent-labeled samples, and extract samples with the same labeling category from the intent-labeled samples to obtain a batch intent-labeled sample set;
[0106] Randomly select one labeled sample from the batch of intent labeled samples as the intent labeled positive sample, and use the remaining labeled samples in the batch of intent labeled samples as the intent labeled negative sample set;
[0107] Reconstructing and pre-training the preset semantic recognition model using the intention-labeled positive samples and the intention-labeled negative sample set as training corpus to obtain positive sample semantic vectors and negative sample semantic vector sets;
[0108] Calculating a loss value between each negative sample semantic vector in the negative sample semantic vector set and the positive sample semantic vector;
[0109] When the loss value satisfies a preset loss condition, the sequence reconstruction pre-training process of the preset semantic recognition model is ended.
[0110] The embodiment of the present invention is based on the principle that semantically similar sentences also have similar semantic vector representations. By randomly selecting one labeled sample from the batch of intent-labeled samples as an intent-labeled positive sample, and using the remaining labeled samples in the batch of intent-labeled samples as intent-labeled negative samples, the intent-labeled positive sample and the intent-labeled negative sample are simultaneously involved in model training, so that the preset semantic recognition model can achieve the effect of concentrated distribution of positive sample vectors and away from negative sample vectors.
[0111] The embodiment of the present invention calculates the loss value between the negative sample semantic vector corresponding to the intention-labeled negative sample and the positive sample semantic vector corresponding to the intention-labeled positive sample, using the following loss function formula:
[0112]
[0113] Among them, L reqa is the loss value between the negative sample semantic vector corresponding to the negative sample labeled with the intent and the positive sample semantic vector corresponding to the positive sample labeled with the intent, B is the total number of intent labeled samples in the batch, τ is the temperature parameter, The semantic vector of the i-th intention-labeled positive sample in the batch of intention-labeled samples, is the semantic vector of the jth intention-labeled negative sample in the batch of intention-labeled samples, q is the intention-labeled positive sample in the batch of intention-labeled samples, and a is the intention-labeled negative sample in the batch of intention-labeled samples.
[0114] In the embodiment of the present invention, the complete semantic information of the entire data to be clustered cannot be reflected through the keywords in the data to be clustered. Therefore, it is necessary to perform semantic extraction on the entire data to be clustered and convert it into a vector format to obtain a semantic vector of the data to be clustered.
[0115] In detail, the method of performing semantic recognition operation on the data set to be clustered using a preset semantic recognition model to obtain a semantic vector set includes:
[0116] Adding a text start symbol before each data to be clustered in the data set to be clustered;
[0117] According to the text start symbol, the data set to be clustered is received using the preset semantic recognition model, and the data set to be clustered is subjected to text vector mapping in the preset semantic recognition model to obtain a plurality of text vector mapping results;
[0118] The multiple text vector mapping results are aggregated to obtain the semantic vector set.
[0119] In the embodiment of the present invention, the text start character refers to adding an identification character in front of the text to facilitate semantic recognition and semantic vector conversion of multiple text data.
[0120] The initial clustering module 102 is used to perform a clustering operation on the semantic vector set to obtain a cluster set;
[0121] In the embodiment of the present invention, the semantic vectors are clustered using the K-Means clustering method.
[0122] In detail, the clustering operation is performed on the semantic vector set to obtain a cluster set, including:
[0123] Randomly selecting a preset number of semantic vectors from the semantic vector set as cluster centers;
[0124] According to the distance between each semantic vector in the semantic vector set and the cluster center, clustering is performed on the remaining semantic vectors in the semantic vector set to obtain the cluster cluster set.
[0125] In an embodiment of the present invention, the clustering operation is a data processing method. For example, the data can be split into multiple clusters according to the intrinsic properties of the data based on the principle that the data blocks in each cluster have as similar characteristics as possible and the characteristics of different clusters are as different as possible. After performing cluster analysis, the data objects in a cluster can be treated as a whole data.
[0126] The model optimization module 103 is used to sequentially calculate the distance between each semantic vector under each cluster in the cluster set and the corresponding cluster center; when the distance does not meet the preset cluster distance condition, adjust the parameters of the preset semantic recognition model, and use the adjusted semantic recognition model to perform a semantic recognition operation on the data set to be clustered to obtain an adjusted semantic vector set; perform a clustering operation on the adjusted semantic vector set to obtain an adjusted cluster cluster set, and calculate the cluster data difference between the adjusted cluster cluster set and the cluster cluster set;
[0127] The embodiment of the present invention uses the MSE distance formula to sequentially calculate the distance between each semantic vector in each cluster in the cluster set and the corresponding cluster center:
[0128]
[0129] Among them, the is the distance from the i-th semantic vector to the corresponding cluster center in each cluster in the cluster set, γ is the hyperparameter for adjusting the contribution of the MSE function, f(x i ) is the vector representation of the i-th semantic vector, M i is the semantic vector of the cluster center of the cluster corresponding to the i-th semantic vector.
[0130] In the embodiment of the present invention, the preset cluster distance condition refers to a distance threshold from each semantic vector to the corresponding cluster center.
[0131] The embodiment of the present invention adjusts the parameters of the semantic model that does not meet the preset clustering distance condition, so that the semantic model can adaptively change the applicability of the model according to the change of the scene, thereby meeting the needs of scene change.
[0132] In the embodiment of the present invention, the method of performing a clustering operation on the adjusted semantic vector set to obtain an adjusted cluster set is consistent with the above-mentioned method of performing a clustering operation on the semantic vector set to obtain a cluster set, which will not be repeated here.
[0133] In the embodiment of the present invention, the difference degree refers to the difference rate between the cluster set and the adjusted cluster set, and the measurement standard can be represented by the number of samples changed in the two cluster sets.
[0134] As an embodiment of the present invention, the calculating of the cluster data difference between the adjusted cluster set and the cluster set includes:
[0135] Counting the number of difference semantic vectors between the adjusted cluster set and the cluster set;
[0136] The ratio of the number of the difference semantic vectors to the total number of semantic vectors is calculated to obtain the cluster data difference degree.
[0137] The text clustering result generation module 104 is used to return to the above-mentioned step of performing clustering operation on the semantic vector set to obtain a cluster cluster set when the sample difference does not meet the preset sample difference condition, until the cluster data difference between the cluster cluster sets obtained after two adjacent clustering operations meets the preset cluster data difference condition, or the distance meets the preset cluster distance condition, then exit the above-mentioned semantic recognition operation and clustering operation, and use the cluster cluster set obtained by the last clustering operation as the clustering result of the data set to be clustered.
[0138] In the embodiment of the present invention, the preset clustering data difference condition refers to a ratio threshold of the number of different semantic vectors between cluster sets obtained from two adjacent clustering operations to all semantic vectors. For example, the ratio threshold can be set to 5%.
[0139] like Figure 4 FIG. 1 is a schematic diagram of the structure of an electronic device for implementing a text clustering method provided by an embodiment of the present invention.
[0140] The electronic device may include a processor 10 , a memory 11 , a communication bus 12 , and a communication interface 13 , and may further include a computer program stored in the memory 11 and executable on the processor 10 , such as a text clustering program.
[0141] In some embodiments, the processor 10 may be composed of an integrated circuit, for example, a single packaged integrated circuit, or a plurality of packaged integrated circuits with the same or different functions, including one or more central processing units (CPUs), microprocessors, digital processing chips, graphics processors, and a combination of various control chips. The processor 10 is the control core (Control Unit) of the electronic device, connecting the various components of the entire electronic device using various interfaces and lines, and executing or executing programs or modules stored in the memory 11 (for example, executing a text clustering program, etc.), as well as calling data stored in the memory 11, to perform various functions of the electronic device and process data.
[0142] The memory 11 includes at least one type of readable storage medium, and the readable storage medium includes a flash memory, a mobile hard disk, a multimedia card, a card-type memory (for example, an SD or DX memory, etc.), a magnetic memory, a disk, an optical disk, etc. In some embodiments, the memory 11 may be an internal storage unit of an electronic device, such as a mobile hard disk of the electronic device. In other embodiments, the memory 11 may also be an external storage device of an electronic device, such as a plug-in mobile hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. equipped on the electronic device. Furthermore, the memory 11 may also include both an internal storage unit of the electronic device and an external storage device. The memory 11 can be used not only to store application software and various types of data installed in the electronic device, such as the code of a text clustering program, but also to temporarily store data that has been output or is to be output.
[0143] The communication bus 12 may be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus. The bus may be divided into an address bus, a data bus, a control bus, etc. The bus is configured to enable communication between the memory 11 and at least one processor 10, etc.
[0144] The communication interface 13 is used for communication between the above-mentioned electronic device and other devices, including a network interface and a user interface. Optionally, the network interface may include a wired interface and / or a wireless interface (such as a WI-FI interface, a Bluetooth interface, etc.), which is generally used to establish a communication connection between the electronic device and other electronic devices. The user interface may be a display (Display), an input unit (such as a keyboard (Keyboard)), optionally, the user interface may also be a standard wired interface, a wireless interface. Optionally, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, and an OLED (Organic Light-Emitting Diode, organic light-emitting diode) touch device, etc. Among them, the display may also be appropriately referred to as a display screen or a display unit, which is used to display information processed in the electronic device and to display a visual user interface.
[0145] Figure 4 Only the electronic device with components is shown, and it can be understood by those skilled in the art that Figure 4 The structure shown does not limit the electronic device, and may include fewer or more components than shown in the figure, or combine certain components, or arrange the components differently.
[0146] For example, although not shown, the electronic device may further include a power source (such as a battery) for powering various components. Preferably, the power source may be logically connected to the at least one processor 10 via a power management device, thereby implementing functions such as charge management, discharge management, and power consumption management through the power management device. The power source may further include any components such as one or more DC or AC power sources, a recharging device, a power failure detection circuit, a power converter or inverter, a power status indicator, etc. The electronic device may further include various sensors, Bluetooth modules, Wi-Fi modules, etc., which will not be described in detail here.
[0147] It should be understood that the embodiment is for illustration only and the scope of the patent application is not limited to this structure.
[0148] The text clustering program stored in the memory 11 of the electronic device is a combination of multiple instructions. When executed in the processor 10, the following can be achieved:
[0149] Acquire a data set to be clustered, and perform a semantic recognition operation on the data set to be clustered using a preset semantic recognition model to obtain a semantic vector set;
[0150] Performing a clustering operation on the semantic vector set to obtain a cluster set;
[0151] Calculating the distance between each semantic vector and the corresponding cluster center in each cluster in the cluster set in sequence;
[0152] When the distance does not meet the preset clustering distance condition, adjusting the parameters of the preset semantic recognition model, and using the adjusted semantic recognition model to perform a semantic recognition operation on the data set to be clustered to obtain an adjusted semantic vector set;
[0153] Performing a clustering operation on the adjusted semantic vector set to obtain an adjusted cluster cluster set, and calculating a cluster data difference between the adjusted cluster cluster set and the cluster cluster set;
[0154] When the sample difference does not meet the preset sample difference condition, return to the above step of performing clustering operation on the semantic vector set to obtain a cluster cluster set, until the cluster data difference between the cluster cluster sets obtained after two adjacent clustering operations meets the preset cluster data difference condition, or the distance meets the preset cluster distance condition, exit the above semantic recognition operation and clustering operation, and use the cluster cluster set obtained by the last clustering operation as the clustering result of the data set to be clustered.
[0155] Specifically, the specific implementation method of the processor 10 for the above instructions can refer to the description of the relevant steps in the corresponding embodiment of the accompanying drawings, which will not be repeated here.
[0156] Furthermore, if the modules / units integrated into the electronic device 1 are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. The computer-readable storage medium can be volatile or non-volatile. For example, the computer-readable medium can include: any entity or device capable of carrying the computer program code, a recording medium, a USB flash drive, a mobile hard drive, a magnetic disk, an optical disk, a computer memory, or a read-only memory (ROM).
[0157] The present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program. When the computer program is executed by a processor of an electronic device, the computer program can implement:
[0158] Acquire a data set to be clustered, and perform a semantic recognition operation on the data set to be clustered using a preset semantic recognition model to obtain a semantic vector set;
[0159] Performing a clustering operation on the semantic vector set to obtain a cluster set;
[0160] Calculating the distance between each semantic vector and the corresponding cluster center in each cluster in the cluster set in sequence;
[0161] When the distance does not meet the preset clustering distance condition, adjusting the parameters of the preset semantic recognition model, and using the adjusted semantic recognition model to perform a semantic recognition operation on the data set to be clustered to obtain an adjusted semantic vector set;
[0162] Performing a clustering operation on the adjusted semantic vector set to obtain an adjusted cluster cluster set, and calculating a cluster data difference between the adjusted cluster cluster set and the cluster cluster set;
[0163] When the sample difference does not meet the preset sample difference condition, return to the above step of performing clustering operation on the semantic vector set to obtain a cluster cluster set, until the cluster data difference between the cluster cluster sets obtained after two adjacent clustering operations meets the preset cluster data difference condition, or the distance meets the preset cluster distance condition, exit the above semantic recognition operation and clustering operation, and use the cluster cluster set obtained by the last clustering operation as the clustering result of the data set to be clustered.
[0164] In the several embodiments provided by the present invention, it should be understood that the disclosed devices, apparatuses, and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the module division is merely a logical function division, and other division methods may be used in actual implementation.
[0165] The modules described as separate components may or may not be physically separate, and the components shown as modules may or may not be physical units, that is, they may be located in one place or distributed across multiple network elements. Some or all of the modules may be selected to achieve the purpose of the solution of this embodiment according to actual needs.
[0166] In addition, the functional modules in various embodiments of the present invention may be integrated into a single processing unit, each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or hardware plus software functional modules.
[0167] It will be apparent to those skilled in the art that the present invention is not limited to the details of the exemplary embodiments described above, and that the present invention can be implemented in other specific forms without departing from the spirit or essential characteristics of the present invention.
[0168] Therefore, the embodiments should be considered in all respects as illustrative and non-restrictive, and the scope of the invention is defined by the appended claims rather than the foregoing description, and all changes that come within the meaning and range of equivalents of the claims are intended to be embraced therein. Any reference to a figure in a claim should not be construed as limiting the claim to which it relates.
[0169] Blockchain, as used in this article, refers to a novel application model for computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanisms, and encryption algorithms. Blockchain is essentially a decentralized database, a series of data blocks generated using cryptographic methods. Each block contains information about a batch of online transactions, used to verify the validity of this information (to prevent counterfeiting) and generate the next block. Blockchain can include the underlying blockchain platform, the platform product service layer, and the application service layer.
[0170] The embodiments of the present application can acquire and process relevant data based on artificial intelligence technology. Artificial Intelligence (AI) is the theory, method, technology, and application system that uses digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, perceive the environment, acquire knowledge, and use knowledge to achieve optimal results.
[0171] Furthermore, it is clear that the word "comprising" does not exclude other units or steps, and the singular does not exclude the plural. Multiple units or devices recited in a system claim may also be implemented by a single unit or device through software or hardware. Terms such as "first" and "second" are used to indicate names and do not imply any particular order.
[0172] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and are not limiting. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solutions of the present invention may be modified or replaced by equivalents without departing from the spirit and scope of the technical solutions of the present invention.
Claims
1. A text clustering method, characterized in that: The method comprises: Acquire a data set to be clustered, and perform a semantic recognition operation on the data set to be clustered using a preset semantic recognition model to obtain a semantic vector set; Performing a clustering operation on the semantic vector set to obtain a cluster set; Calculating the distance between each semantic vector and the corresponding cluster center in each cluster in the cluster set in sequence; When the distance does not meet the preset clustering distance condition, adjusting the parameters of the preset semantic recognition model, and using the adjusted semantic recognition model to perform a semantic recognition operation on the data set to be clustered to obtain an adjusted semantic vector set; performing a clustering operation on the adjusted semantic vector set to obtain an adjusted cluster cluster set, and calculating the cluster data difference between the adjusted cluster cluster set and the cluster cluster set; When the cluster data difference does not meet the preset cluster data difference condition, return to the above step of performing clustering operation on the semantic vector set to obtain cluster cluster sets, until the cluster data difference between the cluster cluster sets obtained after two adjacent clustering operations meets the preset cluster data difference condition, and use the cluster cluster set obtained by the last clustering operation as the clustering result of the data set to be clustered; The step of sequentially calculating the distance between each semantic vector of each cluster in the cluster set and the corresponding cluster center includes: The MSE distance formula is used to calculate the distance from each semantic vector to the corresponding cluster center in each cluster in the cluster set: Among them, the For each cluster in the cluster set, The distance from a semantic vector to the corresponding cluster center, To adjust the hyperparameters of the MSE function contribution, For the The vector representation of semantic vectors, For the said The semantic vector of the cluster center of the cluster corresponding to the semantic vector.
2. The text clustering method according to claim 1, wherein: The method of performing semantic recognition operation on the data set to be clustered by using a preset semantic recognition model to obtain a semantic vector set includes: Adding a text start symbol before each data to be clustered in the data set to be clustered; According to the text start symbol, the data set to be clustered is received using the preset semantic recognition model, and the data set to be clustered is subjected to text vector mapping in the preset semantic recognition model to obtain a plurality of text vector mapping results; The multiple text vector mapping results are aggregated to obtain the semantic vector set.
3. The text clustering method according to claim 1, wherein: The clustering operation is performed on the semantic vector set to obtain a cluster set, including: Randomly selecting a preset number of semantic vectors from the semantic vector set as cluster centers; According to the distance between each semantic vector in the semantic vector set and the cluster center, clustering is performed on the remaining semantic vectors in the semantic vector set to obtain the cluster cluster set.
4. The text clustering method according to claim 1, wherein: The calculating of the cluster data difference between the adjusted cluster set and the cluster set includes: Counting the number of difference semantic vectors between the adjusted cluster set and the cluster set; The ratio of the number of the difference semantic vectors to the total number of semantic vectors is calculated to obtain the cluster data difference degree.
5. The text clustering method according to claim 1, wherein: Before performing a semantic recognition operation on the to-be-clustered data set using a preset semantic recognition model to obtain a semantic vector set, the method further includes: Obtain intent-labeled samples, and extract samples with the same labeling category from the intent-labeled samples to obtain a batch intent-labeled sample set; Randomly select one labeled sample from the batch of intent labeled samples as the intent labeled positive sample, and use the remaining labeled samples in the batch of intent labeled samples as the intent labeled negative sample set; Reconstructing and pre-training the preset semantic recognition model using the intention-labeled positive samples and the intention-labeled negative sample set as training corpus to obtain positive sample semantic vectors and negative sample semantic vector sets; Calculating a loss value between each negative sample semantic vector in the negative sample semantic vector set and the positive sample semantic vector; When the loss value satisfies a preset loss condition, the sequence reconstruction pre-training process of the preset semantic recognition model is ended.
6. The text clustering method according to claim 5, wherein: The calculating the loss value between each negative sample semantic vector in the negative sample semantic vector set and the positive sample semantic vector includes: The following loss function formula is used: in, is the loss value between the negative sample semantic vector corresponding to the negative sample labeled with the intent and the positive sample semantic vector corresponding to the positive sample labeled with the intent, The total number of samples intended to be labeled for the batch, is the temperature parameter, Intended labeling sample for the batch semantic vectors as positive samples of intent annotation, Intended labeling sample for the batch semantic vectors as negative samples of intent annotation, The positive samples of intent labeling in the batch of intent labeling samples, Label negative samples for the intent in the batch of intent labeled samples.
7. A text clustering device for implementing the text clustering method according to any one of claims 1 to 6, characterized in that: The device comprises: The module for processing the data set to be clustered is used to obtain the data set to be clustered, perform semantic recognition operations on the data set to be clustered using a preset semantic recognition model, and obtain a semantic vector set; An initial clustering module, configured to perform a clustering operation on the semantic vector set to obtain a cluster set; A model optimization module is used to sequentially calculate the distance between each semantic vector under each cluster in the cluster set and the corresponding cluster center; when the distance does not meet the preset cluster distance condition, adjust the parameters of the preset semantic recognition model, and use the adjusted semantic recognition model to perform a semantic recognition operation on the data set to be clustered to obtain an adjusted semantic vector set; perform a clustering operation on the adjusted semantic vector set to obtain an adjusted cluster cluster set, and calculate the cluster data difference between the adjusted cluster cluster set and the cluster cluster set; The text clustering result generation module is used to return to the above-mentioned step of performing clustering operation on the semantic vector set to obtain a cluster cluster set when the cluster data difference does not meet the preset cluster data difference condition, until the cluster data difference between the cluster cluster sets obtained after two adjacent clustering operations meets the preset cluster data difference condition, or the distance meets the preset cluster distance condition, then exit the above-mentioned semantic recognition operation and clustering operation, and use the cluster cluster set obtained by the last clustering operation as the clustering result of the data set to be clustered.
8. An electronic device, characterized in that: The electronic device comprises: at least one processor; and, a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor. The computer program is executed by the at least one processor to enable the at least one processor to perform the text clustering method according to any one of claims 1 to 6.
9. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the text clustering method according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Image clustering method and device and computer readable storage medium
CN113590863A
Intention recognition method and device, computer equipment and storage medium
CN114528844A