NLP-based customs document text target feature extraction method and system

By performing sequence labeling and structure matching on customs documents, combined with the iterative correction mechanism of semantic association graphs, the problems of missing fields and logical errors caused by the diversity of customs document formats were solved, achieving high accuracy and consistency in field extraction.

CN121579993AActive Publication Date: 2026-02-27TIANJIN YITAI TECHNOLOGY DEVELOPMENT CO LTD +1
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN202610100232.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-01-26
Publication Date
2026-02-27
Estimated Expiration
2046-01-26

AI Technical Summary

Technical Problem

Existing customs document feature extraction methods cannot effectively fill in missing fields when faced with documents with diverse formats, and the extracted fields lack logical consistency verification, resulting in erroneous results that cannot be automatically corrected.

Method used

By transforming the field missing pattern into document structure diagnostic features, an adaptive completion strategy and an iterative correction mechanism for cross-field semantic association constraints are adopted. By matching the field missing vector with the structure type feature vector, and combining the spatial location and semantic matching degree of the extracted fields, a semantic association graph is constructed to complete the field and verify the logic.

Benefits of technology

It significantly improves the accuracy and logical consistency of field extraction from customs documents with varying and complex formats, reduces errors and omissions in data completion, and enhances the system's adaptability and accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121579993A_ABST
    Figure CN121579993A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of data processing, and discloses a customs document text target feature extraction method and system based on NLP. The method comprises the following steps: carrying out sequence labeling on customs document texts to obtain an initial field set and a field missing vector; matching the field missing vector with the structure type feature vector to determine a field space attention template; screening the candidate text blocks according to the attention template to generate complementation fields; and constructing a semantic association graph for the initial fields and the complemented fields, performing constraint verification and iterative correction, and outputting a target field set. According to the method, the field extraction accuracy and the logic consistency of customs receipts in variable formats and complex formats are improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of data processing, and in particular to a customs document text target feature extraction method and system based on NLP. BACKGROUND

[0002] Customs document text target feature extraction is a key technical link of customs clearance automation, involving automatically identifying and extracting key business fields such as commodity name, HS code, quantity, unit, amount, and place of origin from unstructured or semi-structured text documents such as customs declaration forms, commercial invoices, packing lists, and bills of lading. The existing customs document feature extraction method based on natural language processing mainly uses a sequence labeling model to label the field types of the text. Through deep learning models such as BiLSTM-CRF, the text sequence after tokenization is mapped to a label sequence, and then various business fields are extracted. This method trains a sequence labeling model using large-scale labeled data, enabling the model to learn the context features and boundary recognition patterns of the fields. It achieves high extraction accuracy on standard format documents and provides basic data support for customs automated review.

[0003] However, customs documents have high format diversity. Documents from different countries, different enterprises, and different business types differ greatly in layout, field arrangement order, and table nesting structure, resulting in insufficient generalization ability of the sequence labeling model trained on a fixed training set when faced with new format documents. The field extraction accuracy drops significantly, especially in non-standard formats such as column layout and table nesting, with a missing rate of key fields as high as 30% to 50%. Secondly, existing methods extract each field as an independent target, lacking modeling of the business logic association between fields. They cannot use domain knowledge such as the semantic consistency of commodity names and HS codes, the numerical logic relationship between quantity, unit, and amount, and the trade agreement matching between place of origin and tax rate for cross-validation. This results in errors in which even if the individual field extraction confidence is high, the field combination may still be logically inconsistent, and such logical errors cannot be automatically discovered and corrected before manual review. SUMMARY

[0004] The present application provides a customs document text target feature extraction method and system based on NLP, which solves the technical problems of existing customs document feature extraction methods in which missing fields cannot be effectively completed when faced with format diversification documents, and error results cannot be automatically corrected due to the lack of logical consistency verification between extracted fields. By converting the field missing pattern into a document structure diagnosis feature to implement an adaptive completion strategy, and through a violation feedback mechanism of cross-field semantic association constraints to implement targeted iterative correction, the field extraction accuracy and logical consistency of customs documents with varying and complex formats are improved.

[0005] In a first aspect, the application provides a method for extracting target features of customs document text based on NLP, which comprises:

[0006] Step S1: performing sequence labeling processing on the customs document text to obtain an initial field set and extraction confidence of each field, and generating a field missing vector according to the presence of mandatory fields in high-confidence fields;

[0007] Step S2: performing similarity matching of the field missing vector and a pre-stored structure type feature vector, and calculating a comprehensive score in combination with the spatial position of the extracted fields and the distribution matching degree of the structure template, so as to determine a field spatial attention template from the structure type with the highest comprehensive score;

[0008] Step S3: screening candidate text blocks according to the probability distribution heat map of missing fields in the field spatial attention template, calculating a weighted completion score of spatial response value, format matching degree and semantic matching degree for the candidate text blocks, and generating a completion field from the text block with the highest completion score;

[0009] Step S4: constructing the initial field set and the completion field into a semantic association graph, calculating a constraint violation label between fields based on knowledge graph embedding, performing context expansion or keyword correction on the field node with the lowest confidence according to the constraint violation type, and outputting a target field set after iterative verification.

[0010] In a second aspect, the application provides a system for extracting target features of customs document text based on NLP, which comprises:

[0011] A generating module is configured to perform sequence labeling processing on the customs document text to obtain an initial field set and extraction confidence of each field, and generate a field missing vector according to the presence of mandatory fields in high-confidence fields;

[0012] A matching module is configured to perform similarity matching of the field missing vector and a pre-stored structure type feature vector, and calculate a comprehensive score in combination with the spatial position of the extracted fields and the distribution matching degree of the structure template, so as to determine a field spatial attention template from the structure type with the highest comprehensive score;

