Subject recommendation method, system, and electronic device
By performing bidirectional alternation and unidirectional search on a one-dimensional array, and reducing array elements by combining the search stopping condition, the K nearest neighbors of a high-dimensional large dataset are obtained. This solves the problem of high computational cost and time overhead of the K nearest neighbor search algorithm in high-dimensional datasets, and achieves efficient topic recommendation.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-28
- Publication Date
- 2026-03-31
AI Technical Summary
Existing K-nearest neighbor search algorithms suffer from high computational and time costs when dealing with high-dimensional, large datasets, resulting in low efficiency in topic recommendation.
By dividing a one-dimensional array into a first interval and a second interval, a bidirectional alternating search is performed on the first interval and a unidirectional search is performed on the second interval. The array elements are reduced by combining the search stopping condition until a preset number is reached, and the K nearest neighbors of the word vectors are obtained and clustered.
It significantly improves the efficiency of topic recommendation, reduces computation time, and increases the efficiency of processing high-dimensional, large datasets.
Smart Images

Figure CN115687602B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and more particularly to a topic recommendation method, system, and electronic device. Background Technology
[0002] With the rapid development of the internet, various online platforms face the challenge of processing large amounts of user keywords. Currently, the K-nearest neighbor search algorithm has a wide range of applications. Its main applications include: product recommendation via K-nearest neighbor search. We can use a user's online shopping history to identify other users with similar browsing records, thus recommending products purchased by that user; fuzzy search via K-nearest neighbor search. Based on the user's query, it provides feedback and similar information. For example, a user can take a photo to find products similar to those in the photo; and text clustering via K-nearest neighbor search. We can input large amounts of text into a computer, which will then cluster the text based on its content, potentially categorizing it into different types such as entertainment, education, technology, and employment.
[0003] When online platforms need to process a large number of user-input search terms and extract user-preferred topics based on these terms, topic recommendation based on the K-nearest neighbor search algorithm faces many problems. For example, obtaining a large number of user-input words and a high-dimensional, large-scale dataset of word vectors after segmentation results in significant computational overhead and time consumption. Currently, existing K-nearest neighbor search algorithms show significant improvement in low-dimensional, large-scale datasets, but offer little improvement in high-dimensional, large-scale datasets. Summary of the Invention
[0004] The technical problem to be solved by the present invention is to overcome the shortcomings of the prior art when obtaining user-preferred topics based on a large number of search terms, where the word vector dataset after segmentation of a large number of search terms is a high-dimensional and large dataset, resulting in large computational load and time overhead. The present invention provides a topic recommendation method, system and electronic device.
[0005] The present invention solves the above-mentioned technical problems through the following technical solution:
[0006] This invention provides a topic recommendation method, comprising the following steps:
[0007] Obtain historical search terms and perform word segmentation on them to obtain several word vectors;
[0008] The one-dimensional array is divided into a first interval and a second interval. The first interval includes a preset number of elements. The one-dimensional array is used to store the order of word vectors in the dataset, which is composed of word vectors.
[0009] Perform a bidirectional alternating search on the word vectors corresponding to the first interval to obtain the K nearest neighbors of the word vectors;
[0010] If the bidirectional alternating search meets the first search stopping condition, the bidirectional alternating search stops.
[0011] A one-way search is performed on the word vectors corresponding to the second interval to obtain the K nearest neighbors of the word vectors;
[0012] If the one-way search meets the second search stopping condition, delete the elements in the first interval of the one-dimensional array, and re-divide the one-dimensional array and perform K-nearest neighbor search until the number of elements in the one-dimensional array is less than the preset number.
[0013] Obtain the K nearest neighbors of all word vectors and perform clustering, then make recommendations based on the topics obtained from the clustering.
[0014] Preferably, the word vectors in the dataset are sorted according to the following steps:
[0015] Obtain the reference word vector; where the reference word vector is either one of the two word vectors that are furthest apart in the dataset;
[0016] The word vectors in the dataset are sorted according to the distances between each other word vector in the dataset and the reference word vector.
[0017] Preferably, the steps for obtaining the K nearest neighbors through bidirectional alternating search specifically include:
[0018] Determine multiple K-nearest neighbors of the first target word vector and calculate the maximum distance between the multiple K-nearest neighbors and the first target word vector; wherein, the first target word vector is the word vector corresponding to the first target element, and the first target element is any element in the first interval;
[0019] Determine whether the distance between the word vector corresponding to the first element in the first interval and the first target word vector is less than the maximum distance; where the first element is the element adjacent to the first target element group, and the first target element group includes elements corresponding to multiple K nearest neighbors;
[0020] If so, replace the K nearest neighbor corresponding to the maximum distance with the word vector corresponding to the first element to update multiple K nearest neighbors of the target word vector.
[0021] If not, then update the element adjacent to the first element to the first element.
[0022] Preferably, after replacing the K nearest neighbor corresponding to the maximum distance with the word vector corresponding to the first element, the process further includes:
[0023] Add the first element to the first target element group.
[0024] Preferably, the first search stopping condition is:
[0025] If the difference between the first distance and the second distance is greater than the maximum distance, then stop judging whether the distance between the word vector corresponding to the first element in the first interval and the first target word vector is less than the maximum distance;
[0026] Wherein, the first distance is the distance between the first target word vector and the reference word vector, and the second distance is the distance between the word vector corresponding to the first element and the reference word vector.
[0027] Preferably, the steps for obtaining the K nearest neighbors using a one-way search specifically include:
[0028] Determine multiple K-nearest neighbors of the second target word vector in a selected direction, and calculate the maximum distance between the multiple K-nearest neighbors in the selected direction and the second target word vector; wherein, the second target word vector is the word vector corresponding to the second target element, and the second target element is any element in the second interval;
[0029] Determine whether the distance between the word vector corresponding to the second element in the second interval and the second target word vector is less than the maximum distance; where the second element is the element adjacent to the selected direction of the second target element group, and the second target element group includes elements corresponding to multiple K nearest neighbors in the selected direction;
[0030] If so, the K nearest neighbor corresponding to the maximum distance is replaced with the word vector corresponding to the second element to update the multiple K nearest neighbors in the selected direction of the second target word vector.
[0031] If not, then update the element adjacent to the second element to the second element.
[0032] Preferably, after replacing the K nearest neighbor corresponding to the maximum distance with the word vector corresponding to the second element, the process further includes:
[0033] Add the second element to the second target element group.
[0034] Preferably, the second search stopping condition is:
[0035] If the difference between the third distance and the fourth distance is greater than the maximum distance, then stop judging whether the distance between the word vector corresponding to the second element in the second interval and the second target word vector is less than the maximum distance;
[0036] The third distance is the distance between the second target word vector and the reference word vector, and the fourth distance is the distance between the word vector corresponding to the second element and the reference word vector.
[0037] The present invention also provides a topic recommendation system, comprising:
[0038] The word vector acquisition module is used to acquire historical search terms and perform word segmentation on the historical search terms to obtain several word vectors;
[0039] The partitioning module is used to divide the one-dimensional array into a first interval and a second interval. The first interval includes a preset number of elements. The one-dimensional array is used to store the order of word vectors in the dataset. The dataset is composed of word vectors.
[0040] The bidirectional alternating search stopping module is used to perform bidirectional alternating search on the word vectors corresponding to the first interval to obtain the K nearest neighbor points of the word vectors until the first search stopping condition is met.
[0041] The one-way search module performs a one-way search on the word vectors corresponding to the second interval to obtain the K nearest neighbors of the word vectors;
[0042] In the deletion module, if the unidirectional search meets the second search stopping condition, the elements in the first interval of the one-dimensional array are deleted, and the one-dimensional array is re-divided and K-nearest neighbor search is performed until the number of elements in the one-dimensional array is less than the preset number.
[0043] The recommendation module is used to obtain the K nearest neighbors of all word vectors and perform clustering, and make recommendations based on the topics obtained from the clustering.
[0044] Preferably, the topic recommendation system should include:
[0045] The reference word vector acquisition module is used to obtain reference word vectors; where the reference word vector is either one of the two farthest word vectors in the dataset.
[0046] The sorting module is used to sort the word vectors in the dataset based on the distances between other word vectors in the dataset and the reference word vector.
[0047] Preferably, the bidirectional alternating search stopping module also includes:
[0048] The first calculation unit is used to determine multiple K-nearest neighbors of the first target word vector and calculate the maximum distance between the multiple K-nearest neighbors and the first target word vector; wherein, the first target word vector is the word vector corresponding to the first target element, and the first target element is any element in the first interval;
[0049] The first judgment unit is used to determine whether the distance between the word vector corresponding to the first element in the first interval and the first target word vector is less than the maximum distance; wherein, the first element is the element adjacent to the first target element group, and the first target element group includes elements corresponding to multiple K nearest neighbors;
[0050] If so, replace the K nearest neighbor corresponding to the maximum distance with the word vector corresponding to the first element to update the multiple K nearest neighbors of the first target word vector;
[0051] If not, then update the element adjacent to the first element to the first element.
[0052] Ideally, the topic recommendation system also includes:
[0053] The first adding module is used to add the first element to the first target element group.
[0054] Preferably, the bidirectional alternating search stopping module also includes:
[0055] The first search stopping condition judgment unit is used to stop judging whether the distance between the word vector corresponding to the first element in the first interval and the first target word vector is less than the maximum distance if the difference between the first distance and the second distance is greater than the maximum distance.
[0056] Wherein, the first distance is the distance between the first target word vector and the reference word vector, and the second distance is the distance between the word vector corresponding to the first element and the reference word vector.
[0057] Preferably, the one-way search module also includes:
[0058] The second calculation unit is used to determine multiple K-nearest neighbor points in a selected direction of the second target word vector, and to calculate the maximum distance between the multiple K-nearest neighbor points in the selected direction and the second target word vector; wherein, the second target word vector is the word vector corresponding to the second target element, and the second target element is any element in the second interval;
[0059] The second judgment unit is used to determine whether the distance between the word vector corresponding to the second element in the second interval and the second target word vector is less than the maximum distance; wherein, the second element is an element adjacent to the selected direction of the second target element group, and the second target element group includes elements corresponding to multiple K nearest neighbors in the selected direction;
[0060] If so, the K nearest neighbor corresponding to the maximum distance is replaced with the word vector corresponding to the second element to update the multiple K nearest neighbors in the selected direction of the second target word vector.
[0061] If not, then update the element adjacent to the second element to the second element.
[0062] Ideally, the topic recommendation system also includes:
[0063] The second addition module is used to add the second element to the second target element group.
[0064] Preferably, the module to be deleted also includes:
[0065] The second search stopping condition judgment unit is used to stop judging whether the distance between the word vector corresponding to the second element in the second interval and the second target word vector is less than the maximum distance if the difference between the third distance and the fourth distance is greater than the maximum distance.
[0066] The third distance is the distance between the second target word vector and the reference word vector, and the fourth distance is the distance between the word vector corresponding to the second element and the reference word vector.
[0067] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and running thereon, wherein the processor executes the computer program to implement the above-described topic recommendation method.
[0068] The significant advantages of this invention are as follows: It constructs a one-dimensional array, divides it into a first interval and a second interval, performs a bidirectional alternating search on the word vectors corresponding to elements in the first interval, and a unidirectional search on the word vectors corresponding to elements in the second interval, and reduces the one-dimensional array by determining a stopping condition. After reduction, the first and second intervals are re-divided, and the intervals are reduced again until the number of elements in the one-dimensional array is less than a preset number. Finally, the K nearest neighbors of each data point are obtained. Using K nearest neighbors as the basis for clustering, clustering is completed, and recommendations are made based on the topics obtained from the clustering. This method can significantly improve the execution efficiency of topic recommendation and reduce execution time. Attached Figure Description
[0069] Figure 1 This is a flowchart of the topic recommendation method in Embodiment 1 of the present invention.
[0070] Figure 2 This is a schematic diagram of the structure of a one-dimensional array in the topic recommendation method of Embodiment 1 of the present invention.
[0071] Figure 3 This is a flowchart of step 102 in the subject recommendation method of Embodiment 2 of the present invention.
[0072] Figure 4 This is a flowchart of step 103 in the subject recommendation method of Embodiment 2 of the present invention.
[0073] Figure 5 This is an example diagram illustrating step 1031 in the subject recommendation method of Embodiment 2 of the present invention.
[0074] Figure 6 This is an example diagram illustrating step 103 in the subject recommendation method of Embodiment 2 of the present invention.
[0075] Figure 7 This is a schematic diagram of the module of the topic recommendation system in Embodiment 3 of the present invention.
[0076] Figure 8This is a schematic diagram of the structure of the electronic device according to Embodiment 4 of the present invention. Detailed Implementation
[0077] The present invention will be further illustrated by way of embodiments below, but the present invention is not limited to the scope of the embodiments described herein.
[0078] Example 1
[0079] This embodiment provides a topic recommendation method. (Refer to...) Figure 1 The method for recommending this topic includes the following steps:
[0080] Step S101: Obtain historical search terms and perform word segmentation on the historical search terms to obtain several word vectors;
[0081] Specifically, every day, a large number of users search on online platforms or terminal software, and service providers obtain a large number of search terms entered by users. All the search terms entered by users that day are aggregated and processed into words, resulting in several word segmentation units. These word segmentation units are then used to generate several word vectors using a word2vector model or other models, where the dimensions of the word vectors can be set according to the actual situation.
[0082] For example, if a user enters 1 million search terms on a web platform or mobile software in a single day, these 1 million search terms can be aggregated. Segmenting these 1 million search terms might yield 3 million segmentation units (each search term might have three or four segmentation units, the exact number depending on the complexity of the user's input). Each of these 3 million segmentation units (which may contain duplicates) will then generate a word vector using a word2vector model or other models. Each word vector might have a dimension of 200.
[0083] Step S102: Divide the one-dimensional array into a first interval and a second interval, wherein the first interval includes a preset number of elements, and the one-dimensional array is used to store the order of the word vectors in the dataset, and the dataset is composed of the word vectors;
[0084] Specifically, the preset number can be set according to the actual situation; the one-dimensional array is used to store the order of word vectors in the dataset. For example, the position of the first data in the dataset is 0, the position of the second data is 1, the position of the third data is 2, and so on. The one-dimensional array records the positions of these word vectors.
[0085] Step S103: Perform bidirectional alternating search on the word vector corresponding to the first interval to obtain the K nearest neighbor of the word vector until the first search stopping condition is met;
[0086] Step S104: Perform a one-way search on the word vector corresponding to the second interval to obtain the K nearest neighbor points of the word vector;
[0087] Step S105: If the one-way search meets the second search stopping condition, delete the elements in the first interval of the one-dimensional array, and re-divide the one-dimensional array and perform K-nearest neighbor search until the number of elements in the one-dimensional array is less than the preset number.
[0088] Specifically, firstly, a bidirectional alternating search is performed on the word vectors corresponding to the elements of the first interval in the one-dimensional array to ensure that the precise K-nearest neighbors of the word vectors corresponding to all elements in the first interval are found. The unidirectional search can be either left or right. Secondly, the word vectors corresponding to the elements of the second interval in the one-dimensional array are sequentially subjected to a unidirectional search. This continues until the word vectors corresponding to the elements of the second interval all satisfy the stopping condition for either a left or right search. During this process, the K-nearest neighbors of the word vectors corresponding to the elements of the second interval become increasingly precise. Thirdly, the first interval in the one-dimensional array is deleted. The one-dimensional array after deleting the first interval is then divided back into the first and second intervals, and the above search process is repeated until the number of elements in the one-dimensional array is less than a preset number.
[0089] Step 103 can be performed sequentially with steps 105 and 106, or step 103 can be performed simultaneously with steps 105 and 106.
[0090] For example, refer to Figure 2 A one-dimensional array has n elements. The array is divided into a first interval and a second interval, where the first interval has a preset number of m elements, and the second interval has a preset number of nm elements. A bidirectional search is performed on the word vectors corresponding to the m elements in the first interval to obtain their K-nearest neighbors. If the bidirectional search in the first interval satisfies a first search stopping condition, the bidirectional search stops. A unidirectional search is then performed on the word vectors corresponding to the nm elements in the second interval to obtain their K-nearest neighbors. If the unidirectional search satisfies a second search stopping condition, the elements in the first interval of the one-dimensional array are deleted, and the array is re-divided and a K-nearest neighbor search is performed again until the number of elements in the one-dimensional array is less than the preset number.
[0091] Step S106: Obtain the K nearest neighbors of all word vectors and perform clustering, and make recommendations based on the topics obtained from the clustering.
[0092] This involves obtaining the K nearest neighbors of all word vectors, using each word vector's K nearest neighbor as a feature, and then clustering based on the K nearest neighbor features of all word vectors to obtain different topics.
[0093] This embodiment constructs a one-dimensional array, dividing it into a first interval and a second interval. It performs a bidirectional alternating search on the word vectors corresponding to elements in the first interval and a unidirectional search on the word vectors corresponding to elements in the second interval. A stopping condition is used to reduce the one-dimensional array. After reduction, the first and second intervals are re-divided, and the intervals are reduced again until the number of elements in the one-dimensional array is less than a preset number. Finally, the K-nearest neighbors of each data point are obtained. Using K-nearest neighbors as the basis for clustering, clustering is completed, and recommendations are made based on the topics obtained from the clustering. This method can significantly improve the execution efficiency of topic recommendation and reduce execution time.
[0094] Example 2
[0095] Based on Example 1, this example provides a topic recommendation method. Step S102: The one-dimensional array is used to store the order of the word vectors in the dataset, referring to... Figure 3 The word vectors in the dataset are sorted according to the following steps:
[0096] S1021. Obtain reference word vectors; wherein, the reference word vectors are either of the two word vectors that are furthest apart in the dataset;
[0097] Specifically, the distance between the two farthest word vectors is calculated, which can be one of three methods: Euclidean distance, Manhattan distance, or Minkowski distance. The specific distance is chosen based on the actual situation. After obtaining the two farthest word vectors, one of them is selected as the reference word vector.
[0098] S1022. Sort the word vectors in the dataset according to the distances between the other word vectors in the dataset and the reference word vector.
[0099] Specifically, based on the reference word vector selected in step S1021, other word vectors are sorted according to distance to the reference word vector in ascending or descending order.
[0100] Reference Figure 4 In step S103, the topic recommendation method of this embodiment further includes:
[0101] S1031. Determine multiple K-nearest neighbors of the first target word vector and calculate the maximum distance between the multiple K-nearest neighbors and the first target word vector; wherein, the first target word vector is the word vector corresponding to the first target element, and the first target element is any element in the first interval;
[0102] Specifically, multiple K-nearest neighbors of the first target word vector are determined, wherein the number of K-nearest neighbors is determined or adjusted according to the actual situation.
[0103] For example, refer to Figure 5 There are four elements: A, B, C, D, E, F, G, H, I, J, K, L, M, and Z. Each element corresponds to a word vector, and each word vector can have 200 dimensions. Following step S102, after sorting, a one-dimensional array [C, B, I, M, Z, A, K, L, E, G, H, F, D] is obtained. The word vectors corresponding to elements C and D are the two furthest points; in this example, C is used as the reference point. Assuming the first element is A, and setting the number of K-nearest neighbors to 4, the initial K-nearest neighbors corresponding to the word vectors corresponding to elements A are the word vectors corresponding to elements L, Z, K, and J. The maximum distance between the word vectors corresponding to elements L, Z, K, and J and the word vector corresponding to element A is determined. Assuming the maximum distance point is the word vector corresponding to element J, the distance can be Euclidean distance, Manhattan distance, or Minkowski distance; the specific distance is chosen based on the actual situation.
[0104] S1032. Determine whether the distance between the word vector corresponding to the first element in the first interval and the first target word vector is less than the maximum distance; wherein, the first element is an element adjacent to the first target element group, and the first target element group includes the elements corresponding to the plurality of K nearest neighbors;
[0105] If so, the K nearest neighbor corresponding to the maximum distance is replaced with the word vector corresponding to the first element to update the multiple K nearest neighbors of the first target word vector.
[0106] If not, then update the element adjacent to the first element to the first element.
[0107] Specifically, it is determined whether the distance between the first element adjacent to the first target element group and the first target word vector is less than the maximum distance. If it is less than the maximum distance, the K nearest neighbor point corresponding to the maximum distance is replaced with the word vector corresponding to the first element, thereby updating the multiple K nearest neighbor points of the first target word vector.
[0108] For example, determine whether the distance between the word vector corresponding to the M element adjacent to the L, Z, K, and J elements and the word vector corresponding to the A element is less than the distance between the word vector corresponding to the J element and the word vector corresponding to the A element: if yes, replace the J point with the M point, and update the elements corresponding to the initial K nearest neighbors of the first element A to the word vectors corresponding to the M, L, Z, and K elements; if no, no update is needed.
[0109] After step S1032, the topic recommendation method of this embodiment further includes:
[0110] S1033. Add the first element to the first target element group.
[0111] For example, the first element is added to the first element group. After adding it, the search for adjacent first elements continues, following the same steps as described above, which will not be repeated here. In this embodiment, the elements corresponding to the K nearest neighbors of the word vector corresponding to element A are updated to the word vectors corresponding to elements M, L, E, and Z.
[0112] S1034. If the first search stopping condition of bidirectional alternating search is met, then the bidirectional search stops.
[0113] The specific judgment step is to determine whether the first search stopping condition is met:
[0114] If so, stop the bidirectional search.
[0115] If not, return to step "Determine whether the distance between the word vector corresponding to the first element in the first interval and the first target word vector is less than the maximum distance".
[0116] The first search stopping condition in step S1034 for the bidirectional alternating search includes:
[0117] If the difference between the first distance and the second distance is greater than the maximum distance, then stop judging whether the distance between the word vector corresponding to the first element in the first interval and the first target word vector is less than the maximum distance;
[0118] Wherein, the first distance is the distance between the first target word vector and the reference word vector, and the second distance is the distance between the word vector corresponding to the first element and the reference word vector.
[0119] For example, refer to Figure 6Continue searching for elements adjacent to the first target element group. Once element I is found, the distance between the word vector corresponding to element A and the word vector corresponding to element I is named *di*. The distance between the word vector corresponding to element A and the word vector corresponding to its maximum K-nearest neighbor element Z is named *dz*. Compare *dz* and *di*: if *dz* is greater than *di*, update the K-nearest neighbors of A to M, L, E, and I. Reorder the four K-nearest neighbors of A after the change, and determine the maximum distance among the word vectors corresponding to elements M, L, E, and I from the word vector corresponding to element A. If *di* is greater than *dz*, calculate the distance between the word vector corresponding to element A and the word vector corresponding to the reference point C, named *d(C,A) = d1*, and calculate the distance between the word vector corresponding to element A and the word vector corresponding to the reference point I, named *d(C,I) = d2*. Simultaneously, obtain the distance difference between the word vectors corresponding to elements A and I and the word vector corresponding to the reference point C, named *d3*. The relationship between *d3* and *d1* and *d2* is: *d3* = *d1* - *d2*. The search to the left of A can be stopped when the stopping conditions of di > dz and d3 > dz are met. The nearest neighbors of the word vector corresponding to element A are the word vectors corresponding to elements M, L, E, and Z. At this point, it can be assumed that the distance from the word vector corresponding to the element to the left of M in the one-dimensional array to the word vector corresponding to element A is greater than the distance dz from data point A to the current fourth nearest neighbor. The above-described process is the process of searching to the left. Bidirectional search includes searching to the left and searching to the right. The steps for searching to the right are the same as those for searching to the left, and will not be repeated here.
[0120] Step S104: Perform a one-way search on the word vector corresponding to the second interval to obtain the K nearest neighbor points of the word vector;
[0121] Step S105: If the one-way search meets the second search stopping condition, delete the elements in the first interval of the one-dimensional array, and re-divide the one-dimensional array and perform K-nearest neighbor search until the number of elements in the one-dimensional array is less than the preset number.
[0122] The unidirectional search in steps S104 and S105 is the same as that in step S103 above, and will not be repeated here.
[0123] This embodiment constructs a one-dimensional array, dividing it into a first interval and a second interval. It performs a bidirectional alternating search on the word vectors corresponding to elements in the first interval and a unidirectional search on the word vectors corresponding to elements in the second interval. A stopping condition is used to reduce the one-dimensional array. After reduction, the first and second intervals are re-divided, and the intervals are reduced again until the number of elements in the one-dimensional array is less than a preset number. Finally, the K-nearest neighbors of each data point are obtained. Using K-nearest neighbors as the basis for clustering, clustering is completed, and recommendations are made based on the topics obtained from the clustering. This method can significantly improve the execution efficiency of topic recommendation and reduce execution time.
[0124] Example 3
[0125] This embodiment provides a topic recommendation system, referring to... Figure 7 A schematic diagram of the modules in this embodiment is shown. (Refer to...) Figure 7 The topic recommendation system in this embodiment includes:
[0126] The word vector acquisition module 1 is used to acquire historical search terms and perform word segmentation on the historical search terms to obtain several word vectors;
[0127] Specifically, every day, a large number of users search on online platforms or terminal software, and service providers obtain a large number of search terms entered by users. All the search terms entered by users that day are aggregated and processed into words, resulting in several word segmentation units. These word segmentation units are then used to generate several word vectors using a word2vector model or other models, where the dimensions of the word vectors can be set according to the actual situation.
[0128] For example, if a user enters 1 million search terms on a web platform or mobile software in a single day, these 1 million search terms can be aggregated. Segmenting these 1 million search terms might yield 3 million segmentation units (each search term might have three or four segmentation units, the exact number depending on the complexity of the user's input). Each of these 3 million segmentation units (which may contain duplicates) will then generate a word vector using a word2vector model or other models. Each word vector might have a dimension of 200.
[0129] The partitioning module 2 is used to divide a one-dimensional array into a first interval and a second interval, wherein the first interval includes a preset number of elements, the one-dimensional array is used to store the order of the word vectors in the dataset, and the dataset is composed of the word vectors;
[0130] Specifically, the preset number can be set according to the actual situation; the one-dimensional array is used to store the order of word vectors in the dataset. For example, the position of the first data in the dataset is 0, the position of the second data is 1, the position of the third data is 2, and so on. The one-dimensional array records the positions of these word vectors, and these positions correspond to the word vectors in the dataset.
[0131] The bidirectional alternating search stopping module 3 is used to perform bidirectional alternating search on the word vector corresponding to the first interval to obtain the K nearest neighbor of the word vector until the first search stopping condition is met.
[0132] One-way search module 4 performs a one-way search on the word vector corresponding to the second interval to obtain the K nearest neighbor points of the word vector;
[0133] In the deletion module 5, if the one-way search meets the second search stopping condition, the elements in the first interval of the one-dimensional array are deleted, and the one-dimensional array is re-divided and K-nearest neighbor search is performed until the number of elements in the one-dimensional array is less than the preset number.
[0134] Specifically, firstly, a bidirectional alternating search is performed on the word vectors corresponding to the elements of the first interval in the one-dimensional array to ensure that the precise K-nearest neighbors of all word vectors corresponding to the elements in the first interval are found. The unidirectional search can be left or right. Secondly, the word vectors corresponding to the elements of the second interval in the one-dimensional array are sequentially subjected to a unidirectional search, which can be left or right. This continues until the word vectors corresponding to the elements of the second interval all satisfy the stopping condition for either left or right search. During this process, the K-nearest neighbors of the word vectors corresponding to the elements of the second interval become increasingly precise. Thirdly, the first interval in the one-dimensional array is deleted. The one-dimensional array after deleting the first interval is then divided back into the first and second intervals, and the above search process is repeated until the number of elements in the one-dimensional array is less than a preset number.
[0135] Recommendation module 6 is used to obtain the K nearest neighbors of all word vectors and perform clustering, and make recommendations based on the topics obtained from the clustering.
[0136] This involves obtaining the K-nearest neighbors of all word vectors, using each word vector's K-nearest neighbor as a feature, and then clustering based on the K-nearest neighbor features of all word vectors. This allows the network platform to obtain the topics that users like.
[0137] This embodiment constructs a one-dimensional array, dividing it into a first interval and a second interval. It performs a bidirectional alternating search on the word vectors corresponding to elements in the first interval and a unidirectional search on the word vectors corresponding to elements in the second interval. A stopping condition is used to reduce the one-dimensional array. After reduction, the first and second intervals are re-divided, and the intervals are reduced again until the number of elements in the one-dimensional array is less than a preset number. Finally, the K-nearest neighbors of each data point are obtained. Using K-nearest neighbors as the basis for clustering, clustering is completed, and recommendations are made based on the topics obtained from the clustering. This method can significantly improve the execution efficiency of topic recommendation and reduce execution time.
[0138] Example 4
[0139] This embodiment provides an electronic device, which can be represented in the form of a computing device (e.g., a server device), including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor can implement the topic recommendation method provided in Embodiment 1 when executing the computer program.
[0140] Figure 8 A schematic diagram of the hardware structure of this embodiment is shown, with reference to... Figure 8 As shown, electronic device 9 specifically includes:
[0141] At least one processor 91, at least one memory 92, and a bus 93 for connecting different system components (including processor 91 and memory 92), wherein:
[0142] Bus 93 includes a data bus, an address bus, and a control bus.
[0143] The memory 92 includes volatile memory, such as random access memory (RAM) 921 and / or cache memory 922, and may further include read-only memory (ROM) 923.
[0144] The memory 92 also includes a program / utility 925 having a set (at least one) of program modules 924, including but not limited to: an operating system, one or more application programs, other program modules, and program data, each or some combination of these examples may include an implementation of a network environment.
[0145] The processor 91 executes various functional applications and data processing by running computer programs stored in the memory 92, such as the topic recommendation method provided in Embodiment 1 of the present invention.
[0146] Electronic device 9 can further communicate with one or more external devices 94 (e.g., keyboard, pointing device, etc.). This communication can be performed via input / output (I / O) interface 95. Furthermore, electronic device 9 can also communicate with one or more networks (e.g., local area network (LAN), wide area network (WAN), and / or public network, such as the Internet) via network adapter 96. Network adapter 96 communicates with other modules of electronic device 9 via bus 93. It should be understood that, although not shown in the figures, other hardware and / or software modules can be used in conjunction with electronic device 9, including but not limited to: microcode, device drivers, redundant processors, external disk drive arrays, RAID (disk array) systems, tape drives, and data backup storage systems, etc.
[0147] It should be noted that although several units / modules or sub-units / modules of the electronic device have been mentioned in the detailed description above, this division is merely exemplary and not mandatory. In fact, according to the embodiments of this application, the features and functions of two or more units / modules described above can be embodied in one unit / module. Conversely, the features and functions of one unit / module described above can be further divided and embodied by multiple units / modules.
[0148] While specific embodiments of the present invention have been described above, those skilled in the art should understand that these are merely illustrative examples, and the scope of protection of the present invention is defined by the appended claims. Those skilled in the art can make various changes or modifications to these embodiments without departing from the principles and essence of the present invention, but all such changes and modifications fall within the scope of protection of the present invention.
Claims
1. A theme recommendation method characterized by comprising: The method comprises the following steps: acquiring historical search terms and performing word segmentation on the historical search terms to obtain a plurality of word vectors; dividing a one-dimensional array into a first interval and a second interval, wherein the first interval comprises a preset number of elements, and the one-dimensional array is used to store the arrangement order of the word vectors in a data set composed of the word vectors; performing bidirectional alternate search on the word vectors corresponding to the first interval to obtain K nearest neighbor points of the word vectors until a first search stop condition is met; performing unidirectional search on the word vectors corresponding to the second interval to obtain K nearest neighbor points of the word vectors; if the unidirectional search meets a second search stop condition, deleting the elements of the first interval in the one-dimensional array and re-dividing the one-dimensional array and performing K nearest neighbor point search until the number of elements in the one-dimensional array is less than the preset number; obtaining K nearest neighbors of all word vectors and performing clustering, and performing recommendation according to the obtained topics; The topic recommendation method further comprises: determining a plurality of K nearest neighbor points of a first target word vector and calculating a first maximum distance between the plurality of K nearest neighbor points and the first target word vector; the first search stop condition is that the difference between a first distance and a second distance is greater than the first maximum distance; wherein the first distance is the distance between the first target word vector and a reference word vector, and the second distance is the distance between the word vector corresponding to a first element and the reference word vector; determining a plurality of K nearest neighbor points of a selected direction of a second target word vector and calculating a second maximum distance between the plurality of K nearest neighbor points of the selected direction and the second target word vector; the second search stop condition is that the difference between a third distance and a fourth distance is greater than the second maximum distance; wherein the third distance is the distance between the second target word vector and the reference word vector, and the fourth distance is the distance between the word vector corresponding to a second element and the reference word vector; wherein the reference word vector is any one of the two word vectors farthest apart in the data set.
2. The method of claim 1, wherein, The word vectors in the data set are sorted according to the following steps: acquiring a reference word vector; sorting the word vectors in the data set according to the distances between the reference word vector and other word vectors in the data set.
3. The subject recommendation method of claim 2, wherein, The step of bidirectional alternate search to obtain K nearest neighbor points specifically comprises: determining whether the distance between the word vector corresponding to a first element in the first interval and the first target word vector is less than the first maximum distance; wherein the first target word vector is the word vector corresponding to a first target element, the first target element is any element in the first interval, the first element is an element adjacent to the first target element, and the first target element group comprises elements corresponding to the plurality of K nearest neighbor points; if yes, replacing the K nearest neighbor point corresponding to the maximum distance with the word vector corresponding to the first element to update the plurality of K nearest neighbor points of the first target word vector; if no, updating the element adjacent to the first element as the first element.
4. The subject recommendation method of claim 3, wherein, The step of replacing the K-nearest neighbor point corresponding to the first maximum distance with the word vector corresponding to the first element further comprises: adding the first element to the first target element group.
5. The subject recommendation method of claim 2, wherein, The step of obtaining the K-nearest neighbor point through one-way search specifically comprises: judging whether the distance between the word vector corresponding to the second element in the second interval and the second target word vector is less than the second maximum distance; wherein the second target word vector is the word vector corresponding to the second target element, the second target element is any element in the second interval; the second element is the element adjacent to the second target element in the selected direction, and the second target element group comprises elements corresponding to the K-nearest neighbor points in the selected direction; if yes, replacing the K-nearest neighbor point corresponding to the maximum distance with the word vector corresponding to the second element to update the K-nearest neighbor points in the selected direction of the second target word vector; if no, updating the element adjacent to the second element as the second element.
6. The subject recommendation method of claim 5, wherein, The step of replacing the K-nearest neighbor point corresponding to the second maximum distance with the word vector corresponding to the second element further comprises: adding the second element to the second target element group.
7. A theme recommendation system characterized by, The system is used to execute the subject recommendation method as claimed in any one of claims 1-6.
8. An electronic device comprising a memory, a processor, and a computer program stored on the memory to run on the processor, characterized in that, The processor executes the computer program to implement the subject recommendation method as claimed in any one of claims 1-6.
Citation Information
Patent Citations
Methods and system for semantic search in large databases
CN111213140A
Topic recommendation method and device and electronic equipment
CN114329181A