Geometric semantics-based position coding method
Through a position encoding method based on geometric semantics, using sine wave embedding and geometric extractors, the problem of insufficient text position encoding in the existing technology is solved, and stronger generalization ability and more effective geometry in the entity relationship recognition task are achieved. Layout representation.
Patent Information
- Application Number
- CN202410692907.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-31
- Publication Date
- 2024-09-24
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Existing multi-modal pre-training models are difficult to generalize in entity relationship recognition tasks. Text position encoding is not enough to represent geometric layout semantics, and rule-based position encoding is difficult to deeply represent the geometric layout relationship of text elements. It is easy to interpret pre-training data. Overfitting.
A position encoding method based on geometric semantics is designed. By mapping the position coordinates of the text box into a sine wave position embedding encoding, and introducing geometric extractors such as single attributes, pairwise attributes and coverage testing, it combines autocorrelation encoding and self-attention. force mechanism to form a position encoder with more generalization capabilities.
This method significantly improves the generalization ability in the entity relationship recognition task, avoids overfitting of pre-training data, and can more effectively represent the geometric layout relationship of text elements.
Smart Images

Figure CN118690723A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of neural convolutional networks, and in particular to a position encoding method based on geometric semantics. Background Art
[0002] Recent multimodal pre-trained models, such as LayoutLM, encode image features into token sequences together with text tokens. GeoLayoutLM explicitly incorporates geometric relationships as part of its pre-training task. Such multimodal pre-trained models cannot generalize from traditional language modeling (LM) tasks to RE tasks. In other words, the encoding of text positions is not sufficient to represent geometric layout semantics. We summarize the typical encoding methods below: Position Embedding: Early NLP models, such as BERT, map token position indices and index differences into Embeddings. The gradient of the Embedding is calculated by the cross entropy loss of the labeled logits. The coupling of position and context losses often leads to overfitting in the training corpus (i.e., Masked Token classification predictions) rather than trying to explore the underlying layout semantics. Spatial embedding: LayoutLM and subsequent solutions explore spatial information and use the absolute and relative 2D position information of visual elements. However, spatial encoding is only an embedding in 2D space, and faces the same problems in the design of pre-training tasks and gradient update methods. Rule-based positional encoding: Encodings without learnable parameters may alleviate the overfitting problem. However, these attempts are merely transformations of the original layout features without exploring higher-level geometric layout semantics. Some recent models combine learnable and rule-based positional encoders at the same time. Since the models tend to take the approach of fitting the pre-training task, learnable parameters will dominate. RoFormer proposed rotation matrix-based positional encoding (RoPE), which effectively embeds the sinusoidal position into the cross-attention layer. We made appropriate changes to the 2D positional encoding and found that it had good generalization accuracy after the first epoch. However, it stopped updating in accuracy in subsequent epochs. External Relevance: StructuralLM builds on the BERT architecture and incorporates cell positions into the grouping of text chunks. ERNIE-mmLayout explores salient visual regions through clustering to better reflect the inherent neighborhoods of document elements. These architectures reflect document layout in the sense of local spatial neighborhoods. Although spatial neighborhood information is instructive for entity extraction, as shown in the previous section, this information is not sufficient to determine more general relationships. The current rule-based position encoding is difficult to deeply represent the geometric layout relationship of text elements; the embedding-based position encoding tends to overfit the pre-training data, and therefore it is difficult to generalize to more general scenarios. Summary of the invention
[0003] We design a model-based Geometric Layout Semantic Encoding (GTPE) that is fused with text features to produce more specific semantic representations. We also introduce three pre-training tasks to train GTPE into a general position encoder. This model has stronger generalization capabilities in entity relationship recognition. Therefore, the following solution is proposed: A position encoding method based on geometric semantics comprises the following steps: Step 1, input information, map the position coordinates of each text box into a sine waveform position embedding code; Step 2, outputting the position embedding code to a text editor; Step 3, setting a position ID as an index in the text editor, where the index only represents a token index within a word so that the output result is independent of the order of the input information. Preferably, the position coordinates are in the order of upper left corner (x, y) coordinates, upper right corner (x, y) coordinates, lower right corner (x, y) coordinates and lower left corner (x, y) coordinates. Preferably, the embedding coding is performed through autocorrelation coding of a desired layer to obtain a position vector of a predetermined dimension. Preferably, the method further comprises step 4 of encoding the location ID using a decaying frequency sine wave function. Preferably, the attenuation frequency sine wave function is encoded as: Here f(k,t) represents the tth element in the d-dimensional position vector of the kth token. We apply this mapping direction to the 8 position coordinates of the text box. F(P)=[f(P0) f(P1) … f(P8)] Here F(P) represents the position code of a text box at position P, and f(·) represents the d-dimensional vector formed by concatenating f(·,t) for all t, where d is equal to The length of the model dimension, which refers to the dimension of the latent vector representation of the text encoder (here using the modified RoBERTa). is an unordered set. The encoder first N Transform to form a vector representation of query, key, and value. q i =w q (Ei ) k j =w k (E j ) v j =w v (E j ) Here q ,w k ,w v is the transformation matrix, q i ,k j Used to calculate the self-attention weight a ij , and through {a} ij and {v} j Calculate the next layer position encoding {v′} i , Preferably, before step 1, a pre-training task of step 0-1 is also included, and the pre-training task includes a single attribute geometry extractor, a paired attribute geometry extractor and a coverage test geometry extractor. Preferably, the gradient is separated during the back propagation of the token classification task, and only the parameters of the geometric semantics-based position encoding method are corrected in the step 0-1. Preferably, a single attribute extraction method is: Defining the transformation matrix H i Mapped into a 6-dimensional vector, where the subscript i represents the i-th text box and the vector representation, Here C x ,C y is the center point, w and h represent the length and width, A s is the square root of the area (taking the square root instead of the area itself is to prevent data imbalance), and a is the azimuth, that is, the tilt angle of the text box (a is zero when it is placed horizontally). Preferably, the paired attribute extraction method is: Given subscript i,j, use the transformation matrix H j -H i Mapped into four sets of geometric attributes (a total of 15 dimensions), Here R V ,R C ,D V , a respectively represents the relative position coordinates of the four vertices (8 dimensions), the relative coordinates of the center point (2 dimensions), the distance of the four vertices (4 dimensions), and the relative azimuth (1 dimension). Preferably, the coverage test extraction method: Given a rectangular area, use the transformation matrix Convert the rectangular area (expressed in 8-dimensional position coordinates) into a query vector, and use the vector and H-related calculation function to calculate the coverage ratio of each text box (if it is not covered, the ratio is 0). Here W I is the transformation matrix of the relevant operation, ⊙ represents element-wise multiplication (aligning the last dimension D), σ is the sigmoid function, The coverage percentage of each text box is recorded (each element is between 0 and 1). The terms used in this invention include: GTPE (Geometric Transformer for Positional Encoding): The name of the model proposed in this paper. VRD (Visually Rich Document): A rich document generally refers to a document in which text is laid out in a spatial form, such as a form. Token: The smallest unit used to represent text processing in deep learning models, which can also be extended to grid coding of images. Adam et al. pointed out in their paper on model memory and generalization that within the scope of the model's expressiveness, increasing the learning rate, reducing parameters, and lowering the amplitude of the coefficient matrix can improve the generalization effect of the model under certain conditions. In one-dimensional position coding, commonly used coding functions are sine (cosine), etc. The characteristic of this type of function is that it converts the size of the value into a frequency waveform, effectively suppressing the amplitude. BROS (Teakgyu Hong 2022) and SPADE (Wonseok Hwang 2020) use sinusoidal functions for spatial relative position encoding, demonstrating better generalization capabilities. The current mainstream Transformer also uses LayerNorm to control the amplitude in each MLP layer and uses AdamW to regularize the parameters. The sine function shows good generalization ability in downstream tasks, but in pre-training tasks, its convergence speed is slower than the Embedding encoding method. Therefore, it is speculated that the conditions that need to be met to combine the advantages of the two encoding methods are Only encode geometric semantics and do not overfit to the language model pre-training task; Has trainable parameters and sufficient representation capabilities; The numerical distribution of the code is relatively balanced; To meet these conditions, we set up a pre-training task dedicated to geometric attributes, isolate gradient information in the language model pre-training task, and normalize the final output encoding vector. BRIEF DESCRIPTION OF THE DRAWINGS Figure 1 It is a flow chart of the position encoding method based on geometric semantics of the present invention. DETAILED DESCRIPTION
[0004] Transformer is used as the position encoder. When inputting, the 8 position coordinates of each text box (in the order of upper left corner (x, y) coordinates, upper right corner (x, y) coordinates, lower right corner (x, y) coordinates and lower left corner (x, y) coordinates) are mapped into a sine waveform (Ashish Vaswani 2017) position embedding code. This embedding code is subjected to 4 layers of autocorrelation coding to obtain an N×128-dimensional position vector, where N represents the number of text boxes. The position encoding is output to the text encoder, and its basic structure is similar to RoBERTa. We have modified the definition of the position ID (index). In the original structure, the position encoding is the global index of the token, and here the position ID only represents the token index (local index) within the word. The purpose of this is to make the model output independent of the order of the input sequence and only related to the spatial position. Positional encoding (expanding the overall structure in detail) The decaying frequency sine wave function described in (Ashish Vaswani 2017) encodes the location ID. Here f(k,t) represents the tth element in the d-dimensional position vector of the kth token. We apply this mapping direction to the 8 position coordinates of the text box. F(P)=[f(P0) f(P1) … f(P8)]Here F(P) represents the positional encoding of a text box at position P, f(·) represents the d-dimensional vector formed by concatenating f(·,t) for all t, where d is equal to 1 / 8 the length of the model dimension, which refers to the dimension of the latent vector representation of the text encoder (here using the modified RoBERTa). Let is an unordered set. The encoder first N {E}_N transformation to form a vector representation of query, key, and value. q i =w q (E i ) k j =w k (E j ) v j =w v (E j ) Here q ,w k ,w v is the transformation matrix, q i ,k j Used to calculate the self-attention weight a ij a_ij, and through {a} ij and {v} j Calculate the next layer position encoding {v′} i {v^'}_i, Pre-training tasks In addition to using the token classification target task commonly used in pre-trained language models, this paper also designs three pre-training tasks based on layout semantics, corresponding to three types of geometric attribute extractors. H represents the vector representation of all text boxes (it is an N×D-dimensional vector, where D represents the model dimension). The three types of geometric extractors are: Single attribute: For a single text box, calculate the length, width, center point position, azimuth and area; Paired attributes: For two text boxes, calculate the relative positions of the four vertices, the relative position of the center point, the distance and the azimuth; Coverage test: Given a matrix box, calculate the area ratio of each text box covered by the rectangular box; In order to prevent geometric semantics from overfitting to the token classification task, we separated the gradient of the GTPE model during the back propagation of the token classification task and only corrected the parameters of GTPE in the layout semantic pre-training task. The parameters here refer to the parameters of the position encoding sub-model, because the language model itself includes an image sub-model, a text sub-model, and a position encoding sub-model, where the geometric model is a special implementation of the position encoding model and is also the core implementation of this patent. The parameters of the position encoding sub-model, that is, the weights of the model, determine how the position is encoded as a semantic feature. Single attribute extraction method: Defining the transformation matrix H i Mapped into a 6-dimensional vector, where the subscript i represents the i-th text box and the vector representation, Here C x ,C y is the center point, w and h represent the length and width, A sA_s is the square root of the area (taking the square root instead of the area itself is to prevent data imbalance), and a is the azimuth, that is, the tilt angle of the text box (a is zero when it is placed horizontally). Paired attribute extraction method: Given subscript i,j, use the transformation matrix H j -H i _i is mapped into four sets of geometric attributes (a total of 15 dimensions), Here R V ,R C ,D V , a respectively represents the relative position coordinates of the four vertices (8 dimensions), the relative coordinates of the center point (2 dimensions), the distance of the four vertices (4 dimensions), and the relative azimuth (1 dimension). Coverage test extraction method: Given a rectangular area, use the transformation matrix The rectangular area (expressed in 8-dimensional position coordinates) is converted into a query vector, and the vector is used with the H-related calculation function to calculate the coverage ratio of each text box (if it is not covered, the ratio is 0). Here W I W_I is the transformation matrix of the relevant operation, ⊙ represents element-wise multiplication (aligning the last dimension D), σ is the sigmoid function, The coverage percentage of each text box is recorded (each element is between 0 and 1).
[0005] like Figure 1 As shown, in the present invention, a position encoding method based on geometric semantics includes the following steps: Step 1, input information, map the position coordinates of each text box into a sine waveform position embedding code; Step 2, outputting the position embedding code to a text editor; Step 3, setting a position ID as an index in the text editor, where the index only represents a token index within a word so that the output result is independent of the order of the input information. Preferably, the position coordinates are in the order of upper left corner (x, y) coordinates, upper right corner (x, y) coordinates, lower right corner (x, y) coordinates and lower left corner (x, y) coordinates. Preferably, the embedded coding is performed through autocorrelation coding of a desired layer to obtain a position vector of a predetermined dimension. Preferably, the method further comprises step 4 of encoding the location ID using a decaying frequency sine wave function. Preferably, the attenuation frequency sine wave function is encoded as: Here f(k,t) represents the tth element in the d-dimensional position vector of the kth token. We apply this mapping direction to the 8 position coordinates of the text box. F(P)=[f(P0) f(P1) … f(P8)] Here F(P) represents the position code of a text box at position P, and f(·) represents the d-dimensional vector formed by concatenating f(·,t) for all t, where d is equal to The length of the model dimension, which refers to the dimension of the latent vector representation of the text encoder (here using the modified RoBERTa). is an unordered set. The encoder first N Transform to form a vector representation of query, key, and value. q i =w q (E i ) k j =w k (E j ) v j =w v (E j ) Here q ,w k ,w v is the transformation matrix, q i ,k j Used to calculate the self-attention weight a ij , and through {a} ij and {v} j Calculate the next layer position encoding {v′} i , Preferably, before step 1, a pre-training task of step 0-1 is also included, and the pre-training task includes a single attribute geometry extractor, a paired attribute geometry extractor and a coverage test geometry extractor. Preferably, the gradient is separated during the back propagation of the token classification task, and only the parameters of the position encoding method based on geometric semantics are corrected in the step 0-1. The parameters here refer to the parameters of the position encoding sub-model, because the language model itself includes an image sub-model, a text sub-model and a position encoding sub-model, wherein the geometric model is a special implementation of the position encoding model and is also the core implementation of this patent. The parameters of the position encoding sub-model, that is, the weight of the model, determine how the position is encoded as a semantic feature. Preferably, a single attribute extraction method is: Defining the transformation matrix H i Mapped into a 6-dimensional vector, where the subscript i represents the i-th text box and the vector representation, Here C x ,C y is the center point, w and h represent the length and width, A s is the square root of the area (taking the square root instead of the area itself is to prevent data imbalance), and a is the azimuth, that is, the tilt angle of the text box (a is zero when it is placed horizontally). Preferably, the paired attribute extraction method is: Given subscript i,j, use the transformation matrix H j -H i Mapped into four sets of geometric attributes (a total of 15 dimensions), Here R V ,R C ,D V , a respectively represents the relative position coordinates of the four vertices (8 dimensions), the relative coordinates of the center point (2 dimensions), the distance of the four vertices (4 dimensions), and the relative azimuth (1 dimension). Preferably, the coverage test extraction method: Given a rectangular area, use the transformation matrix Convert the rectangular area (expressed in 8-dimensional position coordinates) into a query vector, and use the vector and H-related calculation function to calculate the coverage ratio of each text box (if it is not covered, the ratio is 0). Here W I is the transformation matrix of the relevant operation, ⊙ represents element-wise multiplication (aligning the last dimension D), σ is the sigmoid function, The coverage percentage of each text box is recorded (each element is between 0 and 1). The preferred embodiments of the present invention are exemplarily given above with the aid of the accompanying drawings, but those skilled in the art should understand that, without exceeding the protection scope of the attached claims, those skilled in the art can form new technical solutions by adding features, combining features, etc.
Claims
1. A position encoding method based on geometric semantics, characterized in that: The steps include: Step 1, input information, map the position coordinates of each text box into a sine waveform position embedding code; Step 2, outputting the position embedding code to a text editor; Step 3, setting a position ID as an index in the text editor, where the index only represents a token index within a word so that the output result is independent of the order of the input information.
2. The method for position coding based on geometric semantics according to claim 1, characterized in that: The position coordinates are in the order of upper left corner (x, y) coordinates, upper right corner (x, y) coordinates, lower right corner (x, y) coordinates and lower left corner (x, y) coordinates.
3. The method for position coding based on geometric semantics according to claim 2, characterized in that: The embedded coding is performed through autocorrelation coding of a desired layer to obtain a position vector of a predetermined dimension.
4. The method for position coding based on geometric semantics according to claim 3, characterized in that: The method also includes step 4 of encoding the location ID with a decaying frequency sine wave function.
5. The method for position coding based on geometric semantics according to claim 3, characterized in that: The attenuation frequency sine wave function is encoded as: Here f(k,t) represents the tth element in the d-dimensional position vector of the kth token. We apply this mapping direction to the 8 position coordinates of the text box. F(P)=[f(P0)f(P1)…f(P8)] Here F(P) represents the position code of a text box at position P, and f(·) represents the d-dimensional vector formed by concatenating f(·,t) for all t, where d is equal to The length of the model dimension, which refers to the dimension of the latent vector representation of the text encoder (here using the modified RoBERTa). is an unordered set. The encoder first N Transform to form a vector representation of query, key, and value. q i =w q (E i ) k j =in k (E j ) v j jw v (E j ) Here q ,w k ,w v is the transformation matrix, q i ,k j Used to calculate the self-attention weight a ij , and through {a} ij and {v} j Calculate the next layer position encoding {v′} i , 6. The method for position coding based on geometric semantics according to claim 5, characterized in that: Before step 1, step 0-1 pre-training task is also included, and the pre-training task includes a single attribute geometry extractor, a paired attribute geometry extractor and a coverage test geometry extractor.
7. The method for position coding based on geometric semantics according to claim 6, characterized in that: The gradient is separated during the back propagation of the token classification task, and the parameters of the geometric semantics-based position encoding method are modified only in the step 0-1.
8. The method for position coding based on geometric semantics according to claim 7, characterized in that: Single attribute extraction method: Defining the transformation matrix H i Mapped into a 6-dimensional vector, where the subscript i represents the i-th text box and the vector representation, Here C x ,C y is the center point, w and h represent the length and width, A s is the square root of the area (taking the square root instead of the area itself is to prevent data imbalance), and a is the azimuth, that is, the tilt angle of the text box (a is zero when it is placed horizontally).
9. The method for position coding based on geometric semantics according to claim 8, characterized in that: Paired attribute extraction method: Given subscript i,j, use the transformation matrix H j -H i Mapped into four sets of geometric attributes (a total of 15 dimensions), Here R V ,R C ,D V , a respectively represents the relative position coordinates of the four vertices (8 dimensions), the relative coordinates of the center point (2 dimensions), the distance of the four vertices (4 dimensions), and the relative azimuth (1 dimension).
10. The method for position coding based on geometric semantics according to claim 9, characterized in that: Coverage test extraction method: Given a rectangular area, use the transformation matrix Convert the rectangular area (expressed in 8-dimensional position coordinates) into a query vector, and use the vector and H-related calculation function to calculate the coverage ratio of each text box (if it is not covered, the ratio is 0). Here W I is the transformation matrix of the relevant operation, ⊙ represents element-wise multiplication (aligning the last dimension D), σ is the sigmoid function, The coverage percentage of each text box is recorded (each element is between 0 and 1).