[0013] A weighting module is configured to screen candidate text blocks according to the probability distribution heat map of missing fields in the field spatial attention template, calculate a weighted completion score of spatial response value, format matching degree and semantic matching degree for the candidate text blocks, and generate a completion field from the text block with the highest completion score;

[0014] A correction module is configured to construct the initial field set and the completion field as a semantic association graph, calculate constraint violation marks between fields based on knowledge graph embedding, perform context expansion or keyword correction on a field node with the lowest confidence according to a constraint violation type, and output a target field set after iteration verification.

[0015] In the technical solution provided in the application, the initial field set and the extraction confidence of each field are obtained by performing sequence labeling processing on the customs document text, and a field missing vector is generated according to the presence of a mandatory field in a high-confidence field, realizing the cognitive transformation from the extraction failure phenomenon to the structural diagnosis feature, so that the field missing is no longer just a defect mark of the extraction result, but becomes a quantitative input reflecting the structural feature of the document format, laying a data foundation for the subsequent adaptive extraction strategy based on structure perception. By performing similarity matching between the field missing vector and a pre-stored structure type feature vector, and combining the spatial position of the extracted field with the distribution matching degree of the structure template to calculate a comprehensive score, the field spatial attention template is determined from the structure type with the highest comprehensive score, realizing a reverse inference mechanism from the missing mode to the document structure type, solving the problem that the priori knowledge of the structure is lacking when the prior art faces the format diversified document, and only a fixed extraction strategy can be used, resulting in insufficient generalization ability, so that the extraction system can dynamically adjust the spatial distribution assumption of the field search according to the actual format structure of the document, and the blind global search is converted into a targeted regional directional search. According to the probability distribution heat map of the missing field in the field spatial attention template, the candidate text blocks are screened, the spatial response value, the format matching degree and the semantic matching degree of the candidate text blocks are calculated, and the weighted completion score is calculated, and the completion field is generated from the text block with the highest completion score. Through the three-dimensional comprehensive evaluation mechanism of spatial priori, format specification and semantic feature, the accuracy and reliability of the missing field completion are significantly improved, and the problems of false completion and incomplete completion caused by the prior art which only relies on keyword matching or a single position heuristic method are avoided. BRIEF DESCRIPTION OF DRAWINGS

[0016] In order to more clearly illustrate the technical solutions of the embodiments of the application, the following will briefly introduce the drawings needed to be used in the embodiment description. Obviously, the drawings in the following description are some embodiments of the application, and other drawings can be obtained by those skilled in the art without creating labor based on these drawings.

[0017] Figure 1 An embodiment schematic diagram of the customs document text target feature extraction method based on NLP in the embodiment of the application;

[0018] Figure 2 An embodiment schematic diagram of the BiLSTM-CRF sequence labeling model structure in the embodiment of the application;

[0019] Figure 3 This is a schematic diagram comparing the field extraction accuracy of different methods on different document formats in the embodiments of this application. Detailed Implementation

[0020] This application provides a method and system for extracting target features from customs document text based on NLP. The terms "first," "second," "third," "fourth," etc. (if present) in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments described herein can be implemented in a sequence other than that illustrated or described herein. Furthermore, the terms "comprising" or "having" and any variations thereof are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0021] For ease of understanding, the specific process of the embodiments of this application is described below. Please refer to [link / reference]. Figure 1 One embodiment of the NLP-based target feature extraction method for customs document text in this application includes:

[0022] Step S1: Perform sequence labeling on the customs document text to obtain the initial field set and the extraction confidence of each field, and generate a field missing vector based on the presence of required fields in high-confidence fields;

[0023] Specifically, a CRNN-CTC architecture OCR model is used to recognize text in customs document images, converting the images into text sequences containing all recognized characters. Then, the Jieba word segmentation tool is used to segment the text into Chinese words, generating a word sequence. The segmentation results are input into a pre-trained BERT-Base-Chinese model, where each word is encoded as a 768-dimensional context vector. All word vectors form a text embedding matrix. This matrix is ​​input into a BiLSTM-CRF sequence labeling model. The bidirectional LSTM layer captures the contextual dependencies of words, while the CRF layer outputs the probability distribution of each word belonging to various label types. Label types include 17 types such as the starting position of the product name, the internal position of the product name, the starting position of the HS code, the starting position of the quantity, and non-target fields. The Viterbi algorithm decodes the globally optimal label sequence from the probability distribution. Based on the label sequence, words corresponding to consecutive labels of the same type are combined into complete fields, extracting the product name, HS code, quantity, unit, amount, and country of origin. The extraction confidence score for each field is calculated by multiplying the label probabilities of all words within that field's range. Fields with an extraction confidence score greater than 0.7 are categorized into a high-confidence field set. The presence of the six required fields—product name, HS code, quantity, unit, amount, and country of origin—in the high-confidence set is statistically analyzed. If a required field exists, its corresponding vector position is marked as 1; otherwise, it is marked as 0, forming a 6-dimensional field missing vector.

[0024] Step S2: Perform similarity matching between the missing field vector and the pre-stored structure type feature vector. Calculate the comprehensive score by combining the spatial location of the extracted fields with the distribution matching degree of the structure template. Determine the field spatial attention template from the structure type with the highest comprehensive score.

