Nsp-based text clustering denoising method for ocr
The BERT model's nsp task is used for OCR text clustering to address the challenge of noise data in OCR technologies, enabling effective noise removal and ensuring data accuracy across different data quality scenarios.
Patent Information
- Application Number
- CN202510167602.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-17
- Publication Date
- 2025-03-14
AI Technical Summary
Current OCR technologies face challenges in distinguishing between valuable and noise data, leading to potential significant impacts on subsequent data processing and analysis, with existing noise removal methods being either rule-based and limited in scope or costly and resource-intensive.
A method utilizing the Next Sentence Prediction (nsp) task of the BERT model for text clustering to identify and remove noise data by calculating semantic relatedness between text segments and setting threshold values for clustering and noise filtering.
This approach provides a general and efficient method for noise data removal, ensuring accurate and reliable output by leveraging contextual analysis and clustering, applicable across various data quality scenarios, including high-resolution scans and low-quality images.
Smart Images

Figure CN119625745A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of noise data recognition, and in particular to a text clustering denoising method for OCR based on NSP. Background Art
[0002] In today's digital age, optical character recognition (OCR) technology has become an important tool for converting text information in PDF files and images into editable text. This technology is widely used in various occasions, including document digitization, data extraction and automated processing. However, when extracting text, OCR technology often cannot distinguish which information is valuable and which is useless noise data. This noise data, such as stains, unclear text or irrelevant marks during the scanning process, may have a significant impact on subsequent data processing and analysis.
[0003] The main methods for removing noise data are: (1) Preprocessing denoising: Remove noise of a specific format according to specific rules. Disadvantages: The coverage is not wide enough, and it requires experts to formulate rules, which is time-consuming and laborious. (2) Based on machine learning: training classification models and using classification models to identify noise. Disadvantages: high cost, difficulty in preparing training sets, and lack of universality. Therefore, the present invention proposes a text clustering denoising method for OCR based on NSP to solve the problems existing in the prior art. Summary of the invention
[0004] In view of the above problems, the purpose of the present invention is to propose a text clustering denoising method for OCR based on NSP. The text clustering denoising method for OCR based on NSP utilizes the BERT model for clustering, analyzes the results, and obtains discrete noise data. It has universality and simplicity and can solve the problems existing in the prior art.
[0005] To achieve the purpose of the present invention, the present invention is implemented by the following technical scheme: a text clustering denoising method for OCR based on NSP, comprising the following steps: Step 1: Get data Prepare the data to be recognized, obtain the text information of the data to be recognized through the OCR method, and regard each result of the OCR method as a sentence of text; Step 2: Clustering The nsp task model is used to calculate the semantic relevance α1 between each previous sentence and the next sentence, and parameter α2 is set as the clustering threshold. The semantic relevance α1 is compared with parameter α2, and according to the comparison results, they are divided into the same cluster or different clusters; Step 3: Get the cluster center For each cluster, the average value of the semantic relevance between each sentence and other sentences in the cluster is calculated, and the sentence with the largest average value is considered as the cluster center of this cluster. In this way, the cluster center of each cluster is calculated. Step 4: Processing of cluster centers After obtaining the cluster center of each cluster, the average semantic correlation between the cluster center of each cluster and the cluster centers of other clusters is calculated; Step 5: Denoising Set the denoising threshold β, compare the average values obtained in step 4, and perform denoising based on the comparison results.
[0006] A further improvement is that in step 1, the data to be identified includes one of PDF or image.
[0007] A further improvement is that in step 1, the result obtained by the OCR method is corrected for typos.
[0008] A further improvement is that in step 2, the comparison method is specifically: when the semantic correlation α1 between the two sentences is less than the parameter α2, they are determined to be in different clusters, otherwise they are in the same cluster, and the texts are divided into different clusters in this way.
[0009] A further improvement is that in step 2, the value of parameter α2 is 0.7.
[0010] A further improvement is that in step 4, the specific steps of calculation are: using a semantic similarity calculation method to calculate the semantic relevance between each cluster center and other cluster centers, and then calculating the average value of the similarity between each cluster center and other cluster centers.
[0011] A further improvement is that in step 5, the specific method of denoising is: When the average value of the cluster center of a cluster is less than the denoising threshold β, it is identified as a noise cluster, otherwise it is identified as a non-noise cluster, and the noise clusters are denoised in turn.
[0012] A further improvement is that in step five, the value of the denoising threshold β is 0.4.
[0013] The beneficial effects of the present invention are as follows: the present invention provides a method combining contextual semantic analysis with cluster analysis, using the NSP task model in the BERT model for clustering, and then analyzing the results to obtain discrete noise data, which has versatility and simplicity. Therefore, the present invention can work in different scenarios and conditions, whether processing high-resolution scanned documents or low-quality mobile phone images, and can identify and filter out irrelevant or erroneous text information to ensure that the final output data is accurate and reliable. BRIEF DESCRIPTION OF THE DRAWINGS
[0014] Figure 1 It is a schematic diagram of the steps of the present invention. DETAILED DESCRIPTION
[0015] In order to deepen the understanding of the present invention, the present invention will be further described in detail below in conjunction with examples. The examples are only used to explain the present invention and do not constitute a limitation on the protection scope of the present invention.
[0016] In the following embodiments, the BERT model is involved, which is a pre-trained language model released by Google in 2018. It can understand the bidirectional relationship of the context and use the Transformer architecture to generate deep semantic representations. The NSP (next sentence prediction) task model is a capability of the BERT model. This task model is used to determine whether a sentence is a reasonable sequel to another sentence. For each pair of consecutive sentences, the model outputs a relevance score (α1) indicating the semantic similarity between the sentences.
[0017] In the process of data cleaning and denoising, removing noisy data is a very important step, which can significantly improve the accuracy and reliability of the model.
[0018] First of all, for the pre-processing denoising method, it is a way to remove specific noise through rules or filters. It mainly relies on manually defined rules or patterns to identify and remove noise data. The rules and algorithms are clear, and can usually be implemented through regular expressions, keyword filtering or specific pattern recognition. It is suitable for some simple noise cleaning tasks, but its coverage is not wide enough. It can usually only identify and remove noise of known patterns. It cannot effectively remove noise that is not covered by the rules. At the same time, the rules need to be manually designed according to the specific application and data characteristics, which usually requires the participation of domain experts. Then, when designing the rules, some noise may be missed, or some valid data may be mistakenly removed. Especially when dealing with complex or changeable data, designing rules is very time-consuming and prone to errors.
[0019] As for the denoising method based on machine learning, it has certain advantages, but training a machine learning model usually requires a large amount of labeled data, which is an expensive process for many tasks. And model training usually requires a large amount of computing resources, then according to some of the above problems, the present invention provides the following embodiments.
[0020] Embodiment 1, according to Figure 1 This embodiment proposes a text clustering denoising method for OCR based on NSP, including the following steps: Step 1: Get data Prepare the data to be recognized, obtain the text information of the data to be recognized by the OCR method, regard each result of the OCR method as a sentence of text, and perform wrong character correction on the result obtained by the OCR method. During the wrong character correction process, a pre-trained NLP model (such as spaCy or the BERT model involved in this embodiment) can be used to perform context analysis, identify inappropriate words and correct them. Through the context, the NLP model can determine whether an incorrect word can be corrected by replacing it with other words, wherein the data to be recognized includes one of PDF or image, and in this embodiment, it is PDF file data; Step 2: Clustering The goal of this step is to cluster the text and assign clusters based on the semantic correlation between the upper and lower sentences. Specifically, the nsp task model is used to calculate the semantic correlation α1 between each upper and lower sentence text, and the parameter α2 is set as the clustering threshold. The value of parameter α2 is 0.7. The semantic correlation α1 is compared with the parameter α2. According to the comparison result, they are divided into the same cluster or different clusters. The specific comparison method is: when the semantic correlation α1 between the two sentences is less than the parameter α2, they are judged to be in different clusters, otherwise they are in the same cluster. In this way, the text is divided into different clusters; Step 3: Get the cluster center For each cluster, the average value of the semantic relevance between each sentence and other sentences in the cluster is calculated, and the sentence with the largest average value is considered as the cluster center of this cluster. In this way, the cluster center of each cluster is calculated. Step 4: Processing of cluster centers After obtaining the cluster center of each cluster, the average value of the semantic relevance between the cluster center of each cluster and the cluster centers of other clusters is calculated respectively, wherein the specific steps of the calculation are: using the semantic similarity calculation method to calculate the semantic relevance between each cluster center and other cluster centers, and then calculating the average value of the similarity between each cluster center and other cluster centers; Step 5: Denoising Set the denoising threshold β to 0.4, compare the average values obtained in step 4, and perform denoising according to the comparison results. The specific method of denoising is as follows: When the average value of the cluster center of a cluster is less than the denoising threshold β, it is identified as a noise cluster, otherwise it is identified as a non-noise cluster. The noise clusters are denoised, that is, deleted.
[0021] Embodiment 2: This embodiment proposes a text clustering denoising method for OCR based on NSP, comprising the following steps: Step 1: First, prepare the data to be recognized, which is image data. You can use various devices (such as mobile phones, scanners) to shoot or scan the target document. Make sure the image is clear, and then use the OCR (optical character recognition) method to obtain the text information of the data to be recognized, for example, use Tesseract, EasyOCR and other OCR libraries to recognize the text information in the image. The OCR method analyzes the characters in the image and converts them into a machine-readable text format. In this embodiment, since the text recognized by OCR is generally a whole string, specific punctuation marks (such as a period, question mark or exclamation mark) are used to segment the text, and then each result of the OCR method is regarded as a sentence of text. The OCR recognition result may contain some typos, spelling errors or inappropriate vocabulary. These errors may be caused by poor image quality, distorted text, font problems, etc. In order to improve the accuracy of the text, it is necessary to correct the typos of the OCR output results. In this embodiment, a dictionary-based spelling correction method is adopted, and a dictionary or word library is used to check whether the words in the recognition result are correct. The corrected results enter the subsequent steps.
[0022] Step 2: Use the nsp task model to calculate the semantic correlation α1 between each previous sentence and the next sentence. The nsp task model is a typical natural language processing task, which aims to predict whether the given two sentences (Sentence A and Sentence B) are continuous, that is, whether the next sentence logically follows the previous sentence. Therefore, the nsp task model is used to obtain the semantic correlation (semantic similarity) between the previous sentence and the next sentence, and set the parameter α2 as the clustering threshold, with a specific value of 0.7. The semantic correlation α1 is compared with the parameter α2. According to the comparison results, they are divided into the same cluster or different clusters. The specific comparison method is: when the semantic correlation α1 between the two sentences is less than the parameter α2, they are judged to be in different clusters, otherwise they are in the same cluster. In this way, the texts are divided into different clusters.
[0023] Step 3: In step 2, the identified data has been clustered into several clusters. For each sentence in the cluster, we calculate the semantic relevance between it and other texts in the cluster and obtain the average value of these relevances. For each cluster, the text with the largest average semantic relevance value is selected as the cluster center of the cluster. This means that the cluster center is the sentence most relevant to other texts in the cluster and represents the core meaning of the cluster. Then, separate calculations are performed to obtain the cluster center of each cluster.
[0024] Step 4: After obtaining the cluster center of each cluster, calculate the average value of the semantic relevance between the cluster center of each cluster and the cluster centers of other clusters. Through this process, we can obtain the cluster center of each cluster and calculate the average value of the semantic relevance between the cluster centers, which helps to understand the similarity between the cluster centers, so as to further analyze and optimize the clustering results. If the similarity between the cluster centers is low, it may mean that the distinction between the clusters is large; conversely, if the similarity between the cluster centers is high, it may mean that the boundaries of the clusters are fuzzy. Specifically, the semantic similarity calculation method is used. In this embodiment, each cluster center is converted into a vector representation based on the BERT model, and the semantic similarity (semantic relevance) between the cluster centers is calculated by cosine similarity, the semantic relevance between each cluster center and other cluster centers is calculated, and then the average value of the similarity between each cluster center and other cluster centers is calculated.
[0025] Step 5: Set the denoising threshold β to 0.4, which is a threshold used to determine whether the cluster centers are similar enough. Compare the average values obtained in step 4, and perform denoising, i.e., delete, based on the comparison results. The denoising threshold β means that if the average similarity between a cluster center and other cluster centers is lower than the threshold, it is considered that the similarity of the cluster center is low, which may be noise or an unrealistic cluster center and needs to be denoised. Therefore, when the average value of the cluster center of a cluster is less than the denoising threshold β, it is identified as a noise cluster, otherwise it is identified as a non-noise cluster. The noise clusters are denoised in turn. The purpose of denoising is to clean up those unrepresentative cluster centers, thereby improving the quality of clustering.
[0026] Therefore, the present invention uses the NSP task to cluster the OCR text data, and then performs some calculations on the clusters. Therefore, a method combining contextual semantic analysis and cluster analysis is provided, and the NSP task model in the BERT model is used for clustering, and then the results are analyzed to obtain discrete noise data, which has versatility and simplicity. Therefore, the present invention can work in different scenarios and conditions, whether it is processing high-resolution scanned documents or low-quality mobile phone images, and can identify and filter out irrelevant or erroneous text information to ensure that the final output data is accurate and reliable.
[0027] The above shows and describes the basic principles, main features and advantages of the present invention. It should be understood by those skilled in the art that the present invention is not limited by the above embodiments. The above embodiments and descriptions are only for explaining the principles of the present invention. Without departing from the framework and scope of application of the present invention, the present invention may have various changes and improvements, which fall within the scope of the present invention to be protected. The scope of protection of the present invention is defined by the attached claims and their equivalents.
Claims
1. A text clustering denoising method for OCR based on NSP, characterized by: The following steps are involved: Step 1: Get data Prepare the data to be recognized, obtain the text information of the data to be recognized through the OCR method, and regard each result of the OCR method as a sentence of text; Step 2: Clustering The nsp task model is used to calculate the semantic relevance α1 between each previous sentence text and the next sentence text, and the parameter α2 is set as the clustering threshold. The semantic relevance α1 is compared with the parameter α2, and according to the comparison results, they are divided into the same cluster or different clusters; Step 3: Get the cluster center For each cluster, the average value of the semantic relevance between each sentence and other sentences in the cluster is calculated, and the sentence with the largest average value is considered as the cluster center of this cluster. In this way, the cluster center of each cluster is calculated. Step 4: Processing of cluster centers After obtaining the cluster center of each cluster, the average semantic correlation between the cluster center of each cluster and the cluster centers of other clusters is calculated; Step 5: Denoising Set the denoising threshold β, compare the average values obtained in step 4, and perform denoising based on the comparison results.
2. According to claim 1, a text clustering denoising method for OCR based on NSP, characterized in that: In the step 1, the data to be identified includes one of PDF or image.
3. According to the NSP-based text clustering denoising method for OCR according to claim 1, it is characterized by: In the step 1, the result obtained by the OCR method is corrected for wrong characters.
4. The text clustering denoising method for OCR based on NSP according to claim 1 is characterized in that: In the step 2, the comparison method is specifically as follows: when the semantic correlation α1 between the two sentences is less than the parameter α2, they are determined to be in different clusters; otherwise, the two sentences are in the same cluster, and the texts are divided into different clusters in this way.
5. The text clustering denoising method for OCR based on NSP according to claim 1 is characterized in that: In the step 2, the value of parameter α2 is 0.
7.
6. The text clustering denoising method for OCR based on NSP according to claim 1, characterized in that: In the step 4, the specific steps of calculation are: using the semantic similarity calculation method to calculate the semantic relevance between each cluster center and other cluster centers, and then calculating the average value of the similarity between each cluster center and other cluster centers.
7. The text clustering denoising method for OCR based on NSP according to claim 1 is characterized by: In step 5, the specific method of denoising is as follows: When the average value of the cluster center of a cluster is less than the denoising threshold β, it is identified as a noise cluster, otherwise it is identified as a non-noise cluster, and the noise clusters are denoised in turn.
8. The text clustering denoising method for OCR based on NSP according to claim 1, characterized in that: In the step 5, the denoising threshold β is 0.4.
Citation Information
Patent Citations
Label extraction method based on short text clustering technology
CN111414479A
Text clustering method based on artificial intelligence, related equipment and storage medium
CN113392209A
Model training method, intelligent customer service question clustering method and related device
CN115391509A
Semantically similar short text clustering method and system and computer equipment
CN116805150A
Text feature clustering method and device, computer equipment and storage medium
CN118656667A