Long text classification method and device, equipment, medium and program product

By randomly adding markers to long text for segmentation and graph structure construction, the problem of information loss in long text classification is solved, and the accuracy of semantic judgment and the adaptability of methods are improved.

CN119740118APending Publication Date: 2025-04-01CHINA MOBILE (SUZHOU) SOFTWARE TECH CO LTD +1
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411799186.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-09
Publication Date
2025-04-01

AI Technical Summary

Technical Problem

The existing long text classification method uses simple truncation processing, resulting in a large amount of text information being lost, affecting the semantic judgment of long texts.

Method used

By randomly adding marks to the target long text for segmentation, the long text is divided into three parts: front, middle and back, and processed based on the preset shortest and longest text thresholds to form short text paragraphs of appropriate length. Then, a long text graph structure and a label graph structure are constructed, and a comparison and matching are performed to determine the classification results of the long text.

Benefits of technology

It effectively avoids the loss of text information, improves the accuracy of semantic judgment of long texts, and adapts to texts of different lengths, enhancing the adaptability of the method.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119740118A_ABST
    Figure CN119740118A_ABST
Patent Text Reader

Abstract

The invention provides a long text classification method and device, equipment, a medium and a program product, and the method comprises the steps: randomly adding a first mark and a second mark in a target long text to segment the target long text, and dividing the target long text into a front part, a middle part and a rear part; processing texts of front, middle and rear parts of the target long text to obtain target short texts, and forming a sentence fragment set; obtaining long text segmentation hierarchies formed in the processing process of all the target short texts; obtaining a long text graph structure and a corresponding long text graph vector according to the sentence fragment set and the long text segmentation hierarchy; obtaining a label graph structure and a corresponding label graph vector according to the sub-label of the target short text; and comparing and matching the long text graph structure and the corresponding long text graph vector with the label graph structure and the corresponding label graph vector, and determining a classification result of the long text. According to the method, the long text is effectively and accurately segmented through hierarchical filling segmentation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present invention relate to the field of artificial intelligence technology, and in particular to a long text classification method, device, equipment, medium and program product. Background Art

[0002] In current text classification, the classification of hierarchical labels of long texts is a typical task. For long texts, a quick way is to truncate the text, extract the first N characters of the text, the last N characters, or a combination of the first and the last characters, and treat the long text as a general text. On this basis, the long text is divided into multiple segments, and then the feature vectors of the multiple segments are extracted by the encoder, and the long text is classified by fusing the feature vectors. However, simply truncating the long text is a simple and crude method that will inevitably lose a lot of text information. It does not take into account the internal connection between the labels, including the hierarchy and mutual exclusivity between the labels, and processes the text in a biased manner, thus affecting the overall semantic judgment of the long text. Summary of the invention

[0003] The embodiments of the present invention provide a long text classification method, apparatus, device, medium and program product to solve the problem that text information is easily lost during the classification process of truncation and segmentation of the existing long text, which affects the semantic judgment of the long text.

[0004] In order to solve the above-mentioned technical problems, the present invention is achieved as follows:

[0005] In a first aspect, an embodiment of the present invention provides a long text classification method, comprising:

[0006] Randomly adding a first marker and a second marker to the target long text to segment the target long text, so as to divide the target long text into three parts: a front part, a middle part, and a back part;

[0007] Based on a preset shortest text threshold and a preset longest text threshold, the texts of the front, middle and back parts of the target long text are processed to obtain a target short text, wherein the length of the target short text is between the shortest text threshold and the longest text threshold, and the processing includes at least one of the following: deleting, retaining or splitting again;

[0008] All the target short texts are grouped into a sentence fragment set, and the long text segmentation level formed in the process of processing all the target short texts is obtained;

[0009] According to the sentence fragment set and the long text segmentation level, a long text graph structure and its corresponding long text graph vector are obtained, wherein the long text graph structure includes: a sentence node represented by a matching relationship between each of the target short texts and its corresponding sub-label, and the long text graph vector includes: a sentence node vector represented by a matching relationship between each of the target short texts and its corresponding sub-label;

[0010] According to the sub-labels of the target short text, a label graph structure and a corresponding label graph vector are obtained, wherein the label graph structure includes: label nodes represented by each sub-label and connecting edges between label nodes, and the connecting edges are set with relationship weights;

[0011] The long text graph structure and its corresponding long text graph vector are compared and matched with the label graph structure and its corresponding label graph vector to determine a classification result of the long text.

[0012] Optionally, comparing and matching the long text graph structure and its corresponding long text graph vector with the label graph structure and its corresponding label graph vector to determine the classification result of the long text includes:

[0013] Calculating a first similarity between the long text graph vector and features of each label subgraph on each path in the label graph structure, wherein the features of the label subgraph are obtained by linearly weighting the adjacent edge relationship weights of the edges with relationship weights set on each path and label node features;

[0014] Calculating a second similarity between each sentence node vector in the long text graph structure and the feature of the label node;

[0015] A classification result of the long text is determined based on the first similarity and the second similarity.

[0016] Optionally, the processing of the text of the front, middle and back parts of the target long text based on a preset shortest text threshold and a preset longest text threshold includes:

[0017] Determine the length of the text of the first, middle and last parts after the initial segmentation;

[0018] If the text lengths of two of the three parts are less than the shortest text threshold, the target long text is re-segmented;

[0019] If the text length of only one part among the first, middle and last parts is less than the shortest text threshold, the part with the text length less than the shortest text threshold is removed;

[0020] If the text length of any part of the front, middle and back parts is greater than the longest text threshold, the part with the text length greater than the longest text threshold is segmented again.

[0021] Optionally, obtaining a long text graph structure and a corresponding long text graph vector according to the sentence fragment set and the long text segmentation level includes:

[0022] According to the long text segmentation hierarchy, a long text hierarchical tree structure is constructed, wherein all leaf nodes of the long text hierarchical tree structure are all target short texts after the target long text is segmented;

[0023] Input the sentence fragment set into the encoder to obtain a sentence feature vector corresponding to each of the target short texts, and calculate a matching relationship between each of the target short texts in the sentence fragment set and its corresponding sub-tag according to the sentence feature vector;

[0024] Constructing a long text graph structure according to the matching relationship between each target short text in the sentence fragment set and its corresponding sub-label and the long text segmentation hierarchy;

[0025] The long text graph structure is input into the graph attention mechanism model to obtain the long text graph vector.

[0026] Optionally, calculating the matching relationship between each target short text in the sentence fragment set and its corresponding sub-tag according to the sentence feature vector includes:

[0027] According to the sentence feature vector, a target sub-tag that satisfies a preset label category probability is calculated, and the sentences are clustered according to the target sub-tag to obtain a label cluster, and the features in the label cluster are fused to obtain a sentence-sub-tag matching pair, and the sentence-sub-tag matching pair is used as the matching relationship between each of the target short texts and its corresponding sub-tag.

[0028] Optionally, obtaining a label graph structure and a corresponding label graph vector according to the sub-labels of the target short text includes:

[0029] Based on the hierarchical structure of the sub-labels of the target short text, a label structure tree is constructed, wherein each sub-label of the label structure tree corresponds to a label node, the vertex is the root node, and each layer in the label structure tree represents a level of label; the hierarchical relationship corresponding to the path from the root node to any label node and the corresponding target long text are taken as positive sample pairs, and other paths are taken as negative sample pairs; the hierarchical relationship corresponding to the path from the root node to any label node is taken as a label subgraph;

[0030] According to the label structure tree, a label graph structure is constructed, and the label graph structure is input into the graph attention mechanism model to obtain a label graph vector, a label node represented by each sub-label, and an edge with a relationship weight.

[0031] In a second aspect, an embodiment of the present invention provides a long text classification device, comprising:

[0032] A segmentation module, used for randomly adding a first marker and a second marker to a target long text to segment the target long text, and dividing the target long text into three parts: a front part, a middle part, and a back part;

[0033] The first processing module is used to process the texts of the front, middle and back parts of the target long text based on a preset shortest text threshold and a longest text threshold to obtain a target short text, wherein the length of the target short text is between the shortest text threshold and the longest text threshold, and the processing includes at least one of the following: deleting, retaining or splitting again;

[0034] A second processing module is used to group all the target short texts into a sentence fragment set, and obtain the long text segmentation level formed in the process of processing all the target short texts;

[0035] A third processing module is used to obtain a long text graph structure and a corresponding long text graph vector according to the sentence fragment set and the long text segmentation level, wherein the long text graph structure includes: a sentence node represented by a matching relationship between each of the target short texts and its corresponding sub-label, and the long text graph vector includes: a sentence node vector represented by a matching relationship between each of the target short texts and its corresponding sub-label;

[0036] A fourth processing module is used to obtain a label graph structure and a corresponding label graph vector according to the sub-labels of the target short text, wherein the label graph structure includes: a label node represented by each sub-label and a connecting edge between the label nodes, and the connecting edge is set with a relationship weight;

[0037] The classification matching module is used to compare and match the long text graph structure and its corresponding long text graph vector with the label graph structure and its corresponding label graph vector to determine the classification result of the long text.

[0038] Optionally, the classification matching module includes:

[0039] A first calculation submodule, used for calculating a first similarity between the long text graph vector and the features of each label subgraph on each path in the label graph structure, wherein the features of the label subgraph are obtained by linearly weighting the adjacent edge relationship weights of the edges with relationship weights set on each path and label node features;

[0040] A second calculation submodule, used to calculate a second similarity between each sentence node vector in the long text graph structure and the feature of the label node;

[0041] The third calculation submodule is used to determine the classification result of the long text based on the first similarity and the second similarity.

[0042] Optionally, the first processing module includes:

[0043] The first judgment submodule is used to judge the text length of the front, middle and back parts after the initial segmentation;

[0044] The second judgment submodule is used for re-segmenting the target long text if the text length of two parts among the first, middle and last parts is less than the shortest text threshold;

[0045] A third judgment submodule is used for removing the part whose text length is less than the shortest text threshold if only one of the three parts is less than the shortest text threshold;

[0046] The fourth judgment submodule is used to re-segment the part whose text length is greater than the longest text threshold if the text length of any part of the front, middle and rear parts is greater than the longest text threshold.

