Document processing method and device
By performing feature extraction and large language model analysis on text blocks in documents, combined with query and screening of document element configurations, the problem of insufficient document processing efficiency and accuracy in the existing technology is solved, and efficient document data processing and structured information extraction are achieved.
Patent Information
- Application Number
- CN202411578494.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-06
- Publication Date
- 2025-03-07
AI Technical Summary
The prior art is difficult to effectively process and extract structured information in document data, resulting in insufficient document processing efficiency and accuracy.
By extracting the text blocks in the document, a large language model is used to parse the document type, and querying the matching document feature information in the document feature configuration, feature filtering and question answer generation.
It realizes efficient and automated processing of document data and structured information extraction, improving the efficiency and accuracy of document processing.
Smart Images

Figure CN119577077A_ABST
Abstract
Description
Technical Field
[0001] This document relates to the field of data processing technology, and in particular to a document processing method and device. Background Art
[0002] With the continuous development of Internet technology and the continuous advancement of social information, the value and importance of document data are increasing. Relevant structured data can be extracted from document data for archiving. For example, for signed contract documents, the name, mailing address, contact information and other data of Party A can often be extracted from the contract documents for storage. For example, for case files, the patient's name, diagnosed disease and other data can be extracted from the case files for storage. In this process, how to better and more effectively process document data has gradually become the focus of attention and the challenge faced by document data parties. Summary of the invention
[0003] One or more embodiments of the present specification provide a document processing method, including: extracting features from a text block contained in a document to obtain text features, and inputting first prompt information constructed based on the document into a large language model for parsing to obtain a document type, and querying document element information matching the document type in a document element configuration. Performing feature screening in the text features based on the document element information to obtain target text features. Constructing second prompt information based on a target text block corresponding to the target text feature and a document element question contained in the document element information. Inputting the second prompt information into a large language model for parsing to obtain an answer to the document element question.
[0004] One or more embodiments of the present specification provide a document processing device, including: a feature extraction module, configured to extract features from a text block contained in a document to obtain text features, and to input first prompt information constructed based on the document into a large language model for parsing to obtain a document type, and to query document element information matching the document type in a document element configuration. A feature screening module, configured to perform feature screening in the text features according to the document element information to obtain target text features. A prompt construction module, configured to construct second prompt information according to a target text block corresponding to the target text feature and a document element question contained in the document element information. A parsing processing module, configured to input the second prompt information into a large language model for parsing to obtain an answer to the document element question.
[0005] One or more embodiments of the present specification provide a document processing device, including: a processor; and a memory configured to store computer executable instructions, wherein when the computer executable instructions are executed, the processor: performs feature extraction on a text block contained in a document to obtain text features, and inputs first prompt information constructed based on the document into a large language model for parsing to obtain a document type, and queries document element information matching the document type in a document element configuration. Performs feature screening in the text features based on the document element information to obtain a target text feature. Constructs a second prompt information based on a target text block corresponding to the target text feature and a document element question contained in the document element information. Inputs the second prompt information into a large language model for parsing to obtain an answer to the document element question.
[0006] One or more embodiments of the present specification provide a computer-readable storage medium for storing computer-executable instructions, which implement the following steps when executed: extracting features from a text block contained in a document to obtain text features, and inputting first prompt information constructed based on the document into a large language model for parsing to obtain a document type, and querying document element information matching the document type in the document element configuration. Perform feature screening in the text features based on the document element information to obtain target text features. Construct second prompt information based on a target text block corresponding to the target text feature and a document element question contained in the document element information. Input the second prompt information into a large language model for parsing to obtain an answer to the document element question. BRIEF DESCRIPTION OF THE DRAWINGS
[0007] In order to more clearly illustrate one or more embodiments of the present specification or the technical solutions in the prior art, the drawings required for use in the embodiments or the prior art descriptions are briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the present specification. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative labor. Figure 1 A schematic diagram of an implementation environment of a document processing method provided for one or more embodiments of this specification; Figure 2 A flowchart of a document processing method provided for one or more embodiments of this specification; Figure 3 A processing flow chart of a document processing method applied to a contract scenario provided for one or more embodiments of this specification; Figure 4 A schematic diagram of an embodiment of a document processing device provided for one or more embodiments of this specification; Figure 5 A schematic diagram of the structure of a document processing device provided in one or more embodiments of this specification. DETAILED DESCRIPTION
[0008] In order to enable those skilled in the art to better understand the technical solutions in one or more embodiments of this specification, the technical solutions in one or more embodiments of this specification will be clearly and completely described below in conjunction with the drawings in one or more embodiments of this specification. Obviously, the described embodiments are only part of the embodiments of this specification, not all of them. Based on one or more embodiments of this specification, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of this document.
[0009] The document processing method provided in one or more embodiments of this specification can be applied to the implementation environment of document processing. Figure 1 , the implementation environment at least includes: Document processing system 101 , feature extraction module 102 , in addition, the implementation environment may also include a large language model 103 .
[0010] Among them, the document processing system 101, the feature extraction module 102 and the large language model 103 can run on a server. Specifically, the document processing system 101, the feature extraction module 102 and the large language model 103 can run on the same server or on different servers. The server can be one or more servers, a server cluster composed of several servers, or a cloud server of a cloud computing platform.
[0011] In this implementation environment, the feature extraction module 102 extracts features from the text blocks contained in the document to obtain text features, and the document processing system 101 inputs the first prompt information constructed based on the document into the large language model 103 for parsing to obtain the document type, queries the document element information matching the document type in the document element configuration, and then selects the target text feature from the text features according to the document element information, inputs the target text block corresponding to the target text feature and the document element question contained in the document element information into the large language model 103 for parsing to obtain the answer to the document element question.
[0012] One or more embodiments of a document processing method provided in this specification are as follows: Reference Figure 2 The document processing method provided in this embodiment specifically includes steps S202 to S208.
[0013] Step S202, extracting features from the text blocks contained in the document to obtain text features, and inputting the first prompt information constructed based on the document into the large language model for parsing to obtain the document type, and searching the document element information matching the document type in the document element configuration.
[0014] The document in this embodiment may be any document, for example, the document may be a contract document, a paper document, an agreement document, a case document, a physical examination document, etc.; the text block refers to a text block obtained by dividing the document into blocks, and the text block may be one or more. The text feature includes a feature vector of the text block, which may specifically be an embedding vector, such as an embedding. This embodiment may be applied to a document processing system.
[0015] The document type refers to the type of the document. For example, if the document is a contract document, the document type may be a contract type, which may specifically include a technical service contract type, a labor contract type, an asset transfer contract type, an insurance contract type, etc.; if the document is a paper document, the document type may be a paper type, which may specifically include xx1 degree thesis, xx2 degree thesis, etc.; if the document is a physical examination document, the document type may be a physical examination item type, which may specifically include xx1 physical examination item type, xx2 physical examination item type, etc. The large language model (LLM) refers to a computer model that can understand and generate natural language.
[0016] The document element configuration includes document element information corresponding to each document type among multiple pre-generated document types, that is, the document element information corresponding to each document type is configured in the document element configuration, and the document element information may include document element questions, may also include document element identifiers, and may also include element association information; the document element identifier may be a document element name, such as a document element identifier of "company_name (Party A / Unit / Company Name)", "employee_name (Party B / Employee Name)"; document element questions refer to questions related to document elements, such as the document element question corresponding to the document element identifier company_name is "What is the name of Party A / Unit / Company?", and the element association information is "Party A / Unit / Company Name: Correspondence Address: Mobile Number:".
[0017] The format of the document element configuration may be a preset format, that is, the document element configuration may be stored in a preset format, and the preset format may be a JSON (JavaScript Object Notation) format, which represents a lightweight data exchange format. For example, in the document element configuration, "file_type" may be used to represent the document type, "field_name" may be used to represent the document element identifier, "field_desc" may be used to represent the document element question, and "field_ass" may be used to represent element association information. The document element configuration may store "file_type: labor contract", "field_name: company_name", "field_desc: what is the name of Party A / unit / company?", "field_ass: Party A / unit / company name: correspondence address: mobile phone number:", which represent the company_name corresponding to the labor contract, what is the name of Party A / unit / company, and "Party A / unit / company name: correspondence address: mobile phone number:". The document element information matching the document type may be one or more pieces.
[0018] In a specific implementation, in order to realize the automation of answering questions for documents, in an optional implementation mode provided by this embodiment, before extracting features from text blocks contained in the document to obtain text features, and inputting the first prompt information constructed based on the document into a large language model for parsing and processing to obtain the document type, before determining the document element information matching the document type in the document element configuration, the following operations are further performed: Get the document uploaded by the user.
[0019] There can be one or more documents.
[0020] In addition, document data uploaded by users can also be obtained. The document data can be document images, document voice, document video, document screen recording or document screenshots. The document data can also be any combination of document images, document voice, document video, document screen recording, document screenshots. The document data can also be other types of data. In this case, the document data can be converted to obtain the document. The conversion processing here includes image recognition processing, voice recognition processing, video recognition processing, screen recording recognition processing or screenshot recognition processing, and specifically can be converting the document data into a document in text form.
[0021] In practical applications, the amount of data in a document may be large. Directly processing the document may result in a large amount of calculation and a high time cost. Therefore, the document may be processed in blocks to obtain text blocks, and the text blocks may be processed to reduce the amount of calculation and improve the document processing efficiency. In an optional implementation provided in this embodiment, in the process of extracting features from the text blocks contained in the document to obtain text features, the following operations are performed: Divide the document into blocks according to a preset block division strategy to obtain the text blocks; The text block is input into a pre-trained feature extraction model to perform feature extraction to obtain the text features.
[0022] The preset block strategy refers to a preset strategy for block processing of documents, and the preset block strategy may include at least one of the following: paragraph block strategy, title block strategy, punctuation block strategy. The pre-trained feature extraction model may be a BGE (BAAI General Embedding) model or a GTE (General Text Embeddings) model, both of which are text embedding models.
[0023] It should be added that after the text features are obtained by the feature extraction, the text features can be stored in a vector database; wherein the vector database can specifically be VectorStore or Redis (RemoteDictionaryServer, remote dictionary service).
[0024] In practical applications, different document types may require different relevant information to be obtained from the document. For example, different contract types may require different contract-related information to be obtained from the corresponding contract. In order to achieve automation and versatility in document processing, the document type of the document may be identified through a large language model. Specifically, the first prompt information constructed based on the document may be parsed and processed through the large language model to obtain the document type. In an optional implementation manner provided in this embodiment, the first prompt information is obtained in the following manner: Extracting a document title from the document, and extracting a preset text segment from the document; The document title and the preset text segment are written into a first prompt template to obtain the first prompt information.
[0025] The document title may be a document body title, specifically a document name. The preset text segments include text segments within a preset text interval, such as text segments of a preset number of paragraphs, text segments of a preset number of pages, or text segments of a preset number of lines.
[0026] The first prompt information is obtained by assembling the above-mentioned document title and preset text fragments, and the document type of the document is parsed by the first prompt information, thereby improving the efficiency of document type parsing. The document type is parsed by using the preset text fragments in the document, that is, part of the document content in the document, without the need for the entire document, thereby reducing the computational amount of document type parsing, thereby improving the efficiency of document type parsing while ensuring the accuracy of parsing.
[0027] In addition, the document title and / or the preset text segment may be extracted from the document, and the document title and / or the preset text segment may be written into the first prompt template to obtain the first prompt information.
[0028] On this basis, optionally, the first prompt template includes a type field of a plurality of preset document types and a first task field of parsing the document type of the document; The document type is obtained after screening the document type among the multiple preset document types based on the document title and the preset text segment included in the first prompt information.
[0029] Among them, the multiple preset document types include multiple pre-set document types, such as multiple preset contract types, "technical service contract", "labor contract", and "asset transfer contract".
[0030] For example, if the document is a contract document, the first prompt template is [You are a legal contract expert and need to determine the type of contract based on the contract name and partial content of the contract. Contract name: {file_name}. Contract content: {file_content}. Based on the above information, determine which category the contract belongs to in the following list ["Technical Service Contract", "Labor Contract", "Asset Transfer Contract"]]; write the contract title in file_name and the preset text fragment in file_content to obtain the first prompt information.
[0031] During the specific execution process, in the process of inputting the first prompt information constructed based on the document into the large language model for parsing and processing to obtain the document type, a prompt can be constructed based on the document and the first prompt template to obtain the first prompt information, and the first prompt information is input into the large language model for parsing and processing to obtain the document type; the parsing processing here may include calculating the probability that the document belongs to each preset document type in multiple preset document types based on the document title and preset text fragments contained in the first prompt information, and filtering out the preset document type as the document type from each preset document type based on the probability; specifically, the probabilities can be sorted, and the preset document type corresponding to the probability that the sorting position is before the preset position is filtered out in the sorting result as the document type; in this way, the efficiency and accuracy of document type parsing by the large language model are improved through the setting of preset document types.
[0032] In the process of querying the document element information matching the document type in the document element configuration, the document type may be queried in the document element configuration, and the document element information under the document type may be read.
[0033] It should be noted that the above-mentioned process of extracting features from the text blocks contained in the document to obtain text features and the above-mentioned process of inputting the first prompt information constructed based on the document into the large language model for parsing to obtain the document type, and querying the document element information matching the document type in the document element configuration, can be executed simultaneously or in an execution order during the execution process. The specific execution order is not limited, and any one process can be executed first and the other process can be executed later.
[0034] It should be added that step S202 can be replaced by extracting features from the text blocks contained in the document to obtain text features, and querying the document element information matching the document type of the document in the document element configuration; optionally, the document type is obtained by user upload; and a new implementation method is formed with other processing steps provided in this embodiment; Alternatively, it may be replaced by obtaining the document uploaded by the user and the document element information, and performing feature extraction on the text block contained in the document to obtain text features, which together with other processing steps provided in this embodiment constitute a new implementation method.
[0035] It should also be added that after step S202 is executed, since there are many document element problems, the relevant content extracted from the document may also be large and cover a wide range. Therefore, in order to improve the comprehensiveness and convenience of the subsequent large language model parsing processing, if the number of document element problems contained in the document element information exceeds the number threshold, the text feature can be used as the target text feature to execute subsequent related processes; if it does not exceed the number threshold, the following step S204 can be executed.
[0036] After the first prompt information constructed based on the document is input into the large language model for parsing to obtain the document type, the document type can also be compared with the preset document type uploaded by the user. If the comparison is consistent, the document element information operation of querying the document type matching the document element configuration is executed. If the comparison is inconsistent, a comparison failure result is generated and sent to the user. After the confirmation instruction of the document type in the comparison failure result uploaded by the user is detected, the document element information operation of querying the document type matching the document type in the document element configuration is executed.
[0037] The above-mentioned step S202 can also be replaced by performing feature extraction on the text blocks contained in the document to obtain text features, and inputting the document title and / or preset text fragments in the document into the large language model to perform document type recognition to obtain the document type, and querying the document element information matching the document type in the document element configuration; or, it can also be replaced by performing feature extraction on the text blocks contained in the document to obtain text features, and performing document type recognition based on the document title and / or preset text fragments in the document to obtain the document type, and querying the document element information matching the document type in the document element configuration, and forming a new implementation method together with the other processing steps provided in this embodiment.
[0038] Step S204: screening the text features according to the document element information to obtain target text features.
[0039] The above-mentioned feature extraction is performed on the text blocks contained in the document to obtain text features, and the first prompt information constructed based on the document is input into the large language model for parsing to obtain the document type, and the document element information matching the document type is queried in the document element configuration. In this step, the target text feature is selected from the text features according to the document element information, so as to realize the screening of text features and improve the pertinence of subsequent answers to document element questions.
[0040] The text feature described in this embodiment may be one or more; the target text feature may be one or more; the document element information may be one or more. In the case where there are multiple document element information, the target text feature may be the target text feature corresponding to each document element information, and the target text feature corresponding to each document element information may also be one or more.
[0041] In practical applications, the number of text features may be large, so a vector database can be introduced to perform feature screening through the text features stored in the vector database to improve the efficiency of feature screening. On the basis of storing the text features in the vector database as mentioned above, feature screening can be performed in the text features stored in the vector database according to the document element information to obtain the target text features.
[0042] In a specific implementation, in order to improve the flexibility of feature screening, in an optional implementation mode provided in this embodiment, in the process of screening features in the text features according to the document element information and obtaining the target text features, the following operations are performed: Reading the document element question or element association information contained in the document element information; Feature screening is performed in the text features according to the document element problem or the element association information to obtain the target text features.
[0043] Among them, the document element questions include relevant questions for document elements. For example, when the document is a contract and the contract type is a labor contract, the document elements include the name of Party A / unit / company, the name of Party B / employee, etc., and the document element questions are "What is the name of Party A / unit / company", "What is the name of Party B / employee". When the document element question is "What is the name of Party A / unit / company", the element-related information is "Party A / unit / company name: Mailing address: Contact information:", and when the document element question is "What is the name of Party B / employee", the element-related information is "Party B / employee name: Mailing address: Mobile phone number:".
[0044] On this basis, in an optional implementation manner provided by this embodiment, in the process of performing feature screening in the text features according to the document element question or the element association information to obtain the target text features, the following operations are performed: Extracting features of the document element problem or the element association information to obtain element problem features or element association features; A similarity calculation is performed between the element question feature or the element association feature and the text feature, and the target text feature is determined from the text features based on the calculated similarity.
[0045] Specifically, in the process of determining the target text feature among the text features based on the calculated similarity, the calculated similarities can be sorted, and the text features corresponding to the similarities whose sorting positions are before the preset positions are screened out in the sorting results as the target text features; the calculated similarity can be the Euclidean distance or the cosine distance.
[0046] In addition, the document element problems and element association information contained in the document element information may also be read, and feature screening may be performed in the text features according to the document element problems and element association information to obtain target text features.
[0047] It should be noted that, in this embodiment, feature screening is performed in the text features according to the document element information, and the process of obtaining the target text features can be performed based on RAG (Retrieval-Augmented Generation) to obtain the target text features.
[0048] Step S206: construct second prompt information according to the target text block corresponding to the target text feature and the document element question included in the document element information.
[0049] The target text feature is obtained by feature screening in the text feature according to the document element information. In this step, the second prompt information is constructed according to the target text block corresponding to the target text feature and the document element question contained in the document element information.
[0050] In practical applications, the target text block corresponding to the target text feature screened out from the text features may be messy. In order to improve the effectiveness of the second prompt information constructed subsequently, and thus improve the efficiency of the subsequent large language model parsing; in an optional implementation manner provided by this embodiment, in the process of constructing the second prompt information according to the target text block corresponding to the target text feature and the document element problem contained in the document element information, the target text block can be sorted according to the position information of the target text block in the document to obtain the sorting result, and the sorting result and the document element problem are written into the second prompt template to obtain the second prompt information; specifically, the following operations can be performed: Determining position information of a plurality of target text blocks in the document, and sorting the plurality of target text blocks according to the position information to obtain a sorting result; The sorting result and the document element question are written into a second prompt template to obtain the second prompt information.
[0051] The position information includes the position order of multiple target text blocks in the document.
[0052] On this basis, optionally, the second prompt template includes a second task field for answering the document element question and a restricted format field for the answer to the document element question.
[0053] Among them, the restricted format field of the answer to the document element question includes a restricted format field that restricts the format of the answer to the document element question output by the large language model, such as the restricted format field is "restrict standard json format" or "restrict txt format"; the restricted format field of the answer to the document element question can be set to any format according to actual needs.
[0054] For example, the second prompt template is [ You are an expert in legal texts. You need to see legal contracts, extract relevant information, and answer relevant questions.
[0055] Legal contract related information: {context} According to the content of the above contract, extract the corresponding information according to the following field descriptions: Field name: xx1, Field description: xxx1 Field name: xx2, Field description: xxx2 Field name: xx3, Field description: xxx3 Please think step by step and answer the questions one by one. The returned data must be in standard JSON format 】; Write the sorting result into context, write the document element identifier into field names xx1, xx2, and xx3, and write the document element question into field descriptions xxx1, xxx2, and xxx3 to obtain the second prompt information:
【 You are an expert in legal texts. You need to see legal contracts, extract relevant information, and answer relevant questions.
[0056] Legal contract related information: {sort results} According to the content of the above contract, extract the corresponding information according to the following field descriptions: Field name: company_name, Field description: What is the name of Party A / Unit / Company? Field name: employee_name, Field description: What is the name of the Party B / employee? Field name: employee_no, Field description: What is the identification number of Party B / employee? Please think step by step and answer the questions one by one. The returned data must be in standard JSON format.
[0057] 】.
[0058] In addition, the above-mentioned operation of writing the sorting result and the document element question into the second prompt template to obtain the second prompt information can also be replaced by inputting the sorting result and the document element question and document element identifier contained in the document element information into the second prompt template to obtain the second prompt information.
[0059] In addition, there is a case where there are multiple document element information. In another optional implementation manner provided by this embodiment, the target text feature includes target text features corresponding to each of the multiple document element information. On this basis, in the process of constructing the second prompt information according to the target text block corresponding to the target text feature and the document element problem included in the document element information, the following operations are performed: Labels are constructed based on each document element information to obtain each label, and target text blocks corresponding to respective target text features are marked based on each label to obtain respective marked text blocks; The marked text block and the document element question are written into a second prompt template to obtain the second prompt information.
[0060] The tags may be element tags, and each tag corresponds to each document element information.
[0061] Specifically, in the process of writing the marked text block and the document element question into the second prompt template to obtain the second prompt information, the marked text block, the document element question and the document element identifier may also be written into the second prompt template to obtain the second prompt information.
[0062] Step S208: input the second prompt information into a large language model for parsing to obtain an answer to the document element question.
[0063] The second prompt information is constructed according to the target text block corresponding to the target text feature and the document element question contained in the document element information. In this step, the second prompt information is input into the large language model for parsing to obtain the answer to the document element question; the large language model here may be the same as the large language model in step S202, or may not be the same.
[0064] In specific implementation, since the large language model does not need to be retrained or fine-tuned, it can be directly deployed and parsed, thereby improving document processing efficiency and convenience. In an optional implementation provided by this embodiment, in the process of inputting the second prompt information into the large language model for parsing to obtain the answer to the document element question, the following operation is performed: the second prompt information is input into the large language model, so that through the large language model, based on the document element question contained in the second prompt information, question-related content is extracted from the target text block, and an answer is generated based on the question-related content to obtain the answer to the question.
[0065] The problem-related content includes the content in the target text block that is related to the document element problem.
[0066] Based on the above-mentioned acquisition of the document uploaded by the user, in an optional implementation manner provided by this embodiment, after the second prompt information is input into the large language model for parsing and processing to obtain the answer to the question about the document element, the following operation is further performed: The answer to the question of the document element is formatted and processed to obtain a converted answer, and the converted answer is sent to the user.
[0067] The format conversion process includes converting the format of the answer to the question into a preset format; the preset format may be a preset format, such as a json format or a txt format. In addition, the preset format may also be other types of formats.
[0068] It should be noted that, in the above-mentioned process of constructing labels based on each document element information to obtain each label, and marking the target text blocks corresponding to the respective target text features based on the each label to obtain the respective marked text blocks, the marked text blocks and the document element question are written into the second prompt template to obtain the second prompt information, and in the process of inputting the second prompt information into the large language model for parsing to obtain the answer to the document element question, the second prompt information can be input into the large language model, so that through the large language model, the question-related content can be extracted from the corresponding marked text block based on the document element question contained in the second prompt information, and the answer can be generated according to the question-related content to obtain the answer to the question.
[0069] After step S208 is executed, there may be a situation where the answer to the document element question output by the large language model is not very accurate. In view of this, in order to further improve the accuracy of the answer to the document element question, the user's feedback information on the answer to the document element question can also be obtained, and the evaluation index of the answer to the question is calculated based on the feedback information, and the model parameters of the large language model are determined according to the evaluation index set including the evaluation index, and the parameters of the large language model are adjusted; after the parameter adjustment, the second prompt information is re-input into the large language model for parsing to obtain the updated answer to the document element question. The evaluation index set here includes the evaluation index or includes the evaluation index and the historical evaluation index.
[0070] The above steps S206 to S208 can be replaced by inputting the target text block corresponding to the target text feature and / or the document element question contained in the document element information into the large language model for answer generation to obtain the answer to the document element question; or, can be replaced by constructing second prompt information based on the target text block corresponding to the target text feature and / or the document element question contained in the document element information, and inputting the second prompt information into the large language model for answer generation to obtain the answer to the document element question.
[0071] It should be supplemented that, each optional implementation method and each feasible execution method in steps S202 to S208 provided in this embodiment can be executed independently as needed, or can be combined and referenced to each other. At the same time, each specific execution step in each optional implementation method or each feasible execution method can also be executed independently or in combination as needed. This embodiment does not make specific limitations on this.
[0072] In summary, the one or more document processing methods provided in this embodiment firstly extract features of text blocks contained in a document to obtain text features, and input first prompt information constructed based on the document into a large language model for parsing to obtain a document type, thereby improving the convenience and efficiency of document type parsing through a large language model, and querying document element information matching the document type in the document element configuration, and secondly, reading document element questions or element association information contained in the document element information, performing feature screening in text features according to the document element questions or element association information, obtaining target text features, determining position information of the target text block in the document, and sorting multiple target text blocks according to the position information to obtain a sorting result, writing the sorting result and the document element question into a second prompt template to obtain second prompt information, and inputting the second prompt information into a large language model for parsing to obtain an answer to the document element question, thereby generating an answer to the question by replacing the text block contained in the document with the target text block, thereby improving the pertinence and efficiency of answer generation by the large language model, and reducing the amount of calculation in the process of answer generation by the large language model.
[0073] The following uses the application of a document processing method provided in this embodiment in a contract scenario as an example to further illustrate the document processing method provided in this embodiment. Figure 3 ,The document processing method applied to the contract scenario specifically includes the following steps.
[0074] Step S302, extracting features from each text block included in the contract document to obtain each text feature, and inputting the first prompt information constructed based on the contract document into the large language model for parsing to obtain the contract type, and querying the contract element information matching the contract type in the contract element configuration.
[0075] Step S304, reading the element association information included in the contract element information, and performing feature screening in each text feature according to the element association information to obtain the target text feature.
[0076] Step S306, determining the position information of the target text block corresponding to the target text feature in the contract document, and sorting the target text block according to the position information to obtain a sorting result.
[0077] Step S308: Write the sorting result and the contract element problem included in the contract element information into a second prompt template to obtain second prompt information.
[0078] Step S310: input the second prompt information into the large language model for parsing and processing to obtain the answer to the question about the contract elements.
[0079] It should be noted that any one of steps S302 to S310 or any combination of multiple steps can be selected from steps S202 to S208 to form a new implementation method according to the needs of implementation deployment; and any one or multiple technical features in the technical scheme composed of steps S302 to S310 can be selected from steps S202 to S208 to form a new implementation method according to the needs of actual deployment, or the technical features in one or more optional implementation methods provided by steps S202 to S208 can be selected to combine into a new implementation method, which will not be elaborated here one by one.
[0080] An embodiment of a document processing device provided in this specification is as follows: In the above-mentioned embodiment, a document processing method is provided, and correspondingly, a document processing device is also provided, which will be described below in conjunction with the accompanying drawings.
[0081] Reference Figure 4 , which shows a schematic diagram of an embodiment of a document processing device provided by this embodiment.
[0082] Since the device embodiment corresponds to the method embodiment, the description is relatively simple, and the relevant parts can refer to the corresponding description of the method embodiment provided above. The device embodiment described below is only illustrative.
[0083] This embodiment provides a document processing device, including: The feature extraction module 402 is configured to extract features from the text blocks contained in the document to obtain text features, and input the first prompt information constructed based on the document into the large language model for parsing to obtain the document type, and query the document element information matching the document type in the document element configuration; A feature screening module 404 is configured to screen the text features according to the document element information to obtain target text features; A prompt construction module 406 is configured to construct second prompt information according to the target text block corresponding to the target text feature and the document element problem included in the document element information; The parsing module 408 is configured to input the second prompt information into the large language model for parsing to obtain an answer to the document element question.
[0084] An embodiment of a document processing device provided in this specification is as follows: Corresponding to the document processing method described above, based on the same technical concept, one or more embodiments of this specification further provide a document processing device, which is used to execute the document processing method provided above. Figure 5 A schematic diagram of the structure of a document processing device provided in one or more embodiments of this specification.
[0085] This embodiment provides a document processing device, including: like Figure 5 As shown, the document processing device may have relatively large differences due to different configurations or performances, and may include one or more processors 501 and memory 502, and the memory 502 may store one or more storage applications or data. Among them, the memory 502 may be a temporary storage or a permanent storage. The application stored in the memory 502 may include one or more modules (not shown in the figure), and each module may include a series of computer executable instructions in the document processing device. Furthermore, the processor 501 may be configured to communicate with the memory 502 to execute a series of computer executable instructions in the memory 502 on the document processing device. The document processing device may also include one or more power supplies 503, one or more wired or wireless network interfaces 504, one or more input / output interfaces 505, one or more keyboards 506, etc.
[0086] In a specific embodiment, the document processing device includes a memory and one or more programs, wherein the one or more programs are stored in the memory, and the one or more programs may include one or more modules, and each module may include a series of computer executable instructions for the document processing device, and the one or more programs are configured to be executed by one or more processors, including computer executable instructions for performing the following: Extracting features of text blocks contained in the document to obtain text features, and inputting first prompt information constructed based on the document into a large language model for parsing to obtain a document type, and searching for document element information matching the document type in a document element configuration; Perform feature screening in the text features according to the document element information to obtain target text features; Constructing second prompt information according to the target text block corresponding to the target text feature and the document element problem included in the document element information; The second prompt information is input into the large language model for parsing to obtain an answer to the document element question.
[0087] An embodiment of a computer-readable storage medium provided in this specification is as follows: Corresponding to the document processing method described above, based on the same technical concept, one or more embodiments of this specification also provide a computer-readable storage medium.
[0088] The computer-readable storage medium provided in this embodiment is used to store computer-executable instructions, and the computer-executable instructions implement the following steps when executed: Extracting features of text blocks contained in the document to obtain text features, and inputting first prompt information constructed based on the document into a large language model for parsing to obtain a document type, and searching for document element information matching the document type in a document element configuration; Perform feature screening in the text features according to the document element information to obtain target text features; Constructing second prompt information according to the target text block corresponding to the target text feature and the document element problem included in the document element information; The second prompt information is input into the large language model for parsing to obtain an answer to the document element question.
[0089] It should be noted that the embodiment of a computer-readable storage medium in this specification and the embodiment of a document processing method in this specification are based on the same inventive concept, so the specific implementation of this embodiment can refer to the implementation of the aforementioned corresponding method, and the repeated parts will not be repeated.
[0090] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referenced to each other. Each embodiment focuses on the differences from other embodiments. For example, the device embodiment, equipment embodiment and computer-readable storage medium embodiment are similar to the method embodiment, so the description is relatively simple. To read the relevant contents in the device embodiment, equipment embodiment and computer-readable storage medium embodiment, please refer to the partial description of the method embodiment.
[0091] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0092] In the 1930s, improvements to a technology could be clearly distinguished as hardware improvements (for example, improvements to circuit structures such as diodes, transistors, switches, etc.) or software improvements (improvements to method flows). However, with the development of technology, many of today's method flow improvements can be regarded as direct improvements to hardware circuit structures. Designers almost always obtain the corresponding hardware circuit structure by programming the improved method flow into the hardware circuit. Therefore, it cannot be said that an improvement in a method flow cannot be implemented using hardware entity modules. For example, a programmable logic device (PLD) (such as a field programmable gate array (FPGA)) is such an integrated circuit whose logical function is determined by the user's programming of the device. Designers can "integrate" a digital system on a PLD by programming it themselves, without having to ask chip manufacturers to design and produce dedicated integrated circuit chips. Moreover, nowadays, instead of manually making integrated circuit chips, this kind of programming is mostly implemented by "logic compiler" software, which is similar to the software compiler used when developing and writing programs, and the original code before compilation must also be written in a specific programming language, which is called hardware description language (HDL). There is not only one kind of HDL, but many kinds, such as ABEL (Advanced Boolean Expression Language), AHDL (Altera Hardware Description Language), Confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), Lava, Lola, MyHDL, PALASM, RHDL (Ruby Hardware Description Language), etc. The most commonly used ones are VHDL (Very-High-Speed Integrated Circuit Hardware Description Language) and Verilog. Those skilled in the art should also know that it is only necessary to program the method flow slightly in the above-mentioned hardware description languages and program it into the integrated circuit, and then it is easy to obtain the hardware circuit that implements the logic method flow.
[0093] The controller may be implemented in any suitable manner, for example, the controller may take the form of a microprocessor or processor and a computer-readable medium storing a computer-readable program code (e.g., software or firmware) executable by the (micro)processor, a logic gate, a switch, an application-specific integrated circuit (ASIC), a programmable logic controller, and an embedded microcontroller, examples of which include but are not limited to the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicone Labs C8051F320, and the memory controller may also be implemented as part of the control logic of the memory. It is also known to those skilled in the art that, in addition to implementing the controller in a purely computer-readable program code manner, the controller may be implemented in the form of a logic gate, a switch, an application-specific integrated circuit, a programmable logic controller, and an embedded microcontroller by logically programming the method steps. Therefore, such a controller may be considered as a hardware component, and the devices for implementing various functions included therein may also be considered as structures within the hardware component. Or even, the devices for implementing various functions may be considered as both software modules for implementing the method and structures within the hardware component.
[0094] The systems, devices, modules or units described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer. Specifically, the computer may be, for example, a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.
[0095] For the convenience of description, the above devices are described in terms of functions and are divided into various units. Of course, when implementing the embodiments of this specification, the functions of each unit can be implemented in the same or multiple software and / or hardware.
[0096] It should be understood by those skilled in the art that one or more embodiments of the present specification may be provided as a method, system or computer program product. Therefore, one or more embodiments of the present specification may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present specification may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0097] This specification is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of this specification. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable test processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable test processing device generate instructions for implementing the process in the flowchart. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0098] These computer program instructions may also be stored in a computer readable memory capable of directing a computer or other programmable test processing device to operate in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0099] These computer program instructions may also be loaded onto a computer or other programmable test processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, whereby the instructions executed on the computer or other programmable device provide for implementing the process described in the flow. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0100] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0101] Memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. Memory is an example of a computer-readable medium.
[0102] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined in this article, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.
[0103] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of features includes not only those features, but also other features not explicitly listed, or also includes features inherent to such process, method, commodity or device. In the absence of further restrictions, features defined by the phrase "including a ..." do not exclude the existence of other identical features in the process, method, commodity or device including the features.
[0104] One or more embodiments of the present specification may be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. One or more embodiments of the present specification may also be practiced in distributed computing environments where tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules may be located in local and remote computer storage media, including storage devices.
[0105] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0106] The above description is only an embodiment of this document and is not intended to limit this document. For those skilled in the art, this document may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of this document should be included in the scope of the claims of this document.
Claims
1. A document processing method, comprising: Extracting features of text blocks contained in the document to obtain text features, and inputting first prompt information constructed based on the document into a large language model for parsing to obtain a document type, and searching for document element information matching the document type in a document element configuration; Perform feature screening in the text features according to the document element information to obtain target text features; Constructing second prompt information according to the target text block corresponding to the target text feature and the document element problem included in the document element information; The second prompt information is input into the large language model for parsing to obtain an answer to the document element question.
2. According to the document processing method of claim 1, the first prompt information is obtained by: Extracting a document title from the document, and extracting a preset text segment from the document; The document title and the preset text segment are written into a first prompt template to obtain the first prompt information.
3. The document processing method according to claim 2, wherein the first prompt template comprises a type field of a plurality of preset document types and a first task field for parsing the document type of the document; The document type is obtained after screening the document type among the multiple preset document types based on the document title and the preset text segment included in the first prompt information.
4. The document processing method according to claim 1, wherein extracting features from the text blocks contained in the document to obtain text features comprises: Divide the document into blocks according to a preset block division strategy to obtain the text blocks; The text block is input into a pre-trained feature extraction model to perform feature extraction to obtain the text features.
5. The document processing method according to claim 1, wherein the step of screening the text features according to the document element information to obtain target text features comprises: Reading the document element question or element association information contained in the document element information; Feature screening is performed in the text features according to the document element problem or the element association information to obtain the target text features.
6. The document processing method according to claim 5, wherein the step of performing feature screening in the text features according to the document element problem or the element association information to obtain the target text features comprises: Extracting features of the document element problem or the element association information to obtain element problem features or element association features; A similarity calculation is performed between the element question feature or the element association feature and the text feature, and the target text feature is determined from the text features based on the calculated similarity.
7. The document processing method according to claim 1, wherein the second prompt information is constructed according to the target text block corresponding to the target text feature and the document element problem contained in the document element information, comprising: Determining position information of a plurality of target text blocks in the document, and sorting the plurality of target text blocks according to the position information to obtain a sorting result; The sorting result and the document element question are written into a second prompt template to obtain the second prompt information.
8. The document processing method according to claim 7, wherein the second prompt template comprises a second task field for answering the document element question and a restricted format field for the answer to the document element question.
9. The document processing method according to claim 1, wherein the step of inputting the second prompt information into a large language model for parsing to obtain an answer to the document element question comprises: The second prompt information is input into a large language model, so that, based on the document element question contained in the second prompt information, question-related content is extracted from the target text block through the large language model, and an answer is generated according to the question-related content to obtain the answer to the question.
10. The document processing method according to claim 1, before the operation of extracting features from the text blocks contained in the document to obtain text features is performed, it also includes: Obtain the document uploaded by the user; After the step of inputting the second prompt information into the large language model for parsing to obtain the answer to the document element question is executed, the method further includes: The answer to the question of the document element is formatted and processed to obtain a converted answer, and the converted answer is sent to the user.
11. The document processing method according to claim 1, wherein the target text feature comprises target text features corresponding to each of a plurality of document element information; The step of constructing the second prompt information according to the target text block corresponding to the target text feature and the document element problem included in the document element information includes: Labels are constructed based on each document element information to obtain each label, and target text blocks corresponding to respective target text features are marked based on each label to obtain respective marked text blocks; The marked text block and the document element question are written into a second prompt template to obtain the second prompt information.
12. A document processing device, comprising: A feature extraction module is configured to extract features from text blocks contained in a document to obtain text features, and to input first prompt information constructed based on the document into a large language model for parsing to obtain a document type, and to query document element information matching the document type in a document element configuration; A feature screening module is configured to screen the text features according to the document element information to obtain target text features; A prompt construction module is configured to construct second prompt information according to the target text block corresponding to the target text feature and the document element problem included in the document element information; The parsing module is configured to input the second prompt information into the large language model for parsing to obtain an answer to the document element question.
13. A document processing device, comprising: processor; and a memory configured to store computer executable instructions that, when executed, cause the processor to: Extracting features of text blocks contained in the document to obtain text features, and inputting first prompt information constructed based on the document into a large language model for parsing to obtain a document type, and searching for document element information matching the document type in a document element configuration; Perform feature screening in the text features according to the document element information to obtain target text features; Constructing second prompt information according to the target text block corresponding to the target text feature and the document element problem included in the document element information; The second prompt information is input into the large language model for parsing to obtain an answer to the document element question.
14. A computer-readable storage medium for storing computer-executable instructions, wherein the computer-executable instructions implement the steps of the method of claim 1 when executed.
Citation Information
Cited By
Document processing method and device
CN120371263A