[0025] Specifically, the customs document structure knowledge base pre-stores 15 typical structure types, including standard horizontal format, column layout format, nested table format, and product description centralized format. Each structure corresponds to a 6-dimensional feature vector, where each dimension represents the historical missing probability of the corresponding required field under that structure. The weighted cosine similarity between the field missing vector and the feature vector of each structure is calculated. The weighting coefficient is determined based on the degree of overlap between the actual missing field and the high-missing-probability field; the higher the overlap, the greater the weight. The top 3 structure types with the highest similarity are selected as candidates, requiring a maximum similarity of 0.6. The bounding box coordinates of high-confidence fields are extracted from the text block location information saved in the OCR stage, and the normalized coordinates of the bounding box center point are calculated. For each candidate structure, its corresponding field spatial distribution template is read. This template uses a Gaussian mixture model to describe the expected distribution of each field type on the page, containing the mean vector and covariance matrix of three Gaussian components. The probability density of the actual coordinates of each extracted field on its corresponding field distribution template is calculated, and the spatial matching degree is obtained by summing the probability densities of all fields under the candidate structure. The overall score is calculated by multiplying the similarity by 0.6 and the normalized matching degree by 0.4. The candidate structure with the highest overall score is selected as the inferred structure type. The field space attention template corresponding to the structure is read from the knowledge base. The template contains a probability heatmap of each required field on the page.

[0026] Step S3: Filter candidate text blocks based on the probability distribution heatmap of missing fields in the field spatial attention template, calculate the weighted completion score of spatial response value, format matching degree and semantic matching degree for the candidate text blocks, and generate the completion field from the text block with the highest completion score;

[0027] Specifically, for the missing fields marked as 0 in the field missing vector, the probability heatmap of the corresponding field is extracted from the field spatial attention template. All text blocks saved in the OCR stage are traversed, and the probability value of the center point coordinates of each text block on the corresponding position on the heatmap is calculated as the spatial response value. Text blocks with response values ​​exceeding 0.5 are selected to form a candidate set. The candidate text blocks are then subjected to field type discrimination. If the missing field is of the HS encoding type, a regular expression is used to match a 4- to 10-digit pure numeric format; a successful match results in a format matching score of 1, otherwise 0. If the missing field is of the quantity type, the number and decimal point formats are matched, and the presence of unit words in the surrounding area is checked. If the missing field is of the origin type, the text block is input into the country / region entity recognition model, and the output geographical location probability is used as the format matching score. The semantic matching score is obtained by encoding the candidate text block into a BERT vector and calculating the cosine similarity with the prototype vector of that field type. The prototype vector is composed of the average vector of 100 standard samples of that field type. The completion score is calculated by summing the spatial response value multiplied by 0.3, the format matching score multiplied by 0.4, and the semantic matching score multiplied by 0.3. The text block with the highest completion score is selected as the completion content for the missing field, generating a completion field that includes the field type, text content, and completion score.

[0028] Step S4: Construct a semantic association graph by combining the initial field set and the completed field set. Based on the knowledge graph embedding, calculate the constraint violation markers between the fields. According to the constraint violation type, perform context expansion or keyword correction on the field node with the lowest confidence. After iterative verification, output the target field set.

[0029] Specifically, a directed semantic association graph is constructed using the fields in the initial field set and the completed field set as nodes. This graph establishes semantic consistency constraints between the product name and HS code, numerical logical constraints between quantity, unit, and amount, trade agreement constraints between country of origin and tax rate, and rule constraints between consignee and trade and regulatory methods. The embedding vectors corresponding to the product name and HS code are queried from the pre-built customs commodity knowledge graph. The relationship distance between the two is calculated using TransE relationship vectors, and the distance is converted into a relationship probability. When the probability is below 0.15, the edge is marked as violating the constraint. For numerical logical constraints, the average unit price and standard deviation of the HS code are obtained by querying the historical database. The implied unit price is calculated by dividing the current amount by the quantity. The deviation multiple is calculated by dividing the difference between the implied unit price and the average unit price by the standard deviation. When the deviation multiple exceeds 2.5, the edge is marked as violating the constraint. All constraint edges are traversed to count the number of violation marks. When the number of violations reaches two or more, a re-extraction process is triggered. The field node with the lowest confidence level among those violating constraints is selected as the re-extraction target. If the target is a product name, a dependency parsing model is used to identify modifiers of attributive or parallel relationships within 10 words before and after the original extraction position and concatenate them into the original product name to form an extended description. If the target is an HS code, the target code is calculated using the knowledge graph relation vector and embedded in the encoding space. The three nearest candidate codes are then searched and returned to the original text for exact matching. Constraint validation is re-executed on the corrected fields to calculate the new number of violations. The process terminates when the number of violations decreases or the iteration reaches three times, and the final set of target fields is output.

[0030] In one specific embodiment, step S1 includes:

[0031] OCR recognition processing is performed on customs document images, the images are converted into text sequences and Chinese word segmentation is performed, and the word segmentation sequence is mapped into a text embedding matrix based on the BERT model;

[0032] The text embedding matrix is ​​input into the BiLSTM-CRF sequence labeling model for labeling. The BiLSTM-CRF sequence labeling model contains a bidirectional LSTM layer and a CRF output layer. The label set includes field start position labels, field internal position labels, and non-target field labels. The optimal label sequence is obtained by decoding using the Viterbi algorithm.

[0033] An initial field set is extracted based on the optimal label sequence. Each field in the initial field set includes the field type, text content, and extraction confidence. The extraction confidence is calculated by multiplying the label probabilities of the corresponding words in each field.

[0034] Fields with a confidence level greater than 0.7 are extracted from the initial field set and marked as high-confidence field set. The presence of required fields in the high-confidence field set is counted, and a field missing vector is generated. The vector element value of 0 indicates that the corresponding required field is missing.