[0047] Optionally, the third processing module includes:

[0048] A first processing submodule is used to construct a long text hierarchical tree structure according to the long text segmentation hierarchy, wherein all leaf nodes of the long text hierarchical tree structure are all target short texts after the target long text is segmented;

[0049] A second processing submodule is used to input the sentence fragment set into an encoder to obtain a sentence feature vector corresponding to each of the target short texts, and calculate a matching relationship between each of the target short texts in the sentence fragment set and its corresponding sub-tag according to the sentence feature vector;

[0050] A third processing submodule is used to construct a long text graph structure according to the matching relationship between each target short text in the sentence fragment set and its corresponding sub-label and the long text segmentation hierarchy;

[0051] The fourth processing submodule is used to input the long text graph structure into the graph attention mechanism model to obtain the long text graph vector.

[0052] Optionally, the second processing submodule includes:

[0053] The fifth processing submodule is used to calculate the target sub-tag that meets the preset label category probability according to the sentence feature vector, cluster the sentences according to the target sub-tag to obtain label clusters, and fuse the features in the label clusters to obtain sentence-sub-tag matching pairs, and use the sentence-sub-tag matching pairs as the matching relationship between each of the target short texts and its corresponding sub-tag.

[0054] Optionally, the fourth processing module includes:

[0055] The sixth processing submodule is used to construct a label structure tree based on the hierarchical structure of the sub-labels of the target short text, wherein each sub-label of the label structure tree corresponds to a label node, the vertex is the root node, and each layer in the label structure tree represents a level of label; the hierarchical relationship corresponding to the path from the root node to any label node and the corresponding target long text are used as positive sample pairs, and other paths are used as negative sample pairs; the hierarchical relationship corresponding to the path from the root node to any label node is used as a label subgraph;

[0056] The seventh processing submodule is used to construct a label graph structure according to the label structure tree, and input the label graph structure into the graph attention mechanism model to obtain a label graph vector, a label node represented by each sub-label, and an edge with a relationship weight.

[0057] In a third aspect, an embodiment of the present invention provides an electronic device, comprising a processor, a memory, and a program or instruction stored in the memory and executable on the processor, wherein the program or instruction, when executed by the processor, implements the steps in the long text classification method described in any one of the first aspects.

[0058] In a fourth aspect, an embodiment of the present invention provides a readable storage medium, on which a program or instruction is stored. When the program or instruction is executed by a processor, the steps in the long text classification method as described in any one of the first aspects are implemented.

[0059] In a fifth aspect, an embodiment of the present invention provides a computer program product, comprising computer instructions, which, when executed by a processor, implement the steps in the long text classification method as described in any one of the first aspects.

[0060] In the present invention, a first marker and a second marker are randomly added to a target long text to segment the target long text, and the target long text is divided into three parts: front, middle and back; the texts of the front, middle and back three parts of the target long text are processed to obtain target short texts to form a set of sentence fragments; the long text segmentation hierarchy formed in the processing of all target short texts is obtained; according to the set of sentence fragments and the long text segmentation hierarchy, a long text graph structure and its corresponding long text graph vector are obtained; according to the sub-labels of the target short text, a label graph structure and its corresponding label graph vector are obtained; the long text graph structure and its corresponding long text graph vector are compared and matched with the label graph structure and its corresponding label graph vector to determine the segmentation of the long text. Classification results; by segmenting the target long text at multiple levels, it can adapt to texts of different lengths as needed, and ensure that the segmented text paragraphs are neither too short nor too long, so as to facilitate subsequent processing or analysis; by randomly adding the first marker and the second marker to segment the target long text, it is possible to try segmentation at different positions, so as to find more suitable segmentation points, thereby enhancing the adaptability of the method; and constructing a hierarchical graph structure based on the hierarchical segmentation mode is helpful to understand and analyze the structure and content of the text, improve processing efficiency, and avoid the problem of information loss caused by excessive segmentation, and solve the problem that the existing long text is easily lost in the classification process of truncated segmentation, which affects the semantic judgment of the long text. BRIEF DESCRIPTION OF THE DRAWINGS

[0061] Various other advantages and benefits will become apparent to those of ordinary skill in the art by reading the detailed description of the preferred embodiments below. The accompanying drawings are only for the purpose of illustrating the preferred embodiments and are not to be considered as limiting the present invention. Moreover, the same reference symbols are used throughout the accompanying drawings to represent the same components. In the accompanying drawings:

[0062] Figure 1 is a flow chart of a long text classification method provided by an embodiment of the present invention;

[0063] Figure 2 It is a schematic diagram of a hierarchical filling and segmentation method of a long text classification method provided by an embodiment of the present invention;

[0064] Figure 3 It is a hierarchical tree structure schematic diagram of a long text classification method provided by an embodiment of the present invention;

[0065] Figure 4 It is a schematic diagram of a long text graph structure of a long text classification method provided by an embodiment of the present invention;

[0066] Figure 5 It is a schematic diagram of the overall structure of a long text classification method provided by an embodiment of the present invention;

[0067] Figure 6is a structural schematic diagram of a long text classification device provided by an embodiment of the present invention;

