A paragraph-level contract extraction method and system based on sample data enhancement
By employing a chapter-level contract extraction method enhanced with sample data, combined with data augmentation and rule correction techniques, the accuracy of contract element extraction has been improved, particularly the accuracy of core fields, thus resolving the issues of low extraction accuracy and misalignment in existing technologies.
Patent Information
- Application Number
- CN202210935527.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-05
- Publication Date
- 2026-01-30
- Estimated Expiration
- 2042-08-05
AI Technical Summary
Existing contract element extraction models lack generalization ability when faced with diverse contract formats and complex information about the parties involved, resulting in low extraction accuracy. In particular, when the granularity of contract fields is fine and the seals and stamps are affected by OCR, the extraction is incomplete or erroneous.
A document-level contract extraction method based on sample data augmentation is adopted. By obtaining the contract text type, paragraph and chapter information is extracted. Combined with data augmentation techniques such as synonym replacement and random insertion and deletion, information extraction is performed using a pre-set network model, and errors and misalignments are corrected through rules to improve extraction accuracy.
It improved the accuracy of contract element extraction, especially the accuracy of core fields reaching 92.3% and the accuracy of non-core fields reaching 75.8%, solving the problems of complex format and misaligned information in the existing model.
Smart Images

Figure CN115422915B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of neural network technology, and in particular to a method and system for extracting chapter-level contracts based on sample data augmentation. Background Technology
[0002] In practical applications, contract documents are diverse in type and format, with issues such as misalignment of basic information between parties, numerous and finer-grained extraction fields, handwritten text, and seals. This results in existing contract element extraction products achieving an average accuracy of around 80%, with fields such as contract number and address achieving only around 70% accuracy. Therefore, it is necessary to improve the accuracy of contract element identification. Existing contract element extraction models mainly suffer from the following problems: (1) There are many types of contracts with complex and diverse formats, and the existing models have weak generalization capabilities. (2) The basic information between parties is misaligned, and the model extraction also suffers from misalignment, lacking the ability to correct it. (3) There are too many contract element extraction fields, and the granularity is finer. Some fields have a small proportion of data, and the model cannot extract them or extracts them incorrectly. (4) The field information of the contract seal is affected by OCR, and the model extracts incomplete or incorrectly. Summary of the Invention
[0003] In view of the shortcomings of the prior art described above, the purpose of this application is to provide a chapter-level contract extraction method and system based on sample data augmentation, which can solve the problems existing in the current contract element extraction model.
[0004] To achieve the above and other related objectives, this application provides a method for extracting chapter-level contracts based on sample data augmentation, the method comprising the following steps:
[0005] Obtain the contract to be processed and determine the text type of the contract to be processed;
[0006] The text extraction method for the contract to be processed is determined based on the text type of the contract to be processed.
[0007] The contract to be processed is subjected to paragraph and chapter information extraction according to the determined text extraction method, and is divided by regular expression matching according to the chapter classification flag. The divided chapter information is then added to the beginning of the corresponding sentence.
[0008] Based on the data type of the elements, the chapter information after division is enhanced;
[0009] Information is extracted from the data-augmented chapter information using a pre-defined network model. The information extracted by the pre-defined network model is then used for error correction, similarity matching, and misalignment correction according to rules, and the final result is output.
[0010] Optionally, the text type of the contract to be processed includes: PDF text type in image format, PDF text type in editable format, and WORD text type.
[0011] Optionally, the process of data enhancement for the divided chapter information includes: performing synonym replacement, random insertion, random replacement, and random deletion on the divided chapter information to expand the data of the divided chapter information.
[0012] Optionally, the process of extracting information from the data-augmented chapter information using a pre-defined network model includes:
[0013] Add start and end positions to each character or word in the contract text;
[0014] Modeling is performed based on contract text information to obtain a two-dimensional matrix of batch size * text length. The new phrase structure composed of characters or words is flattened, and a three-dimensional matrix is obtained through a pre-trained model.
[0015] By implementing the self-attention mechanism to achieve information interaction between characters and words, a representation of the contract text is obtained;
[0016] The obtained representation is input into a conditional random field to extract information from the various element fields in the contract text.
[0017] Optionally, the extracted element field information includes at least one of the following: contract name, Party A's account name, Party B's account name, contract tax rate, currency of amount, whether the amount includes tax, start time, end date, Party A's bank account number, Party B's bank account number, Party A's tax number, Party B's tax number, Party A's legal person status, and Party B's legal person status.
[0018] This application also provides a chapter-level contract extraction system based on sample data augmentation, the system comprising:
[0019] The data acquisition module is used to acquire contracts to be processed and determine the text type of the contracts to be processed.
[0020] The extraction method module is used to determine the text extraction method of the contract to be processed based on the text type of the contract to be processed.
[0021] The segmentation module is used to extract paragraph and chapter information from the contract to be processed according to a determined text extraction method, and to segment it using regular expression matching based on the chapter classification flag, and to add the segmented chapter information to the beginning of the corresponding sentence.
[0022] The data enhancement module is used to enhance the data of the divided chapter information according to the data type of the elements;
[0023] The information extraction module is used to extract information from the data-augmented chapter information using a preset network model, and then performs error correction, similarity matching, and misalignment correction on the information extracted by the preset network model according to rules, and outputs the final result.
[0024] Optionally, the text type of the contract to be processed includes: PDF text type in image format, PDF text type in editable format, and WORD text type.
[0025] Optionally, the process of data enhancement for the divided chapter information includes: performing synonym replacement, random insertion, random replacement, and random deletion on the divided chapter information to expand the data of the divided chapter information.
[0026] Optionally, the process of extracting information from the data-augmented chapter information using a pre-defined network model includes:
[0027] Add start and end positions to each character or word in the contract text;
[0028] Modeling is performed based on contract text information to obtain a two-dimensional matrix of batch size * text length. The new phrase structure composed of characters or words is flattened, and a three-dimensional matrix is obtained through a pre-trained model.
[0029] By implementing the self-attention mechanism to achieve information interaction between characters and words, a representation of the contract text is obtained;
[0030] The obtained representation is input into a conditional random field to extract information from the various element fields in the contract text.
[0031] Optionally, the extracted element field information includes at least one of the following: contract name, Party A's account name, Party B's account name, contract tax rate, currency of amount, whether the amount includes tax, start time, end date, Party A's bank account number, Party B's bank account number, Party A's tax number, Party B's tax number, Party A's legal person status, and Party B's legal person status.
[0032] As described above, this application provides a method and system for extracting chapter-level contracts based on sample data augmentation, which has the following beneficial effects:
[0033] This application first obtains the contract to be processed and determines its text type; then, based on the text type, it determines the text extraction method for the contract; next, it extracts paragraph and chapter information from the contract according to the determined text extraction method, and divides the contract using regular expression matching based on chapter classification markers, adding the divided chapter information to the beginning of the corresponding sentences; then, it performs data augmentation on the divided chapter information according to the element data type; finally, it uses a preset network model to extract information from the data-augmented chapter information, and performs error correction, similarity matching, and misalignment correction on the information extracted by the preset network model through rules, outputting the final result. Using the technical solution described in this application, this application can extract information such as contract name, Party A's account name, Party B's account name, contract tax rate, currency of amount, whether the amount includes tax, start time, end date, Party A's bank account number, Party B's bank account number, Party A's tax number, Party B's tax number, Party A's legal representative, and Party B's legal representative from a contract. Moreover, it can achieve an accuracy rate of 92.3% for the eight core fields of contract name, Party A's account name, Party B's account name, contract tax rate, currency of amount, whether the amount includes tax, start time, and end date, and an accuracy rate of 75.8% for the 25 fields including Party A's bank account number, Party B's bank account number, Party A's tax number, Party B's tax number, Party A's legal representative, and Party B's legal representative. Attached Figure Description
[0034] Figure 1 A flowchart illustrating a document-level contract extraction method based on sample data augmentation, provided as an embodiment;
[0035] Figure 2 This is a schematic diagram of the structure of a preset network model provided in one embodiment;
[0036] Figure 3 This is a schematic diagram of the hardware structure of a document-level contract extraction system based on sample data augmentation, provided as an embodiment. Detailed Implementation
[0037] The following specific examples illustrate the implementation of this application. Those skilled in the art can easily understand other advantages and effects of this application from the content disclosed in this specification. This application can also be implemented or applied through other different specific embodiments, and various details in this specification can also be modified or changed based on different viewpoints and applications without departing from the spirit of this application. It should be noted that, unless otherwise specified, the following embodiments and features in the embodiments can be combined with each other.
[0038] It should be noted that the illustrations provided in the following embodiments are only schematic representations of the basic concept of this application. Therefore, the drawings only show the components related to this application and are not drawn according to the actual number, shape and size of the components in the actual implementation. In the actual implementation, the form, quantity and proportion of each component can be arbitrarily changed, and the layout of the components may also be more complex.
[0039] Please see Figure 1 This application provides a method for extracting chapter-level contracts based on sample data augmentation, comprising the following steps:
[0040] S110, Obtain the contract to be processed and determine its text type. In this embodiment, the text type of the contract to be processed includes: PDF text type in image format, PDF text type in editable format, and WORD text type. The correlation between file type and contract extraction mainly lies in the method of obtaining text from the file. WORD files are readable, and the corresponding text information can be directly obtained. PDFs are divided into readable and unreadable files. Readable files can have their text information directly obtained; unreadable files, such as PNG images, require OCR recognition to obtain their text information. The processing after successful text acquisition for WORD and PDF files is the same.
[0041] S120, determine the text extraction method for the contract to be processed based on its text type. In this embodiment, PDFs are divided into two categories simply to distinguish the different methods of obtaining text within the PDF: one allows direct reading of the text content, while the other requires OCR recognition of the text. The subsequent text processing procedures for both types of PDF text are the same.
[0042] S130, the paragraph and chapter information of the contract to be processed is extracted according to the determined text extraction method, and the contract is divided using regular expression matching according to the chapter classification flag. The divided chapter information is then added to the beginning of the corresponding sentence.
[0043] S140, Based on the element data type, perform EDA data augmentation on the divided chapter information. As an example, the process of augmenting the divided chapter information in this embodiment may include: performing synonym replacement, random insertion, random replacement, and random deletion on the divided chapter information to expand the data. Specifically, the data to be augmented refers to field types with relatively small amounts of labeled data, such as fields like legal person, authorized agent, project manager, and contractor address. EDA data augmentation expands this relatively small amount of labeled data through methods such as synonym replacement, random insertion, random replacement, and random deletion, thereby achieving data augmentation.
[0044] S150 uses a pre-defined network model to extract information from the data-augmented chapter information. The information extracted by the pre-defined network model is then processed using rules for error correction, similarity matching, and misalignment correction, outputting the final result. Specifically, error correction involves correcting typos and fields affected by OCR errors, such as contract name, Party A, and Party B, for PDFs that are images and require OCR to recognize text. This is because OCR is affected by factors such as image quality, image flipping, and seals. Regular expressions are used to optimize the model's extraction results, such as for tax ID numbers, bank account numbers, and contact information, removing incorrect characters extracted by the model. Similarity matching is used for contracts in PDF format, similarity algorithms like difflib are used to build a dictionary for Party A and Party B, and similarity matching is performed. This dictionary can also be used to supplement other information about Party A and Party B, such as legal representative and tax ID numbers. Similarity matching can also be used to correct the model's extraction results. Misalignment correction: This mainly involves using regular expressions to correct the results extracted from the model. Problems such as misalignment between Party A and Party B can be corrected by identifying specific Party A and Party B identifiers, such as Party A, the client, and the buyer.
[0045] According to the above description, in an exemplary embodiment, the network structure of the preset network model is as follows: Figure 2 As shown. In Figure 2 In the diagram, the parameter is defined as: d tt This represents the position matrix of the tail entity. d th This represents the position matrix of the tail entity and the head entity. d ht This represents the position matrix of the head and tail entities. hh This represents the position matrix of the head entity. Linear & CRF represent Linear Conditional Random Fields, a discriminative probabilistic model whose parameter optimization method is maximum likelihood estimation of the objective function. Add & Normal represent summation and normalization. FFN represents a fully connected layer. Self-Attention represents a self-attention mechanism that can directly calculate dependencies regardless of word distances, learning the internal structure of a sentence. Embedding represents an embedding layer that converts characters / words into real vectors. Token represents each character / word in the text. Head represents the head entity. Tail represents the tail entity.
[0046] The process of extracting information from the data-augmented chapter information using a pre-set network model includes: adding start and end positions to each character or word in the contract text; modeling based on the contract text information to obtain a two-dimensional matrix of batch size * text length, and flattening the new phrase structure composed of characters or words to obtain a three-dimensional matrix through a pre-trained model; realizing information interaction between characters and words based on a self-attention mechanism to obtain a representation of the contract text; and inputting the obtained representation into a conditional random field to extract the information of each element field in the contract text. As an example, in this embodiment, the extracted element field information includes at least one of the following: contract name, Party A's account name, Party B's account name, contract tax rate, currency of amount, whether the amount includes tax, start time, end date, Party A's bank account number, Party B's bank account number, Party A's tax number, Party B's tax number, Party A's legal representative, and Party B's legal representative.
[0047] Through the technical solution described in this embodiment, this embodiment can extract information such as contract name, Party A's account name, Party B's account name, contract tax rate, currency of amount, whether the amount includes tax, start time, end date, Party A's bank account number, Party B's bank account number, Party A's tax ID number, Party B's tax ID number, Party A's legal representative, and Party B's legal representative from the contract. Moreover, it can achieve an accuracy rate of 92.3% for the eight core fields of contract name, Party A's account name, Party B's account name, contract tax rate, currency of amount, whether the amount includes tax, start time, and end date, and an accuracy rate of 75.8% for the 25 fields including Party A's bank account number, Party B's bank account number, Party A's tax ID number, Party B's tax ID number, Party A's legal representative, and Party B's legal representative.
[0048] Furthermore, the inventors discovered that contract texts contain a large amount of semi-structured text and a small number of tables, such as basic information of both parties. Existing methods cannot effectively utilize the relationship between table information, paragraph information, and chapter information. The main approach is to divide the contract text into sections by paragraphs and then combine them with chapter information before inputting the combined information into the model. However, table information is not processed in conjunction with chapter and paragraph information, which can easily lead to misalignment and confusion.
[0049] Therefore, this application also provides another exemplary embodiment, which includes a document-level contract extraction method based on Bert-Flat-CRF and augmented sample data, comprising the following steps:
[0050] The document type is determined and parsed separately for PDF and Word documents. PDFs are further divided into PNG image formats and editable PDF files. The relationship between file type and contract extraction primarily lies in the method of text extraction. Word documents are readable, and the text information can be directly extracted. PDFs are divided into readable and unreadable documents. Readable documents allow direct text extraction; unreadable documents, such as PNG images, require OCR recognition to extract the text. The processing of text after successful extraction is the same for both Word and PDF documents. The two PDF categories are simply to differentiate the text extraction methods: one allows direct reading of the text content, while the other requires OCR recognition. The subsequent text processing for both types of PDFs is identical.
[0051] Paragraph and chapter information is extracted, and the paragraphs are divided using regular expression matching based on the chapter classification markers. After division, the chapter information is added to the beginning of the corresponding sentence.
[0052] Data augmentation, based on the data type of the elements, involves EDA data augmentation to increase the diversity of the corpus. Specifically, the data to be augmented refers to fields with relatively small amounts of labeled data, such as fields for legal persons, authorized agents, project managers, and contractor addresses. EDA data augmentation expands this sparsely labeled data through methods such as synonym replacement, random insertion, random replacement, and random deletion, thus achieving the effect of data augmentation.
[0053] The model structure adopts the Bert-Flat-CRF model, which can enhance entities, especially those with longer spans, and incorporate lexical information, resulting in significant gains in few-sample NER. Entities with longer spans refer to entities with longer intervals; simply put, they are entities with longer lengths. Few-sample NER refers to feature extraction with limited labeled data. The Bert-Flat-CRF model structure is as follows: Figure 2As shown below. The model details are as follows: For each token (character / word) in the contract text information, start (Head) and end (tail) positions are added to model the contract text information, obtaining a two-dimensional matrix of batch_size (batch size) * max_len (text length). Then, the Lattice structure is flattened, and a three-dimensional matrix is obtained through a pre-trained model. Information interaction between words and phrases is achieved by self-attention to fully obtain the representation of the contract text. Finally, the representation is input into a CRF (Conditional Random Field) to extract various element field information in the contract text. A Lattice represents a new phrase composed of words / phrases. For example, "Peace Hotel" formed by combining "peace" and "hotel" is a Lattice. In addition, in the Bert-Flat model, Bert generates a semantic dense matrix, and Flat encodes the vocabulary of the text, introducing vocabulary information and relative position information, which significantly improves the performance for small-sample Chinese NER. At the same time, EDA data augmentation is adopted to increase the diversity of the corpus. Finally, combined with post-processing rules, misaligned field information is corrected, rule matching is performed on field information not extracted by the model, and by constructing a matching library, similarity matching repair is carried out for problems such as chapter stamps.
[0054] Post-processing optimization: For the information extracted by the model, operations such as error correction, similarity matching, and misalignment correction are performed through rules to output the final result. Specifically, error correction: Mainly for PDFs that are images, text needs to be recognized through OCR, and misspelled words are corrected. Fields affected by OCR recognition errors, such as contract names, Party A, Party B, etc. Because OCR is affected by factors such as image quality, flipping, and chapter stamps. For the results extracted by the model, regular optimization is carried out, such as for tax numbers, bank account numbers, contact information, to remove incorrect characters over-extracted by the model. Similarity matching: For contracts with PDFs as images, through similarity algorithms such as difflib, a dictionary library is established for Party A and Party B for similarity matching. The dictionary library can also complete other information of Party A and Party B, such as legal persons, tax numbers, etc. Similarity matching can also be used to correct the results extracted by the model. Misalignment correction: Mainly use regular expressions to correct the results extracted by the model for problems such as misalignment of Party A and Party B, through specific markers for Party A and Party B, such as Party A,委托人, buyer, etc.
[0055] In this embodiment, the Bert-Flat model combined with the data augmentation technique EDA and post-processing rules improves the extraction of core element fields to 92.3% and non-core fields to 75.8%.
[0056] In summary, this application provides a document-level contract extraction method based on sample data augmentation. The method involves acquiring the contract to be processed and determining its text type; then determining the text extraction method based on the text type; extracting paragraph and chapter information from the contract according to the determined extraction method; dividing the contract using regular expression matching based on chapter classification markers; adding the divided chapter information to the beginning of each sentence; augmenting the divided chapter information based on the element data type; and finally extracting information from the augmented chapter information using a pre-defined network model. The information extracted by the pre-defined network model is then subjected to error correction, similarity matching, and misalignment correction through rules, and the final result is output. Using the technical solution described in this method, the following elements can be extracted from a contract: contract name, Party A's account name, Party B's account name, contract tax rate, currency of the amount, whether the amount includes tax, start date, end date, Party A's bank account number, Party B's bank account number, Party A's tax ID number, Party B's tax ID number, Party A's legal representative, and Party B's legal representative. Furthermore, it achieves an accuracy rate of 92.3% for the eight core fields: contract name, Party A's account name, Party B's account name, contract tax rate, currency of the amount, whether the amount includes tax, start date, and end date. For the remaining 25 fields, including Party A's bank account number, Party B's bank account number, Party A's tax ID number, Party B's tax ID number, Party A's legal representative, and Party B's legal representative, it achieves an accuracy rate of 75.8%.
[0057] like Figure 3 As shown, this application also provides a chapter-level contract extraction system based on sample data augmentation, the method comprising:
[0058] The data acquisition module 310 is used to acquire contracts to be processed and determine the text type of the contracts. In this embodiment, the text types of the contracts to be processed include: PDF text types in image format, PDF text types in editable format, and WORD text types. The correlation between file type and contract extraction mainly lies in the method of text acquisition within the file. WORD files are readable, and the corresponding text information can be directly obtained. PDFs are divided into readable and unreadable files; readable files can have their text information directly obtained, while unreadable files, such as PNG images, require OCR recognition to obtain their text information. The processing after successful text acquisition for WORD and PDF files is the same.
[0059] The extraction method module 320 is used to determine the text extraction method of the contract to be processed based on the text type of the contract to be processed. In this embodiment, the PDF is divided into two categories only to distinguish the different methods of obtaining the text within the PDF: one can directly read the text content, and the other requires text recognition through OCR. The subsequent text processing process for both types of PDF text is the same.
[0060] The segmentation module 330 is used to extract paragraph and chapter information from the contract to be processed according to a determined text extraction method, and to segment it using regular expression matching based on the chapter classification flag, and to add the segmented chapter information to the beginning of the corresponding sentence.
[0061] The data enhancement module 340 is used to enhance the data of the divided chapter information according to the data type of the elements. As an example, the process of enhancing the data of the divided chapter information in this embodiment may include: performing synonym replacement, random insertion, random replacement, and random deletion on the divided chapter information to expand the data. Specifically, the data to be enhanced refers to field types with relatively small amounts of labeled data, such as fields like legal person, authorized agent, project manager, and contractor address. EDA data enhancement expands this relatively small amount of labeled data through methods such as synonym replacement, random insertion, random replacement, and random deletion, thus achieving the effect of data enhancement.
[0062] The information extraction module 350 is used to extract information from the data-augmented chapter information using a preset network model. The extracted information is then processed according to rules for error correction, similarity matching, and misalignment correction, outputting the final result. Specifically, error correction involves correcting typos and fields affected by OCR errors, such as contract name, "Party A," and "Party B," for PDFs that are images and require OCR to extract text. This is because OCR is affected by factors such as image quality, image flipping, and seals. Regular expressions are used to optimize the model's extraction results, such as for tax ID numbers, bank account numbers, and contact information, removing incorrect characters extracted by the model. Similarity matching is used for contracts in PDF format. Similarity algorithms like difflib are used to build a dictionary for Party A and Party B, and similarity matching is performed. This dictionary can also be used to supplement other information about Party A and Party B, such as legal representative and tax ID numbers. Similarity matching can also be used to correct the model's extraction results. Misalignment correction: This mainly involves using regular expressions to correct the results extracted from the model. Problems such as misalignment between Party A and Party B can be corrected by identifying specific Party A and Party B identifiers, such as Party A, the client, and the buyer.
[0063] According to the above description, in an exemplary embodiment, the network structure of the preset network model is as follows: Figure 2 As shown. In Figure 2 In the diagram, the parameter is defined as: d tt This represents the position matrix of the tail entity. d th This represents the position matrix of the tail entity and the head entity. d ht This represents the position matrix of the head and tail entities. hhThis represents the position matrix of the head entity. Linear & CRF represent Linear Conditional Random Fields, a discriminative probabilistic model whose parameter optimization method is maximum likelihood estimation of the objective function. Add & Normal represent summation and normalization. FFN represents a fully connected layer. Self-Attention represents a self-attention mechanism that can directly calculate dependencies regardless of word distances, learning the internal structure of a sentence. Embedding represents an embedding layer that converts characters / words into real vectors. Token represents each character / word in the text. Head represents the head entity. Tail represents the tail entity.
[0064] The process of extracting information from the data-augmented chapter information using a pre-set network model includes: adding start and end positions to each character or word in the contract text; modeling based on the contract text information to obtain a two-dimensional matrix of batch size * text length, and flattening the new phrase structure composed of characters or words to obtain a three-dimensional matrix through a pre-trained model; realizing information interaction between characters and words based on a self-attention mechanism to obtain a representation of the contract text; and inputting the obtained representation into a conditional random field to extract the information of each element field in the contract text. As an example, in this embodiment, the extracted element field information includes at least one of the following: contract name, Party A's account name, Party B's account name, contract tax rate, currency of amount, whether the amount includes tax, start time, end date, Party A's bank account number, Party B's bank account number, Party A's tax number, Party B's tax number, Party A's legal representative, and Party B's legal representative.
[0065] Through the technical solution described in this embodiment, this embodiment can extract information such as contract name, Party A's account name, Party B's account name, contract tax rate, currency of amount, whether the amount includes tax, start time, end date, Party A's bank account number, Party B's bank account number, Party A's tax ID number, Party B's tax ID number, Party A's legal representative, and Party B's legal representative from the contract. Moreover, it can achieve an accuracy rate of 92.3% for the eight core fields of contract name, Party A's account name, Party B's account name, contract tax rate, currency of amount, whether the amount includes tax, start time, and end date, and an accuracy rate of 75.8% for the 25 fields including Party A's bank account number, Party B's bank account number, Party A's tax ID number, Party B's tax ID number, Party A's legal representative, and Party B's legal representative.
[0066] Furthermore, the inventors discovered that contract texts contain a large amount of semi-structured text and a small number of tables, such as basic information of both parties. Existing methods cannot effectively utilize the relationship between table information, paragraph information, and chapter information. The main approach is to divide the contract text into sections by paragraphs and then combine them with chapter information before inputting the combined information into the model. However, table information is not processed in conjunction with chapter and paragraph information, which can easily lead to misalignment and confusion.
[0067] Therefore, this application also provides another exemplary embodiment, which includes a chapter-level contract extraction system based on Bert-Flat-CRF and augmented sample data, for performing the following steps:
[0068] The document type is determined and parsed separately for PDF and Word documents. PDFs are further divided into PNG image formats and editable PDF files. The relationship between file type and contract extraction primarily lies in the method of text extraction. Word documents are readable, and the text information can be directly extracted. PDFs are divided into readable and unreadable documents. Readable documents allow direct text extraction; unreadable documents, such as PNG images, require OCR recognition to extract the text. The processing of text after successful extraction is the same for both Word and PDF documents. The two PDF categories are simply to differentiate the text extraction methods: one allows direct reading of the text content, while the other requires OCR recognition. The subsequent text processing for both types of PDFs is identical.
[0069] Paragraph and chapter information is extracted, and the paragraphs are divided using regular expression matching based on the chapter classification markers. After division, the chapter information is added to the beginning of the corresponding sentence.
[0070] Data augmentation, based on the data type of the elements, involves EDA data augmentation to increase the diversity of the corpus. Specifically, the data to be augmented refers to fields with relatively small amounts of labeled data, such as fields for legal persons, authorized agents, project managers, and contractor addresses. EDA data augmentation expands this sparsely labeled data through methods such as synonym replacement, random insertion, random replacement, and random deletion, thus achieving the effect of data augmentation.
[0071] The model structure adopts the Bert-Flat-CRF model, which can enhance entities, especially those with longer spans, and incorporate lexical information, resulting in significant gains in few-sample NER. Entities with longer spans refer to entities with longer intervals; simply put, they are entities with longer lengths. Few-sample NER refers to feature extraction with limited labeled data. The Bert-Flat-CRF model structure is as follows: Figure 2As shown below. The model details are as follows: For each token (character / word) in the contract text information, start (Head) and end (tail) positions are added to model the contract text information, obtaining a two-dimensional matrix of batch_size * max_len (text length). Then, the Lattice structure is flattened, and a three-dimensional matrix is obtained through a pre-trained model. Information interaction between words and phrases is achieved through self-attention to fully obtain the representation of the contract text. Finally, the representation is input into CRF (Conditional Random Field) to extract various element field information in the contract text. Lattice refers to a new phrase composed of words / phrases. For example, "Peace Hotel" formed by combining "peace" and "hotel" is a Lattice. In addition, in the Bert-Flat model, Bert generates a semantic dense matrix, and Flat encodes the vocabulary of the text, introducing vocabulary information and relative position information, which significantly improves the performance for small-sample Chinese NER. At the same time, EDA data augmentation is adopted to increase the diversity of the corpus. Finally, combined with post-processing rules, misaligned field information is corrected, and rule matching is performed on field information not extracted by the model. By constructing a matching library, similarity matching repair is performed on issues such as chapter seals.
[0072] Post-processing optimization: After the model extracts information, error correction, similarity matching, misalignment correction, etc. are performed through rules to output the final result. Specifically, error correction: Mainly for PDFs that are images, text needs to be recognized through OCR, and misspelled words are corrected. Fields affected by OCR recognition errors, such as contract names, Party A, Party B, etc. Because OCR is affected by factors such as image quality, flipping, and chapter seals. For the results extracted by the model, regular optimization is performed, such as for tax numbers, bank account numbers, contact information, to remove incorrect characters over-extracted by the model. Similarity matching: For contracts with PDFs as images, through similarity algorithms such as difflib, a dictionary library is established for Party A and Party B for similarity matching. The dictionary library can also complete other information of Party A and Party B, such as legal persons, tax numbers, etc. Similarity matching can also be used to correct the results extracted by the model. Misalignment correction: Mainly use regular expressions to correct the results extracted by the model for problems such as misalignment of Party A and Party B, through specific markers for Party A and Party B, such as Party A, principal, buyer, etc.
[0073] In this embodiment, the Bert-Flat model combined with the data augmentation technique EDA and post-processing rules improves the extraction rate of core element fields to 92.3% and non-core fields to 75.8%.
[0074] In summary, this application provides a document-level contract extraction method based on sample data augmentation. The method involves acquiring the contract to be processed and determining its text type; then determining the text extraction method based on the text type; extracting paragraph and chapter information from the contract according to the determined extraction method; dividing the contract using regular expression matching based on chapter classification markers; adding the divided chapter information to the beginning of each sentence; augmenting the divided chapter information based on the element data type; and finally extracting information from the augmented chapter information using a pre-defined network model. The information extracted by the pre-defined network model is then subjected to error correction, similarity matching, and misalignment correction through rules, and the final result is output. Using the technical solution described in this method, the following elements can be extracted from a contract: contract name, Party A's account name, Party B's account name, contract tax rate, currency of the amount, whether the amount includes tax, start date, end date, Party A's bank account number, Party B's bank account number, Party A's tax ID number, Party B's tax ID number, Party A's legal representative, and Party B's legal representative. Furthermore, it achieves an accuracy rate of 92.3% for the eight core fields: contract name, Party A's account name, Party B's account name, contract tax rate, currency of the amount, whether the amount includes tax, start date, and end date. For the remaining 25 fields, including Party A's bank account number, Party B's bank account number, Party A's tax ID number, Party B's tax ID number, Party A's legal representative, and Party B's legal representative, it achieves an accuracy rate of 75.8%.
[0075] It should be noted that the document-level contract extraction system based on sample data augmentation provided in the above embodiments and the document-level contract extraction method based on sample data augmentation provided in the above embodiments belong to the same concept. The specific ways in which each module and unit performs its operations have been described in detail in the method embodiments, and will not be repeated here. In practical applications, the document-level contract extraction system based on sample data augmentation provided in the above embodiments can be assigned to different functional modules as needed, that is, the internal structure of the system can be divided into different functional modules to complete all or part of the functions described above, and this is not a limitation here.
[0076] The above embodiments are merely illustrative of the principles and effects of this application and are not intended to limit this application. Any person skilled in the art can modify or alter the above embodiments without departing from the spirit and scope of this application. Therefore, all equivalent modifications or alterations made by those skilled in the art without departing from the spirit and technical concept disclosed in this application should still be covered by the claims of this application.
Claims
1. A method for contract extraction at the document level based on sample data augmentation, characterized in that, The method comprises the following steps: acquiring a to-be-processed contract and judging a text type of the to-be-processed contract; determining a text extraction mode of the to-be-processed contract based on the text type of the to-be-processed contract; extracting paragraph and chapter information of the to-be-processed contract according to the determined text extraction mode, and dividing the chapter information according to chapter hierarchical marks using regular matching, and adding the divided chapter information at the beginning of the corresponding sentence; performing data enhancement on the divided chapter information according to an element data type; performing information extraction on the chapter information after data enhancement using a preset network model, and correcting errors, performing similarity matching and correcting misplacement of information extracted by the preset network model through rules to output a final result; wherein the process of performing information extraction on the chapter information after data enhancement using the preset network model comprises: adding a start position and an end position to each character or word of the contract text information; modeling based on the contract text information to obtain a two-dimensional matrix of batch size * text length, and performing flat processing on a new phrase structure composed of words or characters to obtain a three-dimensional matrix through a pre-training model; realizing information interaction between words and characters according to a self-attention mechanism to obtain a representation of the contract text; inputting the obtained representation into a conditional random field to extract each element field information in the contract text.
2. The method of claim 1, wherein the sample data augmentation-based document-level contract extraction method is characterized by, The text type of the to-be-processed contract comprises: a PDF text type in an image format, a PDF text type in an editable format and a WORD text type.
3. The method of claim 1, wherein the sample data augmentation-based document-level contract extraction method is characterized by, The process of performing data enhancement on the divided chapter information comprises: performing synonym replacement, random insertion, random replacement and random deletion on the divided chapter information to expand the data of the divided chapter information.
4. The method of any one of claims 1-3, wherein the method is based on sample data augmentation. The extracted element field information comprises at least one of the following: a contract name, an account name of party A, an account name of party B, a contract tax rate, an amount currency, whether the amount contains tax, a start time, an end date, a bank account number of party A, a bank account number of party B, a tax number of party A, a tax number of party B, a lawyer of party A and a lawyer of party B. 5.A system for sample data augmentation based document level contract extraction, the system comprising: The system comprises: a data acquisition module configured to acquire a to-be-processed contract and judge a text type of the to-be-processed contract; an extraction mode module configured to determine a text extraction mode of the to-be-processed contract based on the text type of the to-be-processed contract; a division module configured to extract paragraph and chapter information of the to-be-processed contract according to the determined text extraction mode, and divide the chapter information according to chapter hierarchical marks using regular matching, and add the divided chapter information at the beginning of the corresponding sentence; a data enhancement module configured to perform data enhancement on the divided chapter information according to an element data type; and The information extraction module is configured to extract information from the chapter information after data enhancement by using a preset network model, correct errors, perform similar matching and position correction on the information extracted by the preset network model by using rules, and output a final result. The process of extracting information from the chapter information after data enhancement by using the preset network model includes adding a start position and an end position for each character or word in the contract text information; modeling based on the contract text information to obtain a two-dimensional matrix of batch size * text length, and performing flat processing on a new phrase structure composed of words or characters to obtain a three-dimensional matrix by using a pre-training model; realizing information interaction between words and characters according to a self-attention mechanism to obtain a representation of the contract text; and inputting the obtained representation into a conditional random field to extract each element field information in the contract text.
6. The sample data augmentation based document-level contract extraction system of claim 5, wherein, The text types of the to-be-processed contract include an image format PDF text type, an editable format PDF text type and a WORD text type.
7. The sample data augmentation based document-level contract extraction system of claim 5, wherein, The process of performing data enhancement on the divided chapter information includes synonym replacement, random insertion, random replacement and random deletion on the divided chapter information to expand the data of the divided chapter information.
8. The sample data augmentation based document-level contract extraction system according to any one of claims 5-7, wherein, The extracted element field information includes at least one of a contract name, an account name of a party A, an account name of a party B, a contract tax rate, an amount currency, whether the amount contains tax, a start time, an end date, a bank account number of the party A, a bank account number of the party B, a tax number of the party A, a tax number of the party B, a lawyer of the party A and a lawyer of the party B.
Citation Information
Patent Citations
BERT-FLAT-based Chinese named entity recognition method
CN112270193A
Systems and methods for intelligent contract analysis and data organization
US20210125297A1