[0035] Specifically, the BiLSTM-CRF sequence labeling model consists of a cascaded connection of an input layer, a bidirectional LSTM layer, a fully connected layer, and a CRF output layer. The input layer receives the text embedding matrix. The forward LSTM layer scans the word sequence from left to right to capture historical context information, while the backward LSTM layer scans from right to left to capture future context information. The hidden state vectors from both directions are concatenated at each time step to form a bidirectional context representation. The hidden layer dimension is set to 256, resulting in a 512-dimensional feature vector after concatenation. The fully connected layer maps the 512-dimensional feature vector to the label space dimension, outputting the original score for each word corresponding to 17 label types. The CRF output layer introduces a label transition matrix to model the transition probability of the label sequence. The elements of this transition matrix represent the probability of transitioning from one label to the next. The legality of the output label sequence is ensured by restricting unreasonable label transition combinations; for example, internal position labels within a field cannot appear directly at the beginning of the sequence, and internal position labels within the same field must follow the starting position label of that field. The model training employs the log-likelihood loss function of a conditional random field, using supervised learning on a labeled customs document training set. The Adam optimizer is used to update model parameters, with a learning rate of 0.001, a batch size of 32, and 50 training epochs. During the decoding phase, the Viterbi algorithm calculates the path to the highest-scoring label sequence globally based on the label scores output from the fully connected layer and the transition matrix of the CRF layer through dynamic programming. The label probability of each word is represented by its normalized score in the optimal path. The extraction confidence of a field is obtained by multiplying the label probabilities of all words within that field; a larger multiplication value indicates higher reliability for that field extraction.

[0036] Figure 2 This is a schematic diagram of the BiLSTM-CRF sequence annotation model structure in the embodiments of this application; Figure 2The hierarchical structure of the BiLSTM-CRF sequence labeling model in this embodiment is shown. The model consists of five layers connected sequentially. The input layer receives a text embedding matrix, generated by the BERT model encoding the word segmentation sequence, with each word corresponding to a 768-dimensional vector. The bidirectional LSTM layer contains two sub-layers: a forward LSTM and a backward LSTM, scanning the word sequence from left to right and from right to left, respectively. The hidden layer dimension is set to 256, and the hidden states in both directions are concatenated at each time step to form a 512-dimensional bidirectional context representation vector. The fully connected layer maps the 512-dimensional feature vector to a 17-dimensional label space, corresponding to 17 label types, including the starting position of the product name, the internal position of the product name, the starting position of the HS code, the starting position of the quantity, the starting position of the unit, the starting position of the amount, and the starting position of the country of origin. The CRF output layer introduces a 17×17-dimensional label transition matrix to model the transition probability of the label sequence, restricting unreasonable label transition combinations to ensure the legality of the output label sequence. The Viterbi decoding layer uses a dynamic programming algorithm to calculate the path of the label sequence with the highest global score based on the label score output by the fully connected layer and the transition matrix of the CRF layer, thereby obtaining the optimal label sequence for field extraction.

[0037] In one specific embodiment, similarity matching is performed between the field missing vector and the pre-stored structure type feature vector, including:

[0038] Fifteen typical document structure types and their corresponding feature vectors are retrieved from the customs document structure knowledge base. The value of each dimension of the feature vector represents the historical missing probability of the corresponding required field under each structure type.

[0039] The similarity between the missing field vector and the feature vector of each structural type is calculated based on the weighted cosine similarity formula. The weight factor in the weighted cosine similarity formula is calculated by the overlap between the actual missing field and the field with high missing probability.

[0040] The top 3 structural types with the highest similarity were selected as candidate structures. The corresponding similarity satisfies a decreasing relationship and the highest similarity is greater than 0.6.

[0041] Specifically, the Customs Document Structure Knowledge Base was constructed through statistical analysis of 5,000 annotated documents. For 15 typical structure types, including standard horizontal format, column layout format, and nested table format, the missing frequency of six mandatory fields (commodity name, HS code, quantity, unit, amount, and country of origin) during the OCR recognition and sequence annotation stages was statistically analyzed for each structure. The missing frequency represents the historical missing probability of that field, forming a 6-dimensional feature vector. The weighted cosine similarity formula introduces a weighting factor to adjust the standard cosine similarity. The weighting factor is calculated as 1 plus 0.3 multiplied by the overlap between the actual missing field and the high-missing-probability field. The overlap is determined by traversing the positions with a value of 0 in the missing vector of each field and checking whether the missing probability of the corresponding structural feature vector at the same position is greater than 0.5. The number of positions that meet the condition is divided by the total number of missing fields to obtain the overlap value. A higher overlap indicates that the current document's missing pattern is closer to the typical missing pattern of that structure type, and the weighting factor is increased accordingly, thus increasing the similarity score.

[0042] After calculating 15 similarity values, they are sorted in descending order. The structure types and their corresponding similarities are extracted from the first, second, and third ranked structures. The similarity of the first-ranked structure is checked to see if it exceeds the confidence threshold of 0.6. If it is lower than 0.6, it means that the missing pattern of the current document does not match any of the known structure types in the knowledge base. At this time, no structure inference is performed, and the system directly enters the global search mode. If the similarity of the first-ranked structure meets the requirements, these three candidate structures and their similarities are passed to the subsequent spatial matching verification stage. The candidate structures are further filtered through spatial location information to finally determine the inferred structure type.

[0043] In one specific embodiment, step S2, calculating a comprehensive score by combining the spatial location of the extracted fields with the distribution matching degree of the structural template, includes:

[0044] Extract the normalized spatial coordinates of the fields that have been successfully extracted from the initial field set. The normalized spatial coordinates include the x and y coordinates of the center point of the field bounding box, the width of the bounding box, and the height.

[0045] For each candidate structure, the corresponding field spatial distribution template is read from the customs document structure knowledge base. The field spatial distribution template uses a Gaussian mixture model to represent the expected distribution of each field type on the page.