[0068] Figure 7 It is a structural schematic diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0069] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0070] Please refer to Figure 1 , an embodiment of the present invention provides a long text classification method, comprising:

[0071] Step 11: randomly adding a first marker and a second marker to the target long text to segment the target long text, and dividing the target long text into three parts: front, middle and back;

[0072] In the embodiment of the present invention, please refer to Figure 2 , through the Hierarchical fill segmentation (HFS) method, that is, randomly adding the first token in the target long text <seg1>and the second marker <seg2>Two special tokens are used to divide the target long text into three parts (PRE, MID, and END). <seg1>and <seg2>For segmentation, the HFS method can try segmentation at different positions to find a more suitable segmentation point. At the same time, if the segmentation is not ideal, it can also re-segment or remove short texts in the future, which enhances the adaptability of the method.

[0073] Step 12: Based on a preset shortest text threshold and a preset longest text threshold, the texts of the front, middle and back parts of the target long text are processed to obtain a target short text, wherein the length of the target short text is between the shortest text threshold and the longest text threshold, and the processing includes at least one of the following: deleting, retaining or splitting again;

[0074] In the embodiment of the present invention, the shortest text threshold is set, which can be specifically set according to actual conditions: min =64 (default) and the longest text threshold, which can be set according to actual conditions: tt max =512 (default).

[0075] In the embodiment of the present invention, optionally, the processing of the text of the front, middle and back parts of the target long text based on the preset shortest text threshold and the longest text threshold includes:

[0076] Determine the length of the text of the first, middle and last parts after the initial segmentation;

[0077] If the text lengths of two of the three parts are less than the shortest text threshold, the target long text is re-segmented;

[0078] If the text length of only one part among the first, middle and last parts is less than the shortest text threshold, the part with the text length less than the shortest text threshold is removed;

[0079] If the text length of any part of the front, middle and back parts is greater than the longest text threshold, the part with the text length greater than the longest text threshold is segmented again.

[0080] In the embodiment of the present invention, by judging the text lengths of the three parts after the initial segmentation, if the text lengths of two parts among PRE, MID, and END are less than the shortest text threshold, it is considered that the current segmentation is not ideal and needs to be segmented again; if the text length of only one part is less than the shortest text threshold after segmentation, this part of the text is directly discarded; under the above two conditions, if the text after segmentation is greater than the longest text threshold, segmentation is continued according to the original mode on the basis of this text, and the text between the shortest text threshold and the longest text threshold is retained as the target short text, and after HFS segmentation, the following is formed. Figure 2 The long text segmentation level shown in the figure; the HFS method allows text segmentation at multiple levels, adapting to texts of different lengths as needed, and by setting the shortest and longest text thresholds, it can ensure that the segmented text paragraphs are neither too short nor too long, thus facilitating subsequent processing or analysis;

[0081] Step 13: All the target short texts are grouped into a sentence fragment set, and the long text segmentation level formed in the process of processing all the target short texts is obtained;

[0082] In the embodiment of the present invention, after HFS segmentation, the long text segmentation hierarchy formed in the process of processing the target short text and all the target short texts is constructed as follows: Figure 3 The hierarchical tree structure shown in the figure, wherein S0 is the original target long text, which is the root node of the hierarchical tree structure, and the S1, S2 and S3 formed by the segmentation are the first level, and so on; that is, all leaf nodes are all target short texts after the long text is segmented, thereby clearly demonstrating the text segmentation process, which is helpful to understand and analyze the structure and content of the text.

[0083] Step 14: obtaining a long text graph structure and its corresponding long text graph vector according to the sentence fragment set and the long text segmentation level, wherein the long text graph structure includes: a sentence node represented by a matching relationship between each of the target short texts and its corresponding sub-label, and the long text graph vector includes: a sentence node vector represented by a matching relationship between each of the target short texts and its corresponding sub-label;

[0084] In the embodiment of the present invention, optionally, obtaining the long text graph structure and its corresponding long text graph vector according to the sentence fragment set and the long text segmentation level includes:

[0085] According to the long text segmentation hierarchy, a long text hierarchical tree structure is constructed, wherein all leaf nodes of the long text hierarchical tree structure are all target short texts after the target long text is segmented;

[0086] Input the sentence fragment set into the encoder to obtain a sentence feature vector corresponding to each of the target short texts, and calculate a matching relationship between each of the target short texts in the sentence fragment set and its corresponding sub-tag according to the sentence feature vector;

[0087] Constructing a long text graph structure according to the matching relationship between each target short text in the sentence fragment set and its corresponding sub-label and the long text segmentation hierarchy;

[0088] The long text graph structure is input into the graph attention mechanism model to obtain the long text graph vector.

[0089] In the embodiment of the present invention, the long text hierarchical tree structure is as follows: Figure 3 As shown, S0 is the original target long text, which is the root node of the hierarchical tree structure, and the segmented S1, S2 and S3 form the first level, and so on; that is, all leaf nodes are all target short texts after the long text is segmented, and a task description template is added at the beginning of each target short text. <t>Determine the specific category to which the following sentence belongs <t>", in order to enhance the subsequent model's understanding of the task, so that the model can more accurately select the sentence fragment set {s1, s2, s3, ..., s h };

