Document entity and relationship extraction method, device and storage medium
By constructing a graph structure of document entities and using graph neural networks to classify vertices and edges, the problem of incomplete and inaccurate extraction of entity information in visually rich documents is solved, accurate extraction of layout and semantic relationships is achieved, and information is improved. Completeness and accuracy of extraction.
Patent Information
- Application Number
- CN202310425886.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-04-20
- Publication Date
- 2024-09-24
- Estimated Expiration
- 2043-04-20
AI Technical Summary
The existing technology ignores layout relationships when extracting entity information in visual rich documents, resulting in incomplete and inaccurate extraction, and cannot effectively utilize and extract relationships between entities, requiring subsequent modules or models to perform additional relationship extraction.
By constructing the graph structure of the document entities, performing vertex classification and edge classification based on the visual characteristics of the entities and the visual characteristics of the edges between entities, determining the layout relationships, category information and semantic relationships of the entities, and using the structured prediction algorithm of the graph neural network to perform Classification of nodes and edges enables complete and accurate extraction of document entity information.
It improves the accuracy and completeness of document entity information extraction, reduces the complexity of module or model design, and achieves effective extraction of layout information and semantic information.
Smart Images

Figure CN116152841B
Abstract
Description
Technical Field
[0001] The present application relates to the technical fields of computer vision and natural language processing, and in particular to a document entity and relationship extraction method, device and storage medium. Background Art
[0002] In reality, there are often documents with rich visual information, i.e., visually rich documents, such as shopping invoices, orders, reports, etc. The main information in such documents is not only determined by the semantics of each entity in the document, but also related to the relationship between entities. The layout relationship between the visual information and text in the document usually has certain rules in order to express the entities and their relationship information in the document.
[0003] For document information extraction, most existing technologies focus only on entity-level information extraction. For example, most methods regard document entity information extraction as a sequence labeling problem and use named entity recognition methods to extract information from documents. In these methods, the document text is usually obtained through an optical character recognition engine, the text is serialized, and then a classification model is used to classify each text into one of the predefined categories. However, for some documents that rely on layout features, serialization has the technical problem of incomplete and inaccurate document entity information extraction. Summary of the invention
[0004] The embodiments of the present application provide a document entity and relationship extraction method, device and storage medium to solve the technical problem of incomplete and inaccurate extraction of visually rich documents and relationships in the prior art.
[0005] In a first aspect, an embodiment of the present application provides a method for extracting document entities and relationships, including:
[0006] Determine visual features of vertices of a graph structure and visual features of edges of the graph structure; the graph structure has entities in the document as vertices and lines between external frames of the entities as edges;
[0007] Document entity information is determined based on the visual features of the vertices and the visual features of the edges; the document entity information includes layout relationships of entities in the document, category information of the entities, and semantic relationships between the entities.
[0008] In some embodiments, determining the layout relationship of the entities based on the visual features of the vertices and the visual features of the edges includes:
[0009] Edge classification is performed using a graph neural network based on the visual features of the vertices and the visual features of the edges to obtain the layout relationship of the entities.
[0010] In some embodiments, determining the category information of the entity and the semantic relationship between the entities based on the visual features of the vertices and the visual features of the edges includes:
[0011] Obtaining vertex features of the graph structure by concatenating the visual features of the vertices and the semantic features of the vertices;
[0012] Based on the vertex features and the visual features of the edges, a graph neural network is used to classify vertices to obtain category information of the entities, and based on the vertex features and the visual features of the edges, a graph neural network is used to classify edges to obtain semantic relationships between the entities.
[0013] In some embodiments, determining visual features of vertices of the graph structure includes:
[0014] Normalizing pixels of the document image of the document to obtain a grayscale image;
[0015] determining image features of the document based on the grayscale image;
[0016] The visual features of the vertices of the graph structure are determined by using an interpolation method based on the image features.
[0017] In some embodiments, determining the visual features of the edges of the graph structure includes:
[0018] Interpolation is performed around the line connecting the center points of the bounding boxes of any two entities to obtain the visual features of the edge.
[0019] In some embodiments, the method further comprises:
[0020] Based on the semantic features of the serialized text of the document, a multi-layer perceptron is used to perform prediction to obtain entities in the document;
[0021] The semantic features of the serialized texts belonging to the same entity are average-pooled to obtain the semantic features of the vertex.
[0022] In some embodiments, the method further comprises:
[0023] Segmenting and tokenizing the serialized text of the document based on a predefined vocabulary to obtain tokenized words;
[0024] Semantic features of the serialized text are determined based on the tokenized words.
[0025] In a second aspect, an embodiment of the present application provides a document entity and relationship extraction device, including:
[0026] A first determination module is used to determine visual features of vertices of a graph structure and visual features of edges of the graph structure; the graph structure has entities in the document as vertices and lines between external frames of the entities as edges;
[0027] The second determination module is used to determine document entity information based on the visual features of the vertices and the visual features of the edges; the document entity information includes layout relationships of entities in the document, category information of the entities, and semantic relationships between the entities.
[0028] In a third aspect, an embodiment of the present application provides an electronic device, including a memory, a transceiver, and a processor;
[0029] The memory is used to store computer programs; the transceiver is used to send and receive data under the control of the processor; the processor is used to read the computer program in the memory and execute the document entity and relationship extraction method described in the first aspect as above.
[0030] In a fourth aspect, an embodiment of the present application further provides a processor-readable storage medium, wherein the processor-readable storage medium stores a computer program, and the computer program is used to enable the processor to execute the document entity and relationship extraction method described in the first aspect as described above.
[0031] In a fifth aspect, an embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and the computer program is used to enable a computer to execute the document entity and relationship extraction method described in the first aspect as described above.
[0032] In a sixth aspect, an embodiment of the present application further provides a communication device-readable storage medium, wherein the communication device-readable storage medium stores a computer program, and the computer program is used to enable the communication device to execute the document entity and relationship extraction method described in the first aspect above.
[0033] In the seventh aspect, an embodiment of the present application further provides a chip product readable storage medium, wherein the chip product readable storage medium stores a computer program, and the computer program is used to enable the chip product to execute the document entity and relationship extraction method described in the first aspect above.
[0034] The document entity and relationship extraction method, device and storage medium provided in the embodiments of the present application construct a graph structure of document entities, perform vertex classification and edge classification based on the visual features of the entities and the visual features of the edges between the entities, obtain the layout relationship of the entities, the category information of the entities and the semantic relationship between the entities, and realize the extraction of layout information and semantic information in document entities, making the extraction of document entity information more complete and accurate. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, a brief introduction will be given below to the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0036] Figure 1 It is a flowchart of a document entity and relationship extraction method provided in an embodiment of the present application;
[0037] Figure 2 It is a schematic diagram of edge visual feature interpolation of a document entity and relationship extraction method provided in an embodiment of the present application;
[0038] Figure 3 It is a system flow chart of a document entity and relationship extraction method provided by an embodiment of the present application;
[0039] Figure 4 It is a structural diagram of a document entity and relationship extraction device provided in an embodiment of the present application;
[0040] Figure 5 It is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0041] Document information extraction generally refers to extracting predefined structured information from a document. Information extraction from visually rich documents often involves computer vision and natural language processing related technologies. However, information extraction from visually rich documents in the prior art usually only focuses on entity information extraction. On the one hand, due to ignoring the layout relationship, the entity information extraction is inaccurate. On the other hand, since the relationship between entities cannot be utilized and extracted, subsequent modules or models are required to perform additional relationship extraction.
[0042] Based on the above technical problems, an embodiment of the present application proposes a method for extracting document entities and relationships, which extracts visual information from document images, parses semantics from text, and combines visual features and semantic features to determine the categories of target entities and their relationships, thereby improving the accuracy of entity information extraction and reducing the complexity of module or model design.
[0043] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0044] Figure 1 is a flowchart of a document entity and relationship extraction method provided in an embodiment of the present application, such as Figure 1 As shown, the embodiment of the present application provides a method for extracting document entities and relationships. The method includes:
[0045] Step 101: Determine visual features of vertices of a graph structure and visual features of edges of the graph structure; the graph structure uses entities in a document as vertices and lines between bounding boxes of the entities as edges.
[0046] Specifically, an entity in a document refers to a text combination consisting of a single or multiple words. For example, in a shopping receipt, there are multiple entities such as "name", "unit price", and "quantity". After determining the entities in the document, a graph structure is constructed with the entities in the document as vertices and the lines between the external frames of the entities as edges. The edges here represent the relationship between entities. There are many ways to construct the graph structure, for example, composing the graph through the line of sight composition method, or composing the graph in a fully connected manner, or composing the graph using the K nearest neighbor algorithm, etc.
[0047] For the constructed graph structure, the visual features of vertices (i.e., the visual features of entities) and the visual features of edges are determined respectively.
[0048] For example, input the document image to be processed, and extract the image features of the document image based on the convolutional neural network. Obtain the serialized document text and text bounding box through optical character recognition (OCR) of the document image. Then use the pre-trained neural network model to obtain the semantic features of the serialized text, and use the multi-layer perceptron to predict whether adjacent texts or words belong to the same entity based on the semantic features of the text, so as to determine all the entities in the document. Merge the minimum bounding boxes of all texts contained in each entity to obtain the bounding box of the entity. Interpolate the image features of the document, and then obtain the visual features of the entity based on the bounding box of the entity. Interpolate around the line connecting the center points of the bounding boxes of any two entities to obtain the visual features of the edge.
[0049] The document can be input in a variety of ways, for example, by photographing and obtaining a document image, then inputting the document image via Bluetooth or wired transmission, or by inserting storage hardware into the system, etc. For another example, the document can be input by scanning the document.
[0050] Step 102: Determine document entity information based on the visual features of the vertices and the visual features of the edges; the document entity information includes layout relationships of entities in the document, category information of the entities, and semantic relationships between the entities.
[0051] Specifically, the document entity information to be extracted mainly includes the layout relationship of entities in the document, the category information of entities, and the semantic relationship between entities.
[0052] The layout relationship of entities indicates the positional relationship of entities in space, for example, which entities are in the same row or column, or which entities belong to the same cell, etc. These layout relationships can be extracted using graph neural networks based on the applied downstream tasks and tags.
[0053] The category information of an entity refers to the result of classifying the entity. For example, in a shopping receipt, "lemon tea", "tissue paper", and "stapler" are one category, all of which are product names; "2", "1", and "1" are one category, all of which are product quantities; "10.00", "30.00", and "25.00" are one category, all of which are product prices.
[0054] Semantic relations between entities include key-value pair relations, relations indicating which entities describe the same object, or other more complex semantic relations.
[0055] For example, for the object "stapler", there are multiple entities such as "stapler", "1", and "25.00" that describe the object. There is a semantic relationship between these entities, and binary classification is used to determine whether the entities describe the same object.
[0056] For another example, for the object “stapler”, the complex semantic relationship can be (“stapler”, “number”, “1”), (“stapler”, “unit price”, “25.00”), etc., given in the form of (entity a, relationship, entity b).
[0057] The layout relationship of entities is determined based on the visual features of the vertices and the visual features of the edges, and the category information of entities and the semantic relationship between entities are determined based on the visual features and semantic features of the vertices and the visual features of the edges.
[0058] For example, the visual features of vertices are used as vertex features of the graph structure, and the visual features of edges are used as edge features of the graph structure. The graph structure is then input into a graph neural network, and a structured prediction algorithm based on a graph neural network is used to perform node classification and edge classification. The category information of entities can be obtained through node classification, and the layout relationship of entities and the semantic relationship between entities can be obtained through edge classification.
[0059] The document entity and relationship extraction method provided in the embodiment of the present application performs vertex classification and edge classification on the graph structure based on the visual features of the entities and the visual features of the edges in the document, obtains the layout relationships of the entities, entity categories and semantic relationships between entities, and realizes the extraction of entity layout information and visual information in the document, making the extraction of document entity information more complete and accurate.
[0060] In some embodiments, determining the layout relationship of the entities based on the visual features of the vertices and the visual features of the edges includes:
[0061] Edge classification is performed using a graph neural network based on the visual features of the vertices and the visual features of the edges to obtain the layout relationship of the entities.
[0062] Specifically, the visual features of the vertices are used as vertex features of the graph structure, and the visual features of the edges are used as edge features of the graph structure. The structured prediction algorithm of the graph neural network is used to classify the edges of the graph structure, to obtain which edges connect entities in the same row, and to obtain the layout relationship of the entities.
[0063] For example, the initial graph structure is constructed using the line-of-sight composition method. , obtain the visual features of the document entity as the vertex features of the graph structure, and obtain the visual features of the edge as the edge features. Input into the graph neural network, so that the vertex aggregates the neighbor edge features and vertex features, and the edge aggregates the vertex features and edge features, to obtain a prediction graph that better integrates the context information of the entity , then based on The vertex labels and edge labels are used to classify the edges and determine whether the edges connect the same row of entities. If they connect the same row of entities, 1 is output, otherwise 0 is output. The output results are integrated to obtain the layout relationship of the entities.
[0064] For another example, Table 1 is an example of a partial shopping receipt. As shown in Table 1, the entities in the shopping receipt include: "milk", "bread", "lemonade", "2", "1", "1", "5.00", "6.00", "15.00", "10.00", "6.00", "15.00", "Total", and "31.00".
[0065] Table 1 Partial shopping receipts
[0066]
[0067] The vertex features of the graph structure of the shopping receipt are obtained as visual features of the entities, and the edge features are obtained as visual features of the edges. Based on the vertex features and edge features, the edges of the graph structure are classified using a structured prediction algorithm of a graph neural network, and the entities "milk", "2", "5.00", and "10.00" are obtained to be in the same row, "bread", "1", "6.00", and "6.00" are in the same row, "lemonade", "1", "15.00", and "15.00" are in the same row, and "total", "31.00" are in the same row, and edges connecting entities in the same row are obtained, thereby obtaining the layout relationship of the entities.
[0068] The document entity and relationship extraction method provided in the embodiment of the present application uses a structured prediction algorithm based on a graph neural network to better mine context information, not only considering the local feature information of a single vertex, but also considering the joint information between a single vertex and its surrounding vertices and edges, and can achieve more accurate edge classification. In practical applications, the input documents may be tilted, and the layout relationship of the entity can be correctly judged through the above-mentioned layout relationship extraction method, thereby improving the accuracy of entity layout relationship extraction.
[0069] In some embodiments, determining the category information of the entity and the semantic relationship between the entities based on the visual features of the vertices and the visual features of the edges includes:
[0070] Obtaining vertex features of the graph structure by concatenating the visual features of the vertices and the semantic features of the vertices;
[0071] Based on the vertex features and the visual features of the edges, a graph neural network is used to classify vertices to obtain category information of the entities, and based on the vertex features and the visual features of the edges, a graph neural network is used to classify edges to obtain semantic relationships between the entities.
[0072] Specifically, the semantic features of the entity are spliced with the visual features of the entity as the vertex features of the graph structure, and the visual features of the edge are used as the edge features of the graph structure. The structured prediction algorithm of the graph neural network is used to classify the vertices of the graph structure to obtain the category information of the entity, and the edges of the graph structure are classified to determine which entities describe the same object, and to obtain the semantic relationship between entities.
[0073] For example, the initial graph structure is constructed using the line-of-sight composition method. , obtain the visual features and semantic features of the document entity, concatenate the two as the vertex features of the graph structure, and obtain the visual features of the edge as the edge feature. Input into the graph neural network, so that the vertex aggregates the neighbor edge features and vertex features, and the edge aggregates the vertex features and edge features, to obtain a prediction graph that better integrates the context information of the entity , then based on The vertex labels and edge labels are used to perform binary classification on vertices and edges, determine the category of the entity and determine which entities connected by the edges describe the same object, and integrate the output classification results to obtain the category information of the entity and the semantic relationship between entities.
[0074] For another example, as shown in Table 1, the vertex features of the graph structure of the shopping receipt are obtained by concatenating the visual features of the entity and the semantic features of the entity, and the edge features are the visual features of the edge. Based on the vertex features and edge features, the structured prediction algorithm of the graph neural network is used to classify the vertices of the graph structure, and the entities "milk", "bread", and "lemonade" are classified into one category, the entities "2", "1", and "1" are classified into one category, the entities "5.00", "6.00", and "15.00" are classified into one category, the entities "10.00", "6.00", and "15.00" are classified into one category, and the "total" is classified into one category and "31.00" is classified into one category. The classification results are integrated to obtain the category information of the entities; the edges of the graph structure are classified to obtain the entities "milk", "2", "5.00", and "10.00" have a semantic relationship, "bread", "1", "6.00", and "6.00" have a semantic relationship, "lemonade", "1", "15.00", and "15.00" have a semantic relationship, and "total" and "31.00" have a semantic relationship. The edge classification results are integrated to obtain the semantic relationship between the entities. In this example, when multiple price entities are included, the actual meaning of the price can be determined only after the subject of the price is determined. For example, the price "10.00" describes a shopping item named "milk". Only naming the entity "10.00" will not provide valuable information.
[0075] The document entity and relationship extraction method provided in the embodiment of the present application uses a structured prediction algorithm based on a graph neural network to better mine contextual information. It not only considers the local feature information of a single vertex, but also considers the joint information between a single vertex and its surrounding vertices and edges. It can achieve more accurate vertex classification and edge classification, thereby improving the accuracy of extracting entity category information and semantic relationships between entities.
[0076] In some embodiments, determining visual features of vertices of the graph structure includes:
[0077] Normalizing pixels of the document image of the document to obtain a grayscale image;
[0078] determining image features of the document based on the grayscale image;
[0079] The visual features of the vertices of the graph structure are determined by using an interpolation method based on the image features.
[0080] Specifically, to obtain the visual features of the vertices, we first need to obtain the image features of the document, preprocess the image of the document, perform normalization processing to obtain a grayscale image after pixel conversion, and then use a convolutional neural network to extract the image features of the document based on the grayscale image. The image features of the document are interpolated according to the external frame of the entity to obtain the visual features of the entity, that is, to determine the visual features of the vertices of the graph structure.
[0081] For example, to preprocess a document image, suppose a coordinate in the document image is The RGB grayscale value of the pixel is ,in, represents the color of the pixel, The value range of is 0 to 255. The document image is normalized to transform it into a grayscale image. The grayscale value of the pixel after transformation is ,Then based on the convolutional neural network, the image features of the processed document image are extracted,and the image features of the document are interpolated according to the bounding box of the entity to obtain the visual features of the vertex.
[0082] The document entity and relationship extraction method provided in the embodiment of the present application can better extract the image features of the document by normalizing the document image, thereby determining the visual features of the vertices based on the image features, thereby improving the accuracy of obtaining the visual features of the vertices, thereby improving the accuracy of document entity and relationship extraction.
[0083] In some embodiments, determining the visual features of the edges of the graph structure includes:
[0084] Interpolation is performed around the line connecting the center points of the bounding boxes of any two entities to obtain the visual features of the edge.
[0085] Specifically, for each edge, interpolation is performed around the line connecting the center points of the bounding boxes of the corresponding two vertices to obtain the visual features of each edge of the graph.
[0086] For example, Figure 2 is a schematic diagram of edge visual feature interpolation of a document entity and relationship extraction method provided in an embodiment of the present application, such as Figure 2 As shown, the dotted grid represents the feature map, the two solid rectangular boxes represent the bounding boxes corresponding to the vertices, and the points between the bounding boxes represent the interpolation processing performed around the line connecting the center points of the vertex bounding boxes to obtain a fixed-size feature map, that is, the visual feature of the edge.
[0087] The document entity and relationship extraction method provided in the embodiment of the present application determines the visual features of the edge by interpolating around the center line of the entity's external frame, so as to obtain more accurate visual features of the edge, thereby improving the accuracy of document entity and relationship extraction.
[0088] In some embodiments, the method further comprises:
[0089] Based on the semantic features of the serialized text of the document, a multi-layer perceptron is used to perform prediction to obtain entities in the document;
[0090] The semantic features of the serialized texts belonging to the same entity are average-pooled to obtain the semantic features of the vertex.
[0091] Specifically, the text is sorted from top to bottom and from left to right according to the position of the text in the document to obtain the serialized text. Based on the semantic features of the serialized text, a multilayer perceptron (MLP) is used to predict whether adjacent texts belong to the same entity, thereby determining all entities in the document. For texts belonging to the same entity, the semantic features of the text are averaged and pooled to obtain the semantic features of each entity, that is, the semantic features of the vertex.
[0092] For example, for the serialized text: "Lemon Tea 1 5.00 5.00 Bread 2 8.00 16.00 Total21.00", the multi-layer perceptron is used for entity prediction to obtain the entities "Lemon Tea", "1", "5.00", "5.00", "Bread", "2", "8.00", "16.00", "Total", "21.00". Then, the semantic features of the obtained serialized text are averaged and pooled, that is, the semantic features of the text "Lemon" and the semantic features of the text "Tea" are averaged and pooled to obtain the semantic features of the entity "Lemon Tea"; similarly, the semantic features of each other entity are obtained. At the same time, the document image is composed using the line of sight composition method, and the vertices of the graph structure are the entities, so the semantic features of the entity are the semantic features of the vertices.
[0093] The document entity and relationship extraction method provided in the embodiment of the present application predicts entities in a sequence text based on a multi-layer perceptron, and then average-pools the semantic features of the sequence text to obtain the semantic features of each text. It can accurately predict entities in the document text and obtain more accurate semantic features of the entities, thereby realizing the extraction of semantic relationships between entities and improving the accuracy of the semantic relationship extraction.
[0094] In some embodiments, the method further comprises:
[0095] Segmenting and tokenizing the serialized text of the document based on a predefined vocabulary to obtain tokenized words;
[0096] Semantic features of the serialized text are determined based on the tokenized words.
[0097] Specifically, after obtaining the serialized text of the document, word segmentation and tokenization are performed according to a predefined vocabulary to obtain tokenized words, and then the tokenized words are input into a pre-trained model to obtain the semantic features of the text. The pre-trained model can select the language representation model BERT.
[0098] The document entity and relationship extraction method provided in the embodiment of the present application constructs a graph structure of document entities, performs vertex classification and edge classification based on the visual features of the entities and the visual features of the edges between the entities, obtains the layout relationships of the entities, the category information of the entities and the semantic relationships between the entities, and realizes the extraction of layout information and semantic information in document entities, making the extraction of document entity information more complete and accurate.
[0099] The document entity and relationship extraction methods provided in the above embodiments are further described below through specific examples:
[0100] Figure 3 is a system flow chart of a document entity and relationship extraction method provided by an embodiment of the present application, such as Figure 3 As shown, the specific steps of obtaining the layout relationship of document entities, entity categories, and semantic relationships between entities based on the visual features of entities and the visual features of edges between entities are as follows:
[0101] Step 1: Get the document image, document text and text bounding box.
[0102] Specifically, the document to be processed is input into the system to obtain a document image, and then optical character recognition (OCR) is performed to obtain the document text and the text border. The specific input method can be to obtain the document image by photographing, and then input the document image by Bluetooth or wired transmission, or to input the document image by inserting storage hardware into the system, etc.; the document can also be input by scanning the document.
[0103] Step 2: Extract the features of the document image. Specifically including step 2.1 and step 2.2:
[0104] Step 2.1: Preprocess the document image. Assume that a certain coordinate in the document image is The RGB grayscale value of the pixel is ,in, represents the color of the pixel, The value range is 0 to 255. The document image is normalized to transform it into a grayscale image. The grayscale value of the pixel after transformation is expressed as:
[0105]
[0106] in, Represents the gray value of the pixel after transformation; Represents the grayscale value of a pixel in the document image; The function represents the mean function, The values correspond to {0.485, 0.456, 0.406}; The function represents the standard deviation function. The corresponding values are {0.229, 0.224, 0.225} respectively.
[0107] Step 2.2: Extract image features of the document based on convolutional neural network.
[0108] Step 3: Input the document text into the neural network model of the pre-trained language to extract the semantic features of the text, which specifically includes steps 3.1 to 3.3:
[0109] Step 3.1: Serialize the document text, sort it from top to bottom and from left to right according to the text position, and obtain serialized text.
[0110] Step 3.2: Segment and tokenize the obtained serialized text according to a predefined vocabulary to obtain tokenized words.
[0111] Step 3.3: Input the tokenized word into the neural network model of the pre-trained language to obtain the semantic features of the text.
[0112] Step 4: Use the semantic features of the text obtained in step 3 to predict the entity, and then obtain the semantic features of the entity, the bounding box of the entity, and the visual features, including steps 4.1 to 4.4:
[0113] Step 4.1: Based on the semantic features of the text, use a multi-layer perceptron to predict whether adjacent texts belong to the same entity, thereby determining the entity of the document.
[0114] Step 4.2: For texts belonging to the same entity, average pool the semantic features of the texts obtained in step 3 to obtain the semantic features of each entity.
[0115] Step 4.3: The minimum bounding box containing all words belonging to the same entity is taken as the bounding box of the entity.
[0116] Step 4.4: Based on the bounding box of the entity, the visual features of the entity are obtained by interpolation on the image features of the document obtained in step 2.
[0117] Step 5: Compose based on the entity's bounding box and classify the layout relationships, specifically including steps 5.1 to 5.3.
[0118] Step 5.1: Based on the positional relationship of the bounding boxes of each entity, the line-of-sight composition method is used to construct a graph structure. The line-of-sight composition method constructs a line-of-sight (LOS) graph, which captures the visual structure of the document entity well. The graph structure uses the document entity as the vertex and the lines between the entities as the edge. The graph structure can be expressed as ,in, represents the edge set of the graph, Represents the vertex set of the graph. It should be noted that the composition method here can be flexibly selected according to the specific needs of the actual application. In addition to the line of sight composition method, the K nearest neighbor algorithm or full connection method can also be used for composition.
[0119] Step 5.2: Use the visual features of the entity obtained in step 4 as vertex features of the graph structure. Figure 2 As shown, for each edge, interpolation is performed around the line connecting the center points of the bounding box of the corresponding two vertices to obtain the visual features of each edge of the graph. The visual features of the edges are the edge features of the graph structure.
[0120] Step 5.3: Transform the above graph structure It is used as an initial graph input into the graph neural network, and the final prediction graph is obtained using a structured prediction algorithm based on the graph neural network. , prediction graph Better integration of contextual information of document entities, The expression is as follows:
[0121]
[0122] in, Represents the predicted graph with the highest label probability for the vertices and edges of the predicted graph; the argmax() function is used to calculate When the maximum value is taken The value of represents a prediction graph; Represents the initial graph Vertex features of Represents the initial graph The edge features of represents the system weight; represent The edge set of ; represent The vertex set of . represents the probability function, Represents the probability of predicting the labels of graph vertices and edges, which is obtained by mapping the vertex features and edge features output by the graph neural network. The calculation formula is as follows:
[0123]
[0124] in, Represents the graph neural network Layer Vertex Features; Represents the graph neural network Layer edge features; the first The layer message passing characteristics are , which is expressed as follows:
[0125]
[0126] in, , Representation diagram A vertex in Represents a vertex The neighbor vertices of Represents a vertex Neighbor side; Representation diagram No. Layer Vertex Neighbor vertices of Features; represents the message feature extraction function, which is used to extract the features of each pair of vertices and edges. Layer Vertex Features Aggregates neighbor edge features and Layer vertex features, The expression is as follows:
[0127]
[0128] in, Represents the message aggregation function, which is used to aggregate neighbor message features; Represents the feature aggregation function, which is used to fuse vertex and neighbor message features. Layer edge features Aggregated Layer vertex features and Layer edge features, The expression is as follows:
[0129]
[0130] in, Represents the feature aggregation function, which is used to fuse vertex and edge features. The vertex labels and edge labels are used to perform binary classification on the edges to obtain the layout relationship of the document entities.
[0131] Step 6: Utilize the graph structure from step 5.1 Perform entity recognition and classification of semantic relationships between entities, specifically including steps 6.1 and 6.2:
[0132] Step 6.1: Concatenate the semantic features of the entity obtained in step 4 with the visual features of the entity as a graph structure The vertex features of the edge obtained in step 5 are used as the edge features of the graph structure.
[0133] Step 6.2: Structure the above graph As an initial graph input into the graph neural network, the vertices aggregate neighbor edge features and vertex features, the edges aggregate vertex features and edge features, and then the vertices are binary classified to obtain entity categories, and the edges are binary classified to obtain semantic relationships between entities. It should be noted that, except for the difference between the vertex features and the vertex features in step 5.3, the process of vertex and edge classification based on the graph neural network here is basically the same as step 5.3.
[0134] Step 7: Integrate the classification results output from steps 5 and 6 to obtain the final result.
[0135] The document entity and relationship extraction method provided in the embodiment of the present application constructs a graph structure of document entities, performs vertex classification and edge classification based on the visual features of the entities and the visual features of the edges between the entities, obtains the layout relationships of the entities, the category information of the entities and the semantic relationships between the entities, and realizes the extraction of layout information and semantic information in document entities, making the extraction of document entity information more complete and accurate.
[0136] Figure 4 is a schematic diagram of the structure of a document entity and relationship extraction device provided in an embodiment of the present application, such as Figure 4 As shown, an embodiment of the present application provides a document entity and relationship extraction device, including a first determination module 401 and a second determination module 402.
[0137] The first determination module 401 is used to determine the visual features of the vertices of the graph structure and the visual features of the edges of the graph structure; the graph structure has entities in the document as vertices and the lines between the external frames of the entities as edges;
[0138] The second determination module 402 is used to determine document entity information based on the visual features of the vertices and the visual features of the edges; the document entity information includes layout relationships of entities in the document, category information of the entities, and semantic relationships between the entities.
[0139] In some embodiments, the second determining module includes:
[0140] The first classification unit is used to perform edge classification based on the visual features of the vertices and the visual features of the edges using a graph neural network to obtain the layout relationship of the entities.
[0141] In some embodiments, the second determining module further includes:
[0142] A concatenation unit, configured to obtain vertex features of the graph structure by concatenating the visual features of the vertices with the semantic features of the vertices;
[0143] The second classification unit is used to perform vertex classification using a graph neural network based on the vertex features and the visual features of the edges to obtain category information of the entities, and to perform edge classification using a graph neural network based on the vertex features and the visual features of the edges to obtain semantic relationships between the entities.
[0144] In some embodiments, the first determining module includes:
[0145] A first acquisition unit, configured to perform normalization processing on pixels of the document image of the document to obtain a grayscale image;
[0146] A first determining unit, configured to determine an image feature of the document based on the grayscale image;
[0147] The second determining unit is used to determine the visual features of the vertices of the graph structure by using an interpolation method based on the image features.
[0148] In some embodiments, the first determining module further includes:
[0149] The second acquisition unit is used to interpolate around the line connecting the center points of the circumscribed frames of any two entities to obtain the visual features of the edge.
[0150] In some embodiments, it also includes:
[0151] A first acquisition module is used to predict entities in the document using a multi-layer perceptron based on semantic features of the serialized text of the document;
[0152] The second acquisition module is used to average pool the semantic features of the serialized text belonging to the same entity to obtain the semantic features of the vertex.
[0153] In some embodiments, it also includes:
[0154] A third acquisition module is used to segment and tokenize the serialized text of the document based on a predefined vocabulary to obtain tokenized words;
[0155] The third determination module is used to determine the semantic features of the serialized text based on the tokenized words.
[0156] Specifically, the document entity and relationship extraction device provided in the embodiment of the present application can implement all the method steps implemented in the above-mentioned document entity and relationship extraction method embodiment, and can achieve the same technical effect. The parts and beneficial effects of this embodiment that are the same as the method embodiment will not be described in detail here.
[0157] It should be noted that the division of units / modules in the above embodiments of the present application is schematic and is only a logical function division. There may be other division methods in actual implementation. In addition, the functional units in the various embodiments of the present application may be integrated into a processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above integrated units may be implemented in the form of hardware or in the form of software functional units.
[0158] Figure 5 is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application, such as Figure 5 As shown, the electronic device includes a memory 520, a transceiver 500, and a processor 510, wherein:
[0159] The memory 520 is used to store computer programs; the transceiver 500 is used to send and receive data under the control of the processor 510; the processor 510 is used to read the computer program in the memory 520 and execute the above-mentioned document entity and relationship extraction method, the method comprising:
[0160] Determine visual features of vertices of a graph structure and visual features of edges of the graph structure; the graph structure has entities in the document as vertices and lines between external frames of the entities as edges;
[0161] Document entity information is determined based on the visual features of the vertices and the visual features of the edges; the document entity information includes layout relationships of entities in the document, category information of the entities, and semantic relationships between the entities.
[0162] In some embodiments, determining the layout relationship of the entities based on the visual features of the vertices and the visual features of the edges includes:
[0163] Edge classification is performed using a graph neural network based on the visual features of the vertices and the visual features of the edges to obtain the layout relationship of the entities.
[0164] In some embodiments, determining the category information of the entity and the semantic relationship between the entities based on the visual features of the vertices and the visual features of the edges includes:
[0165] Obtaining vertex features of the graph structure by concatenating the visual features of the vertices and the semantic features of the vertices;
[0166] Based on the vertex features and the visual features of the edges, a graph neural network is used to classify vertices to obtain category information of the entities, and based on the vertex features and the visual features of the edges, a graph neural network is used to classify edges to obtain semantic relationships between the entities.
[0167] In some embodiments, determining visual features of vertices of the graph structure includes:
[0168] Normalizing pixels of the document image of the document to obtain a grayscale image;
[0169] determining image features of the document based on the grayscale image;
[0170] The visual features of the vertices of the graph structure are determined using an interpolation method based on the image features.
[0171] In some embodiments, determining the visual features of the edges of the graph structure includes:
[0172] Interpolation is performed around the line connecting the center points of the bounding boxes of any two entities to obtain the visual features of the edge.
[0173] In some embodiments, the method further comprises:
[0174] Based on the semantic features of the serialized text of the document, a multi-layer perceptron is used to perform prediction to obtain entities in the document;
[0175] The semantic features of the serialized texts belonging to the same entity are average-pooled to obtain the semantic features of the vertex.
[0176] In some embodiments, the method further comprises:
[0177] Segmenting and tokenizing the serialized text of the document based on a predefined vocabulary to obtain tokenized words;
[0178] Semantic features of the serialized text are determined based on the tokenized words.
[0179] Specifically, the transceiver 500 is used to receive and send data under the control of the processor 510.
[0180] Among them, Figure 5 In the embodiment, the bus architecture may include any number of interconnected buses and bridges, specifically linking together various circuits of one or more processors represented by processor 510 and memory represented by memory 520. The bus architecture may also link together various other circuits such as peripherals, voltage regulators, and power management circuits, which are well known in the art and are therefore not further described herein. The bus interface provides an interface. The transceiver 500 may be a plurality of components, namely, a transmitter and a receiver, providing a unit for communicating with various other devices on a transmission medium, which transmission medium may include a wireless channel, a wired channel, an optical cable, and the like. The processor 510 is responsible for managing the bus architecture and general processing, and the memory 520 may store data used by the processor 510 when performing operations.
[0181] The processor 510 may be a central processing unit (CPU), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or a complex programmable logic device (CPLD). The processor may also adopt a multi-core architecture.
[0182] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a processor-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) or a processor (processor) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk and other media that can store program code.
[0183] In some embodiments, a computer program product is also provided, which includes a computer program. The computer program can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the document entity and relationship extraction methods provided in the above-mentioned method embodiments.
[0184] Specifically, the above-mentioned computer program product provided in the embodiment of the present application can implement all the method steps implemented by the above-mentioned method embodiments, and can achieve the same technical effect. The parts and beneficial effects of this embodiment that are the same as the method embodiment will not be described in detail here.
[0185] In some embodiments, a computer-readable storage medium is also provided, wherein the computer-readable storage medium stores a computer program, and the computer program is used to enable a computer to execute the document entity and relationship extraction methods provided by the above-mentioned method embodiments.
[0186] Specifically, the above-mentioned computer-readable storage medium provided in the embodiment of the present application can implement all the method steps implemented by the above-mentioned method embodiments, and can achieve the same technical effect. The parts and beneficial effects of this embodiment that are the same as the method embodiment will not be described in detail here.
[0187] It should be noted that the computer-readable storage medium can be any available medium or data storage device that can be accessed by the processor, including but not limited to magnetic storage (such as floppy disks, hard disks, magnetic tapes, magneto-optical disks (MO), etc.), optical storage (such as CD, DVD, BD, HVD, etc.), and semiconductor storage (such as ROM, EPROM, EEPROM, non-volatile memory (NAND FLASH), solid-state drive (SSD)), etc.
[0188] It should also be noted that the terms "first", "second", etc. in the embodiments of the present application are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the terms used in this way can be interchangeable under appropriate circumstances, so that the embodiments of the present application can be implemented in an order other than those illustrated or described here, and the objects distinguished by "first" and "second" are generally of the same type, and the number of objects is not limited. For example, the first object can be one or more.
[0189] In the embodiments of the present application, the term "and / or" describes the association relationship of the associated objects, indicating that three relationships may exist. For example, A and / or B may represent: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the associated objects before and after are in an "or" relationship.
[0190] In the embodiments of the present application, the term "plurality" refers to two or more than two, and other quantifiers are similar.
[0191] In this application, "determine B based on A" means that the factor A should be considered when determining B. It is not limited to "B can be determined based on A alone", but should also include: "determine B based on A and C", "determine B based on A, C and E", "determine C based on A, and further determine B based on C", etc. In addition, it can also include taking A as a condition for determining B, for example, "when A meets the first condition, use the first method to determine B"; for example, "when A meets the second condition, determine B", etc.; for example, "when A meets the third condition, determine B based on the first parameter", etc. Of course, it can also be a condition that takes A as a factor for determining B, for example, "when A meets the first condition, use the first method to determine C, and further determine B based on C", etc.
[0192] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present application 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 and optical storage, etc.) containing computer-usable program codes.
[0193] The present application 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 the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer executable instructions. These computer executable instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. 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.
[0194] These processor executable instructions may also be stored in a processor readable memory that can direct a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the processor 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.
[0195] These processor-executable instructions may also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0196] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.
Claims
1. A document entity and relationship extraction method, characterized in that: include: Normalizing pixels of the document image of the document to obtain a grayscale image; Extracting image features of the document based on the grayscale image using a convolutional neural network; Segmenting and tokenizing the serialized text of the document based on a predefined vocabulary to obtain tokenized words; Inputting the tokenized words into a neural network model of a pre-trained language to obtain semantic features of the serialized text; Based on the semantic features of the text, a multi-layer perceptron is used to predict whether adjacent texts belong to the same entity, thereby obtaining an entity of the document; the entity is a text combination consisting of a single word or multiple words obtained by predicting the semantic features of the serialized text of the document using a multi-layer perceptron; Average pooling is performed on the semantic features of the serialized texts belonging to the same entity to obtain the semantic features of the entity; The minimum bounding box containing all words belonging to the same entity is used as the bounding box of the entity, and the visual features of the entity are determined by using an interpolation method on the image features of the document based on the bounding box of the entity; According to the positional relationship of the external frames of the entity, a graph structure is constructed by adopting a line-of-sight composition method, a K nearest neighbor algorithm, or a full connection method; the graph structure constructed by the line-of-sight composition method is a line-of-sight graph; the graph structure has entities in the document as vertices and lines between the external frames of the entity as edges; Using the visual features of the entity as vertex features of the graph structure, and interpolating around the line connecting the center points of the circumscribed frames of two vertices corresponding to each edge to obtain the visual features of the edge; The graph structure is input into the graph neural network, and a structured prediction algorithm based on the graph neural network is used to obtain a prediction graph. The expression of the prediction graph is as follows: ; in, Represents the predicted graph with the highest label probability for the vertices and edges of the predicted graph; the argmax() function is used to calculate When the maximum value is taken The value of represents the prediction graph; Represents the initial graph Vertex features of Represents the initial graph The edge features of represents the system weight; represent The edge set of ; represent The vertex set of represents the probability function, represents the label probability of the predicted graph vertices and edges, and the label probability of the predicted graph vertices and edges is obtained by mapping the vertex features and edge features output by the graph neural network; the first The expression of the layer message passing characteristic is as follows: ; in, represents the graph neural network Layer messaging features; , Representation diagram A vertex in Represents a vertex The neighbor vertices of Represents a vertex Neighbor side; Representation diagram No. Layer Vertex Neighbor vertices of Features; represents a message feature extraction function, which is used to extract the features of each pair of vertices and edges; the first The layer vertex features are obtained by aggregating the neighbor edge features and the The layer vertex features are obtained, and the expression is as follows: ; in, represents the graph neural network Layer vertex features; Represents the message aggregation function, which is used to aggregate neighbor message features; represents a feature aggregation function, which is used to fuse vertex and neighbor message features; Layer edge features are obtained by aggregating Layer vertex features and The layer edge features are obtained, and the expression is as follows: ; in, represents the graph neural network Layer edge features; Represents the feature aggregation function, which is used to fuse vertex features and edge features; According to the vertex labels and edge labels of the prediction graph, the edges are classified into two types to obtain the layout relationship of the entities; the two types refer to dividing the edges into two types: edges connecting entities in the same row and edges not connecting entities in the same row; Obtaining vertex features of the graph structure by concatenating the visual features of the entity and the semantic features of the entity; Based on the vertex features and the visual features of the edges, a graph neural network is used to classify vertices to obtain category information of the entities, and based on the vertex features and the visual features of the edges, a graph neural network is used to classify edges to obtain semantic relationships between the entities.
2. A document entity and relationship extraction device, characterized in that: include: A normalization module, used for normalizing pixels of a document image of a document to obtain a grayscale image; An image feature determination module, configured to extract image features of the document based on the grayscale image and using a convolutional neural network; A word acquisition module, used for segmenting and tokenizing the serialized text of the document based on a predefined word list to obtain tokenized words; A text semantic feature acquisition module, used for inputting the tokenized words into a neural network model of a pre-trained language to obtain semantic features of the serialized text; An entity prediction module is used to predict whether adjacent texts belong to the same entity based on the semantic features of the text using a multi-layer perceptron to obtain the entity of the document; the entity is a text combination consisting of a single word or multiple words predicted based on the semantic features of the serialized text of the document using a multi-layer perceptron; An entity semantic feature acquisition module, used to average pool the semantic features of serialized texts belonging to the same entity to obtain the semantic features of the entity; The minimum bounding box containing all words belonging to the same entity is used as the bounding box of the entity, and the visual features of the entity are determined by using an interpolation method on the image features of the document based on the bounding box of the entity; A graph structure construction module, used to construct a graph structure by using a line-of-sight composition method, a K-nearest neighbor algorithm, or a full connection method according to the positional relationship of the external frames of the entities; the graph structure constructed by the line-of-sight composition method is a line-of-sight graph; the graph structure has entities in the document as vertices and lines between the external frames of the entities as edges; An edge visual feature acquisition module, used to use the visual features of the entity as vertex features of the graph structure, and to interpolate around the center point connection line of the external frame of two vertices corresponding to each edge to obtain the visual features of the edge; The prediction graph acquisition module is used to input the graph structure into the graph neural network and obtain the prediction graph using the structured prediction algorithm based on the graph neural network. The expression of the prediction graph is as follows: ; in, Represents the predicted graph with the highest label probability for the vertices and edges of the predicted graph; the argmax() function is used to calculate When the maximum value is taken The value of represents the prediction graph; Represents the initial graph Vertex features of Represents the initial graph The edge features of represents the system weight; represent The edge set of ; represent The vertex set of represents the probability function, represents the label probability of the predicted graph vertices and edges, and the label probability of the predicted graph vertices and edges is obtained by mapping the vertex features and edge features output by the graph neural network; the first The expression of the layer message passing characteristic is as follows: ; in, represents the graph neural network Layer messaging features; , Representation diagram A vertex in Represents a vertex The neighbor vertices of Represents a vertex Neighbor side; Representation diagram No. Layer Vertex Neighbor vertices of Features; represents a message feature extraction function, which is used to extract the features of each pair of vertices and edges; the first The layer vertex features are obtained by aggregating the neighbor edge features and the The layer vertex features are obtained, and the expression is as follows: ; in, represents the graph neural network Layer vertex features; Represents the message aggregation function, which is used to aggregate neighbor message features; represents a feature aggregation function, which is used to fuse vertex and neighbor message features; Layer edge features are obtained by aggregating Layer vertex features and The layer edge features are obtained, and the expression is as follows: ; in, represents the graph neural network Layer edge features; Represents the feature aggregation function, which is used to fuse vertex features and edge features; An entity layout relationship acquisition module is used to perform binary classification on the edges according to the vertex labels and edge labels of the prediction graph to obtain the layout relationship of the entities; the binary classification refers to dividing the edges into two types: edges connecting entities in the same row and edges not connecting entities in the same row; A vertex feature acquisition module, used for obtaining vertex features of the graph structure by concatenating the visual features of the entity and the semantic features of the entity; The entity category and semantic relationship acquisition module is used to use a graph neural network to perform vertex classification based on the vertex features and the visual features of the edges to obtain the category information of the entities, and to use a graph neural network to perform edge classification based on the vertex features and the visual features of the edges to obtain the semantic relationships between the entities.
3. An electronic device, characterized in that: Including memory, transceiver, processor; The memory is used to store computer programs; the transceiver is used to send and receive data under the control of the processor; the processor is used to read the computer program in the memory and execute the document entity and relationship extraction method described in claim 1.
4. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and the computer program is used to enable a computer to execute the document entity and relationship extraction method described in claim 1.