[0046] Calculate the probability density value of the actual position of each field in the high confidence field set on the corresponding field spatial distribution template, and sum the probability density values ​​of all fields to obtain the matching degree of each candidate structure;

[0047] The comprehensive score of each candidate structure is calculated based on a similarity of 0.6 times and a normalized matching degree of 0.4 times, and the candidate structure with the highest comprehensive score is selected as the inferred structure type.

[0048] Specifically, in the OCR recognition stage, the bounding box coordinates of each text block are saved, including the pixel coordinates of the top left and bottom right corners. For each field in the initial field set, the center point is calculated based on the bounding box of its corresponding text block. The x-coordinate is the average of the pixel values ​​of the left and right boundaries, and the y-coordinate is the average of the pixel values ​​of the top and bottom boundaries. The bounding box width is the pixel difference between the right and left boundaries, and the height is the pixel difference between the bottom and top boundaries. These four values ​​are normalized by dividing them by the total width and total height of the document image. The normalized coordinates and dimensions are both between 0 and 1. The Gaussian mixture model consists of a linear combination of three Gaussian components. Each component is parameterized by a weighting coefficient, a two-dimensional mean vector, and a two-by-two covariance matrix. The mean vector represents the expected position of the field at the center of the page, and the covariance matrix represents the degree of dispersion of the position. The three components correspond to the primary, secondary, and alternative positions of the field in the document, respectively. The probability density value of the coordinate point is calculated by substituting the actual normalized coordinates of the field into the probability density function of the Gaussian mixture model. The larger the value, the more reasonable it is for the field to appear in this position.

[0049] Iterate through all fields in the high-confidence field set. For each candidate structure, read the spatial distribution template corresponding to that field type. Substitute the actual coordinates of the field into the template to calculate the probability density. Sum the probability densities of all fields under that candidate structure to obtain the total matching degree. Normalize the matching degree values ​​of the three candidate structures so that the maximum matching degree corresponds to 1, and scale the others proportionally. The comprehensive score is obtained by multiplying the similarity calculated in step S2 by a weight of 0.6 and adding the normalized matching degree multiplied by a weight of 0.4. The similarity reflects the degree of matching of the missing pattern, and the matching degree reflects the degree of matching of the spatial layout of the extracted fields. Combining the two ensures that the inferred structure type conforms to both the missing features and the spatial features. Compare the comprehensive scores of the three candidate structures and select the one with the highest value as the final inferred structure type. Read the field spatial attention template corresponding to this structure from the knowledge base for subsequent missing field completion.

[0050] In one specific embodiment, step S2, determining the field spatial attention template based on the structure type with the highest overall score, includes:

[0051] Based on the inferred structure type, the field space attention template corresponding to the inferred structure type is read from the customs document structure knowledge base. The field space attention template contains a probability density heatmap of each required field type at each position on the page. The heatmap values ​​range from 0 to 1, representing the probability of each required field appearing at the corresponding position.

[0052] Specifically, the field spatial attention template is stored in the form of a two-dimensional matrix. The number of rows and columns of the matrix corresponds to the number of grids after the document page is normalized. Each grid cell stores the probability density value of the field type appearing at this position. A value of 0 indicates that the field will almost never appear at this position, a value of 1 indicates that the field is very likely to appear at this position, and intermediate values ​​represent different degrees of probability of occurrence. The heatmap is generated by statistically analyzing the distribution density of the actual positions of each field in the historical samples of this structure type. The statistically obtained position frequencies are normalized and filled into the corresponding grids to form a probability heatmap. Independent heatmaps are generated for the six required fields: product name, HS code, quantity, unit, amount, and country of origin. When filling in missing fields, the corresponding heatmap is read according to the field type to guide the spatial filtering of candidate text blocks.

[0053] In one specific embodiment, step S3 includes:

[0054] For missing required fields, the corresponding probability distribution heatmap is read from the field space attention template. The response value of the center point of each text block saved in the OCR recognition stage on the heatmap is calculated. Text blocks with response values ​​greater than 0.5 are selected to form a candidate text block set.

[0055] The field type of each text block in the candidate text block set is determined, the format matching degree is calculated based on regular expression matching, and the semantic matching degree is calculated based on the pre-trained entity recognition model or BERT vector cosine similarity.

[0056] The completion score of each candidate text block is calculated based on 0.3 times the spatial response value, 0.4 times the format matching degree, and 0.3 times the semantic matching degree. The text block with the highest completion score is selected as the completion content of the missing field, and a completion field containing the field type, text content, and completion score is generated.

[0057] Specifically, the required field types with a missing element value of 0 are identified by traversing the field missing vector. The probability heatmap matrix corresponding to the field is extracted from the field spatial attention template. The set of text blocks saved in the OCR recognition stage contains all the recognized text regions in the document and their bounding box coordinates. After calculating the normalized coordinates of the center point of the bounding box of each text block, the grid position of the center point in the heatmap matrix is ​​determined according to the coordinate value. The probability density value stored in the grid is read as the spatial response value. The response value reflects the probability that the text block is located in the typical occurrence position of the missing field. A screening threshold of 0.5 is set to filter out text blocks with low response values, and text blocks with response values ​​exceeding the threshold are retained to form a candidate set. The format matching score uses different discrimination rules for different field types. The HS encoding field uses regular expressions to match 4 to 10 consecutive digits. If there is a complete match, the format matching score is assigned 1; otherwise, it is assigned 0. The quantity field uses regular expressions to match the combination of numbers and decimal points and detects whether there are unit words within a 5-pixel range around the text block. If unit words are found, the format matching score is assigned 0.9; otherwise, it is assigned 0.7. The country of origin field inputs the text block into a country / region entity recognition model based on the RoBERTa architecture. The model outputs the probability that the text belongs to a geographical location entity as the format matching score.