[0090] The sentence fragment set is input into the encoder to obtain the feature vector {e i1 ,e i2 ,e i3 ,…,e iv }, where i = {1, 2, 3, ..., h}, v is the dimension corresponding to each sentence; and the feature vector {e i1 ,e i2 ,e i3 ,…,e iv } Input the softmax model to calculate the probability of its corresponding sub-label, and obtain its most likely sub-label category. Cluster the sentences according to the label category as label clusters, and fuse the features in the label clusters to obtain sentence-sub-label matching pairs (N, L); According to the sentence-sub-label matching pairs, and based on the long text segmentation level of the long text corresponding label, guide the sentence to construct a graph structure relationship, such as Figure 4 As shown, the long text graph structure G = (N, E) is obtained, where N represents the sentence node and E represents the edge. Please refer to Figure 5 , and then pass the long text graph structure G = (N, E) through the GAT model to obtain the long text graph vector T∈R v , and update N and E. At this time, each sentence node is represented by N j ∈R v The hierarchical tree structure clearly shows the text segmentation process, which is helpful to understand and analyze the structure and content of the text; and by segmenting a long text into multiple short texts, the HFS method can reduce the complexity of subsequent processing and improve processing efficiency. At the same time, since the text paragraphs of appropriate length are retained, the problem of information loss caused by over-segmentation is avoided; and the HFS method has good scalability, and the shortest and longest text thresholds can be adjusted as needed, as well as the segmentation strategy can be improved.

[0091] Step 15: according to the sub-labels of the target short text, obtain a label graph structure and its corresponding label graph vector, wherein the label graph structure includes: label nodes represented by each sub-label and connecting edges between label nodes, and the connecting edges are set with relationship weights;

[0092] In the embodiment of the present invention, optionally, obtaining a label graph structure and a corresponding label graph vector according to the sub-labels of the target short text includes:

[0093] Based on the hierarchical structure of the sub-labels of the target short text, a label structure tree is constructed, wherein each sub-label of the label structure tree corresponds to a label node, the vertex is the root node, and each layer in the label structure tree represents a level of label; the hierarchical relationship corresponding to the path from the root node to any label node and the corresponding target long text are taken as positive sample pairs, and other paths are taken as negative sample pairs; the hierarchical relationship corresponding to the path from the root node to any label node is taken as a label subgraph;

[0094] According to the label structure tree, a label graph structure is constructed, and the label graph structure is input into the graph attention mechanism model to obtain a label graph vector, a label node represented by each sub-label, and an edge with a relationship weight.

[0095] In the embodiment of the present invention, a tag structure tree is constructed based on the hierarchical structure of the subtags of the target short text. Figure 5 , where each label corresponds to a Node label node, the vertex is the root node, the first layer is the first-level label, the second layer is the second-level label, and so on. It can represent the hierarchy and mutual exclusivity of different labels, and can also highlight the adjacent edge relationship between labels. The last layer is the final label leaf node. Any path from the root node to the leaf node is the entire hierarchical label information of the corresponding long text, as a label subgraph, and the corresponding target long text as a positive sample pair, and other paths as its negative sample pairs; the label graph structure is obtained through the GAT model to obtain the vector representation of the label graph structure, the adjacent edge relationship weight and the feature representation L of the label node i ∈R v , i = {1, 2, 3, ..., n}, n is the total number of sub-labels, and then linear weighting is performed according to the neighboring edge relationship weight and the feature representation of the label node as the feature representation P of the label subgraph corresponding to each path s ∈R v , s={1,2,3,...,k}, v is the corresponding feature dimension, which is consistent with the sentence feature dimension.

[0096] In an embodiment of the present invention, the hierarchical structure of the label itself is utilized to represent the label in a graph structure through the GAT method, and a task description template is added to the long text feature construction module through the previous text to improve the model's ability to understand the task, and a label cluster is constructed by predicting sentence labels. The sentence graph structure is guided based on the label hierarchy, and then the long text graph structure representation is obtained by combining the GAT network, which simplifies the complexity of the long text graph structure.

[0097] Step 16: Compare and match the long text graph structure and its corresponding long text graph vector with the label graph structure and its corresponding label graph vector to determine the classification result of the long text.

[0098] In the embodiment of the present invention, optionally, comparing and matching the long text graph structure and its corresponding long text graph vector with the label graph structure and its corresponding label graph vector to determine the classification result of the long text includes:

[0099] Calculating a first similarity between the long text graph vector and features of each label subgraph on each path in the label graph structure, wherein the features of the label subgraph are obtained by linearly weighting the adjacent edge relationship weights of the edges with relationship weights set on each path and label node features;

[0100] Calculating a second similarity between each sentence node vector in the long text graph structure and the feature of the label node;

[0101] A classification result of the long text is determined based on the first similarity and the second similarity.

[0102] In the embodiment of the present invention, calculating the first similarity between the features of the long text graph vector and each label subgraph on each path in the label graph structure specifically includes: calculating the first similarity between the long text graph vector T and each label subgraph P on each path in the label graph structure s Perform contrastive learning to calculate the vector T and k subgraphs P s The cosine similarity between them is the first similarity. The calculation process only includes one positive sample pair, that is, the original target long text and the corresponding label subgraph. The other k-1 text and label pairs are negative samples. The loss function at this time is:

[0103]

[0104] Calculating the second similarity between each sentence node vector in the long text graph structure and the feature of the label node specifically includes: j Label node L with child labels i Perform contrastive learning and calculate sentence-subtag matching pairs N j With L i The cosine similarity of , i.e., the second similarity; the calculation process only includes m positive samples, i.e., the number of sub-labels corresponding to the target long text, i.e., the other m n -m combinations are negative samples, and the loss function is defined as:

[0105]

[0106] Combining the objective functions of long text-label subgraph matching and sentence-leaf label matching, the overall objective function is as follows:

[0107] L=w1l TP +w2l NL ; where w1 and w2 are used as hyperparameters to control the contribution of the objective function.

[0108] In the embodiment of the present invention, the overall and local information are integrated through long text-label comparison and matching, thereby improving the accuracy and applicability of long text classification.

[0109] In an embodiment of the present invention, a first marker and a second marker are randomly added to a target long text to segment the target long text, and the target long text is divided into three parts: front, middle and back; the texts of the front, middle and back parts of the target long text are processed to obtain target short texts to form a set of sentence fragments; the long text segmentation hierarchy formed in the process of processing all target short texts is obtained; according to the set of sentence fragments and the long text segmentation hierarchy, a long text graph structure and its corresponding long text graph vector are obtained; according to the sub-labels of the target short text, a label graph structure and its corresponding label graph vector are obtained; the long text graph structure and its corresponding long text graph vector are compared and matched with the label graph structure and its corresponding label graph vector to determine the long text. Classification results; By segmenting the target long text at multiple levels, it can adapt to texts of different lengths as needed, and ensure that the segmented text paragraphs are neither too short nor too long, so as to facilitate subsequent processing or analysis; By randomly adding the first marker and the second marker to segment the target long text, it is possible to try segmentation at different positions to find more suitable segmentation points, thereby enhancing the adaptability of the method; and constructing a hierarchical graph structure based on the hierarchical segmentation mode, it is helpful to understand and analyze the structure and content of the text, improve processing efficiency, and avoid the problem of information loss caused by excessive segmentation, and solve the problem that the existing long text is easily lost in the classification process of truncated segmentation, which affects the semantic judgment of the long text.

[0110] Please refer to Figure 6 , an embodiment of the present invention provides a long text classification device, comprising:

[0111] A segmentation module 61 is used to randomly add a first mark and a second mark to a target long text to segment the target long text, and divide the target long text into three parts: a front part, a middle part, and a back part;

[0112] The first processing module 62 is used to process the text of the front, middle and back parts of the target long text based on a preset shortest text threshold and a longest text threshold to obtain a target short text, wherein the length of the target short text is between the shortest text threshold and the longest text threshold, and the processing includes at least one of the following: deleting, retaining or splitting again;

[0113] The second processing module 63 is used to group all the target short texts into a sentence fragment set, and obtain the long text segmentation level formed in the process of processing all the target short texts;

[0114] The third processing module 64 is used to obtain a long text graph structure and a corresponding long text graph vector according to the sentence fragment set and the long text segmentation level, wherein the long text graph structure includes: a sentence node represented by a matching relationship between each of the target short texts and its corresponding sub-label, and the long text graph vector includes: a sentence node vector represented by a matching relationship between each of the target short texts and its corresponding sub-label;

[0115] The fourth processing module 65 is used to obtain a label graph structure and a corresponding label graph vector according to the sub-labels of the target short text, wherein the label graph structure includes: a label node represented by each sub-label and a connection edge between the label nodes, and the connection edge is set with a relationship weight;

[0116] The classification matching module 66 is used to compare and match the long text graph structure and the corresponding long text graph vector with the label graph structure and the corresponding label graph vector to determine the classification result of the long text.

[0117] In the embodiment of the present invention, optionally, the classification matching module includes:

[0118] A first calculation submodule, used for calculating a first similarity between the long text graph vector and the features of each label subgraph on each path in the label graph structure, wherein the features of the label subgraph are obtained by linearly weighting the adjacent edge relationship weights of the edges with relationship weights set on each path and label node features;

[0119] A second calculation submodule, used to calculate a second similarity between each sentence node vector in the long text graph structure and the feature of the label node;

[0120] The third calculation submodule is used to determine the classification result of the long text based on the first similarity and the second similarity.

[0121] In the embodiment of the present invention, optionally, the first processing module includes:

[0122] The first judgment submodule is used to judge the text length of the front, middle and back parts after the initial segmentation;

[0123] The second judgment submodule is used for re-segmenting the target long text if the text length of two parts among the first, middle and last parts is less than the shortest text threshold;

[0124] A third judgment submodule is used for removing the part whose text length is less than the shortest text threshold if only one of the three parts is less than the shortest text threshold;

[0125] The fourth judgment submodule is used to re-segment the part whose text length is greater than the longest text threshold if the text length of any part of the front, middle and rear parts is greater than the longest text threshold.

[0126] In the embodiment of the present invention, optionally, the third processing module includes:

[0127] A first processing submodule is used to construct a long text hierarchical tree structure according to the long text segmentation hierarchy, wherein all leaf nodes of the long text hierarchical tree structure are all target short texts after the target long text is segmented;

[0128] A second processing submodule is used to input the sentence fragment set into an encoder to obtain a sentence feature vector corresponding to each of the target short texts, and calculate a matching relationship between each of the target short texts in the sentence fragment set and its corresponding sub-tag according to the sentence feature vector;

[0129] A third processing submodule is used to construct a long text graph structure according to the matching relationship between each target short text in the sentence fragment set and its corresponding sub-label and the long text segmentation hierarchy;

[0130] The fourth processing submodule is used to input the long text graph structure into the graph attention mechanism model to obtain the long text graph vector.

[0131] In the embodiment of the present invention, optionally, the second processing submodule includes:

[0132] The fifth processing submodule is used to calculate the target sub-tag that meets the preset label category probability according to the sentence feature vector, cluster the sentences according to the target sub-tag to obtain label clusters, and fuse the features in the label clusters to obtain sentence-sub-tag matching pairs, and use the sentence-sub-tag matching pairs as the matching relationship between each of the target short texts and its corresponding sub-tag.

[0133] In the embodiment of the present invention, optionally, the fourth processing module includes:

[0134] The sixth processing submodule is used to construct a label structure tree based on the hierarchical structure of the sub-labels of the target short text, wherein each sub-label of the label structure tree corresponds to a label node, the vertex is the root node, and each layer in the label structure tree represents a level of label; the hierarchical relationship corresponding to the path from the root node to any label node and the corresponding target long text are used as positive sample pairs, and other paths are used as negative sample pairs; the hierarchical relationship corresponding to the path from the root node to any label node is used as a label subgraph;

[0135] The seventh processing submodule is used to construct a label graph structure according to the label structure tree, and input the label graph structure into the graph attention mechanism model to obtain a label graph vector, a label node represented by each sub-label, and an edge with a relationship weight.

[0136] The long text classification device provided by the embodiment of the present invention can achieve Figure 1 The various processes implemented by the method embodiment and achieving the same technical effect are not described here to avoid repetition.

[0137] An embodiment of the present invention provides an electronic device 70, see Figure 7 As shown, Figure 7 This is a principle block diagram of an electronic device 70 according to an embodiment of the present invention, which includes a processor 71, a memory 72, and a program or instruction stored in the memory 72 and executable on the processor 71. When the program or instruction is executed by the processor, the steps in any long text classification method of the present invention are implemented.

[0138] An embodiment of the present invention provides a readable storage medium, on which a program or instruction is stored. When the program or instruction is executed by a processor, each process of an embodiment of a long text classification method as described above is implemented, and the same technical effect can be achieved. To avoid repetition, it will not be described here.

[0139] The embodiment of the present application also provides a computer program product, including computer instructions. When the computer instructions are executed by a processor, the various processes of the method embodiment shown in the above figure are implemented, and the same technical effect can be achieved. To avoid repetition, they are not repeated here.

[0140] Computer readable media include permanent and non-permanent, removable and non-removable media, and can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.

[0141] It should be noted that the collection, collection, updating, analysis, processing, use, transmission, storage and other aspects of user personal information involved in the technical solution of this disclosure are in compliance with the provisions of relevant laws and regulations, are used for legitimate purposes, and do not violate public order and good morals. Necessary measures are taken for user personal information to prevent illegal access to user personal information data and maintain the security of user personal information and network security.

[0142] It should be noted that, in this article, the term "includes", "comprising" or any other variation thereof is intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also includes other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprising a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.

[0143] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.

