A text classification method and device
By using the vector search library in text classification to generate target vectors of similar vectors, the problem of small amount of training data is solved, and the accuracy of text classification is improved, especially suitable for sensitive data fields.
Patent Information
- Application Number
- CN202311342239.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-10-17
- Publication Date
- 2025-02-18
- Estimated Expiration
- 2043-10-17
AI Technical Summary
The prior art cannot guarantee the accuracy of text classification when the amount of training data is small, especially in the sensitive information field, and it is difficult to obtain a large amount of training data.
The target text information is obtained through the first device, and encoded it according to a preset text encoder to generate a first vector. Then, the target vector with the greatest similarity to the first vector is determined from the vector search library. The target vector is generated from a plurality of similar vectors, and its corresponding text category is used as the text category of the target text information.
The amount of data used to train the model is increased, and the accuracy of text classification is improved, especially in the sensitive data field.
Smart Images

Figure CN117708322B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence technology, and in particular to a text classification method and device. Background Art
[0002] With the rapid development of artificial intelligence (AI) technology, deep learning (DL) has been widely used in image, video, text and other fields.
[0003] Text classification (TC) is a technology based on deep learning technology that maps text containing information to a preset text category or several text categories. Through text classification, a large amount of text information can be quickly classified, saving human resources. As the scope of application of text classification technology becomes more and more extensive, people's requirements for the accuracy of text classification technology are getting higher and higher.
[0004] The existing text classification scheme usually directly uses training models such as BERT (Bidirectional Encoder Representations from Transformers) to classify text information. This method requires a large amount of high-quality training data when performing deep learning. Therefore, when the amount of training data is small, the accuracy of text classification cannot be guaranteed. Summary of the invention
[0005] The embodiments of the present application provide a text classification method and device to improve the accuracy of text classification.
[0006] In a first aspect, an embodiment of the present application provides a text classification method. The method includes: a first device obtains target text information. The target text information is encoded according to a preset text encoder to obtain a first vector, and the first vector corresponds to the target text information. A target vector is determined from a vector retrieval library according to the first vector, the target vector is the vector with the greatest similarity to the first vector in the vector retrieval library, and the similarity between the target vector and the first vector is greater than a preset first threshold value, the target vector is generated based on multiple similar vectors, and the text category corresponding to the similar vector is the same as the text category corresponding to the target vector. The text category corresponding to the target vector is used as the text category of the target text information.
[0007] By adopting this method, the first device can generate one or more target vectors corresponding to the text category based on similar vectors of the same text category, increase the data used for training the model, and thus improve the accuracy of text classification. At the same time, since the target vector is generated based on multiple similar vectors, the text category corresponding to the target vector is used as the text category corresponding to the target text information, which can further improve the accuracy of text classification.
[0008] In a possible design, a preset text encoder is trained based on multiple training data, each of the training data is obtained by joint learning through a federated learning server, and the federated learning server is used to jointly learn data from multiple devices.
[0009] Based on this design, federated learning can be performed through a federated learning server without leaking sensitive data, thereby increasing the amount of data for training the model and improving the performance of the text encoder.
[0010] In one possible design, the first device determines m text information from a text information library according to a first text category corresponding to a target vector, the text information library including a plurality of text information and text categories corresponding to the text information, the text category corresponding to the m text information is the first text category, and m is an integer greater than 1. The m text information is encoded according to a preset text encoder to obtain vectors of the m text information.
[0011] For each of the m vectors of text information, perform the following processing:
[0012] According to the vector, n similar vectors are determined from the vector search library, and the similarity between any one of the n similar vectors and the vector is greater than a preset second threshold, where n is an integer greater than 1. A target vector is generated according to the m*n similar vectors.
[0013] Based on this design, the first device can generate one or more target vectors corresponding to the text category based on similar vectors of the same text category, increase the data used for training the model, and thus improve the accuracy of text classification. At the same time, since the target vector is generated based on multiple similar vectors, the text category corresponding to the target vector is used as the text category corresponding to the target text information, which can further improve the accuracy of text classification.
[0014] In one possible design, the target vector satisfies:
[0015]
[0016] Among them, the similarity vector i is the i-th vector among m*n similar vectors.
[0017] In a possible design, if the maximum value of the similarity between the vector in the vector search library and the first vector is less than a first threshold, a text type corresponding to the target text information is generated according to the target text information, and the text type corresponding to the first vector and the target text information is stored in the vector search library.
[0018] Based on this design, when the training model makes mistakes in classifying text, the classification results can be quickly corrected, and the new text category corresponding to the text information can be stored in the vector retrieval library, which can be updated to optimize the performance of the training model and improve the accuracy of text classification.
[0019] In a second aspect, an embodiment of the present application provides a text classification device. The device includes: a communication module, which is used to obtain target text information. A processing module, which is used to encode the target text information according to a preset text encoder to obtain a first vector, and the first vector corresponds to the target text information. The processing module is also used to determine a target vector from a vector retrieval library based on the first vector, the target vector is the vector with the greatest similarity to the first vector in the vector retrieval library, and the similarity between the target vector and the first vector is greater than a preset first threshold, the target vector is generated based on multiple similar vectors, and the text category corresponding to the similar vector is the same as the text category corresponding to the target vector. The processing module is also used to use the text category corresponding to the target vector as the text category of the target text information.
[0020] In a possible design, a preset text encoder is trained based on multiple training data, each of the training data is obtained by joint learning through a federated learning server, and the federated learning server is used to jointly learn data from multiple devices.
[0021] In one possible design, the processing module is specifically used to determine m text information from a text information library according to a first text category corresponding to the target vector, the text information library including multiple text information and text categories corresponding to the text information, the text category corresponding to the m text information is the first text category, and m is an integer greater than 1. The m text information is encoded according to a preset text encoder to obtain vectors of the m text information.
[0022] For each of the m vectors of text information, perform the following processing:
[0023] According to the vector, n similar vectors are determined from the vector search library, and the similarity between any one of the n similar vectors and the vector is greater than a preset second threshold, where n is an integer greater than 1. A target vector is generated according to the m*n similar vectors.
[0024] In one possible design, the target vector satisfies:
[0025]
[0026] Among them, the similarity vector i is the i-th vector among m*n similar vectors.
[0027] In one possible design, the processing module is specifically used to: if the maximum value of the similarity between the vector in the vector search library and the first vector is less than a first threshold, generate a text type corresponding to the target text information according to the target text information, and store the text type corresponding to the first vector and the target text information in the vector search library.
[0028] In a third aspect, an embodiment of the present application further provides a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, the method as described in the first aspect and any possible design thereof is implemented.
[0029] In a fourth aspect, an embodiment of the present application further provides an electronic device, comprising a memory and a processor, wherein the memory stores a computer program that can be run on the processor, and when the computer program is executed by the processor, the processor implements the method as described in the first aspect above and any possible design thereof.
[0030] The technical effects brought about by the second to fourth aspects and any one of their designs can refer to the technical effects brought about by the corresponding design in the first aspect, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0032] Figure 1 A flowchart of a text classification method provided in an embodiment of the present application;
[0033] Figure 2 A schematic diagram of a process for generating a target vector provided in an embodiment of the present application;
[0034] Figure 3 A structural diagram of a text classification device provided in an embodiment of the present application;
[0035] Figure 4 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0036] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be described in detail in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present application.
[0037] It should be understood that, in the description of the embodiments of the present invention, words such as “first” and “second” are only used to distinguish the description and cannot be understood as indicating or implying relative importance or order.
[0038] The term "and / or" in the embodiments of the present invention is only a description of the association relationship of the associated objects, indicating that three relationships may exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship.
[0039] Next, the text classification method is introduced in combination with the existing technology.
[0040] The existing text classification schemes usually use a training model based on deep learning technology to classify text information. The existing text classification schemes usually need to use a large amount of high-quality training data to train the model before classifying the text, so as to ensure the accuracy of text classification. Although this method can classify text information through a large amount of training, if this method is applied to the field of sensitive information (for example, tax code classification of goods), since a large amount of sensitive data cannot be obtained when training the model, the performance of the model training is poor, and the accuracy of text classification cannot be guaranteed.
[0041] In order to solve the above defects, the present application provides a text classification method and device to improve the accuracy of text classification.
[0042] In the present application, the method adopted includes: the first device can encode the acquired target text information according to a preset text encoder to obtain a first vector corresponding to the target text information. The first device can determine the target vector with the greatest similarity to the first vector from a vector retrieval library according to the first vector. The maximum value of the similarity is greater than a preset first threshold. The target vector is generated based on multiple similar vectors with the same text category as the target vector. The first device can use the text category corresponding to the target vector as the text category of the target text information.
[0043] The vector retrieval library in this application includes multiple vectors and text categories corresponding to the vectors.
[0044] The classification method provided in this application can be applied to the text classification of sensitive data. For example, the scheme provided in this application can classify the tax code of the product name. That is, the product name can be the target text information in this application, and the tax code can be the text category in this application.
[0045] It can be understood that the first device in the present application can use the text category of the target vector with the highest similarity to the first vector in the vector retrieval library as the text category of the target text information. Among them, the target vector is generated based on multiple similar vectors with the same text category as the target vector. That is to say, the first device can generate one or more target vectors corresponding to the text category based on similar vectors of the same text category. Therefore, the use of this method can increase the data used for training the model, thereby improving the accuracy of text classification. At the same time, since the target vector is generated based on multiple similar vectors, using the text category corresponding to the target vector as the text category corresponding to the target text information can further improve the accuracy of text classification. In addition, the first device can be included in a computer system for executing the method shown in the present application, or it can be a processing device in a computer system for executing the method shown in the present application, such as a processor or a processing module, etc., which is not specifically limited in the present application.
[0046] Figure 1 A flowchart of a text classification method provided by an embodiment of the present invention. Taking the first device as the execution subject as an example, the process may include the following steps:
[0047] S101, a first device obtains target text information.
[0048] Specifically, the user can input the target text information that needs to be classified through an input device (such as a keyboard, a touch screen, etc.). The first device can receive the target text information from the input device. Alternatively, the first device can also obtain the target text information through a storage device storing the target text information. In addition, the first device can also obtain the target text information through other methods, which will not be listed one by one in this application.
[0049] S102: The first device encodes the target text information according to a preset text encoder to obtain a first vector, wherein the first vector corresponds to the target text information.
[0050] Specifically, the first device may input the target text information into a preset encoder, and the preset encoder encodes the target text information and outputs a first vector corresponding to the target text information.
[0051] In one or more embodiments, the preset text encoder may be obtained by training based on a plurality of training data. Each of the training data may be obtained by joint learning through a federated learning server. The federated learning server is used to perform joint learning on data of a plurality of devices.
[0052] Exemplarily, in this application, the text encoder model can be trained in the following manner:
[0053] Take the product name as the target text information and the tax code as the text category as an example.
[0054] Step 1: The first device may perform data processing on the goods stored in itself and the tax codes corresponding to the goods names according to preset data processing rules (such as text cleaning, normalization, etc.).
[0055] Step 2: The first device may input the product name into the Bert text encoder in the form of (product name A, product name B, 0 / 1), where 0 represents that the tax codes corresponding to product name A and product name B are different, and 1 represents that the tax codes corresponding to product name A and product name B are the same.
[0056] Step 3: The first device may initialize the local model using the Bert pre-training parameters. The first device may summarize the loss values obtained by pre-training and send the loss values to the federated learning server.
[0057] In step 4, the federated learning server can perform joint learning based on the loss values of multiple devices, obtain learning parameters (such as gradient information), and send the learning parameters to multiple devices.
[0058] It is understandable that the present application may include multiple devices for jointly training a preset text encoder. The specific manner in which the multiple devices obtain the loss value can be referred to the specific manner in which the first device obtains the loss value, and will not be repeated here.
[0059] Furthermore, after obtaining the learning parameters, the first device can update the local text encoder according to the learning parameters and repeat step 3 until the loss value meets the preset condition. Similarly, the remaining devices also train the local text encoder in the same way.
[0060] Based on this embodiment, the preset text encoder can perform model training through a federated learning server. The federated learning server performs joint learning based on the loss values of multiple devices. In other words, federated learning can be performed without leaking sensitive data, thereby increasing the amount of data for training the model and improving the performance of the text encoder.
[0061] S103: The first device determines a target vector from a vector retrieval library according to the first vector.
[0062] Specifically, the first device may search the first vector through a vector search library and determine a target vector from the vector search library. The target vector is a vector in the vector search library that has the greatest similarity to the first vector, and the similarity between the target vector and the first vector is greater than a preset first threshold. The target vector is generated based on multiple similar vectors, and the text category corresponding to the similar vector is the same as the text category corresponding to the target vector.
[0063] Exemplarily, the first device may generate the target vector in the following manner:
[0064] Figure 2 A schematic diagram of a process for generating a target vector provided in an embodiment of the present application. With the first device as the execution subject, the process may include the following steps:
[0065] S201: A first device obtains a first text category corresponding to a target vector.
[0066] S202: The first device determines m text information from a text information database according to the first text type, wherein the text category corresponding to the m text information is the first text category, and m is an integer greater than 1.
[0067] Specifically, if the first device needs to generate a target vector of the first text type, the first device can obtain m text information whose text category is the first text category from the text information library. Among them, m can be set according to its own needs. For example, the first device can determine that all text information whose text category is the first text category in the text information library is according to its own needs. Alternatively, the first device can determine that some text information whose text category is the first text category in the text information library is according to its own needs.
[0068] S203: The first device encodes the m pieces of text information according to a preset text encoder to obtain vectors of the m pieces of text information.
[0069] Specifically, the specific manner in which the first device encodes the m text information according to the preset text encoder can refer to the specific manner in which the first device encodes the target text information according to the preset text encoder, which will not be repeated here.
[0070] S204: The first device determines n similar vectors from a vector search library for each of the m vectors of text information.
[0071] Specifically, the first device may search each of the m vectors of the text information through the vector search library, and determine n similar vectors from the vector search library, wherein the similarity between any one of the n similar vectors and the vector is greater than a preset second threshold, and n is an integer greater than 1.
[0072] That is, the first device may use vectors in the vector search library whose similarity with the vector is greater than a second threshold (eg, 80%) as similar vectors to the vector.
[0073] In addition, if the number of vectors in the vector search library whose similarity to the vector is greater than the second threshold is greater than n, n similar vectors with high similarity can be obtained. If the number of vectors in the vector search library whose similarity to the vector is greater than the second threshold is less than n, the number of n can be readjusted, or the vectors whose similarity to the vector is less than the second threshold can be padded to ensure that the number of similar vectors is n.
[0074] It is understandable that, since m text information corresponds to m vectors, and one vector corresponds to n similarity vectors, m*n similarity vectors can be obtained according to the m text information.
[0075] S205: The first device generates a target vector according to the m*n similarity vectors.
[0076] Optionally, the first device may take an average vector of m*n similar vectors as the target vector.
[0077] The target vector and similarity vector satisfy:
[0078]
[0079] Among them, the similarity vector i is the i-th vector among m*n similar vectors.
[0080] It is understandable that if the m text information is all text information corresponding to the first text category in the text information library, the first device can generate a target vector based on the text information corresponding to the first text category in the text information library. If the m text information is part of the text information corresponding to the first text category in the text information library, the first device can generate multiple target vectors based on the text information corresponding to the first text category in the text information library.
[0081] Based on this embodiment, the first device can generate one or more target vectors corresponding to the text category based on similar vectors of the same text category, increase the data used for training the model, and thus improve the accuracy of text classification. At the same time, since the target vector is generated based on multiple similar vectors, the text category corresponding to the target vector is used as the text category corresponding to the target text information, which can further improve the accuracy of text classification.
[0082] In addition, the present application may include multiple data providing devices, which can generate a target vector corresponding to the first text category based on their own text information library in the same way. It is understandable that since the target vector is generated based on multiple similar vectors and not directly based on text information, sharing the target vector will not leak sensitive data. Therefore, multiple data providing devices can share target vectors with each other, which can further increase the amount of data for training the model, thereby improving the accuracy of text classification.
[0083] The vector retrieval library can be constructed by the first device according to the text information stored in the first device and the text category corresponding to the text information.
[0084] Exemplarily, still taking the product name as the target text information and the tax code as the text category as an example. The first device can encode the product name according to a preset text encoder to generate a vector corresponding to the product name. The first device can store the vector corresponding to the product name and the tax code corresponding to the product name in a database, thereby constructing a vector retrieval library. For example, the first device can store in the form of (vector, tax code). Alternatively, the first device can store in the form of (vector, tax code index). After obtaining the tax code index, the first device can obtain the tax code according to the tax code index by looking up a table or the like.
[0085] S104: The first device uses the text category corresponding to the target vector as the text category of the target text information.
[0086] Specifically, the storage format in the vector retrieval library may be (vector, text category). The first device may obtain the corresponding text category according to the target vector, and use the text category as the text category of the target text information. Alternatively, the storage format in the vector retrieval library may be (vector, text category index). The first device may obtain the index of the corresponding text category according to the target vector, and then obtain the text category by table lookup or the like according to the index of the text category, and use the text category as the text category of the target text information.
[0087] In one or more embodiments, if the maximum value of the similarity between the vector in the vector search library and the first vector is less than a first threshold, a text type corresponding to the target text information is generated according to the target text information, and the text type corresponding to the first vector and the target text information is stored in the vector search library.
[0088] Specifically, in order to ensure the accuracy of text classification, a first threshold may be set. If the similarity between two vectors is less than the first threshold, it means that the text categories corresponding to the two vectors are different text categories.
[0089] The first device can determine the vector with the greatest similarity to the first vector from the vector search library by executing the actions of step S101 to step S103. If the similarity between the vector and the first vector is less than the first threshold, it means that the text categories corresponding to the vector and the first vector are different text categories. The first device can generate a new text category according to the target text information, and store the first vector and the new text category in the vector search library.
[0090] Exemplarily, take the product name C as the target text information, vector C as the vector corresponding to the product name C, and the tax code as the text category as an example.
[0091] If the first device searches vector C through the vector search library and the similarity between the obtained vector and vector C is lower than the set threshold, it means that the result of the training model for text classification of product name C is incorrect. The first device can generate a new tax code based on product name C and store vector C and the tax code in the vector search library.
[0092] Based on this embodiment, when the training model makes an error in classifying text, the classification result can be quickly corrected, and the new text category corresponding to the text information can be stored in the vector retrieval library, the vector retrieval library can be updated, the performance of the training model can be optimized, and the accuracy of text classification can be improved.
[0093] Based on the above content and the same concept, the present application provides a text classification device. Figure 3 The figure shows a modular structure diagram of a text classification device provided in an embodiment of the present application. The device may include a communication module 301 and a processing module 302 .
[0094] The communication module 301 is used to obtain the target text information. The processing module 302 is used to encode the target text information according to a preset text encoder to obtain a first vector, and the first vector corresponds to the target text information. The processing module 302 is also used to determine the target vector from the vector retrieval library according to the first vector, the target vector is the vector with the greatest similarity to the first vector in the vector retrieval library, and the similarity between the target vector and the first vector is greater than a preset first threshold value, the target vector is generated based on multiple similar vectors, and the text category corresponding to the similar vector is the same as the text category corresponding to the target vector. The processing module 302 is also used to use the text category corresponding to the target vector as the text category of the target text information.
[0095] In a possible design, a preset text encoder is trained based on multiple training data, each of the training data is obtained by joint learning through a federated learning server, and the federated learning server is used to jointly learn data from multiple devices.
[0096] In a possible design, the processing module 302 is specifically used to determine m text information from a text information library according to the first text category corresponding to the target vector, the text information library includes multiple text information and text categories corresponding to the text information, the text category corresponding to the m text information is the first text category, and m is an integer greater than 1. The m text information is encoded according to a preset text encoder to obtain vectors of the m text information.
[0097] For each of the m vectors of text information, perform the following processing:
[0098] According to the vector, n similar vectors are determined from the vector search library, and the similarity between any one of the n similar vectors and the vector is greater than a preset second threshold, where n is an integer greater than 1. A target vector is generated according to the m*n similar vectors.
[0099] In one possible design, the target vector satisfies:
[0100]
[0101] Among them, the similarity vector i is the i-th vector among m*n similar vectors.
[0102] In a possible design, the processing module 302 is specifically used to: if the maximum value of the similarity between the vector in the vector search library and the first vector is less than the first threshold, generate the text type corresponding to the target text information according to the target text information, and store the text type corresponding to the first vector and the target text information in the vector search library.
[0103] Figure 4A schematic diagram of the structure of an electronic device provided in an embodiment of the present application is shown.
[0104] The electronic device in the embodiment of the present application may include a processor 401. The processor 401 is the control center of the device, and various interfaces and lines can be used to connect various parts of the device, by running or executing instructions stored in the memory 403 and calling data stored in the memory 403. Optionally, the processor 401 may include one or more processing units, and the processor 401 may integrate an application processor and a modem processor, wherein the application processor mainly processes operating systems and application programs, etc., and the modem processor mainly processes wireless communications. It is understandable that the above-mentioned modem processor may not be integrated into the processor 401. In some embodiments, the processor 401 and the memory 403 may be implemented on the same chip, and in some embodiments, they may also be implemented separately on independent chips.
[0105] Processor 401 can be a general-purpose processor, such as a central processing unit (CPU), a digital signal processor, an application-specific integrated circuit, a field programmable gate array or other programmable logic device, a discrete gate or transistor logic device, a discrete hardware component, and can implement or execute the methods, steps and logic block diagrams disclosed in the embodiments of the present application. A general-purpose processor can be a microprocessor or any conventional processor, etc. The method steps disclosed in the embodiments of the present application can be directly executed by a hardware processor, or can be executed by a combination of hardware and software modules in the processor.
[0106] In the embodiment of the present application, the memory 403 stores instructions that can be executed by at least one processor 401. The at least one processor 401 can be used to execute the method steps disclosed in the embodiment of the present application by executing the instructions stored in the memory 403.
[0107] Memory 403, as a non-volatile computer-readable storage medium, can be used to store non-volatile software programs, non-volatile computer executable programs and modules. Memory 403 may include at least one type of storage medium, such as flash memory, hard disk, multimedia card, card-type memory, random access memory (Random Access Memory, RAM), static random access memory (Static Random Access Memory, SRAM), programmable read-only memory (Programmable Read Only Memory, PROM), read-only memory (Read Only Memory, ROM), electrically erasable programmable read-only memory (Electrically Erasable Programmable Read-Only Memory, EEPROM), magnetic memory, disk, optical disk, etc. Memory 403 is any other medium that can be used to carry or store a desired program code in the form of an instruction or data structure and can be accessed by a computer, but is not limited thereto. The memory 403 in the embodiment of the present application can also be a circuit or any other device that can realize a storage function, for storing program instructions and / or data.
[0108] In the embodiment of the present application, the device may further include a communication interface 402 , through which the electronic device may transmit data.
[0109] Optional, can be Figure 4 The processor 401 (or the processor 401 and the communication interface 402) implements Figure 3 The processing module 302 and / or the communication module 301 shown, that is, the actions of the processing module 302 and / or the communication module 301 can be executed by the processor 401 (or the processor 401 and the communication interface 402).
[0110] Based on the same inventive concept, the embodiment of the present application also provides a computer-readable storage medium, which may store instructions. When the instructions are executed on a computer, the computer executes the operation steps provided in the above method embodiment. The computer-readable storage medium may be Figure 4 The memory 403 is shown.
[0111] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0112] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0113] These computer program instructions may also be stored in a computer readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0114] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0115] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.
Claims
1. A text classification method, characterized in that: The method comprises: The first device acquires target text information; Encoding the target text information according to a preset text encoder to obtain a first vector, where the first vector corresponds to the target text information; Determine a target vector from a vector search library according to the first vector, wherein the target vector is a vector in the vector search library with the greatest similarity to the first vector, and the similarity between the target vector and the first vector is greater than a preset first threshold, the target vector is generated according to a plurality of similar vectors, and the text category corresponding to the similar vector is the same as the text category corresponding to the target vector; Using the text category corresponding to the target vector as the text category of the target text information; The first device generates the target vector according to the plurality of similarity vectors, including: The first device determines m text information from a text information library according to a first text category corresponding to the target vector, the text information library including a plurality of text information and text categories corresponding to the text information, the text category corresponding to the m text information is the first text category, and m is an integer greater than 1; Encoding the m text information according to the preset text encoder to obtain vectors of the m text information; For each of the m vectors of text information, the following processing is performed: Determine n similar vectors from a vector search library according to the vector, wherein the similarity between any one of the n similar vectors and the vector is greater than a preset second threshold, and n is an integer greater than 1; according to similar vectors to generate the target vector.
2. The method according to claim 1, characterized in that The preset text encoder is obtained by training based on multiple training data, each of the training data is obtained by joint learning through a federated learning server, and the federated learning server is used to jointly learn data from multiple devices.
3. The method according to claim 1, characterized in that The target vector satisfies: ; Among them, the similarity vector i For the The i-th vector among similar vectors.
4. The method according to claim 1, characterized in that The method further comprises: If the maximum value of the similarity between the vectors in the vector search library and the first vector is less than the first threshold, generating a text type corresponding to the target text information according to the target text information; The text type corresponding to the first vector and the target text information is stored in the vector retrieval library.
5. A text classification device, characterized in that: The device comprises: A communication module, used for acquiring target text information; A processing module, configured to encode the target text information according to a preset text encoder to obtain a first vector, wherein the first vector corresponds to the target text information; The processing module is further used to determine a target vector from a vector search library according to the first vector, the target vector being a vector in the vector search library with the greatest similarity to the first vector, and the similarity between the target vector and the first vector is greater than a preset first threshold, the target vector is generated according to a plurality of similar vectors, and the text category corresponding to the similar vector is the same as the text category corresponding to the target vector; The processing module is further configured to use the text category corresponding to the target vector as the text category of the target text information; The target vector is generated according to the plurality of similar vectors, and the processing module is specifically used for: According to the first text category corresponding to the target vector, m text information is determined from a text information library, the text information library includes a plurality of text information and text categories corresponding to the text information, the text category corresponding to the m text information is the first text category, and m is an integer greater than 1; Encoding the m text information according to the preset text encoder to obtain vectors of the m text information; For each of the m vectors of text information, the following processing is performed: Determine n similar vectors from a vector search library according to the vector, wherein the similarity between any one of the n similar vectors and the vector is greater than a preset second threshold, and n is an integer greater than 1; according to similar vectors to generate the target vector.
6. The device according to claim 5, characterized in that The preset text encoder is obtained by training based on multiple training data, each of the training data is obtained by joint learning through a federated learning server, and the federated learning server is used to jointly learn data from multiple devices.
7. The device according to claim 5, characterized in that The target vector satisfies: ; Among them, the similarity vector i For the The i-th vector among similar vectors.
8. The device according to claim 5, characterized in that The processing module is specifically used for: If the maximum value of the similarity between the vectors in the vector search library and the first vector is less than the first threshold, generating a text type corresponding to the target text information according to the target text information; The text type corresponding to the first vector and the target text information is stored in the vector retrieval library.
9. An electronic device, characterized in that: The electronic device comprises a processor, and the processor is used to implement the steps of any one of the methods as claimed in claims 1 to 4 when executing a computer program stored in a memory.
10. A computer-readable storage medium, characterized in that: The device stores a computer program, which implements the steps of the method according to any one of claims 1 to 4 when executed by a processor.
Citation Information
Patent Citations
Multi-strategy combined document automatic classification method
CN103092931A
Text classification method and text classification system
CN111949789A