Long text classification method, device, equipment and storage medium
By dividing long texts into sequences and integrating representations to generate chapter representations for classification, the problem of inaccurate classification results of the BERT model in long text classification is solved and the classification accuracy is improved.
Patent Information
- Application Number
- CN202111619122.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-27
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2041-12-27
AI Technical Summary
The existing BERT model has inaccurate classification results due to the sliding window method in long text classification. Especially in scenarios where topics change frequently, it cannot effectively utilize the full-text contextual semantic information.
After dividing the target long text into N sequences, the models are respectively input to obtain text representations of the sequences, and these representations are merged and weighted through the fusion module to generate chapter representations for classification.
By integrating sequence representation and fusing full-text semantic information and contextual information, the accuracy of long text classification is improved.
Smart Images

Figure CN114281996B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of computer technology, and in particular to a long text classification method, apparatus, device and storage medium. Background Art
[0002] In some application scenarios, long texts are often involved, such as telephone consultations. In order to facilitate the subsequent consultation business, the long texts generated by telephone consultations need to be classified according to the topic content. However, for long texts generated by telephone consultations, not only are the text contents long, but they also include a lot of colloquial expressions and scattered key points, making the classification of long texts difficult.
[0003] Currently, BERT (Bidirectional Encoder Representations from Transformers) is used to classify long texts. Specifically, a sliding window is used to segment the text, and the classification results of each window are obtained through BERT. Finally, each window votes to determine the final classification result. However, each window is independent of each other, which makes the classification result inaccurate. Summary of the invention
[0004] The embodiments of the present application provide a long text classification method, apparatus, device and storage medium to improve the classification accuracy of long texts.
[0005] In a first aspect, an embodiment of the present application provides a long text classification method, comprising:
[0006] Divide the acquired target long text into N sequences and input them into the target model to obtain text representations of the N sequences respectively, where N is a positive integer;
[0007] The text representations of the N sequences are fused to obtain the chapter representation of the target long text;
[0008] According to the chapter representation of the target long text, a classification result of the target long text is obtained.
[0009] In a second aspect, an embodiment of the present application provides a long text classification device, comprising:
[0010] A determination unit, used for dividing the acquired target long text into N sequences and inputting the sequences into the target model to obtain text representations of the N sequences respectively, where N is a positive integer;
[0011] A processing unit, used for fusing the text representations of the N sequences to obtain a chapter representation of the target long text;
[0012] The classification unit is used to obtain a classification result of the target long text according to the chapter representation of the target long text.
[0013] In some embodiments, the target model includes a fusion module, and the above-mentioned processing unit is specifically used to merge the text representations of the N sequences to obtain a merged matrix; input the merged matrix into the fusion module to obtain the chapter representation of the target long text output by the fusion module.
[0014] In some embodiments, the fusion module includes a linear transformation layer and a fusion layer, and the above-mentioned processing unit is specifically used to input the merged matrix into the linear transformation layer, and obtain the first matrix, the second matrix and the third matrix through linear transformation of the first weight matrix, the second weight matrix and the third weight matrix respectively; the first matrix, the second matrix and the third matrix are input into the fusion layer to obtain the chapter representation of the target long text.
[0015] In some embodiments, the fusion layer includes a fusion unit and a normalization unit, and the processing unit is specifically used to input the first matrix and the second matrix into the fusion unit, determine the ratio of the transpose of the second matrix multiplied by the first matrix and the scale, and the scale is related to the output dimension of the sequence; input the ratio into the normalization unit to obtain the weights of the text representation of the N sequences; multiply the weights of the text representation of the N sequences by the third matrix to obtain the chapter representation of the target long text.
[0016] Optionally, the normalization unit includes a softmax activation function.
[0017] In some embodiments, the target model also includes fully connected layers (FCs), and the classification unit is specifically used to input the chapter representation of the target long text into the fully connected layer to obtain the predicted probabilities of M labels, where M is a positive integer; and obtain the classification result of the target long text based on the predicted probabilities of the M labels.
[0018] In some embodiments, the above-mentioned determination unit is specifically used to divide the target long text into N sequences through a preset window length and a window sliding step; for each sequence in the N sequences, the sequence is input into the target model to obtain a text representation of the sequence.
[0019] Optionally, the window sliding step size is smaller than the window length.
[0020] In some embodiments, the model also includes a training unit, which is specifically used to input the i-th text that is not labeled in the training data set into the target model after Q rounds of training, and determine the probability of the i-th text with respect to P categories, where Q and P are both positive integers; determine the uncertainty score of the i-th text based on the probability of the i-th text with respect to the P categories; if the uncertainty score of the i-th text is greater than a preset value, label the i-th text; and use the labeled i-th text to train the target model.
[0021] In some embodiments, if the target model is used for a single-label classification task, the training unit is specifically used to multiply the probability of each of the P categories by the logarithm of the probability of the category to obtain the product corresponding to the category, and add the products corresponding to all of the P categories to obtain a first sum; the negative of the first sum is determined as the uncertainty score of the i-th text.
[0022] In some embodiments, if the target model is used for a multi-label classification task, the training unit is specifically used to multiply the probability of the classification by the logarithm of the probability of the classification for each of the P classifications to obtain a first product of the classification; determine a first difference between one and the probability of the classification, and a second difference between one and the logarithm of the probability of the classification, and multiply the first difference by the second difference to obtain a second product of the classification; and determine the difference between the negative of the first product and the second product as the uncertainty score of the i-th text with respect to the classification.
[0023] In some embodiments, if the i-th text is a long text, the training unit is specifically used to divide the i-th text into K sequences and input them into the target model to obtain text representations of the K sequences respectively, where K is a positive integer; the text representations of the K sequences are merged to obtain the chapter representation of the i-th text; and according to the chapter representation of the i-th text, the probability of the i-th text with respect to P categories is obtained.
[0024] In a third aspect, an embodiment of the present application provides a computing device, including a processor and a memory;
[0025] The memory is used to store computer programs;
[0026] The processor is used to execute the computer program to implement the method described in the first aspect above.
[0027] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the storage medium includes computer instructions. When the instructions are executed by a computer, the computer implements the method described in the first aspect.
[0028] In a fifth aspect, an embodiment of the present application provides a computer program product, which includes a computer program, and the computer program is stored in a readable storage medium. At least one processor of a computer can read the computer program from the readable storage medium, and the at least one processor executes the computer program so that the computer implements the method described in the first aspect.
[0029] The long text classification method, device, equipment and storage medium provided in the embodiment of the present application divide the acquired target long text into N sequences and input them into the target model to obtain text representations of N sequences respectively, where N is a positive integer; fuse the text representations of the N sequences to obtain the chapter representation of the target long text; and obtain the classification result of the target long text based on the chapter representation of the target long text. In other words, the present application fuses the text representations of N sequences to obtain the chapter representation of the entire target long text, and performs classification based on the chapter representation of the entire target long text, that is, the semantic information and contextual information of the entire text are considered in the classification process, thereby improving the classification accuracy of the target long text. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0031] Figure 1 A schematic diagram of a system architecture involved in an embodiment of the present application;
[0032] Figure 2 A schematic diagram of a long text classification method flow chart provided in an embodiment of the present application;
[0033] Figure 3 A schematic diagram of a target long text involved in an embodiment of the present application;
[0034] Figure 4A A framework diagram of the BERT model involved in the embodiments of the present application;
[0035] Figure 4B A schematic diagram of the network structure of the BERT model involved in the embodiment of the present application;
[0036] Figure 5A A schematic diagram of a network structure of a target model involved in an embodiment of the present application;
[0037] Figure 5BA schematic diagram of a network structure of a target model involved in an embodiment of the present application;
[0038] Figure 5C A schematic diagram of a network structure of a target model involved in an embodiment of the present application;
[0039] Figure 5D A schematic diagram of a network structure of a target model involved in an embodiment of the present application;
[0040] Figure 6 A specific schematic diagram of the long text classification method involved in the embodiment of the present application;
[0041] Figure 7 A schematic diagram of a long text classification method flow chart provided in an embodiment of the present application;
[0042] Figure 8 A schematic diagram of the model training process involved in an embodiment of the present application;
[0043] Fig. 9 A schematic diagram of the structure of a long text classification device provided in one embodiment of the present application;
[0044] Fig.10 Another structural schematic diagram of a long text classification device provided in one embodiment of the present application;
[0045] Fig.11 A block diagram of a computing device involved in an embodiment of the present application. DETAILED DESCRIPTION
[0046] The technical solutions in the embodiments of the present application will be described below in conjunction with the drawings in the embodiments of the present application.
[0047] It should be understood that in the embodiment of the present invention, "B corresponding to A" means that B is associated with A. In one implementation, B can be determined based on A. However, it should also be understood that determining B based on A does not mean determining B based only on A, and B can also be determined based on A and / or other information.
[0048] In the description of the present application, unless otherwise specified, “plurality” means two or more than two.
[0049] In addition, in order to clearly describe the technical solutions of the embodiments of the present application, in the embodiments of the present application, words such as "first" and "second" are used to distinguish the same items or similar items with substantially the same functions and effects. Those skilled in the art can understand that words such as "first" and "second" do not limit the quantity and execution order, and words such as "first" and "second" do not necessarily limit the difference.
[0050] Figure 1This is a schematic diagram of a system architecture involved in an embodiment of the present application, including a user device 101, a data collection device 102, a training device 103, an execution device 104, a database 105 and a content library 106.
[0051] The data collection device 102 is used to read the training data from the content library 106 and store the read training data in the database 105. The training data involved in the embodiment of the present application includes long text data.
[0052] In some embodiments, the user device 101 is used to perform a labeling operation on the long text data in the database 105 , that is, to label the long text data with a classification label.
[0053] The training device 103 trains the model based on the training data maintained in the database 105, so that the trained target model can accurately predict the classification of the long text. The target model obtained by the training device 103 can be applied to different systems or devices.
[0054] In the attached Figure 1 In the embodiment, the execution device 104 is configured with an I / O interface 107 to exchange data with external devices. For example, the target long text to be classified sent by the user device 101 is received through the I / O interface. The calculation module 109 in the execution device 104 uses the trained target model to classify the input target long text, obtains the classification result of the target long text, and sends the classification result of the target long text to the user device 101 through the I / O interface.
[0055] In some embodiments, the user can annotate the training data in the database 105 through the user device 101. The training device 103 uses the annotated training data to train the target model. Optionally, the training device 103 can also use the unannotated data in the database to perform unsupervised pre-training on the target model.
[0056] The user device 101 may include a mobile phone, a tablet computer, a laptop computer, a PDA, a mobile internet device (MID) or other terminal devices with a browser function installed.
[0057] The execution device 104 may be a server, or other electronic devices with data processing functions, such as a smart terminal.
[0058] Exemplarily, the server may be a computing device such as a rack server, a blade server, a tower server or a cabinet server, etc. The server may be an independent test server or a test server cluster composed of multiple test servers.
[0059] In this embodiment, the execution device 104 is connected to the user device 101 through a network. The network can be a wireless or wired network such as an intranet, the Internet, the Global System of Mobilecommunication (GSM), Wideband Code Division Multiple Access (WCDMA), 4G network, 5G network, Bluetooth, Wi-Fi, or a call network.
[0060] It should be noted that the attached Figure 1 It is only a schematic diagram of a system architecture provided in an embodiment of the present application. The positional relationship between the devices, components, modules, etc. shown in the figure does not constitute any limitation.
[0061] In some embodiments, the data collection device 102, user device 101, training device 103 and execution device 104 may be the same device.
[0062] In some embodiments, the acquisition device 102, training device 103 and execution device 104 may be the same device, such as the same server, and the user device 101 may be another device.
[0063] The above-mentioned database 105 can be distributed on one server or on multiple servers, and the above-mentioned content library 106 can be distributed on one server or on multiple servers.
[0064] Currently, the BERT model is used to implement the classification of long texts. Specifically, the basic BERT model is unsupervisedly pre-trained using massive amounts of text, and the pre-trained BERT model is fine-tuned on downstream text classification tasks to obtain the final BERT model for text classification. The BERT model has a limitation on the encoding length, and the maximum input text length supported by a single encoding is 512. When the input is a long text (that is, the length of the input text is greater than 512), a sliding window is generally used to segment the text, and the classification results of each window are obtained through the BERT model. Finally, each window votes to determine the final classification result.
[0065] The sliding window method can solve the problem of long texts with relatively uniform topics throughout the text, but because each window independently judges the classification results, when the classification results of two or more windows disagree, voting cannot be used to select the appropriate result. For example, in the dialogue scenario involved in an embodiment of the present application, the topic may be constantly changing, and it is necessary to integrate the contextual semantic information of each window to accurately judge the category division of the full text. For example, the beginning of the dialogue may be about issues related to "credits and debts", and in-depth understanding reveals that the main topic involves "divorce disputes". Using a simple sliding window and voting mechanism will result in two or more windows selecting different labels and unable to vote. In other words, when the BERT model is currently used to implement long text classification, there is a problem of inaccurate classification.
[0066] In order to solve the above technical problems, the present application divides the acquired target long text into N sequences and inputs them into the target model to obtain text representations of the N sequences respectively, and fuses the text representations of the N sequences to obtain the chapter representation of the target long text, and then classifies the target long text according to the chapter representation to obtain the classification result of the target long text. In other words, the present application fuses the text representations of the N sequences of the target long text to obtain the chapter representation of the entire target long text, and the chapter representation integrates the full-text semantic information and contextual information of the target long text, so that when performing text classification based on the chapter representation, the classification accuracy of the target long text can be improved.
[0067] The technical solutions of the embodiments of the present application are described in detail below through some embodiments. The following embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments.
[0068] Figure 2 A flowchart of a long text classification method provided in an embodiment of the present application is shown in FIG. Figure 2 As shown, including:
[0069] S201. Divide the acquired target long text into N sequences and input them into the target model to obtain text representations of the N sequences respectively.
[0070] Wherein, N is a positive integer.
[0071] The execution subject of the embodiment of the present application is a device with a long text classification function, such as a long text classification device, which can be a computing device, or a part of a computing device, such as a processor in a computing device. Figure 1 The execution device in Figure 1 The execution device in the description may be understood as a computing device, or a processor in a computing device.
[0072] For ease of description, the following embodiments are introduced by taking the execution subject as a computing device as an example.
[0073] The present application does not restrict the type of the target long text, which can be any type of long text to be classified generated in any scenario.
[0074] For example, the target long text is generated during a telephone consultation. For example, in a legal consultation hotline conversation scenario, the conversation content mainly includes the parties communicating with the lawyer about a specific event, and the lawyer giving advice. The above call is transcribed into text through voice, and the conversation text is as follows: Figure 3 The computing device of the present application can classify the above-mentioned conversation content into the defined consultation event type, so that Figure 3 The dialogue text shown is used as the target long text, and the classification method provided in the embodiment of the present application is executed to achieve classification.
[0075] The target model of the present application supports a limited amount of data, for example, supporting text input within 512 characters. Therefore, the target long text needs to be divided into N sequences.
[0076] In certain embodiments, the number of N sequences is fixed, so that the target long text can be divided into N sequences, and the number of characters included in each sequence in the N sequences can be the same or different, and the application does not limit this. For example, N is 10, and the target long text includes 2000 characters, then the target long text is evenly divided into 10 sequences, and each sequence includes 200 characters. For another example, if N is 10, and the target long text includes 1998 characters, then the target long text is divided into 10 sequences, and the first 9 sequences each include 200 characters, and the last sequence includes 198 characters. Optionally, the last sequence can be padded to 200 characters.
[0077] In some embodiments, the length of each sequence is fixed, so that the number of sequences obtained by dividing different long texts may be different. For example, the length of the sequence is 250 characters, and the target long text includes 2000 characters, then the target long text can be evenly divided into 8 sequences, each of which includes 250 characters. For another example, for example, the length of the sequence is 250 characters, and the target long text includes 1600 characters, then the target long text can be evenly divided into 7 sequences, the first 6 sequences each include 250 characters, and the last sequence includes 100 characters. Optionally, the last sequence can be padded to 250 characters.
[0078] In some embodiments, the target long text is divided according to a preset window length and a window sliding step. Specifically, the above S201 includes the following steps:
[0079] S201-A1, dividing the target long text into N sequences by using a preset window length and window sliding step size;
[0080] S201-A2: For each of the N sequences, input the sequence into the target model to obtain a text representation of the sequence.
[0081] In this embodiment, the target long text is slid on the preset window length and window sliding step, and then the target long text is divided into N sequences. Then, these N sequences are respectively input into the target model for processing to obtain the text representation of each sequence.
[0082] This application does not limit the specific value of the window length, for example, the window length is 512.
[0083] This application does not limit the specific value of the sliding step size of the window.
[0084] In some embodiments, the window sliding step size is equal to the window length, for example, both are 512, which can ensure that all information in the target long text is processed and there will be no problem of processing duplicate information.
[0085] In some embodiments, the window sliding step is greater than the window length, for example, the window sliding step is 600 and the window length is 512. Since the target long text includes more content, important information may appear repeatedly in the target text and will be selected multiple times in the subsequent selection process, while information that appears less frequently is often non-critical information. By setting a larger sliding step, these unimportant information can be eliminated, thereby reducing the amount of data to be processed and improving text classification efficiency.
[0086] In some embodiments, the window sliding step is smaller than the window length, for example, the window sliding step is 256 and the window length is 512. In this way, there is an overlap between two adjacent sequences (or two adjacent windows). When the target model processes a sequence with an overlap, more sufficient contextual semantic information can be obtained through the overlap, thereby improving the accuracy of classification.
[0087] In an embodiment of the present application, the target long text is divided into N sequences, and the N sequences are respectively input into the target model for feature extraction to obtain a text representation of each of the N sequences.
[0088] In this application, the text representation of a sequence can be understood as a representation vector of the sequence, and the text representation of the sequence is used for downstream classification tasks.
[0089] In some embodiments, the textual representation of the sequence is also referred to as the semantic representation of the sequence.
[0090] The present application does not impose any restrictions on the specific network structure of the target model, which can be any model that can predict the text representation of each sequence in N sequences. For example, the target model is a model based on convolutional neural networks (CNN), or it can be a model based on an attention mechanism.
[0091] In one possible implementation, the target model of the embodiment of the present application includes BERT, and the computing device of the present application obtains the text representation of each of the N sequences through the BERT in the target model.
[0092] Figure 4A A framework diagram of the BERT model involved in the embodiment of the present application is shown in FIG. Figure 4B This is a schematic diagram of the network structure of the BERT model involved in the embodiment of the present application. The BERT includes multiple bidirectional Transformers. It should be noted that: Figure 4B Trm in represents Transformer. Figure 4A As shown in Figure 1, the BERT model is mainly composed of three parts: embedding layer, encoding layer, and pooling layer. The following is a brief introduction to the network structure of the BERT model.
[0093] Embedding layer: Convert the input sequence into a continuous distributed representation, that is, convert the input sequence into a word embedding or word vector, such as Figure 4B E1, E2, etc.
[0094] Generally speaking, the input to BERT can be a sequence, such as each of the N sequences mentioned above.
[0095] BERT first uses a special tokenizer to tokenize the sequence. The tokenizer first performs rule-based tokenization on the sequence, and then performs word segmentation. The first token of each sequence is always a special classification token ([CLS]), and the output vector corresponding to the token is used as the text representation of the classification task. That is to say, in this application, the first word of each of the N sequences is marked as [CLS], and the vector corresponding to the [CLS] output by the BERT model is determined as the text representation of the sequence.
[0096] After segmentation, each substring segmented by a space is considered as a token, for example, each word in the sequence is considered as a token. In some embodiments, a token is also referred to as a token. Figure 4B In the text file, token is referred to as Tok.
[0097] The tagger maps these tags into integer codes via a table lookup.
[0098] The entire sequence is represented by three types of encoding vectors, including: tag encoding (also called token embeddings), segment encoding (also called segmentation embeddings), and position encoding (also called position embeddings). Among them, the tag encoding is the vector obtained by converting each tag in the sequence into an integer encoding. The segment encoding records which sequence each tag belongs to, 0 is the first sequence, and 1 is the second sequence. The position encoding records the position of each tag. It should be noted that the position encoding corresponding to the [CLS] tag is 0.
[0099] like Figure 4B As shown, the embedding vector output by the embedding layer is denoted as E, the output vector (i.e., feature representation) of the special [CLS] tag is denoted as C, and the output vector (i.e., feature representation) of the i-th input tag is denoted as Ti.
[0100] For a given token, its input representation is constructed by summing the corresponding token embeddings, segmentation embeddings, and position embeddings.
[0101] Encoding layer: It performs nonlinear representation on the embedding vector output by the embedding layer and extracts the feature representation.
[0102] Optionally, the encoding layer is composed of multiple Transformers.
[0103] Among them, Transformer consists of two parts: encoder and decoder. Optionally, the encoder consists of multiple (for example, 6) identical two sub-layers, the first sub-layer is a multi-head attention layer, and the second sub-layer is a general feedforward neural network. The decoder consists of multiple (for example, 6) identical three sub-layers, the first sub-layer is a masked multi-head attention layer, the second sub-layer is a multi-head attention layer, and the third sub-layer is a general feedforward neural network.
[0104] Pooling layer: It takes out the representation corresponding to the [CLS] tag, makes some transformations, and outputs it as the representation of the entire sequence, and outputs the feature representation of each tag output by the last layer of the encoding layer intactly.
[0105] like Figure 4B As shown, BERT training includes pre-training and fine-tuning. At present, the pre-training model obtains rich syntactic and semantic prior knowledge of natural language through unsupervised training on massive natural language texts. Fine-tuning with a small amount of data on natural language processing (NLP) tasks such as text classification can achieve good results. This application uses the BERT-base model structure as an encoder and fine-tunes it on classification tasks. BERT-base is a 12-layer Transformer network structure.
[0106] In some embodiments, the pre-trained model uses BERT-wwm-ext, which is a Chinese pre-trained model based on full-word mask (Mask). In conventional BERT-base, Chinese is segmented based on characters, without taking into account Chinese word segmentation (CWS) in traditional NLP. In the full-word mask, if a subword of a complete word (Word Piece) is masked, other parts of the word will also be masked. BERT-wwm-ext uses general corpus such as Chinese Wikipedia, Q&A, and news for training, and can achieve better results on Chinese data sets.
[0107] In the embodiment of the present application, if the above-mentioned target model includes BERT, the present application divides the acquired target long text into N sequences, and then inputs the N series into BERT respectively. BERT processes each sequence in the N sequences in the same way, and takes a sequence 1 as an example for explanation. First, sequence 1 is marked by the marker in BERT, and the first word in sequence 1 is specifically marked as [CLS]. Next, the tag embedding, segment embedding and position embedding of sequence 1 are determined, and the word embedding of sequence 1 is obtained by summing the tag embedding, segment embedding and position embedding, and the word embedding is input into the encoding layer (i.e., input Transformer). The encoding layer in BERT processes the word embedding input by the embedding layer to obtain the feature representation of sequence 1, and the feature representation of sequence 1 is input into the pooling layer to obtain the representation corresponding to the [CLS] tag in sequence 1 output by the pooling layer, and the representation corresponding to the [CLS] tag is determined as the text representation of sequence 1, which is used for downstream classification tasks. With reference to the above-mentioned sequence 1, the text representation of each sequence in the N sequences can be obtained by BERT.
[0108] S202: Fuse the text representations of the N sequences to obtain the chapter representation of the target long text.
[0109] This application does not limit the specific method for fusing the text representations of N sequences.
[0110] In one approach, N sequences of text representations are concatenated and input into a convolutional layer or convolutional network to obtain a feature vector, which is determined as the chapter representation of the target long text.
[0111] Optionally, the chapter representation of the target long text has the same dimension as the text representation of each of the N sequences, for example, both are 768.
[0112] In another way, Figure 5A As shown, the target model of the present application includes a fusion module. At this time, the above S202 implements fusion through the following S202-A1 and S202-A2 steps:
[0113] S202-A1, merging the text representations of N sequences to obtain a merge matrix;
[0114] S202-A2, input the merged matrix into the fusion module to obtain the chapter representation of the target long text output by the fusion module.
[0115] Exemplarily, assuming N=3, the dimension of the text representation output by each sequence is 768, and therefore, the size of the merged matrix A obtained by merging the text representations of N sequences is 3X768.
[0116] The basic idea of the fusion module of the present application is to calculate the weights of different parts and then perform weighted summation to achieve different degrees of attention to different parts.
[0117] In some embodiments, the above-mentioned fusion module can be understood as a pre-trained network model. The merge matrix is input into the fusion module for fusion processing to obtain a fusion vector output by the fusion module, and the fusion vector is determined as the chapter representation of the target long text.
[0118] This application does not limit the specific network structure of the fusion module.
[0119] In some embodiments, the fusion module includes a convolutional layer or a convolutional network, which performs feature extraction on the merged matrix A and determines the extracted feature information as a chapter representation of the target long text.
[0120] In some embodiments, Figure 5B As shown, the fusion module includes a linear transformation layer and a fusion layer. In this case, the above S202-A2 includes the following steps:
[0121] S202-A21, input the merged matrix into the linear transformation layer, and respectively undergo linear transformation of the first weight matrix, the second weight matrix, and the third weight matrix to obtain a first matrix, a second matrix, and a third matrix;
[0122] S202-A22, input the first matrix, the second matrix and the third matrix into the fusion layer to obtain the chapter representation of the target long text.
[0123] Specifically, the merge matrix A is input into the linear transformation layer, which uses the first weight matrix W Q Perform a linear transformation on the merged matrix A to obtain the first matrix Q, and use the second weight matrix W K Perform a linear transformation on the merged matrix A to obtain the second matrix K, using the third weight W V The matrix performs a linear transformation on the merged matrix A to obtain the third matrix V.
[0124] For example, Q = W Q A.
[0125] For example, K = W K A.
[0126] For example, V = W V A.
[0127] It should be noted that the above matrix operations are all dot products between two matrices.
[0128] Then, if Figure 5BAs shown, the first matrix, the second matrix and the third matrix are input into the fusion layer to obtain the chapter representation of the target long text.
[0129] The fusion layer of the present application is used to fuse the first matrix, the second matrix and the third matrix to obtain the chapter representation of the target long text.
[0130] This application does not limit the specific network structure of the fusion layer.
[0131] In some embodiments, the fusion layer is a neural network, which can perform fusion processing on the input matrix to obtain a fusion vector, and determine the fusion vector as the chapter representation of the target long text.
[0132] In some embodiments, the fusion layer includes at least one convolution layer, and the first matrix, the second matrix, and the third matrix are cascaded or otherwise merged and input into at least one convolution layer for feature extraction, and the extracted features are determined as the chapter representation of the target long text.
[0133] In some embodiments, Figure 5C As shown, the fusion layer includes a fusion unit and a normalization unit. At this time, the above S202-A22 includes the following steps:
[0134] S202-A221, input the first matrix and the second matrix into a fusion unit, and determine a ratio of a transpose of the second matrix multiplied by the first matrix to a scale, where the scale is related to an output dimension of the sequence;
[0135] S202-A222, input the above ratio into a normalization unit to obtain the weights of the text representations of the N sequences;
[0136] S202-A223, multiply the weights of the text representations of the N sequences by the third matrix to obtain the chapter representation of the target long text.
[0137] Specifically, the first matrix and the second matrix are input into the fusion unit, and the transpose K of the first matrix Q and the second matrix K is fused by the fusion unit. T To maintain the gradient stability and avoid excessive dot product results, we need to divide by the scale to get the ratio B, which is a matrix. The scale is the same as the output dimension d of the sequence. k Related, for example, scaled as d k 1 / 2. Next, the ratio B determined above is normalized by a normalization unit to obtain the weight distribution of the text representation of each sequence, that is, the weight of the text representation of each sequence in the N sequences is obtained, and the weight of the text representation is also a matrix. Then, the weights of the text representation of the N sequences are multiplied by the third matrix V to obtain the final product result, and the final product result is used as the chapter representation of the target long text. The chapter representation integrates the important information of each sequence in the N sequences, so that when classification is performed based on the chapter representation, the accuracy of classification can be improved.
[0138] Optionally, the normalization unit includes an activation function, and the ratio B is normalized by the activation function. The present application does not limit the type of activation function included in the normalization unit. Exemplarily, the activation function included in the normalization unit is a softmax activation function, and the present application normalizes the ratio B by the softmax activation function.
[0139] In some embodiments, the fusion module uses a Self Attention mechanism for fusion.
[0140] Exemplarily, the above fusion layer determines the chapter representation of the target long text through the following formula (1):
[0141]
[0142] Among them, Attention(Q,K,V) is the chapter representation of the target long text. It can be understood that the fusion unit processes the first matrix and the second matrix to obtain the ratio B, and softmax() can be understood as the activation function included in the normalization unit.
[0143] S203. Obtain a classification result of the target long text according to the chapter representation of the target long text.
[0144] The chapter representation of the target long text obtained in the above steps represents the overall feature information of the target long text. Based on this, an accurate classification result of the target long text can be obtained according to the chapter representation of the target long text.
[0145] In one example, the chapter representation representing the overall feature information of the target long text is input into a preset classification network to obtain the classification result of the target long text. The present application does not limit the specific network structure of the preset classification network, as long as text classification can be achieved based on the chapter representation.
[0146] In another example, Figure 5D As shown, the target model of the present application also includes a fully connected layer. In this case, the above S203 includes the following steps:
[0147] S203-A1, input the chapter representation of the target long text into the fully connected layer to obtain the predicted probabilities of M labels, where M is a positive integer;
[0148] S203-A2: According to the predicted probabilities of the M labels, the classification result of the target long text is obtained.
[0149] In the embodiment of the present application, after obtaining the text representation of the entire chapter of the target long text according to the above steps, the dimension of the chapter representation is converted into the dimension of the number of labels through the fully connected layer, for example, from 768 to the dimension of the number of labels, and the model's predicted probability for each label is obtained. The labels of this application can be understood as classification labels, which are preset. This application does not limit the specific category and number of labels, which are determined according to actual needs. For example, the above M=3, and the three labels are inheritance, marriage, and education.
[0150] For example, for a single-label classification task, the predicted probability distributions of all categories are normalized by the softmax function, and the label with the highest probability is selected as the classification result of the target long text.
[0151] Exemplarily, for a multi-label classification task, the predicted probability of each category output by the model is normalized to between 0 and 1 through a sigmoid function. A threshold is then used to determine whether to output the probability of the label. Optionally, a value between 0 and 1 that can give the label the highest evaluation index score is dynamically selected on the test set as the threshold for outputting the answer for each label.
[0152] In a specific embodiment of the present application, Figure 6 As shown, the target model of the present application includes BERT, a fusion module and a fully connected layer. Optionally, the fusion module is a Self Attention fusion module, and the fully connected layer includes a normalization function, such as a sigmoid function. Figure 6As shown, the target long text is "I have a loan note...debt." A sliding window is used to divide the target long text into N sequences according to the preset window length and window sliding step. The first token of each sequence is set to [CLS], which is used as the output to express the text information of the entire sequence. The N sequences are input into the target model to obtain the text representation of each sequence, that is, the output vector corresponding to the first token of each sequence is determined as the text representation of each sequence. Next, the text representations of the N sequences are cascaded and input into the fusion module. Exemplarily, if the dimension of the text representation of each sequence is 768, the size of the cascaded text representation is 768*N. The fusion module performs fusion processing according to the steps in S203 above, and outputs the chapter representation of the target long text. Optionally, the dimension of the chapter representation is 768. Next, the passage representation is input into the fully connected layer (FC) for classification processing. For example, for a multi-label classification task, the predicted probability of each category output by the model is normalized to between 0 and 1 by a sigmoid function, and then the probability of each label is determined based on the threshold to determine whether to output the probability of the label. For example, the output after judging the threshold is as follows: Figure 6 The classification result shown in FIG. The classification result includes the probability that the target long text belongs to different classification categories. In this way, the classification category with the highest probability is determined as the classification category of the target long text, for example Figure 6 The target long text "I have a loan note...debt" is classified into credits and debts.
[0153] The long text classification method provided in the embodiment of the present application is to obtain the text representation of N sequences by dividing the acquired target long text into N sequences and inputting them into the target model, respectively, and N is a positive integer; the text representation of the N sequences is fused to obtain the chapter representation of the target long text; and the classification result of the target long text is obtained according to the chapter representation of the target long text. That is to say, the present application fuses the text representation of the N sequences of the target long text to obtain the chapter representation of the entire target long text, and the chapter representation can characterize the semantic information and contextual information of the entire target long text, so that when the classification is performed based on the chapter representation of the entire target long text, the classification accuracy of the target long text can be improved.
[0154] The above describes the long text classification method provided in the embodiments of the present application. In some embodiments, the present application also relates to the training process of the target model.
[0155] Figure 7 A flowchart of a long text classification method provided in an embodiment of the present application is shown in FIG. Figure 7 As shown, including:
[0156] S701. For the unlabeled ith text in the training data set, input the ith text into the target model after Q rounds of training to determine the probability of the ith text with respect to P categories.
[0157] Wherein, Q and P are both positive integers.
[0158] Training data plays a vital role in the effectiveness of model training. In the hotline conversation classification scenario involved in this application, there are a large number of naturally generated hotline conversation texts, which are long and difficult to label. There is a long tail phenomenon in the classification labels. If the data is randomly sampled for labeling, invalid labeling is likely to occur, that is, a large amount of data that the model has learned to classify will continue to be labeled, while a small amount of data that the model needs to learn, such as long-tail labels, will rarely be labeled, which will waste labeling time and manpower.
[0159] In order to solve the above technical problems, the present application uses an active learning method to select high-quality data sets for annotation, which not only reduces the time and manpower of annotation, but also enables the model to learn unlearned data, thereby achieving sufficient training of the model and obtaining better classification results.
[0160] In the actual classification system, the model iteration process is generally to first label a batch of data, then train the model, and verify the effect. When the effect index does not reach the target, a batch of additional data sets are labeled for training and verification, and this process is repeated until the index reaches the expected level or the effect no longer increases.
[0161] This application selects a batch of high-quality data sets from the unlabeled candidate pool for annotation every time training data is added, so that the model training effect is better. In this process, before the first training, all data are unlabeled, and unsupervised data set selection is required. For example, the K-means clustering method is used to divide all the sentences of the text into a specific category, and then the chapter containing the most sentence categories is selected as the initial selected data set. The selected data set contains better sample diversity, which can enable the model to learn more comprehensive information.
[0162] After a round of training, if the effect is not up to standard and additional data is needed, you can select high-quality data for the trained model in a supervised manner. For example, 300 pieces of data of the "consumer rights protection" type have been labeled, and the model has fully learned the classification of this type of data. In the future, the same type of data can no longer be labeled, and it is mainly necessary to select data that the model is not sure about for labeling. For example, the classification type of "creditor's rights and debtor's rights" with 10 labeled articles is still a relatively difficult type for the model. These data are of higher value for the current model. Using these high-value data for model training can achieve better results than randomly sampling and selecting training data.
[0163] The target model of this application can output the confidence of the classification result for each piece of data to be annotated. When the target model has a high confidence in a certain type of label, it means that the classification category of this data has been relatively determined, and the value of annotation is not high. On the contrary, when the confidence of all classification labels is not high, it means that the target model is uncertain about the classification result of this data, and annotated data is needed to participate in training to improve the model effect.
[0164] This application continuously selects data that is useful for improving the model for annotation, using less data to achieve better training results, thereby saving annotation time and manpower.
[0165] The specific process of model training in this application is as follows Figure 8 As shown, first use the target model (also called the long text classification model) to obtain the classification probability of each unlabeled text in the training data set, and determine the uncertainty score of each text based on the classification probability. Select data with higher uncertainty scores from the unlabeled data for labeling to obtain labeled data. Use these labeled data to train the target model to obtain the target model after one round of training. Repeat Figure 8 The steps shown can obtain the final trained target model.
[0166] It should be noted that in each round of training, the process of selecting the data to be labeled is the same, and in each selection process of the data to be labeled, the selection process of each data to be labeled is also the same. For ease of description, this embodiment takes the unlabeled i-th text in the training data set as an example for explanation, and the i-th text is any unlabeled text in the training data set.
[0167] During the Q+1th round of training, for the unlabeled i-th text in the training data set, the i-th text is input into the target model after Q rounds of training to determine the probability of the i-th text with respect to P categories.
[0168] In some embodiments, if the i-th text is a long text, it is necessary to divide the i-th text into multiple sequences and input them into the target model to determine the probability of the i-th text with respect to P categories. Specifically, the above S701 includes the following steps S701-A1 to S701-A3:
[0169] S701-A1. Divide the i-th text into K sequences and input them into the target model to obtain text representations of the K sequences respectively, where K is a positive integer.
[0170] The specific implementation process of the above S701-A1 can refer to the description of the above S201, which will not be repeated here.
[0171] S701-A2: Fuse the text representations of the K sequences to obtain the chapter representation of the i-th text.
[0172] The specific implementation process of the above S701-A2 can refer to the description of the above S202, which will not be repeated here.
[0173] S701-A3. According to the chapter representation of the ith text, obtain the probability of the ith text with respect to P categories.
[0174] The specific implementation process of the above S701-A3 can refer to the description of the above S203, which will not be repeated here.
[0175] S702: Determine the uncertainty score of the ith text according to the probability of the ith text with respect to P categories.
[0176] Optionally, the uncertainty score of a single text can be represented by the information entropy of the output classification probability.
[0177] According to different classification tasks, the implementation process of S702 includes the following two cases:
[0178] Case 1: If the target model is used for a single-label classification task, the above S702 includes the following steps:
[0179] S702-A1. For each of the P categories, multiply the probability of the category by the logarithm of the probability of the category to obtain a product corresponding to the category, and add the products corresponding to all the categories in the P categories to obtain a first sum;
[0180] S702-A2: Determine the negative of the first sum as the uncertainty score of the i-th text.
[0181] Exemplarily, the uncertainty score of the i-th text is obtained by the following formula (2):
[0182]
[0183] Among them, H(X) is the uncertainty score of the i-th text, p(x j ) is the probability that the i-th text belongs to the j-th category.
[0184] Case 2: If the target model is used for a multi-label classification task, the above S702 includes the following steps:
[0185] S702-B1. For each of the P categories, multiply the probability of the category by the logarithm of the probability of the category to obtain a first product of the category;
[0186] S702-B2, determining a first difference between one and the probability of the classification, and a second difference between one and the logarithm of the probability of the classification, and multiplying the first difference by the second difference to obtain a second product of the classification;
[0187] S702-B3. Determine the difference between the negative of the first product and the second product as the uncertainty score of the i-th text regarding classification.
[0188] In multi-label classification tasks, the probability distribution of each category label prediction is a binomial distribution, with only two results: yes or no. Therefore, the uncertainty score of each category can be represented by binary entropy.
[0189] Exemplarily, the uncertainty score of the i-th text with respect to the classification is obtained by the following formula (3):
[0190] H(X)=-p(x j )log(p(x j ))-(1-p(x j ))(1-log(p(x j )) (3)
[0191] According to the method of the above case 1 or case 2, the uncertainty score of the i-th text can be obtained. Then, the following steps S703 and S704 are performed.
[0192] S703: If the uncertainty score of the i-th text is greater than a preset value, the i-th text is marked.
[0193] This application does not limit the specific values of the above preset values.
[0194] S704: Use the annotated i-th text to train the target model.
[0195] In actual annotation, the unlabeled samples are sorted according to the calculation method of uncertainty scores of different tasks, and the data with high uncertainty are selected for annotation. The labeled data is used to train the model, and the annotation and training are iterated multiple times to obtain the final trained target model. Experiments have shown that in text classification tasks, the training data annotation method provided in the embodiment of the present application can achieve the same or better training effect using less data than randomly sampling and annotating data.
[0196] In the embodiment of the present application, valuable data is selected as a training set for annotation during the annotation process, so that the model can achieve the target effect while effectively reducing the amount of annotation required for training, thereby speeding up the training and annotation process.
[0197] The preferred embodiments of the present application are described in detail above in conjunction with the accompanying drawings. However, the present application is not limited to the specific details in the above embodiments. Within the technical concept of the present application, the technical solution of the present application can be subjected to a variety of simple modifications, and these simple modifications all belong to the protection scope of the present application. For example, the various specific technical features described in the above specific embodiments can be combined in any suitable manner without contradiction. In order to avoid unnecessary repetition, the present application will not further explain various possible combinations. For another example, the various different embodiments of the present application can also be arbitrarily combined, as long as they do not violate the ideas of the present application, they should also be regarded as the contents disclosed in the present application.
[0198] It should also be understood that in the various method embodiments of the present application, the size of the serial numbers of the above-mentioned processes does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
[0199] Combination of the above Figures 2 to 8 , describes in detail the method embodiment of the present application, and the following is combined with Figures 9 to 11 , describe in detail the device embodiments of the present application.
[0200] Fig. 9 A schematic diagram of a long text classification device provided in an embodiment of the present application. The long text classification device 20 may be a computing device or a component of a computing device (eg, an integrated circuit, a chip, etc.) for executing the above classification method.
[0201] A determination unit 21 is used to divide the acquired target long text into N sequences and input the sequences into the target model to obtain text representations of the N sequences respectively, where N is a positive integer;
[0202] A processing unit 22 is used to fuse the text representations of the N sequences to obtain a chapter representation of the target long text;
[0203] The classification unit 23 is used to obtain a classification result of the target long text according to the chapter representation of the target long text.
[0204] In some embodiments, the target model includes a fusion module, a processing unit 22, which is specifically used to merge the text representations of the N sequences to obtain a merged matrix; input the merged matrix into the fusion module to obtain the chapter representation of the target long text output by the fusion module.
[0205] In some embodiments, the fusion module includes a linear transformation layer and a fusion layer, and the processing unit 22 is specifically used to input the merged matrix into the linear transformation layer, and obtain the first matrix, the second matrix and the third matrix through linear transformation of the first weight matrix, the second weight matrix and the third weight matrix respectively; the first matrix, the second matrix and the third matrix are input into the fusion layer to obtain the chapter representation of the target long text.
[0206] In some embodiments, the fusion layer includes a fusion unit and a normalization unit, and the processing unit 22 is specifically used to input the first matrix and the second matrix into the fusion unit, determine the ratio of the transpose of the second matrix multiplied by the first matrix and the scale, and the scale is related to the output dimension of the sequence; input the ratio into the normalization unit to obtain the weights of the text representation of the N sequences; multiply the weights of the text representation of the N sequences by the third matrix to obtain the chapter representation of the target long text.
[0207] Optionally, the normalization unit includes a softmax activation function.
[0208] In some embodiments, the target model also includes a fully connected layer, a classification unit 23, which is specifically used to input the chapter representation of the target long text into the fully connected layer to obtain the predicted probabilities of M labels, where M is a positive integer; and obtain the classification results of the target long text based on the predicted probabilities of the M labels.
[0209] In some embodiments, the determination unit 21 is specifically used to divide the target long text into N sequences through a preset window length and a window sliding step; for each sequence in the N sequences, the sequence is input into the target model to obtain a text representation of the sequence.
[0210] Optionally, the window sliding step size is smaller than the window length.
[0211] In some embodiments, Fig.10The model also includes a training unit 24, and the training unit 25 is specifically used to input the i-th text that is not labeled in the training data set into the target model after Q rounds of training, and obtain the probability of the i-th text output by the target model with respect to P categories, wherein Q and P are both positive integers; determine the uncertainty score of the i-th text according to the probability of the i-th text with respect to the P categories; if the uncertainty score of the i-th text is greater than a preset value, label the i-th text; and use the labeled i-th text to train the target model.
[0212] In some embodiments, if the target model is used for a single-label classification task, the training unit 24 is specifically used to multiply the probability of the classification by the logarithm of the probability of the classification for each of the P classifications to obtain the product corresponding to the classification, and add the products corresponding to all the P classifications to obtain a first sum; the negative of the first sum is determined as the uncertainty score of the i-th text.
[0213] In some embodiments, if the target model is used for a multi-label classification task, the training unit 24 is specifically used to multiply the probability of the classification by the logarithm of the probability of the classification for each of the P classifications to obtain a first product of the classification; determine a first difference between one and the probability of the classification, and a second difference between one and the logarithm of the probability of the classification, and multiply the first difference by the second difference to obtain a second product of the classification; and determine the difference between the negative of the first product and the second product as the uncertainty score of the i-th text with respect to the classification.
[0214] In some embodiments, if the i-th text is a long text, the training unit 24 is specifically used to divide the i-th text into K sequences and input them into the target model to obtain text representations of the K sequences respectively, where K is a positive integer; fuse the text representations of the K sequences to obtain the chapter representation of the i-th text; and obtain the probability of the i-th text regarding P categories based on the chapter representation of the i-th text.
[0215] It should be understood that the device embodiment and the method embodiment may correspond to each other, and similar descriptions may refer to the method embodiment. To avoid repetition, they will not be described here. Specifically, Fig. 9 and Fig.10 The device 20 shown can correspond to the corresponding subject in the method of executing the embodiment of the present application, and the aforementioned and other operations and / or functions of each module in the device are respectively for implementing the corresponding processes in the above method. For the sake of brevity, they will not be repeated here.
[0216] The above describes the device of the embodiment of the present application from the perspective of the functional module in conjunction with the accompanying drawings. It should be understood that the functional module can be implemented in hardware form, can be implemented by instructions in software form, and can also be implemented by a combination of hardware and software modules. Specifically, the steps of the method embodiment in the embodiment of the present application can be completed by the hardware integrated logic circuit and / or software form instructions in the processor, and the steps of the method disclosed in the embodiment of the present application can be directly embodied as a hardware processor to execute, or a combination of hardware and software modules in the processor to execute. Optionally, the software module can be located in a mature storage medium in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, an electrically erasable programmable memory, a register, etc. The storage medium is located in a memory, and the processor reads the information in the memory, and completes the steps in the above method embodiment in conjunction with its hardware.
[0217] Fig.11 is a block diagram of a computing device involved in an embodiment of the present application, which may be Figure 1 The execution device shown is used to execute the method described in the above embodiment. For details, please refer to the description in the above method embodiment.
[0218] Fig.11 The computing device 200 shown includes a memory 201, a processor 202, and a communication interface 203. The memory 201, the processor 202, and the communication interface 203 are communicatively connected to each other. For example, the memory 201, the processor 202, and the communication interface 203 can be communicatively connected by a network connection. Alternatively, the computing device 200 may further include a bus 204. The memory 201, the processor 202, and the communication interface 203 are communicatively connected to each other via the bus 204. Fig.11 The computing device 200 is a memory 201 , a processor 202 , and a communication interface 203 that are communicatively connected to each other via a bus 204 .
[0219] The memory 201 may be a read-only memory (ROM), a static storage device, a dynamic storage device or a random access memory (RAM). The memory 201 may store a program. When the program stored in the memory 201 is executed by the processor 202, the processor 202 and the communication interface 203 are used to execute the above method.
[0220] The processor 202 may be a general-purpose central processing unit (CPU), a microprocessor, an application specific integrated circuit (ASIC), a graphics processing unit (GPU), or one or more integrated circuits.
[0221] The processor 202 may also be an integrated circuit chip with signal processing capabilities. In the implementation process, the method of the present application may be completed by an integrated logic circuit of hardware in the processor 202 or instructions in the form of software. The above-mentioned processor 202 may also be a general-purpose processor, a digital signal processor (digital signal processing, DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (field programmable gate array, FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc. The software module may be located in a mature storage medium in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 201, and the processor 202 reads the information in the memory 201, and completes the method of the embodiment of the present application in combination with its hardware.
[0222] The communication interface 203 uses a transceiver module such as, but not limited to, a transceiver to implement communication between the computing device 200 and other devices or a communication network. For example, a data set can be obtained through the communication interface 203 .
[0223] When the computing device 200 described above includes a bus 204 , the bus 204 may include a path for transmitting information between various components of the computing device 200 (eg, the memory 201 , the processor 202 , and the communication interface 203 ).
[0224] According to the present application, a computer storage medium is also provided, on which a computer program is stored, and when the computer program is executed by a computer, the computer can perform the method of the above method embodiment. In other words, the present application embodiment also provides a computer program product containing instructions, and when the instructions are executed by a computer, the computer can perform the method of the above method embodiment.
[0225] According to the present application, a computer program product or a computer program is also provided, the computer program product or the computer program includes computer instructions, the computer instructions are stored in a computer-readable storage medium. The processor of the computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the method of the above method embodiment.
[0226] In other words, when implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function according to the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions may be transmitted from a website site, a computer, a server, or a data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (digital subscriber line, DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, server, or data center. The computer-readable storage medium may be any available medium that a computer can access or a data storage device such as a server or a data center that includes one or more available media integrated. The available medium may be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a digital video disc (digital video disc, DVD)), or a semiconductor medium (e.g., a solid state drive (solid state disk, SSD)), etc.
[0227] Those of ordinary skill in the art will appreciate that the modules and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0228] In the several embodiments provided in the present application, it should be understood that the disclosed systems, 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 module is only a logical function division. There may be other division methods in actual implementation, such as multiple modules 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 modules, which can be electrical, mechanical or other forms.
[0229] The modules described as separate components may or may not be physically separated, and the components displayed as modules may or may not be physical modules, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. For example, each functional module in each embodiment of the present application may be integrated into a processing module, or each module may exist physically separately, or two or more modules may be integrated into one module.
[0230] Those skilled in the art can clearly understand that, for the convenience and simplicity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments, and will not be repeated here. In addition, various method embodiments and various device embodiments can also refer to each other, and the same or corresponding contents in different embodiments can be quoted from each other without repeated description.
Claims
1. A long text classification method, characterized in that: include: Divide the acquired target long text into N sequences and input them into the target model to obtain text representations of the N sequences respectively, where N is a positive integer; Merging the text representations of the N sequences to obtain a merged matrix, and inputting the merged matrix into a linear transformation layer in a fusion module included in the target model, and performing linear transformations of a first weight matrix, a second weight matrix, and a third weight matrix respectively to obtain a first matrix, a second matrix, and a third matrix; Inputting the first matrix, the second matrix and the third matrix into the fusion layer in the fusion module for fusion, so as to obtain the chapter representation of the target long text; The chapter representation of the target long text is input into the fully connected layer in the target model for processing to obtain the prediction probabilities of M labels, and the classification result of the target long text is obtained according to the prediction probabilities of the M labels, where M is a positive integer.
2. The method according to claim 1, characterized in that The fusion layer includes a fusion unit and a normalization unit. The first matrix, the second matrix and the third matrix are input into the fusion layer in the fusion module for fusion to obtain the chapter representation of the target long text, including: Inputting the first matrix and the second matrix into the fusion unit, determining a ratio of a transpose of the second matrix multiplied by the first matrix to a scale, wherein the scale is related to an output dimension of the sequence; Inputting the ratio into the normalization unit to obtain the weights of the text representations of the N sequences; The weights of the text representations of the N sequences are multiplied by the third matrix to obtain the chapter representation of the target long text.
3. The method according to claim 2, characterized in that The normalization unit includes a softmax activation function.
4. The method according to any one of claims 1 to 3, characterized in that: The obtained target long text is input into the target model to obtain N sequences of text representations, including: Divide the target long text into N sequences by using a preset window length and window sliding step size; For each of the N sequences, the sequence is input into the target model to obtain a text representation of the sequence.
5. The method according to claim 4, characterized in that The window sliding step size is smaller than the window length.
6. The method according to any one of claims 1 to 3, characterized in that: The method further comprises: For the unlabeled i-th text in the training data set, input the i-th text into the target model after Q rounds of training to determine the probability of the i-th text with respect to P categories, where Q and P are both positive integers; Determining an uncertainty score of the i-th text according to the probability of the i-th text with respect to the P categories; If the uncertainty score of the i-th text is greater than a preset value, the i-th text is marked; The target model is trained using the annotated i-th text.
7. The method according to claim 6, characterized in that If the target model is used for a single-label classification task, determining the uncertainty score of the i-th text according to the probability of the i-th text with respect to the P classifications includes: For each of the P categories, multiply the probability of the category by the logarithm of the probability of the category to obtain a product corresponding to the category, and add the products corresponding to all the categories in the P categories to obtain a first sum; The negative of the first sum is determined as the uncertainty score of the i-th text.
8. The method according to claim 6, characterized in that If the target model is used for a multi-label classification task, determining the uncertainty score of the i-th text according to the probability of the i-th text with respect to the P classifications includes: For each of the P categories, multiply the probability of the category by the logarithm of the probability of the category to obtain a first product of the category; determining a first difference between a probability and the classification, and a second difference between a probability and the logarithm of the classification, and multiplying the first difference by the second difference to obtain a second product of the classification; The difference between the negative of the first product and the second product is determined as the uncertainty score of the i-th text with respect to the classification.
9. The method according to claim 6, characterized in that If the i-th text is a long text, the i-th text is input into the target model after Q rounds of training to determine the probability of the i-th text with respect to P categories, including: Divide the i-th text into K sequences and input them into the target model to obtain text representations of the K sequences respectively, where K is a positive integer; The text representations of the K sequences are fused to obtain the chapter representation of the i-th text; According to the chapter representation of the i-th text, the probability of the i-th text with respect to P categories is obtained.
10. A long text classification device, characterized in that: include: A determination unit, used for dividing the acquired target long text into N sequences and inputting the sequences into the target model to obtain text representations of the N sequences respectively, where N is a positive integer; A fusion unit is used to merge the text representations of the N sequences to obtain a merged matrix, and input the merged matrix into a linear transformation layer in a fusion module included in the target model, and respectively undergo linear transformations of a first weight matrix, a second weight matrix, and a third weight matrix to obtain a first matrix, a second matrix, and a third matrix; the first matrix, the second matrix, and the third matrix are input into a fusion layer in the fusion module to obtain a chapter representation of the target long text; The classification unit is used to input the chapter representation of the target long text into the fully connected layer in the target model for processing, obtain the prediction probabilities of M labels, and obtain the classification result of the target long text according to the prediction probabilities of the M labels, where M is a positive integer.
11. A computing device, characterized in that: include: Processor and memory; The memory is used to store computer programs; The processor is configured to execute the computer program to implement the method according to any one of claims 1 to 9.
12. A computer-readable storage medium, characterized in that: The storage medium includes computer instructions. When the instructions are executed by a computer, the computer implements the method according to any one of claims 1 to 9.
Citation Information
Patent Citations
Text recognition processing method and device, electronic equipment and storage medium
CN111832292A
Method and system for constructing text classification system, medium and electronic equipment
CN111966826A
