Long document processing method and device, electronic equipment and medium
By encoding text segments in long documents and combining position information, and using loop processing units to extract deep semantic features, the problem of unclear semantic understanding and information loss in long document processing is solved, and a comprehensive understanding and analysis of long documents is achieved. .
Patent Information
- Application Number
- CN202410040429.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-01-10
- Publication Date
- 2024-10-18
AI Technical Summary
Existing technologies have problems with unclear semantic understanding, information loss or fragmentation when processing long documents. Especially when using sparse attention mechanisms, truncation or segmentation processing, it is difficult to fully understand the structure and content of long documents.
By encoding multiple text segments and combining the position information of each text segment, the loop processing unit is used to process segment by segment to extract deep semantic features to achieve a comprehensive understanding and analysis of long documents.
It improves the processing capabilities of long documents, ensures the accuracy and completeness of semantic features, solves the problem of insufficient semantic understanding and information loss, and achieves more comprehensive long document analysis.
Smart Images

Figure CN118798204A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the technical field of long document processing, and in particular to a long document processing method, device, electronic device and medium. Background Art
[0002] Long documents are usually large in length and complex in structure, containing multiple chapters, paragraphs, and information levels. Long document processing refers to the process of in-depth understanding and analysis of long and complex documents.
[0003] In the related technology, there are three main research directions for long document processing: Direction 1) Using sparse attention mechanism instead of complete self-attention mechanism to reduce the computational complexity to O(N), and optimizing it with CUDA so that the model can accommodate texts with a maximum length of tens of thousands; Direction 2) Reducing the sequence length by truncation, selection or compression to achieve long document processing; Direction 3) Segmenting long documents and then cyclically modeling the connections between segments to achieve long document processing.
[0004] However, the related technologies may have problems with unclear and unsmooth semantic understanding when processing long documents through the above three directions. In direction 1), when using the sparse attention mechanism to process long documents, since a new attention strategy is adopted in the training stage, a large amount of training data and resources are required to train from scratch, which may ignore some important details and lead to insufficient semantic understanding; in direction 2), fixed thresholds or artificially set standards are used to truncate, select or compress long documents. Since the content of long documents is relatively complex, fixed thresholds or standards may not be applicable to all situations, which may lead to loss or accidental deletion of information; in direction 3), the method of segmenting long documents may also lead to a break in semantic understanding. If the segmentation is improper or the connection between segments is ignored, it will lead to vague or incomplete semantic understanding. Summary of the invention
[0005] The present disclosure provides a long document processing method, device, electronic device and medium to solve the problems in the related art. After encoding multiple text segments, the position information of each text segment is combined, and the text is processed segment by segment using a loop processing unit. When each text segment is processed in the loop processing unit, the deep semantic features of the text segment can be extracted more accurately and completely, thereby improving the processing ability of long documents and achieving comprehensive understanding and analysis of long documents.
[0006] A first aspect embodiment of the present disclosure proposes a long document processing method, which includes: encoding multiple text segments in a long document, and obtaining a sequence vector of each of the multiple text segments in combination with position information of the multiple text segments at preset intervals in the long document; inputting the sequence vector of each of the multiple text segments into a loop processing unit in turn to obtain a deep semantic feature of each text segment; and predicting the deep semantic feature of the long document based on the deep semantic feature of each text segment.
[0007] In some embodiments of the present disclosure, multiple text segments are encoded and a sequence vector of each of the multiple text segments is obtained, which includes: obtaining a long document and determining the text type of the long document; based on the text type, the long document is segmented with a preset segmentation length and a preset segmentation strategy corresponding to the text type to obtain multiple text segments in the long document.
[0008] In some embodiments of the present disclosure, encoding multiple text segments and obtaining a sequence vector of each of the multiple text segments includes: encoding the multiple text segments using a pre-trained language model to obtain an encoding vector of each of the multiple text segments; determining position information of each of the multiple text segments in a preset interval of a long document, and converting the position information into a position vector; merging the position vector and the encoding vector to obtain a merged sequence vector.
[0009] In some embodiments of the present disclosure, the sequence vector of each text segment in a plurality of text segments is input into a loop processing unit in turn to obtain the deep semantic features of each text segment, including: determining the sequence length corresponding to each text segment in a plurality of text segments; inputting the sequence vector and sequence length of each text segment in a plurality of text segments into the loop processing unit in turn, performing serialization modeling on the plurality of text segments through the attention mechanism in the loop processing unit, and obtaining the dependency relationship and timing information between each text segment in the plurality of text segments; based on the dependency relationship and timing information, performing text processing on each text segment using an initial hidden state vector or a first hidden state vector, to obtain the deep semantic features of each text segment in the plurality of text segments.
[0010] In some embodiments of the present disclosure, based on dependency and timing information, text processing is performed on each text segment using an initial hidden state vector or a first hidden state vector to obtain deep semantic features of each text segment in multiple text segments, including: inputting a sequence vector and a sequence length of a first text segment in multiple text segments into a loop processing unit, and based on the dependency and timing information, obtaining the deep semantic features and the first hidden state vector of the first text segment using the initial hidden state vector, the first hidden state vector being used to indicate contextual semantic information of the first text segment; inputting a sequence vector and a sequence length of a second text segment in multiple text segments into a loop processing unit, and based on the dependency and timing information, text processing is performed on the second text segment using the contextual semantic information of the first text segment in the hidden state vector of the first text segment to obtain the deep semantic features of the second text segment, the second text segment being text processed after the first text segment is text processed.
[0011] In some embodiments of the present disclosure, based on the deep semantic features of each text segment, predicting the deep semantic features of a long document includes: utilizing the attention mechanism of a cyclic processing unit to aggregate the deep semantic features of each text segment in a plurality of text segments to obtain the deep semantic features of the long document.
[0012] In some embodiments of the present disclosure, predicting the deep semantic features of a long document based on the deep semantic features of each text segment includes: determining the deep semantic features of a third text segment among multiple text segments, and using the deep semantic features of the third text segment as the deep semantic features of the long document, the third text segment being the last text segment to be processed among the multiple text segments.
[0013] A second aspect embodiment of the present disclosure proposes a long document processing device, which includes: a pre-trained language module, a loop processing unit and an aggregation prediction module; the pre-trained language module is used to encode multiple text segments in a long document, and combine the position information of the multiple text segments at preset intervals in the long document to obtain a sequence vector of each of the multiple text segments; the loop processing unit is used to input the sequence vector of each of the multiple text segments into the loop processing unit in turn to obtain the deep semantic features of each text segment; the aggregation prediction module is used to predict the deep semantic features of the long document based on the deep semantic features of each text segment.
[0014] The third aspect embodiment of the present disclosure proposes an electronic device, comprising: a processor and a memory for storing a computer program that can be run on the processor, wherein the processor, when used to run the computer program, executes the method described in the first aspect embodiment of the present disclosure.
[0015] The fourth aspect embodiment of the present disclosure proposes a non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to enable a computer to execute the method described in the first aspect embodiment of the present disclosure.
[0016] In summary, according to the long document processing method proposed in the present invention, by encoding multiple text segments in a long document and combining the position information of the multiple text segments at preset intervals in the long document, a sequence vector of each text segment in the multiple text segments is obtained; the sequence vector of each text segment in the multiple text segments is input into the loop processing unit in turn to obtain the deep semantic features of each text segment; based on the deep semantic features of each text segment, the deep semantic features of the long document are predicted, so that when the loop processing unit uses the sequence vector with position information to perform text processing on each text segment, the deep semantic features of the text segment can be extracted more accurately and completely, thereby improving the processing capability of long documents and achieving a comprehensive understanding and analysis of long documents.
[0017] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] The drawings herein are incorporated into and constitute a part of the specification, illustrate embodiments consistent with the present disclosure, and together with the description are used to explain the principles of the present disclosure, and do not constitute improper limitations on the present disclosure.
[0019] Figure 1 A flowchart of a long document processing method provided by an embodiment of the present disclosure;
[0020] Figure 2 A flowchart of a long document processing method provided by an embodiment of the present disclosure;
[0021] Figure 3 A schematic diagram of an encoder of a cyclic processing unit provided in an embodiment of the present disclosure;
[0022] Figure 4 A framework diagram of a specific long document processing system provided by an embodiment of the present disclosure;
[0023] Figure 5 A schematic diagram of the structure of a long document processing device provided by an embodiment of the present disclosure;
[0024] Figure 6 A schematic diagram of the structure of an electronic device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION
[0025] The embodiments of the present disclosure are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions.
[0026] In order to solve the problems existing in the related art, the present invention combines the position information of each text segment after encoding multiple text segments, and uses a loop processing unit to serialize and model the multiple text segments, so that when the loop processing unit performs text processing on each text segment, the deep semantic features of the text segment can be extracted more accurately and completely, thereby learning the context structure and global information of long documents, improving the processing ability of long documents, and thus achieving comprehensive understanding and analysis of long documents. At the same time, when the deep semantic features of multiple text segments are applied to various long document tasks, such as classification, question and answer, reading comprehension, text summarization, etc., good results are achieved in terms of performance and efficiency.
[0027] The method proposed in the present disclosure can process long documents efficiently and reliably, and can be specifically applied to scenarios such as information extraction, question-answering systems, automatic translation, text comparison and alignment, etc., which are not limited in the embodiments of the present disclosure.
[0028] The long document processing method provided by this application is described in detail below with reference to the accompanying drawings.
[0029] Figure 1 A flowchart of a long document processing method provided by an embodiment of the present disclosure. Figure 1 As shown, the long document processing method includes steps 101-103.
[0030] Step 101 : encode multiple text segments in a long document, and obtain a sequence vector of each text segment in the multiple text segments in combination with position information of the multiple text segments at preset intervals in the long document.
[0031] In an embodiment of the present disclosure, obtaining a sequence vector of each text segment in a plurality of text segments may be implemented by utilizing a pre-trained language module in a long document processing system of the present disclosure, and specifically may be implemented by a pre-trained language model in the pre-trained language module.
[0032] Multiple text segments in a long document are obtained by segmenting the long text. The sequence vector includes the encoding vectors after encoding the multiple text segments, and the position information of each text segment within the preset interval of the long document. Among them, the preset interval refers to the upper and lower limit intervals between the encoder and the decoder that are preset by the staff based on experience. This preset interval can be adjusted according to the needs of the actual application and is not limited in the embodiment of the present disclosure. The position information refers to the position coordinates of the current text segment within the preset interval.
[0033] The present disclosure can identify the relative position or order of each text segment in a long document through position information. By obtaining the position information of each text segment at a preset interval in a long document, each text segment can be accurately located and edited, thereby achieving effective processing and management of the long document.
[0034] Step 102 , sequentially inputting the sequence vector of each text segment in the plurality of text segments into a loop processing unit to obtain a deep semantic feature of each text segment.
[0035] In an embodiment of the present disclosure, the sequence vector of each text segment obtained through step 101 is input into a loop processing unit in sequence according to the order of each text segment in the multiple text segments. The loop processing unit can perform text processing on each text segment, thereby extracting deep semantic features of each text segment.
[0036] Among them, deep semantic features refer to feature vectors that can reflect the deep meaning and intention in the text. Deep semantic features are usually keywords, phrases, sentences, etc. extracted from the text, which can express the theme, emotion, intention and other information of the text.
[0037] The recurrent processing unit may refer to a recurrent Transformer structural unit, which is a model that combines a recurrent neural network (RNN) and a Transformer structure. This model combines the sequence processing capability of the RNN and the attention mechanism of the Transformer, aiming to improve the performance and efficiency of the model when processing sequence data. It should be noted that the recurrent processing unit in the present disclosure can be combined with a gating mechanism to control the transmission of information flow. By combining the gating mechanism, the recurrent processing unit can better capture patterns and relationships in the sequence data, thereby accurately and completely extracting the deep semantic features of the text segment.
[0038] Step 103: predict the deep semantic features of the long document based on the deep semantic features of each text segment.
[0039] In an embodiment of the present disclosure, the prediction of deep semantic features of a long document may be implemented through an aggregation prediction module in a long document processing system.
[0040] Among them, there are two ways to predict the deep semantic features of a long document in the present disclosure. One is to use the deep semantic features of the last text segment in multiple text segments to determine the deep semantic features of the long document; the other is to aggregate the deep semantic features of each text segment in multiple text segments to determine the deep semantic features of the long document. The specific prediction method can be determined according to actual conditions and is not limited in the embodiments of the present disclosure.
[0041] It is understandable that after the deep semantic features of a long document are predicted by the present disclosure, the deep semantic features can be used to perform downstream tasks such as classification, sentiment analysis, summary generation, span extraction, etc. The deep semantic features of each text segment of the present disclosure can achieve significant improvement in the performance of various long document tasks. For example, in a question-answering system, we can use deep semantic features to understand the semantics of a question and find the correct answer in a long document.
[0042] In summary, according to the long document processing method proposed in the present invention, by encoding multiple text segments in a long document and combining the position information of the multiple text segments at preset intervals in the long document, a sequence vector of each text segment in the multiple text segments is obtained; the sequence vector of each text segment in the multiple text segments is input into the loop processing unit in turn to obtain the deep semantic features of each text segment; based on the deep semantic features of each text segment, the deep semantic features of the long document are predicted, so that the deep semantic features of the text segment can be extracted more accurately and completely when the loop processing unit performs text processing on each text segment, thereby improving the processing capability of long documents and achieving a comprehensive understanding and analysis of long documents.
[0043] based on Figure 1 The embodiment shown, Figure 2 The following further illustrates a flow chart of a long document processing method proposed in the present disclosure. Figure 2 based on Figure 1 In the embodiment shown, step 101 and step 102 are further defined. Figure 2 In the embodiment shown, step 101 includes step 201 and step 202, step 101 includes step 203, step 204 and step 205, and step 102 includes step 206, step 207 and step 208. Figure 2 As shown, the method comprises the following steps:
[0044] Step 201, obtain a long document and determine the text type of the long document.
[0045] In an embodiment of the present disclosure, based on the user's input information, a long document corresponding to the current input information is obtained. At the same time, the relevant information of the current long document is analyzed to determine the text type of the long document. The user's input information can be determined according to the actual situation, and the forms of obtaining long documents in different input methods can be the same or different. For example, the user's input information may include text input, voice input, image input, etc. For text input, the user's input information needs to be recognized and converted to obtain the long document corresponding to the current input information; for voice input, the voice input information can be converted into a long document through voice recognition technology; for image input, image recognition and conversion technology can be used to convert picture information into a corresponding long document.
[0046] When determining the text type of a long document, the present disclosure may specifically determine the text type of the current long document by analyzing at least one of the text content, keywords, and text structure of the long document.
[0047] In an optional embodiment of the present disclosure, when a user inputs input information by voice input, the present disclosure uses voice recognition technology to identify the long document corresponding to the input information of the voice input. And by analyzing at least one of the text content, keywords and text structure of the long document, the text type of the current long document is determined. If it is analyzed that the text content of the current long document involves regulations, requirements, processes, responsibilities and other aspects, the text contains keywords such as regulations, systems, processes, responsibilities, and the text structure includes parts such as titles, texts, clauses, appendices, etc., then the text type of the current long document can be determined to be rules and regulations.
[0048] Step 202 , based on the text type, the long document is segmented using a preset segmentation length and a preset segmentation strategy corresponding to the text type to obtain multiple text segments in the long document.
[0049] In an embodiment of the present disclosure, after determining the text type of a long document, the preset segmentation length and preset segmentation strategy corresponding to the text type can be determined, and the current long document can be segmented by using the determined preset segmentation length and preset segmentation strategy to obtain multiple text segments of the long document.
[0050] Among them, the preset segmentation length is set in advance by the staff according to the text type based on experience. For example, when the text type is rules and regulations, the preset segmentation length can be 8 bytes or 4 bytes. Similarly, the preset segmentation strategy is used to guide how to segment long documents, and is also the segmentation strategy corresponding to the text type pre-set by the staff based on experience. When formulating the preset segmentation strategy, it is necessary to consider the content, structure and other relevant factors of the text to ensure the accuracy and effectiveness of the segmentation. For example, the preset segmentation strategy can determine whether overlap is required during segmentation based on whether there is repeated content in the text content of the current long document. The preset segmentation length and the preset segmentation strategy are determined based on the text type. Different text types may have the same or different corresponding preset segmentation lengths and preset segmentation strategies. The specific situation is mainly based on the actual situation and is not limited in the embodiments of the present disclosure.
[0051] Step 203: Encode the multiple text segments using the pre-trained language model to obtain an encoding vector for each of the multiple text segments.
[0052] In an embodiment of the present disclosure, the multiple text segments segmented in step 202 are encoded respectively by the pre-trained language model of the pre-trained language module in the long document processing system, so as to obtain the encoding vector of each text segment. For example, the multiple segmented text segments {seg1, seg2, ..., segn} are respectively encoded into vectorized representations by a shared pre-trained language model, that is, the encoding vector is obtained.
[0053] A pre-trained language model is a deep learning model that automatically captures the structure and semantic information of a language by learning from a large corpus. In a long document processing system, a pre-trained language model is used to encode multiple text segments after segmentation. When encoding the segmented text segments, the pre-trained language model can convert them into high-dimensional vector representations that capture the semantic information and contextual relationships of the text segments. The present disclosure uses a pre-trained language model for encoding to help long document processing systems better understand and analyze text content, thereby performing more accurate classification, summarization, sentiment analysis, and other tasks.
[0054] In an optional embodiment of the present disclosure, the present disclosure may encode each text segment using a pre-trained language model, as shown in Formula 1:
[0055] S k =f LM (w1,w2,…,w n ) (i∈[1,n]) Formula 1
[0056] Where k represents the kth text paragraph, n represents the maximum text paragraph length set, S k Represents the encoding vectors of k text segments.
[0057] Step 204: determine the position information of each text segment in the plurality of text segments in a preset interval of the long document, and convert the position information into a position vector.
[0058] In an embodiment of the present disclosure, in order to solve the problem of position information loss in the encoding of a single text segment, the present disclosure may consider the position information of the text segment in a long document, that is, convert the learned position information of each text segment in a preset interval of the long document into a position vector to indicate the relative position of each text segment in the document.
[0059] Specifically, for each text segment, its position coordinates within a preset interval relative to the long document may be calculated, the position coordinates may be used as position information, and converted into a position vector.
[0060] Step 205: merge the position vector and the encoding vector to obtain a merged sequence vector.
[0061] In an embodiment of the present disclosure, for each text segment, the position vector and the encoding vector obtained above may be merged to obtain a sequence vector corresponding to each text segment.
[0062] Specifically, the position vector and the encoding vector can be merged through a simple addition or concatenation operation, so that the sequence vector of each text segment contains not only semantic information and contextual relationships, but also its position information in the long document. In this way, the problem of position information loss in the encoding of a single text segment can be solved, and the representation ability of the long document processing system can be improved. At the same time, the introduction of this position information also helps to better understand the structure and semantic role of the text segment in the long document, thereby providing more accurate information for subsequent text analysis and processing.
[0063] In an optional embodiment of the present disclosure, in the encoding of a single text segment, the position embedding configured in the pre-trained language model will be recalculated in each segment, thereby losing the specific position of each text segment in the entire document. This position bias may lead to a decrease in representation ability. In order to solve this problem, the present disclosure can assign the learned position vector as a complementary feature to each segment to indicate its relative position in the document, and combine the initial encoding vector and the corresponding position vector to update the encoding vector of the original text segment, as shown in Formula 2:
[0064]
[0065] Among them, S k represents the encoding vector of the kth text segment, represents the position vector of the kth text segment, A sequence vector representing the k-th text segment.
[0066] Step 206: Determine the sequence length corresponding to each text segment in the plurality of text segments.
[0067] In an embodiment of the present disclosure, during the long document processing, each text segment may contain a different number of words or symbols, so their sequence lengths will also be different. Determining the sequence length of each text segment helps to further understand its content, structure, and semantic information. The present disclosure can determine the sequence length of each text segment by calculating the number of words or characters in each text segment. For example, natural language processing technology can be used to segment words and count the number of words in each text segment; or, the number of characters in each text segment can be counted, including letters, numbers, and punctuation marks, etc.; or, the semantic information and contextual relationship of the text segment can be considered, so as to use more advanced natural language processing technology to determine its sequence length. The specific method of determining the sequence length is determined according to the actual situation and is not limited in the embodiments of the present disclosure.
[0068] Step 207, input the sequence vector and sequence length of each text segment in the multiple text segments into the loop processing unit respectively, perform serialization modeling on the multiple text segments through the attention mechanism in the loop processing unit, and obtain the dependency and timing information between each text segment in the multiple text segments.
[0069] In an embodiment of the present disclosure, a loop processing unit is used to perform text processing on each text segment. By inputting the sequence vector and sequence length of each text segment into the loop processing unit, the text content can be better understood, and the semantic information and temporal relationship between the text segments can be captured. This processing method can effectively process long sequence data, and takes into account the dependency and timing information between the text segments, thereby improving the performance and accuracy of the loop processing unit. In the loop processing unit, an attention mechanism is used to focus on the important information in each text segment, and to establish the dependency and timing relationship between the text segments based on this information.
[0070] Dependencies refer to the semantic connections between multiple text segments. These connections may be based on logical, semantic, or grammatical relationships between words, phrases, or sentences. By capturing these dependencies, the recurrent processing unit can better understand the text content and capture the semantic connections between text segments.
[0071] Temporal relations refer to the order relations between text segments. By capturing the temporal relations between text segments, the recurrent processing unit can better process sequence data and improve the performance and accuracy when applied in various tasks.
[0072] Step 208 : Based on the dependency relationship and the timing information, text processing is performed on each text segment using the initial hidden state vector or the first hidden state vector to obtain a deep semantic feature of each text segment in the multiple text segments.
[0073] In an embodiment of the present disclosure, based on the dependency relationship and the timing information, the initial hidden state vector or the first hidden state vector is combined to perform text processing on each text segment according to the gating mechanism to obtain the deep semantic features of each text segment in the multiple text segments.
[0074] Specifically, the sequence vector and sequence length of the first text segment among the multiple text segments can be input into the loop processing unit, and based on the dependency relationship and timing information, the initial hidden state vector is used to obtain the deep semantic features and the first hidden state vector of the first text segment, and the first hidden state vector is used to indicate the contextual semantic information of the first text segment; the sequence vector and sequence length of the second text segment among the multiple text segments are input into the loop processing unit, and based on the dependency relationship and timing information, the contextual semantic information of the first text segment in the hidden state vector of the first text segment is used to process the second text segment, and the deep semantic features of the second text segment are obtained, and the second text segment is processed after the first text segment is processed. Among them, the initial hidden state vector is the initial hidden state pre-set by the staff, for example, it can be set to 0 or 1. It can be understood that only the first processed text segment uses the initial hidden state vector for text processing, and the corresponding other text segments can use the hidden state vector generated by the previous text segment, that is, the first hidden state vector for text processing.
[0075] In an optional embodiment of the present disclosure, taking the loop processing unit as a Transformer unit with a loop structure as an example, Figure 3A schematic diagram of an encoder of a cyclic processing unit shown, the encoder includes a Multi-Head Attention and State Transfer Attention module of self-attention and cross-attention in the Transformer layer Decoder structure, and a gating module for controlling the transmission of historical information flow, wherein Hidden Embeddings represents a hidden state vector; Add & Norm layer is a normalization layer, wherein Add represents a residual connection (Residual Connection) for preventing network degradation, and Norm represents Layer Normalization for normalizing the activation value of each layer. The Transformer unit of the cyclic structure disclosed in the present invention can receive two tensors as input, that is, the sequence vector and sequence length of each text segment as input, wherein the sequence length of each text segment varies with different data sets. The output of the Transformer unit of the cyclic structure after text processing for each text segment is also two tensors, one is used as a local representation of the text segment, that is, the deep semantic features of each text segment, and the other is passed to the next text segment as a hidden state, that is, the hidden state vector. The process of passing the hidden state vector to the next text segment uses a gating mechanism to control the transmission of information flow, so that the deep semantic features of each text segment retain the previous semantic information. After iterating over multiple consecutive text paragraphs, the deep semantic features of each paragraph will be integrated with the historical paragraph information and the global structural information of the long document.
[0076] Step 209 : predicting the deep semantic features of the long document based on the deep semantic features of each text segment.
[0077] In an embodiment of the present disclosure, the present disclosure can use the attention mechanism of the loop processing unit to aggregate the deep semantic features of each text segment in multiple text segments to obtain the deep semantic features of the long document. Alternatively, the deep semantic features of the third text segment in the multiple text segments can be determined, and the deep semantic features of the third text segment are used as the deep semantic features of the long document, and the third text segment is the text segment that is the last to be processed among the multiple text segments.
[0078] Among them, the aggregation processing can adopt aggregation methods such as summation, averaging, maximum pooling, and minimum pooling to integrate local features into global features, that is, to fuse the deep semantic features of each text segment into the deep semantic features of the current long document.
[0079] In summary, the long document processing method disclosed in the present invention makes full use of the long document processing system disclosed in the present invention to realize long document processing, and at the same time expands the length of the processable text sequence in the process of text segmentation, and uses the Transformer unit with a loop structure to solve the problem of semantic fragmentation of long documents caused by the previous single segmentation method, so as to improve the ability to model and represent the overall long document, and can be used in a variety of natural language processing tasks, all of which have achieved excellent performance.
[0080] based on Figure 1 , Figure 2 The embodiment shown, as Figure 4 As shown, the present disclosure provides a specific framework diagram of a long document processing system.
[0081] In the disclosed embodiment, the long document processing system includes a pre-trained language module for text segment encoding, a segment-level loop processing unit, and an aggregation prediction module. The pre-trained semantic module for text segment encoding can specifically encode the text segment through the pre-trained language model in the module, and the segment-level loop processing unit can specifically be a Transformer unit of a loop structure.
[0082] In the embodiment of the present disclosure, it is first necessary to perform reasonable document segmentation on the acquired long document. Specifically, according to the text type of the current long document, different preset segmentation strategies (whether there is overlap, etc.) and preset segmentation lengths (64, 128, 256, 384, 512) can be used to segment the current long document to obtain multiple text segments of the long document. Then, a shared pre-trained language model in the pre-trained language module is used to encode the multiple text segments, thereby obtaining the encoding representation of the multiple text segments, that is, the encoding vector. Among them, the result output by the pre-trained language model can be a token-level text segment encoding vector, which means that the text is segmented and each token is given certain semantic information or feature representation for subsequent processing and analysis. Since there is a problem of position information loss during the encoding process, the present disclosure combines the position information of each text segment on this basis, and converts the position information as a complementary feature to each segment to obtain the final sequence vector, so as to ensure that the global position information of each segment is not lost.
[0083] When the sequence vector of each text segment is input into the loop processing unit, the present disclosure also needs to determine the sequence length of each text segment, and input the sequence length into the loop processing unit. The loop processing unit uses its internal attention mechanism to perform text processing on each text segment in turn, thereby obtaining the deep semantic features and hidden state vector of each text segment. The hidden state vector represents the contextual semantic information of each text segment. At the same time, the present disclosure uses a gating mechanism to transfer the hidden state features of each text segment to the next text segment of the text segment for text processing of the next text segment, so that each text segment can be combined with the historical semantic information of the previous text segment, thereby improving the accuracy and correctness of extracting the deep semantic features of each text segment.
[0084] After obtaining the deep semantic features of each text segment, the aggregation prediction module in the present disclosure can further process the output of the loop processing module to obtain the deep semantic features of the current long document. Among them, the aggregation prediction module can obtain the deep semantic features of the long document in two ways. One way is to aggregate the deep semantic features of multiple text segments by using the attention mechanism in the loop processing unit. The other way is to directly use the deep semantic features of the last text segment as the final deep semantic features of the entire long document, and then use these deep semantic features to perform downstream tasks. This representation of text segments has achieved significant improvement in the performance of various long document tasks.
[0085] In summary, the deep semantic features obtained through the long document processing system disclosed in the present invention have good effects on various long document tasks.
[0086] Figure 5 FIG. 5 is a schematic diagram of a long document processing device 500 provided in an embodiment of the present disclosure. Figure 5 As shown, the long document processing device includes:
[0087] A pre-trained language module 510, a loop processing unit 520, and an aggregate prediction module 530;
[0088] The pre-trained language module 510 is used to encode multiple text segments in a long document, and obtain a sequence vector of each text segment in the multiple text segments in combination with position information of the multiple text segments at preset intervals in the long document;
[0089] The loop processing unit 520 is used to sequentially input the sequence vector of each text segment in the plurality of text segments into the loop processing unit to obtain the deep semantic features of each text segment;
[0090] The aggregate prediction module 530 is used to predict the deep semantic features of the long document based on the deep semantic features of each text segment.
[0091] In some embodiments of the present disclosure, the device 500 also includes: a segmentation unit, which is used to obtain a long document and determine the text type of the long document before encoding multiple text segments and obtaining a sequence vector of each of the multiple text segments; based on the text type, the long document is segmented with a preset segmentation length and a preset segmentation strategy corresponding to the text type to obtain multiple text segments in the long document.
[0092] In some embodiments of the present disclosure, the pre-trained language module 510 is used to: encode multiple text segments using a pre-trained language model to obtain an encoding vector for each of the multiple text segments; determine the position information of each of the multiple text segments in a preset interval of a long document, and convert the position information into a position vector; merge the position vector and the encoding vector to obtain a merged sequence vector.
[0093] In some embodiments of the present disclosure, the pre-trained language module 510 is used to: determine the sequence length corresponding to each text segment in a plurality of text segments; input the sequence vector and sequence length of each text segment in the plurality of text segments into a loop processing unit in turn, perform serialization modeling on the plurality of text segments through an attention mechanism in the loop processing unit, and obtain dependency relationships and timing information between each text segment in the plurality of text segments; perform text processing on each text segment using an initial hidden state vector or a first hidden state vector based on the dependency relationships and timing information, so as to obtain deep semantic features of each text segment in the plurality of text segments.
[0094] In some embodiments of the present disclosure, the pre-trained language module 510 is used to: input the sequence vector and sequence length of a first text segment among multiple text segments into a loop processing unit, and based on the dependency relationship and timing information, use the initial hidden state vector to obtain the deep semantic features and the first hidden state vector of the first text segment, where the first hidden state vector is used to indicate the contextual semantic information of the first text segment; input the sequence vector and sequence length of a second text segment among multiple text segments into the loop processing unit, and based on the dependency relationship and timing information, use the contextual semantic information of the first text segment in the hidden state vector of the first text segment to perform text processing on the second text segment to obtain the deep semantic features of the second text segment, where the second text segment is text processed after the first text segment is text processed.
[0095] In some embodiments of the present disclosure, the aggregation prediction module 530 is used to: utilize the attention mechanism of the loop processing unit to aggregate the deep semantic features of each text segment in multiple text segments to obtain the deep semantic features of the long document.
[0096] In some embodiments of the present disclosure, the aggregation prediction module 530 is used to: determine the deep semantic features of a third text segment among multiple text segments, and use the deep semantic features of the third text segment as the deep semantic features of the long document, and the third text segment is the last text segment to be processed among the multiple text segments.
[0097] In summary, through the long document processing device, by encoding multiple text segments in a long document, and combining the position information of the multiple text segments at preset intervals in the long document, a sequence vector of each text segment in the multiple text segments is obtained; the sequence vector of each text segment in the multiple text segments is input into the loop processing unit in turn to obtain the deep semantic features of each text segment; based on the deep semantic features of each text segment, the deep semantic features of the long document are predicted, so that when the loop processing unit uses the sequence vector with position information to perform text processing on each text segment, the deep semantic features of the text segment can be extracted more accurately and completely, thereby improving the processing capability of long documents, thereby achieving a comprehensive understanding and analysis of long documents.
[0098] Corresponding to the methods provided in the above-mentioned embodiments, the present disclosure also provides a long document processing device. Since the device provided in the embodiment of the present disclosure corresponds to the methods provided in the above-mentioned embodiments, the implementation method is also applicable to the device provided in this embodiment and will not be described in detail in this embodiment.
[0099] In the embodiments provided in the present application, the methods and devices provided in the embodiments of the present application are introduced. In order to implement the functions in the methods provided in the embodiments of the present application, the electronic device may include a hardware structure and a software module, and implement the functions in the form of a hardware structure, a software module, or a hardware structure plus a software module. A function of the functions may be executed in the form of a hardware structure, a software module, or a hardware structure plus a software module.
[0100] Figure 6 is a block diagram of an electronic device 600 for implementing the above-mentioned long document processing method according to an exemplary embodiment. For example, the electronic device 600 may be a mobile phone, a computer, a messaging device, a game console, a tablet device, a medical device, a fitness device, a personal digital assistant, etc.
[0101] Reference Figure 6 The electronic device 600 may include a communication interface 601, which can interact with other devices; a processor 602, which is connected to the communication interface 601 to interact with other devices and is used to execute the method provided by one or more of the above technical solutions when running a computer program; and a memory 603, on which the computer program is stored. Specifically, the specific processing process of the processor 602 can refer to the long document processing method described in the above embodiment of the present disclosure.
[0102] Of course, in actual application, the various components in the electronic device 600 are coupled together through the bus system 604. It can be understood that the bus system 604 is used to realize the connection and communication between these components. In addition to the data bus, the bus system 604 also includes a power bus, a control bus, and a status signal bus. However, for the sake of clarity, Figure 6 Various buses are labeled as bus system 604 .
[0103] The memory 603 in the embodiment of the present application is used to store various types of data to support the operation of the electronic device 600. Examples of such data include: any computer program used to operate on the electronic device 600.
[0104] The method disclosed in the above embodiment of the present application can be applied to the processor 602, or implemented by the processor 602. The processor 602 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit or software instructions in the processor 602. The above processor 602 may be a general processor, a digital signal processor (DSP, Digital Signal Processor), or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc. The processor 602 can implement or execute the various methods, steps and logic block diagrams disclosed in the embodiments of the present application. The general processor may be a microprocessor or any conventional processor, etc. In combination with the steps of the method disclosed in the embodiment of the present application, it can be directly embodied as a hardware decoding processor to execute, or it can be executed by a combination of hardware and software modules in the decoding processor. The software module can be located in a storage medium, which is located in the memory 603, and the processor 602 reads the information in the memory 603 and completes the steps of the above method in combination with its hardware.
[0105] In an exemplary embodiment, the electronic device 600 can be implemented by one or more application specific integrated circuits (ASIC), DSP, programmable logic device (PLD), complex programmable logic device (CPLD), field programmable gate array (FPGA), general processor, controller, microcontroller (MCU), microprocessor, or other electronic components to execute the aforementioned method.
[0106] The embodiments of the present disclosure further provide a non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to enable a computer to execute the long document processing method described in the above embodiments of the present disclosure.
[0107] The embodiments of the present disclosure further provide a computer program product, including a computer program, which executes the long document processing method described in the above embodiments of the present disclosure when a processor executes the computer program.
[0108] An embodiment of the present disclosure also proposes a chip, which includes one or more interface circuits and one or more processors; the interface circuit is used to receive signals from a memory of an electronic device and send signals to the processor, the signals include computer instructions stored in the memory, and when the processor executes the computer instructions, the electronic device executes the long document processing method described in the above embodiment of the present disclosure.
[0109] It should be noted that the terms "first", "second", etc. in the specification and claims of the present disclosure and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present disclosure described herein can be implemented in an order other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.
[0110] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "illustrative embodiments", "examples", "specific examples" or "some examples" etc. means that the specific features, structures, materials or characteristics described in conjunction with the embodiments or examples are included in at least one embodiment or example of the present invention. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner.
[0111] Any process or method description in a flowchart or otherwise described herein may be understood to represent a module, segment or portion of code that includes one or more executable instructions for implementing the steps of a specific logical function or process, and the scope of the preferred embodiments of the present invention includes alternative implementations in which functions may not be performed in the order shown or discussed, including performing functions in a substantially simultaneous manner or in the reverse order depending on the functions involved, which should be understood by those skilled in the art to which the embodiments of the present invention belong.
[0112] The logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as an ordered list of executable instructions for implementing logical functions, and can be embodied in any computer-readable medium for use by an instruction execution system, device or apparatus (such as a computer-based system, a system including a processing module, or other system that can fetch instructions from an instruction execution system, device or apparatus and execute instructions), or in combination with these instruction execution systems, devices or apparatuses. For the purposes of this specification, "computer-readable medium" can be any device that can contain, store, communicate, propagate or transmit a program for use by an instruction execution system, device or apparatus, or in combination with these instruction execution systems, devices or apparatuses. More specific examples of computer-readable media (a non-exhaustive list) include the following: an electrical connection with one or more wires (control method), a portable computer disk box (magnetic device), a random access memory (RAM), a read-only memory (ROM), an erasable and programmable read-only memory (EPROM or flash memory), a fiber optic device, and a portable compact disk read-only memory (CDROM). In addition, the computer-readable medium may even be paper or other suitable medium on which the program is printed, since the program may be obtained electronically, for example, by optically scanning the paper or other medium and then editing, interpreting or otherwise processing in a suitable manner if necessary, and then stored in a computer memory.
[0113] It should be understood that the various parts of the embodiments of the present invention can be implemented by hardware, software, firmware or a combination thereof. In the above embodiments, multiple steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented by hardware, as in another embodiment, it can be implemented by any one of the following technologies known in the art or their combination: a discrete logic circuit having a logic gate circuit for implementing a logic function for a data signal, a dedicated integrated circuit having a suitable combination of logic gate circuits, a programmable gate array (PGA), a field programmable gate array (FPGA), etc.
[0114] A person skilled in the art may understand that all or part of the steps in the method for implementing the above-mentioned embodiment may be completed by instructing related hardware through a program, and the program may be stored in a computer-readable storage medium, which, when executed, includes one or a combination of the steps of the method embodiment.
[0115] In addition, each functional unit in each embodiment of the present invention may be integrated into a processing module, or each unit may exist physically separately, or two or more units may be integrated into one module. The above-mentioned integrated module may be implemented in the form of hardware or in the form of a software functional module. If the integrated module is implemented in the form of a software functional module and sold or used as an independent product, it may also be stored in a computer-readable storage medium. The above-mentioned storage medium may be a read-only memory, a disk or an optical disk, etc.
[0116] Although the embodiments of the present invention have been shown and described above, it is to be understood that the above embodiments are exemplary and are not to be construed as limitations of the present invention. A person skilled in the art may make changes, modifications, substitutions and variations to the above embodiments within the scope of the present invention.
Claims
1. A long document processing method, characterized in that: The method comprises: Encoding a plurality of text segments in a long document, and obtaining a sequence vector of each text segment in the plurality of text segments in combination with position information of the plurality of text segments at preset intervals in the long document; Inputting the sequence vector of each text segment in the plurality of text segments into the loop processing unit in turn to obtain the deep semantic features of each text segment; Based on the deep semantic features of each text segment, the deep semantic features of the long document are predicted.
2. The method according to claim 1, characterized in that The encoding of the multiple text segments to obtain a sequence vector of each text segment in the multiple text segments includes: Acquire a long document and determine the text type of the long document; Based on the text type, the long document is segmented using a preset segmentation length and a preset segmentation strategy corresponding to the text type to obtain a plurality of text segments in the long document.
3. The method according to claim 1, characterized in that The encoding of the multiple text segments in the long document and obtaining the sequence vector of each text segment in the multiple text segments in combination with the position information of the multiple text segments at preset intervals in the long document comprises: Encoding the multiple text segments using a pre-trained language model to obtain an encoding vector for each of the multiple text segments; Determine position information of each text segment in the plurality of text segments in the preset interval of the long document, and convert the position information into a position vector; The position vector and the encoding vector are combined to obtain a combined sequence vector.
4. The method according to claim 1, characterized in that: The step of sequentially inputting the sequence vector of each text segment in the plurality of text segments into the loop processing unit to obtain the deep semantic features of each text segment comprises: Determining a sequence length corresponding to each text segment in the plurality of text segments; The sequence vector and sequence length of each text segment in the multiple text segments are input into the loop processing unit in sequence, and the multiple text segments are serialized and modeled by the attention mechanism in the loop processing unit to obtain the dependency relationship and timing information between each text segment in the multiple text segments; Based on the dependency relationship and the timing information, text processing is performed on each of the text segments using an initial hidden state vector or a first hidden state vector to obtain a deep semantic feature of each of the multiple text segments.
5. The method according to claim 4, characterized in that The step of performing text processing on each text segment using an initial hidden state vector or a first hidden state vector based on the dependency relationship and the timing information to obtain a deep semantic feature of each text segment in the multiple text segments includes: Inputting a sequence vector and a sequence length of a first text segment among the multiple text segments into a loop processing unit, and based on the dependency relationship and the timing information, using the initial hidden state vector to obtain a deep semantic feature and a first hidden state vector of the first text segment, wherein the first hidden state vector is used to indicate contextual semantic information of the first text segment; The sequence vector and sequence length of the second text segment among the multiple text segments are input into the loop processing unit, and based on the dependency relationship and the timing information, the second text segment is text-processed using the contextual semantic information of the first text segment in the hidden state vector of the first text segment to obtain the deep semantic features of the second text segment, and the second text segment is text-processed after the first text segment is text-processed.
6. The method according to claim 1, characterized in that The predicting the deep semantic features of the long document based on the deep semantic features of each text segment includes: The deep semantic features of each text segment in the multiple text segments are aggregated using the attention mechanism of the loop processing unit to obtain the deep semantic features of the long document.
7. The method according to claim 1, characterized in that The predicting the deep semantic features of the long document based on the deep semantic features of each text segment includes: Determine the deep semantic features of a third text segment among the multiple text segments, and use the deep semantic features of the third text segment as the deep semantic features of the long document, wherein the third text segment is the text segment that is last processed among the multiple text segments.
8. A long document processing device, characterized in that: The device comprises: Pre-trained language module, loop processing unit and aggregate prediction module; The pre-trained language module is used to encode multiple text segments in a long document, and obtain a sequence vector of each text segment in the multiple text segments in combination with position information of the multiple text segments at preset intervals in the long document; The loop processing unit is used to sequentially input the sequence vector of each text segment in the multiple text segments into the loop processing unit to obtain the deep semantic features of each text segment; The aggregation prediction module is used to predict the deep semantic features of the long document based on the deep semantic features of each text segment.
9. An electronic device, characterized in that: include: a processor and a memory for storing a computer program capable of being executed on the processor, Wherein, when the processor is used to run the computer program, it executes the method described in any one of claims 1-7.
10. A non-transitory computer-readable storage medium storing computer instructions, characterized in that: The computer instructions are used to cause the computer to execute the method according to any one of claims 1-7.
