A method and apparatus for clustering of discrete sequences
Patent Information
- Application Number
- CN202111006337.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-08-30
- Publication Date
- 2026-10-13
- Estimated Expiration
- 2041-08-30
AI Technical Summary
[0004]有鉴于此,本发明实施例提供了一种离散序列的聚类方法及装置,用于解决现有技术无法对离散序列进行聚类的问题
[0052]本发明实施例提供的离散序列的聚类方法在对包括多个离散序列的序列集合中的离散序列进行聚类时,首先获取包括组成序列集合中的各个离散序列的对象的对象集合,然后利用第一聚类算法获取所述对象集合中的对象的第一聚类结果,再根据所述第一聚类结果生成所述序列集合中的各个离散序列的第一特征向量,并利用第二聚类算法获取所述序列集合中的各个离散序列的第一特征向量的第二聚类结果,最后根据所述第二聚类结果输出所述序列集合中的离散序列的聚类结果。由于本发明实施例可以通过第一聚类算法获取组成离散序列的对象的第一聚类结果,并根据第一聚类结果将离散序列抽象为对应的第一特征向量,再通过第二聚类算法获取离散序列的第一特征向量的第二聚类结果,并根据第二聚类结果输出序列集合中的离散序列的聚类结果,因此本发明实施例提供了一种可以对离散序列进行聚类的方法,可以解决现有技术无法对离散序列进行聚类的问题。
Smart Images

