Method, device and storage medium for extracting structured information from rich text
By constructing text structure diagrams and integrating features, the problem of difficult structured information extraction in rich texts is solved, and efficient and accurate information extraction is achieved.
Patent Information
- Application Number
- CN202510132768.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-06
- Publication Date
- 2025-05-09
- Estimated Expiration
- 2045-02-06
AI Technical Summary
The prior art is difficult to effectively extract structured information in rich texts, due to the problem of diverse formats and excessive useless information.
By constructing a text structure chart, using the text content as nodes and document structure relationships as edges, encoding text features and graph structure features, calculating feature fusion weights, fusing features and predicting the adapted structured data conversion format to extract structured information.
It realizes accurate and flexible extraction of rich texts, and improves the accuracy and applicability of structured information extraction.
Smart Images

Figure CN119557366B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of text processing, and in particular to a method, device and storage medium for extracting structured information from rich text. Background Art
[0002] With the development and popularization of the Internet information age, rich text is usually an important source of text data sources. For example, rich text includes web documents based on Hypertext Markup Language (HTML), office files based on Extensible Markup Language (XML), or notebook files based on Lightweight Markup Language (Markdown).
[0003] However, rich texts often have various formats and contain too much useless information, which makes them impossible to use directly. Therefore, how to extract effective information from rich texts is a technical problem that needs to be solved urgently by technicians in this field. Summary of the invention
[0004] In order to solve the above technical problems, the present application at least provides a method, device and storage medium for extracting structured information from rich text.
[0005] The first aspect of the present application provides a method for extracting structured information from rich text, the method comprising: taking each text content in the original rich text as a node, and the document structure relationship between each text content as an edge, to construct a text structure graph; encoding the text content corresponding to the current node to obtain the text feature corresponding to the current node, and encoding the structural information of the current node in the text structure graph to obtain the graph structure feature corresponding to the current node; obtaining the connection density between the current node and other nodes in the text structure graph and / or the text complexity of the text content corresponding to the current node, and calculating the feature fusion weight corresponding to the current node based on the connection density and / or the text complexity; using the feature fusion weight to fuse the text feature and the graph structure feature corresponding to the current node to obtain the fusion feature corresponding to the current node; predicting the structured data conversion format adapted for the current node based on the fusion feature, and converting the text content corresponding to the current node into the corresponding structured information using the structured data conversion format.
[0006] In one embodiment, the connection density between the current node and other nodes in the text structure graph is obtained, including: counting the number of edges connected to the current node in the text structure graph, and / or counting the number of edges between the current node and the root node, and / or counting the number of paths between the current node and the root node, to obtain the graph structure statistics corresponding to the current node; based on the graph structure statistics corresponding to the current node, the connection density corresponding to the current node is calculated.
[0007] In one embodiment, the text complexity of the text content corresponding to the current node is obtained, including: counting the number of characters in the text content corresponding to the current node, and / or counting the number of sentences in the text content corresponding to the current node, and / or counting the number of paragraphs in the text content corresponding to the current node, to obtain the text statistics corresponding to the current node; based on the text statistics corresponding to the current node, the text complexity corresponding to the current node is calculated.
[0008] In one embodiment, the text features and graph structure features corresponding to the current node are fused using feature fusion weights to obtain a fused feature corresponding to the current node, including: using an attention mechanism to analyze the text features and graph structure features corresponding to the current node to obtain an attention weight; combining the feature fusion weights and the attention weights to perform weighted fusion on the text features and graph structure features corresponding to the current node to obtain a fused feature corresponding to the current node.
[0009] In one embodiment, structural information of the current node in the text structure graph is encoded to obtain graph structural features corresponding to the current node, including: extracting structural information of the current node, encoding the structural information to obtain a node embedding representation of the current node; determining neighboring nodes corresponding to the current node, and obtaining node embedding representations of the neighboring nodes; fusing the node embedding representations of the neighboring nodes and the node embedding representation of the current node to obtain graph structural features corresponding to the current node.
[0010] In one embodiment, the node embedding representations of neighboring nodes and the node embedding representation of the current node are fused to obtain the graph structure features corresponding to the current node, including: calculating the fusion weight between the current node and the neighboring nodes based on the vector distance between the node embedding representation of the current node and the node embedding representation of the neighboring nodes; and performing weighted fusion of the node embedding representations of the neighboring nodes and the node embedding representation of the current node based on the fusion weight between the current node and the neighboring nodes to obtain the graph structure features corresponding to the current node.
[0011] In one embodiment, a structured data conversion format includes a key-value pair, which consists of a key parameter and a value parameter, and different structured data conversion formats correspond to different key parameters; based on the fusion features, the structured data conversion format adapted for the current node is predicted, and the structured data conversion format is used to convert the text content corresponding to the current node into corresponding structured information, including: based on the fusion features, the structured data conversion format adapted for the current node is predicted, and the key parameter corresponding to the adapted structured data format is obtained; the text content corresponding to the current node is used as the value parameter, and the key parameter and value parameter corresponding to the current node are combined to obtain the structured information corresponding to the current node.
[0012] In one embodiment, the method further includes: obtaining screening rules; selecting nodes whose key parameters satisfy the screening rules to obtain information output nodes; obtaining structured information corresponding to each information output node to obtain final output information.
[0013] The second aspect of the present application provides a structured information extraction device for rich text, the device comprising: a graph construction module, used to take each text content in the original rich text as a node, and the document structure relationship between each text content as an edge, to construct a text structure graph; an encoding module, used to encode the text content corresponding to the current node, obtain the text feature corresponding to the current node, and encode the structural information of the current node in the text structure graph, to obtain the graph structure feature corresponding to the current node; a weight calculation module, used to obtain the connection density between the current node and other nodes in the text structure graph and / or the text complexity of the text content corresponding to the current node, and calculate the feature fusion weight corresponding to the current node based on the connection density and / or the text complexity; a feature fusion module, used to fuse the text feature and graph structure feature corresponding to the current node using the feature fusion weight to obtain the fusion feature corresponding to the current node; an information extraction module, used to predict the structured data conversion format adapted for the current node based on the fusion feature, and convert the text content corresponding to the current node into the corresponding structured information using the structured data conversion format.
[0014] A third aspect of the present application provides an electronic device, including a memory and a processor, wherein the processor is used to execute program instructions stored in the memory to implement the above-mentioned method for extracting structured information from rich text.
[0015] A fourth aspect of the present application provides a computer-readable storage medium having program instructions stored thereon, which implement the above-mentioned method for extracting structured information from rich text when the program instructions are executed by a processor.
[0016] The above scheme constructs a text structure graph by taking each text content in the original rich text as a node and the document structure relationship between each text content as an edge; encodes the text content corresponding to the current node to obtain the text feature corresponding to the current node, and encodes the structural information of the current node in the text structure graph to obtain the graph structure feature corresponding to the current node; obtains the connection density between the current node and other nodes in the text structure graph and / or the text complexity of the text content corresponding to the current node, and calculates the feature fusion weight corresponding to the current node based on the connection density and / or the text complexity; uses the feature fusion weight to fuse the text feature and graph structure feature corresponding to the current node to obtain the fusion feature corresponding to the current node; predicts the structured data conversion format adapted for the current node based on the fusion feature, and uses the structured data conversion format to convert the text content corresponding to the current node into the corresponding structured information, which can accurately and flexibly set the feature fusion weight corresponding to each node to improve the feature expression ability of the fusion feature finally obtained for each different node, thereby improving the accuracy and applicability of the structured information extraction of the original rich text.
[0017] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] The drawings herein are incorporated into the specification and constitute a part of the specification. These drawings illustrate embodiments consistent with the present application and are used together with the specification to illustrate the technical solution of the present application.
[0019] Figure 1 is a schematic diagram of a solution implementation environment shown in an exemplary embodiment of the present application;
[0020] Figure 2 is a flowchart of a method for extracting structured information from rich texts shown in an exemplary embodiment of the present application;
[0021] Figure 3 is a schematic diagram of constructing a text structure diagram shown in an exemplary embodiment of the present application;
[0022] Figure 4 is a block diagram of a device for extracting structured information from rich texts shown in an exemplary embodiment of the present application;
[0023] Figure 5 is a schematic structural diagram of an electronic device shown in an exemplary embodiment of the present application;
[0024] Figure 6 It is a schematic diagram of the structure of a computer-readable storage medium shown in an exemplary embodiment of the present application. DETAILED DESCRIPTION
[0025] The scheme of the embodiment of the present application is described in detail below in conjunction with the drawings of the specification.
[0026] In the following description, for the purpose of explanation rather than limitation, specific details such as specific system structures, interfaces, and technologies are provided to facilitate a thorough understanding of the present application.
[0027] The term "and / or" in this article is only an association information describing the associated objects, indicating that there may be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the previous and next associated objects are in an "or" relationship. In addition, "many" in this article means two or more than two. In addition, the term "at least one" in this article means any combination of at least two of any one or more of a plurality of, for example, including at least one of A, B, and C, can mean including any one or more elements selected from the set consisting of A, B, and C.
[0028] The following is a description of the method for extracting structured information from rich text provided in an embodiment of the present application.
[0029] Please refer to Figure 1 , Figure 1 1 is a schematic diagram of a solution implementation environment shown in an exemplary embodiment of the present application. The solution implementation environment may include a terminal 110 and a server 120, and the terminal 110 and the server 120 are connected to each other for communication.
[0030] The number of the terminal 110 may be one or more. The terminal 110 may be a smart phone, a tablet computer, a laptop computer, a desktop computer, a smart speaker, a smart watch, etc., but is not limited thereto.
[0031] Server 120 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers. It can also be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDN), as well as big data and artificial intelligence platforms.
[0032] In one example, the server 120 may extract structured information from the original rich text obtained from the terminal 110 to obtain structured information. Of course, the server 120 may store the structured information locally, transmit it back to the terminal 110, or transmit it to other terminals.
[0033] In one example, a client of a target application is installed and running in the terminal 110. The target application may be an application that provides a structured information extraction function. The target application is used to extract structured information from the original rich text to obtain structured information. The server 120 may be a background server of the target application, which is used to provide background services for the client of the target application.
[0034] In the method for extracting structured information from rich text provided in the embodiment of the present application, the execution subject of each step can be the terminal 110, such as the client of the target application installed and running in the terminal 110, or the server 120, or the terminal 110 and the server 120 can interact and cooperate to execute, that is, part of the steps of the method are executed by the terminal 110 and the other steps are executed by the server 120.
[0035] See also Figure 2 , Figure 2 is a flowchart of a method for extracting structured information from rich texts shown in an exemplary embodiment of the present application. The method for extracting structured information from rich texts can be applied to Figure 1 It should be understood that the method can also be applied to other exemplary implementation environments and be specifically executed by devices in other implementation environments, and this embodiment does not limit the implementation environment to which the method is applicable.
[0036] like Figure 2 As shown, the method for extracting structured information from rich text includes at least steps S210 to S250, which are described in detail as follows:
[0037] Step S210: taking each text content in the original rich text as a node and the document structure relationship between each text content as an edge, to construct a text structure graph.
[0038] Rich Text is a text format that contains formatting information. Compared with Plain Text, Rich Text contains not only text content, but also text style, color, font, size, and embedded images.
[0039] For example, the text content corresponding to each content area in the original rich text can be divided to obtain multiple text contents, and the text contents are respectively used as nodes, and the document structure relationship between the text contents is used as an edge to construct a text structure graph. Among them, the document structure relationship can be obtained by analyzing the format file corresponding to the original rich text.
[0040] For example, obtain the original code file used to render and display the original rich text, parse the original code file to obtain the text content corresponding to each content area, and parse to obtain the association relationship between the text contents to obtain the document structure relationship, and then use the text content as the node and the document structure relationship between the text contents as the edge to construct a text structure graph.
[0041] Take the original rich text as an example of web page rich text, see Figure 3 , Figure 3 is a schematic diagram of constructing a text structure diagram shown in an exemplary embodiment of the present application, such as Figure 3 As shown, the HTML source code of the rich text of the web page and its corresponding DOM tree (Document Object Model Tree) are obtained. By parsing the HTML source code and DOM tree of the rich text of the web page, each text content in the rich text of the web page and the structural path of the DOM tree corresponding to the text content are obtained. For example, the text content "6.4 inches" in the HTML source code corresponds to the DOM tree structure path " / html / body / div / li[1] / div / span[2]". Then html can be used as the root node, body as the subsequent connected node, and span[2] can be constructed in sequence. Similarly, the entire original rich text can be converted into a text structure graph. In the above manner, the DOM tree is converted into a two-dimensional topological structure graph composed of nodes and edges to obtain a text structure graph.
[0042] Of course, for other types of rich text, other methods can be used to construct a text structure diagram, and this application does not limit this. For example, for office documents, the XML file corresponding to the office document or the display layout of the office document can be analyzed to obtain the document structure relationship between each text content and each text content, and obtain a text structure diagram.
[0043] Step S220: Encode the text content corresponding to the current node to obtain the text feature corresponding to the current node, and encode the structural information of the current node in the text structure graph to obtain the graph structure feature corresponding to the current node.
[0044] The current node refers to any node in the text structure graph.
[0045] Text encoding is used to convert text data into digital representation to facilitate subsequent machine learning or deep learning tasks.
[0046] The text content corresponding to the current node can be encoded using one-hot encoding, term frequency-inverse document frequency (TF-IDF) encoding, or word embedding encoding.
[0047] For example, if the original rich text corresponds to i text contents, that is, there are i nodes in the text structure diagram, the text of the original rich text can be represented as ,in represents the text content of the ith node. In addition, the total number of characters contained in the text content of the ith node is N, then the text content of the ith node can be expressed as , Represents the Nth character in the node. Use BERT (Bidirectional Encoder Representations from Transformers) to encode the text content, and input the text content R of each node into the BERT model, as shown in the following formula 1:
[0048] (Formula 1)
[0049] in, , Representation Node The text features of .
[0050] Furthermore, the structural information of the current node in the text structure graph is encoded to obtain the graph structure features corresponding to the current node.
[0051] The structural information of the current node in the text structure graph can be obtained based on the position of the current node in the text structure graph, or the connection relationship between the current node and other nodes, so as to encode the structural information and obtain the graph structure feature corresponding to the current node.
[0052] Step S230: Obtain the connection density between the current node and other nodes in the text structure graph and / or the text complexity of the text content corresponding to the current node, and calculate the feature fusion weight corresponding to the current node based on the connection density and / or text complexity.
[0053] The connection density between the current node and other nodes in the text structure diagram reflects the significance of the structural information of the current node. If the connection density between the current node and other nodes is lower, it indicates that the correlation between the current node and other nodes is lower, that is, the influence of other nodes on the current node is lower, and the significance of the structural information of the current node in the text structure diagram is lower; conversely, if the connection density between the current node and other nodes is higher, it indicates that the correlation between the current node and other nodes is higher, that is, the influence of other nodes on the current node is higher, and the significance of the structural information of the current node in the text structure diagram is higher.
[0054] Exemplarily, obtaining the connection density between the current node and other nodes in the text structure graph includes: counting the number of edges connected to the current node in the text structure graph, and / or counting the number of edges between the current node and the root node, and / or counting the number of paths between the current node and the root node, to obtain the graph structure statistics corresponding to the current node; based on the graph structure statistics corresponding to the current node, calculating the connection density corresponding to the current node;
[0055] In the text structure graph, the number of edges connected to the current node, the number of edges between the current node and the root node, and the number of paths between the current node and the root node are positively correlated with the connection density corresponding to the current node, that is, the more edges connected to the current node in the text structure graph, and / or the more edges between the current node and the root node, and / or the more paths between the current node and the root node, the higher the connection density corresponding to the current node; conversely, the fewer edges connected to the current node in the text structure graph, and / or the fewer edges between the current node and the root node, and / or the fewer paths between the current node and the root node, the lower the connection density corresponding to the current node.
[0056] According to the statistical results of the graph structure corresponding to the current node, the connection density corresponding to the current node is calculated.
[0057] The text complexity of the text content corresponding to the current node reflects the information content of the text content of the current node. If the text complexity of the text content corresponding to the current node is lower, the information content of the text content of the current node is lower; conversely, if the text complexity of the text content corresponding to the current node is higher, the information content of the text content of the current node is higher.
[0058] Exemplarily, obtaining the text complexity of the text content corresponding to the current node includes: counting the number of characters in the text content corresponding to the current node, and / or counting the number of sentences in the text content corresponding to the current node, and / or counting the number of paragraphs in the text content corresponding to the current node, to obtain the text statistics result corresponding to the current node; based on the text statistics result corresponding to the current node, calculating the text complexity corresponding to the current node.
[0059] The number of characters in the text content corresponding to the current node, the number of sentences in the text content corresponding to the current node, and the number of paragraphs in the text content corresponding to the current node are positively correlated with the text complexity corresponding to the current node, that is, the more characters in the text content corresponding to the current node, and / or the more sentences in the text content corresponding to the current node, and / or the more paragraphs in the text content corresponding to the current node, the higher the text complexity corresponding to the current node; conversely, the fewer characters in the text content corresponding to the current node, and / or the fewer sentences in the text content corresponding to the current node, and / or the fewer paragraphs in the text content corresponding to the current node, the lower the text complexity corresponding to the current node.
[0060] According to the text statistics corresponding to the current node, the text complexity corresponding to the current node is calculated.
[0061] After obtaining the connection density and / or text complexity corresponding to the current node, the feature fusion weight corresponding to the current node is calculated based on the connection density and / or text complexity.
[0062] The feature fusion weight includes a weight parameter corresponding to the text feature and / or a weight parameter corresponding to the graph structure feature.
[0063] The connection density is positively correlated with the weight parameter corresponding to the graph structure feature and / or the connection density is negatively correlated with the weight parameter corresponding to the text feature; the text complexity is positively correlated with the weight parameter corresponding to the text feature and / or the connection density is negatively correlated with the weight parameter corresponding to the graph structure feature.
[0064] Based on the connection density and / or text complexity corresponding to the current node, a weight parameter corresponding to the text feature and / or a weight parameter corresponding to the graph structure feature is mapped.
[0065] Step S240: using the feature fusion weight to fuse the text feature and graph structure feature corresponding to the current node, to obtain a fusion feature corresponding to the current node.
[0066] The text features and graph structure features corresponding to the current node are weightedly fused according to the feature fusion weight to obtain the fusion features corresponding to the current node.
[0067] For example, the feature fusion weight includes a weight parameter corresponding to the text feature, and the weight parameter corresponding to the text feature is calculated according to the connection density and / or text complexity.
[0068] For example, if the connection density is a1 and the text complexity is a2, then the weight parameter corresponding to the text feature is , then the text features and graph structure features corresponding to the current node are weighted and fused, which can be expressed as the following formula 2:
[0069] (Formula 2)
[0070] Among them, i represents the sequence number of the current node, is the fusion feature corresponding to the current node, Indicates the weight parameter corresponding to the text feature of the current node, Represents the text feature of the current node, is the graph structure feature corresponding to the current node, and d is the dimension of the feature vector.
[0071] For another example, the feature fusion weight includes a weight parameter corresponding to the graph structure feature, and the weight parameter corresponding to the graph structure feature is calculated according to the connection density and / or text complexity.
[0072] For example, if the connection density is a1 and the text complexity is a2, then the weight parameter corresponding to the graph structure feature is , then the text features and graph structure features corresponding to the current node are weighted and fused, which can be expressed as the following formula 3:
[0073] (Formula 3)
[0074] Among them, i represents the sequence number of the current node, is the fusion feature corresponding to the current node, Represents the weight parameter corresponding to the graph structure feature of the current node, Represents the text feature of the current node, is the graph structure feature corresponding to the current node, and d is the dimension of the feature vector.
[0075] For another example, the feature fusion weight includes a weight parameter corresponding to the text feature and a weight parameter corresponding to the graph structure feature, and the weight parameter corresponding to the text feature and the weight parameter corresponding to the graph structure feature are calculated according to the connection density and / or text complexity.
[0076] For example, if the connection density is a1 and the text complexity is a2, then the weight parameter corresponding to the text feature is , the weight parameter corresponding to the graph structure feature , then the text features and graph structure features corresponding to the current node are weighted and fused, which can be expressed as the following formula 4:
[0077] (Formula 4)
[0078] Among them, i represents the sequence number of the current node, is the fusion feature corresponding to the current node, Indicates the weight parameter corresponding to the text feature of the current node, Represents the weight parameter corresponding to the graph structure feature of the current node, Represents the text feature of the current node, is the graph structure feature corresponding to the current node, and d is the dimension of the feature vector.
[0079] Of course, in addition to the method of calculating feature fusion weights in the above examples, other methods can be used to map connection density and / or text complexity to feature fusion weights, such as using an exponential function to map connection density and / or text complexity to feature fusion weights, which is not limited in this application.
[0080] Step S250: predicting a structured data conversion format suitable for the current node based on the fusion features, and converting the text content corresponding to the current node into corresponding structured information using the structured data conversion format.
[0081] Structured data has a fixed format and structure, such as key-value pairs, table data, etc. The structured data conversion format includes a format template of the structured data and is used to indicate a method of filling text content into the format template.
[0082] The node type to which the current node belongs is obtained based on the fusion feature recognition, so as to query the structured data conversion format corresponding to the node type, obtain the structured data conversion format adapted to the current node, and then use the structured data conversion format to convert the text content corresponding to the current node into the corresponding structured information.
[0083] By fusion features, the structured data conversion format suitable for the current node is predicted, so that the structured information of the current node can be extracted based on the structured data conversion format. Then, by traversing each node, the structured information of the entire original rich text can be extracted.
[0084] The present application encodes nodes based on the text content dimension and the document structure relationship dimension, enriches the feature representation of the nodes, and accurately and flexibly sets the feature fusion weight corresponding to each node according to the connection density between the current node and other nodes in the text structure diagram and / or the text complexity of the text content corresponding to the current node, so as to improve the feature expression ability of the fused features finally obtained for each different node, thereby improving the accuracy and applicability of the structured information extraction of the original rich text.
[0085] Next, some embodiments of the present application are described in detail.
[0086] In some implementations, encoding the structural information of the current node in the text structure graph in step S220 to obtain the graph structure feature corresponding to the current node includes:
[0087] Step S221: extracting the structural information of the current node, encoding the structural information to obtain a node embedding representation of the current node.
[0088] The edge connection relationship between the current node and other nodes is obtained to obtain the structural information of the current node, thereby encoding the structural information of the current node to obtain the node embedding representation of the current node.
[0089] Taking the original rich text as a web page rich text as an example, since the xpath path name corresponding to each node in the DOM tree reflects the structural information of each node, the xpath path name corresponding to the node can be directly encoded to obtain the node embedding representation. Figure 3 The node "span[2]" can be decomposed into "span" to represent the node type and "2" to represent the node serial number. Then two embedding layers are used to encode these two features respectively. Finally, the node embedding representation of the node can be obtained by adding the vectors, as shown in the following formula 5:
[0090] (Formula 5)
[0091] in, Represents the node embedding representation of the current node, Emb1 represents the first embedding layer, Emb2 represents the second embedding layer, Indicates the node type of the current node i, Indicates the sequence number of the current node i.
[0092] Step S222: Determine the neighboring nodes corresponding to the current node, and obtain the node embedding representation of the neighboring nodes.
[0093] Among them, the adjacent nodes refer to the nodes that are connected to the current node and are adjacent to it.
[0094] For example, if there is a direct edge connection with the current node, then the node is determined to be a neighboring node of the current node.
[0095] For another example, if there is a connection path with the current node and the number of edges connected to the current node is less than the edge number threshold, then the node is determined to be a neighboring node of the current node.
[0096] For another example, the nodes with the least number of edges connected to the current node may be traversed in sequence until the number of traversed nodes reaches a node number threshold, and the traversed nodes are used as neighboring nodes of the current node.
[0097] The method of selecting adjacent nodes can be flexibly selected according to actual conditions, and this application does not limit this.
[0098] Exemplarily, an edge number threshold or a node number threshold is determined based on the text complexity corresponding to the current node, and a node whose number of edges connected to the current node is less than the edge number threshold is selected to obtain the neighboring nodes of the current node; or, the nodes with the least number of edges connected to the current node are traversed in sequence until the number of traversed nodes reaches the node number threshold, and the traversed nodes are used as neighboring nodes of the current node.
[0099] Specifically, the text complexity is inversely proportional to the edge number threshold and the node number threshold, so that when the text content of the current node contains less text information, more neighboring nodes are selected to extract features of the current node, so that the graph structure features of the current node can contain more document structure information; when the text content of the current node contains more text information, fewer neighboring nodes are selected to extract features of the current node, saving the computing resources required for graph structure feature extraction.
[0100] Step S223: Fuse the node embedding representations of neighboring nodes and the node embedding representation of the current node to obtain the graph structure features corresponding to the current node.
[0101] By fusing the node embedding representation of the neighboring nodes and the node embedding representation of the current node, the feature information of the neighboring nodes is transferred to the current node, so that the graph structure features corresponding to the current node are finally obtained, which further highlights the structural information in the original rich text.
[0102] In some embodiments, the node embedding representations of neighboring nodes and the node embedding representation of the current node are fused to obtain the graph structure features corresponding to the current node, including: calculating the fusion weight between the current node and the neighboring nodes based on the vector distance between the node embedding representation of the current node and the node embedding representation of the neighboring nodes; and performing weighted fusion of the node embedding representations of the neighboring nodes and the node embedding representation of the current node based on the fusion weight between the current node and the neighboring nodes to obtain the graph structure features corresponding to the current node.
[0103] Specifically, after obtaining the node embedding representation of each node in the result graph, it is necessary to use the feature fusion method for each node and its neighboring nodes to update the features of each node.
[0104] For example, a graph diffusion convolutional neural network model (DCNNs) is used to calculate the feature information between each node and its neighboring nodes, and the final node features are used as the graph structure features of the nodes, as shown in the following formulas 6 and 7:
[0105] (Formula 6)
[0106] (Formula 7)
[0107] Among them, l represents the number of diffusion convolution layers in the diffusion convolutional neural network model, is the node embedding representation of the current node i in layer l, is the node embedding representation of the current node i at the l+1 layer, that is, the graph structure feature corresponding to the updated current node, is the neural network parameter of the lth layer of diffusion convolution, is the set of neighboring nodes of the current node i, is the weight of neighboring node j in the set of neighboring nodes, and the value of k is all neighboring nodes in the set of neighboring nodes. As an activation function, a linear rectified function (Rectified Linear Unit, ReLu) can be used as the activation function, or other functions can be used as the activation function, which is not limited in this application.
[0108] In addition, the weights of different neighboring nodes in the above formula are It is necessary to obtain it by weight normalization in each convolutional layer as shown in Formula 7, which takes into account the different distances of different neighboring nodes and can more accurately calculate the influence of neighboring nodes of different distances on the characteristics of the current node. The node embedding representation of the current node i in the l+1 layer can be used as the graph structure feature corresponding to the current node.
[0109] It should be noted that when performing feature diffusion calculations on nodes, the neural network parameters of each layer of diffusion convolution need to be trained, and the weight of each edge needs to be calculated based on the features of the current diffusion convolution layer. The increase in the number of diffusion convolution layers can improve the fusion capability of node features to a certain extent, but it will also bring more computational complexity to the model, thereby affecting the overall operating efficiency. Considering the efficiency and effect comprehensively, 2 layers of diffusion convolution can be used for calculation. Of course, other layers of diffusion convolution can also be used for calculation according to actual conditions, and this application does not limit this.
[0110] Compared with simply encoding the xpath path as the structural information of the node, the present application constructs a text structure graph and uses the node embedding expression of the current node and the neighboring nodes to aggregate the information of the current node and its neighboring nodes in spatial position, which can effectively reflect the structural information between each node of the rich text and improve the accuracy and versatility of subsequent rich text information extraction.
[0111] In some implementations, in step S240, the text feature and the graph structure feature corresponding to the current node are fused using the feature fusion weight to obtain the fused feature corresponding to the current node, including:
[0112] Step S241: Use the attention mechanism to analyze the text features and graph structure features corresponding to the current node to obtain the attention weight.
[0113] In addition to considering the connection density and / or text complexity of the current node, the attention mechanism can be further used to calculate the weight of the weighted fusion of text features and graph structure features.
[0114] Among them, the attention mechanism network is pre-trained through training samples.
[0115] Step S242: Combine the feature fusion weight and the attention weight to perform weighted fusion on the text feature and graph structure feature corresponding to the current node to obtain the fusion feature corresponding to the current node.
[0116] For example, the feature fusion weight and the attention weight may be weighted and summed to obtain a final weight parameter, and the final weight parameter may be used to weightedly fuse the text feature and the graph structure feature corresponding to the current node to obtain the fusion feature corresponding to the current node.
[0117] For another example, the text feature and graph structure feature corresponding to the current node may be weightedly fused using the feature fusion weight to obtain a first feature; the text feature and graph structure feature corresponding to the current node may be weightedly fused using the attention weight to obtain a second feature; the first feature and the second feature may be concatenated to obtain a fused feature.
[0118] Then, the structured data conversion format suitable for the current node is predicted based on the fusion features, and the text content corresponding to the current node is converted into corresponding structured information using the structured data conversion format.
[0119] For example, a prediction neural network is pre-trained, and the fusion features are input into the prediction neural network to obtain a structured data conversion format adapted to the current node output by the prediction neural network.
[0120] The structured data conversion format includes a key-value pair, which consists of a key parameter (key) and a value parameter (value). Different structured data conversion formats correspond to different key parameters. The key value type of each node is determined by predicting the neural network as an example:
[0121] Specifically, the fusion feature corresponding to the current node i is input into the fully connected layer of the prediction neural network to obtain the hidden feature representation of the neural network , and then the hidden feature is represented by Input into the second fully connected layer of the prediction neural network, and obtain the probability distribution p of the current node i on each key value type through the softmax activation function, as shown in the following formulas 8 and 9:
[0122] (Formula 8)
[0123] (Formula 9)
[0124] in, , To predict the parameter weight matrix that needs to be trained in the neural network, is the fusion feature corresponding to the current node.
[0125] Furthermore, in order to improve the sensitivity of nodes to invalid key types, negative samples can be added to the model during training. By reducing the calculation scores of negative samples, the prediction probability of the model for invalid key value types can be reduced.
[0126] Among them, the cross entropy loss function (Cross Entropy Loss) can be used to train the prediction neural network. Of course, other loss functions can also be used to train the prediction neural network, and this application does not limit this.
[0127] Taking the cross entropy loss function as an example, the calculation formula for training loss is as follows:
[0128] (Formula 10)
[0129] in, is the cross entropy loss function, neg is the negative sample, pos is the positive sample, p is the predicted probability corresponding to the negative sample or positive sample output by the model, is the sample label corresponding to the negative sample or positive sample.
[0130] After the trained prediction neural network predicts the structured data conversion format suitable for the current node, the key value type corresponding to the current node is obtained, and then the text content corresponding to the current node is used as the value parameter. Combined with the key parameter and value parameter corresponding to the current node, the structured information corresponding to the current node is obtained.
[0131] For example, Figure 3 For example, for “Galaxy S20” in the original rich text, the corresponding key value type is predicted to be “name”, and the converted structured information is represented as: (“name”: “Galaxy S20”); for “6.5inch” in the original rich text, the corresponding key value type is predicted to be “size”, and the converted structured information is represented as: (“size”: “6.5 inches”), etc.
[0132] In some implementations, the method further includes: obtaining screening rules; selecting nodes whose key parameters satisfy the screening rules to obtain information output nodes; obtaining structured information corresponding to each information output node to obtain final output information.
[0133] Furthermore, uninteresting keys can be filtered out through screening rules, thereby retaining interesting key-value pairs to extract valid key information from the original rich text and output it as a structured information representation to facilitate information extraction.
[0134] The method for extracting structured information from rich text provided in the present application constructs a text structure graph by taking each text content in the original rich text as a node and the document structure relationship between each text content as an edge; encodes the text content corresponding to the current node to obtain the text feature corresponding to the current node, and encodes the structural information of the current node in the text structure graph to obtain the graph structure feature corresponding to the current node; obtains the connection density between the current node and other nodes in the text structure graph and / or the text complexity of the text content corresponding to the current node, and calculates the feature fusion weight corresponding to the current node based on the connection density and / or the text complexity; uses the feature fusion weight to fuse the text feature and the graph structure feature corresponding to the current node to obtain the fusion feature corresponding to the current node; predicts the structured data conversion format adapted for the current node based on the fusion feature, and uses the structured data conversion format to convert the text content corresponding to the current node into the corresponding structured information, so that the feature fusion weight corresponding to each node can be accurately and flexibly set to improve the feature expression ability of the fusion feature finally obtained for each different node, thereby improving the accuracy and applicability of the structured information extraction of the original rich text.
[0135] Figure 4 FIG. 1 is a block diagram of a structured information extraction device for rich texts shown in an exemplary embodiment of the present application. Figure 4 As shown, the exemplary rich text structured information extraction device 400 includes:
[0136] A graph construction module 410 is used to construct a text structure graph by taking each text content in the original rich text as a node and the document structure relationship between each text content as an edge;
[0137] The encoding module 420 is used to encode the text content corresponding to the current node to obtain the text features corresponding to the current node, and to encode the structural information of the current node in the text structure graph to obtain the graph structure features corresponding to the current node;
[0138] The weight calculation module 430 is used to obtain the connection density between the current node and other nodes in the text structure diagram and / or the text complexity of the text content corresponding to the current node, and calculate the feature fusion weight corresponding to the current node based on the connection density and / or the text complexity;
[0139] A feature fusion module 440 is used to fuse the text feature and the graph structure feature corresponding to the current node using the feature fusion weight to obtain a fusion feature corresponding to the current node;
[0140] The information extraction module 450 is used to predict the structured data conversion format adapted for the current node based on the fusion features, and convert the text content corresponding to the current node into corresponding structured information using the structured data conversion format.
[0141] It should be noted that the structured information extraction device for rich text provided in the above embodiment and the structured information extraction method for rich text provided in the above embodiment belong to the same concept, wherein the specific manner in which each module and unit performs the operation has been described in detail in the method embodiment and will not be repeated here. In practical applications, the structured information extraction device for rich text provided in the above embodiment can allocate the above functions to different functional modules as needed, that is, divide the internal structure of the device into different functional modules to complete all or part of the functions described above, and this is not limited here.
[0142] See also Figure 5 , Figure 5 1 is a schematic diagram of the structure of an embodiment of an electronic device of the present application. The electronic device 500 includes a memory 501 and a processor 502, and the processor 502 is used to execute program instructions stored in the memory 501 to implement the steps in any of the above-mentioned rich text structured information extraction method embodiments. In a specific implementation scenario, the electronic device 500 may include but is not limited to: a microcomputer, a server, and in addition, the electronic device 500 may also include a mobile device such as a laptop computer and a tablet computer, which is not limited here.
[0143] Specifically, the processor 502 is used to control itself and the memory 501 to implement the steps in any of the above-mentioned rich text structured information extraction method embodiments. The processor 502 can also be called a central processing unit (CPU). The processor 502 may be an integrated circuit chip with signal processing capabilities. The processor 502 can also be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. In addition, the processor 502 can be implemented by an integrated circuit chip.
[0144] See also Figure 6 , Figure 6 The computer-readable storage medium 600 stores program instructions 610 that can be executed by a processor, and the program instructions 610 are used to implement the steps in any of the above-mentioned rich text structured information extraction method embodiments.
[0145] In some embodiments, the functions or modules included in the device provided by the embodiments of the present disclosure can be used to execute the method described in the above method embodiments. The specific implementation can refer to the description of the above method embodiments, and for the sake of brevity, it will not be repeated here.
[0146] The above description of various embodiments tends to emphasize the differences between the various embodiments. The same or similar aspects can be referenced to each other, and for the sake of brevity, they will not be repeated herein.
[0147] In the several embodiments provided in the present application, it should be understood that the disclosed methods and devices can be implemented in other ways. For example, the device implementation described above is only schematic. For example, the division of modules or units is only a logical function division. There may be other division methods in actual implementation, such as units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, and the indirect coupling or communication connection of devices or units can be electrical, mechanical or other forms.
[0148] In addition, each functional unit in each embodiment of the present application can be integrated into a processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of a software functional unit. 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 computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or part of the contribution to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor (processor) to perform all or part of the steps of each implementation method of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), disk or optical disk and other media that can store program code.
Claims
1. A method for extracting structured information from rich text, characterized in that: The method comprises: Each text content in the original rich text is used as a node, and the document structure relationship between the text contents is used as an edge to construct a text structure graph; Encode the text content corresponding to the current node to obtain the text feature corresponding to the current node, and encode the structural information of the current node in the text structure graph to obtain the graph structure feature corresponding to the current node; Obtaining the connection density between the current node and other nodes in the text structure graph and / or the text complexity of the text content corresponding to the current node, and calculating the feature fusion weight corresponding to the current node based on the connection density and / or the text complexity; The text feature and the graph structure feature corresponding to the current node are fused using the feature fusion weight to obtain a fusion feature corresponding to the current node; Based on the fusion feature recognition, the node type to which the current node belongs is obtained, the structured data conversion format corresponding to the node type is queried, the structured data conversion format adapted for the current node is obtained, and the structured data conversion format is used to convert the text content corresponding to the current node into corresponding structured information; wherein the structured data conversion format includes a format template for structured data and a method for indicating how to fill the text content into the format template.
2. The method according to claim 1, characterized in that Obtaining the connection density between the current node and other nodes in the text structure graph includes: Counting the number of edges connected to the current node in the text structure graph, and / or counting the number of edges between the current node and a root node, and / or counting the number of paths between the current node and the root node, to obtain a graph structure statistical result corresponding to the current node; Based on the statistical result of the graph structure corresponding to the current node, the connection density corresponding to the current node is calculated.
3. The method according to claim 1, characterized in that Obtaining the text complexity of the text content corresponding to the current node, including: Counting the number of characters in the text content corresponding to the current node, and / or counting the number of sentences in the text content corresponding to the current node, and / or counting the number of paragraphs in the text content corresponding to the current node, to obtain a text statistics result corresponding to the current node; Based on the text statistics corresponding to the current node, the text complexity corresponding to the current node is calculated.
4. The method according to claim 1, characterized in that: The step of fusing the text feature and the graph structure feature corresponding to the current node using the feature fusion weight to obtain the fusion feature corresponding to the current node includes: Analyze the text features and graph structure features corresponding to the current node using the attention mechanism to obtain an attention weight; The feature fusion weight and the attention weight are combined to perform weighted fusion on the text feature and the graph structure feature corresponding to the current node to obtain the fusion feature corresponding to the current node.
5. The method according to claim 1, characterized in that: The encoding of the structural information of the current node in the text structure graph to obtain the graph structure feature corresponding to the current node includes: Extracting structural information of the current node, and encoding the structural information to obtain a node embedding representation of the current node; Determine a neighboring node corresponding to the current node, and obtain a node embedding representation of the neighboring node; The node embedding representation of the neighboring nodes and the node embedding representation of the current node are fused to obtain the graph structure feature corresponding to the current node.
6. The method according to claim 5, characterized in that The fusing the node embedding representation of the neighboring nodes and the node embedding representation of the current node to obtain the graph structure feature corresponding to the current node includes: Calculate a fusion weight between the current node and the neighboring node based on a vector distance between the node embedding representation of the current node and the node embedding representation of the neighboring node; Based on the fusion weight between the current node and the neighboring nodes, the node embedding representation of the neighboring nodes and the node embedding representation of the current node are weightedly fused to obtain the graph structure feature corresponding to the current node.
7. The method according to claim 1, characterized in that The structured data conversion format includes a key-value pair, the key-value pair consists of a key parameter and a value parameter, and different structured data conversion formats correspond to different key parameters; the node type to which the current node belongs is obtained based on the fusion feature recognition, the structured data conversion format corresponding to the node type is queried, the structured data conversion format adapted to the current node is obtained, and the text content corresponding to the current node is converted into corresponding structured information using the structured data conversion format, including: Based on the fusion feature recognition, the node type to which the current node belongs is obtained, the structured data conversion format corresponding to the node type is queried, the structured data conversion format adapted for the current node is obtained, and the key parameters corresponding to the adapted structured data format are acquired; The text content corresponding to the current node is used as a value parameter, and combined with the key parameter and the value parameter corresponding to the current node to obtain the structured information corresponding to the current node.
8. The method according to claim 7, characterized in that The method further comprises: Get the filtering rules; Select nodes whose key parameters satisfy the screening rules to obtain information output nodes; Obtain the structured information corresponding to each information output node to obtain the final output information.
9. An electronic device, characterized in that: The electronic device comprises a memory and a processor, wherein the processor is configured to execute program instructions stored in the memory to implement the steps in the method according to any one of claims 1 to 8.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores program instructions, and the program instructions can be executed by a processor to implement the steps in the method according to any one of claims 1 to 8.
Citation Information
Patent Citations
Information extraction method and device of document graph structure, equipment and storage medium
CN116663557A
Dynamic fusion-based self-adaptive architecture corpus authenticity research and judgment system and method
CN119025677A