Method, device and computing equipment for training page representation model
By training the page representation model and using the layout element categories of the target detection model as labels, we solve the problem of abstract representation of the mini program page content, achieve effective representation of the relationship between page text and layout elements, and improve the efficiency and accuracy of data analysis.
Patent Information
- Application Number
- CN202210454967.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-24
- Publication Date
- 2024-10-11
- Estimated Expiration
- 2042-04-24
AI Technical Summary
The existing technology lacks an effective page abstract representation method, and it is difficult to identify and understand the content in complex mini program pages, especially the relationship between page layout elements and text.
Detect the layout elements of the page through the trained target detection model, and use the element categories of the layout elements as labels to train the page representation model so that it can learn the relationship between the layout elements and text of the page, thereby better representing the text information of the page .
It achieves a more accurate abstract representation of the page content, can better understand the relationship between the text information and layout elements of the page, and improves the efficiency and accuracy of page data analysis.
Smart Images

Figure CN114821616B_ABST
Abstract
Description
Technical Field
[0001] One or more embodiments of the present specification relate to the field of natural language processing, and in particular, to methods, devices, and computing equipment for training page representation models. Background Art
[0002] In the context of the Internet, various pages emerge in an endless stream, including HTML pages, App pages, mini-program pages, etc. In particular, mini-program pages are of various types and have complex contents. Using machine learning models to perform abstract representations on various pages can facilitate the identification of the content that needs attention contained in the page, thereby facilitating further data analysis, such as reviewing whether the content is legal and compliant, whether it infringes on privacy, understanding the entity of the mini-program, etc. However, at present, there is a lack of research on the abstract representation of pages. Therefore, there is an urgent need for a solution to achieve abstract representation of page content, so as to facilitate the understanding of the content of the page. Summary of the invention
[0003] One or more embodiments of the present specification describe a method, apparatus, and computing device for training a page representation model, which detects the element categories of the layout elements of a page through a trained target detection model, and trains the page representation model based on the element categories of the layout elements as labels, so that the page representation model learns the relationship between the layout elements of the page and the text of the page, and thus better represents the text information of the page.
[0004] According to a first aspect, a method for training a page representation model is provided, comprising:
[0005] Acquire a plurality of encoding vectors corresponding to a plurality of objects related to a target page; wherein the plurality of objects include a plurality of first characters located in the target page;
[0006] Using the trained target detection model, detect the calibrated element categories corresponding to the layout elements in the target page to obtain a first result;
[0007] Inputting the multiple encoding vectors into a page representation model, wherein the page representation model processes the multiple encoding vectors based on an attention mechanism to obtain a corresponding multiple representation vectors;
[0008] Determine a second result according to the multiple representation vectors, wherein the second result includes prediction element categories of part or all of the multiple objects;
[0009] Determining a first predicted loss according to the first result and the second result;
[0010] The page representation model is trained according to the first prediction loss.
[0011] According to a possible implementation, determining the first predicted loss based on the first result and the second result includes: migrating the calibrated element category of each layout element in the first result to the multiple first characters to determine a third result; determining the first predicted loss based on the third result and the second result.
[0012] In one embodiment, the method further comprises:
[0013] Performing text detection on the target page to determine the multiple first texts and the first area positions of each of the multiple first texts in the target page; migrating the calibration element category of each layout element in the first result to the multiple first texts, including: for the target layout element in the first result, based on the first area positions of each of the multiple first texts and the second area position of the target layout element in the target page, determining at least one first text in the target layout element, and using the calibration element category of the target layout element as the calibration element category corresponding to the at least one first text it contains.
[0014] In one embodiment of the above implementation, for any character among the multiple first characters, its corresponding encoding vector at least includes a position code and a character embedding vector; wherein the position code is determined based on the first area position corresponding to the character.
[0015] In an embodiment of the above-mentioned implementation manner, the multiple first characters include a target character, and the character embedding vector in the target encoding vector corresponding to the target character is set to represent a masked preset encoding vector; the method also includes: determining the corresponding character prediction result based on the target representation vector corresponding to the target encoding vector in the multiple representation vectors; determining a second prediction loss based on the target character and the character prediction result; the training of the page representation model includes: training the page representation model based on the first prediction loss and the second prediction loss.
[0016] According to a possible implementation, the multiple objects further include a plurality of second characters, and the plurality of second characters represent the name of the application to which the target page belongs.
[0017] In one embodiment, the target page does not include the name of the application.
[0018] In one embodiment, the multiple second characters have a preset element category, and the second result includes a predicted element category for at least a part of the multiple second characters; determining a first prediction loss based on the first result and the second result includes: determining the first prediction loss based on the first result, the preset element category and the second result.
[0019] According to a possible implementation manner, the multiple objects further include multiple sub-pages obtained by segmenting the target page.
[0020] In one embodiment, for any sub-page among the multiple sub-pages, its corresponding encoding vector includes a position code, a graph encoding vector and a sequence code; wherein the position code is determined based on the regional position of the sub-page in the target page, the graph encoding vector is obtained by extracting graph features of the sub-page using a feature extraction network, and the sequence code indicates the order of the sub-page among the multiple sub-pages.
[0021] In one embodiment, the multiple sub-pages include a first sub-page, the first sub-page has multiple layout elements, and the multiple layout elements correspond to multiple calibrated element categories; the second result includes multiple predicted element categories and respective predicted probabilities determined for the first sub-page; the first predicted loss is determined based on the first result and the second result, and also includes: based on the first result, migrating the calibrated element category of each layout element to the multiple sub-pages to determine a fourth result; and determining the first predicted loss based on the first result, the second result and the fourth result.
[0022] In one embodiment, the multiple sub-pages include a second sub-page, and at least one first character in the second sub-page is obscured; the method also includes: determining a fifth result based on the multiple representation vectors, the fifth result including a prediction result of whether the at least one first character is obscured; determining a third prediction loss based on the fifth result; training the page representation model includes: training the page representation model based on the first prediction loss and the third prediction loss.
[0023] According to a second aspect, a device for training a page representation model is provided, comprising:
[0024] An encoding module configured to obtain a plurality of encoding vectors corresponding to a plurality of objects related to a target page; wherein the plurality of objects include a plurality of first characters located in the target page;
[0025] A detection module is configured to use a trained target detection model to detect the calibrated element categories corresponding to the layout elements in the target page to obtain a first result;
[0026] A representation module is configured to input the multiple encoding vectors into a page representation model, and the page representation model processes the multiple encoding vectors based on an attention mechanism to obtain a corresponding multiple representation vectors;
[0027] A prediction module, configured to determine a second result according to the plurality of representation vectors, wherein the second result includes prediction element categories of part or all of the plurality of objects;
[0028] a loss determination module, configured to determine a first predicted loss based on the first result and the second result;
[0029] A training module is configured to train the page representation model according to the first prediction loss.
[0030] According to a third aspect, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed in a computer, the computer is caused to execute the method described in the first aspect.
[0031] According to a fourth aspect, a computing device is provided, comprising a memory and a processor, wherein an executable code is stored in the memory, and when the processor executes the executable code, the method described in the first aspect is implemented.
[0032] In an embodiment of the present specification, the element categories of the layout elements of a page are detected by a trained target detection model, and a page representation model is trained based on the element categories of the layout elements as labels, so that the page representation model learns the relationship between the layout elements of the page and the text of the page, and thus better represents the text information of the page. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative work.
[0034] Figure 1 A schematic diagram showing training of a representation model in one scenario;
[0035] Figure 2 A schematic diagram showing page representation model training in one embodiment;
[0036] Figure 3a An example diagram showing a distillation task according to one embodiment;
[0037] Figure 3b An example diagram showing migration of the marked element category of a layout element to a first character according to an embodiment;
[0038] Figure 4 An example diagram illustrating a VTA task of one embodiment;
[0039] Figure 5 An example diagram illustrating a VMLM task of one embodiment;
[0040] Figure 6 A schematic diagram showing a flow chart of a method for training a page representation model according to an embodiment;
[0041] Figure 7 A schematic diagram showing the structure of an apparatus for training a page representation model according to an embodiment. DETAILED DESCRIPTION
[0042] The solution provided in this specification is described below in conjunction with the accompanying drawings.
[0043] In order to better understand the information expressed by the page, it is usually necessary to implement page representation, so as to facilitate the subsequent analysis and understanding of the page based on the page representation. Here, page representation can be understood as an abstract representation of the information in the page by vectorization, and the representation vector is obtained, that is, the information of the page is quantitatively represented by the representation vector.
[0044] In order to better represent the text information of a page, in one solution, a page representation model is provided, wherein the input is the encoding vector of each of the multiple characters, and the output is the representation vector of each of the multiple characters. The encoding vector corresponding to the character is used to convert the character into a vector input. The page representation model can learn the context information between different characters and obtain the representation vector corresponding to each of the multiple characters, and the representation vector contains the information between the different characters in the page. Figure 1 A schematic diagram showing the training of a page representation model in one scenario. Figure 1 As shown, the encoding vectors of the N characters (i.e., N objects) are E1 to EN respectively, and the page representation model uses E1 to EN as input and T1 to TN as output. The page representation model can be trained by self-supervised learning based on the output of the page representation model. Among them, self-supervised learning can be regarded as an "ideal state" of machine learning. The model learns directly from unlabeled data without the need to annotate data. In addition, the training of the page representation model by self-supervised learning is usually achieved through self-supervised training tasks. Self-supervised training tasks related to text usually include MLM tasks and NSP tasks.
[0045] For the MLM task, the task description is: given a sentence, randomly erase one or several words in the sentence, and predict what the erased words are based on the remaining words.
[0046] When implementing this task, firstly, a certain word is randomly selected from multiple words for prediction with a certain probability, for example, 15%. If the i-th word is selected, it is processed in the following three ways:
[0047] 1) 80% of the time it is [MASK]. For example, my dog is hairy——> my dog is [MASK]
[0048] 2) 10% of the time, it is other random words. For example, my dog is hairy -> my dog is apple
[0049] 3) 10% of the time it is the original text (remains unchanged). For example, my dog is hairy -> my dog is hairy.
[0050] Then, the representation vector corresponding to the i-th word is used to classify all the words in the corpus as the classification target to predict what the original word is, or the probability of belonging to the original word. Among them, the corpus can be understood as a large-scale electronic text library that has been scientifically sampled and processed, which stores language materials that have actually appeared in the actual use of the language, usually including various frequently used words.
[0051] Furthermore, based on the predicted result of the i-th word, the loss is calculated, and the page representation model is trained based on the loss.
[0052] For the NSP task, the task description is: given two sentences in an article, determine whether the second sentence follows the first sentence in the text.
[0053] It should be noted that the MLM task tends to extract representations at the text level, so it cannot directly obtain representations at the sentence level. In order to enable the model to understand the relationship between sentences, the NSP task is used for training, which simply means predicting whether two sentences are connected.
[0054] When implementing this task, for each training sample, sentence A and sentence B are selected from the corpus. 50% of the time, sentence B is the next sentence of sentence A (labeled as IsNext), and the remaining 50% of the time, sentence B is a random sentence in the corpus (labeled as NotNext). Next, the training sample is input into the page representation model for binary classification prediction. Based on the predicted results and the actual results, the loss is calculated, and the page representation model is trained based on the loss.
[0055] However, the text on the page is complex and may include multiple words composed of text, and there is no connection between the previous and next sentences between these words. If the above-mentioned self-supervised training task is adopted, the page representation model can learn the relationship between different texts and the relationship between different sentences, but cannot learn the relationship between the text on the page and other information of the page, such as layout elements (the overall expression of the page layout, which reflects the personality of the page).
[0056] In order to better represent the text information of a page, in some embodiments of the present specification, a distillation task is proposed, that is, the element categories of the layout elements of the page are detected by a trained target detection model, and the element categories of the layout elements are used as labels to train the page representation model, so that the page representation model learns the relationship between the layout elements of the page and the text of the page, and thus better represents the text information of the page.
[0057] Figure 2 An example diagram of page representation model training provided by an embodiment is shown. Figure 2 , describing in detail the five aspects provided by the embodiments of this specification, namely, pages, coding layers, page representation models, self-supervised training tasks (including at least distillation tasks), and downstream tasks.
[0058] First aspect: Page
[0059] The page can be a page of an application. For example, the application can be a web application, and its page can be a web page in html format. The application can also be a terminal App, such as Alipay app, Tmall app, Taobao app; it can also be a mini-program, such as the mini-program in Alipay, etc. Among them, the page includes multiple layout elements. For example, the layout elements may include: product summary, product illustration, button, icon, text block, store name, store location, business hours, etc., which need to be determined in combination with actual conditions, and the embodiments of this specification do not make specific limitations on this. In addition, the embodiments of this specification do not make any limitations on the content of the page, which needs to be determined in combination with actual needs.
[0060] It is worth noting that it is usually necessary to use a large number of pages as samples to build a data set for model training, so as to ensure the accuracy of the page representation model, and the cost of manually obtaining a large number of pages is too high, so the embodiment of this specification obtains the page by automatic screenshot. For example, the full-page screenshots of the pages of Alipay's mini-programs can be taken regularly to obtain a large number of pages. It should be noted that the name of the mini-program may reflect information outside the page, so when taking a screenshot of the mini-program page, the name of the mini-program can be obtained.
[0061] The page includes information such as text and images. In order to better represent the page, the embodiment of this specification represents the page by means of multimodal representation of text and images. Among them, multimodal representation of text and images refers to the abstract representation of the image information and the text information respectively, and then merged into a form of information that has both images and text. It should be noted that the multimodal representation of text and images is only used as an example and does not constitute a specific limitation. In actual applications, the page can also be represented by text representation alone. The following description takes the multimodal representation of text and images as an example.
[0062] When performing multimodal representation of images and text on a page, it is necessary to determine multiple objects to be encoded related to the page. Figure 2 As shown, the multiple objects include multiple characters and multiple sub-pages of a page, and a first separator CLS for distinguishing characters and sub-pages. The multiple characters include characters in a page (referred to as first characters for ease of description and distinction), such as Figure 2 The M first characters are shown: character 1 to character M. Further, considering that the name of the application to which the page belongs may better understand the content of the page, therefore, Figure 2 As shown, the multiple characters may also include characters in the name of the application (referred to as second characters for ease of description and distinction), such as Figure 2 The m second characters are shown: name 1 to name m; correspondingly, a second separator SEP exists in the plurality of objects to distinguish the first character from the second character. It is worth noting that a character is regarded as an object, and a subpage is regarded as an object.
[0063] like Figure 2 As shown, for the first text in the page, the optical character recognition (OCR) technology can be used to perform text recognition on the page. Among them, OCR technology can refer to the detection and recognition of text in an image. For example, OCR technology can include two parts: text detection (Text Detection) and text recognition (Text Recognition). Text detection locates the area of the text in the page, that is, the bounding box of the text is found, which can also be called the target box; text recognition is to recognize the located text. It is worth noting that although the same first text may exist in the page, due to the different positions of the first text, the same first text is treated as different objects.
[0064] It should be understood that when using OCR technology to recognize a page, two parts of content can be obtained: the target frame and the first text. Therefore, the recognition result obtained after optical character recognition of the page includes the coordinate information of each of the multiple target frames and the first text corresponding to each of the multiple target frames; then, the first text corresponding to each target frame in the recognition result is regarded as an object. Here, the coordinate information can be used to illustrate the position of the target frame in the page (referred to as the first coordinate information for the convenience of description), which can usually include the coordinates of the two corner points of the diagonal line of the target frame, which can be specifically expressed as (X1, Y1) and (X2, Y2), where X1, X2 represent the horizontal coordinates, and Y1, Y2 represent the vertical coordinates.
[0065] For multiple sub-pages, N sub-pages can be determined by splitting the page, for example Figure 2 Shown Figure 1 As shown in Figure N, these N images represent N subpages. In actual applications, the subpage has coordinate information, which is used to describe the position of the subpage in the page (referred to as the second coordinate information for ease of description), and may include the coordinates of the two corner points of the diagonal line of the subpage, and the specific performance is the same as the above-mentioned target box. In one example, N subpages are obtained by equally dividing the page. In addition, considering that some pages may be too long, a length threshold can be set to segment pages within the length threshold. For example, N can be 5.
[0066] Aspect 2: Coding Layer
[0067] For any object of the multiple objects, the encoding layer encodes the object to obtain an encoding vector corresponding to the object. The encoding vector can be understood as a vectorized representation of the object, thereby quantifying the object and realizing interaction with the computing device.
[0068] It should be noted that the encoding vector can be designed according to actual conditions, so that the encoding vector can include more information.
[0069] In one example, using a multimodal representation of text and images, the encoding vector of the encoding layer at least integrates token_embedding, 1d position_embedding, 2d position_embedding, and segment_embedding for text. For subpages, the encoding vector of the encoding layer at least integrates image_embedding, 1dposition_embedding, 2d position_embedding, and segment_embedding. Figure 2 As shown, the fusion method can be addition.
[0070] Among them, token_embedding: is to vectorize the text. For example, Figure 2 T1 to Tn and C1 to Cm shown are all token_embeddings.
[0071] Among them, image_embedding: is to vectorize the image. For example, Figure 2 V1 to VN shown are all image_embeddings.
[0072] segment_embedding: Because we are dealing with images (i.e. subpages) and text, we need to distinguish between images and text. Figure 2 As shown, vectors V and T are both segment_embedding, all sub-pages are represented by vector V, and all texts are represented by vector T.
[0073] 1d position_embedding: represents the sequential encoding of the object. Figure 2 As shown in , 1 to m+M+1 are all 1dposition_embedding. Subpages and text are two different types, so they can be encoded separately. For example, Figure 2 As shown, for N sub-pages, they can be numbered in order from top to bottom to determine the sequence number of each of the N sub-pages (generally starting from 0). Figure 2 As shown, the order of the first separator CLS, the second text name 1 to name m, the second separator SEP, the first text character 1 to character M is sorted from 0; for the first text character 1 to character M, they are usually sorted from top to bottom and from left to right; for the second text name 1 to name m, they are sorted from left to right according to the name of the application to which the page belongs. The above sorting method is only an example and does not constitute a specific limitation. The sorting method can be determined in combination with actual conditions.
[0074] 2d position_embedding: represents the 2d position of the object in the page. Figure 2 As shown, B1 to B N +m+M are both 2D position_embedding. For example, the 2D position can be specifically expressed as: (X1, X2, Y1, Y2, W, H). Among them, X1, X2 represent the horizontal coordinates, Y1, Y2 represent the vertical coordinates, W represents the width value, which is equal to X1-X2, and H represents the height value, which is equal to Y1-Y2.
[0075] For a subpage, the 2D position can be determined based on the second coordinate information of the subpage. For a first character, the 2D position is determined based on the first coordinate information of the character. In addition, for the second character, the 2D position can be manually pre-set, and the 2D position is usually in an area outside the page.
[0076] It is worth noting that since the encoding vector integrates the above four embeddings, for text, it can be considered to include the vectorized representation of the text (token_embedding), sequential encoding (1d position_embedding), position encoding (2d position_embedding) and word distinction information (segment_embedding); for sub-pages, the encoding vector can be considered to include the vectorized representation of the sub-page (image_embedding), sequential encoding (1d position_embedding), position encoding (2d position_embedding) and image distinction information (segment_embedding).
[0077] Illustratively, the embedding layer includes a feature extraction network, a word vector table, a position vector table, and a graph-word vector table.
[0078] The feature extraction network is used to extract the semantic information of the sub-page to output the image feature vector. For each sub-page, the sub-page is substituted into the feature extraction network, and the corresponding image_embedding is determined based on the output of the feature extraction network.
[0079] It should be noted that before the sub-page is input into the feature extraction network, the image size needs to be adjusted to a set size so as to meet the input size requirement of the feature extraction network. For example, the set size may be 224*224.
[0080] For example, the feature extraction network can be a convolutional neural network, which first extracts the feature map of the sub-page, then average-pools it to a fixed size, then expands the average-pooled feature map row by row, and then performs linear projection to obtain the image_embedding corresponding to the sub-page.
[0081] For example, the feature extraction network can be a vit (Vision Transformer) model, which is used to divide the subpage into multiple sub-graphs, and then linearize these sub-graphs respectively to obtain the one-dimensional vectors of the multiple sub-graphs; determine the one-dimensional vector of the global tag, and then process the one-dimensional vectors of the multiple sub-graphs and the global tag through the Transformer encoder to extract image information, and obtain the semantic vectors of the multiple sub-graphs and the global tag. Then, image_embedding can be the vector after the semantic vectors of the multiple sub-graphs are fused, or it can be the semantic vector corresponding to the global tag. Here, the Transformer encoder is an encoder based on the attention mechanism.
[0082] The position vector table includes respective encoding vectors of the horizontal coordinate, the vertical coordinate, the width value, and the height value.
[0083] For example, for the 2D position (X1, X2, Y1, Y2, W, H) of any object, the position vector table can be checked to determine the respective encoding vectors of X1, X2, Y1, Y2, W, H, and these encoding vectors are fused (for example, added) to obtain the 2D position_embedding of the object.
[0084] The sorted bit vector table includes a plurality of encoding vectors for respective sequential encodings.
[0085] For any object, based on the sequence number of the object, the encoding vector corresponding to the sequence number, that is, 1d position_embedding, can be determined by looking up the sorting bit vector table.
[0086] Among them, the character vector table includes the encoding vectors of a large number of characters.
[0087] For any character, by looking up the character vector table, you can determine the representation vector corresponding to the character, that is, token_embedding.
[0088] The graph-word vector table includes graph distinction vectors and word distinction vectors.
[0089] like Figure 2 As shown, Figures 1 to 5 The respective graph distinction vectors are V, and the respective word distinction vectors of T1 to Tn and C1 to Cm are T.
[0090] Aspect 3: Page representation model
[0091] The page representation model takes the encoding vectors of multiple objects as input and outputs the representation vectors corresponding to the multiple objects.
[0092] The page representation model is a model based on the attention mechanism. In one embodiment, it can be formed by stacking Transformer encoders, and correspondingly, the dimensions of the encoding vector and the representation vector are the same, for example, both can be 768 dimensions. In addition, this embodiment does not intend to impose any limitation on the model structure of the page representation model, and any model based on the attention mechanism can be used, which needs to be determined in combination with actual conditions.
[0093] Fourth aspect: self-supervised training tasks
[0094] First, the distillation task provided in the embodiments of this specification is described.
[0095] The embodiment of this specification adopts a distillation task (referred to as a TTP task for ease of description) to train a page representation model, so that the page representation model learns the relationship between the layout elements of the page and the text of the page.
[0096] Before describing the distillation task, we first explain knowledge distillation. Knowledge distillation uses the Teacher-Student model, where the teacher is the output of "knowledge" and the student is the receiver of "knowledge". The process of knowledge distillation is divided into two stages: Original model training: Training the "Teacher model", which is characterized by a relatively complex model and can also be integrated from multiple separately trained models. There are no restrictions on the "Teacher model" regarding the model architecture, number of parameters, or whether it is integrated. The only requirement is that for input X, it can output Y, where Y is mapped by a mapping function (such as the softmax function), and the output value corresponds to the probability value of the corresponding category. Simplified model training: Training the "Student model", which is a single model with a small number of parameters and a relatively simple model structure. Similarly, for input X, it can output Y, and Y can also output the probability value of the corresponding category after being mapped by a mapping function (such as the softmax function).
[0097] Figure 3a An example diagram of a distillation task according to an embodiment is shown. Figure 3aAs shown, for the TTP task provided in the embodiment of this specification, the task description is: using a pure image dimension target detection model, predicting the layout elements in the page and their corresponding calibration element categories, and migrating the calibration element categories to the first text in the predicted layout elements, constructing a sample label, that is, the calibration element category corresponding to the first text; then, using the representation vector corresponding to the text output by the page representation model to substitute into the distillation task model (usually a classification model) for classification prediction, determine the prediction result, that is, the predicted element category or predicted category probability distribution corresponding to some or all of the texts in multiple objects (including the probability corresponding to each of all predicted element categories, all predicted element categories can at least include calibration element categories and preset element categories, and the preset element category is a category set for the second text that is different from the calibration element category); then, determine the prediction loss based on the sample label and the prediction result, and train the page representation model based on the prediction loss, so that the layout between the image and the text is adapted, which greatly improves the model effect. Among them, the prediction loss can be determined based on whether the predicted element category corresponding to the text and the calibration element category are the same, and can also be determined based on the probability that the predicted element category corresponding to the text is the calibration element category.
[0098] Furthermore, based on the prediction loss, the page representation model and the distillation task model can be trained simultaneously. At this time, the combination of the page representation model and the distillation task model can be understood as a student model. The object detection model can be understood as a teacher model, and its output can be the calibrated element category of the layout element, or the calibrated category probability distribution of the layout element (including the probabilities corresponding to all calibrated element categories). If it is a calibrated category probability distribution, the prediction loss is determined based on the error between the calibrated category probability distribution corresponding to the first text and the predicted category probability distribution. It should be understood that the feature extraction network, the word vector table, the position vector table, and the image-word vector table are usually pre-trained and do not need to participate in the training of the above-mentioned student model; however, in some possible implementations, the combination of the page representation model, the feature extraction network, the word vector table, the position vector table, the image-word vector table, and the distillation task model can be trained as a student model.
[0099] It is worth noting that the embodiments of this specification adopt the concept of knowledge distillation, using the feature that the student model learns the knowledge of the teacher model, so that the page representation model learns the relationship between the layout elements of the page and the text of the page. However, it does not require the student model to be a model with a small number of parameters and a relatively simple model structure. The model structure of the student model can be flexibly designed according to actual needs without considering the model structure of the teacher model.
[0100] Figure 3b An example diagram showing the migration of the marked element category of the layout element to the first text in one embodiment. Figure 3bAs shown, the page is input into the target detection model. In actual applications, the target detection model outputs the coordinate information of the target box (referred to as the third coordinate information for the convenience of description and distinction) and the calibration element category. However, in order to facilitate the clear description of the technical solution, the embodiment of this specification illustrates the content of the target box in the page; then, the calibration element category corresponding to the target box is used as the calibration element category of the text in the content corresponding to the page; wherein the calibration element category is represented by a number, for example, 1 represents an icon, 2 represents an illustration, and 3 represents a button.
[0101] Then, the image-text alignment task (referred to as VTA task for the convenience of description) provided in the embodiment of this specification is described.
[0102] For the VTA task, it helps the page representation model to align the position of the text and the sub-page. The task description is: randomly mask a part of the first text on the sub-page, use the representation vector corresponding to the text output by the page representation model to perform binary classification, and predict whether the text is blocked.
[0103] Figure 4 FIG. 1 is a schematic diagram of a graphic-text alignment task provided by an embodiment. Figure 4 As shown, a portion of the first text in the page is randomly masked, and then the page is divided into N sub-pages, that is, Figure 1 To Figure N; when executing the VTA task, randomly select some text, and for any selected text, substitute the representation vector of the text output by the page representation model into the image-text alignment task model for binary classification to predict whether the text is blocked. Among them, the image-text alignment task model can be a binary classification model. The embodiment of this specification does not impose any limitation on the model structure of the image alignment task model, and any model that can achieve binary classification can be used.
[0104] Afterwards, the VMLM tasks provided by the embodiments of this specification are described.
[0105] For the VMLM task, the task description is: given a sentence and an image containing the sentence, randomly erase one or several identical words in the sentence and the image, and predict what the erased words are based on the remaining words.
[0106] Figure 5 FIG. 2 shows a schematic diagram of a VMLM task provided by an embodiment. Figure 5 As shown in the figure, for the masked word embedding vectors T1 and C2, the areas occupied by name 1 and word 2 corresponding to T1 and C2 in the page are masked at the same time, so that the model cannot obtain the information of name 1 and word 2 from the information in the sub-page. The masked text is restored through other information, and then the page is divided into N sub-pages, that is, Figure 1To Figure N; when performing the VTA task, the representation vector T1o corresponding to the word embedding vector T1 is substituted into the VMLM task model for prediction to obtain the prediction result corresponding to name 1, which can be the predicted text or the probability value belonging to name 1. Here, the VMLM task model can be a multi-classification model. The embodiment of this specification does not impose any limitation on the model structure of the VMLM task model, and any model that can achieve multi-classification can be used.
[0107] In practical applications, the above three tasks can be performed simultaneously to improve the efficiency of model training. In order to ensure that there is no interference between different tasks, for the TTP task, the predicted element category of the text corresponding to the word embedding vector masked in the VMLM task is not included in the prediction sample, nor is the first part of the text randomly masked by the sub-page in the VTA task. For the VMLM task and the VTA task, the text masked in the page of the VTA task includes the text masked in the VMLM task.
[0108] Fifth aspect: downstream tasks
[0109] The downstream task provided by the embodiments of this specification may be a classification task, that is, understanding the category to which the page belongs.
[0110] In one example, the classification task may be to understand the industry type or business type of the entity to which the page belongs. In one example, the classification task may be a binary classification task, which may be whether the content of the page is compliant or whether the content of the page violates privacy.
[0111] The above classification tasks are merely examples of downstream tasks and do not constitute specific limitations. The specific tasks can be determined based on actual conditions.
[0112] Reviewing the above process, in the embodiments of the present specification, the element categories of the layout elements of the page are detected by a trained target detection model, and the element categories of the layout elements are used as labels to train the page representation model, so that the page representation model learns the relationship between the layout elements of the page and the text of the page, and thus better represents the text information of the page.
[0113] Next, based on the above description, a method for training a page representation model provided by this solution is introduced. It can be understood that the method can be executed by any device, equipment, platform, or device cluster with computing and processing capabilities. See the following description for details.
[0114] Figure 6 FIG. 1 shows an example flow chart of a method for training a page representation model provided in an embodiment of this specification. Figure 6 As shown, the method includes the following steps.
[0115] Step 61, obtaining a plurality of encoding vectors corresponding to a plurality of objects related to a target page; wherein the plurality of objects include a plurality of first characters located in the target page.
[0116] The target page can be considered as any page in the data set. The data set can be understood as a collection of a large number of pages used to train the page representation model. The page here is a screenshot.
[0117] Among them, the multiple objects include multiple first characters in the target page. The first characters are characters obtained by performing OCR recognition on the target page. In order to better understand the information of the page, further, multiple sub-pages after the target page is divided may be included; considering that the name of the application to which the target page belongs may contain information other than the target page, in order to better understand the page, further, the second characters in the name of the application to which the target page belongs are included. In addition, the multiple objects also include a first separator and a second separator, the first separator distinguishes the characters from the sub-pages, and the second separator distinguishes the first characters from the second characters.
[0118] Among them, the encoding vector of the object can be considered as the vectorized representation of the object. For example, for text, the encoding vector may include at least position encoding (see 2d position_embedding above for details), word embedding vector (see token_embedding above for details), sequence encoding (see 1d position_embedding above for details), and word difference encoding (see segment_embedding above for details). For sub-pages, the encoding vector may include at least position encoding (see 2d position_embedding above for details), image encoding vector (see image_embedding above for details), sequence encoding (see 1d position_embeddin g above for details), and image difference encoding (see segment_embedding above for details).
[0119] Step 62, using the trained target detection model, detect the calibrated element categories corresponding to the layout elements in the target page to obtain a first result.
[0120] The target detection model uses layout elements as detection targets and multiple calibration element categories as classification targets, detects the calibration element categories corresponding to the layout elements in the target page, and obtains the first result. Among them, the calibration element categories can be represented by letters or numbers. For example, there are 8 calibration element categories, which are represented by 8 numbers 0-7 respectively. The calibration element categories represented by these 8 numbers 0-7 are product summary, product illustration, button, icon, text block, store name, store location, and business hours. The embodiments of this specification do not impose any restrictions on the number and content of calibration element categories, which need to be determined in combination with actual conditions.
[0121] The first result includes the coordinate information of each of the multiple target frames (indicating the regional position of the layout element on the target page, usually the coordinates of the diagonal line, i.e., the third coordinate information mentioned above) and the calibration element categories corresponding to each of the multiple target frames. In practical applications, the target detection model determines the calibration element category corresponding to each of the multiple target frames by determining the probability distribution of the calibration categories corresponding to each of the multiple target frames, and determines the calibration element category corresponding to the target frame based on the probability distribution. The calibration category probability distribution includes multiple probability values, and the multiple probability values correspond to the multiple calibration element categories one by one. Usually, the calibration element category corresponding to the maximum probability value is used as the calibration element category corresponding to the target frame.
[0122] Step 63: Input the multiple encoding vectors into the page representation model. The page representation model processes the multiple encoding vectors based on the attention mechanism to obtain corresponding multiple representation vectors.
[0123] The page representation model processes the information between multiple encoding vectors based on the attention mechanism, so that the representation vector can represent the contextual information.
[0124] Step 64: determine a second result based on the multiple representation vectors, where the second result includes some or all of the predicted element categories of the multiple objects.
[0125] According to the multiple representation vectors, a part or all of the multiple objects are classified with the multiple prediction element categories as classification targets to determine a second result.
[0126] The second result includes the predicted element categories or predicted category probability distributions of part or all of the multiple objects, and the predicted category probability distribution includes the probability values of the multiple predicted element categories.
[0127] Among them, multiple predicted element categories include multiple calibrated element categories, and further, may also include preset element categories of the second text, such as the name of the application; may also include separator categories; considering that there may be undefined element categories, may also include others (i.e., no specific layout attributes).
[0128] In practical applications, multiple characters are randomly selected, for example, a first character, and another example, a first character and a second character. For any character of the selected multiple characters, the representation vector corresponding to the character is substituted into the distillation task model shown above, and the distillation task model outputs the predicted element category corresponding to the character, or the predicted category probability distribution.
[0129] Step 65, determining a first predicted loss based on the first result and the second result.
[0130] According to a feasible implementation method, the calibrated element category of each layout element in the first result is migrated to multiple first characters to determine the third result; and the first predicted loss is determined based on the third result and the second result.
[0131] In one example, text detection is performed on a target page to determine a plurality of first texts and a first area position of each of the plurality of first texts in the target page; for a target layout element in a first result, at least one first text in the target layout element is determined based on the first area position of each of the plurality of first texts and a second area position of the target layout element in the target page, and the calibrated element category of the target layout element is taken as the calibrated element category corresponding to the at least one first text it contains.
[0132] In a specific embodiment, for a target layout element in the first result, when the first area position overlaps with the second area position of the target layout element, the first text corresponding to the first area position can be considered to be the text in the target layout element.
[0133] Here, the first area position indicates the position of the first text on the target page, which can be represented by the first coordinate information. The second area position indicates the position of the target layout element on the target page, which is represented by the coordinate information of the target box output by the target detection model, that is, the third coordinate information.
[0134] In one example, the second result includes the predicted category probability distribution of each of the multiple characters, and the element category prediction loss corresponding to the characters is calculated by a first cross entropy loss function. The first cross entropy loss function is shown in the following formula (1).
[0135]
[0136] Among them, y i Indicates the label of the i-th word, represented by 1; P irepresents the probability corresponding to the label of the ith word in the predicted category probability distribution corresponding to the ith word; N represents the number of words in the second result. It should be noted that the above cross entropy loss function is only used as an example and does not constitute a specific limitation. The loss function of the first prediction loss can be reasonably designed in combination with the specific situation of the training page representation model.
[0137] Step 66: train the page representation model according to the first prediction loss.
[0138] In practical applications, model parameters of the page representation model are updated according to the first prediction loss.
[0139] According to a feasible implementation, the multiple first characters include a target character, and the word embedding vector in the target encoding vector corresponding to the target character is set to represent the masked preset encoding vector; in this case, the corresponding character prediction result can also be determined according to the target representation vector corresponding to the target encoding vector in the multiple representation vectors; then, the second prediction loss is determined according to the target character and the character prediction result; and the page representation model is trained according to the first prediction loss and the second prediction loss. This process can correspond to the aforementioned VMLM task.
[0140] In one example, the text prediction result may include the predicted text corresponding to the target encoding vector, and correspondingly, the second prediction loss is determined based on whether the target text and the predicted text are the same; in addition, it may also include the probability of belonging to the target text, and correspondingly, the second prediction loss is determined based on the probability of belonging to the target text. In one example, the second prediction loss may be a cross entropy loss, see the above formula (1).
[0141] Taking into account that the target encoding vector is obscured, the target representation vector does not include the information of the target text, and the target text needs to be predicted through the information of the sub-page and other texts; therefore, in the training stage, the reference value of the classification result of the predicted element category based on the target representation vector is low. In order to ensure the reference value of the first prediction loss, the second result does not include the predicted element category corresponding to the target text.
[0142] According to a feasible implementation manner, the multiple objects include multiple sub-pages obtained by segmenting the target page.
[0143] In one example, each of the multiple sub-pages represents a layout element. For example, the target page is segmented based on the coordinate information of the target frame in the first result to determine the multiple sub-pages. It should be noted that, considering that the types of layout elements are various and the sizes of the occupied areas are different, it is preferred to determine the multiple sub-pages by equally dividing the target page.
[0144] In one example, the plurality of subpages includes a first subpage, the first subpage has a plurality of layout elements, the plurality of layout elements have one or more calibrated element categories; the second result includes a plurality of predicted element categories and respective predicted probabilities determined for the first subpage. In such a case, the calibrated element categories of each layout element can be migrated to the plurality of subpages according to the first result to determine the fourth result; then, the first predicted loss is determined based on the first result, the second result, and the fourth result.
[0145] In a specific embodiment, the third area position of the target page corresponding to the sub-page is determined; for the target layout element in the first result, when the third area position overlaps with the second area position of the target layout element, it can be considered that the sub-page corresponding to the third area position includes the target layout element. The third area position indicates the position of the sub-page on the target page, which can be represented by the second coordinate information mentioned above.
[0146] It should be noted that the fourth result includes one or more layout elements corresponding to each of the multiple sub-pages. The second result includes the predicted category probability distribution corresponding to the sub-page. For the sub-page, the sub-page prediction loss can be calculated by the second cross entropy loss function. Correspondingly, the first prediction loss is determined based on the element category prediction loss corresponding to the above text and the element category prediction loss corresponding to the sub-page. For example, it can be the sum of the element category prediction loss corresponding to the text and the element category prediction loss corresponding to the sub-page. The second cross entropy loss function is shown in the following formula (2).
[0147]
[0148] Among them, y ic represents the symbolic function. If the label of the i-th subpage is c, it is 1; P ic represents the probability that the i-th subpage belongs to the tag c; M represents the number of tags of the i-th subpage; and N represents the number of subpages in the second result.
[0149] In one example, multiple sub-pages include a second sub-page, and at least one first character in the second sub-page is obscured; in this case, it is also possible to predict whether at least one first character is obscured based on multiple representation vectors to determine a fifth result; then, determine the third prediction loss based on the fifth result; thereafter, train the page representation model based on the first prediction loss and the third prediction loss. In a specific embodiment, multiple first characters in the page are obscured, and then the page is segmented to obtain multiple sub-pages, and the sub-page with the obscured first character is the above-mentioned second sub-page. Multiple characters are randomly selected, for example, the first character, and for example, the first character and the second character; for any selected character, the representation vector corresponding to the character is input into the above-mentioned image-text alignment model, and the image-text alignment model outputs the prediction result of whether the character is obscured. Here, the fifth result includes the prediction results of whether the multiple randomly selected characters are obscured. This process can correspond to the aforementioned VTA task.
[0150] In one example, the third prediction loss can be determined by a third cross entropy loss function; wherein the third cross entropy loss function is shown in the following formula (3).
[0151]
[0152] Among them, y i represents the label of the i-th character, where masked is 1 and unmasked is 0; P i Indicates the prediction result of whether the i-th character is obscured, where obscured is represented by 1 and unobscured is represented by 0; N represents the number of characters in the fifth result.
[0153] Considering that the first text in the second sub-page is obscured, the second sub-page does not include information about the first text, and it is necessary to predict the obscured text on the second sub-page through information from other sub-pages and texts; therefore, in the training stage, the reference value of the result of classifying the predicted element category based on the representation vector corresponding to the obscured text in the second sub-page is low. In order to ensure the reference value of the first prediction loss, the second result does not include the predicted element category of the first text obscured in the second sub-page, thereby ensuring the reference value of the first prediction loss.
[0154] In addition, the embodiments of this specification only take a target page as an example to illustrate the prediction loss of the page. In actual application, the page representation model is trained through the prediction losses of a large number of pages.
[0155] According to an embodiment of another aspect, a device for training a page representation model is also provided. Figure 7 A schematic diagram of a device for training a page representation model according to an embodiment is shown, and the device can be deployed in any device, platform or device cluster with data storage, computing and processing capabilities. Figure 7 As shown, the device 700 includes:
[0156] The encoding module 71 is configured to obtain a plurality of encoding vectors corresponding to a plurality of objects related to the target page; wherein the plurality of objects include a plurality of first characters located in the target page;
[0157] The detection module 72 is configured to use the trained target detection model to detect the calibrated element categories corresponding to the layout elements in the target page to obtain a first result;
[0158] A representation module 73 is configured to input the plurality of encoding vectors into a page representation model, and the page representation model processes the plurality of encoding vectors based on an attention mechanism to obtain a plurality of corresponding representation vectors;
[0159] A prediction module 74, configured to determine a second result based on the multiple representation vectors, wherein the second result includes predicted element categories of part or all of the multiple objects;
[0160] a loss determination module 75, configured to determine a first predicted loss according to the first result and the second result;
[0161] The training module 76 is configured to train the page representation model according to the first prediction loss.
[0162] In various embodiments, the specific configurations of the above modules are as described above and will not be repeated here.
[0163] Through the above device, the results of the page layout element detection and classification performed by the trained target detection model are transferred to the text in the page, so that the characterization vector of the text can learn the page layout information through the page representation model, thereby better representing the text information of the page.
[0164] According to another embodiment, there is also provided a computer-readable storage medium having a computer program stored thereon, which, when executed in a computer, causes the computer to execute a combination of Figure 6 The method described.
[0165] According to another embodiment of the present invention, a computing device is provided, including a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, the Figure 6 The method described.
[0166] Those skilled in the art should be aware that in one or more of the above examples, the functions described in the present invention can be implemented by hardware, software, firmware or any combination thereof. When implemented by software, these functions can be stored in a computer-readable medium or transmitted as one or more instructions or codes on a computer-readable medium.
[0167] The specific implementation methods described above further illustrate the objectives, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above description is only a specific implementation method of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc. made on the basis of the technical solution of the present invention should be included in the scope of protection of the present invention.
Claims
1. A method for training a page representation model, include: Acquire a plurality of encoding vectors corresponding to a plurality of objects related to a target page; wherein the plurality of objects include a plurality of first characters located in the target page; Using the trained target detection model, detect the calibrated element categories corresponding to the layout elements in the target page to obtain a first result; Inputting the multiple encoding vectors into a page representation model, wherein the page representation model processes the multiple encoding vectors based on an attention mechanism to obtain a corresponding multiple representation vectors; Determine a second result according to the multiple representation vectors, wherein the second result includes prediction element categories of part or all of the multiple objects; Determining a first prediction loss according to the first result and the second result, including migrating the calibrated element category of each layout element in the first result to the plurality of first characters to determine a third result; Determine a first predicted loss according to the third result and the second result; The page representation model is trained according to the first prediction loss.
2. The method according to claim 1, in, The method further comprises: Performing text detection on the target page to determine the plurality of first characters and first area positions of each of the plurality of first characters in the target page; The step of migrating the marked element category of each layout element in the first result to the plurality of first characters includes: For the target layout element in the first result, based on the first area positions of each of the multiple first characters and the second area position of the target layout element on the target page, determine at least one first character within the target layout element, and use the calibrated element category of the target layout element as the calibrated element category corresponding to the at least one first character it contains.
3. The method according to claim 2, in, For any character among the multiple first characters, the corresponding encoding vector includes at least a position code and a character embedding vector; wherein the position code is determined based on the first area position corresponding to the character.
4. The method according to claim 3, in, The plurality of first characters include a target character, and a character embedding vector in a target encoding vector corresponding to the target character is set to represent a masked preset encoding vector; The method further comprises: Determine a corresponding text prediction result according to a target representation vector corresponding to the target encoding vector among the multiple representation vectors; Determining a second prediction loss according to the target text and the text prediction result; The training of the page representation model includes: training the page representation model according to the first prediction loss and the second prediction loss.
5. The method according to claim 1, in, The multiple objects also include a plurality of second characters, and the plurality of second characters represent the name of the application to which the target page belongs.
6. The method according to claim 5, in, The target page does not include the name of the application.
7. The method according to claim 5, in, The plurality of second characters have preset element categories, and the second result includes predicted element categories for at least a portion of the plurality of second characters; The determining of the first prediction loss further includes: The first prediction loss is determined according to the preset element category and the second result.
8. The method according to claim 1, in, The multiple objects also include multiple sub-pages obtained by dividing the target page.
9. The method according to claim 8, in, For any sub-page among the multiple sub-pages, its corresponding encoding vector includes a position code, a graph encoding vector and a sequence code; wherein the position code is determined based on the regional position of the sub-page in the target page, the graph encoding vector is obtained by extracting graph features of the sub-page using a feature extraction network, and the sequence code indicates the order of the sub-page among the multiple sub-pages.
10. The method according to claim 8, in, The multiple sub-pages include a first sub-page, the first sub-page has a plurality of layout elements, and the plurality of layout elements correspond to a plurality of calibrated element categories; The second result includes a plurality of predicted element categories and respective predicted probabilities determined for the first sub-page; The determining a first predicted loss according to the first result and the second result further includes: According to the first result, the marked element category of each layout element is migrated to the plurality of sub-pages to determine a fourth result; Based on the first result, the second result, and the fourth result, a first predicted loss is determined.
11. The method according to claim 8, in, The plurality of sub-pages include a second sub-page, in which at least one first character is obscured; The method further includes: determining a fifth result according to the plurality of representation vectors, the fifth result including a prediction result of whether the at least one first character is blocked; determining a third predicted loss according to the fifth result; The training of the page representation model includes: training the page representation model according to the first prediction loss and the third prediction loss.
12. A device for training a page representation model, include: An encoding module configured to obtain a plurality of encoding vectors corresponding to a plurality of objects related to a target page; wherein the plurality of objects include a plurality of first characters located in the target page; A detection module is configured to use a trained target detection model to detect the calibrated element categories corresponding to the layout elements in the target page to obtain a first result; A representation module is configured to input the multiple encoding vectors into a page representation model, and the page representation model processes the multiple encoding vectors based on an attention mechanism to obtain a corresponding multiple representation vectors; A prediction module, configured to determine a second result according to the plurality of representation vectors, wherein the second result includes prediction element categories of part or all of the plurality of objects; A loss determination module is configured to determine a first predicted loss based on the first result and the second result, including: migrating the calibrated element category of each layout element in the first result to the plurality of first characters to determine a third result; and determining the first predicted loss based on the third result and the second result; A training module is configured to train the page representation model according to the first prediction loss.
13. A computer-readable storage medium having a computer program stored thereon, which, when executed in a computer, causes the computer to execute the method according to any one of claims 1 to 11.
14. A computing device comprising a memory and a processor, It is characterized in that The memory stores executable codes, and when the processor executes the executable codes, the method according to any one of claims 1 to 11 is implemented.
