How to fill in the customs declaration form
By combining semantic recognition model and OCR technology, the text content in the customs declaration form is extracted and standardized, and the problem of low accuracy of single AI extraction is solved, efficient and accurate filling of customs declaration form is achieved, and manual re-inspection time is reduced.
Patent Information
- Application Number
- CN202410164013.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-02-05
- Publication Date
- 2024-12-06
- Estimated Expiration
- 2044-02-05
AI Technical Summary
In the existing customs declaration form filling method, the accuracy of the single AI extraction function is not high, resulting in low overall work efficiency, unable to significantly improve the accuracy of the extraction, and requires manual re-inspection, which is time-consuming and labor-consuming.
By obtaining blank customs declaration forms and sample files, selecting the extraction method based on file type, combining semantic recognition model and OCR technology, text content is extracted, and standardized processing is carried out through cluster analysis model, and finally the extracted content is compared and filled in the customs declaration form , improve extraction accuracy and efficiency.
It significantly improves the accuracy and efficiency of customs declaration form filling, reduces the time of manual processing, provides high-precision extraction results and alternative solutions, and improves the overall filling efficiency.
Smart Images

Figure CN118692096B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of filling out a customs declaration form, and in particular to a method for filling out a customs declaration form. Background Art
[0002] A customs broker is a domestic corporate entity that is authorized by the customs to register and accept the entrustment of the consignor or consignee of imported or exported goods, and handles the customs declaration business on behalf of the consignor or consignee of imported or exported goods or in its own name, and engages in customs declaration services. A customs broker has two main functions: one is to help goods pass through customs; the other is to handle the necessary documents accompanying international goods. Freight forwarding refers to the business of providing services such as handling transportation procedures, picking up, sending, and transporting goods on behalf of others on behalf of others.
[0003] Existing customs brokers, freight forwarders and customers can only extract the required content from customs declarations, bills of lading and other documents through manual entry or single AI recognition technology. However, manual entry is too time-consuming and labor-intensive, and the accuracy of single AI extraction is not high, which cannot significantly improve the accuracy of extraction. In addition, the content recognized by single AI still needs to be manually checked from beginning to end, resulting in low overall work efficiency. Summary of the invention
[0004] Based on this, it is necessary to provide a method for filling out customs declaration forms to address the problem that the accuracy of traditional single AI extraction is not high and cannot significantly improve the accuracy of extraction.
[0005] This application provides methods for filling out the customs declaration form, including:
[0006] Obtain each blank customs declaration form and obtain multiple sample files corresponding to each blank customs declaration form, each sample file corresponding to a file type;
[0007] Based on the different file formats of each sample file, select different methods to extract the text content corresponding to each sample file;
[0008] Determine the file type corresponding to each sample file based on the specific text content at the header of the text content corresponding to each sample file;
[0009] Based on the comparison table between file type and content categories to be extracted, at least one content category to be extracted corresponding to each sample file is obtained, and then all content categories to be extracted of the blank customs declaration form are obtained;
[0010] Extracting the associated text content associated with the content category to be extracted from the text content corresponding to each sample file according to the semantic recognition model, and obtaining the first text content corresponding to each content category to be extracted;
[0011] Convert each sample file into a sample image;
[0012] Recognize each sample image according to OCR to obtain the OCR text corresponding to each sample image, extract the associated text content associated with the content category to be extracted from each OCR text through a cluster analysis model, and obtain the second text content corresponding to each content category to be extracted;
[0013] Standardize all first text contents and second text contents extracted from the text contents corresponding to each sample file to obtain first target text contents corresponding to each content category to be extracted and second target text contents corresponding to each content category to be extracted;
[0014] The first target text content corresponding to each content category to be extracted in each sample file is compared with the second target text content, and based on the comparison result, the text content extracted from each sample file is filled into the corresponding position on the blank customs declaration form, and the completed customs declaration form is output.
[0015] The present application relates to a method for filling out a customs declaration form. By performing text extraction on each sample file that needs to fill out the customs declaration form, a text content of each sample file is obtained, and then the file type corresponding to each file is determined, and based on the file type, a content category to be extracted of the file type is obtained; then, the text content corresponding to each sample file is extracted through a plurality of content extractions on the content category to be extracted, and the content of the same content category to be extracted extracted by each method is uniformly standardized and then compared, and based on different mismatch results, the extracted content of the content category to be extracted is filled into the corresponding position on the blank customs declaration form; based on a plurality of high-precision extraction methods, the content of the content category to be extracted in the sample file is extracted and compared, thereby improving the accuracy of the extraction, and at the same time, it can also reduce the time of manual processing and improve the overall filling efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] Figure 1 A flowchart of a method for filling out a customs declaration form provided in one embodiment of the present application.
[0017] Figure 2 A schematic diagram of the classification of sample documents in the method for filling out a customs declaration form provided in an embodiment of the present application.
[0018] Figure 3 A schematic diagram of text extraction from a sample file in a method for filling out a customs declaration provided in an embodiment of the present application.
[0019] Figure 4 A schematic diagram of text content extracted through semantic recognition from a sample file in a method for filling out a customs declaration form provided in an embodiment of the present application.
[0020] Figure 5A schematic diagram of text content extracted by OCR from a sample file in a method for filling out a customs declaration provided in an embodiment of the present application.
[0021] Figure 6 This is a schematic diagram of a blank customs declaration form after preliminary filling in the customs declaration form filling method provided in one embodiment of the present application.
[0022] Figure 7 A schematic diagram of a customs declaration form after manual verification in the customs declaration form filling method provided in one embodiment of the present application. DETAILED DESCRIPTION
[0023] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0024] like Figure 1 As shown, in one embodiment of the present application, the method for filling out the customs declaration form includes the following steps S100 to S700:
[0025] S100, obtaining each blank customs declaration form and obtaining a plurality of sample files corresponding to each blank customs declaration form, wherein each sample file corresponds to a file type.
[0026] In this step, the connection between the content to be filled in each blank customs declaration form and the source of different documents is used to obtain multiple sample files required for filling in each blank customs declaration form. Since different filled-in contents correspond to different file types, each sample file corresponds to a file type. The classification of file types helps to quickly and accurately process sample files.
[0027] S200, based on the different file formats of each sample file, select different methods to extract text content corresponding to each sample file.
[0028] In this step, since the file format of each sample file is different, different extraction methods are used to extract the text content in the sample file accordingly, thereby ensuring the stability of the extracted text.
[0029] S300: Determine the file type corresponding to each sample file based on the specific text content at the header of the text content corresponding to each sample file.
[0030] In this step, after extracting the text content of the sample file, the text content at the header of the sample file is used to determine the file type of the sample file, so as to facilitate classification of the sample files according to the file type.
[0031] S400, based on the file type and to-be-extracted content category comparison table, obtain at least one to-be-extracted content category corresponding to each sample file, and then obtain all to-be-extracted content categories of the blank customs declaration form.
[0032] In this step, by defining the content categories to be extracted for each file type, all the content categories to be extracted are obtained, and all the content categories to be extracted are defined as all the content categories to be extracted in the blank customs declaration.
[0033] S500: extracting the associated text content associated with the content category to be extracted from the text content corresponding to each sample file according to the semantic recognition model, and obtaining the first text content corresponding to each content category to be extracted.
[0034] In this step, the content category to be extracted of each sample file is obtained based on the file type of each sample file, and then the semantic recognition model is used to extract the corresponding content category to be extracted from the text content corresponding to each sample file, and the extracted content of the content category to be extracted is defined as the first text content.
[0035] S600, converts each sample file into a sample image.
[0036] In this step, each sample file is uniformly converted into a sample image format to facilitate subsequent processing using the OCR method.
[0037] S700, identify each sample image based on OCR to obtain the OCR text corresponding to each sample image, extract the associated text content associated with the content category to be extracted from each OCR text through a cluster analysis model, and obtain the second text content corresponding to each content category to be extracted.
[0038] In this step, the content category to be extracted of each sample file is obtained based on the file type of each sample file, and then the OCR model is used to extract the corresponding content category to be extracted from the text content corresponding to each sample file, and the extracted content of the content category to be extracted is defined as the second text content.
[0039] S800, performing standardization processing on all first text contents and second text contents extracted from the text contents corresponding to each sample file to obtain first target text contents corresponding to each content category to be extracted and second target text contents corresponding to each content category to be extracted.
[0040] In this step, the first text content and the second text content extracted from each sample file still have certain format defects, and need to be processed using unified rules to obtain the first target text content corresponding to each content category to be extracted and the second target text content corresponding to each content category to be extracted. The unified processing rules are customized based on the requirements filled in on the customs declaration form, so as to facilitate the smooth import of the content obtained after unified processing into the corresponding position on the customs declaration form.
[0041] S900, compare the first target text content corresponding to each content category to be extracted in each sample file with the second target text content, fill the content extracted from each sample file into the corresponding position on the blank customs declaration form based on the comparison result, and output the completed customs declaration form.
[0042] In this step, based on the same content category to be extracted, the first target text content extracted from the corresponding text content of the sample file is compared with the second target text content, and different operation procedures are performed according to the comparison results. The final result is that the content that needs to be filled in each content category to be extracted on the customs declaration form is filled in with high accuracy. Even if the result of the content category to be extracted is uncertain, multiple reliable alternative results can be obtained to provide convenient options for manual processing, reduce the time of manual processing, and improve the filling efficiency of the entire customs declaration form.
[0043] In one embodiment of the present application, based on the different file formats of each sample file, selecting different methods to extract the text content corresponding to each sample file includes the following S201 to S206:
[0044] S201, obtain a blank customs declaration form.
[0045] S202: Select a sample file from a plurality of sample files corresponding to the blank customs declaration form.
[0046] S203, reading the sample file to obtain the file format of the sample file.
[0047] S204: When the format of the sample file is DOC or EXCEL, extract text information from the sample file to obtain text content corresponding to the sample file.
[0048] S205: When the format of the sample file is PDF or a picture, the sample file is extracted using an OCR method to obtain text content corresponding to the sample file.
[0049] S206, returning to the step of selecting one of the multiple sample files corresponding to the blank customs declaration form until all the multiple sample files corresponding to the blank customs declaration form have been selected once.
[0050] In this embodiment, a blank customs declaration form is first selected to obtain the blank customs declaration form, each sample file in the blank customs declaration form is obtained, a sample file in the blank customs declaration form is selected, and then the file format of the sample file is obtained. The text content corresponding to the sample file is obtained by using a direct text extraction method for a file format of DOC or EXCEL, and the sample file is extracted using an OCR method for a file format of PDF or a picture to obtain the text content corresponding to the sample file, and then a sample file is selected from multiple sample files corresponding to the blank customs declaration form until the multiple sample files corresponding to the blank customs declaration form have been selected once to obtain the text content corresponding to each sample file.
[0051] By preprocessing each sample file by converting it into corresponding text content in the first step, it is convenient to quickly extract the content of each sample file.
[0052] like Figures 2 to 3 As shown, in one embodiment of the present application, determining the file type corresponding to each sample file based on the specific text content at the header of the text content corresponding to each sample file includes the following S301 to S305:
[0053] S301, obtain a blank customs declaration form.
[0054] S302, selecting a sample file from a plurality of sample files corresponding to the blank customs declaration form.
[0055] S303: Read the sample file to obtain text content corresponding to the sample file.
[0056] S304, based on the header part of the text content, obtain the file type of the sample file; the file type includes one or more of a customs declaration, an invoice, a packing list, and a contract.
[0057] S305, returning to the step of selecting one of the multiple sample files corresponding to the blank customs declaration form, until each sample file corresponding to the blank customs declaration form has been selected once, and the file type of each sample file is obtained.
[0058] In this embodiment, a blank customs declaration form is first selected to obtain the blank customs declaration form and obtain multiple sample files corresponding to the blank customs declaration form. Then, a sample file is selected to obtain text content corresponding to the sample file. Character analysis is performed on the header part of the text content corresponding to the file to obtain the file type corresponding to the sample file, wherein the file type includes one or more of a customs declaration form, an invoice, a packing list, and a contract. Then, a sample file is selected from the multiple sample files corresponding to the blank customs declaration form until each sample file corresponding to the blank customs declaration form has been selected once to obtain the file type of each sample file.
[0059] By analyzing the characters at the header of the text corresponding to each sample file, the file type of the sample file is determined and the corresponding file type is classified, which facilitates the same processing of files of this type, shortens the time required for processing all sample files, and improves processing efficiency.
[0060] In one embodiment of the present application, based on the file type and to-be-extracted content category comparison table, obtaining at least one to-be-extracted content category corresponding to each sample file, and then obtaining all to-be-extracted content categories of the blank customs declaration form includes the following S401 to S403:
[0061] S401, select a sample file.
[0062] S402 , using the file type of the sample file as an index, searching a table of file types and to-be-extracted content categories for at least one to-be-extracted content category corresponding to the file type of the sample file.
[0063] S403, returning to the step of selecting a sample file, until all sample files have been selected, and obtaining all content categories to be extracted corresponding to the blank customs declaration form.
[0064] Specifically, a sample file is first selected to obtain the file type corresponding to the sample file, and all the content categories to be extracted that need to be extracted by the file type of the sample file are obtained based on the comparison relationship between the file type of the file and the content category to be extracted, and then a sample file is returned to be selected until all sample files have been selected, thereby obtaining all the content categories to be extracted corresponding to the blank customs declaration form.
[0065] Before S100, the multi-AI automatic identification and comparison method further includes:
[0066] S010, create multiple file types.
[0067] S020, under each file type, create multiple content categories to be extracted.
[0068] S030, creating a file type and to-be-extracted content category comparison table, registering each file type and multiple to-be-extracted content categories corresponding to the file type into the file type and to-be-extracted content category comparison table, the file type and to-be-extracted content category comparison table is shown in Table 1.
[0069] Table 1 - Comparison table between file types and categories of content to be extracted
[0070]
[0071]
[0072] In this embodiment, by obtaining the corresponding content categories to be extracted from all sample files and then removing the repeated parts therein, all the content categories to be extracted are used as all the content categories to be extracted corresponding to the blank customs declaration form.
[0073] like Figure 4 As shown, in one embodiment of the present application, the text content corresponding to each sample file is extracted according to the semantic recognition model, and the first text content corresponding to each content category to be extracted is obtained, including the following S501 to S509:
[0074] S501, select a sample file.
[0075] S502, obtaining text content corresponding to the sample file, and inputting the text content corresponding to the sample file into the BERT model.
[0076] S503, start the BERT model, and control the BERT model to perform sentence processing on the text content of the sample file to obtain multiple sentences.
[0077] S504, calculating the semantic vector of each sentence.
[0078] S505, select a sentence.
[0079] S506, calculating the similarity between the semantic vector of the sentence and the semantic vector of each content category to be extracted, and determining whether there is any semantic vector of the content category to be extracted whose similarity with the semantic vector of the sentence is greater than or equal to a similarity threshold.
[0080] S507: If the similarity between the semantic vector of any content category to be extracted and the semantic vector of the sentence is greater than or equal to the similarity threshold, a mapping relationship is established between the content category to be extracted and the sentence, and the sentence is defined as the first text content corresponding to the content category to be extracted.
[0081] S508, returning to the step of selecting a sentence until all sentences have been selected once.
[0082] S509, returning to the step of selecting a sample file until each sample file has been selected once.
[0083] Specifically, the BERT model is one of the Chinese pre-training models.
[0084] The BERT model needs to be trained in advance. The following is an implementation method for training the BERT model.
[0085] The method for filling out the customs declaration form also includes: training the BERT model.
[0086] The training of the BERT model includes:
[0087] A plurality of training files are obtained, and the method of steps S051 to S056 is applied to each training file to extract text content in the training file.
[0088] S051, select a training file.
[0089] S052, the text content in the training file is processed by sentence segmentation. During the sentence segmentation process, a placeholder is inserted into each sentence, a CLS placeholder is inserted at the beginning of the sentence, and a SEP placeholder is inserted at the end of the sentence.
[0090] S053, returning to select a training file until all training files have been processed by sentence segmentation.
[0091] S054, input the sentence-processed training file as training data into the BERT model, and train the Token Embeddings layer, Segment Embeddings layer, and Position Embedding layer of the BERT model simultaneously. When training the Token Embeddings layer of the BERT model, the Token Embeddings layer is trained using text content with CLS placeholders and SEP placeholders. When training the Segment Embeddings layer of the BERT model, different sentence tags are used for different sentences, all characters are marked, and the Segment Embeddings layer is trained with the entire text content with different sentence tags. For example, all characters contained in the first sentence are marked with KA, and all characters contained in the second sentence are marked with KB. When training the Position Embedding layer of the BERT model, each character is marked with digital tags from small to large according to the order in which each character appears in the text content, and the Segment Embeddings layer is trained with the entire text content with different digital tags. For example, the first sentence at the beginning of the text content has 5 characters, which are marked with 1, 2, 3, 4, and 5 respectively. The second sentence has 3 characters, which are marked with 6, 7, and 8 respectively, and so on. The Token Embeddings layer represents the sentences, the Segment Embeddings layer represents the similarities and differences between the sentences to which the characters belong, and the Position Embedding layer represents the position of the characters in the entire text content.
[0092] S055, generating a vector for each character according to the character content, sentence tag, and digital tag of each character. Look up Table 1 to obtain the content category to be extracted corresponding to the sentence to which the character belongs, and obtain N fuzzy category keywords of the content category to be extracted corresponding to the sentence to which the character belongs.
[0093] S056, input each character, the sentence to which each character belongs, the content category to be extracted corresponding to the sentence to which each character belongs, and N fuzzy category keywords of the content category to be extracted corresponding to the sentence to which each character belongs as training data into the semantic module in the BERT model to obtain the semantic vector corresponding to each character. Set the semantic vector of the content category to be extracted. Training is completed.
[0094] All sentences in this application may also be phrases. This is because some of the text content is not a complete sentence with semantics, but a phrase with semantics.
[0095] Select a sample file, obtain the text content corresponding to the sample file, input the text content corresponding to the sample file into the BERT model, start the BERT model, obtain multiple sentences output by the BERT model, and then calculate the semantic vector of each sentence to obtain the semantic vector corresponding to each sentence.
[0096] When obtaining the semantic vector of a sentence, first calculate the semantic vector of each character.
[0097]
[0098] The score of the semantic vector of the character is calculated according to Formula 1. x is the semantic vector of the character, and Q(x) is the score of the semantic vector of the character.
[0099] The average of the scores of the semantic vectors of all characters in each sentence is calculated to obtain the score of the semantic vector of each sentence.
[0100] The scores of the semantic vectors of the content categories to be extracted are preset.
[0101] The score of the semantic vector of the sentence is divided by the score of the semantic vector of the content category to be extracted, and the result is multiplied by 100% to obtain a percentage, which is used as the similarity.
[0102] The similarity is compared with a preset similarity threshold. If the similarity is greater than or equal to the preset similarity threshold, a mapping relationship is established between the content category to be extracted and the sentence, and the sentence is defined as the first text content corresponding to the content category to be extracted.
[0103] Return to select a sentence until all sentences have been selected once, and obtain a mapping relationship between each sentence and the corresponding content category to be extracted, and return to select a sample file until each sample file has been selected once.
[0104] All sentences in this application can also be phrases or words, because some of the text content is not a complete sentence with semantics, but a phrase or word with semantics. For example, "Destination country (region): Poland" is a phrase or word, not a complete sentence, but it also has semantics.
[0105] In this embodiment, the text content corresponding to each sample file is divided into multiple sentences, and a semantic vector is calculated for each sentence. By judging whether the similarity between the semantic vector of each sentence and the semantic vector of each content category to be extracted is greater than or equal to a set threshold, a mapping relationship between the content category to be extracted and the sentence is obtained, and then the sentence corresponding to the content category to be extracted is determined to be the first text content.
[0106] like Figure 5 As shown, in one embodiment of the present application, each sample image is identified according to OCR to obtain OCR text corresponding to each sample image, and the associated text content associated with the content category to be extracted is extracted from each OCR text through a cluster analysis model to obtain the second text content corresponding to each content category to be extracted, including the following S701 to S711:
[0107] S701, select a sample file.
[0108] S702: Obtain a sample image corresponding to the sample file.
[0109] S703: Use an OCR method to convert the sample image into an OCR text corresponding to the sample image.
[0110] S704, performing content positioning on the OCR text to obtain the coordinates of each character.
[0111] S705, clustering the characters according to their semantic information, and dividing all the characters into different blocks.
[0112] S706, selecting a block.
[0113] S707, inputting the center point coordinates and text type of the block into the block definition model.
[0114] S708 , starting the block definition model, and outputting the content category to be extracted corresponding to the center point coordinates of the block.
[0115] S709: define all text contents in the block as second text contents corresponding to the content category to be extracted.
[0116] S710, returning to the step of selecting a block until all blocks are selected once.
[0117] S711, returning to the step of selecting a sample file until each sample file has been selected once.
[0118] In this embodiment, a sample file is first selected to obtain a sample image corresponding to the sample file, the sample image is converted into a corresponding OCR text using an OCR method, and then each character in the OCR text is located to obtain the coordinates of each character in the OCR text; then, the characters are clustered according to their semantic information, all the characters are divided into different blocks, one of the blocks is selected to obtain the center point coordinates of the block, the center point coordinates and the text type are input into a block definition model, and the block definition model is started to output the content category to be extracted corresponding to the center point coordinates of the block, and all the text content in the obtained block is defined as the second text content corresponding to the content category to be extracted.
[0119] Returns selecting a block until all differences have been selected once. Returns selecting a sample file until each sample file has been selected once.
[0120] Specifically,
[0121] The OCR model recognizes the text in the image and outputs it in the form of text.
[0122] The use of the OCR model needs to be trained in advance. The following introduces an implementation method of the OCR model training method.
[0123] The method for filling out the customs declaration form also includes: training the OCR model.
[0124] The training of the OCR model includes:
[0125] A plurality of training images are obtained, and the method of steps SX001 to SX014 is adopted for each training image to extract text content in the training image.
[0126] X001, select a training image.
[0127] X002, binarize the training image to obtain a binarized image corresponding to the training image.
[0128] X003, perform noise reduction processing on the binarized image to obtain a noise-reduced image corresponding to the binarized image.
[0129] X004, performing image correction on the denoised image to obtain a corrected image of the denoised image.
[0130] X005, perform layout analysis on the corrected image to obtain segmentation results and line division results of all texts in the corrected image.
[0131] X006, perform character segmentation on all texts in the corrected image to obtain each character in the corrected image.
[0132] X007, perform character recognition on each character in the corrected image.
[0133] X008, character recognition for each character in the corrected image comprises:
[0134] X009, obtain a training image and obtain a template of the training image.
[0135] X010, recognize and extract each character in the corrected image based on deep network feature extraction.
[0136] X011, fill each character in the recognized corrected image into the arrangement, paragraph, position and order corresponding to the template of the training image to obtain the corresponding sorted text.
[0137] X012, correct the corresponding sorted text according to the specific word order and context relationship to obtain all output text contents.
[0138] X013, select a file format to output all the output text content of the training image.
[0139] X014, each binary image, each denoised image, each segmentation result and line division result, each image template, each character, each character arrangement, paragraph, position and order are used as training data and input into the OCR model to obtain all output text content corresponding to each training image. Training is completed.
[0140] In S705, the characters are clustered and analyzed according to the semantic information of the characters. When all the characters are divided into different blocks, a cluster analysis model is used to execute S705.
[0141] The clustering analysis model is a machine learning technology that groups data points according to certain rules.
[0142] The cluster analysis model needs to be trained in advance. The following is an implementation of the cluster analysis model training method.
[0143] The method for filling out the customs declaration form also includes: training the cluster analysis model.
[0144] The training of the cluster analysis model includes:
[0145] W100, obtain multiple training text files, and take step S703 for each training text file to convert the training text file into training OCR text using an OCR method.
[0146] W200, select a training OCR text.
[0147] W300, a coordinate system is established with the lower left corner of the training OCR text as the coordinate origin, and the OCR text after the coordinate system is established is obtained.
[0148] W400, obtains the coordinates of each character in the OCR text after the coordinate system is constructed, and assigns each character a core element label.
[0149] W500, randomly select a character from the OCR text after the coordinate system is constructed as the first initial cluster center;
[0150] W600, traverse the remaining characters in the OCR text after the coordinate system is constructed except for the first initial cluster center, calculate the core element similarity distance value between each character and the nearest cluster center, and establish new cluster centers until K cluster centers are determined. Among them, the higher the similarity of the core element label, the smaller the core element similarity distance value. For example, there are 5 characters in "Destination: Poland", and the core element similarity distance value between these 5 characters is small.
[0151] W700, calculate the distance between each character and the cluster center in the OCR text after the coordinate system is constructed, and assign each character to the cluster corresponding to the cluster center with the smallest distance until each cluster is assigned N characters. N is a positive integer greater than 0.
[0152] W800, for each cluster, calculate the average value of the coordinates of all characters contained in the cluster, and use the point corresponding to the position of the average value as the new cluster center until the new cluster centers of all clusters are selected.
[0153] W910, calculate the straight-line distance between the new cluster center and the old cluster center, and determine whether the core element similarity distance value between the new cluster center and the old cluster center is less than the distance threshold.
[0154] W920, if the core element similarity distance value between the new cluster center and the old cluster center is greater than or equal to the distance threshold, the current cluster center is used as the old cluster center, and the distance between each character and the cluster center in the OCR text after the coordinate system is calculated and constructed is returned, and each character is assigned to the cluster corresponding to the cluster center with the smallest distance until all characters are assigned.
[0155] W930, if the core element similarity distance value between the new cluster center and the old cluster center is less than the distance threshold, then all characters in the cluster are output and the process returns to W200 until a training OCR text is selected and all training OCR texts are clustered.
[0156] Specifically, for example, if the characters contained in the OCR text after the coordinate system is constructed are F1, F2, ..., Fh, F1 is selected as the first initial clustering center, the core element similarity distance values between F2, F3, ..., Fh and F1 are calculated, and the character with the largest core element similarity distance value with F1 is selected as the new clustering center J1.
[0157] Calculate the core element similarity distance values of the cluster centers closest to F1, F2, ..., Fh and J1, and select the feature point with the largest core element similarity distance value as the new cluster center J2. Repeat until K cluster centers are selected. K is a positive integer greater than 5.
[0158] Calculate the distances between characters F1, F2, ..., Fh and cluster centers J1, J2, ..., JK, and assign the characters to the cluster corresponding to the cluster center that is closest to them.
[0159] After the assignment is completed, the average value of all character coordinates contained in each cluster is calculated, and the position corresponding to the coordinate average value is used as the new cluster center.
[0160] Calculate the core element similarity distance between the new cluster center and the old cluster center, and determine whether the core element similarity distance is less than the distance threshold.
[0161] If the similarity between the core elements of the new cluster center and the old cluster center is less than the distance threshold, all feature points in the cluster are output.
[0162] If the core element similarity distance between the new cluster center and the old cluster center is greater than or equal to the distance threshold, return to calculate the distance between F1, F2, ..., Fh and cluster centers J1, J2, ..., JK, and assign the character point to the cluster corresponding to the nearest cluster center.
[0163] Through the above-mentioned W100 to W930, the text content in each training OCR text is clustered according to the different core element labels, so as to complete the training of the clustering analysis model. The core element labels contain semantic information, so that the trained clustering analysis model has the following functions: when an OCR text is input into the trained clustering analysis model, the trained clustering analysis model can cluster the characters according to the semantic information of the characters and divide all the characters into different blocks.
[0164] The following introduces a training method for the block definition model.
[0165] The method for filling out the customs declaration form also includes: training the block definition model.
[0166] The training of the block definition model includes:
[0167] Z100, obtain multiple training file types, each of the training file types includes multiple training text files, and take steps S702 to S705 for each text file in each training file type, and use the OCR method and the cluster analysis model method in sequence to convert the training text files into training cluster analysis texts.
[0168] Z200, select a training file type.
[0169] Z300 reads the training file type and obtains all the training cluster analysis texts in the file type.
[0170] Z400, select a training text for cluster analysis.
[0171] Z500, a coordinate system is established with the lower left corner of the training cluster analysis text as the coordinate origin, and the cluster analysis text after the coordinate system is established is obtained.
[0172] Z600, obtain the center point coordinates of each block in the cluster analysis text after the coordinate system is constructed.
[0173] Z700, returning to the step of selecting a training cluster analysis text, until each training cluster analysis text in the training file type has been selected once, and obtaining the coordinates of each block in different training cluster analysis texts.
[0174] Z800, counts all the coordinates that appear in each block, and defines the coordinates with the most occurrences as the calibration coordinates of the block.
[0175] Z900, return to select a training file type until each training file type has been selected once.
[0176] Through the above Z100 to Z900, each block in each cluster analysis text in each training file type is calibrated to complete the training of the block definition model, so that after a block is input into the block definition model, the trained block definition model can output the content category to be extracted corresponding to the center point coordinates of the block.
[0177] In one embodiment of the present application, the step of performing standardization processing on all first text contents and second text contents extracted from the text contents corresponding to each sample file to obtain first target text contents corresponding to each content category to be extracted and second target text contents corresponding to each content category to be extracted includes the following steps S801 to S804:
[0178] S801, select a sample file.
[0179] S802, acquiring the sample file, and obtaining the first text content and the second text content corresponding to each content category to be extracted in the sample file.
[0180] S803, performing standardization processing on the first text content and the second text content corresponding to each content category to be extracted in the sample file to obtain the first target text content and the second target text content corresponding to each content category to be extracted.
[0181] S804, returning to the step of selecting a sample file until each sample file has been selected once.
[0182] Specifically, a sample file is first selected, the sample file is obtained, and the first text content and the second text content corresponding to each content category to be extracted in the sample file are obtained. The first text content and the second text content corresponding to each content category to be extracted in the sample file are standardized, and the standardization processing direction is the format of the information to be filled in the blank customs declaration form, and the first target text content and the second target text content corresponding to each content category to be extracted are obtained; finally, a sample file is selected again until each sample file has been selected once, and the first target text content and the second target text content corresponding to each content category to be extracted in each sample file are obtained.
[0183] In this embodiment, the first text content and the second text content corresponding to each content category to be extracted in each sample file are unified in specifications, and the unified specifications are specifications that can be directly filled in the customs declaration form, thereby standardizing the extracted content and facilitating the discovery of differences therein.
[0184] In one embodiment of the present application, the standardization process of the first text content and the second text content corresponding to each content category to be extracted in the sample file to obtain the first target text content and the second target text content corresponding to each content category to be extracted includes the following S803a to S803e:
[0185] S803a, select a sample file.
[0186] S803b, acquiring the sample file, and obtaining the first text content and the second text content corresponding to each content category to be extracted in the sample file.
[0187] S803c, the first text content corresponding to each content category to be extracted in the sample file is processed in sequence to unify the uppercase and lowercase formats, unify the Chinese and English bracket formats, unify the full-width and half-width formats, and delete spaces and special characters, so as to obtain the first target text content corresponding to each content category to be extracted in the sample file.
[0188] S803d, the second text content corresponding to each content category to be extracted in the sample file is processed in sequence to unify the upper and lower case formats, unify the Chinese and English bracket formats, unify the full-width and half-width formats, and delete spaces and special characters, so as to obtain the second target text content corresponding to each content category to be extracted in the sample file.
[0189] S803e, returning to the step of selecting a sample file, until each sample file has been selected once.
[0190] Specifically, a sample file is first selected to obtain the first text content and the second text content corresponding to each content category to be extracted in the sample file, and the first text content corresponding to each content category to be extracted in the sample file is sequentially unified in uppercase and lowercase format, Chinese and English bracket format, full-width and half-width format, and spaces and special characters are deleted. The data is also standardized, and the same with complicated sentences or different languages is converted into a format that meets the requirements for filling in the customs declaration form, for example, the People's Republic of China or CHINA is uniformly replaced by China; and the amount with more decimal places is uniformly retained to two decimal places, and rounding is used to determine the final result in the process of retaining two decimal places, so as to obtain the first target text content and the second target text content corresponding to each content category to be extracted in the sample file, and finally return to select a sample file until each sample file has been selected once, so as to obtain the first target text content and the second target text content corresponding to each content category to be extracted in each sample file.
[0191] In this embodiment, by unifying the specific and detailed formats of the first text content and the second text content corresponding to each content category that needs to be extracted in each sample file, the first target text content and the second target text content corresponding to each content category that needs to be extracted in each sample file can be conveniently filled into the customs declaration form.
[0192] like Figure 6 to Figure 7 As shown, in one embodiment of the present application, the first target text content corresponding to each content category to be extracted in each sample file is compared with the second target text content, and based on the comparison result, the content extracted from each sample file is filled into the corresponding position on the blank customs declaration form, and the completed customs declaration form is output, including the following S901 to S909:
[0193] S901, select a sample file.
[0194] S902, acquiring the sample file, and obtaining each content category to be extracted in the sample file.
[0195] S903: Select a content category to be extracted from the sample file.
[0196] S904 , reading a content category to be extracted in the sample file, and obtaining a first target text content and a second target text content corresponding to the content category to be extracted in the sample file.
[0197] S905: Compare the first target text content corresponding to the content category to be extracted in the sample file with the second target text content.
[0198] S906, when there is a part with a consistent comparison result, one of the first target text content and the second target text content corresponding to the to-be-extracted content category with a consistent comparison result is defined as a determined filled-in content, and the determined filled-in content is output.
[0199] S907, when there is an inconsistent part in the comparison result, traverse all sample files corresponding to the blank customs declaration form, extract the text content corresponding to the content category to be extracted that is inconsistent with the comparison result in each sample file corresponding to the blank customs declaration form, use the extracted results as alternative options for the content to be filled in the content category to be extracted, define all alternative options as indefinite filling content, and output the indefinite filling content.
[0200] S908, returning to the step of selecting a content category to be extracted from the sample file, until each content category to be extracted from the sample file has been selected once.
[0201] S909, returning to the step of selecting a sample file until each sample file has been selected once.
[0202] Specifically, first select a sample file to obtain each content category to be extracted in the sample file, select a content category to be extracted to obtain the first target text content and the second target text content corresponding to the content category to be extracted in the sample file, and compare the first target text content and the second target text content corresponding to the content category to be extracted in the sample file.
[0203] Based on the comparison results, different processing is performed. When the comparison result of the first target text content corresponding to the content category to be extracted in the sample file is consistent with the second target text content, one of them is defined as the determined content to be filled in, and the determined content to be filled in is output; when the comparison result of the first target text content corresponding to the content category to be extracted in the sample file is inconsistent with the second target text content, the content category to be extracted in the sample file is extracted from the text content corresponding to each sample file of the blank customs declaration form, and the extracted result is used as an alternative option for the content to be filled in the content category to be extracted and defined as indefinite content to be filled in, and the indefinite content to be filled in is output.
[0204] Finally, return to select a content category to be extracted in the sample file until each content category to be extracted in the sample file has been selected once, and obtain the final extraction result of each content category to be extracted, which can be a definite filled content or an indefinite filled content.
[0205] like Figure 6 to Figure 7 As shown, in this embodiment, by comparing the first target text content and the second target text content corresponding to a content category to be extracted of a sample file, different results are output based on different comparison results. If the comparison results are consistent, the output definite filled-in content is accurate, and if the comparison results are inconsistent, the output is indefinite filled-in content. The indefinite filled-in content can provide an optional solution for subsequent manual processing, thereby reducing the time spent on manual filling and improving the overall filling efficiency and fault tolerance.
[0206] In one embodiment of the present application, the step of comparing the first target text content corresponding to each content category to be extracted in each sample file with the second target text content, filling the content extracted from each sample file into the corresponding position on the blank customs declaration form based on the comparison result, and outputting the completed customs declaration form further includes the following S910 to S916:
[0207] S910, obtain a blank customs declaration form.
[0208] S911, selecting a sample file from a plurality of sample files corresponding to the blank customs declaration form.
[0209] S912, acquiring the sample file, obtaining each definite filled-in content corresponding to the sample file and each content category to be extracted corresponding to the definite filled-in content, each indefinite filled-in content corresponding to the sample file and each content category to be extracted corresponding to the indefinite filled-in content.
[0210] S913, each definite filling content and each indefinite filling content corresponding to the sample file are filled into the corresponding content category position to be extracted on the blank customs declaration form.
[0211] S914, returning to select one of the multiple sample files corresponding to the blank customs declaration form, until each sample file corresponding to the blank customs declaration form has been selected once, and a filled-in customs declaration form is obtained.
[0212] S915, marking all the indefinite contents in the filled-in customs declaration form with special marks to obtain the marked customs declaration form.
[0213] S916, export the marked customs declaration.
[0214] Specifically, firstly, a blank customs declaration form is selected, the blank customs declaration form is obtained, and a sample file in each sample file corresponding to the blank customs declaration form is obtained, and then each definite filled-in content corresponding to the sample file and the content category to be extracted corresponding to each definite filled-in content, as well as each indefinite filled-in content corresponding to the sample file and the content category to be extracted corresponding to each indefinite filled-in content are obtained, and each definite filled-in content and each indefinite filled-in content in the sample file are filled into the corresponding content category position to be extracted on the blank customs declaration form; then, one of the multiple sample files corresponding to the blank customs declaration form is returned to be selected, until each sample file corresponding to the blank customs declaration form has been selected once, and the filled-in customs declaration form is obtained.
[0215] Then, all the indefinite contents in the filled-in customs declaration form are marked with special marks to obtain the marked customs declaration form, and finally the marked customs declaration form is exported.
[0216] In this embodiment, by obtaining each definite filled-in content corresponding to each sample file and each content category to be extracted corresponding to each definite filled-in content, as well as each indefinite filled-in content corresponding to the sample file and each content category to be extracted corresponding to each indefinite filled-in content, each definite filled-in content and each indefinite filled-in content are filled in the customs declaration form based on the position of the content category to be extracted on the blank customs declaration form, and all indefinite filled-in contents in the filled-in customs declaration form are marked with special marks, so that the location that needs to be processed can be quickly found during manual processing, and the corresponding correct content can be quickly found from the options there.
[0217] In one embodiment of the present application, the step of filling each definite filled-in content and each indefinite filled-in content corresponding to the sample file into the corresponding content category position to be extracted on the blank customs declaration form includes the following S011 to S017:
[0218] S011, select a sample file.
[0219] S012, acquiring the sample file, obtaining an indefinite filled-in content corresponding to the sample file, and a content category to be extracted corresponding to the indefinite filled-in content.
[0220] S013: Extract the text content of each sample file based on the category of the content to be extracted to obtain all the extracted text content.
[0221] S014, counting the number of occurrences of each extracted text content, defining the extracted text content with the largest number of occurrences as optional content, and the other extracted text content as candidate content.
[0222] S015, output the optional content to the corresponding position on the blank customs declaration form.
[0223] S016, outputting other extracted text contents to the candidate list at the corresponding position on the white customs list.
[0224] S017, return to the selection of a sample file, until each sample file has been selected once. Specifically, the corresponding content category to be extracted is determined by the extracted indefinite content, and all sample files corresponding to the customs declaration form being filled out and all sample files in the historical customs declaration data are extracted based on the content category to be extracted, and all the extracted contents are counted to obtain the number of occurrences of each content, and the extracted text content with the most occurrences is input as optional content to the corresponding position on the customs declaration form, and the position is marked in red to remind that the item should be verified or manually input during manual processing, and then the other extracted text content is filled into the alternative list of the corresponding position on the customs declaration form as alternative content, which is convenient for selection during manual processing and improves work efficiency.
[0225] The technical features of the above-described embodiments may be arbitrarily combined, and the execution order of the method steps is not limited. To make the description concise, not all possible combinations of the technical features in the above-described embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0226] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A method for filling out a customs declaration form, characterized in that: The method of filling in the customs declaration form includes: Obtain each blank customs declaration form and obtain multiple sample files corresponding to each blank customs declaration form, each sample file corresponding to a file type; Based on the different file formats of each sample file, select different methods to extract the text content corresponding to each sample file; Determine the file type corresponding to each sample file based on the specific text content at the header of the text content corresponding to each sample file; Based on the comparison table between file type and content categories to be extracted, at least one content category to be extracted corresponding to each sample file is obtained, and then all content categories to be extracted of the blank customs declaration form are obtained; Extracting the associated text content associated with the content category to be extracted from the text content corresponding to each sample file according to the semantic recognition model, and obtaining the first text content corresponding to each content category to be extracted; Convert each sample file into a sample image; Recognize each sample image according to OCR to obtain the OCR text corresponding to each sample image, extract the associated text content associated with the content category to be extracted from each OCR text through a cluster analysis model, and obtain the second text content corresponding to each content category to be extracted; Standardize all first text contents and second text contents extracted from the text contents corresponding to each sample file to obtain first target text contents corresponding to each content category to be extracted and second target text contents corresponding to each content category to be extracted; The first target text content corresponding to each content category to be extracted in each sample file is compared with the second target text content, and based on the comparison result, the text content extracted from each sample file is filled into the corresponding position on the blank customs declaration form, and the completed customs declaration form is output.
2. The method for filling out a customs declaration form according to claim 1, characterized in that: The selecting different methods to extract the text content corresponding to each sample file based on the different file formats of each sample file includes: Select a sample file; Read the sample file and obtain the file format of the sample file; When the format of the sample file is DOC or EXCEL, extract text information from the sample file to obtain the text content corresponding to the sample file; When the format of the sample file is PDF or image, the sample file is extracted using an OCR method to obtain the text content corresponding to the sample file; Return to the step of selecting one of the multiple sample files corresponding to the blank customs declaration form until all the multiple sample files corresponding to the blank customs declaration form have been selected once.
3. The method for filling out a customs declaration form according to claim 2, characterized in that: Determining the file type corresponding to each sample file based on the specific text content at the header of the text content corresponding to each sample file includes: Get a blank customs declaration form; Select one of the multiple sample files corresponding to the blank customs declaration form; Read the sample file to obtain the text content corresponding to the sample file; Based on the header part of the text content, the file type of the sample file is obtained; the file type includes one or more of a customs declaration, an invoice, a packing list, and a contract; Return to the step of selecting one of the multiple sample files corresponding to the blank customs declaration form until each sample file corresponding to the blank customs declaration form has been selected once, and obtain the file type of each sample file.
4. The method for filling out a customs declaration form according to claim 3, characterized in that: Based on the comparison table between file type and content categories to be extracted, at least one content category to be extracted corresponding to each sample file is obtained, and then all content categories to be extracted of the blank customs declaration form include: Select a sample file; Using the file type of the sample file as an index, searching a table of file types and to-be-extracted content categories for at least one to-be-extracted content category corresponding to the file type of the sample file; Return to the step of selecting a sample file until all sample files have been selected, and obtain all content categories to be extracted corresponding to the blank customs declaration form.
5. The method for filling out a customs declaration form according to claim 4, characterized in that: The extracting of the associated text content associated with the content category to be extracted from the text content corresponding to each sample file according to the semantic recognition model to obtain the first text content corresponding to each content category to be extracted includes: Select a sample file; Obtain the text content corresponding to the sample file, and input the text content corresponding to the sample file into the BERT model; Start the BERT model and control the BERT model to process the text content of the sample file into sentences to obtain multiple sentences; Calculate the semantic vector of each sentence; Select a sentence; Calculate the similarity between the semantic vector of the sentence and the semantic vector of each content category to be extracted, and determine whether there is any semantic vector of the content category to be extracted and the semantic vector of the sentence whose similarity is greater than or equal to the similarity threshold; If there is any semantic vector of the to-be-extracted content category and the semantic vector of the sentence whose similarity is greater than or equal to the similarity threshold, a mapping relationship is established between the to-be-extracted content category and the sentence, and the sentence is defined as the first text content corresponding to the to-be-extracted content category; Return to the step of selecting a sentence until all sentences have been selected once; Return to the step of selecting a sample file until each sample file has been selected once.
6. The method for filling out a customs declaration form according to claim 5, characterized in that: The method of identifying each sample image according to OCR to obtain an OCR text corresponding to each sample image, extracting the associated text content associated with the content category to be extracted from each OCR text through a cluster analysis model to obtain the second text content corresponding to each content category to be extracted includes: Select a sample file; Get the sample image corresponding to the sample file; Use the OCR method to convert the sample image into the OCR text corresponding to the sample image; Locate the content of the OCR text and obtain the coordinates of each character; Perform cluster analysis on characters based on their semantic information and divide all characters into different blocks; Select a block; Input the block's center point coordinates and text type into the block definition model; Start the block definition model and output the content category to be extracted corresponding to the center point coordinates of the block; defining all text content in the block as second text content corresponding to the content category to be extracted; Return to the step of selecting a block until all blocks have been selected once; Return to the step of selecting a sample file until each sample file has been selected once.
7. The method for filling out a customs declaration form according to claim 6, characterized in that: The standardization process of all first text contents and second text contents extracted from the text contents corresponding to each sample file to obtain the first target text contents corresponding to each content category to be extracted and the second target text contents corresponding to each content category to be extracted includes: Select a sample file; Acquire the sample file, and obtain the first text content and the second text content corresponding to each content category to be extracted in the sample file; Standardizing the first text content and the second text content corresponding to each content category to be extracted in the sample file to obtain the first target text content and the second target text content corresponding to each content category to be extracted; Return to the step of selecting a sample file until each sample file has been selected once.
8. The method for filling out a customs declaration form according to claim 7, characterized in that: The standardization process of the first text content and the second text content corresponding to each content category to be extracted in the sample file to obtain the first target text content and the second target text content corresponding to each content category to be extracted includes: Select a sample file; Acquire the sample file, and obtain the first text content and the second text content corresponding to each content category to be extracted in the sample file; The first text content corresponding to each content category to be extracted in the sample file is sequentially processed to unify the uppercase and lowercase formats, the Chinese and English bracket formats, the full-width and half-width formats, and delete spaces and special characters, to obtain the first target text content corresponding to each content category to be extracted in the sample file; The second text content corresponding to each content category to be extracted in the sample file is sequentially processed to unify the uppercase and lowercase formats, unify the Chinese and English bracket formats, unify the full-width and half-width formats, and delete spaces and special characters, so as to obtain the second target text content corresponding to each content category to be extracted in the sample file; Return to the step of selecting a sample file until each sample file has been selected once.
9. The method for filling out a customs declaration form according to claim 8, characterized in that: The first target text content corresponding to each content category to be extracted in each sample file is compared with the second target text content, and based on the comparison result, the content extracted from each sample file is filled into the corresponding position on the blank customs declaration form, and the completed customs declaration form is output, including: Select a sample file; Obtain the sample file, and obtain each content category to be extracted in the sample file; Select a content category to be extracted from the sample file; Read a content category to be extracted in the sample file, and obtain a first target text content and a second target text content corresponding to the content category to be extracted in the sample file; Comparing the first target text content corresponding to the content category to be extracted in the sample file with the second target text content; When a part with a consistent comparison result appears, one of the first target text content and the second target text content corresponding to the content category to be extracted with the consistent comparison result is defined as a determined filled-in content, and the determined filled-in content is output; When there is an inconsistent part in the comparison result, all sample files corresponding to the blank customs declaration form are traversed, and the text content corresponding to the content category to be extracted that is inconsistent with the comparison result in each sample file corresponding to the blank customs declaration form is extracted, and the extracted results are used as alternatives for the content to be filled in the content category to be extracted, and all alternatives are defined as indefinite filling content, and the indefinite filling content is output; Returning to selecting a content category to be extracted in the sample file, until each content category to be extracted in the sample file has been selected once; Return to the step of selecting a sample file until each sample file has been selected once.
10. The method for filling out a customs declaration form according to claim 9, characterized in that: The step of comparing the first target text content corresponding to each content category to be extracted in each sample file with the second target text content, filling the extracted content from each sample file into the corresponding position on the blank customs declaration form based on the comparison result, and outputting the completed customs declaration form also includes: Get a blank customs declaration form; Select one of the multiple sample files corresponding to the blank customs declaration form; Acquire the sample file, obtain each definite filled-in content corresponding to the sample file and the content category to be extracted corresponding to each definite filled-in content, each indefinite filled-in content corresponding to the sample file and the content category to be extracted corresponding to each indefinite filled-in content; Fill each definite content and each indefinite content corresponding to the sample file into the corresponding content category position to be extracted on the blank customs declaration form; Returning the selection of one of the multiple sample files corresponding to the blank customs declaration form, until each sample file corresponding to the blank customs declaration form has been selected once, and a filled-in customs declaration form is obtained; All the indefinite contents in the filled-in customs declaration form are marked with special marks to obtain the marked customs declaration form; Export the marked customs declaration.
