Scanning document classification method, apparatus, device, and storage medium
By extracting visual features and performing temporal encoding on the page images of scanned documents, and combining page layout structure and inter-page association features, the problem of low classification accuracy and low efficiency caused by optical character recognition in existing technologies is solved, achieving high-precision and high-efficiency document classification.
Patent Information
- Application Number
- CN202611352152.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-02
- Publication Date
- 2026-11-20
AI Technical Summary
In existing technologies, the classification methods for scanned documents rely on optical character recognition and semantic analysis, which leads to errors in recognizing blurry, tilted, or illegible page images, affecting classification accuracy. Furthermore, the processing time is long, making it difficult to meet the needs of rapid classification of batches of multi-page documents.
By extracting visual features from the page images of scanned documents, generating single-page visual features, and performing temporal encoding based on page order, combined with page layout structure and inter-page association features, the document category can be directly identified, avoiding misidentification by optical character recognition and improving classification accuracy and efficiency.
It effectively avoids semantic understanding errors caused by optical character recognition, improves the classification accuracy and efficiency of multi-page scanned documents, and meets the needs of rapid classification of batch documents.
Smart Images

Figure CN123142243A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of image processing technology, and in particular to a method, apparatus, device and storage medium for classifying scanned documents. Background Technology
[0002] A scanned document is a digital file in which all pages are presented as images. Scanned document classification refers to the technical process of automatically classifying scanned documents based on the visual content and / or semantic information of each page's image. This technology is widely used in document management systems, intelligent office platforms, and other fields, aiming to replace manual sorting and achieve efficient batch document classification.
[0003] In existing technologies, the classification of scanned documents generally employs a scheme combining optical character recognition (OCR) and semantic analysis. This scheme performs OCR on each page of the scanned document to obtain text data from the image, and then uses natural language processing (NLP) techniques to perform semantic analysis on the text data to determine the category to which the scanned document belongs. However, in practical applications, the page images of scanned documents are often blurry, tilted, or have illegible text, leading to errors in OCR, which in turn reduces the accuracy of subsequent semantic analysis and ultimately affects classification accuracy. Summary of the Invention
[0004] This application provides a method, apparatus, device, and storage medium for classifying scanned documents, which can accurately identify document categories from two dimensions: the page layout structure features and the inter-page layout association features of the scanned document. This effectively avoids semantic understanding errors caused by misrecognition of optical characters and solves the problem of low document classification accuracy in the prior art.
[0005] Firstly, this application provides a method for classifying scanned documents, including: Visual features are extracted from each page image of the scanned document to be classified, resulting in the corresponding single-page visual features; the scanned document to be classified includes multiple page images arranged in page order. Based on the page order, the visual features of multiple single pages corresponding to the multiple page images are temporally encoded to obtain multi-page sequence features; The document category of the scanned document to be classified is determined based on the multi-page sequence features.
[0006] Secondly, this application provides a document scanning and classification device, comprising: The feature extraction module is configured to extract visual features from each page image of the scanned document to be classified, thereby obtaining the corresponding single-page visual features; the scanned document to be classified includes multiple page images arranged in page order. The temporal coding module is configured to perform temporal coding on multiple single-page visual features corresponding to the multiple page images based on the page order to obtain multi-page sequence features; The document category determination module is configured to determine the document category of the scanned document to be classified based on the multi-page sequence features.
[0007] Thirdly, this application provides a document scanning and classification device, comprising: One or more processors; A memory that stores one or more programs that, when executed by one or more processors, cause the one or more processors to implement the document classification method as described in the first aspect.
[0008] Fourthly, this application provides a storage medium containing computer-executable instructions, which, when executed by a computer processor, are used to perform the scanned document classification method as described in the first aspect.
[0009] In this application, visual features are extracted from each page image of the scanned document to be classified, resulting in corresponding single-page visual features. The scanned document to be classified includes multiple page images arranged in page order. Based on the page order, multiple single-page visual features corresponding to multiple page images are temporally encoded to obtain multi-page sequence features. The document category of the scanned document to be classified is determined based on the multi-page sequence features. Through the above technical means, visual features are directly extracted from each page image to obtain the page layout structure features of the scanned document. By temporally encoding the inter-page layout association features of the multi-page document, the key features of low-quality scanned documents can be effectively preserved. Thus, the document category can be accurately identified based on the two dimensions of page layout structure features and inter-page layout association features, effectively avoiding semantic understanding errors caused by misrecognition of optical characters, improving the classification accuracy of multi-page scanned documents, and eliminating the need for two-stage serial processing of optical recognition and semantic analysis, thereby improving classification efficiency. Attached Figure Description
[0010] Figure 1 This is a flowchart of a document classification method provided in an embodiment of this application; Figure 2 This is a flowchart of generating single-page visual features provided in an embodiment of this application; Figure 3 This is a schematic diagram illustrating the process by which a page feature map, provided in an embodiment of this application, evolves into single-page visual features; Figure 4 This is a flowchart illustrating the determination of multi-page timing characteristics provided in an embodiment of this application; Figure 5This is a flowchart illustrating the process of determining the document category of a scanned document to be classified, as provided in an embodiment of this application. Figure 6 This is a schematic diagram of the document classification network provided in an embodiment of this application; Figure 7 This is a flowchart of the training document classification model provided in the embodiments of this application; Figure 8 This is a flowchart of constructing a training sample set provided in an embodiment of this application; Figure 9 This is a flowchart of single-batch training of the model provided in the embodiments of this application; Figure 10 This is a schematic diagram of the structure of a document scanning and classification device provided in an embodiment of this application; Figure 11 This is a schematic diagram of the structure of a document scanning and classification device provided in an embodiment of this application. Detailed Implementation
[0011] To make the objectives, technical solutions, and advantages of this application clearer, specific embodiments of this application will be described in further detail below with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are merely for explaining this application and not for limiting it. It should also be noted that, for ease of description, only the parts relevant to this application are shown in the drawings, not all of them. Before discussing exemplary embodiments in more detail, it should be mentioned that some exemplary embodiments are described as processes or methods depicted as flowcharts. Although the flowcharts describe operations (or steps) as sequential processes, many of these operations can be performed in parallel, concurrently, or simultaneously. Furthermore, the order of the operations can be rearranged. A process can be terminated when its operation is completed, but it may also have additional steps not included in the drawings. A process can correspond to a method, function, procedure, subroutine, subprogram, etc.
[0012] The terms "first," "second," etc., used in the specification and claims of this application are used to distinguish similar objects and not to describe a specific order or sequence. It should be understood that such use of data can be interchanged where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein, and the objects distinguished by "first," "second," etc., are generally of the same class and the number of objects is not limited; for example, a first object can be one or more. Furthermore, in the specification and claims, "and / or" indicates at least one of the connected objects, and the character " / " generally indicates that the preceding and following objects are in an "or" relationship.
[0013] In relevant implementations, the classification of scanned documents generally employs a scheme combining optical character recognition (OCR) and semantic analysis. This method first performs OCR on each page of the scanned document, converting the image-based text into text data. Then, natural language processing (NLP) techniques are used to perform semantic analysis and keyword extraction on the text content obtained from OCR, thereby determining the document's category and completing the classification. However, in practical applications, the page images of scanned documents are often blurry, tilted, or have illegible text, leading to errors in OCR and affecting the accuracy of subsequent classification. Furthermore, documents such as exam papers and resumes, whose core features are layout-based, have sparse text information, making it difficult to effectively represent their category characteristics through textual semantics. Because this method relies on a two-stage sequential processing of OCR and semantic analysis, the classification accuracy is directly limited by the quality of OCR, and the overall processing time is long. It is difficult to guarantee stable and accurate classification of low-quality scanned documents and layout-driven documents, and it is also difficult to adapt to the rapid classification needs of batches of multi-page documents.
[0014] To address the aforementioned issues, this embodiment provides a method for classifying scanned documents. This method accurately identifies document categories from two dimensions: page layout structure features and inter-page layout association features. It eliminates the reliance on optical character recognition and semantic analysis, thereby improving the classification accuracy and efficiency of multi-page scanned documents.
[0015] The scanned document classification method provided in this embodiment can be executed by a scanned document classification device. This device can be implemented through software and / or hardware, and can consist of two or more physical entities, or a single physical entity. For example, the scanned document classification device can be a terminal device with a scanned document processor installed, such as a computer, tablet, or mobile phone. The scanned document processor is an application or browser with functions such as scanned document recognition and classification. This application can be standalone document classification software or integrated into document processing software, smart office devices, and cloud-based document service platforms. The document categories supported by the scanned document classification device include, but are not limited to, corporate archives, government documents, and educational documents.
[0016] The document scanning and classification device is equipped with at least one operating system, including but not limited to Android, Linux, and Windows. The device can install at least one application based on the operating system; this application can be a built-in application of the operating system or an application downloaded from a third-party device or server. In this embodiment, the document scanning and classification device has at least one application capable of executing the document scanning and classification method.
[0017] For ease of understanding, this embodiment uses a document scanning processor as the main body for executing the document scanning classification method.
[0018] Figure 1 A flowchart of a document classification method provided in an embodiment of this application is given. (Reference) Figure 1 The specific methods for classifying scanned documents include: S110. Visual features are extracted from each page image of the scanned document to be classified to obtain the corresponding single-page visual features; the scanned document to be classified includes multiple page images arranged in page order.
[0019] The scanned document to be classified is a multi-page digital document in which the pages exist as images, including multiple page images arranged in page order. For example, the scanned document to be classified can be a multi-page PDF (Portable Document Format) scanned document, in which multiple page images are arranged in page number order.
[0020] Single-page visual features are the visual features corresponding to a single page image, used to characterize the layout structure information of that page. This embodiment extracts visual features to convert each page image into single-page visual features that characterize its layout structure, providing a foundation for subsequent time-series coding based on page order.
[0021] For example, the document scanning processor preprocesses each page image to adjust it to a preset resolution before converting it into a three-channel image (red, green, blue). For instance, if the preset resolution is 640×640, the shape of the preprocessed page image is [3, 640, 640]. The preprocessed page image is then input into a pre-trained feature extraction network, which extracts visual features from the page image to obtain a corresponding page feature map. This page feature map is then directly used as the visual feature of the corresponding single page. The feature extraction network can be a convolutional neural network (CNN) or an attention-based network (Transformer), among other neural networks. For example, the page image is input into the feature extraction network, and after multiple convolutional and pooling operations, a page feature map with shape [C, H, W] is obtained. This page feature map is then used as the visual feature of the single page, where C is the number of channels, and H and W are the spatial height and width of the page feature map.
[0022] However, the page feature maps output by the feature extraction network are two-dimensional features, which have a high spatial dimensionality. When subsequent temporal encoding is performed based on the page order, the single-page visual features of each page are used as input data for the temporal encoder. The high spatial dimensionality of two-dimensional features makes the input dimension of the temporal encoder large, resulting in high computational cost. This makes the subsequent temporal encoding process more complex and affects the efficiency of document classification.
[0023] Optionally, to reduce the computational overhead of subsequent temporal encoders, the two-dimensional page feature map obtained through feature extraction can be further compressed into one-dimensional single-page visual features through one-dimensional compression processing. This simplifies the temporal coding process, reduces computational overhead, and avoids the problem of complex subsequent temporal coding caused by directly using two-dimensional features as single-page visual features. Specifically, Figure 2 This is a flowchart illustrating the generation of single-page visual features provided in an embodiment of this application. For example... Figure 2 As shown, the steps for generating single-page visual features specifically include S1101-S1102: S1101. Perform convolution processing on the page image to obtain the corresponding page feature map.
[0024] For example, heavy convolutional networks such as Visual Geometry Group (VGG) or ResNet are used as feature extraction networks to perform convolution and pooling operations on the page image to obtain the page feature map of the corresponding page image.
[0025] Optionally, to further improve document classification efficiency, lightweight backbone networks such as MobileNetV2 and MobileNetV3 can be used to replace heavy convolutional networks to extract page feature maps from page images, reducing computational cost. For example, the preprocessed page image [3, 640, 640] can be input into MobileNetV2, and MobileNetV2 can perform multiple convolutions on [3, 640, 640]. The spatial resolution of the output feature map is 1 / 32 of the input size (i.e., 20×20), and the number of channels is increased to 1280. The final output page feature map has the shape [1280, 20, 20].
[0026] Furthermore, the page feature map can be dimensionality reduced using convolutional layers (e.g., 1×1 convolutional layers) to decrease the number of channels, thereby reducing subsequent computation. For example, if the page feature map output by the backbone network has a shape of [1280, 20, 20], a convolutional layer can compress the number of channels from 1280 to 512, resulting in a page feature map with a shape of [512, 20, 20].
[0027] S1102. Perform one-dimensional compression on the page feature map to obtain the corresponding single-page visual features.
[0028] For example, global pooling can be used to perform one-dimensional compression on the page feature map output by the feature extraction network or convolutional layer, compressing each channel of the page feature map to one dimension in both the vertical and horizontal directions. For instance, if the shape of the page feature map is [1280, 20, 20], one-dimensional compression will yield a feature with a shape of [512, 1, 1]. This feature is then flattened in terms of spatial dimensions to obtain a 512-dimensional column vector as the single-page visual feature.
[0029] In this embodiment, the page image is convolved to obtain a page feature map, and then the page feature map is compressed in one dimension to obtain single-page visual features. This effectively reduces the dimensionality of the input features for subsequent temporal coding, reduces the computational overhead of temporal coding, and improves classification efficiency.
[0030] It should be noted that while global pooling can compress the entire page feature map into a single vector, effectively reducing the dimensionality of single-page visual features and simplifying subsequent calculations, it cannot distinguish the layout information of the page in the vertical direction (such as headers, body text, and footers). This results in the single-page visual features not representing the layout structure with sufficient precision.
[0031] Optionally, to preserve the layout information in the vertical direction of the page, this embodiment does not compress the entire page feature map into a single vector. Instead, it first divides the page feature map into multiple image blocks in the vertical direction, so that each image block corresponds to a layout segment of the page in the vertical direction. Then, pooling is used to compress each image block to one dimension, preserving the layout information in the vertical direction while compressing horizontal redundancy. Finally, spatial flattening is performed on each compressed image block to convert the single-page visual features into a one-dimensional sequence. This allows the single-page visual features to accurately represent the document's layout structure while reducing the dimensionality of the input data for subsequent temporal coding.
[0032] Specifically, the process of generating single-page visual features includes: dividing the page feature map into multiple image blocks along the vertical direction; compressing the horizontal dimension of each image block to one dimension through pooling operations; and flattening the compressed image blocks of the page feature map in terms of spatial dimension to obtain the corresponding single-page visual features. For example, the vertical layout structure of the page feature map, from top to bottom, consists of a header, body text, and footer. The header and footer each occupy a small portion of the page layout, while the body text occupies the majority. Based on layout occupancy, the page feature map can be divided into three image blocks along the vertical direction, corresponding to the header, body text, and footer respectively from top to bottom. The height of the image blocks corresponding to the header and footer is the same but smaller than the height of the image block corresponding to the body text. For example, the height of the image blocks corresponding to the header and footer is one-quarter of the height of the page feature map, and the height of the image block corresponding to the body text is half the height of the page feature map. That is, when the shape of the page feature map is [512, 20, 20], the page feature map is divided into three image blocks from top to bottom, and the shapes of the three image blocks are [512, 5, 20], [512, 10, 20] and [512, 5, 20] respectively.
[0033] Since subsequent image patches will be compressed into a single vector through pooling, the layout structure of the main text will lose detailed features due to compression. Therefore, the main text region in the page feature map can be divided into at least two image patches to preserve detailed features. For example, Figure 3 This is a schematic diagram illustrating the process by which a page feature map, provided in an embodiment of this application, evolves into single-page visual features. For example... Figure 3 As shown, the page feature map with shape [512, 20, 20] is divided vertically into four uniform image blocks (corresponding to the header area, upper text area, lower text area, and footer area from top to bottom), with each image block having a shape of [512, 5, 20]. Then, a pooling operation is used to compress each channel image of each image block one-dimensionally, reducing each channel image from 5×20 to 1×1. The feature of each image block, compressed from [512, 5, 20] to [512, 1, 1], compresses redundant features in the horizontal direction, retaining only the aggregated information in the vertical direction, thus avoiding noise interference from excessive redundant features. After the pooling operation compresses the four image blocks, the final output feature shape is [512, 4, 1]. Subsequently, the output features of the pooling operation are flattened in terms of spatial dimensions to concatenate the 1×1 features of each image block under 512 channels to obtain a 512-dimensional column vector. Then, the 512-dimensional column vectors corresponding to the four image blocks are concatenated to finally obtain a 2048-dimensional column vector, which is used as the visual feature of a single page.
[0034] This embodiment reduces the page feature map from two-dimensional features to one-dimensional features through vertical partitioning, pooling compression, and flattening. This ensures that the single-page visual features obtained after dimensionality reduction still retain the layout information of the page in the vertical direction, thereby improving the ability of single-page visual features to represent the layout structure and balancing document classification efficiency and accuracy.
[0035] S120. Based on the page order, perform temporal encoding on multiple single-page visual features corresponding to multiple page images to obtain multi-page sequence features.
[0036] In this context, page order refers to the actual arrangement order of multiple page images in the scanned document to be classified. Since there is a progressive relationship in the layout structure between multiple pages of a scanned document—for example, the cover, table of contents, main text, and references of a thesis document are arranged in sequence—this embodiment uses temporal encoding of the single-page visual features of multiple page images based on page order. This allows the multi-page sequence features to express the layout association information between pages, providing a basis for subsequent document classification.
[0037] For example, a scanned document processor can employ a Transformer encoder to temporally encode multiple single-page visual features. Specifically, multiple single-page visual features are organized into a sequence according to page order and input into the Transformer encoder. The Transformer encoder uses a self-attention mechanism to calculate the dependencies between the individual single-page visual features, and then extracts the multi-page sequence features layer by layer through multi-head attention layers and a feedforward network.
[0038] However, the self-attention mechanism in the Transformer encoder calculates attention weights equally for all pages, lacking explicit constraints on page order. This makes it difficult to effectively model the layout progression relationship between pages, resulting in limited ability of multi-page sequence features to represent the layout progression relationship between pages, which in turn affects the accuracy of subsequent document classification.
[0039] In another embodiment, considering the insufficient modeling capability of the Transformer encoder for temporal progression relationships, a temporal encoder can be used to temporally encode a temporal sequence obtained by organizing multiple single-page visual features in page order. The temporal encoder transmits state information between time steps and extracts latent states step by step, thereby modeling the layout progression relationships between pages, enabling multi-page sequence features to more fully express the layout association features between pages. Specifically, Figure 4 This is a flowchart illustrating the determination of multi-page timing characteristics provided in an embodiment of this application. For example... Figure 4 As shown, the steps for determining the timing characteristics of multiple pages specifically include S1201-S1203: S1201. Based on the page order, organize the visual features of multiple single pages corresponding to multiple page images into a temporal sequence.
[0040] For example, multiple single-page visual features are arranged sequentially according to the page order of the scanned document to be classified, forming a temporal sequence. For instance, if the number of pages in the scanned document to be classified is T, and the single-page visual features are 2048-dimensional column vectors, the column vectors of the T single-page visual features are sorted sequentially according to the page order to form a temporal sequence of shape [T, 2048], where the temporal sequence is {p1, p2, ..., p...}. i ,...,p T}, p i Let be the single-page visual feature of the i-th page in the document.
[0041] S1202. Input the time series sequence into the pre-trained time encoder and extract the hidden states of multiple time steps of the time series sequence through the time encoder.
[0042] For example, a time-series encoder can employ a unidirectional Long Short-Term Memory (LSTM) network. The time-series sequence is input into the LSTM network in forward order. At each time step, the network calculates the hidden state of the current time step based on the input features of that time step and the hidden state of the previous time step, thereby extracting the hidden states of multiple time steps of the time-series sequence one by one. The hidden state of each time step carries the context information of that time step and the pages preceding it. For example, the time-series sequence is {p1, p2, ..., p...}. i ,...,p T After inputting into the unidirectional long short-term memory network, the network first uses p1 as the hidden state h1 for the first time step, then uses p2 as the input feature for the second time step, and calculates the hidden state h2 for the second time step using p2 and h1. This process continues until the hidden state h2 for the last time step is calculated. T .
[0043] When a one-way long short-term memory network encodes a temporal sequence, the hidden state of each time step can only obtain the contextual information of the pages before that time step. However, it is possible that the scanning order of some documents has been reversed. For example, the normal order of a thesis document is cover, table of contents, main text, and references, but due to scanning errors, it becomes references, main text, table of contents, and cover. In this case, the hidden state of the time step extracted by the one-way long short-term memory network cannot correctly represent the layout progression relationship between pages.
[0044] In another embodiment, to overcome the limitation that unidirectional long short-term memory networks can only utilize forward context, this embodiment simultaneously employs two independent encoding branches: a forward long short-term memory network and a backward long short-term memory network. The forward branch extracts the forward hidden state of each time step in the forward order of the time sequence, while the backward branch extracts the backward hidden state of each time step in the reverse order of the time sequence. The forward and backward hidden states of the same time step are then merged, so that the hidden state of each time step simultaneously contains the context information of the pages before and after that time step, thereby enabling a more complete modeling of the relationships between pages in a multi-page document.
[0045] Specifically, the temporal encoder includes a forward long short-term memory (LSTM) network and a backward long short-term memory (LSTM) network. The forward LSTM network extracts the first hidden states of multiple time steps sequentially based on the forward order of the temporal sequence. The backward LSTM network extracts the second hidden states of multiple time steps sequentially based on the reverse order of the temporal sequence. The hidden states of corresponding time steps are determined based on the first and second hidden states of the same time step, resulting in the hidden states of multiple time steps of the temporal sequence. Here, the first hidden state is calculated by combining the input features of the current time step with the hidden state of the previous time step; the second hidden state is calculated by combining the input features of the current time step with the hidden state of the next time step. Here, "next" and "before" refer to the "before" and "after" constraints imposed by the forward order of the temporal sequence.
[0046] For example, the time series {p1,p2,...,p} i ,...,p T Input a forward Long Short-Term Memory (LSTM) network and a backward Long Short-Term Memory (LSTM) network. The forward LSTM network uses p1 as the first hidden state at the first time step. Then p2 is used as the input feature for the second time step, and through p2 and Calculate the first hidden state at the second time step This process continues until the first hidden state of the last time step is calculated. The first hidden state at each time step carries context information about that time step and the pages preceding it. The reversed long short-term memory network starts processing from the last time step, and... T The second hidden state as the last time step Then p T-1 As the input feature of the penultimate time step, through p T-1 and Calculate the second hidden state at the penultimate time step. This process continues until the second hidden state of the first time step is calculated. The second hidden state at each time step carries context information about the corresponding time step and subsequent pages. Then, the first and second hidden states at the same time step are concatenated to obtain the hidden state of that time step, such as the first hidden state of the i-th time step. and the second hidden state at the i-th time step The hidden state h at time i is obtained by concatenation. i At this point, the hidden state of each time step contains the page context information before and after that time step. Regardless of whether the document's pages are in ascending or descending order, the hidden states of each time step correctly express the layout progression relationship between pages, which helps improve the accuracy of subsequent document classification.
[0047] This embodiment uses bidirectional encoding of temporal sequences via forward and backward long short-term memory networks, so that the hidden state at each time step simultaneously contains both forward and backward contexts. This provides a more comprehensive model of inter-page relationships in the document, improves the ability of multi-page sequence features to represent the layout progression relationship between pages, and thus enhances the document classification accuracy.
[0048] S1203. Determine the multi-page sequence features based on the hidden states of multiple time steps.
[0049] For example, the time series {p1,p2,...,p} i ,...,p T After inputting into the timing encoder, the timing encoder outputs multiple hidden states for time steps, namely {h1, h2, ..., h...}. i ,...,h T}, which can be {h1,h2,...,h i ,...,h T The characteristics of the multi-page sequence are determined, thus providing features that include page layout structure information and inter-page layout relationship information for subsequent classification processing.
[0050] This embodiment organizes multiple single-page visual features into a temporal sequence based on page order, and models the layout progression relationship between pages through the hidden states of multiple time steps, capturing the layout association features between pages of a multi-page document. This enables the classification process to combine the layout association features between pages and the page layout structure features for classification, ensuring the accuracy of document classification.
[0051] S130. Determine the document category of the scanned document to be classified based on the multi-page sequence features.
[0052] The document category refers to the category to which the scanned document belongs. For example, document categories may include resumes, contracts, books, exam papers, financial reports, academic papers, government documents, tender documents, and others. This embodiment determines the document category based on multi-page sequence features, enabling automatic classification of scanned documents.
[0053] For example, multi-page sequence features can be input into a pre-trained classification model, which then integrates and processes these features and directly outputs the document category. Internally, the classification model can perform adaptive pooling on the multi-page sequence features before outputting the document category through a fully connected layer.
[0054] Optionally, the length of the multi-page sequence features is the same as the number of pages in the document. However, different documents have different page counts. To unify the feature lengths of different documents and reduce the computational complexity of the classification model, multi-page sequence features of different lengths can be aggregated into a feature vector of uniform length before classification. This uniform-length feature vector is then input into a pre-trained classifier to determine the document category. This decouples feature aggregation and the classifier, reducing computational overhead. Specifically, Figure 5 This is a flowchart illustrating the process of determining the document category of a scanned document to be classified, as provided in an embodiment of this application. For example... Figure 5 As shown, the step of determining the document category of the document to be scanned specifically includes S1301-S1302: S1301. Aggregate the features of the multi-page sequence to obtain the document embedding vector of the preset scale.
[0055] For example, multi-page sequence features can be averaged along the page dimension to aggregate them into an average feature vector, which is then used as the document embedding vector. For instance, a single-page visual feature is a 2048-dimensional column vector. After temporal encoding, the resulting multi-page sequence features have a shape of [T, 2048], where T is the number of pages. The multi-page sequence features are equivalent to a T×2048 feature matrix. Averaged pooling along the page dimension is equivalent to averaging the feature values in the same row of the feature matrix and using this average as the feature value for the corresponding row in the average feature vector. The resulting average feature vector is a 2048-dimensional column vector. The 2048 dimension is the preset scale; regardless of the number of pages in the document, average pooling will convert it into a 2048-dimensional column vector. Of course, the 2048 dimension is just an example; the preset scale can be adjusted according to actual needs.
[0056] It should be noted that when average pooling aggregates features from multiple pages, it averages the feature values of all pages. While it retains the overall information, it loses the key page features that contain the most information in the document, resulting in the document embedding vector not adequately representing the key features of the page.
[0057] Optionally, to ensure that the document embedding vector retains both overall page information and highlights key page features, this embodiment employs both max pooling and average pooling, two complementary aggregation methods. Max pooling preserves key page features, while average pooling preserves global page features, thus improving the feature accuracy of the document embedding vector. Specifically, max pooling is performed on multi-page sequence features along the page dimension to obtain key page features; average pooling is performed on multi-page sequence features along the page dimension to obtain global page features; and the key page features and global page features are concatenated to obtain a document embedding vector of a preset scale.
[0058] For example, given a multi-page sequence feature matrix of T×2048, when performing max pooling on the multi-page sequence features along the page dimension, the largest eigenvalue in the same row of the feature matrix is taken as the eigenvalue of the corresponding row in the page key features. The resulting page key features are a 2048-dimensional column vector, preserving the key information of each page. When performing average pooling on the multi-page sequence features along the page dimension, the average value of the eigenvalues in the same row of the feature matrix is taken as the eigenvalue of the corresponding row in the page global features. The resulting page global features are also a 2048-dimensional column vector, preserving the overall information of each page. Concatenating the page global features and the page key features yields a 4096-dimensional column vector. This column vector is used as the document embedding vector, ensuring that the document embedding vector highlights key page features while retaining global information.
[0059] This embodiment extracts key features from a page using max pooling and global features from a page using average pooling. The two are then concatenated to form a document embedding vector. This document embedding vector highlights the features of the page with the most information in the document while retaining the overall information of all pages, resulting in a more comprehensive feature representation of multi-page documents and thus improving classification accuracy.
[0060] S1302. Input the document embedding vector into a pre-trained classifier, and use the classifier to determine the document category of the scanned document to be classified.
[0061] For example, the classifier can be a classification network containing a single-layer fully connected network. After the document embedding vector is input into the classifier, the single-layer fully connected network directly maps the document embedding vector to the document category dimension, outputting the predicted probabilities of multiple document categories. The document category with the highest predicted probability is taken as the classification result. For example, if the preset document categories include resumes, contracts, books, exam papers, financial reports, papers, government documents, tender documents, and others (nine categories in total), then the single-layer fully connected network outputs a column vector with nine dimensions, where each dimension corresponds to a document category, and the feature values in the column vector are the predicted probabilities of the corresponding document category. If the second row of the column vector output by the single-layer fully connected network has the largest feature value, and the second row corresponds to the contract category, then the document to be classified is determined to be a contract document.
[0062] In addition, the classifier can be configured to include a first fully connected network and a second fully connected network. The first fully connected network performs dimensionality transformation on the document embedding vector to obtain intermediate features. These intermediate features are then input into the second fully connected network, which maps them to the document category dimension, yielding the predicted probability of the scanned document belonging to each category. The category with the highest predicted probability is then determined as the document category of the scanned document. For example, the document embedding vector is input into the first fully connected network, which performs a linear transformation to obtain dimensionality-reduced features. Then, an activation function (such as ReLU) is used to non-linearly activate these features, yielding intermediate features. These intermediate features are then input into the second fully connected network, which again performs dimensionality reduction and non-linear activation, mapping the activated features to the document category space of each dimension to obtain the original scores for each document category. Finally, a normalization function is used to convert the original scores into a probability distribution, yielding the predicted probability of each document category. The category with the highest predicted probability is then selected as the document category of the scanned document. This embodiment uses two fully connected networks to perform two dimensionality reduction mappings and nonlinear activations on the document embedding vectors to improve the accuracy of document classification.
[0063] Based on the above embodiments, an end-to-end document classification model can be constructed by combining a feature extraction network, a vertical spatial pooling module, a temporal modeling module, a temporal encoder, a feature aggregation module, and a classifier. For example, Figure 6 This is a schematic diagram of the document classification network provided in an embodiment of this application. For example... Figure 6 As shown, the input of the feature extraction network serves as the input of the document classification model, which can extract page features from page images 1,..., i,..., T of the scanned document to be classified. Figure 1Page feature maps i, ..., T are generated. The output of the feature extraction network is connected to the input of the vertical spatial pooling module. After multiple page feature maps output by the feature extraction network are passed to the vertical spatial pooling module, the vertical spatial pooling module divides the page feature maps into multiple image blocks along the vertical direction and performs pooling and spatial flattening operations on the multiple image blocks to output single-page visual features 1, ..., single-page visual features i, ..., single-page visual features T. The output of the vertical spatial pooling module is connected to the input of the temporal modeling module. After the vertical spatial pooling module inputs multiple single-page visual features into the temporal modeling module, the temporal modeling module organizes the multiple single-page visual features into a temporal sequence according to the page order. The output of the temporal modeling module is connected to the input of the temporal encoder. After the temporal modeling module transmits the temporal sequence to the temporal encoder, the temporal encoder extracts the hidden states of multiple time steps of the temporal sequence as multi-page sequence features. The output of the temporal encoder is connected to the feature aggregation module. After the temporal encoder passes the multi-page sequence features to the feature aggregation module, the feature aggregation module performs max pooling and global pooling on the multi-page sequence features and then concatenates them into a text embedding vector. The output of the feature aggregation module is connected to the input of the classifier. After the feature aggregation module passes the text embedding vector to the classifier, the classifier outputs the document category of the scanned document to be classified based on the text embedding vector.
[0064] In practical applications, users can store multiple scanned documents in a folder. The user inputs the folder's file path to the document scanner, which automatically loads the documents from the folder based on that path. Then, it calls a pre-deployed document classification model to classify each document individually, obtaining its document category. Finally, it creates a corresponding category folder for each category and stores the scanned documents in that folder, achieving automatic archiving management of multiple scanned documents. Alternatively, the document scanner can display a file addition window, allowing the user to drag and drop a scanned document into it. The scanner then uses the pre-deployed document classification model to classify the document, obtaining its document category, and displays the category as a list associated with the scanned document on the interface. Alternatively, the document scanning processor may have a document management space that includes at least one scanned document. Users can select one or more scanned documents and trigger a classification operation. The document scanning processor then calls a pre-deployed document classification model to classify the selected scanned document and obtain its document category. The document category and the name of the scanned document are displayed in a list format in the sidebar window of the document management space.
[0065] It should be noted that the classification ability of a document classification model depends on the prior model training phase. Therefore, the document classification model can be trained before it is formally applied to document classification in real-world scenarios. Figure 7 This is a flowchart of the training document classification model provided in an embodiment of this application. For example... Figure 7 As shown, the specific steps for training the document classification model include S210-S220: S210. Construct a training sample set, which includes multiple sample documents and their corresponding document categories.
[0066] For example, scanned copies of various document types are collected as sample documents, and each sample document is labeled with its corresponding document category. Multiple sample documents and their corresponding document categories form a training dataset. The scanned copies can be editable electronic documents directly converted into scanned documents by software, such as converting a Word document to a PDF document; or they can be scanned documents obtained by scanning paper documents using a scanner. For instance, to train a document classification model to classify resumes, contracts, books, exam papers, financial reports, academic papers, government documents, tender documents, and other documents (nine categories in total), electronic documents of these categories can be collected, converted into scanned documents using software, and labeled with their corresponding categories to construct a training sample set. The entire construction process eliminates the need for manual scanning of paper documents, saving significant manpower and time.
[0067] However, while the method of collecting scanned documents converted from electronic documents can quickly build a training sample set, the distribution of the training samples differs from the real scanning scenarios with issues such as image blurring, image skew, missing pages, and duplicate pages. This results in insufficient generalization ability of the model to real scanned documents, affecting the model's classification accuracy in practical application scenarios.
[0068] Optionally, to reduce the distributional differences between training samples and real scanning scenarios, this embodiment first converts electronic documents into scanned documents, then performs image quality degradation processing and / or page addition / deletion processing on the scanned documents. This simulates abnormal situations such as image quality degradation, missing pages, or duplication that may occur during real scanning, thereby expanding the diversity of training samples. This allows the model to learn various differences in real scanned documents during the training phase, improving the model's generalization ability to real scanned documents. Specifically, Figure 8 This is a flowchart illustrating the construction of a training sample set provided in an embodiment of this application. For example... Figure 8 As shown, the steps for constructing the training sample set specifically include S2101-S2103: S2101. Convert multiple electronic documents into multiple scanned documents respectively.
[0069] For example, various categories of electronic documents are collected, and conversion software is used to convert the electronic documents into scanned documents.
[0070] S2102. Perform data preprocessing on at least one scanned document to obtain a sample document; wherein, the data preprocessing includes quality degradation processing of page images and / or page addition / deletion processing of the scanned document.
[0071] Data preprocessing refers to the processing of scanned documents to simulate various imaging differences and page anomalies in real-world scanning scenarios. For example, quality degradation processing in data preprocessing can convert page images of a scanned document into blurry and / or skewed images to simulate low-quality page images caused by human error or machine malfunctions in real-world scanning scenarios. Page addition / deletion processing in data preprocessing can repeatedly add or delete partial page images from a scanned document to simulate repeated or missed scans caused by human error or machine malfunctions in real-world scanning scenarios.
[0072] For example, page images in a scanned document can be randomly degraded in quality, and / or page images in the scanned document can be randomly added or deleted to simulate various imaging differences and page anomalies in a real scanning scenario, thereby obtaining a sample document.
[0073] In one embodiment, the quality degradation processing of the page image includes at least one of color dithering, grayscale processing, and Gaussian blurring. For example, color dithering randomly adjusts the color attributes of the page image, such as brightness, contrast, saturation, and hue, with a preset probability. For instance, brightness, contrast, saturation (adjustment increment can be set to 0.3), and hue (adjustment increment can be set to 0.1) are randomly adjusted with a 60% probability to adapt to lighting differences between different scanners. Grayscale processing converts the page image to a grayscale image with a preset probability. For instance, a color image is converted to a grayscale image with a 20% probability, forcing the model to adapt to black and white scanned or copied documents. Gaussian blurring applies Gaussian blur to the page image with a preset probability. For instance, a Gaussian blur is applied to the image with a 30% probability, and the Gaussian kernel value can be set to a range of 0.1 to 2.0 to simulate out-of-focus, low-resolution, or blurry old documents. This embodiment performs quality degradation operations on the page image through color dithering, grayscale processing, and Gaussian blurring to simulate the imaging differences of different scanners in the sample document, thereby improving the model's generalization ability.
[0074] In addition to the above-mentioned processing, quality degradation processing can also include image skew processing. For example, the page image in the scanned document can be randomly rotated clockwise or counterclockwise by a preset angle (e.g., set to 0~20 degrees) to simulate the page image skew caused by the paper document being placed at an angle in the scanner.
[0075] In one embodiment, the page addition and deletion processing of a scanned document may involve: retaining the first and last page images of the scanned document, and randomly sampling multiple page images from the intermediate page sequence. For example, the first page of a document typically contains key information such as the title, and the last page typically contains key information such as stamps and signatures. Therefore, the document prioritizes retaining the first and last page images to avoid losing key features. Multiple page images are randomly sampled from the intermediate pages of the document, and the first and last page images, along with the sampled page images, are sorted according to page order to obtain a sample document.
[0076] Alternatively, the page addition / deletion processing in a scanned document can also involve randomly deleting and / or adding page images from the middle of the scanned document. For example, a page image from the middle of the scanned document can be randomly discarded with a preset probability (which can be set to 20%) to simulate missing or missed pages. Another example is that a page image can be randomly copied with a preset probability (which can be set to 10%) and inserted before or after that page image in the scanned document to simulate repeated paper feeding during scanning.
[0077] Alternatively, the page addition and deletion processing of a scanned document can also involve padding the number of pages in the scanned document based on a preset vector. For example, when the scanned document is a short document with fewer than the preset number of pages, a preset zero vector can be used to fill the scanned document to a fixed length to adapt to the subsequent fixed-length inference process.
[0078] This embodiment simulates real-world scanning scenarios such as missing documents, repeated paper feeding, and insufficient page count by adding or deleting pages from the scanned document. This allows the model to adapt to scanned documents with different page counts and levels of completeness, thereby improving the model's generalization ability.
[0079] It should be noted that not all scanned documents will exhibit imaging anomalies or page count errors during the scanning process; in fact, in most cases, the scanned documents will have normal page images and page counts. To address this, a subset of scanned documents can be randomly subjected to quality degradation processing and / or page addition / deletion processing to obtain corresponding sample documents. The remaining scanned documents that have not undergone quality degradation processing and / or page addition / deletion processing can be directly used as sample documents. These unprocessed documents represent normal scanning conditions, thus ensuring the model's ability to distinguish between normal and abnormal scanned documents.
[0080] S2103. Construct a training sample set based on multiple sample documents and the document categories of the corresponding electronic documents.
[0081] For example, after converting scanned documents into sample documents, multiple sample documents are associated with the document categories of the corresponding electronic documents and stored in the training sample set to provide a data foundation for subsequent model training.
[0082] This embodiment converts electronic documents into scanned documents and then uses quality degradation processing and page addition / deletion processing to simulate real scanning scenarios, reducing the distribution difference between training samples and real scanning scenarios, thereby improving the robustness and generalization ability of the model.
[0083] S220. Train a pre-built document classification model using a training sample set.
[0084] The document classification model includes a feature extraction network, a temporal encoder, and a classifier. The feature extraction network extracts multiple single-page visual features from the sample document. The temporal encoder performs temporal encoding on these single-page visual features to output a multi-page feature sequence. The classifier outputs the predicted probability of the sample document belonging to each document category based on the multi-page feature sequence. It's important to note that the model parameters for the feature extraction network, temporal encoder, and classifier are those that need to be updated during the training phase. This does not mean that the document classification model only includes these three modules; for example, it may also include... Figure 6 The module includes a vertical spatial pooling module, a temporal modeling module, and a feature aggregation module.
[0085] For example, multiple sample documents can be randomly selected from the training sample set as samples for the current training batch. The document classification model is then trained using these samples in a single batch. After the document classification model has undergone multiple batches of training and reaches the training termination condition, the trained document classification model is obtained. Specifically, Figure 9 This is a flowchart of single-batch training of the model provided in the embodiments of this application. For example... Figure 9 As shown, the specific steps of single-batch training of this model include S2201-S2204: S2201. Extract sample documents from the training sample set for the current training batch, input the sample documents from the current training batch into the document classification model, and obtain the predicted probability of the sample documents belonging to each document category output by the document classification model.
[0086] For example, N sample documents are randomly selected from the training sample set as samples for the current training batch. The N sample documents of the current training batch are input into the document classification model one by one. The feature extraction network extracts multiple single-page visual features of the sample documents. The temporal encoder performs temporal encoding on the multiple single-page visual features to obtain a multi-page feature sequence. The classifier outputs the predicted probability of the sample document belonging to each document category based on the multi-page feature sequence, and obtains the prediction results of the N sample documents in the current training batch.
[0087] S2202. Based on the document category of the sample documents in the current training batch and the predicted probability of the sample documents belonging to each document category, determine the cross-entropy loss value of the current training batch.
[0088] For example, the category label and corresponding predicted probability of a sample document in the current training batch are substituted into a preset cross-entropy loss function to calculate the cross-entropy loss value of that sample document. Subsequently, the cumulative or average value of the cross-entropy loss values of N sample documents in the current training batch is used as the cross-entropy loss value of the current training batch.
[0089] Optionally, since the learning difficulty of samples of different categories varies, different sample weights can be set for samples of different categories, allocating higher weights to difficult samples with greater learning difficulty. This introduces sample weights into the calculation of the cross-entropy loss value of the current training batch, guiding the model to focus more on difficult samples with greater learning difficulty, thereby improving the model's training performance. Specifically, the cross-entropy loss value of each sample document in the current training batch can be determined based on the document category and the predicted probability of belonging to each document category; the sample weight of each sample document can be obtained based on the document category of each sample document in the current training batch; and the cross-entropy loss values of each sample document can be weighted and summed according to the sample weights of each sample document to determine the cross-entropy loss value of the current training batch.
[0090] For example, a first weight value (e.g., 1) is set for easy samples (such as resumes or papers), and a second weight value (e.g., 2) is set for difficult samples (such as contracts or tender documents). The first sample weight is less than the second sample weight. When the document category of a sample document belongs to the easy sample category, the sample weight of that sample document is determined to be the first weight value; when the document category of a sample document belongs to the difficult sample category, the sample weight of that sample document is determined to be the second weight value. The document category of the sample document and its predicted probability of belonging to each document category are substituted into the calculation formula of the cross-entropy loss function to calculate the cross-entropy loss value of that sample document. The sample weights of the N sample documents in the current training batch are multiplied by the corresponding cross-entropy loss values, and then summed. The sum is divided by N to obtain the cross-entropy loss value of the current training batch. That is, the expression for the cross-entropy loss value of the current training batch is:
[0091] in, This represents the sample weight of the i-th sample document in the current training batch. Let be the cross-entropy loss value of the i-th sample document. Let be the predicted probability that the i-th sample document belongs to the true document category. For example, if the document category of the i-th sample document is "contract," and the document classification model outputs a predicted probability of 0.79 for the i-th sample document belonging to the "contract" category, then... =0.79.
[0092] This embodiment sets different sample weights for different categories of samples to introduce sample weights into the calculation of cross-entropy loss value of the current training batch, so that the model pays more attention to difficult samples during training and improves the overall classification accuracy of the model.
[0093] S2203. Optimize the network parameters of the feature extraction network, temporal encoder, and classifier based on the cross-entropy loss value.
[0094] For example, based on the cross-entropy loss value of the current training batch, the network parameters of the feature extraction network, temporal encoder, and classifier are updated via backpropagation. Hyperparameters such as the number of iterations and learning rate can be preset, and the network parameters are updated using a gradient descent optimization algorithm.
[0095] S2204. If the document classification model meets the preset training termination conditions, the trained document classification model is obtained.
[0096] The training termination condition refers to the conditions that the document classification model must meet to end training. This can include at least one of the following: convergence of the cross-entropy loss value, the model's classification accuracy reaching a preset threshold, or the number of training batches reaching a preset number. If the document classification model does not meet the preset training termination condition, sample documents for the next training batch can be obtained from the training sample set. The corresponding cross-entropy loss value is determined based on the sample documents of the latest training batch, and the model is optimized again based on the cross-entropy loss value, thus achieving multi-batch cyclical training of the model. When the document classification model meets the preset training termination condition, training stops, resulting in a fully trained document classification model. The fully trained document classification model has the ability to accurately classify various types of scanned documents and can be deployed for the classification and management of scanned documents.
[0097] In this embodiment, sample documents are obtained in batches from the training sample set for batch training of the model. When the training termination condition is met, the trained document classification model is obtained, which enables the model to learn the mapping relationship from page images to document categories, thus ensuring the document classification accuracy of the model.
[0098] In summary, the document classification method provided in this application extracts visual features from each page image of the scanned document to be classified, obtaining corresponding single-page visual features. The scanned document to be classified includes multiple page images arranged in page order. Based on the page order, multiple single-page visual features corresponding to multiple page images are temporally encoded to obtain multi-page sequence features. The document category of the scanned document to be classified is determined based on the multi-page sequence features. Through the above technical means, visual features are directly extracted from each page image to obtain the page layout structure features of the scanned document. By temporally encoding the inter-page layout association features of the multi-page document, the key features of low-quality scanned documents can be effectively preserved. Thus, the document category can be accurately identified based on the two dimensions of the page layout structure features and inter-page layout association features of the scanned document. This effectively avoids semantic understanding errors caused by misrecognition of optical characters, improves the classification accuracy of multi-page scanned documents, and eliminates the need for two-stage serial processing of optical recognition and semantic analysis, thereby improving classification efficiency.
[0099] Based on the above embodiments, this application also provides a document scanning and classification device. Figure 10 This is a schematic diagram of the structure of a document scanning and classification device provided in an embodiment of this application. (Reference) Figure 10 The document classification device provided in this embodiment specifically includes: a feature extraction module 21, a temporal encoding module 22, and a document category determination module 23.
[0100] The feature extraction module 21 is configured to extract visual features from each page image of the scanned document to be classified, thereby obtaining the corresponding single-page visual features; the scanned document to be classified includes multiple page images arranged in page order. The temporal coding module 22 is configured to perform temporal coding on multiple single-page visual features corresponding to multiple page images based on page order to obtain multi-page sequence features; The document category determination module 23 is configured to determine the document category of the scanned document to be classified based on multi-page sequence features.
[0101] Based on the above embodiments, the feature extraction module 21 includes: a convolution processing submodule, configured to perform convolution processing on the page image to obtain the corresponding page feature map; and a compression processing submodule, configured to perform one-dimensional compression processing on the page feature map to obtain the corresponding single-page visual features.
[0102] Based on the above embodiments, the compression processing submodule includes: a vertical division unit configured to divide the page feature map into multiple image blocks along the vertical direction; a horizontal compression unit configured to compress each image block to one dimension through pooling operations; and a flattening unit configured to perform spatial dimension flattening processing on the multiple compressed image blocks of the page feature map to obtain the corresponding single-page visual features.
[0103] Based on the above embodiments, the temporal coding module 22 includes: a sequence organization submodule, configured to organize multiple single-page visual features corresponding to multiple page images into a temporal sequence based on page order; a hidden state extraction submodule, configured to input the temporal sequence into a pre-trained temporal encoder and extract the hidden states of multiple time steps of the temporal sequence through the temporal encoder; and a sequence feature determination submodule, configured to determine multi-page sequence features based on the hidden states of multiple time steps.
[0104] Based on the above embodiments, the timing encoder includes a forward long short-term memory network and a reverse long short-term memory network; correspondingly, the hidden state extraction submodule includes: a forward extraction unit configured to extract the first hidden state of multiple time steps one by one in the forward order of the timing sequence through the forward long short-term memory network; a reverse extraction unit configured to extract the second hidden state of multiple time steps one by one in the reverse order of the timing sequence through the reverse long short-term memory network; and a hidden state fusion unit configured to determine the hidden state of the corresponding time step based on the first hidden state and the second hidden state of the same time step.
[0105] Based on the above embodiments, the document category determination module 23 includes: an aggregation submodule, configured to aggregate multi-page sequence features to obtain a document embedding vector of a preset scale; and a classification submodule, configured to input the document embedding vector into a pre-trained classifier to determine the document category of the scanned document to be classified.
[0106] Based on the above embodiments, the aggregation submodule includes: a max pooling unit, configured to perform max pooling on multi-page sequence features in the page dimension to obtain key page features; an average pooling unit, configured to perform average pooling on multi-page sequence features in the page dimension to obtain global page features; and a concatenation unit, configured to concatenate the key page features and the global page features to obtain a document embedding vector of a preset scale.
[0107] Based on the above embodiments, the classification submodule includes: a nonlinear transformation unit configured to perform dimensional transformation on the document embedding vector through a first fully connected network to obtain intermediate features; a category mapping unit configured to input the intermediate features into a second fully connected network and map the intermediate features to the document category dimension through the second fully connected network to obtain the predicted probability that the scanned document to be classified belongs to each document category; and a category determination unit configured to determine the document category with the highest predicted probability as the document category of the scanned document to be classified.
[0108] Based on the above embodiments, the document scanning classification device further includes: a training sample set construction module, configured to construct a training sample set before extracting visual features from each page image of the document to be classified, the training sample set including multiple sample documents and corresponding document categories; and a model training module, configured to train a pre-constructed document classification model using the training sample set.
[0109] Based on the above embodiments, the training sample set construction module includes: a document conversion submodule, configured to convert multiple electronic documents into multiple scanned documents respectively; a preprocessing submodule, configured to perform data preprocessing on at least one scanned document to obtain sample documents; wherein, the data preprocessing includes quality degradation processing of page images and / or page addition and deletion processing of scanned documents; and a sample set construction submodule, configured to construct a training sample set according to the multiple sample documents and the document categories of the corresponding electronic documents.
[0110] Based on the above embodiments, the quality degradation processing of the page image includes at least one of color dithering processing, grayscale processing, and Gaussian blur processing.
[0111] Based on the above embodiments, the page addition and deletion processing of the scanned document includes any one of the following: retaining the first page image and the last page image of the scanned document, and randomly selecting multiple page images from the intermediate page sequence; or, randomly deleting and / or adding page images in the middle of the scanned document; or, completing the number of pages in the scanned document based on a preset vector.
[0112] Based on the above embodiments, the model training module includes: a prediction submodule, configured to extract sample documents of the current training batch from the training sample set, input the sample documents of the current training batch into the document classification model, and obtain the predicted probability of the sample documents belonging to each document category output by the document classification model; a loss calculation submodule, configured to determine the cross-entropy loss value of the current training batch based on the document category of the sample documents of the current training batch and the predicted probability of the sample documents belonging to each document category; a parameter optimization submodule, configured to optimize the network parameters of the feature extraction network, the temporal encoder, and the classifier based on the cross-entropy loss value; and a training completion submodule, configured to obtain the trained document classification model when the document classification model meets the preset training termination conditions.
[0113] Based on the above embodiments, the loss calculation submodule includes: a loss value calculation unit, configured to determine the cross-entropy loss value of each sample document based on the document category of each sample document in the current training batch and the predicted probability of belonging to each document category; a weight determination unit, configured to obtain the sample weight of each sample document based on the document category of each sample document in the current training batch; and a total loss calculation unit, configured to perform a weighted summation of the cross-entropy loss values of each sample document according to the sample weight of each sample document to determine the cross-entropy loss value of the current training batch.
[0114] The document scanning classification device provided in this application embodiment can be used to execute the document scanning classification method provided in the above embodiment, and has corresponding functions and beneficial effects.
[0115] Figure 11 This is a schematic diagram of the structure of a document scanning and classification device provided in an embodiment of this application, with reference to... Figure 11 The document scanning and sorting device includes a processor 31, a memory 32, a communication device 33, an input device 34, and an output device 35. The number of processors 31 and the number of memories 32 in the document scanning and sorting device can be one or more. The processor 31, memory 32, communication device 33, input device 34, and output device 35 of the document scanning and sorting device can be connected via a bus or other means.
[0116] The memory 32, as a computer-readable storage medium, can be used to store software programs, computer-executable programs, and modules, such as program instructions / modules corresponding to the document scanning classification method in any embodiment of this application (e.g., feature extraction module 21, timing encoding module 22, and document category determination module 23 in the document scanning classification device). The memory 32 may primarily include a program storage area and a data storage area. The program storage area may store the operating system and at least one application program required for a function; the data storage area may store data created based on the use of the device, etc. Furthermore, the memory 32 may include high-speed random access memory and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other non-volatile solid-state storage device. In some instances, the memory may further include memory remotely located relative to the processor, and these remote memories can be connected to the device via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
[0117] The communication device 33 is used for data transmission.
[0118] The processor 31 executes various functional applications and data processing of the device by running software programs, instructions and modules stored in the memory 32, thereby realizing the above-mentioned scanned document classification method.
[0119] Input device 34 can be used to receive input digital or character information, and to generate key signal inputs related to user settings and function control of the device. Output device 35 may include display devices such as a display screen.
[0120] The document scanning classification device provided above can be used to execute the document scanning classification method provided in the above embodiments, and has corresponding functions and beneficial effects.
[0121] This application also provides a storage medium containing computer-executable instructions. When executed by a computer processor, the computer-executable instructions are used to perform a scanned document classification method. The scanned document classification method includes: extracting visual features from each page image of the scanned document to be classified to obtain corresponding single-page visual features; the scanned document to be classified includes multiple page images arranged in page order; performing temporal encoding on the multiple single-page visual features corresponding to the multiple page images based on the page order to obtain multi-page sequence features; and determining the document category of the scanned document to be classified based on the multi-page sequence features.
[0122] Storage medium – any type of memory device or storage device. The term “storage medium” is intended to include: mounting media, such as CD-ROM, floppy disk, or magnetic tape devices; computer system memory or random access memory, such as DRAM, DDR RAM, SRAM, EDO RAM, Rambus RAM, etc.; non-volatile memory, such as flash memory, magnetic media (e.g., hard disk or optical storage); registers or other similar types of memory elements, etc. Storage medium may also include other types of memory or combinations thereof. Furthermore, storage medium may reside in a first computer system in which the program is executed, or it may reside in a different second computer system connected to the first computer system via a network (such as the Internet). The second computer system can provide program instructions to the first computer for execution. The term “storage medium” can include two or more storage media residing in different locations (e.g., in different computer systems connected via a network). Storage medium may store program instructions (e.g., specifically implemented as a computer program) executable by one or more processors.
[0123] Of course, the computer-executable instructions provided in the embodiments of this application are not limited to the scanned document classification method described above, but can also perform related operations in the scanned document classification method provided in any embodiment of this application.
[0124] The document scanning classification device, storage medium, and document scanning classification equipment provided in the above embodiments can execute the document scanning classification method provided in any embodiment of this application. For technical details not described in detail in the above embodiments, please refer to the document scanning classification method provided in any embodiment of this application.
[0125] The above description is merely a preferred embodiment and the technical principles employed in this application. This application is not limited to the specific embodiments described herein, and various obvious changes, readjustments, and substitutions that can be made by those skilled in the art will not depart from the scope of protection of this application. Therefore, although this application has been described in detail through the above embodiments, this application is not limited to the above embodiments, and may include many other equivalent embodiments without departing from the concept of this application. The scope of this application is determined by the scope of the claims.
Claims
1. A method for classifying scanned documents, characterized in that, include: Visual features are extracted from each page image of the scanned document to be classified, resulting in the corresponding single-page visual features. The scanned document to be classified includes multiple page images arranged in page order; Based on the page order, the visual features of multiple single pages corresponding to the multiple page images are temporally encoded to obtain multi-page sequence features; The document category of the scanned document to be classified is determined based on the multi-page sequence features.
2. The scanned document classification method according to claim 1, characterized in that, The process involves extracting visual features from each page image of the scanned document to be classified, resulting in corresponding single-page visual features, including: The page image is convolved to obtain the corresponding page feature map; The page feature map is compressed in one dimension to obtain the corresponding single-page visual features.
3. The scanned document classification method according to claim 2, characterized in that, The step of performing one-dimensional compression processing on the page feature map to obtain the corresponding single-page visual features includes: The page feature map is divided into multiple image blocks along the vertical direction; Each image block is compressed to one dimension using a pooling operation; Spatial dimension flattening is performed on multiple compressed image blocks of the page feature map to obtain the corresponding single-page visual features.
4. The scanned document classification method according to claim 1, characterized in that, The step of temporally encoding multiple single-page visual features corresponding to the multiple page images based on the page order to obtain multi-page sequence features includes: Based on the page order, the visual features of multiple single pages corresponding to the multiple page images are organized into a temporal sequence; The time series sequence is input into a pre-trained time encoder, and the hidden states of multiple time steps of the time series sequence are extracted by the time encoder. Multi-page sequence features are determined based on the hidden states of the multiple time steps.
5. The scanned document classification method according to claim 4, characterized in that, The timing encoder includes a forward long short-term memory network and a reverse long short-term memory network; Accordingly, the step of extracting the hidden states of multiple time steps of the time sequence through the time encoder includes: The first hidden state of multiple time steps is extracted one by one through the forward long short-term memory network based on the forward order of the time sequence; The second hidden state of multiple time steps is extracted one by one by the reverse order of the time sequence through the reverse long short-term memory network. The hidden states of the corresponding time steps are determined based on the first and second hidden states of the same time step, thereby obtaining the hidden states of multiple time steps of the time sequence.
6. The scanned document classification method according to claim 1, characterized in that, The process of determining the document category of the scanned document to be classified based on the multi-page sequence features includes: The multi-page sequence features are aggregated to obtain a document embedding vector of a preset scale; The document embedding vector is input into a pre-trained classifier, which determines the document category of the scanned document to be classified.
7. The scanned document classification method according to claim 6, characterized in that, The aggregation process of the multi-page sequence features to obtain a document embedding vector of a preset scale includes: Max pooling is performed on the multi-page sequence features along the page dimension to obtain key page features; The multi-page sequence features are subjected to average pooling along the page dimension to obtain the global page features; The key features of the page and the global features of the page are concatenated to obtain a document embedding vector of a preset scale.
8. The scanned document classification method according to claim 6, characterized in that, The classifier includes a first fully connected network and a second fully connected network; Accordingly, determining the document category of the scanned document to be classified using the classifier includes: The document embedding vector is dimensionally transformed using the first fully connected network to obtain intermediate features; The intermediate features are input into the second fully connected network, and the intermediate features are mapped to the document category dimension through the second fully connected network to obtain the predicted probability that the scanned document to be classified belongs to each document category; The document category with the highest predicted probability is determined as the document category of the document to be classified and scanned.
9. The scanned document classification method according to claim 1, characterized in that, Before performing visual feature extraction on each page image of the scanned document to be classified, the method further includes: Construct a training sample set, which includes multiple sample documents and their corresponding document categories; The pre-built document classification model is trained using the training sample set; The document classification model includes a feature extraction network, a temporal encoder, and a classifier. The feature extraction network is used to extract multiple single-page visual features from the sample document. The temporal encoder is used to temporally encode the multiple single-page visual features of the sample document to output a multi-page feature sequence of the sample document. The classifier is used to output the predicted probability of the sample document belonging to each document category based on the multi-page feature sequence of the sample document.
10. The scanned document classification method according to claim 9, characterized in that, The construction of the training sample set includes: Convert multiple electronic documents into multiple scanned documents; At least one of the scanned documents is preprocessed to obtain a sample document; wherein, the data preprocessing includes quality degradation processing of page images and / or page addition / deletion processing of the scanned document; A training sample set is constructed based on the multiple sample documents and the document categories of the corresponding electronic documents.
11. The scanned document classification method according to claim 10, characterized in that, The quality degradation processing of the page image includes at least one of color dithering, grayscale processing, and Gaussian blurring.
12. The scanned document classification method according to claim 10, characterized in that, The page addition and deletion processing of the scanned document includes any of the following: Retain the first and last page images of the scanned document, and randomly select multiple page images from the intermediate page sequence; or, Randomly delete and / or add page images from the middle of the scanned document; or, The number of pages in the scanned document is completed based on preset vectors.
13. The scanned document classification method according to claim 9, characterized in that, The process of training a pre-built document classification model using the training sample set includes: Sample documents of the current training batch are extracted from the training sample set, and the sample documents of the current training batch are input into the document classification model to obtain the predicted probability of the sample documents belonging to each document category output by the document classification model. Based on the document category of the sample documents in the current training batch and the predicted probability of the sample documents belonging to each document category, the cross-entropy loss value of the current training batch is determined. Optimize the network parameters of the feature extraction network, the temporal encoder, and the classifier based on the cross-entropy loss value; When the document classification model meets the preset training termination conditions, the trained document classification model is obtained.
14. The scanned document classification method according to claim 13, characterized in that, The determination of the cross-entropy loss value for the current training batch, based on the document categories of the sample documents in the current training batch and the predicted probability of each sample document belonging to each document category, includes: Based on the document category and the predicted probability of belonging to each document category of each sample document in the current training batch, the cross-entropy loss value of each sample document is determined respectively. Based on the document category of each sample document in the current training batch, obtain the sample weight of each sample document; The cross-entropy loss values of each of the sample documents are weighted and summed according to their respective sample weights to determine the cross-entropy loss value of the current training batch.
15. A document scanning and classification device, characterized in that, include: The feature extraction module is configured to extract visual features from each page image of the scanned document to be classified, thereby obtaining the corresponding single-page visual features. The scanned document to be classified includes multiple page images arranged in page order; The temporal coding module is configured to perform temporal coding on multiple single-page visual features corresponding to the multiple page images based on the page order to obtain multi-page sequence features; The document category determination module is configured to determine the document category of the scanned document to be classified based on the multi-page sequence features.
16. A document scanning and classification device, characterized in that, include: One or more processors; A memory that stores one or more programs, which, when executed by one or more processors, cause the one or more processors to implement the scanned document classification method as described in any one of claims 1-14.
17. A storage medium containing computer-executable instructions, characterized in that, The computer-executable instructions, when executed by a computer processor, are used to perform the scanned document classification method as described in any one of claims 1-14.