[0058] Semantic matching is calculated by inputting candidate text blocks into a BERT model and encoding them as 768-dimensional vectors. The prototype vector corresponding to the field type is read from a pre-built field prototype vector library. The prototype vector is generated by averaging 100 standard samples of that field type after BERT encoding. The cosine similarity value, calculated by dividing the dot product of the candidate text vector and the prototype vector by the product of their magnitudes, is used as the semantic matching score. A value closer to 1 indicates a greater similarity between the candidate text's semantic features and the typical features of that field type. The completion score is calculated by summing the spatial response value multiplied by a weight of 0.3, the format matching score multiplied by a weight of 0.4, and the semantic matching score multiplied by a weight of 0.3. The weight allocation reflects that format conformity is more important than spatial location and semantic features. The completion score is calculated for each text block in the candidate text block set. The text block with the highest score is selected, and its text content is extracted as the completion value for the missing field. The field type, completed text content, and completion score are encapsulated into a completion field data structure and added to the field set.

[0059] In one specific embodiment, step S4 includes:

[0060] Construct a semantic association graph by using the initial field set and the completed field as nodes, and establish semantic consistency constraint edges between product name and HS code, numerical logic constraint edges between quantity, unit and amount, trade agreement constraint edges between country of origin and tax rate, and rule constraint edges between consignee and trade method and supervision method.

[0061] The relationship distance between the commodity name vector and the HS code vector is calculated based on the pre-built customs commodity knowledge graph. When the relationship probability is less than 0.15, the constraint edge is marked as violated. The implicit unit price deviation of quantity and amount is calculated based on the historical average unit price and standard deviation. When the deviation exceeds 2.5 times the standard deviation, the constraint edge is marked as violated.

[0062] The field node with the lowest confidence level that participates in the constraint violation edge is selected as the re-extraction target. For missing product names, the modifiers are expanded in the context through dependency parsing. For HS encoding errors, candidate codes are calculated through knowledge graph relation vectors and corrected by keyword matching in the original text.

[0063] Re-execute constraint validation on the corrected fields. Terminate the iteration when the number of constraint violations decreases or the number of iterations reaches 3, and output the target field set.

[0064] Specifically, the semantic association graph uses each field in the initial field set and the complete field set as nodes. Directed constraint edges are established between nodes based on business logic. An edge from the product name node to the HS code node indicates that both must satisfy product classification consistency. Triangular constraint edges between the quantity node, unit node, and amount node indicate that the three must satisfy numerical calculation relationships. An edge from the country of origin node to the tax rate node indicates that the country of origin and the declared tax rate must comply with trade agreements. An edge from the consignee node to the trade method node and the regulatory method node indicates that the enterprise nature and trade type must match regulatory rules. The customs commodity knowledge graph uses the TransE algorithm to embed commodity descriptions and HS codes into a 128-dimensional vector space. The product name vector plus the relation vector should be close to the corresponding HS code vector. The Euclidean distance between the product name vector plus the relation vector and the HS code vector is calculated, and the distance is converted into relation probability using an exponential function. When the probability is below a threshold of 0.15, semantic inconsistency is determined, and the edge is marked as violated.

[0065] Numerical logic constraints obtain the average unit price and standard deviation under the current HS code by querying the historical database. The implicit unit price is calculated by dividing the amount by the quantity. The deviation is calculated by subtracting the average unit price from the implicit unit price, taking the absolute value, and then dividing it by the standard deviation. If the deviation exceeds 2.5 times the standard deviation, it indicates that there is an identification error in the quantity or amount, and the edge is marked as violated. Violation markers of all constraint edges are counted. When the number of violations reaches two or more, re-extraction is triggered. The field nodes of the violating edges are traversed, and the one with the lowest confidence is selected as the re-extraction target. If the target is the product name, the dependency parsing model is used to search for words with a nodal-head relationship or a parallel relationship within 10 words before and after the original extraction position. The modifiers are concatenated to the original product name to form an extended description, and the relationship probability with the HS code is recalculated. If the target is the HS code, the target code embedding is calculated through the knowledge graph relation vector. The three candidate codes with the closest Euclidean distance are searched in the HS code space. The string form of the candidate codes is used as keywords for exact matching in the original text. If a match is successful, the original extraction result is replaced with the matching code.

[0066] After the correction is completed, the semantic association graph is reconstructed to calculate the new number of constraint violations. If the number of violations decreases, the remaining violating fields are corrected iteratively. If the number of violations does not decrease or the number of iterations reaches 3, the iteration is terminated, and the current field set is output as the final target field set.

[0067] Figure 3 This is a schematic diagram comparing the field extraction accuracy of different methods on different document formats in the embodiments of this application; Figure 3This paper presents a comparison of the field extraction accuracy of the method in this application with existing methods on customs documents of different formats. The horizontal axis represents four different extraction methods: rule-based extraction, sequence labeling-based unstructured inference, sequence labeling combined with structure inference, and the method of this invention (including constraint verification). The vertical axis represents the percentage of field extraction accuracy. The bar charts with three different fill patterns represent three types of test data: standard format documents, variable format documents, and complex format documents. The charts show that the rule-based extraction method achieves an accuracy of 72% on standard format documents, but its accuracy drops to 45% and 38% on variable and complex format documents, respectively, demonstrating its sensitivity to format changes. The sequence labeling-based unstructured inference method achieves 85% accuracy on standard format documents, but only 55% accuracy on complex format documents. The sequence labeling-based structure inference method, by introducing a field missing pattern and structure type matching mechanism, improves the accuracy to 78% and 72% on variable and complex format documents, respectively. The method of this invention, by further combining the constraint verification and iterative correction mechanism of cross-field semantic association graph, achieves an accuracy of 93%, 87%, and 83% on standard format, variable format, and complex format documents, respectively. Compared with the unstructured inference method of sequence labeling, it improves the accuracy of variable format documents by 25 percentage points, verifying the effectiveness of the structure inference based on missing patterns and the constraint violation feedback correction mechanism.

