Text classification method, text classification device, electronic device and storage medium
Patent Information
- Application Number
- CN202210687739.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-17
- Publication Date
- 2025-01-21
- Estimated Expiration
- 2042-06-17
Smart Images

Figure CN114942994B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence technology, and in particular to a text classification method, a text classification device, an electronic device and a storage medium. Background Art
[0002] In common classification scenarios, materials (for example, text materials or image materials, etc.) are often classified by manual judgment. This method often has a large degree of human subjectivity and will affect the classification accuracy. Therefore, how to improve the accuracy of text classification has become a technical problem that needs to be solved urgently. Summary of the invention
[0003] The main purpose of the embodiments of the present application is to propose a text classification method, a text classification device, an electronic device and a storage medium, aiming to improve the accuracy of text classification.
[0004] To achieve the above purpose, a first aspect of an embodiment of the present application proposes a text classification method, the method comprising:
[0005] Get the original text to be classified;
[0006] Performing subject word recognition on the original text through a preset subject word recognition model to obtain entity subject words;
[0007] Concatenate the original text and the entity keyword to obtain a target embedding feature vector;
[0008] Calculating the classification probability of the target embedded feature vector using a preset text classification model and reference classification labels to obtain a classification probability value corresponding to each reference classification label;
[0009] The reference classification labels are screened according to the classification probability values to obtain target classification labels for the original text.
[0010] In some embodiments, the step of performing subject word recognition on the original text through a preset subject word recognition model to obtain entity subject words includes:
[0011] Perform word segmentation processing on the original text through the subject word recognition model to obtain target text segments;
[0012] Extracting keywords from the target text segment according to preset weight parameters to obtain a text keyword set;
[0013] The text keywords in the text keyword set are combined to obtain the entity subject words.
[0014] In some embodiments, the step of performing word segmentation processing on the original text through the subject word recognition model to obtain the target text segment includes:
[0015] Performing vocabulary recognition on the original text through a preset word segmenter to obtain word segment entity features;
[0016] Performing word segmentation processing on the original text according to the entity features of the word segment to obtain an initial text word segment;
[0017] The initial text segment is filtered to obtain the target text segment.
[0018] In some embodiments, the step of extracting keywords from the target text segment according to a preset weight parameter to obtain a text keyword set includes:
[0019] Sorting the target text word segments by importance to obtain a text word segment sequence;
[0020] Assigning weights to the text word segment sequence according to the weight parameters to obtain a weighted word segment sequence;
[0021] The weighted word segment sequence is screened to obtain the text keyword set.
[0022] In some embodiments, the step of concatenating the original text and the entity keyword to obtain a target embedding feature vector includes:
[0023] Performing word embedding processing on the original text to obtain a text embedding feature vector;
[0024] Performing word embedding processing on the entity subject words to obtain a subject word embedding feature vector;
[0025] The text embedding feature vector and the subject word embedding feature vector are spliced according to a preset splicing order to obtain the target embedding feature vector.
[0026] In some embodiments, the step of calculating the classification probability of the target embedded feature vector using a preset text classification model and a reference classification label to obtain a classification probability value corresponding to each reference classification label includes:
[0027] Obtaining the reference classification label;
[0028] Performing word embedding processing on the reference classification label to obtain a reference classification label vector;
[0029] The text classification model is used to calculate the vector similarity between the reference classification label vector and the target embedded feature vector to obtain the classification probability value.
[0030] In some embodiments, before the step of calculating the classification probability of the target embedded feature vector using a preset text classification model and a reference classification label to obtain a classification probability value corresponding to each reference classification label, the method includes pre-training the text classification model, specifically including:
[0031] Get label text and reference classification labels;
[0032] Performing subject word recognition on the label text to obtain sample subject words;
[0033] Concatenate the label text and the sample keyword to obtain a sample embedding feature vector;
[0034] Calculate the classification probability of the sample embedded feature vector by using the text classification model and the reference classification label to obtain a sample classification prediction value;
[0035] The loss value is calculated by using the loss function of the text classification model and the sample classification prediction value to obtain a model loss value;
[0036] The text classification model is gridded and parameterized according to the model loss value to optimize the text classification model.
[0037] To achieve the above-mentioned purpose, a second aspect of an embodiment of the present application provides a text classification device, the device comprising:
[0038] The device comprises:
[0039] A text acquisition module is used to acquire the original text to be classified;
[0040] A subject word recognition module, used to perform subject word recognition on the original text through a preset subject word recognition model to obtain entity subject words;
[0041] A concatenation module is used to concatenate the original text and the entity keyword to obtain a target embedding feature vector;
[0042] A probability calculation module, used to perform classification probability calculation on the target embedded feature vector through a preset text classification model and a reference classification label, and obtain a classification probability value corresponding to each reference classification label;
[0043] The screening module is used to screen the reference classification labels according to the classification probability values to obtain target classification labels of the original text.
[0044] To achieve the above-mentioned purpose, the third aspect of an embodiment of the present application proposes an electronic device, which includes a memory, a processor, a program stored in the memory and executable on the processor, and a data bus for realizing connection and communication between the processor and the memory, and the program, when executed by the processor, implements the method described in the first aspect above.
[0045] To achieve the above-mentioned purpose, the fourth aspect of an embodiment of the present application proposes a storage medium, which is a computer-readable storage medium used for computer-readable storage, and the storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement the method described in the first aspect above.
[0046] The text classification method, text classification device, electronic device and storage medium proposed in the present application obtain the original text to be classified; and perform subject word recognition on the original text through a preset subject word recognition model to obtain entity subject words, which can more conveniently obtain entity subject words that can represent the text content of the original text, and intuitively reflect the subject content of the original text through the entity subject words. Further, the original text and the entity subject words are spliced to obtain the target embedded feature vector; the classification probability of the target embedded feature vector is calculated through the preset text classification model and the reference classification label to obtain the classification probability value corresponding to each reference classification label. This method can reflect the correlation between the target embedded feature vector and each reference classification label through the classification probability value, which can be helpful to determine the classification label to which the target embedded feature vector belongs. Therefore, the reference classification label can be screened according to the classification probability value to obtain the target classification label of the original text, which can improve the accuracy of text classification. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] Figure 1 is a flowchart of a text classification method provided in an embodiment of the present application;
[0048] Figure 2 yes Figure 1 Flow chart of step S102 in FIG.
[0049] Figure 3 yes Figure 2 Flow chart of step S201 in FIG.
[0050] Figure 4 yes Figure 2 Flow chart of step S202 in FIG.
[0051] Figure 5 yes Figure 1 Flow chart of step S103 in FIG.
[0052] Figure 6 is another flow chart of the text classification method provided by an embodiment of the present application;
[0053] Figure 7 yes Figure 1 Flow chart of step S104 in FIG.
[0054] Figure 8 is a structural diagram of a text classification device provided in an embodiment of the present application;
[0055] Fig. 9 It is a schematic diagram of the hardware structure of the electronic device provided in the embodiment of the present application. DETAILED DESCRIPTION
[0056] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0057] It should be noted that, although the functional modules are divided in the device schematic diagram and the logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than the module division in the device or the order in the flowchart. The terms "first", "second", etc. in the specification, claims and the above drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.
[0058] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.
[0059] First, some nouns involved in this application are analyzed:
[0060] Artificial intelligence (AI) is a new technical science that studies and develops theories, methods, technologies and application systems for simulating, extending and expanding human intelligence. AI is a branch of computer science that attempts to understand the essence of intelligence and produce a new type of intelligent machine that can respond in a similar way to human intelligence. Research in this field includes robotics, speech recognition, image recognition, natural language processing and expert systems. AI can simulate the information process of human consciousness and thinking. AI is also a theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.
[0061] Natural language processing (NLP): NLP uses computers to process, understand and apply human languages (such as Chinese, English, etc.). NLP is a branch of artificial intelligence and an interdisciplinary subject between computer science and linguistics. It is often referred to as computational linguistics. Natural language processing includes grammatical analysis, semantic analysis, and text understanding. Natural language processing is often used in technical fields such as machine translation, handwritten and printed character recognition, speech recognition and text-to-speech conversion, information intent recognition, information extraction and filtering, text classification and clustering, public opinion analysis and opinion mining. It involves data mining related to language processing, machine learning, knowledge acquisition, knowledge engineering, artificial intelligence research, and linguistic research related to language computing.
[0062] Information Extraction: A text processing technology that extracts specified types of entity, relationship, event and other factual information from natural language text and forms structured data output. Information extraction is a technology that extracts specific information from text data. Text data is composed of some specific units, such as sentences, paragraphs, and chapters. Text information is composed of some small specific units, such as characters, words, phrases, sentences, paragraphs, or a combination of these specific units. Extracting noun phrases, names, place names, etc. from text data are all text information extraction. Of course, the information extracted by text information extraction technology can be various types of information.
[0063] Latent Dirichlet Allocation (LDA) is a topic model that can give the topic of each document in a document set in the form of probability distribution. LDA is a typical bag-of-words model, that is, it considers a document to be a set of words, and there is no order or precedence between words. A document can contain multiple topics, and each word in the document is generated by one of the topics.
[0064] Softmax function: The Softmax function is a normalized exponential function that can "compress" a K-dimensional vector z containing any real number into another K-dimensional real vector so that the range of each element is between (0,1) and the sum of all elements is 1. This function is often used in multi-classification problems.
[0065] Tokenizer: A tokenizer takes a string as input, splits the string into individual words or tokens, and then outputs a token stream.
[0066] Embedding: Embedding is a vector representation, which means using a low-dimensional vector to represent an object. The object can be a word, a product, a movie, etc. The property of this embedding vector is that it can make objects corresponding to vectors with similar distances have similar meanings. For example, the distance between embedding (Avengers) and embedding (Iron Man) will be very close, but the distance between embedding (Avengers) and embedding (Gone with the Wind) will be farther. Embedding is essentially a mapping from semantic space to vector space, while trying to maintain the relationship of the original samples in the semantic space in the vector space as much as possible. For example, the positions of two semantically similar words in the vector space are also relatively close. Embedding can encode objects with low-dimensional vectors and retain their meaning. It is often used in machine learning. In the process of building machine learning models, objects are encoded into a low-dimensional dense vector and then passed to DNN to improve efficiency.
[0067] BERT (Bidirectional Encoder Representation from Transformers) model: The BERT model further increases the generalization ability of the word vector model, fully describes the characteristics of character level, word level, sentence level and even inter-sentence relationship, and is built based on Transformer. There are three types of embeddings in BERT, namely Token Embedding, Segment Embedding, and Position Embedding; Token Embeddings is a word vector, and the first word is the CLS mark, which can be used for subsequent classification tasks; Segment Embeddings is used to distinguish between two sentences, because pre-training not only does LM but also does classification tasks with two sentences as input; Position Embeddings, the position word vector here is not the trigonometric function in Transfor, but is learned by BERT through training. However, BERT directly trains a position embedding to retain the position information, randomly initializes a vector for each position, adds model training, and finally obtains an embedding containing position information. Finally, in terms of the combination of position embedding and word embedding, BERT chooses to directly splice.
[0068] In common classification scenarios, materials (for example, text materials or image materials, etc.) are often classified by manual judgment. This method often has a large degree of human subjectivity and will affect the classification accuracy. Therefore, how to improve the accuracy of text classification has become a technical problem that needs to be solved urgently.
[0069] Based on this, the embodiments of the present application provide a text classification method, a text classification device, an electronic device and a storage medium, aiming to improve the accuracy of text classification.
[0070] The text classification method, text classification device, electronic device and storage medium provided in the embodiments of the present application are specifically described through the following embodiments. First, the text classification method in the embodiments of the present application is described.
[0071] The embodiments of the present application can acquire and process relevant data based on artificial intelligence technology. Among them, artificial intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.
[0072] AI basic technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, mechatronics, etc. AI software technologies mainly include computer vision technology, robotics technology, biometrics technology, speech processing technology, natural language processing technology, and machine learning / deep learning.
[0073] The text classification method provided in the embodiment of the present application relates to the field of artificial intelligence technology. The text classification method provided in the embodiment of the present application can be applied to a terminal, can be applied to a server side, or can be software running in a terminal or a server side. In some embodiments, the terminal can be a smart phone, a tablet computer, a laptop computer, a desktop computer, etc.; the server side can be configured as an independent physical server, or a server cluster or a distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms; the software can be an application that implements the text classification method, etc., but is not limited to the above forms.
[0074] The present application can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, etc. The present application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present application can also be practiced in distributed computing environments, in which tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.
[0075] Figure 1 is an optional flowchart of the text classification method provided in the embodiment of the present application. Figure 1 The method may include but is not limited to steps S101 to S105.
[0076] Step S101, obtaining the original text to be classified;
[0077] Step S102, performing subject word recognition on the original text through a preset subject word recognition model to obtain entity subject words;
[0078] Step S103, concatenating the original text and the entity keywords to obtain a target embedding feature vector;
[0079] Step S104, calculating the classification probability of the target embedded feature vector using a preset text classification model and reference classification labels to obtain a classification probability value corresponding to each reference classification label;
[0080] Step S105, filtering the reference classification labels according to the classification probability values to obtain target classification labels of the original text.
[0081] Steps S101 to S105 shown in the embodiment of the present application obtain the original text to be classified; and perform subject word recognition on the original text through a preset subject word recognition model to obtain entity subject words, which can more conveniently obtain entity subject words that can represent the text content of the original text, and intuitively reflect the subject content of the original text through the entity subject words. Further, the original text and the entity subject words are spliced to obtain a target embedded feature vector; the classification probability of the target embedded feature vector is calculated through a preset text classification model and reference classification labels to obtain the classification probability value corresponding to each reference classification label. This method can reflect the degree of correlation between the target embedded feature vector and each reference classification label through the classification probability value, which can be helpful to determine the classification label to which the target embedded feature vector belongs. Therefore, the reference classification labels can be screened according to the classification probability value to obtain the target classification label of the original text, which can improve the accuracy of text classification.
[0082] In step S101 of some embodiments, a web crawler may be written, and after setting the data source, data may be crawled in a targeted manner to obtain the original text data to be classified. The original text to be classified may also be obtained in other ways, without limitation. The original text to be classified may be a product description text, a news text, or other types of text materials, without limitation.
[0083] See also Figure 2 In some embodiments, step S102 may include but is not limited to steps S201 to S203:
[0084] Step S201, segmenting the original text using a subject word recognition model to obtain a target text segment;
[0085] Step S202, extracting keywords from the target text segment according to preset weight parameters to obtain a text keyword set;
[0086] Step S203, combining the text keywords in the text keyword set to obtain entity keywords.
[0087] In step S201 of some embodiments, the subject word recognition model can be constructed based on the LDA algorithm. The original text is divided into multiple initial text segments by the word segmenter of the subject word recognition model and the preset part-of-speech categories, and then the initial text segments are screened to obtain target text segments, wherein the preset part-of-speech categories include nouns, verbs, adjectives, adverbs, etc.
[0088] In step S202 of some embodiments, the weight parameter can be set according to actual business needs, or according to the importance of the target text segment, without limitation. When extracting keywords from the target text segment, the target text segment can be sorted according to the importance of the target text segment to obtain the importance sequence of the target text segment, and then the preset weight parameter is assigned to each target text segment in the importance sequence in descending order, thereby obtaining a text keyword set.
[0089] In step S203 of some embodiments, the entity keyword can be composed of one or more text keywords in the text keyword set. When multiple text keywords are involved, they can be randomly combined according to business needs without limitation. For example, when multiple text keywords are involved, three text keywords are selected to be combined to form the entity keyword.
[0090] See also Figure 3 In some embodiments, step S301 may include but is not limited to steps S301 to S303:
[0091] Step S301, performing vocabulary recognition on the original text through a preset word segmenter to obtain word segment entity features;
[0092] Step S302, segmenting the original text according to the entity features of the word segment to obtain an initial text word segment;
[0093] Step S303: filter the initial text segment to obtain the target text segment.
[0094] In step S301 and step S302 of some embodiments, the preset word segmenter can be a Jieba word segmenter, etc., without limitation. Taking the Jieba word segmenter as an example, the original text is subjected to vocabulary recognition processing by the Jieba word segmenter. Specifically, the dictionary file in the Jieba word segmenter is first loaded, and each word and the number of times the word appears in the Jieba word segmenter are obtained. Further, the dictionary file is traversed, and a directed acyclic graph of all possible word segmentation situations in the original sentence data is constructed by string matching, and the maximum probability of all paths from each character node in the original text to the end of the sentence is calculated, and the end position of the corresponding character word segment in the directed acyclic graph at the maximum probability is recorded at the same time, and the node path and node information are used as word segment entity features, and the original text is segmented according to the node path to obtain the initial text word segment.
[0095] In step S303 of some embodiments, the initial text segments may be filtered according to their segment lengths, and initial text segments whose segment lengths exceed a preset segment length threshold are removed to obtain target text segments that meet the requirements.
[0096] Through the above steps S301 to S303, the original text can be easily split into multiple separate target text segments, and the semantic content information of the original text can be represented by the target text segments, thereby improving the efficiency of text classification.
[0097] See also Figure 4 In some embodiments, step S302 may include but is not limited to steps S401 to S403:
[0098] Step S401, sorting the target text segments by importance to obtain a text segment sequence;
[0099] Step S402, weighting the text word sequence according to the weight parameter to obtain a weighted word sequence;
[0100] Step S403: Screen the weighted word segment sequence to obtain a text keyword set.
[0101] In step S401 of some embodiments, the target text segments are sorted by importance according to their parts of speech and business scenario requirements to obtain a text segment sequence. For example, in the importance sorting process of some embodiments, the importance of nouns is higher than that of adjectives, the importance of adjectives is higher than that of verbs, and the importance of verbs is higher than that of adverbs.
[0102] In step S402 of some embodiments, the preset weight parameters are assigned to each target text segment in the text segment sequence in order according to the numerical value to obtain a weighted segment sequence. For example, the target text segments of the text segment sequence are "hair dryer", "household", "black", and "foldable" in order, and the weight parameters include 0.5, 0.21, 0.08, and 0.13. Then, the weight 0.5 is matched to the target text segment "hair dryer", and the weight 0.21 is matched to the target text segment "household"; the weight 0.13 is matched to the target text segment "black"; and the weight 0.08 is matched to the target text segment "foldable". The weighted segment sequence can be expressed as "hair dryer (0.5)", "household (0.21)", "black (0.13)", and "foldable (0.08)".
[0103] In step S403 of some embodiments, the weighted segment sequence is screened according to the part-of-speech categories and weight parameters of the target text segments, and the target text segments whose part-of-speech categories do not meet the current business requirements and the target text segments whose weight parameters are less than or equal to the preset threshold are filtered out, thereby reducing the number of target text segments and obtaining a set of text keywords that meet the current business requirements.
[0104] See also Figure 5 In some embodiments, step S103 may include but is not limited to steps S501 to S503:
[0105] Step S501, performing word embedding processing on the original text to obtain a text embedding feature vector;
[0106] Step S502, performing word embedding processing on the entity subject word to obtain a subject word embedding feature vector;
[0107] Step S503, concatenating the text embedding feature vector and the topic word embedding feature vector according to a preset concatenation order to obtain a target embedding feature vector.
[0108] In step S501 of some embodiments, word embedding processing is performed on the original text through a BERT model, etc., and the original text is embedded from a high-dimensional space into a low-dimensional continuous vector space, so that each word or phrase in the original text is mapped to a vector in the real number field, and a text embedding feature vector is obtained.
[0109] In step S502 of some embodiments, entity keywords are subjected to word embedding processing through a BERT model or the like, and the entity keywords are embedded from a high-dimensional space into a low-dimensional continuous vector space, so that each word or phrase in the entity keywords is mapped to a vector on the real number domain, thereby obtaining a keyword embedding feature vector.
[0110] In step S503 of some embodiments, in order to reflect the subject content of the original text, the preset splicing order may be that the subject word is in front and the original text is in the back. Therefore, when the text embedding feature vector and the subject word embedding feature vector are spliced, the subject word embedding feature vector is placed in the front position and the text embedding feature vector is placed in the back position. The subject word embedding feature vector and the text embedding feature vector are vector-added to obtain the target embedding feature vector.
[0111] See also Figure 6 In some embodiments, before step S104, the text classification method further includes pre-training a text classification model, including but not limited to steps S601 to S606:
[0112] Step S601, obtaining label text and reference classification labels;
[0113] Step S602, performing keyword recognition on the label text to obtain sample keyword;
[0114] Step S603, concatenating the label text and the sample keyword to obtain a sample embedding feature vector;
[0115] Step S604, calculating the classification probability of the sample embedded feature vector using the text classification model and the reference classification label to obtain the sample classification prediction value;
[0116] Step S605, calculating the loss value by using the loss function of the text classification model and the sample classification prediction value to obtain the model loss value;
[0117] Step S606, gridding and adjusting the parameters of the text classification model according to the model loss value to optimize the text classification model.
[0118] In step S601 of some embodiments, a web crawler can be written, and after the data source is set, data can be crawled in a targeted manner to obtain label text. Label text can also be obtained in other ways, not limited to this. Among them, the label text can be a product description text with a product label, a news text, or other types of text materials, without limitation; the reference classification label can be set according to actual business needs, and the reference classification label can include specific products in various fields, such as sweepers, vacuum cleaners, drones, etc., without limitation.
[0119] In step S602 of some embodiments, the tag text is segmented by a keyword recognition model to obtain a tag text segment; then keywords are extracted from the tag text according to a preset weight parameter to obtain a sample keyword set; finally, the sample keywords in the sample keyword set are combined to obtain a sample keyword. This process is basically the same as the above steps S201 to S203, and will not be repeated here.
[0120] In step S603 of some embodiments, word embedding is performed on the label text to obtain a label text embedding vector; word embedding is performed on the sample subject words to obtain a sample subject word embedding vector; the sample subject word embedding vector and the label text embedding vector are concatenated in the order of the sample subject word embedding vector first and the label text embedding vector later to obtain a sample embedding feature vector.
[0121] In step S604 of some embodiments, the classification probability of the sample embedded feature vector is calculated by using the classification function of the text classification model and the reference classification label, wherein the classification function may be a softmax function, and the probability distribution of the sample embedded feature vector is created on each reference classification label by the softmax function to obtain a sample classification prediction value, which may characterize the possibility that the sample embedded feature vector belongs to each reference classification label.
[0122] In step S605 of some embodiments, the loss function is a minimization loss function. Minimizing the loss function can reflect the optimal result of the text classification model. The minimization loss function can be expressed as Loss = ∑y i logy′ i +(1-y i )log(1-y′ i ), where y i is the true label of the label text, y′ i It is the sample classification prediction value of the label text. Therefore, the model loss value Loss of the text classification model can be easily calculated through the loss function and the sample classification prediction value.
[0123] In step S606 of some embodiments, when the text classification model is adjusted in a grid-based manner according to the model loss value, the maximum text vector length, training rate, batch_size, etc. are adjusted, and the text classification model is trained and verified according to the preset values to find the parameters of the optimal result, wherein the main parameters include indicators such as auc, precision, and recall. For example, in the process of grid-based parameter adjustment, the maximum and minimum values are set for different parameters, and the parameters are adjusted in a continuous cycle until the text classification model has the optimal result or the number of training times exceeds the set threshold, and the parameter adjustment is stopped to obtain the final text classification model.
[0124] Through the above steps S601 to S606, the text classification model can be trained and optimized more accurately to obtain the optimal text classification model, thereby improving the training effect and model performance of the text classification model.
[0125] See also Figure 7 In some embodiments, step S104 may include but is not limited to steps S701 to S703:
[0126] Step S701, obtaining a reference classification label;
[0127] Step S702, performing word embedding processing on the reference classification label to obtain a reference classification label vector;
[0128] Step S703, using the text classification model to calculate the vector similarity between the reference classification label vector and the target embedded feature vector, to obtain a classification probability value.
[0129] In step S701 of some embodiments, the reference classification label can be set according to actual business needs, and the reference classification label can include specific products in various fields, such as sweepers, vacuum cleaners, drones, etc., without limitation.
[0130] In step S702 of some embodiments, word embedding processing is performed on the reference classification label to achieve mapping of the reference classification label from the semantic space to the vector space, thereby obtaining a classification label in vector form, namely, a reference classification label vector.
[0131] In step S703 of some embodiments, when calculating the vector similarity of the reference classification label vector and the target embedded feature vector through the text classification model, a collaborative filtering algorithm such as the cosine similarity algorithm can be used to calculate the similarity of the reference classification label vector and the target embedded feature vector, and the obtained similarity value is used as the classification probability value. The classification probability value can characterize the degree of correlation and approximation between the reference classification label vector and the target embedded feature vector. The classification probability value can more conveniently and intuitively reflect the degree to which the target embedded feature vector is close to each reference classification label vector.
[0132] In step S105 of some embodiments, since the size of the classification probability value can represent the possibility that the original text belongs to each reference classification label, the larger the classification probability value, the greater the possibility that the original text belongs to the category corresponding to the reference classification label. Therefore, when the reference classification labels are screened according to the classification probability values, the reference classification label with the largest classification probability value is selected as the target classification label of the original text. The target classification label can be used to represent the category to which the original text belongs.
[0133] In a specific embodiment, original text 1 is a news description text, which includes the text content "The market for sweeping robots is booming. Sweeping machines in the home field are already well known, and are also gradually advancing in the commercial field. At present, the square has begun to promote the use of machine sanitation workers to keep the square clean."; original text 2 is a product description text, which includes the text content "A certain brand of sweeping robot can achieve sweeping and mopping in one, and has a large suction force of 2500Pa." The text classification method of the embodiment of the present application can easily extract the entity keywords of original text 1 as "sweeping, commercial use", and the entity keywords of original text 2 The keywords are "sweeping, suction, household use"; therefore, the original text 1 and its entity keywords are classified and processed through the text classification model, and the original text 1 is classified as the reference classification label of "sweeping machine". The original text 2 and its entity keywords are classified and processed through the text classification model, and the original text 2 is classified as the reference classification label of "sweeping machine". This method can realize the classification of different information of the same type of products, put the information, news, product descriptions, etc. of the same type of products in the same category, effectively realize the classification processing of mixed categories, and improve the classification accuracy of materials and materials.
[0134] The text classification method of the embodiment of the present application obtains the original text to be classified; and performs subject word recognition on the original text through a preset subject word recognition model to obtain entity subject words, which can more conveniently obtain entity subject words that can represent the text content of the original text, and intuitively reflect the subject content of the original text through the entity subject words. Further, the original text and the entity subject words are spliced to obtain a target embedded feature vector; the classification probability of the target embedded feature vector is calculated through a preset text classification model and reference classification labels to obtain the classification probability value corresponding to each reference classification label. This method can reflect the degree of correlation between the target embedded feature vector and each reference classification label through the classification probability value, which can be helpful to determine the classification label to which the target embedded feature vector belongs. Therefore, the reference classification labels can be screened according to the classification probability value to obtain the target classification label of the original text, which can improve the accuracy of text classification.
[0135] See also Figure 8 The present application also provides a text classification device that can implement the above-mentioned text classification method. The device includes:
[0136] The text acquisition module 801 is used to acquire the original text to be classified;
[0137] The subject word recognition module 802 is used to perform subject word recognition on the original text through a preset subject word recognition model to obtain entity subject words;
[0138] A concatenation module 803 is used to concatenate the original text and the entity keyword to obtain a target embedding feature vector;
[0139] The probability calculation module 804 is used to calculate the classification probability of the target embedded feature vector through a preset text classification model and a reference classification label to obtain a classification probability value corresponding to each reference classification label;
[0140] The screening module 805 is used to screen the reference classification labels according to the classification probability values to obtain the target classification labels of the original text.
[0141] In some embodiments, the keyword identification module 802 includes:
[0142] The word segmentation unit is used to perform word segmentation on the original text through the subject word recognition model to obtain the target text segment;
[0143] A keyword extraction unit, used to extract keywords from the target text segment according to a preset weight parameter to obtain a text keyword set;
[0144] The combination unit is used to combine the text keywords in the text keyword set to obtain entity keywords.
[0145] In some embodiments, the word segmentation unit includes:
[0146] The vocabulary recognition subunit is used to perform vocabulary recognition on the original text through a preset word segmenter to obtain the entity features of the word segment;
[0147] The word segmentation subunit is used to perform word segmentation on the original text according to the entity features of the word segment to obtain the initial text word segment;
[0148] The filtering subunit is used to filter the initial text segment to obtain the target text segment.
[0149] In some embodiments, the keyword extraction unit includes:
[0150] A sorting subunit is used to sort the target text word segments by importance to obtain a text word segment sequence;
[0151] An allocating subunit, used for allocating weights to the text word segment sequence according to the weight parameter to obtain a weighted word segment sequence;
[0152] The screening subunit is used to screen the weighted word sequence to obtain a text keyword set.
[0153] In some embodiments, the splicing module 803 includes:
[0154] The first word embedding unit is used to perform word embedding processing on the original text to obtain a text embedding feature vector;
[0155] The second word embedding unit is used to perform word embedding processing on the entity subject word to obtain a subject word embedding feature vector;
[0156] The first concatenation unit is used to concatenate the text embedding feature vector and the topic word embedding feature vector according to a preset concatenation order to obtain a target embedding feature vector.
[0157] In some embodiments, the probability calculation module 804 includes:
[0158] A label acquisition unit, used to acquire a reference classification label;
[0159] The third word embedding unit is used to perform word embedding processing on the reference classification label to obtain a reference classification label vector;
[0160] The first calculation unit is used to calculate the vector similarity of the reference classification label vector and the target embedded feature vector through the text classification model to obtain a classification probability value.
[0161] In some embodiments, the text classification device further includes a model training module, specifically including:
[0162] An acquisition unit, used to acquire label text and reference classification labels;
[0163] The recognition unit is used to perform keyword recognition on the label text to obtain sample keyword;
[0164] The second concatenation unit is used to concatenate the label text and the sample keyword to obtain a sample embedding feature vector;
[0165] The second calculation unit is used to calculate the classification probability of the sample embedded feature vector through the text classification model and the reference classification label to obtain the sample classification prediction value;
[0166] A third calculation unit is used to calculate the loss value by using the loss function of the text classification model and the sample classification prediction value to obtain the model loss value;
[0167] The optimization unit is used to perform grid-based parameter adjustment on the text classification model according to the model loss value to optimize the text classification model.
[0168] The specific implementation of the text classification device is basically the same as the specific implementation of the above-mentioned text classification method, and will not be repeated here.
[0169] The embodiment of the present application also provides an electronic device, the electronic device comprising: a memory, a processor, a program stored in the memory and executable on the processor, and a data bus for realizing connection and communication between the processor and the memory, and the program is executed by the processor to realize the above-mentioned text classification method. The electronic device can be any intelligent terminal including a tablet computer, a car computer, etc.
[0170] See also Fig. 9 , Fig. 9 The hardware structure of an electronic device of another embodiment is illustrated, and the electronic device includes:
[0171] The processor 901 may be implemented by a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (Application Specific Integrated Circuit, ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of the present application;
[0172] The memory 902 can be implemented in the form of a read-only memory (ROM), a static storage device, a dynamic storage device, or a random access memory (RAM). The memory 902 can store an operating system and other application programs. When the technical solution provided in the embodiment of this specification is implemented by software or firmware, the relevant program code is stored in the memory 902, and the processor 901 calls and executes the text classification method of the embodiment of this application;
[0173] Input / output interface 903, used to implement information input and output;
[0174] Communication interface 904, used to realize communication interaction between the device and other devices, which can be realized by wired mode (such as USB, network cable, etc.) or wireless mode (such as mobile network, WIFI, Bluetooth, etc.);
[0175] A bus 905 that transmits information between various components of the device (e.g., the processor 901, the memory 902, the input / output interface 903, and the communication interface 904);
[0176] The processor 901 , the memory 902 , the input / output interface 903 and the communication interface 904 are connected to each other in communication within the device via a bus 905 .
[0177] An embodiment of the present application also provides a storage medium, which is a computer-readable storage medium used for computer-readable storage. The storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement the above-mentioned text classification method.
[0178] The memory, as a non-transient computer-readable storage medium, can be used to store non-transient software programs and non-transient computer executable programs. In addition, the memory may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some embodiments, the memory may optionally include a memory remotely disposed relative to the processor, and these remote memories may be connected to the processor 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.
[0179] The text classification method, text classification device, electronic device and storage medium provided in the embodiment of the present application obtain the original text to be classified; and perform subject word recognition on the original text through a preset subject word recognition model to obtain entity subject words, which can more conveniently obtain entity subject words that can represent the text content of the original text, and intuitively reflect the subject content of the original text through the entity subject words. Further, the original text and the entity subject words are spliced to obtain a target embedded feature vector; the classification probability of the target embedded feature vector is calculated through a preset text classification model and a reference classification label to obtain a classification probability value corresponding to each reference classification label. This method can reflect the degree of correlation between the target embedded feature vector and each reference classification label through the classification probability value, which can be helpful to determine the classification label to which the target embedded feature vector belongs. Therefore, the reference classification labels can be screened according to the classification probability value to obtain the target classification label of the original text, which can improve the accuracy of text classification.
[0180] The embodiments described in the embodiments of the present application are intended to more clearly illustrate the technical solutions of the embodiments of the present application and do not constitute a limitation on the technical solutions provided in the embodiments of the present application. Those skilled in the art will appreciate that with the evolution of technology and the emergence of new application scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.
[0181] It can be understood by those skilled in the art that Figure 1-7 The technical solutions shown in the figure do not constitute a limitation on the embodiments of the present application, and may include more or fewer steps than those shown in the figure, or a combination of certain steps, or different steps.
[0182] The device embodiments described above are merely illustrative, and the units described as separate components may or may not be physically separated, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0183] Those skilled in the art will appreciate that all or some of the steps in the methods disclosed above, and the functional modules / units in the systems and devices may be implemented as software, firmware, hardware, or a suitable combination thereof.
[0184] The terms "first", "second", "third", "fourth", etc. (if any) in the specification 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.
[0185] It should be understood that in the present application, "at least one (item)" means one or more, and "plurality" means two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the objects associated before and after are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.
[0186] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the above units is only a logical function division. There may be other division methods in actual implementation, such as 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 devices or units, which can be electrical, mechanical or other forms.
[0187] The units described above 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.
[0188] 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.
[0189] 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, and the computer software product is stored in a storage medium, including multiple instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, referred to as ROM), random access memory (Random Access Memory, referred to as RAM), disk or optical disk and other media that can store programs.
[0190] The preferred embodiments of the present invention are described above with reference to the accompanying drawings, but the scope of the rights of the present invention is not limited thereto. Any modification, equivalent substitution and improvement made by a person skilled in the art without departing from the scope and essence of the present invention should be within the scope of the rights of the present invention.
Claims
1. A text classification method, characterized in that: The method comprises: Get the original text to be classified; Performing subject word recognition on the original text through a preset subject word recognition model to obtain entity subject words; Concatenate the original text and the entity keyword to obtain a target embedding feature vector; Calculating the classification probability of the target embedded feature vector using a preset text classification model and reference classification labels to obtain a classification probability value corresponding to each reference classification label; Screening the reference classification labels according to the classification probability values to obtain target classification labels for the original text; The subject word recognition of the original text is performed by a preset subject word recognition model to obtain entity subject words, including: The original text is segmented by the word segmenter of the subject word recognition model and the preset part-of-speech category to obtain a plurality of initial text segments, and the plurality of initial text segments are screened to obtain a target text segment, wherein the subject word recognition model is constructed based on the LDA algorithm; Extracting keywords from the target text segment according to a preset weight parameter to obtain a text keyword set, wherein the weight parameter is set according to the importance of the target text segment; Combining the text keywords in the text keyword set to obtain the entity subject words; The concatenating the original text and the entity keyword to obtain a target embedding feature vector includes: Performing word embedding processing on the original text through the BERT model, embedding the original text from a high-dimensional space into a low-dimensional continuous vector space, and obtaining a text embedding feature vector; Performing word embedding processing on the entity topic words through the BERT model, embedding the entity topic words from the high-dimensional space into the low-dimensional continuous vector space, and obtaining a topic word embedding feature vector; According to a preset splicing order, the subject word embedding feature vector is placed at a front position, the text embedding feature vector is placed at a front position, and vector addition is performed on the subject word embedding feature vector and the text embedding feature vector to obtain the target embedding feature vector; The classification probability calculation of the target embedded feature vector is performed using a preset text classification model and a reference classification label to obtain a classification probability value corresponding to each reference classification label, including: Acquire the reference classification label; perform word embedding processing on the reference classification label to obtain a reference classification label vector; perform vector similarity calculation on the reference classification label vector and the target embedded feature vector through the text classification model to obtain the classification probability value.
2. The text classification method according to claim 1, characterized in that: The step of extracting keywords from the target text segment according to the preset weight parameters to obtain a text keyword set includes: Sorting the target text word segments by importance to obtain a text word segment sequence; Assigning weights to the text word segment sequence according to the weight parameters to obtain a weighted word segment sequence; The weighted word segment sequence is screened to obtain the text keyword set.
3. The text classification method according to any one of claims 1 to 2, characterized in that: Before the step of calculating the classification probability of the target embedded feature vector by using a preset text classification model and a reference classification label to obtain a classification probability value corresponding to each reference classification label, the method includes pre-training the text classification model, specifically including: Get label text and reference classification labels; Performing subject word recognition on the label text to obtain sample subject words; Concatenate the label text and the sample keyword to obtain a sample embedding feature vector; Calculate the classification probability of the sample embedded feature vector by using the text classification model and the reference classification label to obtain a sample classification prediction value; The loss value is calculated by using the loss function of the text classification model and the sample classification prediction value to obtain a model loss value; The text classification model is gridded and parameterized according to the model loss value to optimize the text classification model.
4. A text classification device, characterized in that: The device comprises: A text acquisition module is used to acquire the original text to be classified; A subject word recognition module is used to perform subject word recognition on the original text through a preset subject word recognition model to obtain entity subject words; A concatenation module is used to concatenate the original text and the entity keyword to obtain a target embedding feature vector; A probability calculation module, used to perform classification probability calculation on the target embedded feature vector through a preset text classification model and a reference classification label, and obtain a classification probability value corresponding to each reference classification label; A screening module, used for screening the reference classification labels according to the classification probability values to obtain target classification labels for the original text; The subject word recognition of the original text is performed by a preset subject word recognition model to obtain entity subject words, including: The original text is segmented by the word segmenter of the subject word recognition model and the preset part-of-speech category to obtain a plurality of initial text segments, and the plurality of initial text segments are screened to obtain a target text segment, wherein the subject word recognition model is constructed based on the LDA algorithm; Extracting keywords from the target text segment according to a preset weight parameter to obtain a text keyword set, wherein the weight parameter is set according to the importance of the target text segment; Combining the text keywords in the text keyword set to obtain the entity subject words; The concatenating the original text and the entity keyword to obtain a target embedding feature vector includes: Performing word embedding processing on the original text through the BERT model, embedding the original text from a high-dimensional space into a low-dimensional continuous vector space, and obtaining a text embedding feature vector; Performing word embedding processing on the entity topic words through the BERT model, embedding the entity topic words from the high-dimensional space into the low-dimensional continuous vector space, and obtaining a topic word embedding feature vector; According to a preset splicing order, the subject word embedding feature vector is placed at a front position, the text embedding feature vector is placed at a front position, and vector addition is performed on the subject word embedding feature vector and the text embedding feature vector to obtain the target embedding feature vector; The classification probability calculation of the target embedded feature vector is performed using a preset text classification model and a reference classification label to obtain a classification probability value corresponding to each reference classification label, including: Acquire the reference classification label; perform word embedding processing on the reference classification label to obtain a reference classification label vector; perform vector similarity calculation on the reference classification label vector and the target embedded feature vector through the text classification model to obtain the classification probability value.
5. An electronic device, characterized in that: The electronic device includes a memory, a processor, a program stored in the memory and executable on the processor, and a data bus for realizing connection and communication between the processor and the memory. When the program is executed by the processor, the steps of the text classification method according to any one of claims 1 to 3 are realized.
6. A storage medium, the storage medium being a computer-readable storage medium, used for computer-readable storage, characterized in that: The storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement the steps of the text classification method according to any one of claims 1 to 3.
Citation Information
Patent Citations
Text classification method and device, terminal equipment and readable storage medium
CN112417153A