Figure CN115730225B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of data processing technology, and in particular to a method and apparatus for clustering discrete sequences. Background Technology
[0002] Clustering tasks can typically be performed using either supervised or unsupervised learning algorithms. Supervised learning algorithms work by training a clustering model using a large amount of historical data with class labels, then classifying objects within the same category and grouping them into a single cluster. Unsupervised learning algorithms primarily use clustering algorithms to cluster objects. The principle of unsupervised learning is to predefine descriptive features of objects and group objects with similar features into the same cluster, thus achieving the clustering of objects in the task.
[0003] In practical engineering applications, there are sometimes needs to perform clustering tasks based on discrete sequences. However, because discrete sequences are difficult to categorize using labels, such clustering tasks cannot be performed using supervised learning algorithms. For example, evaluating the similarity of operation sequences from different mobile phone users requires clustering based on these sequences. However, the length of these sequences is variable, and the corresponding page types are numerous, making it difficult to transform the problem into a supervised learning problem and solve it using supervised learning algorithms through manual labeling. Furthermore, because existing clustering algorithms can only cluster single objects and cannot cluster discrete sequences, such clustering tasks cannot be directly transformed into unsupervised learning problems and solved using clustering algorithms. In summary, existing clustering algorithms cannot perform clustering tasks based on discrete sequences; therefore, how to cluster discrete sequences is a problem that urgently needs to be solved. Summary of the Invention
[0004] In view of this, embodiments of the present invention provide a method and apparatus for clustering discrete sequences, which solves the problem that the prior art cannot cluster discrete sequences.
[0005] To achieve the above objectives, the embodiments of the present invention provide the following technical solutions:
[0006] In a first aspect, embodiments of the present invention provide a clustering method for discrete sequences, comprising:
[0007] Obtain a set of objects, the set of objects comprising objects that make up each discrete sequence in the sequence set, the sequence set comprising multiple discrete sequences;
[0008] A first clustering result is obtained using a first clustering algorithm, wherein the first clustering result is the clustering result of the objects in the object set;
[0009] The first feature vector of each discrete sequence in the sequence set is generated based on the first clustering result. The first feature vector of any discrete sequence is a feature vector obtained by processing the number of objects in the discrete sequence belonging to each object cluster in the first clustering result.
[0010] A second clustering result is obtained using a second clustering algorithm. The second clustering result is the clustering result of the first feature vector of each discrete sequence in the sequence set.
[0011] Based on the second clustering result, output the clustering result of the discrete sequences in the sequence set.
[0012] As an optional implementation of this invention, obtaining the first clustering result using the first clustering algorithm includes:
[0013] Generate one-hot codes for each object in the object set based on pre-selected object features;
[0014] The third clustering result is obtained by using the first clustering algorithm. The third clustering result is the clustering result of the one-hot encoding of each object in the object set.
[0015] Based on the third clustering result, obtain the first clustering result.
[0016] As an optional implementation of this invention, generating the first feature vector of each discrete sequence in the sequence set based on the first clustering result includes:
[0017] Based on the first clustering result, obtain the number of objects in each discrete sequence of the sequence set that belong to each object cluster;
[0018] Based on the number of object clusters to which each discrete sequence in the sequence set belongs, the first feature vector of each discrete sequence in the sequence set is obtained.
[0019] As an optional implementation of this invention, obtaining the first feature vector of each discrete sequence in the sequence set based on the number of object clusters to which each discrete sequence in the sequence set belongs includes:
[0020] Based on the number of object clusters to which each discrete sequence in the sequence set belongs, a second feature vector is generated for each discrete sequence in the sequence set.
[0021] The second feature vector of each discrete sequence in the sequence set is processed based on a preset natural language processing model to obtain the first feature vector of each discrete sequence in the sequence set.
[0022] As an optional implementation of this invention, the step of processing the second feature vector of each discrete sequence in the sequence set based on a preset natural language processing model to obtain the first feature vector of each discrete sequence in the sequence set includes:
[0023] The second feature vector of each discrete sequence in the sequence set is processed based on the bag-of-words model to obtain the first feature vector of each discrete sequence in the sequence set.
[0024] As an optional implementation of this invention, the step of processing the second feature vector of each discrete sequence in the sequence set based on the bag-of-words model to obtain the first feature vector of each discrete sequence in the sequence set includes:
[0025] Obtain the term frequency (TF) of each element in the second feature vector of each discrete sequence. The TF of any element is the ratio of the value of that element to the total number of objects contained in the object cluster corresponding to that element.
[0026] Obtain the inverse text frequency index (IDF) of each element in the second feature vector of each discrete sequence. The IDF of any element is the logarithm of the ratio of the total number of discrete sequences in the sequence set to the number of discrete sequences in the sequence set that belong to the object cluster corresponding to that element.
[0027] Based on the TF and IDF of each element in the second feature vector of each discrete sequence, the weight ratio of each element is obtained. The weight ratio of any element is the product of the TF and IDF of that element.
[0028] The first feature vector of each discrete sequence in the sequence set is obtained based on the weight ratio of each element in the second feature vector of each discrete sequence.
[0029] As an optional implementation of this invention, the step of processing the second feature vector of each discrete sequence in the sequence set based on a preset natural language processing model to obtain the first feature vector of each discrete sequence in the sequence set includes:
[0030] Based on the second feature vector of each discrete sequence in the sequence set, obtain the feature matrix of the sequence set;
[0031] Based on the feature matrix and word vector model of the sequence set, the first feature vector of each discrete sequence in the sequence set is obtained.
[0032] As an optional implementation of the present invention, the word vector model is a word2vec model, a doc2vec model, or a deep bidirectional representation BERT model.
[0033] As an optional implementation of the present invention, the discrete sequence is a sequence composed of page layout files of the user interface displayed sequentially on the user operation terminal device.
[0034] Secondly, embodiments of the present invention provide a clustering apparatus for discrete sequences, comprising:
[0035] A generation unit is used to obtain an object set, the object set including objects that make up each discrete sequence in a sequence set, the sequence set including multiple discrete sequences;
[0036] The first clustering unit is used to obtain a first clustering result using a first clustering algorithm, wherein the first clustering result is the clustering result of the objects in the object set;
[0037] The feature integration unit is used to generate a first feature vector for each discrete sequence in the sequence set based on the first clustering result. The first feature vector of any discrete sequence is a feature vector obtained by processing the number of objects in the discrete sequence belonging to each object cluster in the first clustering result.
[0038] The second clustering unit is used to obtain the second clustering result, which is the clustering result of the first feature vector of each discrete sequence in the sequence set;
[0039] The output unit is used to output the clustering result of the discrete sequences in the sequence set based on the second clustering result.
[0040] As an optional implementation of this invention, the first clustering unit is specifically used to generate one-hot codes for each object in the object set based on pre-selected object features; obtain a third clustering result using the first clustering algorithm, wherein the third clustering result is the clustering result of the one-hot codes of each object in the object set; and obtain the first clustering result based on the third clustering result.
[0041] As an optional implementation of this invention, the feature integration unit is specifically used to obtain the number of objects belonging to each object cluster of each discrete sequence in the sequence set according to the first clustering result; and to obtain the first feature vector of each discrete sequence in the sequence set according to the number of objects belonging to each object cluster of each discrete sequence in the sequence set.
[0042] As an optional implementation of the present invention, the feature integration unit is specifically used to generate a second feature vector for each discrete sequence in the sequence set based on the number of object clusters to which each discrete sequence in the sequence set belongs, and to process the second feature vector of each discrete sequence in the sequence set based on a preset natural language processing model to obtain a first feature vector for each discrete sequence in the sequence set.
[0043] As an optional implementation of the present invention, the feature integration unit is specifically used to process the second feature vector of each discrete sequence in the sequence set based on the bag-of-words model to obtain the first feature vector of each discrete sequence in the sequence set.
[0044] As an optional implementation of this invention, the feature integration unit is specifically used to obtain the term frequency (TF) of each element in the second feature vector of each discrete sequence, where the TF of any element is the ratio of the value of that element to the total number of objects contained in the object cluster corresponding to that element; obtain the inverse text frequency index (IDF) of each element in the second feature vector of each discrete sequence, where the IDF of any element is the logarithm of the ratio of the total number of discrete sequences in the sequence set to the number of discrete sequences in the sequence set that belong to the object cluster corresponding to that element; obtain the weight percentage of each element based on the TF and IDF of each element in the second feature vector of each discrete sequence, where the weight percentage of any element is the product of the TF and IDF of that element; and obtain the first feature vector of each discrete sequence in the sequence set based on the weight percentage of each element in the second feature vector of each discrete sequence.
[0045] As an optional implementation of the present invention, the feature integration unit is specifically used to obtain the feature matrix of the sequence set based on the second feature vector of each discrete sequence in the sequence set;
[0046] Based on the feature matrix and word vector model of the sequence set, the first feature vector of each discrete sequence in the sequence set is obtained.
[0047] As an optional implementation of the present invention, the word vector model is a word2vec model, a doc2vec model, or a deep bidirectional representation BERT model.
[0048] As an optional implementation of the present invention, the discrete sequence is a sequence composed of page layout files of the user interface displayed sequentially on the user operation terminal device.
[0049] Thirdly, embodiments of the present invention provide an electronic device, including: a memory and a processor, wherein the memory is used to store a computer program; and the processor is used to cause the electronic device to implement the clustering method of discrete sequences described in any of the above embodiments when the computer program is invoked.
[0050] Fourthly, embodiments of the present invention provide a computer-readable storage medium storing a computer program, which, when executed by a computing device, causes the computing device to implement the clustering method for discrete sequences described in any of the above embodiments.
[0051] Fifthly, embodiments of the present invention provide a computer program product that, when run on a computer, enables the computer to implement the clustering method for discrete sequences described in any of the above embodiments.
[0052] The discrete sequence clustering method provided in this embodiment of the invention, when clustering discrete sequences in a sequence set including multiple discrete sequences, first obtains an object set including the objects that make up each discrete sequence in the sequence set. Then, it uses a first clustering algorithm to obtain a first clustering result of the objects in the object set. Next, it generates a first feature vector for each discrete sequence in the sequence set based on the first clustering result, and uses a second clustering algorithm to obtain a second clustering result of the first feature vectors of each discrete sequence in the sequence set. Finally, it outputs the clustering result of the discrete sequences in the sequence set based on the second clustering result. Since this embodiment of the invention can obtain the first clustering result of the objects that make up the discrete sequence using the first clustering algorithm, abstract the discrete sequence into a corresponding first feature vector based on the first clustering result, obtain the second clustering result of the first feature vector of the discrete sequence using the second clustering algorithm, and output the clustering result of the discrete sequences in the sequence set based on the second clustering result, this embodiment of the invention provides a method for clustering discrete sequences, which can solve the problem that existing technologies cannot cluster discrete sequences. Attached Figure Description
[0053] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.
[0054] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0055] Figure 1This is one of the flowcharts illustrating the steps of a clustering method for discrete sequences provided in an embodiment of the present invention.
[0056] Figure 2 The second flowchart illustrates the steps of a clustering method for discrete sequences provided in an embodiment of the present invention.
[0057] Figure 3 This is a schematic diagram of the structure of the discrete sequence clustering device provided in an embodiment of the present invention;
[0058] Figure 4 This is a schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present invention. Detailed Implementation
[0059] To better understand the above-mentioned objectives, features, and advantages of the present invention, the solutions of the present invention will be further described below. It should be noted that, unless otherwise specified, the embodiments of the present invention and the features thereof can be combined with each other.
[0060] Many specific details are set forth in the following description in order to provide a full understanding of the invention, but the invention may also be practiced in other ways different from those described herein; obviously, the embodiments in the specification are only some embodiments of the invention, and not all embodiments.
[0061] In the embodiments of the present invention, the terms "exemplary" or "for example" are used to indicate that something is an example, illustration, or description. Any embodiment or design described as "exemplary" or "for example" in the embodiments of the present invention should not be construed as being more preferred or advantageous than other embodiments or designs. Specifically, the use of the terms "exemplary" or "for example" is intended to present the relevant concepts in a specific manner. Furthermore, in the description of the embodiments of the present invention, unless otherwise stated, "a plurality of" means two or more.
[0062] The execution entity of the discrete sequence clustering method provided in this embodiment of the invention can be a discrete sequence clustering device. This discrete sequence clustering device can be a mobile phone, tablet computer, laptop computer, handheld computer, vehicle terminal, wearable device, ultra-mobile personal computer (UMPC), netbook, personal digital assistant (PDA), personal computer (PC), etc., and this embodiment of the invention does not specifically limit it.
[0063] Based on the above, embodiments of the present invention provide a clustering method for discrete sequences, referring to... Figure 1 As shown, the clustering method for this discrete sequence includes the following steps S11 to S15:
[0064] S11. Get the collection of objects.
[0065] The object set includes objects that make up each discrete sequence in the sequence set, and the sequence set includes multiple discrete sequences.
[0066] Specifically, the implementation of obtaining the object set can include: first obtaining a sequence set, then extracting each object from each discrete sequence in the sequence set one by one, and combining all the extracted objects into the object set. For example: the obtained sequence set includes three discrete sequences: discrete sequence A, discrete sequence B, and discrete sequence C, where discrete sequence A is [object 1, object 2, object 3], discrete sequence B is [object 3, object 4, object 5], and discrete sequence C is [object 6, object 7, object 8, object 9]. Then the obtained object set can be: {object 1, object 2, object 3, object 3, object 4, object 5, object 6, object 7, object 8, object 9} or {object 1, object 2, object 3, object 4, object 5, object 6, object 7, object 8, object 9}.
[0067] As an optional embodiment of the present invention, the discrete sequence is a sequence composed of page layout files of the user interface displayed sequentially on the user operation terminal device.
[0068] Specifically, when a user operates a terminal device, the device displays different user interfaces based on the user's different actions. The sequence of user actions is related to factors such as the usage scenario of the terminal device and the user's operating habits. When it is necessary to evaluate the similarity between different user action sequences to cluster them, the sequence of page layout files of the user interfaces displayed sequentially by the terminal device during user operation can be represented by the discrete sequence clustering method provided in this embodiment of the invention.
[0069] Optionally, the page layout file for the user interface can be an Extensible Markup Language (xml) file.
[0070] For example, when a user operates a terminal device, the user interface displayed by the terminal device in sequence is: user interface 1, user interface 4, user interface 8, and user interface 10. The page layout file of user interface 1 is xml file 1, the page layout file of user interface 4 is xml file 4, the page layout file of user interface 8 is xml file 8, and the page layout file of user interface 10 is xml file 10. Then the corresponding discrete sequence includes 4 objects, specifically: [xml file 1, xml file 4, xml file 8, xml file 10].
[0071] It should be noted that the discrete sequence, which is a sequence of page layout files of the user interface displayed sequentially on the user operation terminal device, is only a specific application of the embodiments of the present invention. However, the embodiments of the present invention are not limited to this. Various problems that can be described as discrete sequence clustering can be implemented by the discrete sequence clustering method provided by the embodiments of the present invention.
[0072] S12. Obtain the first clustering result using the first clustering algorithm.
[0073] The first clustering result is the clustering result of the objects in the object set.
[0074] Since the first clustering result is the clustering result of the objects in the object set, the first clustering result includes at least one object cluster, and each object cluster includes at least one object.
[0075] Furthermore, the first clustering algorithm in this embodiment of the invention can be any existing clustering algorithm. For example, the first clustering algorithm can be the K-MEANS algorithm, K-MEDOIDS algorithm, CLARANS algorithm, BIRCH algorithm, CURE algorithm, CHAMELEON algorithm, DBSCAN algorithm, OPTICS algorithm, DENCLUE algorithm, etc.
[0076] S13. Generate the first feature vector of each discrete sequence in the sequence set based on the first clustering result.
[0077] Wherein, the first feature vector of any discrete sequence is the feature obtained by processing the number of objects in the discrete sequence belonging to each object cluster in the first clustering result.
[0078] As an optional implementation of this invention, the above-mentioned step S13 (generating the first feature vector of each discrete sequence in the sequence set based on the first clustering result) may include the following steps 13a and 13b:
[0079] Step 13a: Obtain the number of objects in each discrete sequence of the sequence set belonging to each object cluster based on the first clustering result.
[0080] Following the example above, the following will illustrate step 13a by taking the first clustering result as including 4 object clusters, and object cluster 1 including: object 1, object 5, object 6; object cluster 2 including: object 2, object 3, object 9; object cluster 3 including: object 4, object 7; and object cluster 4 including: object 8.
[0081] For a discrete sequence A [object1, object2, object3], the results of the first clustering show that: the number of objects belonging to object cluster 1 is 1, the number of objects belonging to object cluster 2 is 2, the number of objects belonging to object cluster 3 is 0, and the number of objects belonging to object cluster 4 is 0.
[0082] For the discrete sequence B [object 3, object 4, object 5], the results of the first clustering show that: the number of objects belonging to object cluster 1 in the discrete sequence B is 1, the number of objects belonging to object cluster 2 is 1, the number of objects belonging to object cluster 3 is 1, and the number of objects belonging to object cluster 4 is 0.
[0083] For the discrete sequence C [object 6, object 7, object 8, object 9], the results of the first clustering show that: the number of objects belonging to object cluster 1 in the discrete sequence C is 1, the number of objects belonging to object cluster 2 is 1, the number of objects belonging to object cluster 3 is 1, and the number of objects belonging to object cluster 4 is 1.
[0084] Step 13b: Generate the first feature vector of each discrete sequence in the sequence set according to the number of each object cluster to which each discrete sequence in the sequence set belongs.
[0085] Furthermore, since objects in discrete sequences have contextual dependencies, much like natural language, this embodiment of the invention can process the number of object clusters to which objects in a discrete sequence belong, based on a model used for natural language processing, to obtain the first feature vector of each discrete sequence. That is, step 13b (generating the first feature vector of each discrete sequence in the sequence set based on the number of object clusters to which objects in each discrete sequence belong) can be implemented using steps 13c and 13d as follows:
[0086] 13c. Generate a second feature vector for each discrete sequence in the sequence set based on the number of object clusters to which each discrete sequence in the sequence set belongs.
[0087] Continuing from the example above:
[0088] In discrete sequence A, the number of objects belonging to object cluster 1 is 1, the number of objects belonging to object cluster 2 is 2, the number of objects belonging to object cluster 3 is 0, and the number of objects belonging to object cluster 4 is 0. Therefore, the second feature vector of discrete sequence A is: [1, 2, 0, 0].
[0089] In discrete sequence B, the number of objects belonging to object cluster 1 is 1, the number of objects belonging to object cluster 2 is 1, the number of objects belonging to object cluster 3 is 1, and the number of objects belonging to object cluster 4 is 0. Therefore, the second feature vector of discrete sequence B is: [1, 1, 1, 0].
[0090] In the discrete sequence C, the number of objects belonging to object cluster 1 is 1, the number of objects belonging to object cluster 2 is 1, the number of objects belonging to object cluster 3 is 1, and the number of objects belonging to object cluster 4 is 1. Therefore, the second feature vector of the discrete sequence C is: [1, 1, 1, 1].
[0091] 13d. Based on a preset natural language processing model, process the second feature vector of each discrete sequence in the sequence set to obtain the first feature vector of each discrete sequence in the sequence set.
[0092] S14. Use the second clustering algorithm to obtain the second clustering result.
[0093] The second clustering result is the clustering result of the first feature vector of each discrete sequence in the sequence set.
[0094] That is, the first feature vectors of each discrete sequence in the sequence set are clustered by the second clustering algorithm, thereby obtaining the clustering results of the first feature vectors of each discrete sequence in the sequence set.
[0095] Since the second clustering result is the clustering result of the first feature vectors of each discrete sequence in the sequence set, the second clustering result includes at least one first feature vector cluster, and each first feature vector cluster includes at least one first feature vector of a discrete sequence.
[0096] The second clustering algorithm in this embodiment of the invention can also be any existing clustering algorithm. For example, the second clustering algorithm can be: K-MEANS algorithm, K-MEDOIDS algorithm, CLARANS algorithm, BIRCH algorithm, CURE algorithm, CHAMELEON algorithm, DBSCAN algorithm, OPTICS algorithm, DENCLUE algorithm, etc.
[0097] It should be noted that the first clustering algorithm and the second clustering algorithm in the embodiments of the present invention can be the same clustering algorithm or they can be different clustering algorithms.
[0098] S15. Output the clustering results of the discrete sequences in the sequence set based on the second clustering result.
[0099] Specifically, since the first feature vector corresponds one-to-one with the discrete sequences in the sequence set, discrete sequences in the sequence set whose first feature vectors belong to the same first feature vector cluster can be placed into the same discrete sequence cluster, thereby obtaining the clustering result of the discrete sequences in the sequence set.
[0100] For example, when the second clustering result includes two first feature vector clusters, and first feature vector cluster 1 includes the first feature vector corresponding to discrete sequence A and the first feature vector corresponding to discrete sequence C, and first feature vector cluster 2 includes the first feature vector corresponding to discrete sequence B, then the clustering result of discrete sequences includes two discrete sequence clusters, one of which includes discrete sequence A and discrete sequence C, and the other of which includes discrete sequence B.
[0101] The discrete sequence clustering method provided in this embodiment of the invention, when clustering discrete sequences in a sequence set including multiple discrete sequences, first obtains an object set including the objects that make up each discrete sequence in the sequence set. Then, it uses a first clustering algorithm to obtain a first clustering result of the objects in the object set. Next, it generates a first feature vector for each discrete sequence in the sequence set based on the first clustering result, and uses a second clustering algorithm to obtain a second clustering result of the first feature vectors of each discrete sequence in the sequence set. Finally, it outputs the clustering result of the discrete sequences in the sequence set based on the second clustering result. Since this embodiment of the invention can obtain the first clustering result of the objects that make up the discrete sequence using the first clustering algorithm, abstract the discrete sequence into a corresponding first feature vector based on the first clustering result, obtain the second clustering result of the first feature vector of the discrete sequence using the second clustering algorithm, and output the clustering result of the discrete sequences in the sequence set based on the second clustering result, this embodiment of the invention provides a method for clustering discrete sequences, which can solve the problem that existing technologies cannot cluster discrete sequences.
[0102] As an extension and refinement of the above embodiments, this invention also provides another method for clustering discrete sequences, referring to... Figure 2 As shown, the clustering method for this discrete sequence includes the following steps S201 to S220:
[0103] S201, Get the collection of objects.
[0104] The object set includes objects that make up each discrete sequence in the sequence set, and the sequence set includes multiple discrete sequences.
[0105] S202. Generate one-hot codes for each object in the object set based on the pre-selected object features.
[0106] Specifically, in this embodiment of the invention, the pre-selected object features can be selected from the object's features based on clustering requirements. For example, when the object is an XML file, the XML file includes attribute information such as text style, position, resource identification code, format, visibility, and border style for each control on the page. Based on clustering requirements, one or more attributes can be selected from the text style, position, resource identification code, format, visibility, and border style attributes as pre-selected object features, thereby converting each XML file into corresponding one-hot encodings.
[0107] For example, the one-hot encoding of an object can be [0, 1, 1, 4, 3, 0, 0], where the length of the one-hot encoding is determined by the length of the pre-selected object features, and the length of the one-hot encoding of each object is the same.
[0108] S203. Obtain the third clustering result using the first clustering algorithm.
[0109] The third clustering result is the clustering result of the one-hot encoding of each object in the object set.
[0110] Since the third clustering result is the clustering result of the one-hot codes of each object in the object set, the third clustering result includes at least one one-hot code cluster, and each one-hot code cluster includes the one-hot code of at least one object.
[0111] In this embodiment of the invention, when obtaining the third clustering result using the first clustering algorithm, the input of the first clustering algorithm is the value of each pre-selected object feature of the one-hot encoding of each object in the object set, and its dimension is the product of the total number of objects in the object set and the length of the pre-selected object feature. The output of the first clustering algorithm is the one-hot encoding cluster to which the one-hot encoding of each object in the object set belongs, and its dimension is the total number of objects in the object set. For example, if the object set includes 9000 objects, the length of the pre-selected object feature is 2000, and the third clustering result includes 150 one-hot encoding clusters, then the input dimension of the first clustering algorithm is 9000*2000, the output dimension of the first clustering algorithm is 9000, and all 9000 output values of the first clustering algorithm belong to [1, 150].
[0112] S204. Obtain the first clustering result based on the third clustering result.
[0113] Specifically, since there is a one-to-one correspondence between one-hot encoding and objects in the object set, objects in the object set whose one-hot encodings belong to the same one-hot encoding cluster can be aggregated into the same object cluster, thereby obtaining the clustering result of objects in the object set.
[0114] For example: when the third clustering result includes 4 one-hot encoded clusters, and one-hot encoded cluster 1 includes: the one-hot encoding of object 1, the one-hot encoding of object 5 and the one-hot encoding of object 6, one-hot encoded cluster 2 includes: the one-hot encoding of object 2, the one-hot encoding of object 4 and the one-hot encoding of object 5, one-hot encoded cluster 3 includes: the one-hot encoding of object 4 and the one-hot encoding of object 7, and one-hot encoded cluster 4 includes: the one-hot encoding of object 8, then the first clustering result also includes 4 object clusters, and object cluster 1 includes: object 1, object 5 and object 6, object cluster 2 includes: object 2, object 4 and object 5, object cluster 3 includes: object 4 and object 7, and object cluster 4 includes: object 8.
[0115] S205. Based on the first clustering result, obtain the number of objects in each discrete sequence of the sequence set that belong to each object cluster.
[0116] S206. Generate a second feature vector for each discrete sequence in the sequence set based on the number of object clusters to which each discrete sequence in the sequence set belongs.
[0117] S207. Based on a preset natural language processing model, process the second feature vector of each discrete sequence in the sequence set to obtain the first feature vector of each discrete sequence in the sequence set.
[0118] As an embodiment of the present invention, step S207 (processing the second feature vectors of each discrete sequence in the sequence set based on a preset natural language processing model to obtain the first feature vectors of each discrete sequence in the sequence set) can be implemented in the following two ways:
[0119] Implementation Method 1
[0120] The second feature vector of each discrete sequence in the sequence set is processed based on the bag-of-words model to obtain the first feature vector of each discrete sequence in the sequence set.
[0121] That is, the pre-defined natural language processing model can be the bag-of-words model.
[0122] Specifically, the process of processing the second feature vector of each discrete sequence in the sequence set based on the bag-of-words model to obtain the first feature vector of each discrete sequence in the sequence set may include the following steps a to d:
[0123] Step a: Obtain the term frequency (TF) of each element in the second feature vector of each discrete sequence.
[0124] Here, the TF of any element is the ratio of the value of that element to the total number of objects contained in the object cluster corresponding to that element.
[0125] That is, TF = x / Q; where x is the value of the element and Q is the total number of objects contained in the object cluster corresponding to the element.
[0126] Optionally, a feature matrix of the sequence set can be generated based on the second feature vector of each discrete sequence in the sequence set, and the word frequency of each element in the second feature vector of each discrete sequence can be obtained based on the feature matrix of the sequence set.
[0127] For example, a sequence set includes discrete sequence A, discrete sequence B, and discrete sequence C. The second eigenvector of discrete sequence A is [1, 2, 0, 0], the second eigenvector of discrete sequence B is [1, 1, 1, 0], and the second eigenvector of discrete sequence C is [1, 1, 1, 1]. Therefore, the feature matrix of the sequence set can be generated based on the second eigenvectors of each discrete sequence in the sequence set. 1 2 0 0 1 1 1 0 1 1 1 1
[0131] In the second feature vector corresponding to the sequence set, the value of the element in the first row and first column is 1. The total number of objects in the object cluster corresponding to the first row and first column is 3 (the sum of all elements in the first column). Therefore, the word frequency of the element in the first row and first column is 1 / 3. The word frequency of each element in the matrix can be obtained in the same way.
[0132] Step b: Obtain the inverse document frequency (IDF) of each element in the second feature vector of each discrete sequence.
[0133] Wherein, the IDF of any element is the logarithm of the ratio of the total number of discrete sequences in the sequence set to the number of discrete sequences in the sequence set that belong to the object cluster corresponding to that element.
[0134] That is, IDF = log(m / y); where m is the total number of discrete sequences in the sequence set, and y is the number of discrete sequences in the sequence set that belong to the object cluster corresponding to the element.
[0135] Since the total number of discrete sequences in the sequence set is equal to the number of columns in the feature matrix of the sequence set, and the number of discrete sequences in the sequence set that belong to the object cluster corresponding to the element is equal to the number of elements in the column of the feature matrix of the sequence set whose values are not equal to 0, the inverse text frequency index of each element in the second feature vector of each discrete sequence can also be obtained through the feature matrix of the sequence set.
[0136] Following the example above, the feature matrix of the sequence set is: 1 2 0 0 1 1 1 0 1 1 1 1
[0140] The total number of discrete sequences in the sequence set is 3. The number of elements with values other than 0 in the column containing the element in the 1st row and 4th column is 1. Therefore, the inverse text frequency index of the element in the 1st row and 4th column is log(3 / 1).
[0141] Step c: Obtain the weight ratio of each element based on the TF and IDF of each element in the second feature vector of each discrete sequence.
[0142] The weight of any element is the product of its TF and IDF.
[0143] Weight percentage = TF * IDF.
[0144] Step d: Obtain the first feature vector of each discrete sequence in the sequence set according to the weight ratio of each element in the second feature vector of each discrete sequence.
[0145] Specifically, each element in the second feature vector of the discrete sequence can be replaced with the weight ratio of each element, thereby obtaining the first feature vector of each discrete sequence in the sequence set.
[0146] Implementation Method Two
[0147] Based on the second feature vector of each discrete sequence in the sequence set, the feature matrix of the sequence set is obtained, and based on the feature matrix of the sequence set and the word vector model, the first feature vector of each discrete sequence in the sequence set is obtained.
[0148] That is, the feature matrix of the sequence set is input into the word vector model to obtain the first feature vector of each discrete sequence in the sequence set.
[0149] Optionally, the word vector model can be a word2vec model, a doc2vec model, or a deep bidirectional representation (BERT) model. In practical applications, the word vector model can be selected according to different application scenarios, thereby improving the flexibility of the discrete sequence clustering method provided in this embodiment of the invention.
[0150] S208. Obtain the second clustering result using the second clustering algorithm.
[0151] The second clustering result is the clustering result of the first feature vector of each discrete sequence in the sequence set.
[0152] S209. Output the clustering results of the discrete sequences in the sequence set based on the second clustering result.
[0153] The discrete sequence clustering method provided in this embodiment of the invention, when clustering discrete sequences in a sequence set including multiple discrete sequences, first obtains an object set including the objects that make up each discrete sequence in the sequence set. Then, it uses a first clustering algorithm to obtain a first clustering result of the objects in the object set. Next, it generates a first feature vector for each discrete sequence in the sequence set based on the first clustering result, and uses a second clustering algorithm to obtain a second clustering result of the first feature vectors of each discrete sequence in the sequence set. Finally, it outputs the clustering result of the discrete sequences in the sequence set based on the second clustering result. Since this embodiment of the invention can obtain the first clustering result of the objects that make up the discrete sequence using the first clustering algorithm, abstract the discrete sequence into a corresponding first feature vector based on the first clustering result, obtain the second clustering result of the first feature vector of the discrete sequence using the second clustering algorithm, and output the clustering result of the discrete sequences in the sequence set based on the second clustering result, this embodiment of the invention provides a method for clustering discrete sequences, which can solve the problem that existing technologies cannot cluster discrete sequences.
[0154] Based on the same inventive concept, as an implementation of the above method, this embodiment of the invention also provides a discrete sequence clustering device. This device embodiment corresponds to the aforementioned method embodiment. For ease of reading, this device embodiment will not repeat the details of the aforementioned method embodiment one by one, but it should be clear that the discrete sequence clustering device in this embodiment can correspondingly implement all the contents of the aforementioned method embodiment.
[0155] This invention provides a clustering device for discrete sequences. Figure 3 This is a schematic diagram of the clustering device for the discrete sequence, as shown below. Figure 3As shown, the clustering device 300 for the discrete sequence includes:
[0156] The generation unit 31 is used to obtain an object set, the object set including objects that make up each discrete sequence in the sequence set, the sequence set including multiple discrete sequences;
[0157] The first clustering unit 32 is used to obtain a first clustering result using a first clustering algorithm, wherein the first clustering result is the clustering result of objects in the object set;
[0158] Feature integration unit 33 is used to generate a first feature vector for each discrete sequence in the sequence set based on the first clustering result. The first feature vector of any discrete sequence is a feature vector obtained by processing the number of objects in the discrete sequence belonging to each object cluster in the first clustering result.
[0159] The second clustering unit 34 is used to obtain the second clustering result, which is the clustering result of the first feature vector of each discrete sequence in the sequence set;
[0160] Output unit 35 is used to output the clustering result of the discrete sequences in the sequence set according to the second clustering result.
[0161] As an optional implementation of this invention, the first clustering unit 32 is specifically used to generate one-hot codes for each object in the object set based on pre-selected object features; obtain a third clustering result using the first clustering algorithm, wherein the third clustering result is the clustering result of the one-hot codes of each object in the object set; and obtain the first clustering result based on the third clustering result.
[0162] As an optional implementation of this invention, the feature integration unit 33 is specifically used to obtain the number of objects belonging to each object cluster of each discrete sequence in the sequence set according to the first clustering result; and to obtain the first feature vector of each discrete sequence in the sequence set according to the number of objects belonging to each object cluster of each discrete sequence in the sequence set.
[0163] As an optional implementation of the present invention, the feature integration unit 33 is specifically used to obtain the second feature vector of each discrete sequence in the sequence set according to the number of each object cluster to which each discrete sequence in the sequence set belongs, and to process the second feature vector of each discrete sequence in the sequence set based on a preset natural language processing model to obtain the first feature vector of each discrete sequence in the sequence set.
[0164] As an optional implementation of the present invention, the feature integration unit 33 is specifically used to process the second feature vector of each discrete sequence in the sequence set based on the bag-of-words model to obtain the first feature vector of each discrete sequence in the sequence set.
[0165] As an optional implementation of this invention, the feature integration unit 33 is specifically used to obtain the term frequency (TF) of each element in the second feature vector of each discrete sequence, where the TF of any element is the ratio of the value of that element to the total number of objects contained in the object cluster corresponding to that element; obtain the inverse text frequency index (IDF) of each element in the second feature vector of each discrete sequence, where the IDF of any element is the logarithm of the ratio of the total number of discrete sequences in the sequence set to the number of discrete sequences in the sequence set that belong to the object cluster corresponding to that element; obtain the weight ratio of each element based on the TF and IDF of each element in the second feature vector of each discrete sequence, where the weight ratio of any element is the product of the TF and IDF of that element; and obtain the first feature vector of each discrete sequence in the sequence set based on the weight ratio of each element in the second feature vector of each discrete sequence.
[0166] As an optional implementation of this invention, the feature integration unit 33 is specifically used to obtain the feature matrix of the sequence set based on the second feature vector of each discrete sequence in the sequence set; and to obtain the first feature vector of each discrete sequence in the sequence set based on the feature matrix of the sequence set and the word vector model.
[0167] As an optional implementation of the present invention, the word vector model is a word2vec model, a doc2vec model, or a deep bidirectional representation BERT model.
[0168] As an optional implementation of the present invention, the discrete sequence is a sequence composed of page layout files of the user interface displayed sequentially on the user operation terminal device.
[0169] The discrete sequence clustering device provided in this embodiment can execute the discrete sequence clustering method provided in the above method embodiment. Its implementation principle and technical effect are similar, and will not be repeated here.
[0170] Based on the same inventive concept, embodiments of the present invention also provide an electronic device. Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention, such as... Figure 4As shown, the electronic device provided in this embodiment includes a memory 41 and a processor 42. The memory 41 is used to store a computer program; the processor 42 is used to enable the electronic device to implement the discrete sequence clustering method provided in the above embodiment when the computer program is invoked.
[0171] This invention also provides a computer-readable storage medium storing a computer program. When the computer program is executed by a computing device, the computing device implements the clustering method for discrete sequences provided in the above embodiments.
[0172] This invention also provides a computer program product that, when run on a computer, enables the computer to implement the clustering method for discrete sequences provided in the above embodiments.
[0173] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product implemented on one or more computer-usable storage media containing computer-usable program code.
[0174] The processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor can be a microprocessor or any conventional processor.
[0175] Memory may include non-persistent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0176] Computer-readable media include both permanent and non-permanent, removable and non-removable storage media. Storage media can store information using any method or technology; the information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0177] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. A clustering method for discrete sequences, characterized in that, include: Obtain an object set, the object set including objects that make up each discrete sequence in the sequence set, the sequence set including multiple discrete sequences; the discrete sequence is a sequence composed of page layout files of the user interface displayed sequentially based on the user operation terminal device, the page layout file including the attribute information of the controls in the page; One-hot codes for each object in the object set are generated based on the attribute information of the control. The third clustering result is obtained by using the first clustering algorithm. The third clustering result is the clustering result of the one-hot encoding of each object in the object set. Based on the third clustering result, a first clustering result is obtained, wherein the first clustering result is the clustering result of the objects in the object set; The first feature vector of each discrete sequence in the sequence set is generated based on the first clustering result. The first feature vector of any discrete sequence is a feature vector obtained by processing the number of objects in the discrete sequence belonging to each object cluster in the first clustering result. A second clustering result is obtained using a second clustering algorithm. The second clustering result is the clustering result of the first feature vector of each discrete sequence in the sequence set. Based on the second clustering result, output the clustering result of the discrete sequences in the sequence set; Based on the clustering results of the discrete sequences in the sequence set, the similarity between the user operation sequences corresponding to the discrete sequences in the sequence set is evaluated.
2. The method according to claim 1, characterized in that, The step of generating the first feature vector for each discrete sequence in the sequence set based on the first clustering result includes: Based on the first clustering result, obtain the number of objects in each discrete sequence of the sequence set that belong to each object cluster; Based on the number of object clusters to which each discrete sequence in the sequence set belongs, the first feature vector of each discrete sequence in the sequence set is obtained.
3. The method according to claim 2, characterized in that, The step of obtaining the first feature vector of each discrete sequence in the sequence set based on the number of object clusters to which each discrete sequence in the sequence set belongs includes: Based on the number of object clusters to which each discrete sequence in the sequence set belongs, a second feature vector is generated for each discrete sequence in the sequence set. The second feature vector of each discrete sequence in the sequence set is processed based on a preset natural language processing model to obtain the first feature vector of each discrete sequence in the sequence set.
4. The method according to claim 3, characterized in that, The step of processing the second feature vector of each discrete sequence in the sequence set based on a preset natural language processing model to obtain the first feature vector of each discrete sequence in the sequence set includes: The second feature vector of each discrete sequence in the sequence set is processed based on the bag-of-words model to obtain the first feature vector of each discrete sequence in the sequence set.
5. The method according to claim 4, characterized in that, The process of processing the second feature vector of each discrete sequence in the sequence set based on the bag-of-words model to obtain the first feature vector of each discrete sequence in the sequence set includes: Obtain the term frequency (TF) of each element in the second feature vector of each discrete sequence. The TF of any element is the ratio of the value of that element to the total number of objects contained in the object cluster corresponding to that element. Obtain the inverse text frequency index (IDF) of each element in the second feature vector of each discrete sequence. The IDF of any element is the logarithm of the ratio of the total number of discrete sequences in the sequence set to the number of discrete sequences in the sequence set that belong to the object cluster corresponding to that element. Based on the TF and IDF of each element in the second feature vector of each discrete sequence, the weight ratio of each element is obtained. The weight ratio of any element is the product of the TF and IDF of that element. The first feature vector of each discrete sequence in the sequence set is obtained based on the weight ratio of each element in the second feature vector of each discrete sequence.
6. The method according to claim 3, characterized in that, The step of processing the second feature vector of each discrete sequence in the sequence set based on a preset natural language processing model to obtain the first feature vector of each discrete sequence in the sequence set includes: Based on the second feature vector of each discrete sequence in the sequence set, obtain the feature matrix of the sequence set; Based on the feature matrix and word vector model of the sequence set, the first feature vector of each discrete sequence in the sequence set is obtained.
7. The method according to claim 6, characterized in that, The word vector model is either the word2vec model, the doc2vec model, or the deep bidirectional representation BERT model.
8. A clustering device for discrete sequences, characterized in that, include: A generation unit is used to obtain an object set, the object set including objects that make up each discrete sequence in the sequence set, the sequence set including multiple discrete sequences; the discrete sequence is a sequence composed of page layout files of the user interface displayed sequentially based on the user operation terminal device, the page layout file including the attribute information of the controls in the page; The first clustering unit is used to generate one-hot codes for each object in the object set based on the attribute information of the control, obtain a third clustering result using a first clustering algorithm, and obtain a first clustering result based on the third clustering result. The third clustering result is the clustering result of the one-hot codes of each object in the object set, and the first clustering result is the clustering result of the objects in the object set. The feature integration unit is used to generate a first feature vector for each discrete sequence in the sequence set based on the first clustering result. The first feature vector of any discrete sequence is a feature vector obtained by processing the number of objects in the discrete sequence belonging to each object cluster in the first clustering result. The second clustering unit is used to obtain the second clustering result, which is the clustering result of the first feature vector of each discrete sequence in the sequence set; An output unit is configured to output the clustering results of the discrete sequences in the sequence set based on the second clustering result; The output unit is further configured to evaluate the similarity between user operation sequences corresponding to discrete sequences in the sequence set based on the clustering results of discrete sequences in the sequence set.
9. An electronic device, characterized in that, include: A memory and a processor, the memory being used to store a computer program; the processor being used to cause the electronic device to implement the clustering method for discrete sequences according to any one of claims 1-7 when the computer program is invoked.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a computing device, causes the computing device to implement the clustering method for discrete sequences according to any one of claims 1-7.
11. A computer program product, characterized in that, When the computer program product is run on a computer, the computer enables the computer to implement the clustering method for discrete sequences as described in any one of claims 1-7.
Citation Information
Patent Citations
K-Means text clustering method and device and terminal equipment
CN111782812A
Object pushing method and device based on colors
CN113191822A