[0068] The above describes the NLP-based target feature extraction method for customs document text in the embodiments of this application. The following describes the NLP-based target feature extraction system for customs document text in the embodiments of this application. One embodiment of the NLP-based target feature extraction system for customs document text in the embodiments of this application includes:

[0069] The generation module is used to perform sequence labeling on customs document text, obtain an initial field set and the extraction confidence of each field, and generate a field missing vector based on the presence of required fields in high-confidence fields;

[0070] The matching module is used to perform similarity matching between the missing field vector and the pre-stored structure type feature vector, calculate the comprehensive score by combining the spatial location of the extracted field with the distribution matching degree of the structure template, and determine the field spatial attention template by the structure type with the highest comprehensive score.

[0071] The weighting module is used to filter candidate text blocks based on the probability distribution heatmap of missing fields in the field spatial attention template, calculate a weighted completion score of spatial response value, format matching degree and semantic matching degree for the candidate text blocks, and generate a completion field from the text block with the highest completion score.

[0072] The correction module is used to construct a semantic association graph by combining the initial field set with the completed fields, embedding constraint violation markers between fields based on the knowledge graph, performing context expansion or keyword correction on the field node with the lowest confidence according to the constraint violation type, and outputting the target field set after iterative verification.

[0073] The above embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit it. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A method for extracting target features of customs document text based on NLP, characterized in that, The method comprises: Step S1: sequence labeling processing is performed on the customs document text to obtain an initial field set and extraction confidence of each field, and a field missing vector is generated according to the presence of mandatory fields in high-confidence fields; Step S2: similarity matching is performed between the field missing vector and a pre-stored structure type feature vector, and a comprehensive score is calculated by combining the spatial position of the extracted field and the distribution matching degree of the structure template, and the field spatial attention template is determined according to the structure type with the highest comprehensive score; Step S3: candidate text blocks are screened according to the probability distribution heat map of missing fields in the field spatial attention template, a weighted completion score of spatial response value, format matching degree and semantic matching degree is calculated for the candidate text blocks, and a completion field is generated from the text block with the highest completion score; Step S4: the initial field set and the completion field are constructed into a semantic association graph, a constraint violation label between fields is calculated based on knowledge graph embedding, the field node with the lowest confidence is contextually expanded or keyword corrected according to the constraint violation type, and the target field set is output after iterative verification.

2. The NLP-based customs document text target feature extraction method according to claim 1, characterized in that, The step S1 comprises: An OCR recognition process is performed on the customs document image to convert the image into a text sequence and perform Chinese word segmentation, and the segmented sequence is mapped into a text embedding matrix based on a BERT model; The text embedding matrix is input into a BiLSTM-CRF sequence labeling model for labeling, the BiLSTM-CRF sequence labeling model comprises a bidirectional LSTM layer and a CRF output layer, the labeling label set comprises a field start position label, a field internal position label and a non-target field label, and the optimal label sequence is obtained by decoding through a Viterbi algorithm; An initial field set is extracted according to the optimal label sequence, each field in the initial field set comprises a field type, text content and extraction confidence, and the extraction confidence is calculated by multiplying the label probabilities of the corresponding words of each field; Fields with an extraction confidence greater than 0.7 in the initial field set are marked as a high-confidence field set, the presence of a mandatory field set in the high-confidence field set is counted, and a field missing vector is generated, with a value of 0 indicating that the corresponding mandatory field is missing.

3. The NLP based customs document text target feature extraction method according to claim 1, wherein, In the step S2, the similarity matching between the field missing vector and the pre-stored structure type feature vector comprises: 15 typical document structure types and corresponding feature vectors are read from a customs document structure knowledge base, and each dimension value of the feature vector represents the historical missing probability of the corresponding mandatory field under each structure type; The similarity between the field missing vector and each structure type feature vector is calculated based on a weighted cosine similarity formula, and the weight factor in the weighted cosine similarity formula is calculated by the coincidence degree of the actual missing field and the high missing probability field; The top 3 structure types with the highest similarity are selected as candidate structures, and the corresponding similarity satisfies a decreasing relationship and the highest similarity is greater than 0.

6.

4. The NLP-based customs document text target feature extraction method according to claim 3, characterized in that, In the step S2, the comprehensive score is calculated by combining the spatial position of the extracted field and the distribution matching degree of the structure template, which comprises: extract normalized spatial coordinates of successfully extracted fields in the initial field set, the normalized spatial coordinates including horizontal and vertical coordinates of a field bounding box center point, a bounding box width and a height; read a corresponding field spatial distribution template from the customs document structure knowledge base for each candidate structure, the field spatial distribution template representing an expected position distribution of each field type on the page using a Gaussian mixture model; calculate a probability density value of an actual position of each field in the high-confidence field set on the corresponding field spatial distribution template, and sum the probability density values of all fields to obtain a matching degree of each candidate structure; calculate a comprehensive score of each candidate structure based on 0.6 times the similarity and 0.4 times the normalized matching degree, and select the candidate structure with the highest comprehensive score as the inferred structure type.

5. The NLP based customs document text target feature extraction method according to claim 4, wherein, In the step S2, the field spatial attention template is determined from the structure type with the highest comprehensive score, including: reading a field spatial attention template corresponding to the inferred structure type from the customs document structure knowledge base according to the inferred structure type, the field spatial attention template including a probability density heat map of each mandatory field type at each position on the page, the heat map value ranging from 0 to 1, indicating the probability of occurrence of each mandatory field at the corresponding position.

