NLP-based customs document text target feature extraction method and system
By employing an adaptive completion strategy and a cross-field semantic association constraint mechanism, the problems of missing fields and logical inconsistencies under the diverse formats of customs documents were resolved, thereby improving the accuracy and consistency of field extraction.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- TIANJIN YITAI TECHNOLOGY DEVELOPMENT CO LTD
- Filing Date
- 2026-01-26
- Publication Date
- 2026-05-05
AI Technical Summary
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.
By transforming missing field patterns into document structure diagnostic features, and employing an adaptive completion strategy and a violation feedback mechanism for cross-field semantic association constraints, adaptive field extraction and logical consistency correction are achieved.
It improves the accuracy and logical consistency of field extraction for customs documents with varying and complex formats, and significantly reduces the problems of incorrect and missing completion.
Smart Images

Figure CN121579993B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing technology, and in particular to a method and system for extracting target features from customs document text based on NLP. Background Technology
[0002] Customs document text feature extraction is a key technical step in customs clearance automation, involving the automatic identification and extraction of key business fields such as commodity name, HS code, quantity, unit, amount, and country of origin from unstructured or semi-structured text documents such as customs declarations, commercial invoices, packing lists, and bills of lading. Existing natural language processing-based customs document feature extraction methods primarily employ sequence labeling models to annotate text fields, using deep learning models such as BiLSTM-CRF to map segmented text sequences into label sequences, thereby extracting various business fields. These methods train sequence labeling models on large-scale labeled data, enabling the models to learn contextual features and boundary recognition patterns of fields, achieving high extraction accuracy on standard format documents and providing fundamental data support for automated customs review.
[0003] However, customs documents exhibit a high degree of diversity in format. Documents from different countries, companies, and business types vary significantly in layout, field order, and table nesting structures. This leads to insufficient generalization ability of sequence labeling models trained on fixed training sets when faced with new document formats, resulting in a substantial drop in field extraction accuracy. In particular, under non-standard formats such as column layouts and table nesting, the missing rate of key fields can reach 30% to 50%. Secondly, existing methods extract each field as an independent target, lacking modeling of the business logic relationships between fields. They cannot utilize knowledge in areas such as the semantic consistency between product names and HS codes, the numerical logical relationship between quantity, unit, and amount, and the trade agreement matching between country of origin and tax rate for cross-validation. Consequently, even if the confidence level of a single field extraction is high, erroneous results may still occur due to contradictory business logic in field combinations. Such logical errors cannot be automatically detected and corrected before manual review. Summary of the Invention
[0004] This application provides a method and system for extracting target features from customs document text based on NLP. It solves the technical problems of existing customs document feature extraction methods, such as the inability to effectively complete missing fields when faced with documents with diverse formats, and the lack of logical consistency verification between extracted fields, which leads to the inability to automatically correct erroneous results. By transforming the field missing pattern into document structure diagnostic features to realize an adaptive completion strategy, and by realizing targeted iterative correction through the violation feedback mechanism of cross-field semantic association constraints, the accuracy and logical consistency of field extraction for customs documents with varying and complex formats are improved.
[0005] Firstly, this application provides a method for extracting target features from customs document text based on NLP, the method comprising:
[0006] 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;
[0007] 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, and determine the field spatial attention template from the structure type with the highest comprehensive score;
[0008] Step S3: Filter candidate text blocks according to 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;
[0009] Step S4: Construct a semantic association graph by combining the initial field set with the completed fields. Based on the knowledge graph embedding, calculate the constraint violation markers between 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.
[0010] Secondly, this application provides a NLP-based system for extracting target features from customs document text, the NLP-based system for extracting target features from customs document text comprising:
[0011] 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;
[0012] 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.
[0013] 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.
[0014] 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.
[0015] The technical solution provided in this application obtains an initial set of fields and the extraction confidence of each field by performing sequence annotation processing on customs document text. It then generates a field missing vector based on the presence of required fields in high-confidence fields. This achieves a cognitive transformation from extraction failure to structural diagnostic features, making field missing no longer merely a defect marker in the extraction result, but a quantitative input reflecting the document's layout and structural features, laying a data foundation for subsequent structure-aware adaptive extraction strategies. By matching the field missing vector with pre-stored structural type feature vectors based on similarity, and calculating a comprehensive score by combining the spatial location of extracted fields with the distribution matching degree of structural templates, the structural type with the highest comprehensive score determines the field spatial attention template. This realizes a reverse inference mechanism from missing patterns to document structural types, solving the problem of insufficient generalization ability caused by the lack of prior structural knowledge and the use of fixed extraction strategies when facing documents with diverse formats in existing technologies. This allows the extraction system to dynamically adjust the spatial distribution assumptions of field searches based on the actual layout and structure of the document, transforming blind global searches into targeted regional searches. Candidate text blocks are selected based on the probability distribution heatmap 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. The text block with the highest completion score generates the completion field. Through a three-dimensional comprehensive evaluation mechanism of spatial prior, format specification and semantic features, the accuracy and reliability of missing field completion are significantly improved, avoiding the problems of false completion and omission caused by existing technologies that rely solely on keyword matching or single position heuristic methods. Attached Figure Description
[0016] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0017] Figure 1 This is a schematic diagram of an embodiment of the NLP-based target feature extraction method for customs document text in this application.
[0018] Figure 2 This is a schematic diagram of the BiLSTM-CRF sequence annotation model structure in the embodiments of this 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 from customs document text based on NLP, characterized in that, The method includes: 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; 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, and determine the field spatial attention template from the structure type with the highest comprehensive score; Step S3: Filter candidate text blocks according to 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; Step S4: Construct a semantic association graph using the initial field set and the completed fields. Calculate constraint violation markers between fields based on knowledge graph embedding. Perform context expansion or keyword correction on the field node with the lowest confidence level according to the constraint violation type. After iterative verification, output the target field set, including: constructing a semantic association graph using the initial field set and the completed fields as nodes; establishing semantic consistency constraint edges between commodity 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 / regulatory method; and calculating the commodity name vector and HS code based on the pre-constructed customs commodity knowledge graph. The relationship distance of the S-encoded vector is used to mark constraint edge violations when the relationship probability is below 0.
15. 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 a violation. The field node with the lowest confidence among the violation edges 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 using knowledge graph relationship vectors and corrected by keyword matching in the original text. The constraint verification is re-executed on the corrected fields. The iteration is terminated when the number of constraint violations decreases or the number of iterations reaches 3, and the target field set is output.
2. The method for extracting target features from customs document text based on NLP according to claim 1, characterized in that, Step S1 includes: 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; The text embedding matrix is input into the BiLSTM-CRF sequence labeling model for labeling. The BiLSTM-CRF sequence labeling model includes 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. An initial field set is extracted based on the optimal label sequence. Each field in the initial field set includes a field type, text content, and extraction confidence. The extraction confidence is calculated by multiplying the label probabilities of the corresponding words in each field. 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 value of each element in the vector is 0, which indicates that the corresponding required field is missing.
3. The method for extracting target features from customs document text based on NLP according to claim 1, characterized in that, In step S2, the similarity matching between the missing field vector and the pre-stored structural type feature vector includes: 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. The similarity between the missing vector of the field 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 obtained by calculating the overlap between the actual missing field and the field with high missing probability. 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.
4. The method for extracting target features from customs document text based on NLP according to claim 3, characterized in that, In step S2, the calculation of the comprehensive score by combining the spatial location of the extracted fields with the distribution matching degree of the structural template includes: Extract the normalized spatial coordinates of the fields that have been successfully extracted from the initial field set. The normalized spatial coordinates include the horizontal and vertical coordinates of the center point of the field bounding box, the width of the bounding box, and the height. 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. 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; 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.
5. The NLP-based method for extracting target features from customs document text according to claim 4, characterized in that, In step S2, determining the field spatial attention template from the structure type with the highest comprehensive score includes: 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.
6. The method for extracting target features from customs document text based on NLP according to claim 1, characterized in that, Step S3 includes: For the 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. For each text block in the candidate text block set, the field type 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. 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.
7. A NLP-based system for extracting target features from customs document text, characterized in that, For implementing the NLP-based target feature extraction method for customs document text as described in any one of claims 1-6, the NLP-based target feature extraction system for customs document text comprises: 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; 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. 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. The correction module is used to construct a semantic association graph by combining the initial field set and the completed fields. It calculates constraint violation markers between fields based on knowledge graph embedding, and performs context expansion or keyword correction on the field node with the lowest confidence level according to the constraint violation type. After iterative verification, it outputs the target field set, including: constructing a semantic association graph using the initial field set and the completed fields as nodes; establishing semantic consistency constraint edges between commodity 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 / regulatory method; and calculating the commodity name vector and its relation to the pre-constructed customs commodity knowledge graph. The relation distance of the HS encoding vector is used to mark constraint edge violations when the relation probability is below 0.
15. 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 a violation. The field node with the lowest confidence among the violation edges 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 using knowledge graph relation vectors and corrected by keyword matching in the original text. The constraint verification is re-executed on the corrected fields. The iteration is terminated when the number of constraint violations decreases or the number of iterations reaches 3, and the target field set is output.
8. The system according to claim 7, characterized in that, Sequence labeling is performed on the customs document text to obtain an initial field set and the extraction confidence of each field. A field missing vector is generated based on the presence of required fields in high-confidence fields, including: 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; The text embedding matrix is input into the BiLSTM-CRF sequence labeling model for labeling. The BiLSTM-CRF sequence labeling model includes 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. An initial field set is extracted based on the optimal label sequence. Each field in the initial field set includes a field type, text content, and extraction confidence. The extraction confidence is calculated by multiplying the label probabilities of the corresponding words in each field. 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 value of each element in the vector is 0, which indicates that the corresponding required field is missing.
9. The system according to claim 8, characterized in that, Candidate text blocks are selected based on the probability distribution heatmap of missing fields in the field spatial attention template. A weighted completion score is calculated for each candidate text block, considering spatial response value, format matching degree, and semantic matching degree. The text block with the highest completion score generates completion fields, including: For the 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. For each text block in the candidate text block set, the field type 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. 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.
Citation Information
Patent Citations
Financial data intelligent entry and verification method
CN120449835A