A single certificate identification sparse attention method based on two-stage constant false alarm detection and gate data association
Patent Information
- Application Number
- CN202611274181.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-21
- Publication Date
- 2026-10-30
AI Technical Summary
第一,固定窗口稀疏模式将计算限制在局部范围内,难以表征发票代码标签与号码区、大小写金额以及表头与跨页明细行之间的长程关系
针对高分辨率单证识别中注意力计算开销较高、稀疏关键要素易丢失、长程字段关联不合理、计算资源配置缺乏自适应性以及异常输入缺乏保障等问题,本发明通过系统级结构设计取得以下技术效果:
Smart Images

Figure CN123016447A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of multimodal model and enterprise document image recognition technology, specifically involving a sparse attention computation method for automated document information extraction. Background Technology
[0002] In automated information extraction scenarios for corporate documents such as bills, invoices, customs declarations, and contracts, high-resolution scanned images, after being segmented and encoded by a visual Transformer, can generate thousands to tens of thousands of feature tags. This makes the secondary complexity of self-attention computation a significant factor affecting inference latency and memory usage. Document images also exhibit significant spatial sparsity and layout priors: the images contain large areas of white space, table lines, and empty cells, with uneven distribution of effective ink. Although key elements such as seals, handwritten signatures, and low-contrast printed fields have sparse ink, they are of high business importance. Furthermore, stable geometric relationships exist between fields, such as labels and values, headers and details, and amounts in both uppercase and lowercase letters.
[0003] Existing sparse attention methods still suffer from the following problems when applied to the above scenarios. First, the fixed-window sparse pattern restricts computation to a local scope, making it difficult to represent long-range relationships between invoice code labels and number areas, uppercase and lowercase amounts, and headers and cross-page detail rows. Second, thresholds based on globally normalized statistics are easily affected by dense text regions, causing key sparse elements such as seals and signatures located in low-background areas to be missed, and potentially leading to mutual occlusion within dense regions. Third, routing mechanisms with fixed association quantities lack layout constraints, which may introduce unreasonable associations or truncate necessary associations in dense documents. Fourth, empirical thresholds lacking statistical meaning make it difficult to configure computational load according to document complexity. Fifth, when faced with blank, ghosting, or extremely dense inputs, existing methods may exhibit degradation by retaining too few or too many elements, lacking a clear failure safety mechanism. Summary of the Invention
[0004] To address the aforementioned issues, this invention provides a structured sparse attention method. This method draws upon clutter estimation, constant false alarm rate (CFAR) detection, gate correlation, and track maintenance concepts from radar signal processing, and combines them with sparse matrix storage and multi-rate sampling mechanisms. It sequentially performs layout prior map generation, dual-channel signal-to-clutter ratio (SCR) scoring, two-stage CFAR selection, gate-constrained Bayesian data correlation, and dual-format sparse batch processing. Thus, attention computation can focus on informative feature labeling, maintaining key sparse elements under the constraint of the desired CFAR rate, while utilizing layout gates to improve the geometric rationality of long-range field correlations. This method can also configure the computational load according to the complexity of individual documents and perform fail-safe degradation under abnormal input conditions, thereby reducing inference computation and memory usage while maintaining the recall rate of key elements and the integrity of long-range field correlations.
[0005] To achieve the above objectives, the present invention provides the following technical solution: A sparse attention method for document identification based on two-level constant false alarm rate detection and gate data association includes the following steps: S1. Layout Prior Atlas Generation: A multi-channel layout prior atlas is extracted from the original document image using a non-neural network regularization algorithm. The atlas includes a background channel representing the background intensity and a target prior channel representing the location of key elements, and is pooled according to the feature map resolution of each stage of the subsequent network. S2, Dual-channel signal-to-clutter ratio scoring: The input feature map of the current network stage is processed by a learnable matched filter to obtain the signal response. The clutter control field is obtained by spatially weighted constant positive mixing of the background channel. The ratio of the signal response to the clutter control field is calculated as the decision value. The target prior channel is injected into the calculation branch of the signal response. S3. Dual-level constant false alarm rate selection: The decision quantity is subjected to dual-level constant false alarm rate detection at the region level and feature level to select significant regions and significant features, wherein the threshold coefficients at the region level and feature level are analytically derived or numerically solved based on the expected false alarm rate. S4. Gate-constrained Bayesian association: Project the selected salient regions to calculate semantic likelihood, and use the prior relative position of the layout as the layout gate. Obtain the posterior probability of the association between regions through Bayesian fusion, and generate a variable-length association index table based on the posterior probability. S5. Dual-format sparse batch processing: Using the variable-length association index table, sparse attention is constructed through variable-length or fixed-length paths. Attention calculation is performed on the salient features, and the calculation results are scattered back to the original spatial index. Unselected features are retained through identity residuals. S6. Three-rate rhythm control: The layout prior map generation step is executed at the first rate, the dual-channel signal-to-noise ratio scoring step, the dual-level constant false alarm rate selection step and the gate-constrained Bayesian association step are executed at the second rate in each network stage, and the dual-format sparse batch processing step is executed at the third rate in each sparse attention layer. The structural parameters generated by steps S2 to S4 are shared in consecutive multi-layers within the same network stage.
[0006] Preferably, in step S1: The background channel includes an ink density map and a table line edge density map. The ink density map is formed by performing grayscale inversion and adaptive binarization on the original image to obtain a stroke mask and then performing local pooling. The table line edge density map is formed by extracting table lines and borders through gradient magnitude or edge detection operators and then performing local pooling. The target prior channel includes at least a stamp sensitivity map, which is generated by red difference and thresholding and is used to characterize the prior strength of the red stamp.
[0007] Preferably, in step S2: the signal response is calculated as follows: Where T is the input Input feature map, W R and b R For learnable parameters; w s Weights are injected into the target prior; M seal The stamp-sensitive map is pooled to the current network stage resolution; the clutter control field is calculated as follows: M j To traverse the background channel, K j For small, learnable convolutional kernels, * denotes convolution, exp(w j Ensure that the mixed weights of each channel are always positive, ε floor The noise basis term; F is positive point-by-point and has the same resolution as the feature map; the decision metric is: .
[0008] Preferably, in step S3: The region-level detection specifically involves: dividing the feature map into non-overlapping rectangular regions; calculating the norm of the decision value within each region to obtain a region score; performing unit-average constant false alarm rate (CFAR) detection after convolution with a learnable cohesive kernel; wherein the threshold coefficient is analytically derived from the expected false alarm rate. The feature-level detection specifically involves: for each feature within the region retained by the region-level detection, using the scores of other features in the same region as a reference set, performing ordered statistical CFAR detection; wherein the threshold coefficient is obtained by numerically solving the expected false alarm rate using ordered statistical relations.
[0009] Preferably, in the regional detection, the reference window of the area to be inspected is the neighborhood centered on it, excluding the adjacent protection ring and itself. The protection ring is used to prevent self-occlusion caused when a large target spans multiple areas. The expected false alarm rate is configured according to the global layout statistics extracted in step S1, so as to use a lower false alarm rate in documents with low ink coverage and a higher false alarm rate in documents with high ink coverage.
[0010] Preferably, in step S4: the semantic likelihood is calculated by the dot product of the region-level query vector and the key vector; the layout gate is a learnable relative displacement binning bias table or an anisotropic elliptical gate; the Bayesian fusion is the row-oriented softmax applied to the semantic likelihood and the layout gate. The posterior probability is obtained by combining the posterior probability and the posterior probability. All candidate associations whose posterior probabilities exceed the threshold are retained, and a lower limit and an upper limit are set for the number of associations so that the number of associations adapts to the posterior probability of the region.
[0011] Preferably, in step S5: the variable-length path adopts CSR format, and the effective association range of each line is limited by the row pointer, without the need for padding. Full mask; the fixed-length path adopts the ELLPACK format, is computed in parallel by fixed-length blocks, and is masked by a mask. Padding; when using a mixed format, regular associations are processed within a fixed-length body, while associations exceeding the fixed-length capacity are handled separately. Through overflow side-path processing, the attention contributions of the main segment and the overflow segment are processed in the same log-sum-exp manner. Softmax denominator normalization.
[0012] Preferably, in step S6: The second rate recalculates the structural parameters at the boundary of adjacent network stages, or inherits the selected region index from the previous level based on the parent-child mesh mapping; The method also includes an event-triggered resampling step: by monitoring the cosine similarity of the convergence features of adjacent layers, when the drift exceeds a threshold, the structural parameters are recalculated in advance within the current network stage.
[0013] Preferably, the method further includes: Step S7, Cross-page track maintenance: Regularize the pages of the multi-page input, and do not pass complete features between pages, but only pass the structural track composed of the region representative vectors of the selected regions; after the structural parameters of the new page are generated, the new page region is associated with the existing track to improve the retention probability of the matching region or establish cross-page association; confirm the track through the M / N rule, and update the track prototype with exponential moving average.
[0014] Preferably, the method further includes: Step S8, Automatic Gain Adjustment Mechanism: The retention rate of feature labels in each network stage is used as the monitoring quantity. When the retention rate is lower than the lower limit, the expected false alarm rate is increased to relax the retention conditions. When the retention rate is higher than the upper limit, the expected false alarm rate is decreased to tighten the retention conditions. When the retention rate still does not recover after the expected false alarm rate is adjusted to the boundary, the current network stage is switched to dense window attention to prioritize the availability of output under abnormal input conditions.
[0015] Preferably, in step S2, the learnable parameters WR and bR in the signal response, the target prior injection weight ws, and the learnable convolutional kernel Kj and mixed weight wj in the clutter control field are trained through a dual-gated weighted path under end-to-end task loss. The dual-gated weighted path is as follows: , where σ(·) is the sigmoid function, σ(R′) constitutes the saliency self-weighting gate, and σ(F) makes the learning capacity focus on regions with strong background and high requirements for normalization accuracy; the gradient is backpropagated to the two branches through this path, so that the response parameters, background mixing parameters, cohesion kernel and route projection parameters can be trained under end-to-end task loss.
[0016] Preferably, in step S5, after the sparse attention calculation is completed, the scattering write-back adopts a residual connection form: , where S is a sparse operator that is non-zero only on the association pattern. Although the unselected feature labels do not participate in the attention calculation of the current layer, they are still retained through the identity residual and enter the dense downsampling and re-scoring of subsequent network stages.
[0017] Compared with the prior art, the beneficial effects of the present invention are: To address the problems in high-resolution document recognition, such as high attention computation overhead, easy loss of sparse key elements, unreasonable long-range field associations, lack of adaptive computing resource allocation, and lack of protection against abnormal inputs, this invention achieves the following technical effects through system-level structural design: First, this invention constructs a priori map of the document layout. Through regularization algorithms such as grayscale inversion binarization, red difference, and edge detection, multi-channel priors, including ink density, seal sensitivity, and table line edge density, are extracted from the original document image on the CPU side. The background channel enters the scoring denominator, and the target prior channel enters the scoring numerator, forming a dual-channel signal-to-noise ratio decision structure. This structure simultaneously utilizes local background normalization and target prior enhancement to improve the scoring of key sparse elements such as seals located in low-background areas.
[0018] Second, this invention employs a two-stage constant false alarm rate (CFAR) selection mechanism. At the regional level, a sliding window local clutter estimation including protection units is used to reduce the impact of global statistical variations and target self-leakage on the threshold. At the feature level, ordered statistical CFAR detection is used, replacing mean estimation with quantile ordinal statistics. Under the given background model and interference ratio conditions, this mechanism can reduce the impact of dense interference on threshold estimation. The threshold coefficient is determined by the expected false alarm rate, giving the retention ratio a clear statistical meaning and allowing the computational load to be configured according to the complexity of individual documents.
[0019] Third, this invention employs a gate-constrained Bayesian data association routing mechanism. Regional semantic affinity and relative layout priors are fused in an additive Logit form, corresponding to the posterior product of semantic likelihood and layout priors, making geometric relationships such as labels and values, headers and details, explicit constraints. The number of associations is adaptively determined by the posterior threshold and is subject to upper and lower bound constraints, thereby reducing irrelevant candidates in sparse regions while preventing necessary associations in dense regions from being truncated by a fixed number.
[0020] Fourth, this invention employs a dual-format sparse association batch processing mechanism. The variable-length association index table can use either Compressed Sparse Row (CSR) variable-length storage or ELLPACK fixed-length storage, and can handle cases of uneven association numbers through a hybrid (HYB) format consisting of a fixed-length main body and an overflow side path. The CSR path limits the computation range by row boundaries, reducing redundant computations caused by padding; scattering and writing back are represented as sparse operator actions, and unselected feature markers are retained through identity residuals, thus forming a complete data flow closed loop. Fifth, this invention employs a three-rate zero-order preservation mechanism, which separately sets up graph generation once per document, structural decision-making once per network stage, and attention computation once per layer. Structural parameters are preserved within the same network stage and resampled at the network stage boundaries; the preserved index can also be passed to the cross-modal fusion layer, so that the key-value set of cross-attention is constructed from the preserved feature labels without changing the existing structure of the language model.
[0021] Sixth, this invention establishes cross-page trajectory maintenance and automatic gain adjustment mechanisms. Cross-page trajectories, using prototype features and page layout, constitute lightweight structural memory for streaming processing of multi-page documents and improve the retention probability of low-contrast continuation fields. The automatic gain adjustment mechanism constitutes a fail-safe response through noise floor, retention rate interval monitoring, expected false alarm rate step adjustment, and network stage-based density degradation. All of these mechanisms operate on the inference-phase attention structure and can be combined with different training or fine-tuning methods. Attached Figure Description
[0022] The accompanying drawings, which are included to provide a further understanding of embodiments of the invention and form part of this application, do not constitute a limitation thereof. In the drawings: Figure 1 This is the overall flowchart of the sparse attention chain of the present invention; Figure 2 This is a schematic diagram illustrating the generation of the prior art for the layout of this invention; Figure 3 This is a diagram of the dual-channel signal-to-noise ratio scoring structure of the present invention; Figure 4 This is a schematic diagram of the dual-level constant false alarm selection method of the present invention; Figure 5 This is the gate-constrained Bayesian data association routing graph of the present invention; Figure 6 This is a schematic diagram of the dual-format sparse batch processing of the present invention; Figure 7 This is the zero-order hold rhythm diagram for the three-rate system of the present invention; Figure 8 This is a schematic diagram illustrating cross-page track maintenance according to the present invention; Figure 9 This is the three-level response diagram of the automatic gain adjustment of the present invention. Figure 10 This is a detailed diagram of the dimensional flow in an embodiment of the present invention. Detailed Implementation
[0023] To further illustrate the technical means and effects of the present invention in achieving its intended purpose, the following detailed description of the specific implementation methods, structures, features, and effects of the present invention, in conjunction with the accompanying drawings and preferred embodiments, is provided below.
[0024] The present invention discloses a sparse attention method for document recognition based on two-stage constant false alarm rate detection and gate data association. The overall processing flow is as follows: Figure 1 As shown, the process sequentially includes page prior map generation, dual-channel signal-to-noise ratio scoring, two-level constant false alarm rate selection, gate-constrained Bayesian association, dual-format sparse batch processing, and three-rate rhythm control, and optionally includes cross-page track maintenance and automatic gain adjustment mechanisms. L3, L4, and L5 output region and feature indices, variable-length association index tables, and sparse format parameters, respectively, which together constitute the set of structural parameters for subsequent network layer reuse.
[0025] This invention can employ two system architectures. The first is an end-to-end multimodal model, where the model takes a document image as input and outputs field text and its coordinates. This invention operates in the mid-to-high-level network stages and cross-modal fusion layer of the visual encoder. The second is a two-level system consisting of an optical character recognition module and a large language model. The optical character recognition or vision module outputs text and coordinates, while the large language model performs field classification. This invention operates in the backbone network of the vision module. Both system architectures use the same sparse attention processing chain, differing only in the module injection location.
[0026] Specifically, it includes the following steps: Step 1 (L0): Generation of the priori map of the layout like Figure 2 As shown, this step is used to generate the layout prior signals required for the entire chain. A multi-channel layout prior map is extracted from the original document image using a non-neural network rule-based algorithm. This process is executed on the CPU side, without increasing GPU memory usage; it is calculated once for each document and pooled according to the feature map resolution of each network stage for reuse in subsequent network stages.
[0027] 1.1 Background Channel (Entering the denominator of the scoring formula in Step 3): (1) Ink density map M_ink: The original image is reversed in grayscale and adaptively binarized to obtain a stroke mask, and then local pooling is used to form a pixel-by-pixel ink density estimate, which represents "the background ink intensity at this location"; (2) Table line edge density map M_edge: The table lines and borders are extracted by gradient magnitude or edge detection operator, and the edge density is estimated by local pooling to represent "the intensity of layout line interference at this location".
[0028] 1.2 Target Prior Path (Numerator of the scoring formula in Step 3): (1) Seal Sensitive Map M_seal: Generated by red difference R-(G+B) / 2 and thresholding, used to characterize the prior strength of red seals. Since seals usually have high business importance and their ink distribution may be sparse, an independent target prior channel is set.
[0029] (2) Expandable channels: For handwritten signature channels in blue and black ink, the construction method is the same as that of red difference, only the color difference rules are changed.
[0030] 1.3 Graph Fusion and Multi-Resolution Multiplexing: Each channel can be fused using rule-based weighted fusion or used independently. The main implementation uses a channel-by-channel independent fusion method, while rule-based weighted fusion is used as an alternative implementation. Subsequently, pooling is performed according to the feature map resolution of each injection network stage to obtain graphs aligned with each network stage. These graphs represent the background intensity and prior location of key elements, respectively, and are used for signal-to-noise ratio scoring in step three and false alarm rate configuration in step four.
[0031] 1.4 Global layout statistics: While generating the map, global statistics such as the ink coverage rate (stroke mask ratio) and connected component count of the whole map are extracted in a regularized manner and output to step four for global allocation of false alarm rate, and output to step nine for extreme input monitoring.
[0032] Step 2 (L1): Dense Shallow Layer and Sparse Injection Layer Strategy 2.1 The input document image first undergoes dense feature extraction through Conv Stem and several subsequent low-level network stages. Since the number of shallow feature labels is small and texture information needs to be extracted densely, sparse processing is not used in the shallow layers.
[0033] 2.2 Two-stage sparse attention is injected only into mid-to-high-level network stages. In this layer, the number of feature labels is relatively large, and the quadratic complexity of self-attention significantly impacts inference overhead. The example configuration starts injection from a network stage with a feature map size of 64×64. The injection starting point is an adjustable structural parameter: earlier injection can improve the computational savings but may reduce the preservation of low-level textures; later injection can retain more low-level information, but the computational savings are correspondingly reduced.
[0034] 2.3 Each sparse network stage contains several consecutive sparse attention layers; the example configuration has two layers. Adjacent network stages are connected through a downsampling module, with the feature map resolution halved at each stage.
[0035] Step 3 (L2): Importance scoring of dual-channel signal-to-noise ratio like Figure 3 As shown, the ratio of the signal response to the local background control field is used to form the scale-normalized decision quantity; target prior injection and local background normalization together improve the relative score of low-background key elements. Specifically, 3.1 Signal Response (Molecular End). Let the input feature map of a certain sparse network stage be T (dimensions Hs × Ws × C). The feature response is calculated by a learnable linear layer and ReLU activation, and then injected into the target prior channel of step one:
[0036] Among them, W R and b R W is a learnable parameter. R It can be viewed as a learnable matched filter; w s Weights are injected into the target prior; M seal This is a stamp-sensitive map pooled to the current network stage resolution. The main embodiment uses additive bias injection of the target prior; multiplicative gain and independent parallel channels can be used as alternatives. This structure explicitly introduces the stamp prior into the numerator.
[0037] 3.2 Background control field (denominator). The background channel is mixed with a constant positive value through spatial weighting to obtain the control field:
[0038] Where M j Traverse the background channels (Mink, Medge), K j For small, learnable convolutional kernels (achieving spatially variable weights: allowing different background normalization intensities for header, detail, and signature areas), * denotes convolution, exp(w j Ensure that the mixed weights of each channel are always positive, ε floor This is the noise basis term (defined in step nine to prevent division by zero in blank areas). F is positive point by point and has the same resolution as the feature map.
[0039] 3.3 Decision Quantity. The confidence-to-noise ratio decision quantity is calculated feature-by-feature:
[0040] This ratio decision quantity constitutes a scale-invariant normalized statistic under the multiplicative background model, and its statistical meaning comes from the relative relationship between the response term and the background control field; this form is also consistent with the relative stimulus perception relationship described by Weber's law. Subsequent step four uses the ratio of S to the reference window statistic for threshold decision-making, thus the global scaling factor can be canceled in the decision, and this invention does not require a separate global scaling parameter lacking statistical interpretation. The logarithmic form log S = log R′ - log F can be used as an equivalent implementation, where S is the feature-wise, channel-wise decision quantity, which is obtained as a feature-wise scalar score after compression along the channel dimension using the p-norm in step four 4.1.
[0041] 3.4 The scoring results can be divided into three categories. For dense text regions, both R′ and F are high, while S is suppressed after background normalization; for key sparse elements such as seals in low background regions, R′ is at a medium level while F is low, S is relatively improved and further enhanced by target prior injection; for pure blank regions, R′ is close to zero, and S is also close to zero.
[0042] 3.5 Training Path Declaration. Since the threshold selection operation itself is non-differentiable, this invention uses a dual-gated weighted path to make the learnable parameter (W)... R b R w s K j w j (Including condensation kernels, routing projections, etc.) Normal training under end-to-end task loss:
[0043] Here, σ(·) is the sigmoid function. σ(R′) forms a saliency self-weighting gate, and σ(F) makes the learning capacity focus on regions with strong background and high requirements for normalization accuracy. The gradient is backpropagated to the two branches through this path, enabling the response parameters, background mixing parameters, cohesion kernel, and route projection parameters to be trained under end-to-end task loss.
[0044] 3.6 Functional distinction between Step 3 and Step 4. The control field F in Step 3 originates from the point-by-point external prior formed from the original document image and is used to describe the background attributes of the current location; the threshold reference in Step 4 originates from the neighborhood statistics of the scoring field itself and is used to determine the significance of the current score relative to the local neighborhood. The former performs prior normalization, while the latter performs homologous adaptive detection; their input sources and technical functions are different.
[0045] Step 4 (L3): Two-level constant false alarm selection like Figure 4As shown, the regional-level CA-CFAR forms local thresholds through reference cells and protection cells, while the feature-level OS-CFAR estimates the background through the k-th order statistic. These two threshold levels are used for regional selection and feature selection within the region, respectively. Specifically, 4.1 Region Partitioning and Region Decision. The feature map is divided into N regions. w There are N non-overlapping rectangular regions, each region containing N t Each feature. The decision value S from step three is subjected to p-norm (default p=2) comparison and compression (along the channel dimension and region dimension) to obtain the feature-by-feature score and region decision value:
[0046] in, This indicates that the p-norm is calculated for all features and all channels within region c. This invention does not perform global Softmax normalization on region scores to avoid dense regions altering the global baseline and reducing the relative scores of low-background key elements; region selection is instead accomplished by a local constant false alarm threshold.
[0047] 4.2 Point-based aggregation. The region decision variable ρ is convolved with a learnable aggregation kernel K_θ to obtain the aggregation region score. The main implementation uses a 3×3 kernel, but a 5×3 anisotropic kernel set along the text line direction can also be used. This processing is used to merge the discrete responses of the same semantic entity in adjacent regions, improving the detectability of the target's interior and edge regions. Non-negative kernel constraints and dilation and erosion concatenation can be used as alternative methods.
[0048] 4.3 Area-level sliding window constant false alarm rate (CA-CFAR) detection. For each area c to be inspected in the grid: (1) Reference window Ω(c): The internal region is a (2R+1)×(2R+1) neighborhood centered on c, excluding the adjacent guard ring G(c) and c itself, and the number of reference units M = (2R+1). 2 - (2G+1) 2 The boundary region reference window is counted based on the actual reference cells falling into the mesh, and α_w is recalculated based on the actual M. In this section, M refers to the number of region-level reference cells M_w (M_w=16 in the example); (2) Clutter estimation: ; (3) Judgment: The region is then retained, where the threshold coefficient αw is analytically derived from the expected false alarm rate P_fa,w:
[0049] (Under the background assumption of exponential distribution; different derived formulas are corresponding to background models such as Weibull and log-normal, which are listed as replacement methods); When the actual background distribution deviates from the exponential assumption, the detector still gives a monotonically effective significance ranking, only the false alarm rate deviates from the nominal value.
[0050] (4) The function of the protective ring: When a large target such as a seal spans multiple areas, its energy will seep into the reference window of the adjacent area, causing "self-masking"; after setting the protective ring, the area to be inspected is only compared with the pure background that is not adjacent, and the edge area of the target is not submerged by its own energy.
[0051] 4.4 Feature-Ordered Statistical Constant False Alarm Rate Detection (OS-CFAR). For each feature f within each retained region: (1) Reference set Φ(f): The scores of the remaining features in the same region (which may include neighborhood features; in the main embodiment, the scores of the remaining N_t-1 features in the same region are taken), sorted in ascending order. (1) ≤ ... ≤ x ( M ) In this section, M refers to the size of the feature-level reference set M_t (M_t=15 in the example); (2) Clutter estimation: Take the k-th order x (k) k = ⌈q·M⌉, where q is the quantile; (3) Judgment: S(f) ≥ αt · x (k) The features are preserved, where the threshold coefficient αt is numerically solved by the expected false alarm rate through ordered statistical relations:
[0052] (4) Anti-masking property: The quantile ordinal statistic is used instead of the mean as clutter estimate. When the number of dense interference features does not exceed Mk, the k-th ordinal statistic is not affected by higher ordinal interference values, thus reducing the contamination of threshold estimation by dense text features.
[0053] 4.5 Global Configuration of Expected False Alarm Rate. Pfa,w and Pfa,t are used to replace empirical thresholds lacking statistical interpretation and are set regularly by the global layout statistics obtained in step one. Documents with low ink coverage can have a smaller expected false alarm rate, while documents with high ink coverage can have a larger expected false alarm rate. The main implementation uses a segmented configuration table, but continuous functions can also be used. Parameter adjustment can be interpreted as adjusting the probability of retaining background errors.
[0054] 4.6 Numerical Example (Self-Consistent Calculation). Assume an 8×8 grid: the top left 4×4 area comprises 16 densely packed areas with a regional score of approximately 0.9; the bottom right stamp spans 4 areas (center 0.7, edge 0.5); the remaining 44 blank areas have a score of approximately 0.1.
[0055] (1) Existing global threshold mechanism: For ease of explanation, the following uses unnormalized scores for illustrative comparison, and the scores are rounded down and multiplied to three decimal places. The global mean is approximately 0.328, and after multiplying by 0.95, the threshold is approximately 0.312, meaning that stamp edge areas with a score of 0.5 can still be retained. When the layout contains two densely packed table areas, the global mean rises to approximately 0.53, and the threshold is approximately 0.503, at which point stamp edge areas may be missed. This result indicates that the global statistical threshold is easily affected by distant dense areas.
[0056] (2) When using this invention, the local reference window of the seal edge region mainly contains a low-response background, and the clutter estimate is about 0.1. When Pfa,w=5%, αw is about 3.29, and the threshold is about 0.33, so the seal edge region with a score of 0.5 can be preserved. The local clutter estimate of the table region is about 0.9, and the corresponding threshold is increased to about 2.97, thereby suppressing background mispreservation. Feature-level ordered statistics can also reduce the impact of high-order dense features on the 75th quantile estimation. It should be noted that 0.9 is the average level of the decision quantity of the region within the dense block; in actual documents, local high-contrast regions such as the title line, total line, and block edge can still be preserved through local decision, and the decrease in the uniform text region preservation rate is the expected sparsification behavior.
[0057] 4.7 This step outputs the first part of the structural parameter set, namely the selected region set, the selected feature set, and their spatial index.
[0058] Step 5 (L4): Bayesian data association routing with gate constraints like Figure 5 As shown, semantic affinity and the prior relative location of regions together form the posterior association probability. The posterior threshold and upper and lower bounds on the number of associations are used to generate a variable-length association index table and suppress candidate associations with unreasonable layout positions. Specifically, 5.1 Regional Projection and Semantic Likelihood. The selected set of regions is projected onto a linear layer as query, key, and value tensors. The mean of all selected query / key vectors within each region is then calculated to obtain the regional representative. , Calculate the region-level affinity matrix:
[0059] Where dr is the dimension of the region representative vector. Aij is considered as the logarithmic form of the semantic association likelihood between region i and region j (modeling statement: the dot product is used here as an equivalent measure of log likelihood).
[0060] 5.2 Layout Gate. For a pair of regions (i, j), a layout relative position prior B(Δx, Δy) is defined, where Δx and Δy are the relative displacements of the region centers. The main embodiment uses a learnable binning bias table to divide the relative displacements into 7×7 equal bins and obtains the logarithmic prior bias by looking up the table. Anisotropic elliptic gates or learnable Mahalanobis distance gates can also be used. Soft gates use additive logarithmic priors, while hard gates remove candidates outside the gate from the association set. This gate is used to explicitly represent the layout geometric relationships between labels and values, headers and details, and amounts in both uppercase and lowercase.
[0061] 5.3 Bayesian Fusion. The Softmax algorithm operates on the sum of affinity and gate: P_ij = Softmax_j(A_ij + B_ij) The additive Logit bias is mathematically always equal to the posterior product of semantic likelihood and layout prior: P(association) ∝ P(semantic similarity) × P(layout rationality). False associations that are semantically similar but layout-unlikely (such as two similarly textured money areas directly connected across a page) are structurally excluded by the gate.
[0062] 5.4 Posterior Threshold-Driven Adaptive Association Number. Instead of assigning a fixed k partners to each region, all candidates whose posterior correlation exceeds the threshold τ are retained:
[0063] A lower bound (kmin) and an upper bound (kmax) are set for the number of associations. The lower bound is used to avoid empty association sets, and the upper bound is used to limit the computational scale of dense regions. The number of associations adaptively changes with the posterior probability of the region, so that the field regions in sparse documents maintain a small association set, while the header regions in dense documents retain the necessary column-oriented associations.
[0064] 5.5 Directionality of Association. The main implementation uses a directed association from Q to K; the symmetric variant can take the conjunction or mean of Pij and Pji to represent bidirectional field relationships such as case verification.
[0065] 5.6 Output of Variable-Length Association Index Table. Due to the varying number of associations in each region, this step outputs the second part of the structure parameter set: the variable-length association index table. This index table can be used directly by the CSR path or, after being padded to a fixed length, by the ELLPACK path; associations exceeding the fixed-length capacity can be handled by the HYB overflow side path. This maintains consistency between the routing output and the subsequent batch processing data structure.
[0066] 5.7 Application Examples. Invoices may contain multiple numerical regions with similar textures. Fixed-quantity association can easily introduce candidates unrelated to the target field. Layout gates can concentrate the association probability on the same-line label and adjacent uppercase amount areas, and suppress candidates with unreasonable layout positions such as decorative borders. For customs declaration headers, vertical layout priors can cover the detail areas in the same column, allowing the number of associations to adjust with the column length.
[0067] Step Six (L5): Two-Format Sparse Association Attention and Scattering Writeback like Figure 6 As shown, the same variable-length associative index table can be processed by CSR, ELLPACK, or HYB paths. CSR limits the calculation range by row boundaries, ELLPACK uses fixed-length padding, and HYB uses a fixed-length body and overflow sidepaths to handle both regular rows and highly associative rows. Specifically, 6.1 Data Structure Definition. The variable-length associative index table output from step five is formalized into two storage paths: (1) CSR-style variable-length path (main implementation): Each row corresponds to a selected area, and its associated records consist of a value array, a column index array, and a row pointer array. Note that the calculation is performed row by row according to the boundaries defined by the row pointers, without the need for uniform padding.
[0068] (2) ELLPACK type fixed-length path: All rows are padded to a fixed-length two-dimensional array according to the capacity k_pad, and the padding position is masked using a validity flag. The padding, aggregation and masking processing in the prior art can be used as the fixed-length implementation method of this framework.
[0069] 6.2 Relationship between Padding and Storage Format. In CSR paths, there are no padding elements, and the effective calculation range can be limited by the line boundaries defined by the line pointers; therefore, no padding mask is needed. The mask is mainly used to represent variable-length associations in fixed-length formats, and its existence is determined by the storage format used.
[0070] 6.3 Query Key-Value Construction and Attention Calculation. For each selected region: the selected features of this region are projected to obtain query Q; the selected features of this region and the selected features of each associated region in the association table are projected to obtain key K and value V. CSR paths are calculated row by row according to row pointers; ELLPACK paths are calculated in parallel by fixed-length blocks, with masking and padding. The attention output is the effect of the sparse association operator on that row. Associated regions include their own regions by default.
[0071] 6.4 HYB Hybrid Format. Let the normal associativity capacity be k_pad. Rows with an associativity ni not exceeding k_pad are processed in the fixed-length main body; highly associative rows with an associativity exceeding k_pad will have the excess portion stored in a triple consisting of row number, column number, and value in the overflow side path. The attention contribution of the main body segment and the overflow segment is normalized under the same Softmax denominator using the log-sum-exp method, making the segmentation result equivalent to performing a complete attention operation on all associativity of that row, thereby reducing redundant calculations by padding with the longest row and avoiding truncating highly associative regions. k_pad can be set based on the 85% to 95% quantile of the associativity distribution across the entire graph.
[0072] 6.5 Scattering Back and Identity Residual. The attention output is scattered back to its original position according to the original spatial index, and the full-layer output is formalized as the action of a sparse operator:
[0073] In this model, the sparse operator S is non-zero only on the association pattern. Selected feature labels are updated using residuals based on the attention results, while unselected feature labels are retained using identity residuals. Although unselected feature labels do not participate in the attention calculation of the current layer, they still enter the dense downsampling and re-scoring in subsequent network stages.
[0074] 6.6 Sparse MLP. In the main embodiment, the MLP only computes selected features, making its computational scope consistent with the effective feature set of sparse attention. Performing a dense MLP on all features can be used as an alternative implementation. A depthwise separable convolution layer can also be added after scattering write-back to compensate for local contextual information.
[0075] 6.7 Application Example. In a customs declaration network stage, the typical association number for approximately 60 selected areas is 4 to 6, while each of the 3 header areas is associated with 20 detail areas. If the fixed-length capacity is set to 20, most rows will generate a lot of padding calculations; if the capacity is set to 6, some column associations in the header area will be truncated. The HYB path can use a fixed-length body with a capacity of 6 and write the excess associations of the header area into the overflow side path, thereby reducing padding calculations and preserving column associations. The CSR path calculates according to the actual boundaries of each row, without needing to mask the padding positions.
[0076] Step 7 (L6): Three-rate zero-order hold rhythm control like Figure 7 As shown (the number of layers is for illustrative purposes), graph generation, structure decision-making, and sparse attention are performed according to slow loops, medium loops, and fast loops, respectively. Structural parameters are maintained within the same network stage and resampled when network stage boundaries or feature drift exceeds a threshold. Specifically, 7.1 Three-rate hierarchical structure. The entire chain is divided into three loops according to the operating rhythm:
[0077] 7.2 Zero-order Preservation. This involves consecutive n layers within the same network stage sharing the same set of structural parameters. The rationale is that feature changes between adjacent Transformer layers are typically smaller than those across network stages, allowing structural decisions to be reused between adjacent layers. The number of layers, n, is an adjustable parameter, satisfying 1 ≤ n ≤ number of layers within the network stage. Increasing n reduces the average cost of structural decisions but decreases the index update frequency; decreasing n improves the index's ability to follow feature changes but increases the computational cost of intermediate loops.
[0078] 7.3 Resampling and Index Inheritance Between Network Stages. When the resolution changes at the boundary of a network stage, the prior map is repooled according to the new resolution, and the set of structural parameters is recalculated. As an alternative, the index of the selected region at the previous level can be inherited based on the parent-child mesh mapping, so that the corresponding child mesh region receives a priori bonus in subsequent scoring.
[0079] 7.4 Event-Triggered Resampling. Feature drift can be monitored by the cosine similarity of converged features from adjacent layers. When the drift exceeds a threshold δ, the set of structural parameters is recalculated within the network stage. Increasing δ reduces the triggering frequency, making the processing closer to a fixed cycle; decreasing δ increases the tracking frequency of feature changes but increases the overhead of structural decisions. The main embodiment uses a fixed cycle, while the event-triggered method is used as an alternative implementation.
[0080] 7.5 Cross-modal feedforward channel. The retained indexes from the visual side are passed to the cross-modal fusion layer via the feedforward channel. The fusion layer constructs the key-value set for cross-attention based solely on the retained feature labels, without re-executing the selection process or altering the existing structure of the language model. The key-value length decreases as the retention rate decreases, reducing computational cost in both the visual encoding and cross-modal fusion stages.
[0081] Step 8 (L7, Dependent Implementation): Maintaining the Cross-Page Track like Figure 8 As shown, cross-page processing only saves structural tracks such as prototype features and page position, and does not save complete feature maps of historical pages. Tracks are maintained through confirmation, update, and cancellation rules, and are used to improve the retention and association probability of consecutive fields across pages. Specifically, 8.1 Applicable Scenarios and Alignment Prerequisites. Applicable to streaming processing of multi-page documents (multi-page customs declarations, renewal invoices, multi-page contracts). Multi-page inputs are first aligned using regularized page alignment (translation / rotation registration using header lines, table lines, etc. as anchors), and subsequent gate and position calculations are performed in the aligned coordinate system; in unaligned scenarios, the gate degenerates into a large tolerance form (variant).
[0082] 8.2 Track Carrier. To avoid increasing GPU memory usage with the number of historical pages, complete original features are not transmitted between pages. Only a prototype (dimension d_r=128) composed of region representative vectors of the selected regions and a structural track composed of the page position are transmitted. The single-page track set consists of a finite number of low-dimensional vectors, and its storage overhead remains bounded.
[0083] 8.3 Track Association. After generating the set of structural parameters for the new page, the semantic likelihood and layout gate association operators from step five are reused to associate the new page region with existing tracks. Region-level and page-level associations use a consistent calculation method to maintain consistency in cross-page association rules.
[0084] 8.4 Track Function. The primary implementation method is track prior injection, which involves increasing the prior score of the region matching the existing track in step three or four, thus giving the low-contrast continuation table header a higher retention probability. An alternative method is cross-page association edges, where the current page region performs attention on the track prototype to establish cross-page relationships for fields such as subtotal and cumulative.
[0085] 8.5 Lifecycle Management. Unmatched high-scoring regions are established as candidate tracks and confirmed using the M / N rule. The main implementation uses a 2 / 3 confirmation, meaning a track is considered official when it appears at least twice in three consecutive pages. After a successful match, the prototype is updated using an exponential moving average: p ← β·p + (1-β)·f_obs, where p is the track prototype, f_obs is the observation features of the matched region on the current page, and β is the historical weight. The track is cancelled when there are no matches for m consecutive pages, with m=2 by default. The track update rate β determines the relative weight between the historical prototype and the current observation.
[0086] 8.6 Bounded Memory Streaming Processing. Multi-page documents are input sequentially and output page by page. Only the characteristics of the current page and a limited number of tracks are stored in the video memory, keeping the video memory usage of the entire multi-page document at the level of a single page.
[0087] Step Nine (L8): Automatic Gain Adjustment and Fail-Safe Mechanism like Figure 9 As shown, the failure safety mechanism sequentially executes noise floor protection, expected false alarm rate adjustment based on retention rate, and switching to dense window attention according to network stage. Each stage has clearly defined trigger and exit conditions. Specifically, 9.1 Noise Basis Term. The noise basis ε_floor in the control field of step three shall be determined according to the provisions of this clause: ε_floor represents the minimum positive value of the background estimate and should be set to a normal number lower than that of the typical ink blot density (it can be on the order of 1% of the typical ink blot density).
[0088] 9.2 Retention Rate Monitoring and Gain Adjustment. The retention rate, a feature marker for each network stage, is used as the monitoring parameter, with a lower limit rmin and an upper limit rmax. When the retention rate is below rmin, Pfa is increased in multiplicative steps to relax the retention conditions; when the retention rate is above rmax, Pfa is decreased to tighten the retention conditions. The adjustment only applies to the inference-era threshold parameters and is limited to preset upper and lower bounds. Step four provides the initial configuration of Pfa; this step performs bounded adjustments based on this initial configuration.
[0089] 9.3 Failure-Safe Mode. When the retention rate still fails to recover to the set range after Pfa is adjusted to the boundary, the current network stage is switched to dense window attention. This mode prioritizes output availability under abnormal input conditions at the cost of increased computational latency.
[0090] 9.4 Three-level response mechanism. The first level adds a noise floor to avoid a denominator of zero; the second level adjusts the expected false alarm rate based on the retention rate; the third level switches to dense window attention according to network stage when the adjustment is ineffective. Each level has clearly defined trigger and exit conditions.
[0091] Example: like Figure 10 As shown, this embodiment is used to specifically illustrate the implementation process of the core solution of the present invention, and to demonstrate the dimensional settings and data flow from the original scanned document to the field output.
[0092] I. Basic Settings The input is a scanned A4 document at 300 dpi, resampled to 1024×1024×3. The backbone network consists of a Conv Stem (stride of 4) and 3 network stages, with sparse processing injected starting from the 2nd network stage. Each sparse network stage contains 2 sparse attention layers, maintaining a layer count of n=2. The system adopts an end-to-end multimodal architecture, reusing the visual-side index in the cross-modal fusion layer.
[0093] II. A priori graph of the layout (L0, slow loop) The CPU generates Mink, Mseal, and Medge (each 1024×1024), which are pooled to two resolution versions of 64×64 and 32×32 respectively; global statistics: ink coverage ηcov = 18%, which is judged as a medium-to-high complexity component, and the segment table is allocated to Pfa,w = 5% and Pfa,t = 5%.
[0094] III. Dense Shallow Layer (L1) The initial convolutional module outputs a 256×256×64 feature map; the first network stage outputs a 128×128×128 feature map, both using dense computation.
[0095] IV. Network Stage 2: Sparse Injection Start Point (64×64×256, 4096 Feature Labels) (1) Region division: 16×16=256 regions (Nw=256), each region has 4×4=16 feature labels (Nt=16).
[0096] (2) L2 score: W_R dimension 256×256; R′ is 4096×256 (feature-wise and channel-wise), F is 4096 dimensions, and S is a 4096-dimensional feature-wise score after channel compression.
[0097] (3) L3 region level: R=2, G=1, reference window is 5×5, after removing 3×3 protection units, M=16. Pfa,w=5% corresponds to αw≈3.29. After the decision, about 60 regions are retained, and the region retention rate is about 23.4%, including high local contrast regions such as table headers, field labels and block edges.
[0098] (4) L3 Feature Level: Within the region, M=15, q=0.75, k=12. Pfa,t=5% corresponds to αt≈2.34. Each retention region retains an average of 6 features, totaling approximately 360 feature labels, with a retention rate of approximately 8.8%, which is within the working interval defined by rmin=2% and rmax=40%, therefore L8 is not triggered.
[0099] (5) L4 routing: region representative dimension dr = 128; gate binning table 7×7; τ = 0.05, kmin = 2, k_max = 24. Typical region association number 4~6, each of the 3 header regions is associated with 20 detail regions.
[0100] (6) L5 calculation: The main implementation uses the CSR path, and the attention of each of the 60 rows is calculated according to the row boundaries without setting a padding mask. When using the HYB replacement method, k_pad takes the 90th percentile of the distribution of the number of associations, which is 6; 14 of the 3 header rows exceed the association and enter the overflow side path, and are merged with the main body through log-sum-exp.
[0101] (7) L6 rhythm: The two layers of the current network phase share the same set of structural parameters, and scoring and routing are not repeated within the network phase.
[0102] (8) Scattering writeback: 360 selected feature labels are updated with attention result residuals, and the remaining 3736 feature labels are passed by identity; sparse MLP only applies to selected feature labels.
[0103] V. Network Stage 3 (32×32×512, 1024 Feature Labels) The graph was repooled to 32×32, and the set of structural parameters was recalculated. This network stage was divided into 8×8 regions, each containing 16 feature labels, retaining approximately 20 regions and approximately 120 feature labels. The two layers within the network stage shared the same set of structural parameters.
[0104] VI. Cross-modal fusion and output The key-value set of the cross-attention fusion layer is constructed only by the final index retained by the visual side: the key-value length is about 120 (compared to 1024 feature labels in the whole image, it shrinks by about 88%); the decoder outputs the text and coordinates of each field.
[0105] VII. Multi-page scenarios (L7 takes effect) The three customs declaration forms are entered in page order. On page 1, the header area is selected and a candidate track is created, containing 128 prototype features and page position. On page 2, if the column headers are printed too lightly, the track prior increases its retention probability, and the prototype is updated with β=0.3. On page 3, the cumulative field is linked to historical subtotal tracks via cross-page association edges. Only the features of the current page and approximately 30 tracks are saved during processing.
[0106] 8. Extreme Cases (L8 Effective) When the retention rate of blank scans falls below rmin=2%, Pfa increases in increments of 1.5. If the retention rate still does not recover after adjusting to the upper bound, the current network stage switches to dense window attention. At this point, the output flow remains usable, but inference latency increases.
[0107] In summary, compared with existing sparse attention techniques and the aforementioned borrowed techniques, the core technological innovations of this invention are mainly as follows: First, to address the issue that importance scoring relies solely on the features themselves and lacks prior information about the layout, this invention employs a dual-channel signal-to-noise ratio (SNR) scoring structure. The background channel, after being mixed by a constant positive learnable method, enters the denominator, while the target prior channel enters the numerator, forming the ratio of the response to the local background estimate. This decision factor exhibits scale invariance under the multiplicative background model, and subsequent constant false alarm rate (CFAR) decisions can absorb global scaling; therefore, there is no need to set a separate global scaling parameter that lacks statistical interpretation.
[0108] Second, to address the issue that global normalization thresholds are easily affected by dense regions and that empirical parameters lack statistical interpretation, this invention uses a two-level constant false alarm rate (CFAR) threshold to replace global Softmax normalization. At the region level, a sliding window CA-CFAR with guard cells is used, while at the feature level, OS-CFAR is used. The threshold coefficients are determined analytically or numerically based on the expected false alarm rate. The region score is also processed by agglomeration kernels before detection to improve the detectability of locally sparse but semantically critical regions.
[0109] Third, addressing the shortcomings of existing routing mechanisms that lack format constraints and employ a fixed number of associations, this invention constructs a gate-constrained Bayesian data association routing system. A learnable binning bias table or anisotropic elliptic gate is used to represent the format prior, and row-wise Softmax is used to fuse it with semantic affinity to form the posterior association probability. The number of associations is determined by both the posterior threshold and upper and lower bound constraints, outputting a variable-length association index table.
[0110] Fourth, to address the issues of redundant computations and unclear scattering-write-back relationships arising from fixed-length padding and masking, this invention represents sparse attention batch processing as a dual-format sparse correlation operator. The CSR path replaces the padding mask with row boundaries, the ELLPACK path uses a fixed-length implementation, and the HYB path balances regular and highly correlated regions through a fixed-length main body and overflow side paths. Layer outputs are uniformly represented as Y=(I+S)X, and unselected feature markers are retained using identity residuals.
[0111] Fifth, addressing the issues of unclear structural decision update rhythm and lack of cross-modal transfer, this invention sets up three processing cycles: slow loop, medium loop, and fast loop. The slow loop generates a priori graph of the layout; the medium loop performs scoring, selection, and association to generate a set of structural parameters; and the fast loop performs sparse association attention. Structural parameters are maintained at zero order within the same network stage, resampled at network stage boundaries, and can be transferred to the cross-modal fusion layer by retaining the index.
[0112] Sixth, to address the issues of cross-page field continuity and abnormal input degradation in multi-page documents, this invention establishes a cross-page track maintenance and automatic gain adjustment mechanism. The cross-page track only transmits prototype features and page position, and uses confirmation, update, and cancellation rules for lifecycle management; the automatic gain adjustment mechanism adjusts the expected false alarm rate based on the retention rate, and switches to dense window attention according to network stage when adjustment is ineffective. The above mechanism operates during the inference period and can be implemented independently of the training parameter structure.
[0113] The above description of the embodiments is provided to enable those skilled in the art to understand and apply the present invention. It will be apparent to those skilled in the art that various modifications can be made to these embodiments, and the general principles described herein can be applied to other embodiments without inventive effort. Therefore, the present invention is not limited to the above embodiments, and any improvements and modifications made by those skilled in the art based on the disclosure of the present invention without departing from the scope of the present invention should be within the protection scope of the present invention.
Claims
1. A sparse attention method for document recognition based on two-stage constant false alarm rate detection and gate data association, characterized in that: Includes the following steps: S1. Layout Prior Atlas Generation: A multi-channel layout prior atlas is extracted from the original document image using a non-neural network regularization algorithm. The atlas includes a background channel representing the background intensity and a target prior channel representing the location of key elements, and is pooled according to the feature map resolution of each stage of the subsequent network. S2, Dual-channel signal-to-clutter ratio scoring: The input feature map of the current network stage is processed by a learnable matched filter to obtain the signal response. The clutter control field is obtained by spatially weighted constant positive mixing of the background channel. The ratio of the signal response to the clutter control field is calculated as the decision value. The target prior channel is injected into the calculation branch of the signal response. S3. Dual-level constant false alarm rate selection: The decision quantity is subjected to dual-level constant false alarm rate detection at the region level and feature level to select significant regions and significant features, wherein the threshold coefficients at the region level and feature level are analytically derived or numerically solved based on the expected false alarm rate. S4. Gate-constrained Bayesian association: Project the selected salient regions to calculate semantic likelihood, and use the prior relative position of the layout as the layout gate. Obtain the posterior probability of the association between regions through Bayesian fusion, and generate a variable-length association index table based on the posterior probability. S5. Dual-format sparse batch processing: Using the variable-length association index table, sparse attention is constructed through variable-length or fixed-length paths. Attention calculation is performed on the salient features, and the calculation results are scattered back to the original spatial index. Unselected features are retained through identity residuals. S6. Three-rate rhythm control: The layout prior map generation step is executed at the first rate, the dual-channel signal-to-noise ratio scoring step, the dual-level constant false alarm rate selection step and the gate-constrained Bayesian association step are executed at the second rate in each network stage, and the dual-format sparse batch processing step is executed at the third rate in each sparse attention layer. The structural parameters generated by steps S2 to S4 are shared in consecutive multi-layers within the same network stage.
2. The sparse attention method for document recognition based on dual-level constant false alarm rate detection and gate data association as described in claim 1, characterized in that: In step S1: The background channel includes an ink density map and a table line edge density map. The ink density map is formed by performing grayscale inversion and adaptive binarization on the original image to obtain a stroke mask and then performing local pooling. The table line edge density map is formed by extracting table lines and borders through gradient magnitude or edge detection operators and then performing local pooling. The target prior channel includes at least a stamp sensitivity map, which is generated by red difference and thresholding and is used to characterize the prior strength of the red stamp.
3. A single-stage constant false alarm rate (CFAR) detection method based on gate data correlation as described in claim 2. The method for identifying sparse attention is characterized by: In step S2: the signal response is calculated as follows: Where T is the input Input feature map, W R and b R For learnable parameters; w s Weights are assigned to the target prior; M seal The stamp-sensitive map is pooled to the current network stage resolution; the clutter control field is calculated as follows: M j Traverse each background channel, K j For small, learnable convolutional kernels, * denotes convolution, exp(w j Ensure that the mixed weights of each channel are always positive, ε floor The noise basis term; F is positive point-by-point and has the same resolution as the feature map; the decision metric is: .
4. The sparse attention method for document recognition based on dual-level constant false alarm rate detection and gate data association as described in claim 3, characterized in that: In step S3: The region-level detection specifically involves: dividing the feature map into non-overlapping rectangular regions; calculating the norm of the decision value within each region to obtain a region score; performing unit-average constant false alarm rate (CFAR) detection after convolution with a learnable cohesive kernel; wherein the threshold coefficient is analytically derived from the expected false alarm rate. The feature-level detection specifically involves: for each feature within the region retained by the region-level detection, using the scores of other features in the same region as a reference set, performing ordered statistical CFAR detection; wherein the threshold coefficient is obtained by numerically solving the expected false alarm rate using ordered statistical relations.
5. The sparse attention method for document recognition based on dual-level constant false alarm rate detection and gate data association as described in claim 4, characterized in that: In the regional-level detection, the reference window of the area to be inspected is the neighborhood centered on it, and the adjacent protection ring and itself are removed. The protection ring is used to prevent self-occlusion caused when a large target spans multiple areas. The expected false alarm rate is configured according to the global layout statistics extracted in step S1, so as to use a lower false alarm rate in documents with low ink coverage and a higher false alarm rate in documents with high ink coverage.
6. A single-stage constant false alarm rate (CFAR) detection method based on gate data correlation as described in claim 5. The method for identifying sparse attention is characterized by: In step S4: the semantic likelihood is calculated by the dot product of the region-level query vector and the key vector; the layout gate is a learnable relative displacement binning bias table or an anisotropic elliptical gate; the Bayesian fusion is a row-oriented softmax operation applied to the semantic likelihood and the layout gate. The posterior probability is obtained by combining the posterior probability and the posterior probability. All candidate associations whose posterior probabilities exceed the threshold are retained, and a lower limit and an upper limit are set for the number of associations so that the number of associations adapts to the posterior probability of the region.
7. A single-stage constant false alarm rate (CFAR) detection method based on gate data correlation as described in claim 6. The method for identifying sparse attention is characterized by: In step S5: the variable-length path adopts CSR format, and the effective association range of each line is limited by the row pointer, without the need for padding. Full mask; the fixed-length path adopts the ELLPACK format, is computed in parallel by fixed-length blocks, and is masked by a mask. Padding; when using a mixed format, regular associations are processed within a fixed-length body, while associations exceeding the fixed-length capacity are handled separately. Through overflow side-path processing, the attention contributions of the main segment and the overflow segment are processed in the same log-sum-exp manner. Softmax denominator normalization.
8. The sparse attention method for document recognition based on dual-level constant false alarm rate detection and gate data association as described in claim 7, characterized in that: In step S6: The second rate recalculates the structural parameters at the boundary of adjacent network stages, or inherits the selected region index from the previous level based on the parent-child mesh mapping; The method also includes an event-triggered resampling step: by monitoring the cosine similarity of the convergence features of adjacent layers, when the drift exceeds a threshold, the structural parameters are recalculated in advance within the current network stage.
9. A sparse attention method for document recognition based on dual-level constant false alarm rate detection and gate data association as described in claim 8, characterized in that: The method further includes: Step S7, Cross-page track maintenance: Regularize the pages of the multi-page input, and do not pass complete features between pages, but only pass the structural track composed of the region representative vectors of the selected regions; after the structural parameters of the new page are generated, the new page region is associated with the existing track to improve the retention probability of the matching region or establish cross-page association; confirm the track through the M / N rule, and update the track prototype with exponential moving average.
10. The sparse attention method for document recognition based on dual-level constant false alarm rate detection and gate data association as described in claim 9, characterized in that: The method further includes: Step S8, Automatic Gain Adjustment Mechanism: The retention rate of feature labels in each network stage is used as the monitoring quantity. When the retention rate is lower than the lower limit, the expected false alarm rate is increased to relax the retention conditions. When the retention rate is higher than the upper limit, the expected false alarm rate is decreased to tighten the retention conditions. When the retention rate still does not recover after the expected false alarm rate is adjusted to the boundary, the current network stage is switched to dense window attention to prioritize the availability of output under abnormal input conditions.
