Text classification method and device, computer program product and electronic equipment
By acquiring and preprocessing text data sets and generating fusion vector representations using pre-trained encoder and knowledge graph encoder, the problems of small number of training data sets and low sample classification accuracy in the prior art are solved, and the model performance is significantly improved.
Patent Information
- Application Number
- CN202510024403.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-07
- Publication Date
- 2025-04-11
AI Technical Summary
In the prior art, the number of training data sets is small and the accuracy of sample classification is low, resulting in poor model performance.
The first and second data sets are generated by obtaining the original data set and the label-free data set from the data source of the text data, exploratory data analysis and preprocessing. After the merge, the initial training data set is obtained, and further data analysis and preprocessing are carried out to generate the training data set. Each training sample in the training dataset is input to the pretrained encoder and knowledge graph encoder, and a pretrained vector representation and a knowledge graph vector representation are generated, and fused to generate a fusion vector representation, which is finally sent to the classifier to obtain the classification results.
By increasing the amount of training sample data and improving classification accuracy, the model performance is improved, and the problems of small number of training data sets and low sample classification accuracy are solved.
Smart Images

Figure CN119807418A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of big data, and more specifically, to a text classification method, device, computer program product, and electronic device. Background Art
[0002] In the existing technology, text classification is an important field of natural language processing and is widely used in scenarios such as sentiment analysis, topic classification, and information retrieval. Traditional methods usually rely on manual feature extraction combined with machine learning models for classification, but the effect is limited when faced with large-scale data. In recent years, the rapid development of deep learning technology has promoted the application of pre-trained models in text classification, and has significantly improved classification performance by capturing contextual semantic information. At the same time, in order to solve the problem of insufficient semantic information, some technologies attempt to combine external knowledge bases or knowledge graphs to enhance the accuracy of text representation. However, in low-resource environments, insufficient training data and uneven category distribution remain major challenges.
[0003] Currently, no effective solution has been proposed to address the problem that the number of training data sets in related technologies is small, and the classification accuracy of samples in the data sets is low, resulting in poor model performance when the training data sets are used to train the model. Summary of the invention
[0004] The main purpose of the present application is to provide a text classification method, device, computer program product and electronic device to solve the problem in the related art that the number of training data sets is small and the classification accuracy of samples in the data sets is low, resulting in poor model performance when the training data sets are used to train the model.
[0005] In order to achieve the above-mentioned purpose, according to one aspect of the present application, a text classification method is provided. The method includes: obtaining an original data set and an unlabeled data set from a data source of text data; performing exploratory data analysis on the original data set, and preprocessing the original data set based on the analysis results to obtain a first data set, recalling pseudo labels for unlabeled samples in the unlabeled data set to obtain a second data set; merging the first data set and the second data set to obtain an initial training data set, performing exploratory data analysis on the initial training data set, and preprocessing the initial training data set based on the analysis results to obtain a training data set; inputting each training sample in the training data set into a pretraining encoder to generate a pretraining vector representation, and inputting each training sample in the training data set into a knowledge graph encoder to generate a knowledge graph vector representation; for each training sample, merging the pretraining vector representation and the knowledge graph vector representation to generate a fused vector representation, and sending the fused vector representation to a classifier to obtain a classification result.
[0006] Optionally, obtaining the original data set and unlabeled data from a data source of text data includes: determining the data source, wherein the data source includes at least a network, an online database, and a local database; obtaining labeled samples from the data source, and determining the original data set based on the obtained labeled samples, wherein the labeled samples include text content and labels corresponding to the text content; obtaining unlabeled samples from the data source, and determining the unlabeled data set based on the obtained unlabeled samples, wherein the unlabeled samples include text content.
[0007] Optionally, an exploratory data analysis is performed on the original data set, and the original data set is preprocessed based on the analysis results to obtain a first data set, including: determining the label categories of the original labels of the samples in the original data set, and the number of labels under each label category, and judging whether there are label categories with unbalanced label quantities based on the label categories and the number of labels under each label category, wherein the unbalanced label quantity refers to that the difference between the number of labels under at least one label category and the average number of labels of all label categories is greater than a preset number; in the case of category labels with unbalanced label quantities, samples under the label categories with unbalanced label quantities are removed from the original data set to obtain an updated original data set; determining the length of the samples in the updated original data set, and judging whether there are samples with abnormal lengths, wherein the samples with abnormal lengths include samples with a length greater than a first preset length, samples with a length less than a second preset length, and samples with empty text content, and the first preset length is greater than the second preset length; in the case of samples with abnormal lengths, the samples with abnormal lengths are removed from the updated original data set to obtain the first data set.
[0008] Optionally, recalling pseudo labels for unlabeled samples in the unlabeled data set to obtain the second data set includes: determining a threshold for judging whether to recall pseudo labels for unlabeled samples; calculating a term frequency-inverse document frequency value for each sample in the unlabeled data set and each sample in the first data set to obtain M groups of term frequency-inverse document frequency values, wherein each group of term frequency-inverse document frequency values includes N term frequency-inverse document frequency values, M is the number of unlabeled samples in the unlabeled dataset, and N is the number of labeled samples in the first dataset, where M and N are positive integers; for each unlabeled sample in the unlabeled dataset, determine the maximum term frequency-inverse document frequency value from a corresponding set of term frequency-inverse document frequency values to obtain M first term frequency-inverse document frequency values; for each first term frequency-inverse document frequency value, when the first term frequency-inverse document frequency value is greater than a threshold, recall the label of the labeled sample corresponding to the first term frequency-inverse document frequency value to the unlabeled sample to obtain a pseudo-label sample, and when the first term frequency-inverse document frequency value is less than or equal to the threshold, discard the unlabeled sample corresponding to the first term frequency-inverse document frequency value; poll all unlabeled samples in the unlabeled dataset, and determine all pseudo-label samples as the second dataset.
[0009] Optionally, determining a threshold for judging whether to recall a pseudo-label for an unlabeled sample includes: traversing each sample in the first data set, calculating the term frequency-inverse document frequency values of the current sample and samples in the first data set other than the current sample, and obtaining N groups of term frequency-inverse document frequency values, each group containing N-1 term frequency-inverse document frequency values; for each labeled sample in the first data set, determining the maximum term frequency-inverse document frequency value from a corresponding group of term frequency-inverse document frequency values, and obtaining N second term frequency-inverse document frequency values; sorting the N second term frequency-inverse document frequency values from large to small, and selecting the second term frequency-inverse document frequency value of a preset order as the threshold.
[0010] Optionally, an exploratory data analysis is performed on the initial training data set, and the initial training data set is preprocessed based on the analysis results to obtain the training data set, including: determining the label category of the merged label of the samples in the initial training data set, and the number of labels under each label category, and judging whether there are label categories with unbalanced label quantities based on the label category and the number of labels under each label category, wherein the unbalanced label quantity refers to that the difference between the number of labels under at least one label category and the average number of labels of all label categories is greater than a preset number; in the case of category labels with unbalanced label quantities, samples under the label categories with unbalanced label quantities are removed from the initial training data set to obtain an updated initial training data set; determining the length of the samples in the updated initial training data set, and judging whether there are samples with abnormal lengths, wherein the samples with abnormal lengths include samples with a length greater than a third preset length, samples with a length less than a fourth preset length, and samples with empty text content, and the third preset length is greater than the fourth preset length; in the case of samples with abnormal lengths, the samples with abnormal lengths are removed from the updated initial training data set to obtain the training data set.
[0011] Optionally, each training sample in the training data set is input into a pre-trained encoder, and generating a pre-trained vector representation includes: segmenting the training sample through a word segmenter, and generating a first word unit sequence according to the word segmentation result; truncating or padding the first word unit sequence according to the maximum input length of the pre-trained encoder to generate a second word unit sequence, wherein the word units in the word unit sequence whose length exceeds the maximum input length are truncated, and the word units whose length is less than the maximum input length are padded with a first preset value; matching each word unit in the second word unit sequence with a term in the vocabulary, and mapping the successfully matched word units to the corresponding vocabulary index to generate an input identification sequence; generating an attention mask according to the positions of the actual word units and the padding word units in the second word unit sequence, wherein the actual word unit position is represented by the second preset value, and the padding word unit position is represented by the first preset value; inputting the input identification sequence and the attention mask into the pre-trained encoder, extracting the value of the classification word unit position of the last layer of the pre-trained encoder, and obtaining the pre-trained vector representation.
[0012] Optionally, each training sample in the training data set is input into the knowledge graph encoder to generate a knowledge graph vector representation, including: performing entity recognition on the training sample through an entity recognition model to generate an entity word unit sequence, wherein words that are not recognized as entities are represented by a first preset value; replacing the entity words in the entity word unit sequence with the query representation in the knowledge graph to obtain a sparse vector representation; and densifying the sparse vector representation to generate a knowledge graph vector representation of the training sample.
[0013] Optionally, for each training sample, the pre-trained vector representation and the knowledge graph vector representation are fused to generate a fused vector representation, including: for each training sample, the pre-trained vector representation and the knowledge graph vector representation are spliced to generate a spliced vector; the spliced vector is linearly transformed to obtain a linear transformation result, and the linear transformation result is input into an activation function to calculate a first dynamic weight, wherein the first dynamic weight is used to control the fusion ratio of the pre-trained vector representation and the knowledge graph vector representation; the first dynamic weight is subtracted from the total weight value to obtain a second dynamic weight, wherein the second dynamic weight is used to control the fusion ratio of the pre-trained vector representation and the knowledge graph vector representation; and the pre-trained vector representation and the knowledge graph vector representation are weightedly summed according to the first dynamic weight and the second dynamic weight to generate a fused vector representation.
[0014] In order to achieve the above-mentioned purpose, according to another aspect of the present application, a text classification device is provided. The device includes: a data set acquisition module, which is used to acquire an original data set and an unlabeled data set from a data source of text data; a data set processing module, which is used to perform exploratory data analysis on the original data set, and preprocess the original data set based on the analysis results to obtain a first data set, and recall pseudo labels for unlabeled samples in the unlabeled data set to obtain a second data set; a data set merging and processing module, which is used to merge the first data set and the second data set to obtain an initial training data set, perform exploratory data analysis on the initial training data set, and preprocess the initial training data set based on the analysis results to obtain a training data set; a vector conversion module, which is used to input each training sample in the training data set into a pretraining encoder to generate a pretraining vector representation, and input each training sample in the training data set into a knowledge graph encoder to generate a knowledge graph vector representation; a vector fusion and classification module, which is used to fuse the pretraining vector representation and the knowledge graph vector representation for each training sample, generate a fused vector representation, and send the fused vector representation to a classifier to obtain a classification result.
[0015] In order to achieve the above-mentioned purpose, according to another aspect of the present application, a computer program product is provided, which includes: a non-volatile computer-readable storage medium storing a computer program, and the computer program implements a text classification method when executed by a processor.
[0016] In order to achieve the above-mentioned purpose, according to another aspect of the present application, an electronic device is provided. The device includes: a computer program is stored in a memory, and a processor is configured to execute a text classification method through the computer program.
[0017] In an embodiment of the present application, an original data set and an unlabeled data set are obtained from a data source of text data; an exploratory data analysis is performed on the original data set, and the original data set is preprocessed based on the analysis results to obtain a first data set, and pseudo labels are recalled for unlabeled samples in the unlabeled data set to obtain a second data set; the first data set and the second data set are merged to obtain an initial training data set, an exploratory data analysis is performed on the initial training data set, and the initial training data set is preprocessed based on the analysis results to obtain a training data set; each training sample in the training data set is input into a pretrained encoder to generate a pretrained vector representation, and each training sample in the training data set is input into a knowledge graph encoder to generate a knowledge graph vector representation; for each training sample, the pretrained vector representation and the knowledge graph vector representation are fused to generate a fused vector representation, and the fused vector representation is sent to a classifier to obtain a classification result. By performing exploratory analysis and preprocessing on the data to obtain the first data set, generating pseudo labels to obtain the second data set, merging the two and preprocessing them to obtain the training data set, extracting the global semantics and knowledge graph semantic information and fusing and classifying them, the technical effect of increasing the amount of training sample data and improving classification accuracy is achieved, thereby solving the problem of the small number of training data sets in related technologies and the low classification accuracy of samples in the data sets, which leads to poor model performance when the training data set is used to train the model. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] The drawings constituting a part of the present application are used to provide a further understanding of the present application. The illustrative embodiments and descriptions of the present application are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0019] Figure 1 A hardware structure block diagram of a computer terminal for implementing a text classification method is shown;
[0020] Figure 2 is a flowchart of a text classification method provided according to an embodiment of the present application;
[0021] Figure 3 It is a flowchart based on knowledge graph encoding provided according to an embodiment of the present application;
[0022] Figure 4 This is the process of the optional text classification method provided in the embodiment of the present application Figure 1 ;
[0023] Figure 5 is a schematic diagram of a text classification device provided according to an embodiment of the present application;
[0024] Figure 6 It is a structural block diagram of an electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0025] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present application.
[0026] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0027] It should be noted that the collected information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data for display, data for analysis, etc.) involved in this application are information and data authorized by the user or fully authorized by all parties, and the collection, storage, use, processing, transmission, provision, disclosure and application of relevant data are in compliance with relevant laws, regulations and standards, necessary confidentiality measures are taken, and public order and good customs are not violated, and corresponding operation entrances are provided for users to choose to authorize or refuse. For example, an interface is set up between this system and relevant users or institutions, providing users with corresponding operation entrances for users to choose to agree or refuse the results of automated decision-making; if the user chooses to refuse, the expert decision-making process will be entered.
[0028] Example 1
[0029] According to an embodiment of the present application, a method embodiment of text classification is also provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0030] The method embodiment provided in the first embodiment of the present application can be executed in a mobile terminal, a computer terminal or a similar computing device. Figure 1FIG. 1 shows a hardware structure block diagram of a computer terminal for implementing a text classification method. Figure 1 As shown, the computer terminal 10 (or mobile device) may include one or more (shown in the figure as 102a, 102b, ..., 102n) processors 102 (the processor 102 may include but is not limited to a processing device such as a microprocessor (MCU, Microcontroller Unit) or a programmable logic device (FPGA, Field-Programmable Gate Array)), a memory 104 for storing data, and a transmission device 106 for communication functions. In addition, it may also include: a display, an input / output interface (I / O interface, Input / Output interface), a universal serial bus (USB, Universal Serial Bus) port (which may be included as one of the ports of the BUS bus), a network interface, a power supply and / or a camera. Those skilled in the art can understand that Figure 1 The structure shown is only for illustration and does not limit the structure of the above electronic device. Figure 1 More or fewer components as shown, or with Figure 1 Different configurations are shown.
[0031] It should be noted that the one or more processors 102 and / or other data processing circuits described above may generally be referred to herein as "data processing circuits". The data processing circuits may be embodied in whole or in part as software, hardware, firmware, or any other combination thereof. In addition, the data processing circuit may be a single independent processing module, or may be incorporated in whole or in part into any of the other components in the computer terminal 10 (or mobile device). As involved in the embodiments of the present application, the data processing circuit acts as a processor control (e.g., selection of a variable resistor terminal path connected to an interface).
[0032] The memory 104 can be used to store software programs and modules of application software, such as the program instructions / data storage device corresponding to the text classification method in the embodiment of the present application. The processor 102 executes various functional applications and data processing by running the software programs and modules stored in the memory 104, that is, to implement the above-mentioned text classification method. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to the computer terminal 10 via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0033] The transmission device 106 is used to receive or send data via a network. The specific example of the above network may include a wireless network provided by a communication provider of the computer terminal 10. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0034] The display may be, for example, a touch screen liquid crystal display (LCD), which may enable a user to interact with a user interface of the computer terminal 10 (or mobile device).
[0035] Under the above operating environment, this application provides Figure 2 The text classification method shown. Figure 2 It is a flowchart of a text classification method provided according to an embodiment of the present application.
[0036] Step S201, obtaining an original data set and an unlabeled data set from a data source of text data;
[0037] Specifically, the data source of text data refers to the source containing text data, which can include real-time updated network data sources, online databases that provide structured or semi-structured text, and local databases that store local text. The original data set refers to the data set of labeled samples, and the original data set refers to the labeled sample data set, in which each piece of data contains text content and its corresponding label.
[0038] Unlabeled datasets refer to datasets with only text and no labels, which can be obtained from the Internet, online databases, and local databases.
[0039] The purpose of obtaining the original dataset and the unlabeled dataset is to provide a sample basis for subsequent training and pseudo-label generation.
[0040] Step S202, performing exploratory data analysis on the original data set, and preprocessing the original data set based on the analysis result to obtain a first data set, and recalling pseudo labels for unlabeled samples in the unlabeled data set to obtain a second data set.
[0041] Specifically, Exploratory Data Analysis (EDA) analyzes the data's label distribution, sample length and other characteristics to check whether there are anomalies in the data. For example, it analyzes whether the label classification distribution is balanced, whether the sample is too long or too short, etc. Through EDA, basic statistical information of the data can be obtained, and parts that need to be cleaned and processed can be identified. Cleaning methods include removing inappropriate samples, such as samples with abnormal lengths, and finally processing the original data based on the EDA results to obtain the first data set.
[0042] In the unlabeled dataset, by calculating the Term Frequency-Inverse Document Frequency (TF-IDF) between the unlabeled sample and each labeled sample in the first dataset, the similarity is compared, and the pseudo-label is recalled for the unlabeled sample based on the label of the labeled sample with the highest similarity. These pseudo-labels can be completed by recalling the pseudo-labels with the most similar labeled samples. The generated pseudo-labeled dataset is the second dataset, which provides more samples for subsequent training. Among them, recalling pseudo-labels means copying the labels of labeled samples to unlabeled samples.
[0043] Step S203, merging the first data set and the second data set to obtain an initial training data set, performing exploratory data analysis on the initial training data set, and preprocessing the initial training data set based on the analysis result to obtain a training data set.
[0044] Specifically, the initial training data set is obtained by merging the cleaned first data set and the second data set to obtain a larger data set, in order to increase the number of training samples and enable the model to learn more sample distribution characteristics.
[0045] Re-performing exploratory data analysis can ensure the quality of the merged data. For example, analyzing whether the label classification distribution is balanced, whether the sample is too long or too short, etc. Preprocessing is to further clean up the abnormal data in the initial training data set based on the new analysis results, and finally obtain the training data set.
[0046] The role of the training data set is to provide a set of samples with complete labels, provide data support for subsequent vectorization and classification, and ensure that the sample coverage is wide enough.
[0047] Step S204: input each training sample in the training data set into a pre-trained encoder to generate a pre-trained vector representation, and input each training sample in the training data set into a knowledge graph encoder to generate a knowledge graph vector representation.
[0048] Specifically, inputting a pre-trained encoder means inputting each sample in the training dataset into a pre-trained encoder (such as the ROBERT model). The pre-trained encoder converts the text into a vector representation, that is, the text content is converted into semantic vectors through a deep learning model. These vectors capture the semantic information of the text.
[0049] Inputting the knowledge graph encoder means inputting the text samples in the training data into the knowledge graph encoder, which extracts entities in the text based on entity recognition technology and maps the entity information into vector representation. The knowledge graph encoder uses the external knowledge graph to enhance the semantic information in the text, especially the entity information contained in the text.
[0050] Step 205, fuse the pre-trained vector representation and the knowledge graph vector representation to generate a fused vector representation, and send the fused vector representation to the classifier to obtain a classification result.
[0051] Specifically, the gating mechanism is used to fuse the vector representation generated by the pre-trained encoder and the vector representation generated by the knowledge graph encoder, combining the global semantic information of the text and the semantic information of the specific entity to generate a more complete text representation, that is, the fused vector representation. The fused vector representation is denoted as .
[0052] The fusion vector is represented as Input into the classifier to obtain the final classification result. The classifier can predict the category of the text based on the fusion vector.
[0053] Will Enter the first fully connected layer. The number of neurons in this fully connected layer is a hyperparameter and can be set to 360, that is,
[0054]
[0055] in, Indicates the label corresponding to a sample. and are the learning parameters, is the fused vector representation, and ReLU is the nonlinear activation function.
[0056] The output of the first layer is fed into the second fully connected layer, where the number of neurons is the number of predefined labels c, that is:
[0057]
[0058]
[0059] in, and is the learning parameter, z is the output vector of the second fully connected layer, refers to the output of the rth neuron in the last layer, is the final classification probability distribution, which indicates the probability that the input sample belongs to each category. is used to Convert to positive values to make the probability distribution smoother, and we get After that, further calculation is performed to obtain the classification results .
[0060] In an embodiment of the present application, an original data set and an unlabeled data set are obtained from a data source of text data; an exploratory data analysis is performed on the original data set, and the original data set is preprocessed based on the analysis results to obtain a first data set, and pseudo labels are recalled for unlabeled samples in the unlabeled data set to obtain a second data set; the first data set and the second data set are merged to obtain an initial training data set, an exploratory data analysis is performed on the initial training data set, and the initial training data set is preprocessed based on the analysis results to obtain a training data set; each training sample in the training data set is input into a pretrained encoder to generate a pretrained vector representation, and each training sample in the training data set is input into a knowledge graph encoder to generate a knowledge graph vector representation; for each training sample, the pretrained vector representation and the knowledge graph vector representation are fused to generate a fused vector representation, and the fused vector representation is sent to a classifier to obtain a classification result. By performing exploratory analysis and preprocessing on the data to obtain the first data set, generating pseudo labels to obtain the second data set, merging the two and preprocessing them to obtain the training data set, extracting the global semantics and knowledge graph semantic information and fusing and classifying them, the technical effect of increasing the amount of training sample data and improving classification accuracy is achieved, thereby solving the problem of the small number of training data sets in related technologies and the low classification accuracy of samples in the data sets, which leads to poor model performance when the training data set is used to train the model.
[0061] In order to expand the scale of training data and provide a basis for subsequent pseudo-label generation, optionally, in the text classification method provided in the embodiment of the present application, the original data set and unlabeled data are obtained from the data source of the text data, including: determining the data source, wherein the data source includes at least a network, an online database, and a local database; obtaining labeled samples from the data source, and determining the original data set based on the obtained labeled samples, wherein the labeled samples include text content and labels corresponding to the text content; obtaining unlabeled samples from the data source, and determining the unlabeled data set based on the obtained unlabeled samples, wherein the unlabeled samples include text content.
[0062] Specifically, data sources refer to sources that contain text data, which can include real-time updated network data sources, online databases that provide structured or semi-structured text, and local databases that store local text. The purpose of determining data sources is to clarify the reliability and diversity of data sources and ensure the comprehensiveness and accuracy of the samples obtained.
[0063] When obtaining labeled samples, labeled samples refer to sample data containing text content and its corresponding classification labels. The purpose is to provide standardized and accurate training samples so that it can correctly learn classification features. When obtaining unlabeled samples, unlabeled samples refer to samples that only contain text content but no corresponding labels. The purpose of obtaining them is to annotate the samples through pseudo-label generation methods to obtain pseudo-label samples.
[0064] The embodiments of the present application achieve the effect of providing a suitable data set for subsequent data preprocessing, pseudo-label generation and model training by efficiently acquiring labeled samples and unlabeled samples from data sources of different sources.
[0065] In order to improve the balance and quality of the data set, optionally, in the text classification method provided in the embodiment of the present application, an exploratory data analysis is performed on the original data set, and the original data set is preprocessed based on the analysis results to obtain the first data set, including: determining the label category of the original label of the sample in the original data set, and the number of labels under each label category, and judging whether there is a label category with an unbalanced number of labels according to the label category and the number of labels under each label category, wherein the unbalanced number of labels refers to that the difference between the number of labels under at least one label category and the average number of labels of all label categories is greater than a preset number; in the case of the existence of category labels with an unbalanced number of labels, samples under the label category with an unbalanced number of labels are removed from the original data set to obtain an updated original data set; determining the length of the samples in the updated original data set, and judging whether there are samples with abnormal length, wherein the samples with abnormal length include samples with a length greater than a first preset length, samples with a length less than a second preset length, and samples with empty text content, and the first preset length is greater than the second preset length; in the case of the existence of samples with abnormal length, samples with abnormal length are removed from the updated original data set to obtain the first data set.
[0066] Specifically, the original dataset .in , Represents a sample and the label corresponding to the sample, respectively. Indicates the number of samples. By counting the distribution of labels, the number of samples in each category is calculated. ,in is the total number of categories; and based on the number distribution of label categories, it is determined whether there are category labels with unbalanced label numbers. Specifically, if the difference between the number of samples under a certain category label and the average number of samples of all categories is greater than the preset number, it is considered to be an unbalanced category.
[0067] For each sample in the updated original data set, determine whether there is an abnormal length sample based on the text length. Samples longer than the first preset length can be considered too long, and samples shorter than the second preset length can be considered too short. Samples with abnormal length (too long or too short) are removed from the updated original data set to obtain the first data set. .
[0068] The embodiment of the present application achieves the effect of eliminating the imbalance in data distribution and the influence of abnormal samples by performing label distribution statistics and text length checks on the original data set, thereby generating a data set with a more reasonable structure.
[0069] In order to expand the size of the data set and obtain pseudo-label samples through pseudo-label recall, optionally, in the text classification method provided in the embodiment of the present application, recalling pseudo-labels for unlabeled samples in the unlabeled data set to obtain the second data set includes: determining a threshold for judging whether to recall pseudo-labels for unlabeled samples; calculating the term frequency-inverse document frequency value of each sample in the unlabeled data set and each sample in the first data set to obtain M groups of term frequency-inverse document frequency values, wherein each group of term frequency-inverse document frequency values includes N term frequency-inverse document frequency values, M is the number of unlabeled samples in the unlabeled dataset, and N is the number of labeled samples in the first dataset, where M and N are positive integers; for each unlabeled sample in the unlabeled dataset, determine the maximum term frequency-inverse document frequency value from a corresponding set of term frequency-inverse document frequency values to obtain M first term frequency-inverse document frequency values; for each first term frequency-inverse document frequency value, when the first term frequency-inverse document frequency value is greater than a threshold, recall the label of the labeled sample corresponding to the first term frequency-inverse document frequency value to the unlabeled sample to obtain a pseudo-label sample, and when the first term frequency-inverse document frequency value is less than or equal to the threshold, discard the unlabeled sample corresponding to the first term frequency-inverse document frequency value; poll all unlabeled samples in the unlabeled dataset, and determine all pseudo-label samples as the second dataset.
[0070] Specifically, the unlabeled dataset .in represents a sample in an unlabeled dataset, Represents the number of samples in the unlabeled dataset.
[0071] right Each sample in , with the first data set Each sample Calculate the term frequency-inverse document frequency value (TF-IDF value). Take the largest value among the N values, that is, , and threshold If the maximum value is greater than the threshold , then Corresponding tags Recall to , generate pseudo-label samples; if the maximum value is less than or equal to the threshold , then discard the unlabeled sample. Among them, the term frequency-inverse document frequency value (TF-IDF value) is an indicator used to measure the similarity between samples.
[0072] Polling completed After all the unlabeled samples are collected, the second dataset is finally obtained. , which contains all pseudo-labeled samples.
[0073] In a low-resource scenario (referring to a small amount of training data), the embodiment of the present application uses a pseudo-label strategy to pseudo-label a large amount of unlabeled data, expand the amount of training sample data, and avoid the problem of overfitting or underfitting of the model trained by the training data set.
[0074] The embodiment of the present application calculates the similarity between unlabeled samples and labeled samples based on the word frequency-inverse document frequency value, and determines whether to generate a pseudo label according to a threshold, thereby effectively expanding the training data set and improving the coverage of model training.
[0075] In order to determine the threshold for judging whether to recall the pseudo-label for the unlabeled sample, optionally, in the text classification method provided in the embodiment of the present application, determining the threshold for judging whether to recall the pseudo-label for the unlabeled sample includes: traversing each sample in the first data set, calculating the term frequency-inverse document frequency values of the current sample and the samples in the first data set other than the current sample, and obtaining N groups of term frequency-inverse document frequency values, each group containing N-1 term frequency-inverse document frequency values; for each labeled sample in the first data set, determining the maximum term frequency-inverse document frequency value from the corresponding group of term frequency-inverse document frequency values, and obtaining N second term frequency-inverse document frequency values; sorting the N second term frequency-inverse document frequency values from large to small, and selecting the second term frequency-inverse document frequency value of a preset order as the threshold.
[0076] Specifically, Each sample in , calculate and select the sample with the largest TF-IDF value , that is, samples other than themselves, forming a triple . The values are sorted and the corresponding values are selected as thresholds according to the preset order (such as the top 10%). ,The purpose of selection is to ensure that the similarity between the recalled unlabeled samples and the labeled samples in the first dataset is higher than a certain level, thereby improving the reliability of the pseudo-labels.
[0077] The embodiment of the present application determines the threshold of pseudo-label recall based on the internal similarity calculation of the first data set, thereby achieving the effect of ensuring the accuracy of recalling pseudo-label samples while avoiding low-similarity samples from interfering with model training.
[0078] In order to optimize the quality of the initial training data set and solve the problems of unbalanced label quantity and abnormal sample length, optionally, in the text classification method provided in the embodiment of the present application, an exploratory data analysis is performed on the initial training data set, and the initial training data set is preprocessed based on the analysis results to obtain the training data set, including: determining the label category of the merged label of the sample in the initial training data set, and the number of labels under each label category, and judging whether there is a label category with an unbalanced label quantity according to the label category and the number of labels under each label category, wherein the unbalanced label quantity means that the difference between the number of labels under at least one label category and the average number of labels of all label categories is greater than a preset number; in the case of category labels with an unbalanced label quantity, samples under the label category with an unbalanced label quantity are removed from the initial training data set to obtain an updated initial training data set; determining the length of the samples in the updated initial training data set, and judging whether there are samples with abnormal length, wherein the samples with abnormal length include samples with a length greater than a third preset length, samples with a length less than a fourth preset length, and samples with empty text content, and the third preset length is greater than the fourth preset length; in the case of samples with abnormal length, samples with abnormal length are removed from the updated initial training data set to obtain the training data set.
[0079] Specifically, the training dataset , represents the number of samples, . Statistics of training data set The label distribution in gets the number of categories with the least number of .in, is the first data set, is the second data set, are the training samples and the labels corresponding to the training samples, is the sequence number of the training sample in the training data set.
[0080] The distribution of sample lengths in the statistical training data set D is calculated. Samples longer than the third preset length can be considered too long, and samples shorter than the fourth preset length and samples with empty text content can be considered too short. The overlong part is truncated to obtain the truncated length , and remove samples that are too short.
[0081] The embodiments of the present application achieve the effect of optimizing the distribution of training data and improving data quality by eliminating category samples with unbalanced number of labels, truncating overly long samples, and eliminating overly short samples.
[0082] In order to convert the training sample text into a semantic vector representation that can be understood by the model, optionally, in the text classification method provided in the embodiment of the present application, each training sample in the training data set is input into a pre-trained encoder, and generating a pre-trained vector representation includes: segmenting the training sample through a word segmenter, and generating a first word unit sequence according to the word segmentation result; truncating or padding the first word unit sequence according to the maximum input length of the pre-trained encoder to generate a second word unit sequence, wherein the word units in the word unit sequence whose length exceeds the maximum input length are truncated, and the word units whose length is less than the maximum input length are padded with a first preset value; matching each word unit in the second word unit sequence with a term in the vocabulary, and mapping the successfully matched word units to the corresponding vocabulary index to generate an input identification sequence; generating an attention mask according to the positions of the actual word units and the filling word units in the second word unit sequence, wherein the actual word unit position is represented by the second preset value, and the filling word unit position is represented by the first preset value; inputting the input identification sequence and the attention mask into the pre-trained encoder, extracting the value of the classification word unit position of the last layer of the pre-trained encoder, and obtaining the pre-trained vector representation.
[0083] Specifically, the training samples The Tokenizer is used to convert the input of the pre-trained encoder (Robert). The Tokenizer first uses the word-level segmentation strategy to Split to get tokens, token sequence ,in Refers to the number of tokens after segmentation.
[0084] For the word segmentation results, according to the maximum input length (512) of the pre-trained encoder (Robert), the word sequence is Do truncation or padding. The uniform length is , where the training sample length If the number of word units exceeds the maximum input length, the word unit is truncated to the length L, and the excess part is directly truncated; for training samples whose word unit number is less than the maximum input length, the word unit is padded to the first preset value, which can be the number 0.
[0085] Then the Tokenizer will map the processed sample sequence to the numbers in the vocabulary and output the input identifier sequence (input_ids) and attention mask (attention_mask). Input input_ids and attention_mask are input into the Robert model, and the value of the last layer of the model classification word (CLS, Classification) is taken, which is the Robert vector encoding of the sample. .
[0086]
[0087] The input identification sequence is a sequence of digital indexes after each word in the word sequence is mapped through the vocabulary, which is used to represent the numerical input of the training sample; the attention mask is used to identify the positions of the actual word and the filler word in the input sequence. The position of the actual word is represented by the second preset value (such as the query representation of the actual word on the knowledge graph), and the position of the filler word is represented by the first preset value (such as 0). The attention mask helps the model distinguish between valid data and filler data when processing input.
[0088] The embodiment of the present application extracts deep semantic features through a pre-trained encoder, thereby generating high-quality vector representations for subsequent classification tasks, thereby improving the learning effect of the model.
[0089] In order to extract entity semantic information in training samples and generate a vector representation with knowledge enhancement characteristics, optionally, in the text classification method provided in the embodiment of the present application, each training sample in the training data set is input into the knowledge graph encoder, and generating the knowledge graph vector representation includes: performing entity recognition on the training samples through an entity recognition model to generate an entity word unit sequence, wherein the word units that are not recognized as entities are represented by a first preset value; replacing the entity word units in the entity word unit sequence with the query representation in the knowledge graph to obtain a sparse vector representation; and densifying the sparse vector representation to generate a knowledge graph vector representation of the training samples.
[0090] Specifically, the entity recognition model is a model used to identify entity tokens with clear meanings in text (such as names of people, places, organization names, etc.); the entity token sequence is a token sequence extracted from the training samples by the entity recognition model; the knowledge graph is a structured semantic network that stores a collection of entities and their relationships, and is used to represent the hierarchical relationships and associations between entities in the training samples; the query representation is a vectorized representation corresponding to a certain entity in the knowledge graph, which is used to replace the entity tokens in the entity token sequence.
[0091] Figure 3 is a flowchart based on knowledge graph encoding provided according to an embodiment of the present application, such as Figure 3 As shown: For the sample Use the entity recognition (BERT+CRF) model to identify entities in the sample sequence. Similarly, use Tokenizer to Token splitting is performed ,in Refers to the number of tokens after segmentation. Get input_ids and attention_mask and send them to the BERT model to get the hidden state of the last layer of BERT Fully connected to the predefined entity type (entity_number) neurons, and finally through a CRF layer to identify the entity in the sample. , where O means that the token is not recognized as an entity, , Respectively represent the two recognized entities.
[0092] The CRF layer (Conditional Random Field) is a model layer used for sequence labeling tasks. The CRF layer can be applied to tasks such as entity recognition and is used to globally optimize the output labeling sequence.
[0093] Query the representation of each entity on the knowledge graph. Convert to That is, the original position of O is replaced by the first preset value, which can be the number 0. The original position of the entity is replaced by the query representation of the entity on the knowledge graph. The sample is obtained. The sparse vector representation of the entity word sequence is represented by the first preset value, and the part recognized as the entity is replaced by the query representation in the knowledge graph to generate the vector form. The sparse representation retains the sparse distribution characteristics of the entities in the text.
[0094] The obtained sparse vector representation is first passed through a fully connected layer (Denselayer layer), and then through a bidirectional long short-term memory network layer (BiLSTM) layer to obtain a dense vector representation, so that the final vector representation contains both the semantic features of the entity and is suitable for the input requirements of the subsequent model, that is,
[0095]
[0096] The embodiment of the present application combines the entity information in the training samples with the semantic enhancement characteristics of the knowledge graph, thereby improving the model's understanding of the semantic associations between text entities and the classification accuracy.
[0097] In order to combine the pre-trained semantic information and the knowledge graph enhancement information to generate a vector representation of comprehensive semantic features, optionally, in the text classification method provided in the embodiment of the present application, for each training sample, the pre-trained vector representation and the knowledge graph vector representation are fused to generate a fused vector representation, including: for each training sample, the pre-trained vector representation and the knowledge graph vector representation are spliced to generate a spliced vector; the spliced vector is linearly transformed to obtain a linear transformation result, and the linear transformation result is input into the activation function to calculate a first dynamic weight, wherein the first dynamic weight is used to control the fusion ratio of the pre-trained vector representation and the knowledge graph vector representation; the first dynamic weight is subtracted from the total weight value to obtain a second dynamic weight, wherein the second dynamic weight is used to control the fusion ratio of the pre-trained vector representation and the knowledge graph vector representation; the pre-trained vector representation and the knowledge graph vector representation are weighted summed according to the first dynamic weight and the second dynamic weight to generate a fused vector representation.
[0098] Specifically, a gating mechanism is used to The two vector representations of are fused into the final vector representation. The gating mechanism is a mechanism that dynamically adjusts the weights of the input features and optimizes the fusion effect of the two vectors by learning trainable parameters.
[0099] Assume that the pre-trained vector is represented as , the knowledge graph vector is represented as , concatenating these two vectors into , and then calculate the dynamic weights through linear transformation and activation function :
[0100]
[0101] in is a learnable parameter, Can be a Sigmoid activation function. Dynamic weights Represents the proportion of the pre-trained vector in the final fusion vector. Next, the two vectors are fused using the weighted summation formula:
[0102]
[0103] It is the fused semantic vector representation, that is, the fused vector representation.
[0104] The embodiment of the present application combines global semantics and local entity information to improve text classification accuracy and model generalization ability by weighted fusion of pre-trained vector representation and knowledge graph vector representation; it can also be expressed as the use of a dual-tower encoding strategy, which makes the input samples semantically richer through the dual representation of the pre-trained model and the knowledge graph, shortens the distribution of training data and test data, and alleviates the challenge of poor model generalization ability.
[0105] If a single bidirectional encoder representation conversion encoding (BERT, Bidirectional Encoder Representations from Transformers) is used, there may be a semantic gap between the training data and the test data. However, by introducing the knowledge graph, this gap can be shortened at the semantic level. For example, some entities are interrelated in the knowledge graph, and these relationships will have mutual influence in the embedding representation, thereby enhancing the consistency of semantics.
[0106] Optionally, in the optional text classification method provided in the embodiment of the present application, Figure 4 This is the process of the optional text classification method provided in the embodiment of the present application Figure 1 ;like Figure 4 As shown, the process of the text classification method can be:
[0107] S1, perform exploratory data analysis on the original data set, count the label distribution and remove abnormal samples. Generate pseudo labels for the unlabeled data set, and construct a new training data set by combining the original data set and the pseudo-label data set.
[0108] S2, use the pre-trained model to encode the semantic vector of the training data to generate global semantic features. Use the knowledge graph encoder to vectorize the entities in the training data to generate local semantic features. For each training sample, the pre-trained vector representation and the knowledge graph vector representation are weighted and summed through a fusion mechanism to generate a fused vector representation.
[0109] S3, inputs the fusion vector representation into the classification layer, classifies the training samples, and outputs the classification results.
[0110] The embodiments of the present application optimize and expand the data set through exploratory data analysis and pseudo-label recall, improve feature quality by combining pre-trained semantic representation and knowledge graph representation, and use the classification layer to complete efficient text classification.
[0111] It should be noted that the steps shown in the flowcharts of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and that, although a logical order is shown in the flowcharts, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0112] Example 2
[0113] The present application also provides a text classification device. It should be noted that the text classification device of the present application can be used to execute the text classification method provided in the present application. The text classification device provided in the present application is introduced below.
[0114] According to an embodiment of the present application, a device for implementing the above-mentioned text classification method is also provided. Figure 5 is a schematic diagram of a text classification device provided according to an embodiment of the present application, such as Figure 5 As shown, the device comprises:
[0115] The data set acquisition module 501 is used to acquire the original data set and the unlabeled data set from the data source of the text data.
[0116] The data set processing module 502 is used to perform exploratory data analysis on the original data set, and preprocess the original data set based on the analysis results to obtain a first data set, and recall pseudo labels for unlabeled samples in the unlabeled data set to obtain a second data set.
[0117] The data set merging and processing module 503 is used to merge the first data set and the second data set to obtain an initial training data set, perform exploratory data analysis on the initial training data set, and preprocess the initial training data set based on the analysis result to obtain a training data set.
[0118] The vector conversion module 504 is used to input each training sample in the training data set into the pre-training encoder to generate a pre-training vector representation, and input each training sample in the training data set into the knowledge graph encoder to generate a knowledge graph vector representation.
[0119] The vector fusion and classification module 505 is used to fuse the pre-trained vector representation and the knowledge graph vector representation for each training sample, generate a fused vector representation, and send the fused vector representation to the classifier to obtain a classification result.
[0120] In an embodiment of the present application, a data set acquisition module 501 acquires an original data set and an unlabeled data set from a data source of text data; a data set processing module 502 performs exploratory data analysis on the original data set, and preprocesses the original data set based on the analysis results to obtain a first data set, and recalls pseudo labels for unlabeled samples in the unlabeled data set to obtain a second data set; a data set merging and processing module 503 merges the first data set and the second data set to obtain an initial training data set, performs exploratory data analysis on the initial training data set, and preprocesses the initial training data set based on the analysis results to obtain a training data set; a vector conversion module 504 inputs each training sample in the training data set into a pre-trained encoder to generate a pre-trained vector representation, and inputs each training sample in the training data set into a knowledge graph encoder to generate a knowledge graph vector representation; a vector fusion and classification module 505 fuses the pre-trained vector representation and the knowledge graph vector representation for each training sample to generate a fused vector representation, and sends the fused vector representation to a classifier to obtain a classification result. By performing exploratory analysis and preprocessing on the data to obtain the first data set, generating pseudo labels to obtain the second data set, merging the two and preprocessing them to obtain the training data set, extracting the global semantics and knowledge graph semantic information and fusing and classifying them, the technical effect of increasing the amount of training sample data and improving classification accuracy is achieved, thereby solving the problem of the small number of training data sets in related technologies and the low classification accuracy of samples in the data sets, which leads to poor model performance when the training data set is used to train the model.
[0121] Optionally, in the text classification device provided in the embodiment of the present application, the data set acquisition module 501 includes: a data source determination module, used to determine the data source, wherein the data source includes at least a network, an online database and a local database; an original data set determination module, used to obtain labeled samples from the data source, and determine the original data set according to the obtained labeled samples, wherein the labeled samples include text content and labels corresponding to the text content; an unlabeled data set determination module, used to obtain unlabeled samples from the data source, and determine the unlabeled data set according to the obtained unlabeled samples, wherein the unlabeled samples include text content.
[0122] Optionally, in the text classification device provided in the embodiment of the present application, the data set processing module 502 includes: a label category determination module, which is used to determine the label category of the original label of the sample in the original data set, and the number of labels under each label category, and determine whether there is a label category with an unbalanced label quantity according to the label category and the number of labels under each label category, wherein the unbalanced label quantity refers to that the difference between the number of labels under at least one label category and the average number of labels of all label categories is greater than a preset number; an original data set updating module, which is used to remove samples under the label category with an unbalanced label quantity from the original data set in the case where there are category labels with an unbalanced label quantity, so as to obtain an updated original data set; a length judgment module, which is used to determine the length of the sample in the updated original data set, and determine whether there is a sample with an abnormal length, wherein the sample with an abnormal length includes a sample with a length greater than a first preset length, a sample with a length less than a second preset length, and a sample with empty text content, and the first preset length is greater than the second preset length; a length abnormal removal module, which is used to remove the sample with an abnormal length from the updated original data set in the case where there are samples with an abnormal length, so as to obtain a first data set.
[0123] Optionally, in the text classification device provided in the embodiment of the present application, the data set processing module 502 includes: a threshold determination module, which is used to determine a threshold for judging whether to recall pseudo labels for unlabeled samples; a term frequency-inverse document frequency value calculation module, which is used to calculate the term frequency-inverse document frequency value of each sample in the unlabeled data set and each sample in the first data set, and obtain M groups of term frequency-inverse document frequency values, wherein each group of term frequency-inverse document frequency values includes N term frequency-inverse document frequency values, M is the number of unlabeled samples in the unlabeled data set, and N is the number of labeled samples in the first data set; the first term frequency-inverse document frequency value determination module is used to calculate the term frequency-inverse document frequency value of each sample in the unlabeled data set and each sample in the first data set, and obtain M groups of term frequency-inverse document frequency values, wherein each group of term frequency-inverse document frequency values includes N term frequency-inverse document frequency values, M is the number of unlabeled samples in the unlabeled data set, and N is the number of labeled samples in the first data set; unlabeled samples, determine the maximum word frequency-inverse document frequency value from a corresponding set of word frequency-inverse document frequency values, and obtain M first word frequency-inverse document frequency values; a pseudo-label sample determination module is used for, for each first word frequency-inverse document frequency value, when the first word frequency-inverse document frequency value is greater than a threshold, recalling the label of the labeled sample corresponding to the first word frequency-inverse document frequency value to the unlabeled sample to obtain a pseudo-label sample, and when the first word frequency-inverse document frequency value is less than or equal to the threshold, discarding the unlabeled sample corresponding to the first word frequency-inverse document frequency value; a polling module is used to poll all unlabeled samples in the unlabeled data set, and determine all pseudo-label samples as the second data set.
[0124] Optionally, in the text classification device provided in the embodiment of the present application, the threshold determination module includes: a first data set traversal module, used to traverse each sample in the first data set, calculate the term frequency-inverse document frequency values of the current sample and the samples in the first data set other than the current sample, and obtain N groups of term frequency-inverse document frequency values, each group containing N-1 term frequency-inverse document frequency values; a second term frequency-inverse document frequency value determination module, used to determine the maximum term frequency-inverse document frequency value from a corresponding group of term frequency-inverse document frequency values for each labeled sample in the first data set, and obtain N second term frequency-inverse document frequency values; a threshold determination submodule, used to sort the N second term frequency-inverse document frequency values from large to small, and select the second term frequency-inverse document frequency value of a preset order as the threshold.
[0125] Optionally, in the text classification device provided in the embodiment of the present application, the data set merging and processing module 503 includes: a balance judgment module, which is used to determine the label category of the merged label of the sample in the initial training data set, and the number of labels under each label category, and judge whether there is a label category with an unbalanced label quantity according to the label category and the number of labels under each label category, wherein the unbalanced label quantity refers to that the difference between the number of labels under at least one label category and the average number of labels of all label categories is greater than a preset number; an initial training data set updating module, which is used to remove samples under the label category with an unbalanced label quantity from the initial training data set in the case where there are category labels with an unbalanced label quantity, so as to obtain an updated initial training data set; a length abnormality judgment module, which is used to determine the length of the sample in the updated initial training data set, and judge whether there is a sample with an abnormal length, wherein the sample with an abnormal length includes a sample with a length greater than a third preset length, a sample with a length less than a fourth preset length, and a sample with empty text content, and the third preset length is greater than the fourth preset length; a training data set determination module, which is used to remove the sample with an abnormal length from the updated initial training data set in the case where there are samples with an abnormal length, so as to obtain a training data set.
[0126] Optionally, in the text classification device provided in the embodiment of the present application, the vector conversion module 504 includes: a first word-unit sequence generation module, which is used to segment the training sample through a word segmenter and generate a first word-unit sequence according to the word segmentation result; a second word-unit sequence generation module, which is used to truncate or fill the first word-unit sequence according to the maximum input length of the pre-trained encoder to generate a second word-unit sequence, wherein the word segments in the word-unit sequence whose length exceeds the maximum input length are truncated, and the word segments whose length is less than the maximum input length are filled with a first preset value; an input identification sequence generation module, which Each word in the second word-gram sequence is matched with an item in the vocabulary, and the successfully matched word-gram is mapped to a corresponding vocabulary index to generate an input identification sequence; an attention mask generation module is used to generate an attention mask according to the positions of actual word-grams and filler word-grams in the second word-gram sequence, wherein the actual word-gram position is represented by a second preset value and the filler word-gram position is represented by a first preset value; a pre-trained vector representation determination module is used to input the input identification sequence and the attention mask into a pre-trained encoder, extract the value of the classification word-gram position of the last layer of the pre-trained encoder, and obtain a pre-trained vector representation.
[0127] Optionally, in the text classification device provided in the embodiment of the present application, the vector conversion module 504 includes: an entity word unit sequence generation module, which is used to perform entity recognition on the training sample through the entity recognition model to generate an entity word unit sequence, wherein the word unit that is not recognized as an entity is represented by a first preset value; a sparse vector representation determination module, which is used to replace the entity word units in the entity word unit sequence with the query representation in the knowledge graph to obtain a sparse vector representation; a knowledge graph vector representation determination module, which is used to densify the sparse vector representation to generate a knowledge graph vector representation of the training sample.
[0128] Optionally, in the text classification device provided in the embodiment of the present application, the vector fusion and classification module 505 includes: a splicing vector generation module, which is used to splice the pre-trained vector representation and the knowledge graph vector representation for each training sample to generate a splicing vector; a first dynamic weight calculation module, which is used to perform a linear transformation on the splicing vector to obtain a linear transformation result, and input the linear transformation result into an activation function to calculate a first dynamic weight, wherein the first dynamic weight is used to control the fusion ratio of the pre-trained vector representation and the knowledge graph vector representation; a second dynamic weight calculation module, which is used to subtract the first dynamic weight from the total weight value to obtain a second dynamic weight, wherein the second dynamic weight is used to control the fusion ratio of the pre-trained vector representation and the knowledge graph vector representation; a fusion vector representation generation module, which is used to perform weighted summation of the pre-trained vector representation and the knowledge graph vector representation according to the first dynamic weight and the second dynamic weight to generate a fusion vector representation.
[0129] It should be noted that the above modules correspond to steps S201 to S205 in Example 1, and the examples and application scenarios implemented by the modules and corresponding steps are the same, but are not limited to the contents disclosed in the above Example 1. It should be noted that the above modules or units may be hardware components or software components stored in a memory (e.g., memory 104) and processed by one or more processors (e.g., processors 102a, 102b, ..., 102n), and the above modules may also be part of the device and may be run in the computer terminal 10 provided in Example 1.
[0130] Example 3
[0131] An embodiment of the present application may provide an electronic device, Figure 6 is a structural block diagram of an electronic device according to an embodiment of the present application. Figure 6 As shown, the electronic device may include: one or more ( Figure 6 Only one is shown) processor 602, memory 604, storage controller, and peripheral interface, wherein the peripheral interface is connected to the radio frequency module, audio module and display.
[0132] Among them, the memory can be used to store software programs and modules, such as program instructions / modules corresponding to the methods and devices in the embodiments of the present application, and the processor executes various functional applications and data processing by running the software programs and modules stored in the memory, that is, realizing the above-mentioned method. The memory may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory may further include a memory remotely arranged relative to the processor, and these remote memories may be connected to the terminal via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0133] The processor can call the information and application programs stored in the memory through the transmission device to perform the following steps: obtain an original data set and an unlabeled data set from a data source of text data; perform exploratory data analysis on the original data set, and preprocess the original data set based on the analysis results to obtain a first data set, and recall pseudo labels for unlabeled samples in the unlabeled data set to obtain a second data set; merge the first data set and the second data set to obtain an initial training data set, perform exploratory data analysis on the initial training data set, and preprocess the initial training data set based on the analysis results to obtain a training data set; input each training sample in the training data set into a pre-trained encoder to generate a pre-trained vector representation, and input each training sample in the training data set into a knowledge graph encoder to generate a knowledge graph vector representation; for each training sample, fuse the pre-trained vector representation and the knowledge graph vector representation to generate a fused vector representation, and send the fused vector representation to a classifier to obtain a classification result.
[0134] The processor can also call the information and application programs stored in the memory through the transmission device to perform the following steps: obtaining the original data set and unlabeled data from the data source of the text data, including: determining the data source, wherein the data source includes at least a network, an online database, and a local database; obtaining labeled samples from the data source, and determining the original data set based on the obtained labeled samples, wherein the labeled samples include text content and labels corresponding to the text content; obtaining unlabeled samples from the data source, and determining the unlabeled data set based on the obtained unlabeled samples, wherein the unlabeled samples include text content.
[0135] The processor can also call the information and application stored in the memory through the transmission device to perform the following steps: perform exploratory data analysis on the original data set, and preprocess the original data set based on the analysis results to obtain the first data set, including: determining the label category of the original label of the sample in the original data set, and the number of labels under each label category, and judging whether there is a label category with an unbalanced label quantity according to the label category and the number of labels under each label category, wherein the unbalanced label quantity means that the difference between the number of labels under at least one label category and the average number of labels of all label categories is greater than a preset number; in the case of category labels with an unbalanced label quantity, remove the samples under the label category with an unbalanced label quantity from the original data set to obtain an updated original data set; determine the length of the samples in the updated original data set, and judge whether there are samples with abnormal length, wherein the samples with abnormal length include samples greater than a first preset length, samples less than a second preset length, and samples with empty text content, and the first preset length is greater than the second preset length; in the case of samples with abnormal length, remove the samples with abnormal length from the updated original data set to obtain the first data set.
[0136] The processor can also call the information and application program stored in the memory through the transmission device to perform the following steps: recalling pseudo labels for unlabeled samples in the unlabeled data set to obtain the second data set includes: determining a threshold for judging whether to recall pseudo labels for unlabeled samples; calculating the word frequency-inverse document frequency value of each sample in the unlabeled data set and each sample in the first data set to obtain M groups of word frequency-inverse document frequency values, wherein each group of word frequency-inverse document frequency values includes N word frequency-inverse document frequency values, M is the number of unlabeled samples in the unlabeled dataset, and N is the number of labeled samples in the first dataset; for each unlabeled sample in the unlabeled dataset, determine the maximum term frequency-inverse document frequency value from a corresponding set of term frequency-inverse document frequency values to obtain M first term frequency-inverse document frequency values; for each first term frequency-inverse document frequency value, when the first term frequency-inverse document frequency value is greater than a threshold, recall the label of the labeled sample corresponding to the first term frequency-inverse document frequency value to the unlabeled sample to obtain a pseudo-label sample, and when the first term frequency-inverse document frequency value is less than or equal to the threshold, discard the unlabeled sample corresponding to the first term frequency-inverse document frequency value; poll all unlabeled samples in the unlabeled dataset, and determine all pseudo-label samples as the second dataset.
[0137] The processor can also call the information and application stored in the memory through the transmission device to perform the following steps: determining the threshold for judging whether to recall the pseudo-label for the unlabeled sample includes: traversing each sample in the first data set, calculating the term frequency-inverse document frequency value of the current sample and the samples in the first data set other than the current sample, and obtaining N groups of term frequency-inverse document frequency values, each group containing N-1 term frequency-inverse document frequency values; for each labeled sample in the first data set, determining the maximum term frequency-inverse document frequency value from the corresponding group of term frequency-inverse document frequency values, and obtaining N second term frequency-inverse document frequency values; sorting the N second term frequency-inverse document frequency values from large to small, and selecting the second term frequency-inverse document frequency value of the preset order as the threshold.
[0138] The processor can also call the information and application stored in the memory through the transmission device to perform the following steps: perform exploratory data analysis on the initial training data set, and pre-process the initial training data set based on the analysis results to obtain the training data set, including: determining the label category of the merged label of the samples in the initial training data set, and the number of labels under each label category, and judging whether there is a label category with an unbalanced label quantity according to the label category and the number of labels under each label category, wherein the unbalanced label quantity means that the difference between the number of labels under at least one label category and the average number of labels of all label categories is greater than a preset number; in the case of category labels with an unbalanced label quantity, remove samples under the label category with an unbalanced label quantity from the initial training data set to obtain an updated initial training data set; determine the length of the samples in the updated initial training data set, and judge whether there are samples with abnormal length, wherein the samples with abnormal length include samples greater than a third preset length, samples less than a fourth preset length, and samples with empty text content, and the third preset length is greater than the fourth preset length; in the case of samples with abnormal length, remove the samples with abnormal length from the updated initial training data set to obtain the training data set.
[0139] The processor can also call the information and application stored in the memory through the transmission device to perform the following steps: input each training sample in the training data set into the pre-trained encoder, and generate a pre-trained vector representation, including: segmenting the training sample through a word segmenter, and generating a first word unit sequence according to the word segmentation result; truncating or padding the first word unit sequence according to the maximum input length of the pre-trained encoder to generate a second word unit sequence, wherein the word units in the word unit sequence whose length exceeds the maximum input length are truncated, and the word units whose length is less than the maximum input length are padded with a first preset value; matching each word unit in the second word unit sequence with a term in the vocabulary, and mapping the successfully matched word units to the corresponding vocabulary index to generate an input identification sequence; generating an attention mask according to the positions of the actual word units and the filling word units in the second word unit sequence, wherein the actual word unit position is represented by the second preset value, and the filling word unit position is represented by the first preset value; inputting the input identification sequence and the attention mask into the pre-trained encoder, extracting the value of the classification word unit position of the last layer of the pre-trained encoder, and obtaining the pre-trained vector representation.
[0140] The processor can also call the information and application programs stored in the memory through the transmission device to perform the following steps: input each training sample in the training data set into the knowledge graph encoder to generate a knowledge graph vector representation, including: performing entity recognition on the training samples through the entity recognition model to generate an entity word unit sequence, wherein the word units that are not recognized as entities are represented by a first preset value; replacing the entity word units in the entity word unit sequence with the query representation in the knowledge graph to obtain a sparse vector representation; and densifying the sparse vector representation to generate a knowledge graph vector representation of the training samples.
[0141] The processor can also call the information and application stored in the memory through the transmission device to perform the following steps: for each training sample, the pre-trained vector representation and the knowledge graph vector representation are fused to generate a fused vector representation, including: for each training sample, the pre-trained vector representation and the knowledge graph vector representation are spliced to generate a spliced vector; the spliced vector is linearly transformed to obtain a linear transformation result, and the linear transformation result is input into the activation function to calculate a first dynamic weight, wherein the first dynamic weight is used to control the fusion ratio of the pre-trained vector representation and the knowledge graph vector representation; the first dynamic weight is subtracted from the total weight value to obtain a second dynamic weight, wherein the second dynamic weight is used to control the fusion ratio of the pre-trained vector representation and the knowledge graph vector representation; the pre-trained vector representation and the knowledge graph vector representation are weighted summed according to the first dynamic weight and the second dynamic weight to generate a fused vector representation.
[0142] In an embodiment of the present application, an original data set and an unlabeled data set are obtained from a data source of text data; an exploratory data analysis is performed on the original data set, and the original data set is preprocessed based on the analysis results to obtain a first data set, and pseudo labels are recalled for unlabeled samples in the unlabeled data set to obtain a second data set; the first data set and the second data set are merged to obtain an initial training data set, an exploratory data analysis is performed on the initial training data set, and the initial training data set is preprocessed based on the analysis results to obtain a training data set; each training sample in the training data set is input into a pretrained encoder to generate a pretrained vector representation, and each training sample in the training data set is input into a knowledge graph encoder to generate a knowledge graph vector representation; for each training sample, the pretrained vector representation and the knowledge graph vector representation are fused to generate a fused vector representation, and the fused vector representation is sent to a classifier to obtain a classification result. By performing exploratory analysis and preprocessing on the data to obtain the first data set, generating pseudo labels to obtain the second data set, merging the two and preprocessing them to obtain the training data set, extracting the global semantics and knowledge graph semantic information and fusing and classifying them, the technical effect of increasing the amount of training sample data and improving classification accuracy is achieved, thereby solving the problem of the small number of training data sets in related technologies and the low classification accuracy of samples in the data sets, which leads to poor model performance when the training data set is used to train the model.
[0143] It can be understood by those skilled in the art that Figure 6 The structure shown is for illustration only, and the electronic device may also be a terminal device such as a smart phone, a tablet computer, a PDA, and a mobile Internet device (MID). Figure 6 The structure of the electronic device is not limited. Figure 6 More or fewer components (such as network interfaces, display devices, etc.) shown in, or with Figure 6 Different configurations are shown.
[0144] A person of ordinary skill in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing the hardware related to the terminal device through a program, and the program can be stored in a computer-readable storage medium, and the storage medium may include: a flash drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.
[0145] Example 4
[0146] The embodiment of the present application further provides a storage medium. Optionally, in this embodiment, the storage medium can be used to store the program code executed by the text classification method provided in the first embodiment.
[0147] Optionally, in this embodiment, the above storage medium may be located in any computer terminal in a computer terminal group in a computer network, or in any mobile terminal in a mobile terminal group.
[0148] The present application also provides a computer program product, which, when executed on a data processing device, is suitable for executing the steps of the text classification method.
[0149] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.
[0150] In the above embodiments of the present application, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.
[0151] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.
[0152] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0153] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0154] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, server or network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, disk or optical disk, etc., which can store program code.
[0155] The above is only a preferred implementation of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.
Claims
1. A text classification method, characterized in that: The following steps are involved: Obtain original data sets and unlabeled data sets from data sources of text data; Performing exploratory data analysis on the original data set, and preprocessing the original data set based on the analysis result to obtain a first data set, and recalling pseudo labels for unlabeled samples in the unlabeled data set to obtain a second data set; Merging the first data set and the second data set to obtain an initial training data set, performing the exploratory data analysis on the initial training data set, and preprocessing the initial training data set based on the analysis result to obtain a training data set; Input each training sample in the training data set into a pre-training encoder to generate a pre-training vector representation, and input each training sample in the training data set into a knowledge graph encoder to generate a knowledge graph vector representation; For each training sample, the pre-trained vector representation and the knowledge graph vector representation are fused to generate a fused vector representation, and the fused vector representation is sent to a classifier to obtain a classification result.
2. The text classification method according to claim 1, characterized in that: Obtain raw data sets and unlabeled data from data sources of text data, including: Determine the data source, wherein the data source includes at least a network, an online database and a local database; Acquire labeled samples from the data source, and determine the original data set according to the acquired labeled samples, wherein the labeled samples include text content and labels corresponding to the text content; An unlabeled sample is obtained from the data source, and the unlabeled data set is determined according to the obtained unlabeled sample, wherein the unlabeled sample includes text content.
3. The text classification method according to claim 1, characterized in that: Performing exploratory data analysis on the original data set, and preprocessing the original data set based on the analysis result, to obtain a first data set including: Determine the label categories of the original labels of the samples in the original data set, and the number of labels under each label category, and determine whether there is a label category with an unbalanced number of labels according to the label categories and the number of labels under each label category, wherein the unbalanced number of labels refers to that the difference between the number of labels under at least one label category and the average number of labels under all label categories is greater than a preset number; In the case where there are category labels with an unbalanced number of labels, samples under the label category with the unbalanced number of labels are removed from the original data set to obtain an updated original data set; Determine the length of samples in the updated original data set, and judge whether there are samples with abnormal lengths, wherein the samples with abnormal lengths include samples with a length greater than a first preset length, samples with a length less than a second preset length, and samples with empty text content, and the first preset length is greater than the second preset length; In the case where the samples with abnormal length exist, the samples with abnormal length are removed from the updated original data set to obtain the first data set.
4. The text classification method according to claim 1, characterized in that: Recalling pseudo labels for the unlabeled samples in the unlabeled data set to obtain a second data set includes: Determining a threshold for determining whether to recall a pseudo-label for the unlabeled sample; Calculate the term frequency-inverse document frequency value of each sample in the unlabeled data set and each sample in the first data set to obtain M groups of the term frequency-inverse document frequency values, wherein each group of the term frequency-inverse document frequency values contains N term frequency-inverse document frequency values, M is the number of unlabeled samples in the unlabeled data set, N is the number of labeled samples in the first data set, and M and N are positive integers; For each of the unlabeled samples in the unlabeled data set, determining the maximum term frequency-inverse document frequency value from a corresponding set of term frequency-inverse document frequency values, and obtaining M first term frequency-inverse document frequency values; For each of the first term frequency-inverse document frequency values, when the first term frequency-inverse document frequency value is greater than the threshold, the label of the labeled sample corresponding to the first term frequency-inverse document frequency value is recalled to the unlabeled sample to obtain a pseudo-labeled sample; when the first term frequency-inverse document frequency value is less than or equal to the threshold, the unlabeled sample corresponding to the first term frequency-inverse document frequency value is discarded; All the unlabeled samples in the unlabeled data set are polled, and all the pseudo-labeled samples are determined as a second data set.
5. The text classification method according to claim 4, characterized in that: Determining a threshold for judging whether to recall a pseudo label for the unlabeled sample includes: Traversing each sample in the first data set, calculating the term frequency-inverse document frequency value of the current sample and samples in the first data set other than the current sample, and obtaining N groups of the term frequency-inverse document frequency values, each group containing N-1 term frequency-inverse document frequency values; For each of the labeled samples in the first data set, determine the maximum term frequency-inverse document frequency value from a corresponding set of term frequency-inverse document frequency values to obtain N second term frequency-inverse document frequency values; Sort the N second term frequency-inverse document frequency values from large to small, and select the second term frequency-inverse document frequency value of a preset order as the threshold.
6. The text classification method according to claim 1, characterized in that: The exploratory data analysis is performed on the initial training data set, and the initial training data set is preprocessed based on the analysis result to obtain a training data set including: Determine the label categories of the merged labels of the samples in the initial training data set, and the number of labels under each label category, and determine whether there is a label category with an unbalanced number of labels according to the label categories and the number of labels under each label category, wherein the unbalanced number of labels refers to that the difference between the number of labels under at least one label category and the average number of labels under all label categories is greater than a preset number; In the case where there are category labels with an unbalanced number of labels, samples under the label category with the unbalanced number of labels are removed from the initial training data set to obtain an updated initial training data set; Determine the length of the samples in the updated initial training data set, and judge whether there are samples with abnormal lengths, wherein the samples with abnormal lengths include samples with a length greater than a third preset length, samples with a length less than a fourth preset length, and samples with empty text content, and the third preset length is greater than the fourth preset length; In the case where the samples with abnormal length exist, the samples with abnormal length are removed from the updated initial training data set to obtain the training data set.
7. The text classification method according to claim 1, characterized in that: Inputting each training sample in the training data set into a pre-training encoder to generate a pre-training vector representation includes: Segmenting the training sample using a word segmenter, and generating a first word unit sequence according to the word segmentation result; According to the maximum input length of the pre-trained encoder, the first word sequence is truncated or padded to generate a second word sequence, wherein the word segments in the word sequence that are longer than the maximum input length are truncated, and the word segments in the word sequence that are shorter than the maximum input length are padded to a first preset value; Match each word in the second word-unit sequence with a word in the vocabulary, and map the successfully matched word-unit to a corresponding vocabulary index to generate an input identification sequence; Generate an attention mask according to the positions of the actual word-gram and the filler word-gram in the second word-gram sequence, wherein the actual word-gram position is represented by a second preset value, and the filler word-gram position is represented by a first preset value; The input identification sequence and the attention mask are input into the pre-trained encoder, and the value of the classification word position of the last layer of the pre-trained encoder is extracted to obtain the pre-trained vector representation.
8. The text classification method according to claim 1, characterized in that: Input each training sample in the training data set into the knowledge graph encoder to generate a knowledge graph vector representation including: Perform entity recognition on the training sample by using an entity recognition model to generate an entity word-gram sequence, wherein the word-gram that is not recognized as an entity is represented by a first preset value; The entity word in the entity word sequence is replaced by the query representation in the knowledge graph to obtain a sparse vector representation; The sparse vector representation is densified to generate the knowledge graph vector representation of the training sample.
9. The text classification method according to claim 1, characterized in that: For each training sample, the pre-trained vector representation and the knowledge graph vector representation are fused to generate a fused vector representation, including: For each training sample, concatenate the pre-trained vector representation with the knowledge graph vector representation to generate a concatenated vector; Performing a linear transformation on the concatenated vector to obtain a linear transformation result, and inputting the linear transformation result into an activation function to calculate a first dynamic weight, wherein the first dynamic weight is used to control the fusion ratio of the pre-trained vector representation and the knowledge graph vector representation; Subtracting the first dynamic weight from the total weight value to obtain a second dynamic weight, wherein the second dynamic weight is used to control the fusion ratio of the pre-trained vector representation and the knowledge graph vector representation; The pre-trained vector representation and the knowledge graph vector representation are weightedly summed according to the first dynamic weight and the second dynamic weight to generate the fused vector representation.
10. A text classification device, characterized in that: include: A data set acquisition module is used to acquire original data sets and unlabeled data sets from the data source of text data; A data set processing module, configured to perform exploratory data analysis on the original data set, preprocess the original data set based on the analysis result to obtain a first data set, and recall pseudo labels for unlabeled samples in the unlabeled data set to obtain a second data set; a data set merging and processing module, configured to merge the first data set and the second data set to obtain an initial training data set, perform the exploratory data analysis on the initial training data set, and pre-process the initial training data set based on the analysis result to obtain a training data set; A vector conversion module, used to input each training sample in the training data set into a pre-training encoder to generate a pre-training vector representation, and input each training sample in the training data set into a knowledge graph encoder to generate a knowledge graph vector representation; The vector fusion and classification module is used to fuse the pre-trained vector representation and the knowledge graph vector representation for each training sample to generate a fused vector representation, and send the fused vector representation to the classifier to obtain a classification result.
11. A computer program product, characterized in that The invention comprises a non-volatile computer-readable storage medium, wherein the non-volatile computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the text classification method according to any one of claims 1 to 9 is implemented.
12. An electronic device comprising a memory and a processor, characterized in that: The memory stores a computer program, and the processor is configured to execute the text classification method according to any one of claims 1 to 9 through the computer program.