Legal risk early warning method and system based on text recognition
By using a neural network-based named entity recognition model and optical character recognition technology, key information in legal contracts is automatically extracted, solving the subjectivity problem of traditional legal risk warning and achieving efficient and accurate legal risk warning.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- NANJING FAFAFA INFORMATION TECH CO LTD
- Filing Date
- 2025-11-28
- Publication Date
- 2026-04-17
AI Technical Summary
Traditional legal risk warnings rely on professional analysis, which is subjective and the assessment results are uncertain, thus failing to meet the need for rapid early warning.
By employing a neural network-based named entity recognition model, combined with optical character recognition and image processing technologies, keywords and risk characteristics in legal contracts are automatically extracted, and legal risk analysis and early warning are conducted through risk prediction algorithms.
It improved the accuracy and efficiency of legal risk prediction, enabled timely legal risk warnings, and reduced losses caused by legal issues.
Smart Images

Figure CN121882679A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of text recognition technology, and in particular to a legal risk warning method and system based on text recognition. Background Technology
[0002] In the process of business operation and contract signing, enterprises need to deal with various legal risks, and legal risk early warning is an essential part of this process. Legal risk early warning is a mechanism based on the identification, analysis, and assessment of legal risks. It identifies potential legal risks in advance and issues warnings so that relevant parties can take preventative and response measures. This helps enterprises and individuals identify legal risks early and avoid or reduce losses caused by legal issues.
[0003] The main components of legal risk early warning include warnings of changes in laws and regulations and contract risk warnings. These warnings remind businesses and individuals to pay close attention to relevant legal changes to avoid violating the law due to ignorance. Contract risk warnings monitor the signing, performance, modification, and contact of contracts, clarifying the risk of breach of contract for businesses and individuals. Traditional legal risk early warning methods rely on legal professionals to identify and analyze potential legal risks through case analysis, compliance checks, and questionnaires. These methods are subject to subjective influences, leading to uncertainties in the assessment results and failing to meet the need for rapid early warning. Summary of the Invention
[0004] To address the technical problems of the prior art, this application provides a legal risk early warning method and system based on text recognition. It establishes a named entity recognition model based on neural networks to extract keywords involving legal risks from legal texts, and further analyzes legal risks to make early warnings, thereby improving the accuracy and efficiency of legal risk prediction.
[0005] This application provides a legal risk warning method based on text recognition, including: (1) Obtain color image data of legal contract documents and convert the image data into text data using optical character recognition methods; (2) Preprocess the legal contract text data to remove irrelevant information and extract the effective content; (3) The preprocessed legal contract text data is fed into the pre-trained named entity recognition model, and key information is output to extract features related to legal risks. (4) The extracted risk features are quantified and analyzed using a risk prediction algorithm to obtain the risk analysis results of the legal contract text; (5) Based on the risk analysis results of the legal contract text, issue early warning notices in a timely manner to remind relevant personnel to pay attention to and deal with potential legal risks.
[0006] Furthermore, Optical Character Recognition (OCR) refers to the process by which electronic devices examine printed characters on paper, determine their shapes by detecting dark and light patterns, and then translate the shapes into computer text using character recognition methods. For printed characters, optical methods such as scanning are used to convert the text in paper documents into black-and-white dot matrix image files. Recognition software then converts the text in the image into text format for subsequent editing and processing. The basic principle of OCR is to simulate the human visual system and brain processing to achieve automatic recognition and understanding of text.
[0007] Furthermore, before converting legal contract image data into text data, image processing methods are needed to increase image clarity and improve the accuracy of text recognition. Image processing steps include binarization, noise reduction, and tilt correction. First, the legal contract image is converted into a binary image using a global thresholding method.
[0008] Secondly, Gaussian filtering is used to remove noise from the binarized image of the legal contract. The smoothing effect is achieved by weighting each pixel and its neighborhood in the image. The weight distribution follows the law of a two-dimensional Gaussian function. This weight allocation method preserves the edge information of the text in the image. The Gaussian filtering process is a convolution operation that sums the Gaussian kernel with the local region of the image.
[0009] Finally, the Hough transform is used to correct the tilt of the filtered binary image of the legal contract. During OCR, images may tilt due to scanning and shooting issues, affecting subsequent text recognition. The Hough transform calculates the tilt angle and automatically corrects this by detecting the text line baseline or document edge lines. The core idea of this method is to detect geometric features in the image through spatial transformation and a voting mechanism. In the traditional Cartesian coordinate system, a straight line can be represented as:
[0010] in, and These are the horizontal and vertical coordinates in the Cartesian coordinate system. It's the slope. It is the intercept; this representation has the problem of perpendicular lines, that is... Approaching infinity, the Hough transform solves this problem using polar coordinate parameterization, representing the straight line as:
[0011] in, This represents the distance from the line to the origin. This represents the angle between the line and the horizontal axis. This transformation maps a line in Cartesian space to a point in parameter space, achieving the conversion from image space to parameter space.
[0012] Furthermore, the preprocessing steps for legal contract text data include text cleaning, text segmentation, and text standardization.
[0013] Furthermore, named entity recognition (NER) is a core foundational task in natural language processing. It refers to the technology of automatically identifying named entities with specific meanings from text and classifying them into predefined categories. These named entities include names of people, places, organizations, and predefined proper nouns, and can be extended to specific types of expressions such as time, date, currency amounts, and percentages. The NER task can be transformed into a sequence labeling problem. Labeling rules are used to label word sequences in the segmented text. A named entity recognition model is then constructed to predict each word sequence in the text, thus completing entity recognition.
[0014] The named entity recognition model used in this invention is based on the BERT-BiLSTM-CRF structure. The BERT model is a pre-trained language model based on Transformer, employing bidirectional encoding and utilizing contextual information for word representation learning. Pre-trained on a large-scale corpus, BERT can capture deep-level linguistic knowledge and contextual relationships. In the named entity recognition model, it is used as the text encoder, mapping each word to a context-related word embedding. Bi-LSTM is an abbreviation for Bidirectional Long Short-Term Memory Network. It captures long-term dependencies in the input sequence through forward and backward propagation. In the named entity recognition task, Bi-LSTM models the relationship between the preceding and following word segments, so that each word contains the contextual dependencies of its preceding and following parts. Conditional Random Fields (CRFs) are discriminative models used for labeling and segmenting sequence data. In named entity recognition tasks, CRFs are used to model dependencies between labels, fully leveraging the global consistency of labels and the conditional dependencies between contexts. By calculating the conditional probabilities of label sequences, the final labeling results are optimized. The entire model combines the contextual representation capabilities of BERT, the long-term dependency capture capabilities of Bi-LSTM, and the sequence labeling optimization of CRFs.
[0015] This application also provides a legal risk early warning system based on text recognition, including: Data acquisition module: used to acquire color image data of legal contract documents, and convert the image data into text data using optical character recognition methods; Data preprocessing module: used to preprocess legal contract text data, remove irrelevant information, and extract valid content; Risk Feature Extraction Module: This module is used to feed pre-processed legal contract text data into a pre-trained named entity recognition model, output key information, and extract features related to legal risks. Risk Analysis Module: This module quantifies the extracted risk characteristics, analyzes them using risk prediction algorithms, and obtains the risk analysis results for the legal contract text. Risk warning module: Based on the risk analysis results of legal contract texts, it is used to issue timely warning notices to remind relevant personnel to pay attention to and deal with potential legal risks.
[0016] The present invention discloses the following technical effects: This invention proposes a legal risk early warning method and system based on text recognition. It employs optical character recognition (OCR) to convert legal contract image data into text data, serving as the foundation for text recognition. To ensure the clarity and accuracy of the converted text data, the legal contract images are binarized, denoised, and tilt-corrected before conversion to improve image quality and highlight character edges. Based on the preprocessed legal contract text data, a pre-trained named entity recognition model is introduced to identify key information in the legal contract and extract risk features. The named entity model used in this invention combines the contextual representation capability, long-term dependency capture capability, and sequence labeling optimization capability of classic models, effectively improving the accuracy and efficiency of risk feature recognition. Furthermore, a risk prediction algorithm is used to statistically analyze the extracted legal contract risk features, obtaining risk analysis results. Based on these results, timely early warning notifications are issued to relevant personnel, providing timely legal risk warnings during enterprise management and contract signing processes to avoid unnecessary losses. Attached Figure Description
[0017] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings of the embodiments of the present invention will be briefly described below. Flowcharts are used in this application to illustrate the operations performed by the system according to the embodiments of the present application. It should be understood that the preceding or following operations are not necessarily performed precisely in sequence. Instead, various steps can be processed in reverse order or simultaneously as needed. Furthermore, other operations can be added to these processes, or one or more steps can be removed from these processes.
[0018] Figure 1 This is a flowchart illustrating a legal risk warning method based on text recognition, provided as an embodiment of this application.
[0019] Figure 2 This is a schematic diagram of the structure of the named entity recognition model provided in the embodiments of this application.
[0020] Figure 3 This is a schematic diagram of the BERT model in the named entity model provided in the embodiments of this application.
[0021] Figure 4This is a schematic diagram of the structure of a legal risk warning system based on text recognition, provided in an embodiment of this application. Detailed Implementation
[0022] The above description is only an overview of the technical solution of this application. In order to better understand the technical means of this application and to implement it in accordance with the contents of the specification, and to make the above and other objects, features and advantages of this application more obvious and understandable, the following are specific embodiments of this application.
[0023] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description of this application will be provided in conjunction with the accompanying drawings. The described embodiments should not be considered as limitations on this application. All other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0024] In the following description, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or server that includes a series of steps or units is not necessarily limited to those explicitly listed, but may include other steps or modules not explicitly listed or inherent to such processes, methods, products, or devices. Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of this application only.
[0025] Example 1: This application provides a legal risk warning method based on text recognition, such as... Figure 1 As shown, the method includes: Step S10: Obtain color image data of the legal contract document and convert the image data into text data using optical character recognition (OCR).
[0026] In this embodiment, the legal contract image data is obtained by scanning paper legal contract documents. Before converting it into text data, image processing methods are needed to increase image clarity and improve the accuracy of text recognition. The image processing steps include binarization, noise reduction, and tilt correction. First, the legal contract image is converted into a binary image using a global thresholding method. The detailed steps include: The color image of the legal contract is converted to grayscale to obtain the original grayscale image. Calculate the histogram of the original grayscale image to obtain the total number of pixels in the image. and total average gray value The calculation process is represented by the following formula:
[0027] in, Represents grayscale value Number of times it appears; Set an initial threshold The original grayscale image is segmented into foreground and background based on a threshold: the grayscale values of the foreground and background are 255 and 0, respectively, as expressed by the formula:
[0028] in, It outputs the grayscale values of the binary image; Iterate through all possible thresholds from 0 to 255, and for each threshold... Calculate the pixel ratio of foreground to background, average grayscale value, and inter-class variance: The formula for calculating pixel ratio is expressed as follows:
[0029] in, and These represent the pixel ratios of the foreground and background, respectively, and the average grayscale values of the foreground and background are then obtained:
[0030] in, and These represent the average grayscale values of the foreground and background, respectively. Finally, the inter-class variance is calculated based on the pixel ratio and the average grayscale value. :
[0031] Choose to make the inter-class variance Maximum threshold Using the optimal threshold, the original grayscale image of the legal contract is segmented to obtain a binarized image of the legal contract.
[0032] Secondly, Gaussian filtering is used to remove noise from the binarized image of the legal contract. The smoothing effect is achieved by weighting each pixel and its neighborhood in the image, where the weight distribution follows the law of a two-dimensional Gaussian function.
[0033] Define the size of the Gaussian kernel sliding window as Summing the Gaussian kernel with a local region of the binarized image of the legal contract, the filtered image... Pixel value of position Expressed as a formula:
[0034]
[0035] in, and These represent the horizontal and vertical movement distances of the Gaussian kernel sliding window, respectively. , representing the maximum distance traveled; Represents a two-dimensional Gaussian function. It is the standard deviation of the Gaussian function; This represents the original pixel value.
[0036] Finally, the process of using Hough transform to correct the tilt of the filtered binary image of the legal contract is as follows: The filtered binarized image of the legal contract is used as the input image, and the Canny edge detector algorithm is used to extract the edges in the input image. Perform parameter space initialization and construct an all-zero matrix as the accumulator matrix to record each parameter combination. The number of votes, of which This represents the distance from a straight line to the origin in polar coordinates. This represents the angle between a straight line and the horizontal axis in a polar coordinate system. For each edge point, calculate all parameter combinations in the parameter space and vote on them in the accumulator; Find the points with the highest vote counts in the accumulator. The average value of the parameters corresponding to these points is the detected line parameter. Select the average angle value from these points. As the tilt angle of the document; Define a rotation matrix based on the document's tilt angle, and use the rotation matrix to rotate the input image back to the horizontal direction, thus achieving tilt correction for legal contract images.
[0037] Based on the preprocessed legal contract image data, an OCR tool converts the legal contract image data into text data. This embodiment uses the open-source Tesseract OCR engine. The Tesseract installation package is downloaded and installed on a computer, and the installation path is added to the system environment variables. The target image filename and the desired language are entered into the command line to perform OCR, resulting in text-formatted legal contract data, which is saved as a .txt file. The command line format is: `tesseract target image filename output_text -l chi_sim`, where the `chi_sim` parameter represents Chinese characters.
[0038] Step S20: Preprocess the legal contract text data, remove irrelevant information, and extract the valid content.
[0039] In this embodiment, the preprocessing procedure for legal contract text data includes text cleaning, text segmentation, and text standardization. The detailed steps are as follows: Remove irrelevant characters from text data, including special characters, garbled text, extra spaces, and newlines. Use regular expressions to identify and delete characters that do not conform to the text format. Identify and remove duplicate text paragraphs and sentences, and remove headers, footers, page numbers, version notices, and advertising information based on text location; Natural language processing tools are used to segment text paragraphs, divide paragraph topics, and use punctuation marks as sentence splitting points to divide paragraph text into individual sentences; Convert information such as dates and monetary units in text data into a uniform format to ensure consistent data encoding.
[0040] Step S30: The preprocessed legal contract text data is fed into the pre-trained named entity recognition model, which outputs key information and extracts features related to legal risks.
[0041] In this embodiment, the detailed steps for obtaining the pre-trained named entity recognition model include: A legal risk corpus was constructed, with data sources including corporate contracts, agreements, laws and regulations, policy documents, news reports, and social media content. The entity text data in the corpus was preprocessed. We established naming entity definition rules to classify the data in the corpus, defining company name, contract terms, legal terms, contract validity period, and contract amount as entity categories. We assigned entity category labels to each entity text data, and used the BMEO annotation system to perform word-level positional annotations on each entity in the corpus. B marks the beginning of an entity; M marks the middle part of an entity; E marks the end of an entity; O marks non-entity content. In this embodiment, the Python-based text annotation tool YEDDA is used to directly import TXT text from the corpus and annotate each entity according to the definition. A named entity recognition model based on the BERT-BiLSTM-CRF architecture is established, which takes entity text data in the corpus as input and outputs a label sequence corresponding to the target type for each character; The training objective is to maximize the log-likelihood function between the input and output data domains. Backpropagation is used to update the model parameters, and the accuracy is calculated. Recall rate and F1 scores As an evaluation metric for assessing model performance:
[0042]
[0043]
[0044] in, The number of correctly identified entities, To identify the number of erroneous entities, This represents the number of unidentified entities. The parameters of the best-performing model are saved as a pre-trained named entity recognition model to extract risk features from legal contract text data.
[0045] Step S40: Quantify the extracted risk features, analyze the risk features using a risk prediction algorithm, and obtain the risk analysis results of the legal contract text.
[0046] In this embodiment, the legal risk entities identified in step S30, including contract terms, legal terms, contract validity period, and contract amount, are defined as risk features. A scoring standard is set for each risk feature, and the degree of risk is assessed based on the contract validity period and contract amount. The frequency of risk keywords in contract terms and legal terms is statistically analyzed, and a risk score is defined based on the frequency. A risk prediction algorithm based on clustering is used to perform risk analysis on the input legal contract risk features according to the set scoring standard, assess the degree of risk, and obtain a risk score.
[0047] Step S50: Based on the risk analysis results of the legal contract text, issue a timely warning notice to remind relevant personnel to pay attention to and handle potential legal risks.
[0048] Example 2: This application provides a legal risk warning method based on text recognition. The detailed structure of the named entity model used is as follows: Figure 2 As shown: In this embodiment, the named entity model consists of three parts: a BERT layer, a Bi-LSTM layer, and a CRF layer. It combines the context representation capability of BERT, the sequence modeling capability of Bi-LSTM, and the label dependency modeling capability of CRF.
[0049] The BERT model performs sequence encoding on the input legal contract text data, generating context-dependent embedding vectors for each word. The detailed structure of the BERT model is as follows: Figure 2 As shown: The model adopts the encoder part of Transformer, which is composed of multiple Transformer blocks stacked together. Each Transformer block contains a multi-head self-attention layer and a feedforward layer. Layer normalization and residual structure are introduced after them. The multi-head self-attention mechanism concatenates the attention weights calculated by multiple heads to capture semantic information in the text sequence from multiple perspectives. The feedforward layer consists of two fully connected layers and uses the ReLU activation function to realize the non-linear transformation of semantic information.
[0050] In BERT, the input legal contract text is segmented into sentence sequences and word sequences. The word sequences are mapped to a high-dimensional space to obtain word embeddings, which are obtained through pre-training on a large-scale corpus. In addition, BERT introduces sentence embeddings to distinguish between two different but related sentences, and positional embeddings to obtain the positional information of each word in the text. The positional encoding formula is as follows:
[0051]
[0052] in, and These represent the position embeddings of elements at even and odd positions, respectively. The position embedding is a vector. It refers to the position of each word in the sentence. It is the index of each element in the vector. This represents the dimension of the positional encoding vector. The final BERT input embedding is obtained by adding the word embedding, sentence embedding, and positional embedding.
[0053] Bi-LSTM stands for Bidirectional Long Short-Term Memory Network. It captures long-term dependencies in input sequences through forward and backward propagation. In named entity recognition tasks, Bi-LSTM models the relationships between preceding and following word segments, ensuring that each word contains contextual dependencies between its preceding and following parts. Long Short-Term Memory networks are an improvement on traditional recurrent neural networks, introducing memory units and threshold mechanisms to control information forgetting, input, and output, thus solving the problems of vanishing and exploding gradients during model training.
[0054] CRF replaces the traditional softmax as the output layer of the named entity recognition model. During training, it learns a relational transition matrix containing label transition relationships from the data, thus obtaining the associations and constraints between labels. This is for the sentence sequence output by the Bi-LSTM layer. The model outputs a label sequence of... probability for:
[0055]
[0056] in, Indicates other possible sequence labels predicted by the model. This is the score matrix output by the Bi-LSTM layer. This is the relational transition matrix; This represents the position index in the matrix.
[0057] During model training, by maximizing the probability The log-likelihood function yields the output sequence with the highest overall probability, which serves as the predicted output of the named entity recognition model. This outputs key entities in legal contract texts for extracting legal risk features.
[0058] Example 3: The text recognition-based legal risk early warning system provided in this embodiment of the invention can execute the text recognition-based legal risk early warning method provided in any embodiment of the invention, and has the corresponding functional modules and beneficial effects of the execution method. The system framework is as follows: Figure 4 As shown, it includes the following modules: Data acquisition module: used to acquire color image data of legal contract documents, and convert the image data into text data using optical character recognition methods; Data preprocessing module: used to preprocess legal contract text data, remove irrelevant information, and extract valid content; Risk Feature Extraction Module: This module is used to feed pre-processed legal contract text data into a pre-trained named entity recognition model, output key information, and extract features related to legal risks. Risk Analysis Module: This module quantifies the extracted risk characteristics, analyzes them using risk prediction algorithms, and obtains the risk analysis results for the legal contract text. Risk warning module: Based on the risk analysis results of legal contract texts, it is used to issue timely warning notices to remind relevant personnel to pay attention to and deal with potential legal risks.
[0059] Although this application makes various references to certain modules in the system according to the embodiments of this application, any number of different modules can be used and run on user terminals and / or servers. The various units and modules included are only divided according to functional logic, but are not limited to the above division, as long as the corresponding functions can be achieved; in addition, the specific names of each functional unit are only for easy distinction between each other and are not used to limit the scope of protection of this invention.
[0060] The specific embodiments described above do not constitute a limitation on the scope of protection of this application. Those skilled in the art should understand that various modifications, combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this application should be included within the scope of protection of this application. In some cases, the actions or steps described in this application can be performed in a different order than that shown in the embodiments and still achieve the desired results. Furthermore, the processes depicted in the accompanying drawings do not necessarily require a specific or sequential order to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
Claims
1. A legal risk early warning method based on text recognition, characterized in that, The method includes: (1) Obtain color image data of legal contract documents and convert the image data into text data using optical character recognition methods; (2) Preprocess the legal contract text data to remove irrelevant information and extract the effective content; (3) The preprocessed legal contract text data is fed into the pre-trained named entity recognition model, and key information is output to extract features related to legal risks. (4) The extracted risk features are quantified and analyzed using a risk prediction algorithm to obtain the risk analysis results of the legal contract text; (5) Based on the risk analysis results of the legal contract text, issue early warning notices in a timely manner to remind relevant personnel to pay attention to and deal with potential legal risks.
2. The legal risk warning method based on text recognition as described in claim 1, characterized in that, In step (1), before converting the legal contract image data into text data, image processing methods are used to increase image clarity and improve the accuracy of text recognition. The image processing steps include binarization, noise reduction, and tilt correction.
3. The legal risk early warning method based on text recognition as described in claim 2, characterized in that, The binarization is achieved through a global thresholding method, and the detailed steps include: The color image of the legal contract is converted to grayscale to obtain the original grayscale image. Calculate the histogram of the original grayscale image to obtain the total number of pixels and the total average grayscale value of the image; Set an initial threshold The original grayscale image is segmented into foreground and background based on a threshold: the grayscale values of the foreground and background are 255 and 0, respectively, as expressed by the formula: in, The grayscale values of the original image. It outputs the grayscale values of the binary image; Iterate through all possible thresholds from 0 to 255, and for each threshold, calculate the pixel ratio of foreground and background, the average gray value, and the inter-class variance. The threshold that maximizes the inter-class variance is selected as the optimal threshold to segment the original grayscale image of the legal contract, resulting in a binarized image of the legal contract.
4. The legal risk early warning method based on text recognition as described in claim 2, characterized in that, The denoising method is Gaussian filtering, which achieves a smoothing effect by weighting each pixel and its neighborhood in the image, wherein the weight distribution follows the law of a two-dimensional Gaussian function; Define the size of the Gaussian kernel sliding window as Summing the Gaussian kernel with a local region of the binarized image of the legal contract, the filtered image... Pixel value of position Expressed as a formula: in, and These represent the horizontal and vertical movement distances of the Gaussian kernel sliding window, respectively. , representing the maximum distance traveled; Represents a two-dimensional Gaussian function. It is the standard deviation of the Gaussian function; This represents the original pixel value.
5. A legal risk warning method based on text recognition as described in claim 2, characterized in that, The tilt correction is based on the Hough transform method. The process of tilt correction for the filtered binary image of the legal contract is as follows: The filtered binarized image of the legal contract is used as the input image, and the Canny edge detector algorithm is used to extract the edges in the input image. Perform parameter space initialization and construct an all-zero matrix as the accumulator matrix to record each parameter combination. The number of votes, of which This represents the distance from a straight line to the origin in polar coordinates. This represents the angle between a straight line and the horizontal axis in a polar coordinate system. For each edge point, calculate all parameter combinations in the parameter space and vote on them in the accumulator; Find the points with the highest vote counts in the accumulator. The average value of the parameters corresponding to these points is the detected line parameter. Select the average angle value from these points. As the tilt angle of the document; Define a rotation matrix based on the document's tilt angle, and use the rotation matrix to rotate the input image back to the horizontal direction, thus achieving tilt correction for legal contract images.
6. The legal risk warning method based on text recognition as described in claim 1, characterized in that, In step (2), the preprocessing procedure for legal contract text data includes text cleaning, text segmentation, and text standardization. The detailed steps are as follows: Remove irrelevant characters from text data, including special characters, garbled text, extra spaces, and newlines. Use regular expressions to identify and delete characters that do not conform to the text format. Identify and remove duplicate text paragraphs and sentences, and remove headers, footers, page numbers, version notices, and advertising information based on text location; Natural language processing tools are used to segment text paragraphs, divide paragraph topics, and use punctuation marks as sentence splitting points to divide paragraph text into individual sentences; Convert information such as dates and monetary units in text data into a uniform format to ensure consistent data encoding.
7. A legal risk early warning method based on text recognition as described in claim 1, characterized in that, Step (3) involves obtaining the detailed steps of the pre-trained named entity recognition model, including: A legal risk corpus was constructed, with data sources including corporate contracts, agreements, laws and regulations, policy documents, news reports, and social media content. The entity text data in the corpus was preprocessed. We established naming entity definition rules to classify the data in the corpus, defining company name, contract terms, legal terms, contract validity period, and contract amount as entity categories. We assigned entity category labels to each entity text data, and used the BMEO annotation system to perform word-level positional annotations on each entity in the corpus. B marks the beginning of an entity; M marks the middle part of an entity; E marks the end of an entity; O marks non-entity content. The Python-based text annotation tool YEDDA is used to directly import TXT text from the corpus and annotate each entity according to the definition. A named entity recognition model based on the BERT-BiLSTM-CRF architecture is established, which takes entity text data in the corpus as input and outputs a label sequence corresponding to the target type for each character; The training objective is to maximize the log-likelihood function between the input and output data. The model parameters are updated by backpropagation, and the accuracy, recall and F1 score are calculated as evaluation metrics to assess the model performance. The parameters of the best-performing model are saved as a pre-trained named entity recognition model to extract risk features from legal contract text data.
8. A legal risk early warning method based on text recognition as described in claim 1, characterized in that, In step (4), legal risk entities, including contract terms, legal terms, contract validity period and contract amount, are defined as risk characteristics. Scoring criteria are set for each risk characteristic. The degree of risk is assessed based on the contract validity period and contract amount. The frequency of risk keywords in contract terms and legal terms is counted. Risk scores are defined based on the frequency. A risk prediction algorithm based on clustering is used to analyze the risk characteristics of the input legal contracts according to the set scoring criteria, assess the degree of risk, and obtain a risk score.
9. A legal risk early warning system based on text recognition, characterized in that, The system is used to implement the legal risk warning method based on text recognition as described in any one of claims 1-8, and the system includes: Data acquisition module: used to acquire color image data of legal contract documents, and convert the image data into text data using optical character recognition methods; Data preprocessing module: used to preprocess legal contract text data, remove irrelevant information, and extract valid content; Risk Feature Extraction Module: This module is used to feed pre-processed legal contract text data into a pre-trained named entity recognition model, output key information, and extract features related to legal risks. Risk Analysis Module: This module quantifies the extracted risk characteristics, analyzes them using risk prediction algorithms, and obtains the risk analysis results for the legal contract text. Risk warning module: Based on the risk analysis results of legal contract texts, it is used to issue timely warning notices to remind relevant personnel to pay attention to and deal with potential legal risks.