[0144] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for enabling a service classification device (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in each embodiment of the present application.

[0145] The above is only a preferred implementation of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.< / t> < / t>

Claims

1. A long text classification method, characterized in that: include: Randomly adding a first marker and a second marker to the target long text to segment the target long text, so as to divide the target long text into three parts: a front part, a middle part, and a back part; Based on a preset shortest text threshold and a preset longest text threshold, the texts of the front, middle and back parts of the target long text are processed to obtain a target short text, wherein the length of the target short text is between the shortest text threshold and the longest text threshold, and the processing includes at least one of the following: deleting, retaining or splitting again; All the target short texts are grouped into a sentence fragment set, and the long text segmentation level formed in the process of processing all the target short texts is obtained; According to the sentence fragment set and the long text segmentation level, a long text graph structure and its corresponding long text graph vector are obtained, wherein the long text graph structure includes: a sentence node represented by a matching relationship between each of the target short texts and its corresponding sub-label, and the long text graph vector includes: a sentence node vector represented by a matching relationship between each of the target short texts and its corresponding sub-label; According to the sub-labels of the target short text, a label graph structure and a corresponding label graph vector are obtained, wherein the label graph structure includes: label nodes represented by each sub-label and connecting edges between label nodes, and the connecting edges are set with relationship weights; The long text graph structure and its corresponding long text graph vector are compared and matched with the label graph structure and its corresponding label graph vector to determine a classification result of the long text.

2. The long text classification method according to claim 1, characterized in that: The comparing and matching the long text graph structure and its corresponding long text graph vector with the label graph structure and its corresponding label graph vector to determine the classification result of the long text includes: Calculating a first similarity between the long text graph vector and features of each label subgraph on each path in the label graph structure, wherein the features of the label subgraph are obtained by linearly weighting the adjacent edge relationship weights of the edges with relationship weights set on each path and label node features; Calculating a second similarity between each sentence node vector in the long text graph structure and the feature of the label node; A classification result of the long text is determined based on the first similarity and the second similarity.

3. The long text classification method according to claim 1, characterized in that: The processing of the text of the front, middle and back parts of the target long text based on the preset shortest text threshold and the longest text threshold includes: Determine the length of the text of the first, middle and last parts after the initial segmentation; If the text lengths of two of the three parts are less than the shortest text threshold, the target long text is re-segmented; If the text length of only one part among the first, middle and last parts is less than the shortest text threshold, the part with the text length less than the shortest text threshold is removed; If the text length of any part of the front, middle and back parts is greater than the longest text threshold, the part with the text length greater than the longest text threshold is segmented again.

4. The long text classification method according to claim 1, characterized in that: The obtaining of a long text graph structure and a corresponding long text graph vector according to the sentence fragment set and the long text segmentation level includes: According to the long text segmentation hierarchy, a long text hierarchical tree structure is constructed, wherein all leaf nodes of the long text hierarchical tree structure are all target short texts after the target long text is segmented; Input the sentence fragment set into the encoder to obtain a sentence feature vector corresponding to each of the target short texts, and calculate a matching relationship between each of the target short texts in the sentence fragment set and its corresponding sub-tag according to the sentence feature vector; Constructing a long text graph structure according to the matching relationship between each target short text in the sentence fragment set and its corresponding sub-label and the long text segmentation hierarchy; The long text graph structure is input into the graph attention mechanism model to obtain the long text graph vector.

5. The long text classification method according to claim 4, characterized in that: The calculating, according to the sentence feature vector, a matching relationship between each target short text in the sentence fragment set and its corresponding sub-tag comprises: According to the sentence feature vector, a target sub-tag that satisfies a preset label category probability is calculated, and the sentences are clustered according to the target sub-tag to obtain a label cluster, and the features in the label cluster are fused to obtain a sentence-sub-tag matching pair, and the sentence-sub-tag matching pair is used as the matching relationship between each of the target short texts and its corresponding sub-tag.

6. The long text classification method according to claim 1, characterized in that: The step of obtaining a label graph structure and a corresponding label graph vector according to the sub-labels of the target short text includes: Based on the hierarchical structure of the sub-labels of the target short text, a label structure tree is constructed, wherein each sub-label of the label structure tree corresponds to a label node, the vertex is the root node, and each layer in the label structure tree represents a level of label; the hierarchical relationship corresponding to the path from the root node to any label node and the corresponding target long text are taken as positive sample pairs, and other paths are taken as negative sample pairs; the hierarchical relationship corresponding to the path from the root node to any label node is taken as a label subgraph; According to the label structure tree, a label graph structure is constructed, and the label graph structure is input into the graph attention mechanism model to obtain a label graph vector, a label node represented by each sub-label, and an edge with a relationship weight.

7. A long text classification device, characterized in that: include: A segmentation module, used for randomly adding a first marker and a second marker to a target long text to segment the target long text, and dividing the target long text into three parts: a front part, a middle part, and a back part; The first processing module is used to process the texts of the front, middle and back parts of the target long text based on a preset shortest text threshold and a longest text threshold to obtain a target short text, wherein the length of the target short text is between the shortest text threshold and the longest text threshold, and the processing includes at least one of the following: deleting, retaining or splitting again; A second processing module is used to group all the target short texts into a sentence fragment set, and obtain the long text segmentation level formed in the process of processing all the target short texts; A third processing module is used to obtain a long text graph structure and a corresponding long text graph vector according to the sentence fragment set and the long text segmentation level, wherein the long text graph structure includes: a sentence node represented by a matching relationship between each of the target short texts and its corresponding sub-label, and the long text graph vector includes: a sentence node vector represented by a matching relationship between each of the target short texts and its corresponding sub-label; A fourth processing module is used to obtain a label graph structure and a corresponding label graph vector according to the sub-labels of the target short text, wherein the label graph structure includes: a label node represented by each sub-label and a connecting edge between the label nodes, and the connecting edge is set with a relationship weight; The classification matching module is used to compare and match the long text graph structure and its corresponding long text graph vector with the label graph structure and its corresponding label graph vector to determine the classification result of the long text.

8. An electronic device, characterized in that: The method comprises a processor, a memory, and a program or instruction stored in the memory and executable on the processor, wherein the program or instruction, when executed by the processor, implements the steps in the long text classification method as claimed in any one of claims 1 to 6.

9. A readable storage medium, characterized in that: The readable storage medium stores a program or an instruction, and when the program or the instruction is executed by the processor, the steps in the long text classification method according to any one of claims 1 to 6 are implemented.

10. A computer program product, characterized in that The method comprises computer instructions, which, when executed by a processor, implement the steps in the long text classification method according to any one of claims 1 to 6.

Citation Information

Cited By

  • Long text classification method and apparatus, and device, medium and program product

    WO2026124475A1