Method, device and storage medium for classifying an ultra-long text
By segmenting extremely long texts to generate partially overlapping text fragments and then classifying them using a text classification model trained to convergence, the problem of low classification accuracy for extremely long texts in existing technologies is solved, achieving higher classification accuracy.
Patent Information
- Application Number
- CN202311094610.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-28
- Publication Date
- 2025-12-30
- Estimated Expiration
- 2043-08-28
AI Technical Summary
The accuracy of classification results for extremely long texts in existing technologies is low, mainly due to the independent processing of text fragments.
By segmenting extremely long texts, text fragments with partial overlap are generated, and then classified using a text classification model trained to convergence. The model is trained on a training sample set to ensure that there are connections between the text fragments.
It improves the accuracy of ultra-long text classification by obtaining more accurate classification results through reasonable text segmentation and training model optimization.
Smart Images

Figure CN117150013B_ABST
Abstract
Description
Technical Field
[0001] This application relates to artificial intelligence technology, and more particularly to a method, apparatus, device, and storage medium for classifying extremely long texts. Background Technology
[0002] As society and work require development, a large amount of data is generated, including extremely long texts. In some scenarios, in order to save extremely long texts in an orderly manner, each extremely long text can be classified, and then the same type or nearly the same type can be saved to the same storage path to achieve orderly saving of extremely long texts.
[0003] In existing technologies, a long string of text is segmented into multiple text fragments, and the feature vectors corresponding to each text fragment are obtained. The corresponding feature vectors are then fused to obtain the target feature vector, which is then input into a preset classification model to obtain the classification result of the long text.
[0004] However, in existing technologies, very long texts are divided into multiple text segments from left to right on an equal basis. When classifying based on these multiple text segments, the accuracy of the classification results for very long texts is often low. Summary of the Invention
[0005] This application provides a method, apparatus, device, and storage medium for classifying extremely long texts, in order to solve the problem of low accuracy in the classification results of extremely long texts.
[0006] Firstly, this application provides a method for classifying extremely long texts, the method comprising:
[0007] Obtain the target long text to be classified;
[0008] The target long text is segmented to obtain multiple target text segments; the multiple target text segments have the same character length; a portion of any target text segment overlaps with a portion of an adjacent target text segment; the portion of the segment includes at least one of a preceding segment and a following segment;
[0009] Determine the target text vector corresponding to each target text segment;
[0010] Each of the target text vectors is input into a text classification model that has been trained to convergence, and the classification result of the target long text is obtained using the text classification model that has been trained to convergence. The text classification model that has been trained to convergence is obtained by training an initial text classification model using a training sample set, which includes multiple training samples. The training samples include multiple training text vectors and their corresponding actual classification sub-results. The multiple training text vectors are obtained based on the multiple training text segments. The multiple training text segments are segmented from the long training text. The multiple training text segments have the same character length. Parts of any training text segment overlap with parts of its adjacent training text segments.
[0011] Secondly, this application provides a classification device for extremely long texts, the device comprising:
[0012] The acquisition module is used to acquire the target long text to be classified;
[0013] A segmentation module is used to segment the target long text to obtain multiple target text segments; the multiple target text segments have the same character length; a portion of any target text segment overlaps with a portion of an adjacent target text segment; the portion of the segment includes at least one of a preceding segment and a following segment;
[0014] The determination module is used to determine the target text vector corresponding to each target text fragment;
[0015] The acquisition module is used to input each of the target text vectors into a text classification model that has been trained to convergence, and to obtain the classification result of the target long text using the text classification model that has been trained to convergence. The text classification model that has been trained to convergence is obtained by training an initial text classification model using a training sample set, which includes multiple training samples. The training samples include multiple training text vectors and their corresponding actual classification sub-results. The multiple training text vectors are obtained based on the multiple training text segments. The multiple training text segments are segmented from the long training text. The multiple training text segments have the same character length. Parts of any training text segment overlap with parts of its adjacent training text segments.
[0016] Thirdly, this application provides an electronic device, including: a processor, and a memory and a transceiver communicatively connected to the processor;
[0017] The memory stores computer-executed instructions; the transceiver is used for sending and receiving data.
[0018] The processor executes computer execution instructions stored in the memory to implement the method as described in the first aspect or any of the above embodiments.
[0019] Fourthly, this application provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, are used to implement the method described in the first aspect or any of the above embodiments.
[0020] Fifthly, this application provides a computer program product, including a computer program that, when executed by a processor, implements the method described in the first aspect or any of the above embodiments.
[0021] Sixthly, this application provides a computer program product, including a computer program that, when executed by a processor, implements the method described in the first aspect or any of the above embodiments.
[0022] This application provides a method, apparatus, device, and storage medium for classifying extremely long texts. The classification apparatus (hereinafter referred to as the classification apparatus) acquires the target extremely long text to be classified, segments it, and obtains multiple target text segments. In this application, some segments of any target text segment overlap with some segments of adjacent target text segments. Due to this partial overlap, there is a connection between the target text segments, allowing characters in each target text segment to be connected. Each target text segment can connect preceding and following segments, rather than being isolated from each other, thus making the target text segments more reasonable. This further makes the target text vector more reasonable. Then, the target text is determined... The target text vector corresponding to the segment is then input into a text classification model trained to convergence to obtain the classification result. The text classification model trained to convergence in this application is trained based on multiple training samples, and the training text segments in this application also have partial overlap with their adjacent training text segments. It can be seen that during the training stage, the relationship between the training text segments is controlled to make the training text segments more reasonable. As a result, the model trained based on reasonable training text segments will be more optimized. Therefore, this application uses a more optimized text classification model trained to convergence to classify the target text vector, thereby obtaining a classification result with better accuracy. Attached Figure Description
[0023] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.
[0024] Figure 1 An application scenario diagram for the classification method of ultra-long text provided in this application;
[0025] Figure 2 This is a flowchart illustrating a method for classifying extremely long texts, as provided in Example 1.
[0026] Figure 3 This is a schematic diagram of multiple target text fragments provided in Example 1;
[0027] Figure 4 This is a flowchart illustrating a method for classifying extremely long texts, as provided in Example 3.
[0028] Figure 5 This is a flowchart illustrating a method for classifying extremely long texts, as provided in Example 4.
[0029] Figure 6 A flowchart illustrating a method for classifying extremely long texts, as provided in Example 6;
[0030] Figure 7 A flowchart illustrating a method for classifying extremely long texts, as provided in Example 7;
[0031] Figure 8 A schematic diagram of a classification device for ultra-long texts provided in Embodiment 9;
[0032] Figure 9 This is a schematic diagram of an electronic device structure provided in Embodiment 10.
[0033] The accompanying drawings illustrate specific embodiments of this application, which will be described in more detail below. These drawings and descriptions are not intended to limit the scope of the concept in any way, but rather to illustrate the concept of this application to those skilled in the art through reference to particular embodiments. Detailed Implementation
[0034] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.
[0035] In existing technologies, a long string of text is segmented into multiple text fragments, and the feature vectors corresponding to each text fragment are obtained. The corresponding feature vectors are then fused to obtain the target feature vector, which is then input into a preset classification model to obtain the classification result of the long text.
[0036] However, in existing technologies, when classifying texts using multiple fragments, each fragment is independent of the others, which can easily lead to lower accuracy in classifying very long texts.
[0037] To address the shortcomings of existing technologies, the inventors of this solution have creatively designed a new approach. This solution provides a classification method for extremely long texts. To solve the problem of low classification accuracy, this solution segments the target extremely long text to be classified, obtaining multiple target text fragments. Each target text fragment partially overlaps with its adjacent fragments, demonstrating a connection between them and making the target text fragments more logical. Therefore, the determined target text vectors are also more logical, leading to more accurate classification results when input into a convergent text classification model, better reflecting the true classification of extremely long texts. Furthermore, the convergent text classification model in this solution is trained using multiple training samples, including multiple training text vectors and their corresponding actual classification sub-results. These training text vectors are obtained based on training text fragments. Notably, there is partial overlap between training text fragments and their adjacent training text fragments. Therefore, the convergent text classification model relies on these partially overlapping training text fragments. Due to the partial overlap between adjacent training text fragments, the convergent text classification model trained in this way is superior.
[0038] The following section introduces the application scenarios of the classification method, apparatus, device, and storage medium for extremely long texts provided in this application.
[0039] Figure 1 This diagram illustrates an application scenario for the classification method for extremely long texts provided in this application. For example... Figure 1 As shown in the diagram, the application scenario includes electronic device 101.
[0040] Among them, electronic device 101 can be a mobile phone, computer or server, etc., without restriction.
[0041] The electronic device 101 includes a long text classification device (hereinafter referred to as classification device) 102, which includes a text classification model 103 trained to convergence.
[0042] Specifically, the classification device 102 acquires the target long text to be classified. In one approach, a user triggers a request to classify the target long text via electronic device 101, thereby electronic device 101 acquires the target long text and sends it to classification device 102.
[0043] Furthermore, the classification device 102 segments the target long text to obtain multiple target text fragments. A portion of any target text fragment overlaps with portions of its adjacent target text fragments.
[0044] Furthermore, the classification device 102 determines the target text vector corresponding to each target text segment, and then inputs each target text vector into the text classification model 103 that has been trained to convergence, thereby obtaining the classification result of the target long text.
[0045] It should be noted that the text classification model trained to convergence is obtained by training the initial text classification model using the training sample set. The training sample set includes multiple training samples, which in turn include multiple training text vectors and their corresponding actual classification sub-results. The training text vectors are obtained based on training text segments, which are obtained by training ultra-long text segmentation. Parts of any training text segment overlap with parts of its adjacent training text segments.
[0046] It should be noted that the training text segment in this application includes at least one training character, and the number of training characters can be 2048. It is understood that the target text segment includes at least one target character, and the number of corresponding target characters is the same as the number of training characters.
[0047] It should be noted that there is partial overlap between adjacent training text segments in this application. The characters in the overlapping part can be used to connect adjacent training text segments, thus playing a role in connecting the previous training text segment with the next training text segment. As a result, the model trained based on the training text segments will be more optimized.
[0048] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, use and processing of the relevant data must comply with relevant laws, regulations and standards, and corresponding operation entry points are provided for users to choose to authorize or refuse.
[0049] It should be noted that the classification method, apparatus, device and storage medium for ultra-long texts provided in this application can be applied to the fields of artificial intelligence and fintech, as well as to any field other than artificial intelligence and fintech. The application fields of this application are not limited.
[0050] This application provides a classification method for extremely long texts, aiming to solve the above-mentioned technical problems in the prior art.
[0051] The technical solution of this application and how the technical solution of this application solves the above-mentioned technical problems are described in detail below with specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments. The embodiments of this application will now be described with reference to the accompanying drawings.
[0052] Example 1
[0053] The subject of this application is a classification device for extremely long texts, which is located in an electronic device.
[0054] Figure 2 This is a flowchart illustrating a method for classifying extremely long texts, as provided in Example 1. Figure 2 As shown, the specific steps are as follows.
[0055] S201, Obtain the target long text to be classified.
[0056] Among them, ultra-long text refers to text consisting of a certain number of characters.
[0057] Among them, the target long text refers to the long text classified in this task.
[0058] In one approach, a user triggers a classification request via a classification device, which generates the request, including the target long text to be classified or a target long text identifier. Further, the classification device sends the classification request to an electronic device, which then obtains the target long text, or obtains the target long text based on the target long text identifier.
[0059] In one approach, a classification device in an electronic device, in response to receiving an excessively long text sent by any device, identifies the excessively long text as the target excessively long text to be classified.
[0060] S202, the target long text is segmented to obtain multiple target text segments; the multiple target text segments have the same character length; a portion of any target text segment overlaps with a portion of an adjacent target text segment; the portion of the segment includes at least one of the preceding portion and the following portion.
[0061] The overlapping part consists of the first and second segments.
[0062] Figure 3 This is a schematic diagram of multiple target text fragments provided in Example 1. Figure 3As shown, the target long text A is segmented into three target text segments: the first target segment, the second target segment, and the third target segment. The latter part of the first target segment overlaps with the former part of the second target segment, and the latter part of the second target segment overlaps with the former part of the third target segment. Figure 3 In the image, the black portion represents the overlapping area.
[0063] It should be noted that the overlap length between the first and second parts of the text is the same. In one approach, assuming the target super-long text has a length of N, the preset text segment length is s, and the overlap length is 0, the number of target text segments n that the target super-long text is divided into can be calculated using the following formula (1):
[0064]
[0065] Among them, symbols This indicates rounding up to the nearest integer.
[0066] It is understood that the length in this application refers to the number of characters.
[0067] S203, determine the target text vector corresponding to each target text segment.
[0068] In one approach, the classification device can determine the target text vector corresponding to the target text fragment based on a preset dictionary. The preset dictionary includes vectors corresponding to at least one character.
[0069] S204, input each target text vector into a text classification model that has been trained to convergence, and use the text classification model trained to convergence to obtain the classification result of the target long text; the text classification model trained to convergence is obtained by training the initial text classification model with a training sample set, which includes multiple training samples; the training samples include multiple training text vectors and their corresponding actual classification sub-results; the multiple training text vectors are obtained based on multiple training text segments; the multiple training text segments are segmented from training long texts; the multiple training text segments have the same character length; and some segments of any training text segment overlap with some segments of its adjacent training text segments.
[0070] It should be noted that each target text vector is input into the converged text classification model in sequence, thereby training the converged text classification model to obtain the target classification sub-results corresponding to each target text vector. Then, the classification result of the target long text is determined based on multiple target classification sub-results.
[0071] It should be noted that the text classification model trained to convergence in this application can be a recurrent Transformer Encoder model, wherein the recurrent Transformer Encoder model can include the ERNIE model.
[0072] This embodiment provides a method for classifying extremely long texts. In this embodiment, there is partial overlap between adjacent target text segments, thereby establishing connections between target text segments. Furthermore, there is a relationship between the previous and next target text segments, resulting in a more reasonable target text vector. This vector, when input into a convergent text classification model, improves the accuracy of the classification results. In addition, the convergent text classification model in this embodiment is also trained based on multiple training text segments, and since adjacent training text segments also partially overlap, they are connected, leading to a better model. Therefore, the convergent text classification model is more optimized, resulting in more accurate classification of extremely long target texts.
[0073] Example 2
[0074] This embodiment is a further refinement of the first embodiment described above. In this embodiment, the target text fragment includes at least one target character.
[0075] This embodiment is an optional method for determining the target text vector corresponding to each target text fragment, and the specific content is as follows.
[0076] For each target text segment, a preset encoding algorithm is used to vectorize at least one target character to obtain a vector corresponding to at least one target character; for each target text segment, the vectors corresponding to at least one target character are concatenated to obtain the target text vector corresponding to each target text segment.
[0077] The preset encoding algorithm is pre-selected, for example, one-hot encoding, etc., and is not limited here.
[0078] For example, let's take a target text fragment A as an example. Suppose that the target text fragment A contains 2048 target characters. Then, a preset encoding algorithm is used to perform vector encoding on the 2048 characters to obtain the vectors corresponding to the 2048 target characters.
[0079] Furthermore, the classification device concatenates the vectors corresponding to the 2048 target characters according to the order of the target characters, thereby obtaining the target text vector corresponding to the target text fragment A.
[0080] This embodiment provides a method for classifying ultra-long texts. In this embodiment, a preset coding algorithm is used to perform vector coding on at least one target character included in a target text segment, so that a target text vector corresponding to the target text segment can be quickly obtained.
[0081] Embodiment III
[0082] This embodiment is a further refinement of any of the above embodiments, and this embodiment is an optional manner before inputting each target text vector into a text classification model trained to convergence.
[0083] Figure 4 It is a schematic flowchart of a method for classifying ultra-long texts provided in Embodiment III. As Figure 4 shown, the specific steps are as follows.
[0084] S401. Obtain multiple training ultra-long texts.
[0085] Among them, the number of characters included in the multiple training ultra-long texts is the same, that is, the lengths of the multiple training ultra-long texts are the same.
[0086] It should be noted that before obtaining the multiple training ultra-long texts, this embodiment further includes the following content.
[0087] Obtain candidate ultra-long texts; the lengths of the candidate ultra-long texts can be inconsistent; <00
[0093] S402, each training super-long text is divided into multiple training text segments; the multiple training text segments have the same character length; some segments of any training text segment overlap with some segments of its adjacent training text segments.
[0094] It should be noted that the training text segments segmented in this step, like the target text segments, have partial overlap. For a detailed description, please refer to Example 1, which will not be repeated here.
[0095] It should be noted that the length of the overlap between the training phase and the application phase can be the same.
[0096] S403: For each training super-long text, obtain multiple training text vectors based on multiple training text segments, and determine the multiple training text vectors and their corresponding actual classification sub-results as training samples to obtain a training sample set.
[0097] The actual classification sub-result is the actual sub-result corresponding to the training text segment. For example, suppose there are three training text segments: the first training segment, the second training segment, and the third training segment. The first training segment corresponds to the first actual classification sub-result, the second training segment corresponds to the second actual classification sub-result, and the third training segment corresponds to the third actual classification sub-result. It should be noted that in this application, the actual classification sub-result and the classification result are numerical results.
[0098] It should be noted that any training text vector corresponds to its own training text segment. If the training text segment includes N training characters, then each training character corresponds to a training vector. Therefore, the number of training vectors included in the training text vector is the same as the number of training characters included in the training text segment.
[0099] In one approach, the actual subclassification result can be a vector classification corresponding to N training vectors in the training text vector. That is, the actual subclassification result can be a vector classification including the N training vectors. Thus, each training vector corresponds to one vector classification.
[0100] In one approach, the actual subclassification result can also be a summation vector classification of N training vectors, meaning that an actual subclassification result includes a total vector classification.
[0101] S404 uses a training sample set to train the initial text classification model to obtain a text classification model that has been trained to convergence.
[0102] It should be noted that the initial text classification model initializes the model parameters by training the training sample set, which allows for optimization of the initialized model parameters. Ultimately, the model parameters that meet the preset convergence conditions are obtained, thus leading to a text classification model that has been trained to convergence.
[0103] This embodiment provides a method for classifying extremely long texts. In this embodiment, multiple training extremely long texts are obtained and segmented to obtain multiple training text fragments. Since some fragments of any training text fragment overlap with some fragments of its adjacent training text fragments, the adjacent training text fragments are connected and have a certain relationship. The training text fragments are more reasonable, and thus the text classification model trained on the training text fragments is more optimized.
[0104] Example 4
[0105] This embodiment is a further refinement of any of the above embodiments. This embodiment is an optional method of training an initial text classification model using a training sample set to obtain a text classification model that has been trained to convergence.
[0106] Figure 5 This is a flowchart illustrating a method for classifying extremely long texts, as provided in Example 4. Figure 5 As shown, the specific steps are as follows.
[0107] S501, for each training text vector of each training sample, determine the current input feature based on the current training text vector.
[0108] Here, the current training text vector refers to the training text vector that the classification device is currently processing.
[0109] Here, the current input feature refers to the input feature corresponding to the current training text vector into the initial text classification model.
[0110] S502, input the current input features into the initial text classification model to obtain the current output features.
[0111] It is understandable that after the current input features are fed into the initial text classification model, the initial text classification model can output the corresponding current output features.
[0112] S503, in response to obtaining the current output feature, takes the next training text vector as the current training text vector and continues to execute the steps from determining the current input feature based on the current training text vector to inputting the current input feature into the initial text classification model, until the output features corresponding to all training text vectors are obtained.
[0113] For example, suppose there are three training text vectors, namely the first training vector, the second training vector, and the third training vector. Suppose the current training text vector is the first training vector. After executing step S502, the next training text vector in the order (i.e., the second training vector) is taken as the current training text vector. Then, the current input feature is determined based on the second training vector (the current training text vector), i.e., S501 is executed. Then, the current input feature is input into the initial text classification model to obtain the current output feature, i.e., S502 is executed. Then, the next training text vector in the order is taken as the current training text vector, i.e., the third training vector is determined as the current training text vector. Then, S501-S503 are executed again to obtain the output features corresponding to all training text vectors.
[0114] S504, determine whether the preset convergence condition is met based on the output features corresponding to each training text vector.
[0115] The preset convergence conditions may include conditions corresponding to the preset total loss value, or conditions for the preset number of training texts with excessive length; there are no restrictions here.
[0116] S505, in response to satisfying the preset convergence condition, the text classification model that satisfies the convergence condition is determined as the text classification model trained to convergence.
[0117] This embodiment provides a method for classifying very long texts. In this embodiment, the current input feature is determined based on the current training text vector, and then the current output feature is obtained by using an initial text classification model. The next training text vector in the order is then used as the current training text vector, and the above operation is repeated to obtain the corresponding current output feature. This process is repeated until the output features corresponding to all training text vectors are obtained. Therefore, this embodiment can obtain the output features corresponding to each training text vector in an orderly manner, and then determine whether the preset convergence condition is met based on each output feature, thereby accurately determining the text classification model that has been trained to convergence.
[0118] Example 5
[0119] This embodiment is a further refinement of any of the above embodiments. In this embodiment, the current training text vector is the training text vector that is ranked first.
[0120] The current input features are determined based on the current training text vectors, including:
[0121] The current training text vector is determined as the current input feature.
[0122] It should be noted that the training text vector ranked first can be directly identified as the current input feature.
[0123] This embodiment also includes the following method: if the current training text vector is not the first-ranked training text vector, this method is an optional way to determine the current input feature based on the current training text vector, specifically:
[0124] The output features of the previous training text vector and the current training text vector are input into a preset input feature function to obtain the input feature result; the input feature result is then determined as the current input feature.
[0125] The output feature of the previous training text vector is used as the previous output feature. The previous training text vector is the training text vector preceding the current training text vector.
[0126] According to the exemplary description in S503, suppose there are three training text vectors, namely the first training vector, the second training vector and the third training vector, respectively. Suppose the current training text vector is the second training vector, then the previous training text vector is the first training vector.
[0127] It should be noted that for training text vectors that are not ranked first, in order to improve the accuracy and relevance of the current input features, the corresponding current input features are related to the previous output features, so they are input into the preset input feature function to determine the current input features.
[0128] This embodiment provides a classification method for very long texts. In this embodiment, depending on whether the current training text is the first-ranked training text vector, targeted current input features are obtained, resulting in more accurate current input features. Furthermore, for the case where the current training text vector is not the first-ranked training text vector, the current input features are determined based on the output features of the previous training text vector and the current training text vector. Thus, the current output features in this embodiment learn from the previous output features, making the current input features more complete and accurate.
[0129] Example 6
[0130] This embodiment is a further refinement of any of the above embodiments. This embodiment is an optional way to input the output features of the previous training text vector and the current training text vector into a preset input feature function to obtain the input feature result.
[0131] Figure 6 This is a flowchart illustrating a method for classifying extremely long texts, as provided in Example 6. Figure 6 As shown, the specific steps are as follows.
[0132] S601 uses a preset input feature function to perform gradient separation on the output features of the previous training text vector to obtain gradient separation features.
[0133] Formula (2) is a preset input feature function in one approach, as shown in (2):
[0134] (2)α i =Summary(SG h) i-1 )o(β i )
[0135] Where, α i The input feature result is given, where i is the sequential numerical value of the training text vector, and h is the input feature result. i-1 β represents the output feature corresponding to the previous training text vector. i Let h be the current training text vector, where SG function identifier is the gradient separation function identifier, referring to the gradient separation function identifier for h. i-1 Gradient separation is performed. The Summary function identifier is the summary linear transformation function identifier, which refers to performing a summary linear transformation on the matrix. Here, 'o' indicates matrix concatenation. It should be noted that the gradient separation function and the summary linear transformation function in this step can be preset and are not restricted here.
[0136] S602 uses a preset input feature function to perform a summarizing linear transformation on the gradient separation features to obtain the summarizing features.
[0137] S603 uses a preset input feature function to concatenate the summarized features with the current training text vector to obtain the input feature result.
[0138] In this embodiment, the classification device performs gradient separation on the output features of the previous training text vector to obtain gradient separation features. Then, it performs a summative linear transformation on the gradient separation features to obtain summative features. Finally, it performs matrix transformation on the summative features with the current training text vector to obtain the input feature result.
[0139] It should be noted that gradient separation in this embodiment can separate more important features. The summary linear transformation summarizes the gradient separation features, and the resulting summary features can characterize the features possessed by the previous training text vector. Matrix concatenation combines the summary features with the current training text vector, so the resulting input feature result combines the features possessed by the previous training text vector with the current training text vector, thus making the input feature result more accurate.
[0140] It is understandable that the input feature results for the training text vectors that come later in the sequence can reflect the features of all the preceding training text vectors, thus the input feature results for the later training text vectors are more accurate.
[0141] Understandably, in the application phase, this suggests that the later the target text vector appears, the more accurate the target classifier result will be, and multiple later target classifier results may be the same.
[0142] This embodiment provides a classification method for very long texts. In this embodiment, the output features corresponding to the previous training text vector are first subjected to gradient separation to obtain gradient separation features. Then, a summary linear transformation is performed to obtain summary features. Finally, the summary features and the current training text vector are concatenated to obtain the input feature result. It can be seen that the input feature result combines the summary features corresponding to the previous training text vector and the current training text vector, thereby making the input feature result more complete and accurate.
[0143] Example 7
[0144] This embodiment is a further refinement of any of the above embodiments. In this embodiment, the preset convergence condition includes a condition that is less than or equal to the preset total loss value.
[0145] This embodiment is an optional method for determining whether a preset convergence condition is met based on the output features corresponding to each training text vector.
[0146] Figure 7 This is a flowchart illustrating a method for classifying extremely long texts, as provided in Example 7. Figure 7 As shown, the specific steps are as follows.
[0147] S701, input the output features corresponding to each training text vector and the actual classification sub-result into the preset loss function to obtain the sub-loss value corresponding to each training text vector.
[0148] The preset loss function can be the BCELoss function or cross-entropy, etc., and there are no restrictions here.
[0149] For example, the preset loss function in this embodiment can be as shown in equation (3):
[0150] (3)
[0151] Here, classify refers to the classification function, that is, the classification function for h. i Classify, h i It refers to the current subclassification result output by the current text classification model for the i-th training text vector, where label real i This refers to the actual sub-classification result corresponding to the i-th training text vector. This refers to the classification weight of the actual subclassification result, where n is the total number of training text segments, and LOSS i It refers to the sub-loss value corresponding to the i-th training text vector.
[0152] For example, the classification function can be a linear discriminant analysis function or others; there are no restrictions here.
[0153] Furthermore, the preset loss function calculates the sub-loss value corresponding to each training text vector based on the current sub-classification result and the actual sub-classification result. The current sub-classification result is the sub-classification result output by the current text classification model, which includes either the initial text classification model or a text classification model with optimized model parameters based on the initial text classification model.
[0154] For example, suppose there are three training text vectors, namely the first training vector, the second training vector, and the third training vector. Then the output features corresponding to each training text vector are the first output feature h1, the second output feature h2, and the third output feature h3, respectively.
[0155] It should be noted that the preset loss function in this step can be preset. For example, let's assume the preset loss function is as shown in equation (4):
[0156]
[0157] Based on the above example, the classification device calculates the first sub-loss value LOSS1 corresponding to the first training vector, the second sub-loss value LOSS2 corresponding to the second training vector, and the third sub-loss value LOSS3 corresponding to the third training vector.
[0158] In this embodiment, the preset loss function takes into account the classification weights corresponding to the order of the actual classification sub-results, that is... Since classification weights are taken into account, it can be seen that the classification weights of the training text vectors are greater the later they are processed, and thus the calculated sub-loss values reflect more weights the later they are processed.
[0159] S702, calculate the sum of the loss values of each sub-loss value.
[0160] Furthermore, calculate the loss. 总 =LOSS1+LOSS2+LOSS3, among which, LOSS 总 S703, in response to the condition that the summation loss value is less than or equal to the preset total loss value, it is determined that the preset convergence condition is met.
[0161] For example, assuming the condition for the total loss value to be less than or equal to the preset total loss value is less than or equal to 0.3, and assuming the summation loss value is 0.2, then it is determined that the summation loss value satisfies the condition of being less than or equal to the preset total loss value, thus determining that the preset convergence condition is met at this time.
[0162] S703, in response to the summation loss value not meeting the condition of being less than or equal to the preset total loss value, determine that the preset convergence condition is not met.
[0163] For example, assuming the condition for the total loss value to be less than or equal to the preset total loss value is less than or equal to 0.3, and assuming the summation loss value is 0.4, then it is determined that the summation loss value does not meet the condition of being less than or equal to the preset total loss value, thus determining that the preset convergence condition is not met at this time.
[0164] It should be noted that, for cases where the preset convergence condition is not met, the model parameters in the text classification model need to be optimized to obtain new optimized model parameters. Based on these optimized model parameters, an updated text classification model is obtained. Then, the training text vectors in the training samples are used to determine the current input features corresponding to the current training text vectors. The current input features are then input into the updated text classification model for training. Some steps from Examples 4 to 7 are executed iteratively until the summation loss value satisfies the condition that it is less than or equal to the preset total loss value.
[0165] This embodiment provides a classification method for very long texts. In this embodiment, the output features corresponding to each training text vector and the actual classification sub-results are input into a preset loss function to obtain each sub-loss value. Then, the sum of the sub-loss values is calculated. Since this embodiment presets a convergence condition, it presets a convergence condition that is more suitable for optimizing the text classification model. Furthermore, the classification device accurately determines whether the preset convergence condition is met based on the condition that the total loss value is less than or equal to the preset total loss value.
[0166] Example 8
[0167] This embodiment is a further refinement of any of the above embodiments. This embodiment is an optional method for obtaining the classification result of the target long text by using a text classification model trained to convergence. The specific content is as follows.
[0168] A text classification model trained to convergence is used to obtain target sub-results corresponding to multiple target text vectors; the target sub-result ranked last is determined as the classification result of the target long text.
[0169] Specifically, multiple target text vectors are input into a text classification model that has been trained to convergence, thereby obtaining the target classification sub-results corresponding to each target text vector. For example, after obtaining the target input feature A corresponding to a target text vector A, the target input feature A is input into a classification function. The classification function calculates multiple candidate sub-results based on the dimension of the target input feature A, and the largest candidate sub-result is determined as the target sub-result. The target sub-results corresponding to all target text vectors are calculated in order from beginning to end. Since the target input features corresponding to later target text vectors include features of earlier target text vectors, the target sub-results corresponding to later target text vectors are closer to the classification result of the target long text. Therefore, the target sub-result ranked last is determined as the classification result of the target long text.
[0170] It should be noted that after determining the classification result of the target long text, the text result can be determined according to the preset text classification mapping relationship. The preset text classification mapping relationship is the mapping relationship between the preset classification result and its corresponding text classification result. For example, assuming the preset classification result 0.5 corresponds to the text classification result of "education", and the preset classification result 1 corresponds to the text classification result of "children", then if the obtained classification result of the target long text is 0.5, then according to the preset text classification mapping relationship, the target text classification result is determined to be "education", meaning the target long text is a long text belonging to the "education" category.
[0171] This embodiment provides a classification method for extremely long texts. The target sub-results obtained by training a text classification model to convergence are more accurate. Since the target input features corresponding to the later target text vectors include the features of the earlier target text vectors, the target sub-results corresponding to the later target text vectors are closer to the classification result of the extremely long text. Therefore, the target sub-result ranked last is determined as the classification result of the extremely long text, so the final classification result is more accurate.
[0172] Example 9
[0173] The following is an embodiment of the device of this application. Figure 8 This is a schematic diagram of a classification device for extremely long texts provided in Embodiment Nine. Figure 8 As shown, the device 800 includes the following modules.
[0174] Module 801 is used to acquire the target long text to be classified.
[0175] Segmentation module 802 is used to segment the target long text to obtain multiple target text segments; the multiple target text segments have the same character length; a portion of any target text segment overlaps with a portion of an adjacent target text segment; the portion of the segment includes at least one of a preceding segment and a following segment.
[0176] The determination module 803 is used to determine the target text vector corresponding to each target text segment;
[0177] The module 804 is used to input each target text vector into a text classification model that has been trained to convergence, and to obtain the classification result of the target long text using the text classification model that has been trained to convergence. The text classification model that has been trained to convergence is obtained by training an initial text classification model using a training sample set, which includes multiple training samples. The training samples include multiple training text vectors and their corresponding actual classification sub-results. The multiple training text vectors are obtained based on multiple training text segments. The multiple training text segments are segmented from training long texts. The multiple training text segments have the same character length. Parts of any training text segment overlap with parts of its adjacent training text segments.
[0178] In one approach, the target text fragment includes at least one target character;
[0179] Module 803, in determining the target text vector corresponding to each target text fragment, is specifically used for:
[0180] For each target text segment, a preset encoding algorithm is used to vector encode at least one target character to obtain a vector corresponding to at least one target character;
[0181] For each target text segment, the vector corresponding to at least one target character is concatenated to obtain the target text vector corresponding to each target text segment.
[0182] In one approach, before inputting each target text vector into a text classification model trained to convergence, this embodiment provides a classification device for ultra-long texts, which further includes: a training module;
[0183] The acquisition module 801 is also used to acquire multiple training texts that are extremely long;
[0184] The segmentation module 802 is also used to segment each training long text into multiple training text segments; the multiple training text segments have the same character length; and some segments of any training text segment overlap with some segments of its adjacent training text segments.
[0185] The determination module 803 is also used to obtain multiple training text vectors based on multiple training text segments for each training long text, and to determine the multiple training text vectors and their corresponding actual classification sub-results as training samples to obtain a training sample set.
[0186] The training module is used to train the initial text classification model using the training sample set to obtain a text classification model that has been trained to convergence.
[0187] In one approach, the training module, when training an initial text classification model using a training sample set to obtain a converged text classification model, is specifically used for:
[0188] For each training text vector of each training sample, determine the current input feature based on the current training text vector;
[0189] The current input features are fed into the initial text classification model to obtain the current output features;
[0190] In response to obtaining the current output feature, the next training text vector in the order is used as the current training text vector, and the process continues from determining the current input feature based on the current training text vector to inputting the current input feature into the initial text classification model, until the output features corresponding to all training text vectors are obtained.
[0191] Determine whether the preset convergence condition is met based on the output features corresponding to each training text vector;
[0192] In response to the satisfaction of the preset convergence condition, the text classification model that satisfies the convergence condition is determined as the text classification model that has been trained to convergence.
[0193] In one approach, the current training text vector is the training text vector that is ranked first.
[0194] The training module, when determining the current input features based on the current training text vector, is specifically used for:
[0195] The current training text vector is determined as the current input feature.
[0196] In one approach, if the current training text vector is not the first training text vector in the order;
[0197] The training module, when determining the current input features based on the current training text vector, is specifically used for:
[0198] The output features of the previous training text vector and the current training text vector are input into a preset input feature function to obtain the input feature result; the input feature result is then determined as the current input feature.
[0199] In one approach, the training module, when inputting the output features of the previous training text vector and the current training text vector into a preset input feature function to obtain the input feature results, is specifically used for:
[0200] The output features of the previous training text vector are subjected to gradient separation using a preset input feature function to obtain gradient separation features.
[0201] A pre-defined input feature function is used to perform a summarizing linear transformation on the gradient separation features to obtain the summarizing features.
[0202] The summarized features are concatenated with the current training text vector using a preset input feature function to obtain the input feature result.
[0203] In one approach, the preset convergence conditions include conditions that are less than or equal to a preset total loss value;
[0204] The training module, when determining whether the preset convergence condition is met based on the output features corresponding to each training text vector, is specifically used for:
[0205] The output features corresponding to each training text vector and the actual classification sub-results are input into the preset loss function to obtain the sub-loss value corresponding to each training text vector;
[0206] Calculate the sum of the losses for each sub-loss value;
[0207] The condition that the summation loss value is less than or equal to the preset total loss value is used to determine whether the preset convergence condition is met.
[0208] If the summation loss value does not meet the condition of being less than or equal to the preset total loss value, it is determined that the preset convergence condition is not met.
[0209] In one approach, module 804, when obtaining the classification result of the target long text using a text classification model trained to convergence, is specifically used for:
[0210] A text classification model trained to convergence is used to obtain target classification sub-results corresponding to multiple target text vectors;
[0211] The target subclass result ranked last is determined as the classification result of the target long text.
[0212] Example 10
[0213] Figure 9 This is a schematic diagram of an electronic device structure provided in Embodiment 10. Figure 9As shown, the electronic device 900 may include: a processor 901, and a memory 902 and a transceiver 903 communicatively connected to the processor 901. The memory 902 stores computer-executable instructions; the transceiver 903 is used for sending and receiving data; the processor 901 executes the computer-executable instructions stored in the memory 902 to implement any of the method embodiments in Examples 1 to 8 above. The specific implementation methods and technical effects are similar, and will not be repeated here.
[0214] In this embodiment, the transceiver 903, storage 902, and processor 901 are connected via a bus. The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. The bus can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 9 The bus is represented by a single thick line, but this does not mean that there is only one bus or one type of bus.
[0215] Example 11
[0216] This application provides a computer-readable storage medium storing computer-executable instructions. When executed by a processor, the computer-executable instructions are used to implement any one of the method embodiments 1 to 8 described above. The specific implementation methods and technical effects are similar and will not be repeated here.
[0217] Example 12
[0218] This application provides a computer program product, including a computer program that, when executed by a processor, implements any one of the method embodiments of Examples 1 to 8 above. The specific implementation methods and technical effects are similar, and will not be repeated here.
[0219] In the several embodiments provided by this invention, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of modules is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple modules or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or modules may be electrical, mechanical, or other forms.
[0220] The modules described as separate components may or may not be physically separate. Similarly, the components shown as modules may or may not be physical modules; they may be located in one place or distributed across multiple network modules. Some or all of the modules can be selected to achieve the purpose of this embodiment, depending on actual needs.
[0221] Furthermore, the functional modules in the various embodiments of the present invention can be integrated into one processing module, or each module can exist physically separately, or two or more modules can be integrated into one module. The integrated module can be implemented in hardware or in the form of hardware plus software functional modules.
[0222] The program code used to implement the methods of the present invention can be written in any combination of one or more programming languages. This program code can be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable interrupt handling device, such that when executed by the processor or controller, the program code causes the functions / operations specified in the flowcharts and / or block diagrams to be implemented. The program code can be executed entirely on the machine, partially on the machine, as a standalone software package partially on the machine and partially on a remote machine, or entirely on a remote machine or server.
[0223] In the context of this invention, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. Machine-readable media can include, but are not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0224] Furthermore, although the operations are described in a specific order, this should be understood as requiring that such operations be performed in the specific order shown or in sequential order, or requiring that all illustrated operations be performed to achieve the desired result. In certain environments, multitasking and parallel processing may be advantageous. Similarly, although several specific implementation details are included in the above discussion, these should not be construed as limiting the scope of the invention. Certain features described in the context of individual embodiments may also be implemented in combination in a single implementation. Conversely, various features described in the context of a single implementation may also be implemented individually or in any suitable sub-combination in multiple implementations.
[0225] Other embodiments of this application will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of this application that follow the general principles of this application and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this application are indicated by the following claims.
[0226] It should be understood that this application is not limited to the precise structure described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this application is limited only by the appended claims.
Claims
1. A method of classifying an ultra-long text, characterized by, The method comprises: acquiring a target super-long text to be classified; segmenting the target super-long text to obtain a plurality of target text segments; the plurality of target text segments have the same character length; a partial segment in any of the target text segments overlaps with a partial segment of an adjacent target text segment; the partial segment includes at least one of a front partial segment and a rear partial segment; determining a target text vector corresponding to each target text segment; inputting each target text vector into a text classification model trained to convergence, and obtaining a classification result of the target super-long text by using the text classification model trained to convergence; the text classification model trained to convergence is obtained by training an initial text classification model by using a training sample set; the training sample set includes a plurality of training samples; each training sample includes a plurality of training text vectors and a corresponding actual classification result; the plurality of training text vectors are obtained based on a plurality of training text segments; the plurality of training text segments are obtained by segmenting a training super-long text; the plurality of training text segments have the same character length; a partial segment of any of the training text segments overlaps with a partial segment of an adjacent training text segment; before the step of inputting each target text vector into a text classification model trained to convergence, the initial text classification model is trained by using the training sample set; the step of training the initial text classification model by using the training sample set comprises: for each training text vector of each training sample, determining a current input feature according to a current training text vector; inputting the current input feature into the initial text classification model to obtain a current output feature; in response to obtaining the current output feature, taking a training text vector ranked next as the current training text vector, and continuing to perform the steps from determining the current input feature according to the current training text vector to inputting the current input feature into the initial text classification model until output features corresponding to all training text vectors are obtained; determining whether a preset convergence condition is met according to the output features corresponding to the training text vectors; in response to meeting the preset convergence condition, determining a text classification model meeting the convergence condition as the text classification model trained to convergence; if the current training text vector is not the training text vector ranked first; the step of determining the current input feature according to the current training text vector comprises: inputting an output feature of a previous training text vector and the current training text vector into a preset input feature function to obtain an input feature result; determining the input feature result as the current input feature; the step of inputting the output feature of the previous training text vector and the current training text vector into the preset input feature function to obtain the input feature result comprises: performing gradient separation on the output feature of the previous training text vector by using the preset input feature function to obtain a gradient separation feature; performing summary linear transformation on the gradient separation feature by using the preset input feature function to obtain a summary feature; The summary feature is spliced with the current training text vector by using the preset input feature function to obtain an input feature result.
2. The method of claim 1, wherein, The target text segment includes at least one target character; The target text vector corresponding to each target text segment is determined by: For each target text segment, at least one target character included in the target text segment is vector-encoded by using a preset encoding algorithm to obtain a vector corresponding to the at least one target character. For each target text segment, the vectors corresponding to the at least one target character are spliced to obtain a target text vector corresponding to the target text segment.
3. The method of claim 1, wherein, The method further comprises: obtaining a plurality of training super-long texts; each of the training super-long texts is divided into a plurality of training text segments; the character lengths of the plurality of training text segments are the same; and a partial segment of any training text segment overlaps with a partial segment of an adjacent training text segment; for each training super-long text, a plurality of training text vectors are obtained based on the plurality of training text segments, and the plurality of training text vectors and corresponding actual classification sub-results are determined as training samples to obtain a training sample set.
4. The method of claim 1, wherein, If the current training text vector is the first ranked training text vector; The current input feature is determined according to the current training text vector, comprising: The current training text vector is determined as the current input feature.
5. The method of claim 1, wherein, The preset convergence condition comprises a condition of being less than or equal to a preset total loss value; The output feature corresponding to each training text vector is determined to determine whether the preset convergence condition is met, comprising: The output feature corresponding to each training text vector and the actual classification sub-result are input into a preset loss function to obtain a sub-loss value corresponding to each training text vector; The sum loss value of each sub-loss value is calculated; In response to the condition that the sum loss value is less than or equal to the preset total loss value, it is determined that the preset convergence condition is met; In response to the condition that the sum loss value does not meet the condition of being less than or equal to the preset total loss value, it is determined that the preset convergence condition is not met.
6. The method according to any one of claims 1 to 5, characterized in that, The classification result of the target super-long text is obtained by using the text classification model trained to convergence, comprising: The target classification sub-result corresponding to each target text vector is obtained by using the text classification model trained to convergence; The last ranked target classification sub-result is determined as the classification result of the target super-long text.
7. An apparatus for classifying an ultra-long text, characterized by comprising: The device comprises: an acquisition module configured to acquire a target super-long text to be classified; a division module configured to divide the target super-long text to obtain a plurality of target text segments; the character lengths of the plurality of target text segments are the same; a partial segment in any target text segment overlaps with a partial segment in an adjacent target text segment; the partial segment includes at least one of a front partial segment and a rear partial segment; a determination module configured to determine a target text vector corresponding to each target text segment; and The obtaining module is configured to input each of the target text vectors into a text classification model trained to convergence, and obtain a classification result of the target long text by using the text classification model trained to convergence; the text classification model trained to convergence is obtained by training an initial text classification model by using a training sample set, the training sample set includes a plurality of training samples, each of the training samples includes a plurality of training text vectors and corresponding actual classification sub-results, the plurality of training text vectors are obtained based on a plurality of training text segments, the plurality of training text segments are obtained by dividing a training long text, the plurality of training text segments have the same character length, and a partial segment of any one of the training text segments overlaps with a partial segment of an adjacent training text segment; The training module is configured to, for each training text vector of each training sample, determine a current input feature according to a current training text vector; input the current input feature into the initial text classification model to obtain a current output feature; in response to obtaining the current output feature, take a training text vector ranked next as the current training text vector, and continue to perform the steps from determining the current input feature according to the current training text vector to inputting the current input feature into the initial text classification model until the output features corresponding to all the training text vectors are obtained; determine whether a preset convergence condition is met according to the output features corresponding to each training text vector; in response to the preset convergence condition being met, determine the text classification model meeting the convergence condition as the text classification model trained to convergence; the current training text vector is not the training text vector ranked first; the training module, when determining the current input feature according to the current training text vector, is specifically configured to: input the output feature of the previous training text vector and the current training text vector into a preset input feature function to obtain an input feature result; determine the input feature result as the current input feature; the training module, when inputting the output feature of the previous training text vector and the current training text vector into the preset input feature function to obtain the input feature result, is specifically configured to: perform gradient separation on the output feature of the previous training text vector by using the preset input feature function to obtain a gradient separation feature; perform summary linear transformation on the gradient separation feature by using the preset input feature function to obtain a summary feature; 8. An electronic device comprising: splice the summary feature and the current training text vector by using the preset input feature function to obtain the input feature result. a processor, a memory and a transceiver connected in communication with the processor; the memory stores computer execution instructions; the transceiver is configured to transmit and receive data; 9. A computer-readable storage medium, characterized in that, the processor executes the computer execution instructions stored in the memory to implement the method in any one of claims 1-6. The computer readable storage medium stores computer execution instructions, and the computer execution instructions are executed by the processor to implement the method in any one of claims 1-6.
10. A computer program product comprising a computer program which, when executed by a processor, implements the method of any of claims 1-6.
Citation Information
Patent Citations
Long text classification method, terminal and computer storage medium
CN112307208A
Code completion method and device and related equipment
CN112527273A