Text category determination method, apparatus, device, and storage medium
By acquiring the target word vectors of text information and matching them using cluster centers and a contrastive learning model, the problems of low efficiency and insufficient accuracy in text information classification are solved, and fast and accurate text classification is achieved.
Patent Information
- Application Number
- CN202111663495.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Priority Date
- 2021-11-15
- Filing Date
- 2021-12-31
- Publication Date
- 2025-12-05
- Estimated Expiration
- 2041-12-31
AI Technical Summary
Existing technologies struggle to quickly and accurately classify text information, especially multi-labeled text information, resulting in low classification efficiency and insufficient accuracy.
By acquiring the target word vectors of the text information to be classified and matching them with multiple preset word vectors, the text category is determined using cluster centers and a contrastive learning model, thus achieving fast and accurate text classification.
It improves the matching efficiency and accuracy of text information classification, requiring only one processing step to confirm the category, thus enhancing the efficiency and accuracy of classification.
Smart Images

Figure CN116127059B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer vision technology in artificial intelligence technology, and more specifically, to a method, apparatus, device and storage medium for determining text categories. Background Technology
[0002] With the development of digital media technology, various applications generate a large amount of text information, such as text messages or articles posted by users within these applications. Some of this text information contains prohibited content, such as malicious advertisements or uncivilized messages. Improper management of this type of text information can damage the social environment of applications and even expose application platforms to legal risks.
[0003] Currently, the common method for managing text information is to identify sentence categories and then take subsequent measures such as account permission restrictions, comment deletion, traffic limiting, or account revocation based on the category. However, with the increase in the number of categories that need to be distinguished, and the increase in tags that text information may contain, how to correctly classify text information has become a challenge. In production environments, text is generally divided into categories such as: normal text, malicious advertising, and text containing uncivilized information. Each category may need to be further classified or graded. The large number of categories places high demands on accurate classification, and some text may have multiple tags simultaneously. However, currently, it is usually difficult to quickly and accurately determine the category of text information. Summary of the Invention
[0004] In view of the above problems, embodiments of this application propose a method, apparatus, device and storage medium for determining text categories to improve the above problems.
[0005] In a first aspect, embodiments of this application provide a method for determining text categories. The method includes: acquiring text information to be classified and multiple clustering categories, wherein the multiple clustering categories are obtained by clustering multiple preset word vectors, each clustering category includes at least one preset word vector, and each clustering category corresponds to a cluster center; extracting target word vectors from the text information to be classified; matching each cluster center with the target word vector to obtain a target clustering center matching the target word vector; matching the target word vector with preset word vectors included in the clustering category corresponding to the target clustering center to obtain a target preset word vector; and determining the category of the text information to be classified based on the category label corresponding to the target preset word vector.
[0006] Secondly, embodiments of this application provide a text category determination method applied to a terminal device. The method includes: acquiring text information to be classified; sending the text information to be classified to a server, so that the server inputs the text information to be classified into a contrastive learning model deployed thereon to obtain target word vectors; matching multiple cluster centers with the target word vectors respectively to obtain target cluster centers matching the target word vectors; matching the target word vectors with preset word vectors included in the cluster categories corresponding to the target cluster centers to obtain target preset word vectors, wherein the multiple cluster centers are the centers in multiple cluster categories obtained by clustering multiple preset word vectors, and each cluster category includes at least one preset word vector; receiving category labels corresponding to the target preset word vectors fed back by the server; and determining the category of the text information to be classified based on the category labels corresponding to the target preset word vectors.
[0007] Thirdly, embodiments of this application provide a text category determination device, which includes a first information acquisition module, a vector extraction module, a first matching module, a second matching module, and a first category determination module. The first information acquisition module is used to acquire text information to be classified and multiple clustering categories, wherein the multiple clustering categories are obtained by clustering multiple preset word vectors, each clustering category includes at least one preset word vector, and each clustering category corresponds to a cluster center; the vector extraction module is used to extract target word vectors from the text information to be classified; the first matching module is used to match each of the cluster centers with the target word vectors to obtain target cluster centers that match the target word vectors; the second matching module is used to match the target word vectors with the preset word vectors included in the clustering categories corresponding to the target cluster centers to obtain target preset word vectors; the first category determination module is used to determine the category of the text information to be classified based on the category labels corresponding to the target preset word vectors.
[0008] In one possible implementation, the vector extraction module is further used to perform word segmentation on the text information to be classified; and input the segmented text information to be classified into a contrastive learning model to obtain target word vectors.
[0009] In one possible implementation, the apparatus further includes: a sample acquisition module, an input module, and a training module. The sample acquisition module is used to acquire a positive sample dataset and a negative sample dataset, wherein the positive sample dataset includes positive sample text and the negative sample dataset includes negative sample text. The input module is used to input at least one of the positive sample texts and multiple of the negative sample texts into an initial model to obtain positive sample word vectors corresponding to each positive sample text and negative sample word vectors corresponding to each negative sample text. The training module is used to perform comparative learning training on the initial model based on each of the positive sample word vectors and each of the negative sample word vectors until the training termination condition is met, thereby obtaining a comparative learning model.
[0010] In one possible implementation, the first matching module is further configured to calculate the distance between each cluster center and the target word vector to obtain a first vector distance value corresponding to each cluster center, and to take the cluster center corresponding to the first vector distance value that is less than a first preset distance threshold as the target cluster center.
[0011] In one possible implementation, the second matching module is further configured to calculate the distance between the preset word vectors in the cluster category to which the target cluster center belongs and the target word vector, to obtain the second vector distance value corresponding to each preset word vector, and to take the preset word vectors corresponding to the second vector distance values that are less than the second preset distance threshold as the target preset word vectors.
[0012] In one possible implementation, the first category determination module is further configured to: when there are at least two category labels corresponding to the target preset word vector, and there are identical category labels among the at least two category labels, determine the category corresponding to the category label with the largest number of identical category labels among the at least two category labels as the category of the text information to be classified; and when there is only one category label corresponding to the target preset word vector, determine the category corresponding to that category label as the category of the text information to be classified.
[0013] In one possible implementation, the first category determination module is further configured to, when there are at least two category labels corresponding to the target preset word vector, and there are no identical category labels among the at least two category labels, perform similarity calculation between each target preset word vector and the target word vector to obtain the target preset word vector with the highest similarity to the target word vector, and determine the category corresponding to the category label of the target preset word vector as the category of the text information to be classified.
[0014] Fourthly, this application also provides a category determination device applied to a terminal device. The device includes: a second information acquisition module, an information sending module, a tag receiving module, and a second category determination module. The second information acquisition module is used to acquire text information to be classified; the information sending module is used to send the text information to be classified to a server, so that the server inputs the text information to be classified into its deployed contrastive learning model to obtain target word vectors, and matches multiple cluster centers with the target word vectors respectively to obtain target cluster centers matching the target word vectors, and matches the target word vectors with preset word vectors included in the cluster categories corresponding to the target cluster centers to obtain target preset word vectors. The multiple cluster centers are the centers of multiple cluster categories obtained by clustering multiple preset word vectors, and each cluster category includes at least one preset word vector; the tag receiving module is used to receive category tags corresponding to the target preset word vectors fed back by the server; the second category determination module is used to determine the category of the text information to be classified based on the category tags corresponding to the target preset word vectors.
[0015] In one possible implementation, the second information acquisition module is further configured to acquire caller information in response to a call request from the model call interface; and if it is confirmed that the caller to which the caller information belongs has call permissions, acquire the text information to be classified.
[0016] In one possible implementation, the device further includes a category display module, which is used to generate display information including the categories of the text information to be classified; and to display the display information through the model call interface.
[0017] Fifthly, embodiments of this application also provide an electronic device, including: a processor; a memory, wherein computer-readable instructions are stored on the memory, and when the computer-readable instructions are executed by the processor, the text category determination method described above is implemented.
[0018] Sixthly, embodiments of this application provide a computer-readable storage medium storing computer-readable instructions thereon, which, when executed by a processor, implement the text category determination method as described above.
[0019] In a seventh aspect, embodiments of this application provide a computer program product or computer program that includes computer instructions stored in a computer-readable storage medium. A processor of a computer device retrieves the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the method described above.
[0020] This application provides a text category determination method, apparatus, electronic device, and storage medium. By extracting target word vectors from the text information to be classified, the target word vectors can represent the text information to be classified, as well as text information with the same or similar meanings. When a target preset word vector matching the target word vector is found from multiple preset word vectors, multiple cluster centers corresponding to the multiple preset word vectors are matched with the target word vector to obtain target cluster centers matching the target word vector. Furthermore, the target word vector is matched with preset word vectors included in the cluster categories corresponding to the target cluster centers to obtain target preset word vectors. Therefore, when determining the category of the text information to be classified based on the category labels corresponding to the found target preset word vectors, the target word vector of the text information to be classified can be matched with only a small number of preset word vectors to find the target preset word vector matching the target word vector, thus greatly improving the matching efficiency of the target word vector. At the same time, using the category labels corresponding to the found target preset word vectors to determine the category of the text information to be classified can make the determined category of the text information to be classified more accurate. Furthermore, for each piece of text information to be classified, only one processing step is needed to confirm its category. Therefore, in addition to obtaining more accurate categories, the efficiency of category confirmation can also be improved. Attached Figure Description
[0021] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application. It is obvious that the drawings described below are merely some embodiments of this application, and those skilled in the art can obtain other drawings based on these drawings without any inventive effort.
[0022] Figure 1 A schematic diagram of an exemplary system architecture to which the technical solutions of the embodiments of this application can be applied is shown;
[0023] Figure 2 This is a flowchart illustrating a text category determination method according to an embodiment of this application;
[0024] Figure 3 This is a flowchart illustrating a text category determination method according to another embodiment of this application;
[0025] Figure 4 This is a flowchart illustrating the training process of a contrastive learning model according to an embodiment of this application.
[0026] Figure 5 This is a training schematic diagram of a contrastive learning model according to another embodiment of this application;
[0027] Figure 6 This is a flowchart illustrating another method for determining a category, according to a specific embodiment of this application;
[0028] Figure 7 This is a timing diagram illustrating a text category determination method according to a specific embodiment of this application;
[0029] Figure 8 This is an interactive schematic diagram illustrating a text category determination method according to a specific embodiment of this application;
[0030] Figure 9 This is a connection block diagram of a text category determination device according to a specific embodiment of this application;
[0031] Figure 10 This is a connection block diagram of a text category determination device according to another specific embodiment of this application;
[0032] Figure 11 A schematic diagram of the structure of an electronic device suitable for implementing embodiments of this application is shown. Detailed Implementation
[0033] Exemplary embodiments will now be described more fully with reference to the accompanying drawings. However, these exemplary embodiments can be implemented in many forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided to make this application more comprehensive and complete, and to fully convey the concept of the exemplary embodiments to those skilled in the art.
[0034] Furthermore, the described features, structures, or characteristics can be combined in any suitable manner in one or more embodiments. Numerous specific details are provided in the following description to give a thorough understanding of embodiments of this application. However, those skilled in the art will recognize that the technical solutions of this application can be practiced without one or more of the specific details, or other methods, components, apparatuses, steps, etc., can be employed. In other instances, well-known methods, apparatuses, implementations, or operations are not shown or described in detail to avoid obscuring various aspects of this application.
[0035] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities can be implemented in software, in one or more hardware modules or integrated circuits, or in different network and / or processor devices and / or microcontroller devices.
[0036] The flowcharts shown in the accompanying drawings are merely illustrative and do not necessarily include all content and operations / steps, nor do they necessarily have to be performed in the described order. For example, some operations / steps can be broken down, while others can be combined or partially combined; therefore, the actual execution order may change depending on the specific circumstances.
[0037] It should be noted that "multiple" as mentioned in this article refers to two or more.
[0038] With the research and advancement of artificial intelligence technology, it has been studied and applied in multiple fields, playing an increasingly important role.
[0039] Artificial intelligence (AI) is the theory, methods, technology, and application systems that use digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, perceive the environment, acquire knowledge, and use that knowledge to achieve optimal results. In other words, AI is a comprehensive technology within computer science that attempts to understand the essence of intelligence and produce a new kind of intelligent machine that can react in a way similar to human intelligence. Let's take the application of AI in machine learning as an example:
[0040] Machine Learning (ML) is a multidisciplinary field involving probability theory, statistics, approximation theory, convex analysis, and algorithm complexity theory. It specifically studies how computers can simulate or implement human learning behavior to acquire new knowledge or skills and reorganize existing knowledge structures to continuously improve their performance. Machine learning is the core of artificial intelligence and the fundamental way to endow computers with intelligence; its applications span all areas of artificial intelligence. Machine learning and deep learning typically include techniques such as artificial neural networks, belief networks, reinforcement learning, transfer learning, inductive learning, and instructional learning.
[0041] The inventors discovered through research that, currently, there are three common methods for classifying large amounts of text information in applications to remove text information containing violations: manual review, classification using a single model, and classification using multiple models.
[0042] When manually classifying text information, the accuracy of classification is usually high, but the efficiency and cost of manual review are low. Using a single model for text classification requires only one inference, making it fast; however, determining multiple categories can be approximated as multiple tasks, leading to difficulty in training convergence. A single model also suffers from low accuracy when simultaneously judging categories with significantly different properties. When using multiple models for text classification, each model is responsible for determining only one category, requiring a comprehensive assessment of all models' results. This approach offers higher accuracy compared to a single-model method, but the need for multiple models results in significant training overhead, and the sequential processing of all text information across models causes the judgment time to increase approximately linearly with the number of models.
[0043] Based on this, the inventors provide a method for determining text categories, which includes: acquiring text information to be classified; extracting target word vectors from the text information to be classified; searching for a target preset word vector that matches the target word vector from multiple preset word vectors; and determining the category of the text information to be classified based on the category label corresponding to the target preset word vector. Since similar text information to be classified corresponds to similar target word vectors, by extracting the target word vectors of the text information to be classified, it is possible to make the target word vectors represent not only the text information to be classified, but also text information with the same or similar meanings as the text information to be classified. Then, when searching for a target preset word vector that matches the target word vector from multiple preset word vectors, each cluster center is matched with the target word vector to obtain the target cluster center that matches the target word vector. The target word vector is then matched with the preset word vectors included in the cluster category corresponding to the target cluster center to obtain the target preset word vector. When determining the category of the text information to be classified based on the category label corresponding to the found target preset word vector, it is possible to find the target preset word vector that matches the target word vector by matching only a small number of preset word vectors, thereby greatly improving the matching efficiency of the target word vector. At the same time, using the category label corresponding to the found target preset word vector to determine the category of the text information to be classified can make the determined category of the text information to be classified more accurate. Compared to comparing the prediction results of multiple models to determine the category of each text message to be classified, this application only requires the text message to be classified to undergo a single processing step to complete the category confirmation. Therefore, in addition to obtaining more accurate categories, it can also improve the efficiency of further category confirmation.
[0044] Before proceeding with specific explanations, the terms used in this application are explained as follows:
[0045] Text messages can be categorized into categories such as normal text, malicious advertising, and inappropriate content. Malicious advertising text messages contain malicious links or accounts carrying malicious advertisements and misleading information. When a user clicks on such a message, if it contains a malicious advertising link, a malicious account may use this link to infiltrate the user's computer information system, illegally steal data including personal information, and seek illegal profits. If the text message contains malicious advertising accounts and misleading information, it may induce the user to add malicious accounts, potentially leading to malicious inducements and consumption. Inappropriate content text messages contain uncivilized words or sentences. Apart from the aforementioned malicious advertising and inappropriate content text messages containing illegal information, other types of text are generally considered normal text.
[0046] Word vectors for text information refer to the vector representation of text information. Similar text information will also have similar word vectors. For example, text information obtained by replacing one or more words in a target text information with homophones, synonyms, or emoticons with the same meaning is similar text information to the target text information. Accordingly, when extracting word vectors for the target text information, vectors can be extracted for each word included in the target text information to construct the word vectors for the target text information. Since only some words in the text information are replaced, and word vectors with the same or similar words are usually quite similar, the vectors obtained for each similar text information will also be similar.
[0047] A contrastive learning model is a model trained by automatically constructing similar or dissimilar samples and then performing contrastive learning. Similar samples are closer together in the mapping space, while dissimilar samples are farther apart. Contrastive learning models can identify the similarity of texts and extract target word vectors corresponding to the text information to be classified.
[0048] The implementation details of the technical solutions in the embodiments of this application are described in detail below:
[0049] Figure 1 This is a schematic diagram illustrating an application scenario according to an embodiment of this application, such as... Figure 1 As shown, this application scenario includes a terminal device 10 and a server 20 that communicates with the terminal device 10 via a network. The network can be a wide area network (WAN), a local area network (LAN), or a combination of both.
[0050] Server 20 can store text information to be classified, and terminal device 10 can obtain the text information to be classified from server 20 via network.
[0051] Terminal device 10 can be a smartphone, tablet computer, laptop computer, desktop computer, vehicle terminal, or other similar device.
[0052] After acquiring the text information to be classified and multiple cluster categories, the terminal device 10 can extract the target word vector of the text information to be classified; match each cluster center with the target word vector to obtain the target cluster center that matches the target word vector; match the target word vector with the preset word vectors included in the cluster category corresponding to the target cluster center to obtain the target preset word vector; and determine the category of the text information to be classified based on the category label corresponding to the target preset word vector.
[0053] It should be understood that the processes of extracting the target word vector from the text information to be classified; matching each cluster center with the target word vector to obtain the target cluster center that matches the target word vector; and matching the target word vector with the preset word vectors included in the cluster category corresponding to the target cluster center to obtain the target preset word vector can also be performed in the server 20. That is, after obtaining the text information to be classified, the terminal device 10 can also send the text information to be classified to the server 20, so that when the server 20 obtains the text information to be classified, it can extract the target word vector of the text information to be classified, and find the target preset word vector that matches the target word vector from multiple preset word vectors, and return the target preset word vector and the category label corresponding to the target preset word vector to the terminal device. When the terminal device 10 receives the category label returned by the server 20, it can finally determine the category of the text information to be classified based on the category label of the target preset word vector.
[0054] It should be understood that after obtaining the category of the text information to be classified, the terminal device 10 can also display the category of the text information to be classified or report the category of the text information to be classified to the server.
[0055] Figure 2 This is a flowchart illustrating a text category determination method according to an embodiment of this application. This method can be executed by an electronic device with processing capabilities, such as a server, a terminal device, or an interaction between a server and a terminal device to implement this solution, etc., without specific limitations herein. (Refer to...) Figure 2 As shown, the method includes at least steps S110 to S140, which are described in detail below:
[0056] Step S110: Obtain the text information to be classified and multiple clustering categories.
[0057] The multiple cluster categories are obtained by clustering multiple preset word vectors. Each cluster category includes at least one preset word vector and each cluster category corresponds to a cluster center.
[0058] Uncategorized text information refers to information consisting of one or more strings, including text, symbols, pinyin, and initials of words and phrases, entered by users when evaluating products, community applications, videos, articles, or live streams. Uncategorized text information can also refer to a specific article or a paragraph of text.
[0059] There are multiple ways to obtain the text information to be classified.
[0060] In one possible implementation, the system may receive text information to be categorized input by a user. Specifically, it may receive text information to be categorized input by the user through text input, voice input, or other input methods.
[0061] In another possible implementation, the text information to be categorized can be extracted from the comment section of community applications, products, videos, or articles.
[0062] In another possible implementation, the text information can be obtained by taking a screenshot of the comment section of a community application, product, video, or article, and then extracting the text from the image to obtain the text information to be categorized.
[0063] The process of obtaining multiple preset categories can be as follows: obtain multiple preset word vectors, and cluster the multiple preset word vectors to obtain multiple cluster categories, as well as the cluster center corresponding to each cluster category.
[0064] Multiple pre-defined word vectors can be stored as a dataset on an electronic device or server. Each pre-defined word vector corresponds to a pre-defined text message and at least one category label. Pre-defined word vectors corresponding to similar pre-defined text messages are less distant from each other, while dissimilar word vectors are more distant from each other. It should be understood that the pre-defined word vectors should be extracted from the pre-defined text message.
[0065] When clustering multiple preset word vectors, specific clustering methods can be used, such as K-means clustering, Mean-Shift clustering algorithm, density-based noise spatial clustering, expectation-maximization (EM) clustering using Gaussian mixture model (GMM), or agglomerative hierarchical clustering.
[0066] Step S120: Extract the target word vectors of the text information to be classified.
[0067] In one possible implementation, step S120 can be: extracting target word vectors from the text information to be classified using a deep learning model. The deep learning model can be a contrastive learning model or a convolutional neural network model, etc.
[0068] In another implementable manner, the above step S120 may be: performing word segmentation on the text information to be classified to obtain the text information to be classified after word segmentation, and extracting word vectors from the text information to be classified after word segmentation to obtain target word vectors.
[0069] There are various ways to extract word vectors from the text information to be classified after word segmentation.
[0070] In one implementable manner, when extracting word vectors from the text information to be classified after word segmentation, a sparse description method (One-hot Representation) or a distributed description method (Distributed Representation) may be adopted. The target word vector refers to a set of complex numbers or real numbers arranged in an array. The vectors corresponding to the words may be preset. The sorting of the vectors corresponding to each word in the vector matrix is determined according to the arrangement order of the words in the current text. One or more vectors may be used as a row of the vector matrix, and the word vectors are sorted in sequence according to the arrangement order of the corresponding words in the current text to obtain the target word vector. Also, one or more word vectors may be used as a column of the vector matrix, and the vectors corresponding to the words are sorted in sequence according to the arrangement order of the words in the current text to obtain the target word vector.
[0071] Among them, the sparse description method represents a word as a vector composed of 0s and 1s, and the dimension of the vector is the same as the number of words in the word list. The word list is composed of the words to be vectorized. In the word vector corresponding to a word, the dimension value at the position of the word vector corresponding to the arrangement order of the word in the dictionary is 1, and the values of the remaining dimensions are 0. For example, if a word list contains 100 words, each word in the word list is converted into a 100-dimensional vector. Exemplarily, if the arrangement order of "您" in the word list is 3, the word vector of "您" is represented as [0,0,1,0,0……], and if the arrangement order of "尾号" in the word list is 5, the word vector of "尾号" is represented as [0,0,0,0,1,……]. The position of the word in the word list may be set randomly, or the word frequency of the words in a preset text set may be counted, and the words are arranged in sequence in the word list according to the word frequency. When a word is obtained, the arrangement order of the word in the word list is obtained, the word vector is obtained according to the arrangement order, and the word vectors are arranged in the order in the text information to be classified to obtain the target word vector. The distributed description method is a low-dimensional word vector representation method. For example, when a word list contains 10 words, the word vector of "尾号" can be represented only by a five-dimensional vector, such as [0.2,-0.15,-0.33,0.25,-0.14]. The word vectors corresponding to the distributed description method can be obtained by using a word vector model such as word2vector.
[0072] In another possible implementation, when extracting word vectors from the segmented text information to be classified, a deep learning model can be used to extract the target word vectors from the segmented text information to be classified.
[0073] There are various types of deep learning models. For example, contrastive learning models can be used to extract target word vectors from the segmented text to be classified, such as unsupervised contrastive learning models, the simCSE contrastive learning model, or the Sentence-BERT algorithm. Alternatively, the BERT-flow model can be used to extract target word vectors from the segmented text. Finally, the BERT-whitening model can be used to extract target word vectors from the segmented text.
[0074] It should be noted that when using the algorithm model to extract vectors from the text information to be classified after word segmentation, it can effectively ensure that similar text information is closer in the mapping space and dissimilar text information is farther apart in the mapping space. That is, the distance value of the extracted target word vectors corresponding to similar text information is smaller, while the distance of the extracted target word vectors corresponding to dissimilar text information is larger.
[0075] The number of vectors in the target word vector set is preset. When the number of vectors is less than the preset number, invalid vectors can be added before the first vector and / or within the last vector of the vector matrix. Invalid vectors are vectors that will not affect the extracted features when using model parameters, such as vectors containing only 0s. When the number of vectors exceeds the preset number, some vectors can be deleted. The rules for deleting vectors can be set as needed. For example, the vectors of the target words that appear later in the current text can be deleted.
[0076] Furthermore, it should be understood that the process of extracting the preset word vectors of the preset text information should be the same as the extraction method used to extract the target word vectors of the text information to be classified.
[0077] Step S130: Match each cluster center with the target word vector to obtain the target cluster center that matches the target word vector.
[0078] Specifically, step S130 can involve calculating the distance between each cluster center and the target word vector to obtain a first vector distance value corresponding to each cluster center, and selecting the cluster center whose first vector distance value is less than a first preset distance threshold as the target cluster center. The value of the first preset distance threshold can be set according to actual needs and is not specifically limited here.
[0079] Step S130 above can also involve calculating the distance between each cluster center and the target word vector to obtain the first vector distance value corresponding to each cluster center, sorting the first vector distance values in ascending order, selecting the first set number of first vector distance values in the sorted order, and obtaining the cluster center corresponding to the selected first vector value as the target cluster center. The first set number can be 3, 5, or 6, etc., and is not specifically limited here.
[0080] Step S140: Match the target word vector with the preset word vectors included in the cluster category corresponding to the target cluster center to obtain the target preset word vector.
[0081] Specifically, step S140 can be: calculating the distance between the preset word vectors in the cluster category to which the target cluster center belongs and the target word vector, obtaining the second vector distance value corresponding to each preset word vector, and taking the preset word vectors corresponding to the second vector distance values that are less than a second preset distance threshold as the target preset word vectors. The value of the second preset distance threshold can be set according to actual needs and is not specifically limited here. Furthermore, the first preset distance threshold and the second distance threshold can be the same, and the second preset distance threshold can also be less than the first preset distance threshold.
[0082] Step S140 above can also be: calculating the distance between the preset word vectors in the cluster category to which the target cluster center belongs and the target word vector, obtaining the second vector distance value corresponding to each preset word vector, sorting the second vector distance values in ascending order, selecting the second preset number of second vector distance values in the sorted order, and obtaining the preset word vector corresponding to the selected second vector value as the target word vector. The second preset number can be 3, 5, 6, or 8, etc., and is not specifically limited here.
[0083] Step S150: Determine the category of the text information to be classified based on the category label corresponding to the target preset word vector.
[0084] Specifically, the category tags mentioned above can be used to indicate the category of the target preset text information corresponding to the target preset word vector. That is, the category tags can specifically include descriptive words such as normal text, malicious advertising, and uncivilized information to identify the category of the target preset text information corresponding to the target preset word vector.
[0085] When the target preset word vector corresponds to a category label, the category corresponding to that category label can be determined as the category of the text information to be classified.
[0086] When the target preset word vector corresponds to at least two category labels, it is possible to detect whether the at least two label categories include the same category label.
[0087] In this implementation, if at least two category labels have the same category label, the category corresponding to the category label with the most identical category labels among the at least two category labels is determined as the category of the text information to be classified; alternatively, the category corresponding to the category label with more than a set value of identical category labels among the at least two category labels can be determined as the category of the text information to be classified.
[0088] If at least two category labels do not share the same category label, then the similarity between each target preset word vector and the target word vector can be calculated. The target preset word vector with the highest similarity to the target word vector is obtained, and the category corresponding to the category label of that target preset word vector is determined as the category of the text information to be classified. Alternatively, target preset word vectors with a similarity greater than the target word vector threshold can be obtained, and the category corresponding to the category label of that target preset word vector is determined as the category of the text information to be classified.
[0089] The text category determination method provided in this application, since similar text information to be classified also corresponds to similar target word vectors, can extract the target word vectors of the text information to be classified, so that the target word vectors can represent the text information to be classified, and can also represent text information with the same or similar meaning as the text information to be classified. In addition, by matching each cluster center with the target word vector, the target cluster center matching the target word vector is obtained, and the target word vector is matched with the preset word vectors included in the cluster category corresponding to the target cluster center, the target preset word vector is obtained. When determining the category of the text information to be classified based on the category label corresponding to the found target preset word vector, the target word vector of the text information to be classified can be matched with only a small number of preset word vectors to find the target preset word vector matching the target word vector, thereby greatly improving the matching efficiency of the target word vector. At the same time, when determining the category of the text information to be classified using the category label corresponding to the found target preset word vector, the determined category of the text information to be classified can be more accurate. Furthermore, compared to determining the category of each text message by comparing the prediction results of multiple models, this application only requires the text message to be classified to undergo one processing step to complete the category confirmation. Therefore, in addition to obtaining more accurate categories, it can also improve the efficiency of further category confirmation.
[0090] Please see Figure 3 Another embodiment of this application provides a text category determination method applicable to electronic devices, the method comprising:
[0091] Step S210: Obtain the text information to be classified and multiple cluster categories.
[0092] The multiple cluster categories are obtained by clustering multiple preset word vectors. Each cluster category includes at least one preset word vector and each cluster category corresponds to a cluster center.
[0093] Step S220: Perform word segmentation on the text information to be classified to obtain the segmented text information to be classified.
[0094] In this implementation, word segmentation refers to dividing a piece of text information into multiple words. The segmentation method can be set according to actual needs. For example, one or more of the following methods can be used: string matching-based segmentation, understanding-based segmentation, or statistical segmentation. Alternatively, word segmentation tools such as Jieba or Hanlp can be used to segment the current text. After obtaining the current text, word segmentation is performed to obtain the target words corresponding to the current text.
[0095] In one embodiment, when segmenting the current text, preprocessing can be performed first. Preprocessing methods can include removing invalid words, replacing characters of specific data types, such as replacing numbers or words, replacing initial abbreviations, and replacing emoticons. Removing invalid words can include interjections such as "ya" and "oh".
[0096] Step S230: Input the segmented text information to be classified into the contrastive learning model to obtain the target word vector.
[0097] Contrastive learning is a type of self-supervised learning, belonging to discriminative self-supervised learning. The key principle of contrastive learning is: by automatically constructing similar or dissimilar sample text information, the trained model is required to have similar sample text information that is close in distance in the mapping space, and dissimilar sample text information that is far in distance in the mapping space.
[0098] Please see Figure 4 In this embodiment, unlabeled sample text data can be used for training. The specific training process includes the following steps:
[0099] Step S232: Obtain the positive sample dataset and the negative sample dataset. The positive sample dataset includes positive sample text, and the negative sample dataset includes negative sample text.
[0100] Step S234: Input at least one positive sample text and multiple negative sample texts into the initial model to obtain the positive sample word vector corresponding to each positive sample text and the negative sample word vector corresponding to each negative sample text.
[0101] Step S236: Perform comparative learning training on the initial model based on the word vectors of each positive sample and each negative sample until the training termination condition is met, and then obtain the comparative learning model.
[0102] It should be noted that when positive and negative sample texts are input into the initial model, the image passes through the model twice with the same sample text. The randomness of node discarding in the model results in two different target word vectors being generated for each sample text. During training, these vectors are input into the loss function to calculate the model loss. The model gradually converges during training. When the calculated model loss is less than the preset loss threshold or when both positive and negative sample texts in the positive and negative sample datasets have participated in training, the training termination condition is met. At this point, the training of the initial model is complete, and the contrastive learning model is obtained.
[0103] like Figure 5 As shown, in one possible implementation, the initial model includes an encoder. When the number of positive and negative sample texts input to the initial model is one positive sample text and multiple negative sample texts, respectively, the encoder encodes the positive and negative sample texts separately to obtain two word vectors corresponding to the positive sample text and two word vectors corresponding to each negative sample text. After obtaining the word vectors corresponding to the positive and negative sample texts, the similarity between the two word vectors of the positive sample text and the similarity between the word vectors of the positive sample text and each negative sample text can be calculated. The model parameters are then adjusted after calculating the model loss using the following loss function. The loss function can be... Among them, L i Let be the model loss value, and e be a mathematical constant, an infinite non-repeating decimal, and a transcendental number, with a value of approximately 2.718281828459045. For positive sample text similarity, Let τ represent the similarity between positive and negative samples, τ be a temperature parameter used to adjust the model's attention to challenging negative examples, and N be the number of negative sample texts. Since unsupervised learning aims to learn the common characteristics of similar data from a large amount of data and encode them into high-level representations, excellent results can be achieved by fine-tuning the learning model according to different specific tasks. Furthermore, the goal of contrastive learning is to learn an encoder that encodes similar data in a similar manner and makes the encoding results of different classes of data as different as possible. Therefore, by utilizing the contrastive learning model trained as described above, it is possible to effectively ensure that the target word vectors of similar text information are close in distance, while the target word vectors of dissimilar text information are far apart.
[0104] Step S240: Match each cluster center with the target word vector to obtain the target cluster center that matches the target word vector.
[0105] Step S250: Match the target word vector with the preset word vectors included in the cluster category corresponding to the target cluster center to obtain the target preset word vector.
[0106] It should be understood that if the target word vector is obtained by processing the text to be classified using a contrastive learning model, then the preset word vector can also be obtained by processing the preset text information using the same contrastive learning model.
[0107] Step S260: Determine the category of the text information to be classified based on the category label corresponding to the target preset word vector.
[0108] This application provides a text category determination method that extracts target word vectors from text information to be classified using a contrastive learning model. When extracting word vectors using the contrastive learning model, similar text information corresponds to similar target word vectors. Therefore, by extracting target word vectors from text information to be classified, the target word vectors can represent not only the text information to be classified but also text information with the same or similar meaning. Furthermore, the method searches for target preset word vectors that match the target word vector from multiple preset word vectors. By matching each cluster center with the target word vector, the method obtains the target word vector matching the target word vector. The target cluster center is selected, and the target word vector is matched with the preset word vectors included in the cluster category corresponding to the target cluster center to obtain the target preset word vector. When determining the category of the text information to be classified based on the category label corresponding to the found target preset word vector, the target word vector of the text information to be classified can be matched with only a small number of preset word vectors to find the target preset word vector that matches the target word vector, thereby greatly improving the matching efficiency of the target word vector. At the same time, when determining the category of the text information to be classified by using the category label corresponding to the found target preset word vector, the category of the text information to be classified can be more accurate.
[0109] Please see Figure 6 Another embodiment of this application also provides a text category determination method applicable to terminal devices, the method comprising the following steps:
[0110] Step S410: Obtain the text information to be classified.
[0111] It should be noted that in step S410, when the terminal device obtains the text information to be classified, in order to facilitate confirmation of whether the terminal device or the user using the terminal device has the permission to call the contrastive learning model deployed in the server, in one possible implementation, step S410 may include: in response to the call request of the model call interface, obtaining caller information; if it is confirmed that the caller to which the caller information belongs has the call permission, obtaining the text information to be classified.
[0112] The aforementioned caller information may include the user's identity information, the terminal device's device identifier, or both. It should be understood that if the caller information includes the user's identity information, then the caller to which the caller information belongs is the user; if the caller information includes the terminal device's device identifier, then the caller to which the caller information belongs is the terminal device. If a preset match exists between the caller information and the predefined information, it can be confirmed that the caller to which the caller information belongs has the calling authority, and the step of obtaining the text information to be categorized can be executed.
[0113] Step S420: Send the text information to be classified to the server so that the server inputs the text information to be classified into its deployed contrastive learning model to obtain the target word vector, and matches multiple cluster centers with the target word vector to obtain the target cluster center that matches the target word vector. Then, match the target word vector with the preset word vectors included in the cluster category corresponding to the target cluster center to obtain the target preset word vector.
[0114] Among them, multiple cluster centers are the centers of multiple cluster categories obtained by clustering multiple preset word vectors, and each cluster category includes at least one preset word vector.
[0115] It should be understood that the server can perform subsequent vector extraction and vector matching steps as soon as it receives the text information to be classified, or the server can perform subsequent vector extraction and vector matching steps as soon as it receives a vector processing request including the text information to be classified.
[0116] In one possible implementation, when a terminal device sends text information to be classified to a server, it can construct a vector extraction request including the text information to be classified and a vector retrieval request. This allows the server, upon receiving the vector extraction request and the vector retrieval request, to first extract the target word vector of the text information to be classified in response to the vector extraction request, and then, in response to the vector retrieval request, search for a target preset word vector that matches the target word vector from its stored multiple preset word vectors.
[0117] In another possible implementation, when the terminal device sends the text information to be classified to the server, it can first perform word segmentation on the text information to be classified to obtain segmented text information. Then, it constructs a vector extraction request including the segmented text information. Upon receiving the vector extraction request, the server uses its deployed classification learning model to process the segmented text information to obtain target word vectors and sends these target word vectors back to the terminal device. Upon receiving the target word vectors, the terminal device can construct a retrieval request including the target word vectors and send it to the server. Upon receiving this retrieval request, the server matches multiple cluster centers with the target word vectors to obtain target cluster centers that match the target word vectors. The server then matches the target word vectors with preset word vectors included in the cluster categories corresponding to the target cluster centers to obtain target preset word vectors and sends the category labels corresponding to the target preset word vectors back to the terminal device.
[0118] Step S430: Receive the category labels corresponding to the target preset word vectors from the server.
[0119] Step S440: Determine the category of the text information to be classified based on the category label corresponding to the target preset word vector.
[0120] For details on the specific implementation process of each of the above steps, please refer to the detailed description of the foregoing embodiments; they will not be repeated here.
[0121] After the terminal device determines the category of the text information to be classified based on the category label corresponding to the target preset word vector, in order to facilitate users to view the category of the text information to be classified, in this embodiment, the method includes: generating display information including the category of the text information to be classified; and displaying the display information through the model call interface.
[0122] The information to be displayed may specifically include text information to be categorized and the category of that text information.
[0123] This application provides a text category determination method applicable to terminal devices. By deploying a contrastive learning model and a database including multiple preset word vectors on the server side, the method enables different terminals to call the server-deployed contrastive learning model and database to classify text information. During the category confirmation process, since similar text information also corresponds to similar target word vectors, by extracting the target word vectors of the text information to be classified, the method can ensure that the target word vectors can represent the text information to be classified, as well as text information with the same or similar meaning. This allows multiple cluster centers to be associated with the target word vectors. By matching word vectors, target cluster centers matching the target word vector are obtained. The target word vector is then matched with the preset word vectors included in the cluster categories corresponding to the target cluster centers to obtain target preset word vectors. When determining the category of the text information to be classified based on the category labels corresponding to the found target preset word vectors, the target word vector of the text information to be classified can be matched with only a small number of preset word vectors to find the target preset word vector that matches the target word vector, thereby greatly improving the matching efficiency of the target word vector. At the same time, using the category labels corresponding to the found target preset word vectors to determine the category of the text information to be classified can make the determined category of the text information to be classified more accurate.
[0124] Please refer to the following: Figure 7 and Figure 8 Another embodiment of this application also provides a text category determination method, applied to a terminal device 10 and a server 20, the method comprising:
[0125] When a user needs to determine the category of a text message to be classified, the terminal device 10 performs a model invocation operation to send a model invocation interface request to the user. Upon receiving this invocation operation, the terminal device 10 can invoke the verification module to perform an authentication operation and return an authentication success response upon successful authentication. The verification module is a software program module. Specifically, the terminal device 10 can, in step S510, respond to the model invocation interface request by obtaining caller information. Upon obtaining the caller information, the terminal device 10 can determine, based on pre-stored information, whether the caller to which the obtained caller information belongs has the permission to invoke the contrastive learning model deployed on the server 20.
[0126] If the terminal device 10 receives a successful authentication response, that is, confirms that the caller to which the caller information belongs has the calling authority, it calls the processing function to perform word segmentation processing on the text information to be classified. Specifically, step S520 can be executed: obtain the text information to be classified and perform word segmentation processing on the text information to be classified. In this way, the word segmented text information to be classified can be obtained.
[0127] To facilitate the server 20 in extracting the vector of the text information to be classified after word segmentation, the terminal device 10 can perform step S530 after performing word segmentation on the text information to be classified: constructing a vector extraction request including the text information to be classified after word segmentation and sending the vector extraction request to the server 20.
[0128] When server 20 receives a vector extraction request, it may execute step S540: in response to the vector extraction request, it calls its deployed contrastive learning model to extract the target word vectors of the text information to be classified after word segmentation.
[0129] The contrastive learning model can be a model pre-trained and stored by the server 20. The specific training process of the contrastive learning model can be found in the detailed description in the foregoing embodiments, and will not be repeated here.
[0130] After the server 20 completes the vector extraction of the text information to be classified, step S550 can be executed: the target word vector is fed back to the terminal device 10.
[0131] When the terminal device 10 receives the target word vector, step S560: construct a retrieval request including the target word vector and send it to the server 20.
[0132] When the server 20 receives a vector retrieval request, it may perform step S570: in response to the vector retrieval request, it matches multiple cluster centers with the target word vector to obtain the target cluster center that matches the target word vector, and matches the target word vector with the preset word vectors included in the cluster category corresponding to the target cluster center to obtain the target preset word vector.
[0133] It should be understood that before the server 20 matches multiple cluster centers with the target word vector to obtain the target cluster center that matches the target word vector, it can first cluster multiple preset word vectors to obtain multiple cluster categories and cluster centers of each cluster category. Each cluster category includes at least one preset word vector. Then, it searches for the target cluster center that matches the target word vector and searches for the target preset word vector that matches the target word vector from the preset word vectors corresponding to each target cluster center.
[0134] After the server 20 obtains the target preset word vector, step S580 can be executed: the category label corresponding to the target preset word vector is fed back to the terminal device 10.
[0135] When the terminal device 10 receives the category label corresponding to the target preset word vector, it executes step S590: determine the category of the text information to be classified based on the category label corresponding to the target preset word vector.
[0136] After determining the category of the text information to be categorized, terminal device 10 can also generate display information including the category of the text information to be categorized; and display the display information through a model call interface. This allows users to view the category of the text information to be categorized. It should be understood that after confirming the category of the text information to be categorized, terminal device 10 can also process the text information to be categorized according to the determined category, such as deleting the text information to be categorized, or performing account permission restrictions, account revocation, and traffic limiting on the account corresponding to the text information to be categorized.
[0137] The following describes an apparatus embodiment of this application, which can be used to perform the methods described in the above embodiments of this application. For details not disclosed in the apparatus embodiments of this application, please refer to the method embodiments described in the above embodiments of this application.
[0138] Figure 9 This is a text category determination device according to an embodiment, such as Figure 9 As shown, the text category determination device 600 includes: a first information acquisition module 610, a vector extraction module 620, a first matching module 630, a second matching module 640, and a first category determination module 640.
[0139] The first information acquisition module 610 is used to acquire the text information to be classified and multiple cluster categories. The multiple cluster categories are obtained by clustering multiple preset word vectors. Each cluster category includes at least one preset word vector and each cluster category corresponds to a cluster center. The vector extraction module 620 is used to extract the target word vector of the text information to be classified. The first matching module 630 is used to match each cluster center with the target word vector to obtain the target cluster center that matches the target word vector. The second matching module 640 is used to match the target word vector with the preset word vectors included in the cluster category corresponding to the target cluster center to obtain the target preset word vector. The first category determination module 650 is used to determine the category of the text information to be classified based on the category label corresponding to the target preset word vector.
[0140] In one possible implementation, the vector extraction module 620 is further used to perform word segmentation on the text information to be classified; and input the segmented text information to be classified into a contrastive learning model to obtain the target word vector.
[0141] In one possible implementation, the device 600 further includes: a sample acquisition module, an input module, and a training module. The sample acquisition module is used to acquire a positive sample dataset and a negative sample dataset, wherein the positive sample dataset includes positive sample text and the negative sample dataset includes negative sample text. The input module is used to input at least one positive sample text and multiple negative sample texts into an initial model to obtain positive sample word vectors corresponding to each positive sample text and negative sample word vectors corresponding to each negative sample text. The training module is used to perform comparative learning training on the initial model based on each positive sample word vector and each negative sample word vector until the training termination condition is met, thus obtaining a comparative learning model.
[0142] In one possible implementation, the first matching module 630 is further configured to calculate the distance between each cluster center and the target word vector to obtain the first vector distance value corresponding to each cluster center, and to take the cluster center corresponding to the first vector distance value that is less than the first preset distance threshold as the target cluster center.
[0143] In this implementation, the second matching module 640 is further configured to calculate the distance between the preset word vectors in the cluster category to which the target cluster center belongs and the target word vector, to obtain the second vector distance value corresponding to each preset word vector, and to take the preset word vector corresponding to the second vector distance value that is less than the second preset distance threshold as the target preset word vector.
[0144] In one possible implementation, the first category determination module 650 is further configured to determine the category corresponding to the category label with the most identical category labels among the at least two category labels as the category of the text information to be classified when the category label corresponding to the target preset word vector is at least two and there are identical category labels among the at least two category labels; and to determine the category corresponding to the category label as the category of the text information to be classified when the category label corresponding to the target preset word vector is one.
[0145] In one possible implementation, the first category determination module 650 is further configured to calculate the similarity between each target preset word vector and the target word vector when there are at least two category labels corresponding to the target preset word vector and there are no identical category labels among the at least two category labels, obtain the target preset word vector with the highest similarity to the target word vector, and determine the category corresponding to the category label of the target preset word vector as the category of the text information to be classified.
[0146] Figure 10 This is a text category determination device 700 shown according to another embodiment of this application, such as... Figure 10 As shown, the text category determination device 700 includes: a second information acquisition module 710, an information sending module 720, a tag receiving module 730, and a second category determination module 740.
[0147] The second information acquisition module 710 is used to acquire text information to be classified; the information sending module 720 is used to send the text information to be classified to the server, so that the server inputs the text information to be classified into its deployed contrastive learning model to obtain target word vectors, and matches multiple cluster centers with the target word vectors respectively to obtain target cluster centers that match the target word vectors, and matches the target word vectors with the preset word vectors included in the cluster categories corresponding to the target cluster centers to obtain target preset word vectors. The multiple cluster centers are the centers in multiple cluster categories obtained by clustering multiple preset word vectors, and each cluster category includes at least one preset word vector; the label receiving module 730 is used to receive the category labels corresponding to the target preset word vectors fed back by the server; the second category determination module 740 is used to determine the category of the text information to be classified according to the category labels corresponding to the target preset word vectors.
[0148] In one possible implementation, the second information acquisition module 710 is further configured to acquire caller information in response to a call request from the model call interface; and if it is confirmed that the caller to which the caller information belongs has call permissions, acquire the text information to be classified.
[0149] In one possible implementation, the device 700 further includes a category display module, which generates display information including categories of text information to be classified; and displays the display information through a model call interface.
[0150] It should be noted that the device embodiments in this application correspond to the aforementioned method embodiments. The specific principles in the device embodiments can be found in the content of the aforementioned method embodiments, and will not be repeated here.
[0151] The following will combine Figure 11 This application provides a description of an electronic device 100.
[0152] Please see Figure 11 Based on the text category determination method provided in the above embodiments, this application embodiment also provides another electronic device 100 including a processor 102 capable of executing the aforementioned method. The electronic device 100 can be a server 10 or a terminal device. The terminal device can be a smartphone, tablet computer, computer, or portable computer, etc., which can install a first client and / or a second client.
[0153] The electronic device 100 also includes a memory 104. The memory 104 stores a program that can execute the contents of the foregoing embodiments, and the processor 102 can execute the program stored in the memory 104.
[0154] The processor 102 may include one or more cores for data processing and message matrix units. The processor 102 connects to various parts within the electronic device 100 using various interfaces and lines, and performs various functions and processes data by running or executing instructions, programs, code sets, or instruction sets stored in the memory 104, and by calling data stored in the memory 104. Optionally, the processor 102 may be implemented using at least one hardware form of Digital Signal Processing (DSP), Field-Programmable Gate Array (FPGA), or Programmable Logic Array (PLA). The processor 102 may integrate one or more of the following: Central Processing Unit (CPU), Graphics Processing Unit (GPU), and modem. The CPU primarily handles the operating system, user interface, and applications; the GPU is responsible for rendering and drawing the displayed content; and the modem handles wireless communication. It is understood that the modem may also not be integrated into the processor 102 and may be implemented separately using a communication chip.
[0155] The memory 104 may include random access memory (RAM) or read-only memory (ROM). The memory 104 can be used to store instructions, programs, code, code sets, or instruction sets. The memory 104 may include a program storage area and a data storage area. The program storage area may store instructions for implementing an operating system, instructions for implementing at least one function, instructions for implementing the various method embodiments described below, etc. The data storage area may also store data acquired by the electronic device 100 during use (e.g., recommended data and operating methods).
[0156] The electronic device 100 may also include a network module and a screen. The network module is used to receive and transmit electromagnetic waves, converting electromagnetic waves into electrical signals, thereby enabling communication with communication networks or other devices, such as audio playback devices. The network module may include various existing circuit elements used to perform these functions, such as antennas, radio frequency transceivers, digital signal processors, encryption / decryption chips, SIM cards, memory, etc. The network module can communicate with various networks such as the Internet, corporate intranets, and wireless networks, or communicate with other devices via wireless networks. The aforementioned wireless networks may include cellular telephone networks, wireless local area networks, or metropolitan area networks. The screen can display interface content and facilitate data interaction.
[0157] In some embodiments, the electronic device 100 may further include a peripheral interface 106 and at least one peripheral device. The processor 102, memory 104, and peripheral interface 106 can be connected via a bus or signal line. Each peripheral device can be connected to the peripheral interface via a bus, signal line, or circuit board. Specifically, the peripheral device includes at least one of the following: a radio frequency component 108, a positioning component 112, a camera 114, an audio component 116, a display screen 118, and a power supply 122.
[0158] Peripheral interface 106 can be used to connect at least one I / O (Input / Output) related peripheral device to processor 102 and memory 104. In some embodiments, processor 102, memory 104 and peripheral interface 106 are integrated on the same chip or circuit board; in some other embodiments, any one or two of processor 102, memory 104 and peripheral interface 106 can be implemented on separate chips or circuit boards, and this application embodiment does not limit this.
[0159] The radio frequency (RF) component 108 is used to receive and transmit RF (Radio Frequency) signals, also known as electromagnetic signals. The RF component 108 communicates with communication networks and other communication devices via electromagnetic signals. The RF component 108 converts electrical signals into electromagnetic signals for transmission, or converts received electromagnetic signals back into electrical signals. Optionally, the RF component 108 includes: an antenna system, an RF transceiver, one or more amplifiers, a tuner, an oscillator, a digital signal processor, a codec chipset, a user identity module card, etc. The RF component 108 can communicate with other terminals via at least one wireless communication protocol. This wireless communication protocol includes, but is not limited to: the World Wide Web, metropolitan area networks, intranets, various generations of mobile communication networks (2G, 3G, 4G, and 5G), wireless local area networks, and / or WiFi (Wireless Fidelity) networks. In some embodiments, the RF component 108 may also include circuitry related to NFC (Near Field Communication), which is not limited in this application.
[0160] The positioning component 112 is used to locate the current geographical location of the electronic device 100 in order to enable navigation or LBS (Location Based Service). The positioning component 112 can be a positioning component based on the US GPS (Global Positioning System), China's BeiDou system, or Russia's Galileo system.
[0161] Camera 114 is used to capture images or videos. Optionally, camera 114 includes a front-facing camera and a rear-facing camera. Typically, the front-facing camera is located on the front panel of the electronic device 100, and the rear-facing camera is located on the back of the electronic device 100. In some embodiments, there are at least two rear-facing cameras, which are any one of a main camera, a depth-sensing camera, a wide-angle camera, and a telephoto camera, to achieve background blurring by fusion of the main camera and the depth-sensing camera, panoramic shooting by fusion of the main camera and the wide-angle camera, VR (Virtual Reality) shooting, or other fusion shooting functions. In some embodiments, camera 114 may also include a flash. The flash can be a single-color temperature flash or a dual-color temperature flash. A dual-color temperature flash refers to a combination of a warm light flash and a cool light flash, which can be used for light compensation at different color temperatures.
[0162] Audio component 116 may include a microphone and a speaker. The microphone is used to collect sound waves from the user and the environment, and convert the sound waves into electrical signals that are input to processor 102 for processing, or input to radio frequency component 108 for voice communication. For stereo acquisition or noise reduction purposes, there may be multiple microphones, each located at a different part of electronic device 100. The microphone may also be an array microphone or an omnidirectional microphone. The speaker is used to convert electrical signals from processor 102 or radio frequency component 108 into sound waves. The speaker may be a conventional diaphragm speaker or a piezoelectric ceramic speaker. When the speaker is a piezoelectric ceramic speaker, it can convert electrical signals not only into sound waves that humans can hear, but also into sound waves that humans cannot hear for purposes such as ranging. In some embodiments, audio component 114 may also include a headphone jack.
[0163] Display screen 118 is used to display a UI (User Interface). This UI may include graphics, text, icons, videos, and any combination thereof. When display screen 118 is a touch display screen, it also has the ability to collect touch signals on or above its surface. These touch signals can be input as control signals to processor 102 for processing. In this case, display screen 118 can also be used to provide virtual buttons and / or a virtual keyboard, also known as soft buttons and / or a soft keyboard. In some embodiments, there may be one display screen 118, which serves as the front panel of electronic device 100; in other embodiments, there may be at least two display screens, respectively disposed on different surfaces of electronic device 100 or in a folded design; in still other embodiments, display screen 118 may be a flexible display screen, disposed on a curved or folded surface of electronic device 100. Furthermore, display screen 118 may be configured as a non-rectangular irregular shape, i.e., a non-rectangular screen. Display screen 118 may be made of materials such as LCD (Liquid Crystal Display) or OLED (Organic Light-Emitting Diode).
[0164] Power supply 122 is used to supply power to various components in electronic device 100. Power supply 122 can be alternating current, direct current, a disposable battery, or a rechargeable battery. When power supply 122 includes a rechargeable battery, the rechargeable battery can be a wired rechargeable battery or a wireless rechargeable battery. A wired rechargeable battery is a battery that is charged via a wired line, while a wireless rechargeable battery is a battery that is charged via a wireless coil. The rechargeable battery can also be used to support fast charging technology.
[0165] This application also provides a computer-readable storage medium. This computer-readable medium stores program code that can be called by a processor to execute the methods described in the above method embodiments.
[0166] Computer-readable storage media can be electronic storage devices such as flash memory, EEPROM (Electrically Erasable Programmable Read-Only Memory), EPROM, hard disk, or ROM. Optionally, computer-readable storage media includes non-transitory computer-readable storage medium. The computer-readable storage medium has storage space for program code that performs any of the method steps described above. This program code can be read from or written to one or more computer program products. The program code can be compressed, for example, in a suitable form.
[0167] This application also provides a computer program product or computer program that includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the methods described in the various optional implementations above.
[0168] In summary, the text category determination method, apparatus, electronic device, and storage medium provided in this application extract target word vectors from the text information to be classified. This allows the target word vectors to represent not only the text information to be classified but also text information with the same or similar meanings. Furthermore, by matching each cluster center with the target word vector to obtain target cluster centers that match the target word vector, and by matching the target word vector with preset word vectors included in the cluster categories corresponding to the target cluster centers to obtain target preset word vectors, the category of the text information to be classified can be determined based on the category labels corresponding to the found target preset word vectors. This allows matching the target word vectors with only a small number of preset word vectors to find the target preset word vectors that match the target word vectors, thus greatly improving the matching efficiency of the target word vectors. Simultaneously, using the category labels corresponding to the found target preset word vectors to determine the category of the text information to be classified can make the determined category of the text information to be classified more accurate.
[0169] It should be noted that although several modules or units for the device used to perform actions have been mentioned in the detailed description above, this division is not mandatory. In fact, according to the embodiments of this application, the features and functions of two or more modules or units described above can be embodied in one module or unit. Conversely, the features and functions of one module or unit described above can be further divided and embodied by multiple modules or units.
[0170] Through the above description of the embodiments, those skilled in the art will readily understand that the exemplary embodiments described herein can be implemented by software or by combining software with necessary hardware. Therefore, the technical solutions according to the embodiments of this application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (such as a CD-ROM, USB flash drive, external hard drive, etc.) or on a network, including several instructions to cause a computing device (such as a personal computer, server, touch terminal, or network device, etc.) to execute the method according to the embodiments of this application.
[0171] Other embodiments of this application will readily occur to those skilled in the art upon consideration of the specification and practice of the embodiments disclosed herein. This application is intended to cover any variations, uses, or adaptations of this application that follow the general principles of this application and include common knowledge or customary techniques in the art not disclosed herein.
[0172] It should be understood that this application is not limited to the precise structure described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this application is limited only by the appended claims.
Claims
1. A text category determination method characterized by comprising: The method comprises the following steps: obtaining text information to be classified and a plurality of clustering categories, wherein the plurality of clustering categories are obtained by clustering a plurality of preset word vectors, each clustering category comprises at least one preset word vector, and each clustering category corresponds to a clustering center; extracting a target word vector of the text information to be classified; matching each clustering center with the target word vector to obtain a target clustering center matched with the target word vector; matching the target word vector with a preset word vector included in a clustering category corresponding to the target clustering center to obtain a target preset word vector; determining a category of the text information to be classified according to a category label corresponding to the target preset word vector.
2. The method of claim 1, wherein, The method for extracting the target word vector of the text information to be classified comprises the following steps: performing word segmentation on the text information to be classified; inputting the text information to be classified after word segmentation into a contrast learning model to obtain the target word vector.
3. The method of claim 2, wherein, The contrast learning model is obtained by the following method: obtaining a positive sample data set and a negative sample data set, wherein the positive sample data set comprises positive sample texts, and the negative sample data set comprises negative sample texts; inputting at least one positive sample text and a plurality of negative sample texts into an initial model to obtain a positive sample word vector corresponding to each positive sample text and a negative sample word vector corresponding to each negative sample text; performing contrast learning training on the initial model based on each positive sample word vector and each negative sample word vector until a training end condition is reached to obtain the contrast learning model.
4. The method of claim 1, wherein, The method for matching each clustering center with the target word vector to obtain a target clustering center matched with the target word vector comprises the following steps: performing distance calculation on each clustering center and the target word vector to obtain a first vector distance value corresponding to each clustering center, and taking a clustering center corresponding to a first vector distance value smaller than a first preset distance threshold as the target clustering center.
5. The method of claim 4, wherein, The method for matching the target word vector with a preset word vector corresponding to the target clustering center to obtain a target preset word vector comprises the following steps: performing distance calculation on a preset word vector in a clustering category to which the target clustering center belongs and the target word vector to obtain a second vector distance value corresponding to each preset word vector, and taking a preset word vector corresponding to a second vector distance value smaller than a second preset distance threshold as the target preset word vector.
6. The method according to any one of claims 1 to 5, characterized in that, The method for determining a category of the text information to be classified according to a category label corresponding to the target preset word vector comprises the following steps: if the category label corresponding to the target preset word vector is at least two, and there is a same category label in the at least two category labels, taking a category corresponding to a category label with the largest number of same category labels in the at least two category labels as the category of the text information to be classified; if the category label corresponding to the target preset word vector is one, taking a category corresponding to the category label as the category of the text information to be classified.
7. The method of claim 6, wherein, The method further includes: If the category label corresponding to the target preset word vector is at least two, and there is no same category label in the at least two category labels, similarity calculation is performed on each target preset word vector and the target word vector to obtain a target preset word vector with the highest similarity to the target word vector, and a category corresponding to the category label of the target preset word vector is determined as the category of the text information to be classified.
8. A text category determination method characterized by comprising: The method is applied to a terminal device, and includes: obtaining text information to be classified; sending the text information to be classified to a server, so that the server inputs the text information to be classified into a contrast learning model deployed by the server to obtain a target word vector, and matches a plurality of clustering centers with the target word vector respectively to obtain a target clustering center matched with the target word vector, matches preset word vectors included in a clustering category corresponding to the target clustering center with the target word vector to obtain a target preset word vector, the plurality of clustering centers are centers in a plurality of clustering categories obtained by clustering a plurality of preset word vectors, and each clustering category includes at least one preset word vector; receiving a category label corresponding to the target preset word vector fed back by the server; determining a category of the text information to be classified according to the category label corresponding to the target preset word vector.
9. The method of claim 8, wherein, The step of obtaining text information to be classified includes: obtaining caller information in response to a calling request of a model calling interface; if it is confirmed that a caller to which the caller information belongs has a calling right, obtaining text information to be classified.
10. The method of claim 9, wherein, After the category of the text information to be classified is determined according to the category label of the preset text information corresponding to the target preset word vector, the method further includes: generating to-be-displayed information including the category of the text information to be classified; displaying the to-be-displayed information through the model calling interface.
11. A text category determination apparatus characterized by comprising: The device includes: a first information obtaining module configured to obtain text information to be classified and a plurality of clustering categories, the plurality of clustering categories are obtained by clustering a plurality of preset word vectors, each clustering category includes at least one preset word vector, and each clustering category corresponds to a clustering center; a vector extracting module configured to extract a target word vector of the text information to be classified; a first matching module configured to match each of the clustering centers with the target word vector to obtain a target clustering center matched with the target word vector; a second matching module configured to match the target word vector with preset word vectors included in a clustering category corresponding to the target clustering center to obtain a target preset word vector; a first category determining module configured to determine a category of the text information to be classified according to a category label corresponding to the target preset word vector.
12. A text category determination device, applied to a terminal device, characterized in that, The device includes: a second information obtaining module configured to obtain text information to be classified; The information sending module is configured to send the text information to be classified to a server, so that the server inputs the text information to be classified into a contrast learning model deployed by the server, obtains a target word vector, and matches a plurality of clustering centers with the target word vector respectively to obtain a target clustering center matched with the target word vector, matches the target word vector with a preset word vector included in a clustering category corresponding to the target clustering center to obtain a target preset word vector, the plurality of clustering centers are centers in a plurality of clustering categories obtained by clustering a plurality of preset word vectors, and each clustering category includes at least one preset word vector; The label receiving module is configured to receive a category label corresponding to the target preset word vector fed back by the server. The second category determining module is configured to determine a category of the text information to be classified according to the category label corresponding to the target preset word vector.
13. An electronic device, comprising: Comprise: A processor; A memory, the memory has computer readable instructions stored thereon, and the computer readable instructions are executed by the processor to implement the method in any one of claims 1-7 or 8-10.
14. A computer-readable storage medium having stored thereon computer-readable instructions, wherein, When the computer readable instructions are executed by the processor, the method in any one of claims 1-7 or 8-10 is implemented.
15. A computer program product comprising computer instructions, characterized in that, The computer instructions are executed by the processor to implement the method in any one of claims 1-7 or 8-10.
Citation Information
Patent Citations
Text recognition method and device, storage medium and electronic equipment
CN112256880A
Data classification method and device, storage medium and electronic device
CN112948583A