6. The NLP based customs document text target feature extraction method according to claim 1, wherein, The step S3 includes: reading a corresponding probability distribution heat map from the field spatial attention template for the missing mandatory field, calculating a response value of each text block center point saved in the OCR recognition stage on the heat map, and screening text blocks with a response value greater than 0.5 to form a candidate text block set; performing field type discrimination on each text block in the candidate text block set, calculating a format matching degree based on regular expression matching, and calculating a semantic matching degree based on a pre-trained entity recognition model or BERT vector cosine similarity; calculating a completion score of each candidate text block based on 0.3 times the spatial response value, 0.4 times the format matching degree, and 0.3 times the semantic matching degree, selecting the text block with the highest completion score as the completion content of the missing field, and generating a completion field containing the field type, the text content, and the completion score.

7. The NLP based customs document text target feature extraction method according to claim 1, wherein, The step S4 includes: building a semantic association graph with the initial field set and the completion field as nodes, establishing semantic consistency constraint edges between the commodity name and the HS code, numerical logic constraint edges between the quantity unit and the amount, trade agreement constraint edges between the place of origin and the tax rate, and rule constraint edges between the consignee and the trade mode supervision mode; calculating the relationship distance between the commodity name vector and the HS code vector based on the pre-built customs commodity knowledge graph, marking the constraint edge as violated when the relationship probability is less than 0.15, and calculating the implied unit price deviation of the quantity and the amount based on the historical average unit price and the standard deviation, marking the constraint edge as violated when the deviation exceeds 2.5 times the standard deviation; selecting the field node with the lowest confidence participating in the violated constraint edge as the re-extraction target, expanding the modifying components in the context through dependency syntax analysis for the commodity name missing, and calculating candidate codes through knowledge graph relationship vectors and correcting keywords in the original text for the HS code error; Re-execute constraint verification on the modified field, terminate iteration when the number of constraint violations decreases or the number of iterations reaches 3, and output the target field set.

8. A system for NLP based extraction of target features from customs document text, characterized in that, The NLP-based customs document text target feature extraction system for implementing the method according to any one of claims 1-7 comprises: A generation module configured to perform sequence labeling processing on the customs document text to obtain an initial field set and an extraction confidence of each field, and generate a field missing vector according to the presence of a mandatory field in a high-confidence field; A matching module configured to perform similarity matching of the field missing vector and a pre-stored structure type feature vector, and calculate a comprehensive score in combination with a distribution matching degree of a spatial position of the extracted field and the structure template, so as to determine a field spatial attention template from a structure type with the highest comprehensive score; A weighting module configured to filter candidate text blocks according to a probability distribution heat map of missing fields in the field spatial attention template, calculate a weighted completion score of a spatial response value, a format matching degree and a semantic matching degree for the candidate text blocks, and generate a completion field from a text block with the highest completion score; A correction module configured to construct the initial field set and the completion field into a semantic association graph, calculate a constraint violation label between fields based on knowledge graph embedding, perform context expansion or keyword correction on a field node with the lowest confidence according to a constraint violation type, and output a target field set after iterative verification.

9. The system of claim 8, wherein, The customs document text is subjected to sequence labeling processing to obtain an initial field set and an extraction confidence of each field, and a field missing vector is generated according to the presence of a mandatory field in a high-confidence field, including: The customs document image is subjected to OCR recognition processing to convert the image into a text sequence and perform Chinese word segmentation, and the segmented sequence is mapped into a text embedding matrix based on a BERT model; The text embedding matrix is input into a BiLSTM-CRF sequence labeling model for labeling, the BiLSTM-CRF sequence labeling model comprises a bidirectional LSTM layer and a CRF output layer, a labeling label set comprises a field start position label, a field internal position label and a non-target field label, and an optimal label sequence is obtained by decoding through a Viterbi algorithm; An initial field set is extracted according to the optimal label sequence, each field in the initial field set comprises a field type, a text content and an extraction confidence, and the extraction confidence is calculated by multiplying the label probabilities of the corresponding words of each field; Fields with an extraction confidence greater than 0.7 in the initial field set are marked as a high-confidence field set, the presence of a mandatory field set in the high-confidence field set is counted, and a field missing vector is generated, with a value of 0 indicating that the corresponding mandatory field is missing.

10. The system of claim 8, wherein, The candidate text blocks are filtered according to the probability distribution heat map of missing fields in the field spatial attention template, a weighted completion score of a spatial response value, a format matching degree and a semantic matching degree is calculated for the candidate text blocks, and a completion field is generated from a text block with the highest completion score. reading a corresponding probability distribution heat map from the field space attention template for the missing mandatory field, calculating a response value of each text block center point saved in the OCR recognition stage on the heat map, and screening text blocks with a response value greater than 0.5 to form a candidate text block set; performing field type discrimination on each text block in the candidate text block set, calculating a format matching degree based on regular expression matching, and calculating a semantic matching degree based on a pre-trained entity recognition model or BERT vector cosine similarity; calculating a completion score of each candidate text block based on 0.3 times the spatial response value, 0.4 times the format matching degree, and 0.3 times the semantic matching degree, selecting a text block with the highest completion score as the completion content of the missing field, and generating a completion field containing the field type, the text content, and the completion score.

Citation Information

Patent Citations

  • Financial data intelligent entry and verification method

    CN120449835A

  • Intelligent identification and import method for building industry communication project contract scanning copy

    CN120671651A

  • Method and system for extracting credible evidence of document based on large model

    CN120783359A

  • Visual data extraction method based on medical information system

    CN121117093A

  • Excel data intelligent import method and system based on dynamic mapping

    CN121212099A