Text recognition method and apparatus, electronic device, storage medium, and program product

Through iterative training and parameter adjustment, the reference model is used to guide small model learning, which solves the computing resource problems caused by the growth of deep learning model parameters and the decrease in text recognition accuracy, and achieves efficient text recognition effects.

WO2024187785A1PCT designated stage expired Publication Date: 2024-09-19TENCENT TECHNOLOGY (SHENZHEN) CO LTD

Patent Information

Application Number
PCT/CN2023/129845
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2023-03-10
Filing Date
2023-11-06
Publication Date
2024-09-19

AI Technical Summary

Technical Problem

The exponential growth of the parameters of the deep learning model leads to an increase in model volume and increased computing resource consumption, resulting in a slower response speed. When the model is simplified to improve implementation, the text recognition accuracy decreases, making it difficult to effectively implement it in practical applications.

Method used

Through the pre-built text sample set and reference model, the text recognition model to be trained is iteratively trained, and the model parameters are adjusted using the prediction difference of the conversion block mapping relationship and mask information, so that the text recognition model fits the output and internal structure of the reference model. , thereby improving accuracy.

Benefits of technology

It improves the accuracy of the text recognition model, avoids the decrease in accuracy caused by model simplification, and ensures the response speed and accuracy of the model in practical applications.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2023129845_19092024_PF_FP_ABST
    Figure CN2023129845_19092024_PF_FP_ABST
Patent Text Reader

Abstract

Disclosed in embodiments of the present application are a text recognition method and apparatus, an electronic device, a storage medium, and a program product. The method comprises: on the basis of a pre-constructed text sample set and a reference model, performing at least one iterative training on a text recognition model to be trained; and inputting a text to be recognized into a trained text recognition model, and recognizing a named entity in said text to obtain text content corresponding to the named entity, wherein in each iterative training, the following process is executed: respectively inputting into the reference model and the text recognition model a text sample selected from the text sample set, the reference model comprising at least one first transformation block used for feature extraction, the text recognition model comprising at least one second transformation block used for feature extraction, and the number of the first transformation blocks being greater than that of the second transformation blocks; obtaining an output difference between each second transformation block and a corresponding first transformation block in the reference model on the basis of a transformation block mapping relationship; obtaining a prediction difference between the text recognition model and the reference model in mask information included in the text sample; and adjusting the parameters of the text recognition model on the basis of each output difference and the prediction difference.
Need to check novelty before this filing date? Find Prior Art

Description

Text recognition method, device, electronic device, storage medium and program product

[0001] This application claims priority to the Chinese patent application filed with the China Patent Office on March 10, 2023, with application number 202310262181.4 and application name “A method, device, electronic device and storage medium for text recognition”. Technical Field

[0002] The present application relates to the field of computer technology, and in particular to a method, device, electronic device, storage medium, and program product for text recognition.

[0003] Background of the Invention

[0004] With the rapid development of deep learning technology, model performance, especially model accuracy, is increasing. Researchers have discovered that by continuously expanding model parameters, the accuracy of deep learning models can be continuously improved to a certain extent. However, the exponential growth of model parameters means that the model size increases, which in turn increases the computing resources consumed by the model operation and the time it takes for the model to process a task. This results in slower response times and higher hardware requirements for these large models in actual online applications, making them difficult to implement.

[0005] In related technologies, various simplifications are performed on the model, which results in a significant decrease in model precision and accuracy. This is especially true in text recognition scenarios, where text recognition based on the model obtained in the above manner also reduces the accuracy of text recognition.

[0006] In summary, how to improve the accuracy of text recognition is an urgent problem to be solved.

[0007] Summary of the Invention

[0008] Embodiments of the present application provide a method, apparatus, electronic device, storage medium, and program product for text recognition, to improve the accuracy of text recognition.

[0009] The present invention provides a method for text recognition, including:

[0010] Based on a pre-built text sample set and a reference model, performing at least one iterative training on the text recognition model to be trained to obtain a trained text recognition model;

[0011] Inputting the text to be recognized into the trained text recognition model, recognizing the named entities in the text to be recognized, and obtaining the text content corresponding to the named entities;

[0012] Each iteration of training performs the following process:

[0013] Inputting text samples selected from the text sample set into the reference model and the text recognition model respectively; the reference model includes at least one first conversion block for feature extraction, and the text recognition model includes at least one second conversion block for feature extraction, and the number of the first conversion blocks is greater than the number of the second conversion blocks;

[0014] Based on the conversion block mapping relationship, obtaining an output difference between each second conversion block and the corresponding first conversion block in the reference model;

[0015] Obtaining a difference in predictions between the text recognition model and the reference model for mask information contained in the text sample; and

[0016] Parameters of the text recognition model are adjusted based on the respective output differences and the predicted differences.

[0017] An embodiment of the present application provides a text recognition device, comprising:

[0018] A training unit, configured to perform at least one iterative training on a text recognition model to be trained based on a pre-built text sample set and a reference model to obtain a trained text recognition model;

[0019] A prediction unit, configured to input the text to be recognized into the trained text recognition model, recognize named entities in the text to be recognized, and obtain text content corresponding to the named entities;

[0020] Wherein, the training unit includes:

[0021] an input subunit, configured to input text samples selected from the text sample set into the reference model and the text recognition model, respectively, in each iterative training; the reference model includes at least one first conversion block for feature extraction, and the text recognition model includes at least one second conversion block for feature extraction, wherein the number of the first conversion blocks is greater than the number of the second conversion blocks;

[0022] An acquisition subunit is configured to obtain, in each iterative training, an output difference between each second conversion block and the corresponding first conversion block in the reference model based on the conversion block mapping relationship; and obtain a prediction difference between the text recognition model and the reference model for the mask information contained in the text sample; and,

[0023] The adjustment subunit is used to adjust the parameters of the text recognition model based on each output difference and the prediction difference in each iterative training.

[0024] An electronic device provided by an embodiment of the present application includes a processor and a memory, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor performs the steps of the above-mentioned text recognition method.

[0025] An embodiment of the present application provides a computer-readable storage medium, which includes a computer program. When the computer program is run on an electronic device, the computer program is used to enable the electronic device to perform the steps of the above-mentioned text recognition method.

[0026] An embodiment of the present application provides a computer program product, which includes a computer program stored in a computer-readable storage medium; when a processor of an electronic device reads the computer program from the computer-readable storage medium, the processor executes the computer program, causing the electronic device to perform the steps of the above-mentioned text recognition method.

[0027] BRIEF DESCRIPTION OF THE DRAWINGS

[0028] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:

[0029] FIG1 is a schematic diagram of an application scenario of a text recognition method provided by an embodiment of the present application;

[0030] FIG2 is an overall flow chart of a text recognition method provided in an embodiment of the present application;

[0031] FIG3 is a schematic diagram of the structure of a reference model and a text recognition model provided in an embodiment of the present application;

[0032] FIG4 is a schematic diagram of a text sample input model provided in an embodiment of the present application;

[0033] FIG5 is a schematic diagram of a conversion block mapping relationship provided in an embodiment of the present application;

[0034] FIG6 is a logic diagram of obtaining output differences provided by an embodiment of the present application;

[0035] FIG7 is a logic diagram of obtaining prediction differences provided by an embodiment of the present application;

[0036] FIG8 is a flowchart of another text recognition method provided by an embodiment of the present application;

[0037] FIG9 is a logical interaction diagram of a terminal device and a server when applying a text recognition model provided in an embodiment of the present application;

[0038] FIG10 is a schematic diagram of the structure of a text recognition device provided in an embodiment of the present application;

[0039] FIG11 is a schematic diagram of a hardware structure of an electronic device provided in an embodiment of the present application;

[0040] FIG12 is a schematic diagram of a hardware structure of another electronic device provided by an embodiment of the present application.

[0041] Implementation Method

[0042] To make the purpose, technical solutions, and advantages of the embodiments of this application more clear, the technical solutions of this application will be clearly and completely described below in conjunction with the drawings in the embodiments of this application. Obviously, the described embodiments are part of the embodiments of the technical solutions of this application, but not all of them. Based on the embodiments described in this application document, all other embodiments obtained by ordinary technicians in this field without making creative efforts shall fall within the scope of protection of the technical solutions of this application.

[0043] The following is an introduction to some concepts involved in the embodiments of this application.

[0044] Reference model: used to guide the distillation training of the text recognition model to be trained. It is a large-scale and complex model that has been trained. It has the same application direction as the text recognition model to be trained, that is, the reference model itself is a model applied to text recognition. In this application, the reference model can also be called a teacher model, and the text recognition model to be trained can be called a student model.

[0045] Distillation training: Let the small model (such as the student model) learn to simulate the prediction behavior of the large model (such as the teacher model), in this way, the knowledge of the large model is "taught" to the small model.

[0046] Text recognition model: It learns text recognition by imitating a reference model. It is small in scale and simple in structure. After training, it is applied to text recognition scenarios.

[0047] Transformation block: used for feature extraction. Each transformation block contains a self-attention sublayer and a feedforward neural network (FNN) sublayer.

[0048] Conversion block mapping relationship: the correspondence between all the second conversion blocks of the text recognition model and some of the first conversion blocks of the reference model. Since the number of first conversion blocks in the reference model is greater than the number of second conversion blocks in the text recognition model, it is necessary to use the conversion block mapping relationship to determine which first conversion block of the reference model each second conversion block of the text recognition model corresponds to. This can be done in a one-to-one manner, or by taking the first few first conversion blocks and the last few first conversion blocks of the reference model to correspond to each second conversion block of the text recognition model, and so on.

[0049] The embodiments of the present application relate to artificial intelligence (AI) and machine learning (ML) technology, and are designed based on computer vision technology and machine learning in artificial intelligence.

[0050] The reference model and text recognition model in the embodiments of the present application are trained using machine learning or deep learning technology.

[0051] After the text recognition model is trained based on the above method, it can be applied to recognize entity names in texts in advertisements, books, and topic discussions.

[0052] The following is a brief introduction to the design concept of the embodiment of this application:

[0053] In related technologies, to address the difficulty of implementing large models, model pruning is often used to prune the model, removing some layers to make the model sparse and reduce the model's computational complexity. Alternatively, model quantization is used to compress weights originally stored as 32-bit floating-point numbers to 16, 8, or 4 bits to reduce the size of the model weights and further reduce memory requirements after the model is implemented. Model pruning and quantization can also be used in combination. However, both model pruning and quantization can lead to a significant decrease in model precision and accuracy.

[0054] Based on this, the embodiment of the present application provides a method, device, electronic device and storage medium for text recognition. By using a pre-constructed text sample set and a large-scale reference model, a smaller-scale text recognition model is iteratively trained at least once. The text recognition model is small in scale and will not cause implementation difficulties. By guiding the text recognition model to learn through the reference model, the text recognition model can retain the accuracy of the reference model as much as possible. In each iterative training, text samples selected from the text sample set are input into the reference model and the text recognition model respectively. Not only are the parameters of the text recognition model adjusted by the prediction difference of the mask information between the text recognition model and the reference model, but also, based on the conversion block mapping relationship, at least one conversion block included in the text recognition model is obtained, and the output difference between each and the corresponding target conversion block in the reference model is obtained, and the parameters of the text recognition model are adjusted based on each prediction difference. This method enables the text recognition model to fit not only the output of the last layer of the reference model, but also the various sub-layers within the reference model. The text recognition model can learn a large amount of implicit knowledge contained in more parameters of the reference model, and the accuracy is further improved. Based on this, the accuracy of identifying named entities in the text to be identified by the text recognition model is also further improved.

[0055] The preferred embodiments of the present application are described below in conjunction with the drawings in the specification. It should be understood that the preferred embodiments described herein are only used to illustrate and explain the present application and are not used to limit the present application. In addition, the embodiments and features in the embodiments of the present application can be combined with each other if there is no conflict.

[0056] As shown in Figure 1, which is a schematic diagram of an application scenario of an embodiment of the present application, the application scenario diagram includes two terminal devices 110 and a server 120.

[0057] In the embodiment of the present application, the terminal device 110 includes but is not limited to mobile phones, tablet computers, laptop computers, desktop computers, e-book readers, intelligent voice interaction devices, smart home appliances, car terminals and other devices; a text recognition-related client can be installed on the terminal device, which can be software (such as a browser, text recognition software, etc.), or a web page, applet, etc. The server 120 is a background server corresponding to the software or web page, applet, etc., or a server specifically used for text recognition, which is not specifically limited in this application. The server 120 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDNs), and basic cloud computing services such as big data and artificial intelligence platforms.

[0058] It should be noted that the text recognition method in each embodiment of the present application can be executed by an electronic device, which can be a terminal device 110 or a server 120, that is, the method can be executed by the terminal device 110 or the server 120 alone, or can be executed jointly by the terminal device 110 and the server 120.

[0059] For example, when executed by server 120, server 120 performs at least one iterative training on the text recognition model to be trained based on a pre-built text sample set and a reference model to obtain a trained text recognition model; each text sample includes a sentence or a paragraph of text, and the text includes at least one masked information; in each iterative training, server 120 inputs the text samples selected from the text sample set into the reference model and the text recognition model respectively; and based on the conversion block mapping relationship, obtains the output difference between each second conversion block in the text recognition model and the corresponding target conversion block in the reference model; and obtains the prediction difference between the output layer of the text recognition model and the reference model for the mask information; finally, server 120 adjusts the parameters of the text recognition model based on each output difference and prediction difference. Finally, the trained text recognition model can be applied to a proper name recognition scenario, such as recognizing the name of a person in a text.

[0060] In an optional implementation, the terminal device 110 and the server 120 may communicate via a communication network.

[0061] In an optional implementation, the communication network is a wired network or a wireless network.

[0062] It should be noted that what is shown in FIG1 is only an example. In fact, the number of terminal devices and servers is not limited and is not specifically limited in the embodiments of the present application.

[0063] In an embodiment of the present application, when there are multiple servers, the multiple servers can be combined into a blockchain, and the servers are nodes on the blockchain; as in the text recognition method disclosed in the embodiment of the present application, the training data involved can be stored on the blockchain, for example, training samples, model parameters, model outputs, etc.

[0064] In addition, the embodiments of the present application can be applied to various scenarios, including not only text recognition scenarios, but also including but not limited to cloud technology, artificial intelligence, smart transportation, assisted driving and other scenarios.

[0065] The text recognition method provided by the exemplary embodiment of the present application is described below in combination with the application scenarios described above and with reference to the accompanying drawings. It should be noted that the above application scenarios are only shown to facilitate understanding of the spirit and principles of the present application, and the implementation of the present application is not limited in this respect.

[0066] 2 is a flowchart illustrating an implementation of a text recognition method provided in an embodiment of the present application. The method is executed by an electronic device, which may be the terminal device 110 or the server 120 shown in FIG1 . The specific implementation process of the method is as follows:

[0067] S201: Based on a pre-built text sample set and a reference model, perform at least one iterative training on a text recognition model to be trained to obtain a trained text recognition model.

[0068] In the above steps, the reference model is used to guide the text recognition model to be trained to perform imitation learning, also known as distillation training. It is a trained model with the same application direction as the text recognition model to be trained. The reference model can also be called a teacher model.

[0069] The text recognition model to be trained learns text recognition by imitating the reference model. It is small in scale and simple in structure. After training, it can be applied to text recognition scenarios, such as entity name recognition. In this application, the text recognition model to be trained can be referred to as the student model.

[0070] In an embodiment of the present application, a trained text recognition model can be used to identify named entities in a text to be recognized and obtain the text content corresponding to the named entities. Named entities refer to entities in a text that have a specific meaning or specific reference, including names of people, places, organizations, dates, proper nouns (which can be abbreviated as proper nouns), etc. For example, if the text recognition model to be trained is ultimately used to recognize geographic names in a text, then the reference model is a geographic location proper noun recognition model.

[0071] It should be noted that the training method of the model proposed in this application can be applied not only to text recognition models, but also to other text processing models, such as text classification models, text translation models, etc. This application does not make specific limitations.

[0072] Taking the text classification model as an example, in the subsequent step S2014, it is necessary to further combine the text recognition model and the reference model to adjust the parameters of the predicted differences in the text types of the text samples. Alternatively, based on the text recognition model obtained in step S2014, further training is performed using text samples marked with real text types to obtain a text classification model, and so on. The text translation model is also similar, and this article does not make specific restrictions.

[0073] In addition, both the reference model and the text recognition model have multi-layer structures. In the embodiment of the present application, each layer includes a conversion block, and each conversion block includes two sublayers: an attention sublayer (self-attention) and a feedforward neural network (FNN) sublayer. The number of conversion blocks of the reference model is greater than the number of conversion blocks of the text recognition model, that is, the number of layers of the reference model is greater than the number of layers of the text recognition model.

[0074] For example, the reference model and the text recognition model to be trained in this application can be a bidirectional encoding model (Bidirectional Encoder Representations from Transformer conversion block, BERT) based on a transformer. The BERT model is a model with a transformer architecture. The transformer is a multi-layer structure. During the model distillation training process, a pre-trained language model (Mask Language Model, Mask LM) technology based on a mask mechanism can be used for training. Therefore, it is necessary to obtain a large-scale text corpus as a text sample. The text sample in this article can contain a sentence or a paragraph of text.

[0075] In an embodiment of the present application, a specific method for pre-constructing a text sample set includes: dividing the original text into a string sequence, masking some characters in the string sequence, and obtaining mask information for each masked character. In this way, each text sample includes the string sequence after masking some characters and at least one piece of mask information at the masked position. All text samples constitute the text sample set.

[0076] For example, before inputting a text sample into the model, the server first breaks the original text into a sequence of strings. Specifically, each character is called a token and serves as the basic unit of model input. For Chinese original text, each character can be recorded as a token, and this process breaks the original Chinese text into individual characters. For English original text, each word can be recorded as a token, and this process breaks the original English text into individual words. This process is similar for other languages ​​and is not specifically limited in this article.

[0077] In addition, the original text contains two special flags: [CLS] and [SEP]. [CLS] is located at the beginning of the first sentence in the original text, and there is a [SEP] between two sentences in the original text. By concatenating [CLS] and at least one [SEP], you can get a string sequence, also known as a token sequence.

[0078] Then, in the token sequence, some tokens are randomly masked (for example, 15% of the tokens are masked). The positions of these masked tokens may be discontinuous or continuous. Each masked token corresponds to a mask information at its position, that is, each text sample contains at least one mask information. This mask information can be represented as a flag bit [mask] or [mark].

[0079] After constructing a text sample set using the aforementioned method, text samples can be selected from this set and fed into the reference model and the text recognition model to be trained for at least one iterative training. During this training, the reference model and the text recognition model to be trained are responsible for predicting the specific masked information in the text. This process primarily enables the model to learn the meaning of the language itself, and to learn the connections between characters, characters, and words. Guided by the reference model, the parameters of the text recognition model are continuously adjusted during distillation training. After this, the distilled text recognition model can be directly applied to specific scenarios, or more targeted text samples can be selected based on the specific scenario to further fine-tune the trained text recognition model.

[0080] Since the training method of the model proposed in this application can be applied not only to text recognition models, but also to other text processing models, after using the above-mentioned text samples containing mask information to perform distillation training on the text recognition model, the text processing model after distillation training can also be directly applied to specific scenarios, or according to the application scenarios of the text processing model in actual application and the specific tasks to be processed (such as text translation, text classification, etc.), more targeted training samples can be selected to fine-tune the model parameters.

[0081] In the above steps, the specific implementation process of each iterative training is as follows S2011-S2014:

[0082] S2011: Input text samples selected from the text sample set into the reference model and the text recognition model respectively.

[0083] As listed above, the reference model and the text recognition model to be trained can be a BERT model, whose encoding layer includes a conversion block, the reference model includes at least one first conversion block for feature extraction, and the text recognition model includes at least one second conversion block for feature extraction.

[0084] Each transformation block consists of two sublayers: an attention sublayer and a feedforward neural network sublayer. The attention sublayer outputs the degree of association between each pair of characters in the text sample. This is achieved by using the attention mechanism in the BERT model.

[0085] The feedforward neural network sublayer employs a unidirectional multi-layered structure, consisting of an input layer, at least one hidden layer, and an output layer. Each layer contains several neurons, each of which receives signals from neurons in the previous layer and generates outputs for the next layer. The feedforward neural network sublayer uses the output of the attention sublayer as input, performs a forward pass, and outputs a vector of a specific dimension, which can then be passed to the next transformation block.

[0086] The number of first transformation blocks of the reference model is greater than the number of second transformation blocks of the text recognition model. For example, the number of transformation blocks of the reference model is m, the number of transformation blocks of the text recognition model is n, and m>n.

[0087] Refer to Figure 3, which is a schematic diagram of the structure of a reference model and a text recognition model in an embodiment of the present application. Both the reference model 301 and the text recognition model 302 are models based on a conversion block structure, comprising multiple layers of conversion blocks, one for each layer, and each conversion block comprising an attention sublayer and a feedforward neural network sublayer. The reference model 301 has a relatively large number of first conversion blocks. For example, as shown in Figure 3, there are six first conversion blocks in the reference model 301 and two second conversion blocks in the text recognition model 302.

[0088] Taking a specific scenario as an example, the server selects a text sample from the text sample set, whose content is "[CLS] This bridge is located in the [covered][covered] north [SEP] and has [covered] great significance in the history of bridges [SEP]...", in which three characters are covered. As shown in Figure 4, a schematic diagram of a text sample input model provided in an embodiment of the present application is shown. The server inputs the above text sample 403 into a reference model 401 and a text recognition model 402, where the number of first conversion blocks in the reference model 401 is m, the number of second conversion blocks in the text recognition model 402 is n, and m>n.

[0089] S2012: Based on the conversion block mapping relationship, obtain an output difference between each second conversion block and the corresponding first conversion block in the reference model.

[0090] Taking into account the inconsistency between the number of second conversion blocks in the text recognition model and the number of first conversion blocks in the reference model, the number of first conversion blocks in the reference model is greater than the number of second conversion blocks in the text recognition model. Therefore, in order to achieve the association between the conversion blocks, the present application also introduces a conversion block mapping relationship, which specifically represents which conversion block the various conversion blocks of the text recognition model correspond to in the reference model. That is, the mapping relationship is the mapping relationship between the various second conversion blocks of the text recognition model and some of the first conversion blocks in the reference model.

[0091] As shown in Figure 5, a schematic diagram of a conversion block mapping relationship is provided in an embodiment of the present application. An optional method is to adopt a single-to-single mapping method. For example, the text recognition model 502 has 3 second conversion blocks (labeled 1-3), and the reference model 501 has 12 first conversion blocks (labeled 1-12). The mapping relationship between the second conversion block in the text recognition model 502 and the first conversion block in the reference model 501 is 1-4, 2-8, and 3-12.

[0092] In addition, the first several first conversion blocks or the last several first conversion blocks of the reference model may also be used to participate in the mapping, for example, 1-1, 2-2, 3-3, or 1-10, 2-11, 3-12.

[0093] It should be noted that the conversion block mapping methods listed above are only examples. Any conversion block mapping method is applicable to the embodiments of the present application and will not be described in detail herein.

[0094] For the output difference, since each conversion block includes an attention sublayer and a feedforward neural network sublayer, the output difference between conversion blocks also contains two parts: the first output difference corresponding to the attention sublayers and the second output difference corresponding to the feedforward neural network sublayers.

[0095] An optional approach is to perform the following operations for each second conversion block in the text recognition model to obtain the first output difference:

[0096] Based on the conversion block mapping relationship, determining a first conversion block corresponding to the second conversion block in the reference model as a target conversion block;

[0097] The difference between the outputs of the second transformation block and the target transformation block in the attention sub-layer is used as the first output difference.

[0098] To illustrate with reference to the above-mentioned figures, for example, the first conversion block 4 in the reference model is the target conversion block corresponding to the second conversion block 1 in the text recognition model, the first conversion block 8 in the reference model is the target conversion block corresponding to the second conversion block 2 in the text recognition model, and the first conversion block 12 in the reference model is the target conversion block corresponding to the second conversion block 3 in the text recognition model.

[0099] Furthermore, based on the attention sublayer in the second conversion block, a first degree of association between every two characters in the text sample is obtained; and based on the attention sublayer in the target conversion block, a second degree of association between every two characters in the text sample is obtained.

[0100] Finally, a first output difference is obtained based on the difference between the first association degree and the second association degree of each two characters.

[0101] From the perspective of learning (or distillation), the first degree of association output by the attention sublayer in the text recognition model is used for observation, so it can also be called the observation degree of association; the second degree of association output by the attention sublayer in the reference model is used for comparison, so it can also be called the comparison degree of association.

[0102] In one example, the attention sublayer in the second conversion block of the text recognition model obtains the query matrix Q, key matrix K, and value matrix V of each character based on each character in the input text sample, and further obtains the first degree of association between each two characters based on Q, K, and V.

[0103] Similarly, the attention sublayer in the corresponding target conversion block in the reference model obtains the query matrix Q, key matrix K, and value matrix V of each character based on each character in the input text sample, and further obtains the second degree of association between each two characters based on Q, K, and V.

[0104] Finally, the sum of the squared differences between each first association degree and the corresponding second association degree may be taken as the first output difference.

[0105] For example, A represents the reference model, B represents the text recognition model, and the specific formula for the first output difference is as follows:

[0106] in, is the second correlation degree between the i-th word and the j-th word output by the reference model, The first correlation between the i-th and j-th characters output by the text recognition model is x, which is the length of the token in the text sample, that is, the number of characters in the text. This distillation process not only distills the masked information, but also the remaining unmasked characters in the text sample.

[0107] In the above embodiment, the text recognition model is trained using the output of the attention sub-layer of the reference model as supervision, so that the text recognition model can fit the attention value of the reference model as much as possible. The attention value is used to indicate the proportion of important information contained in the text, thereby improving the accuracy of the text recognition model.

[0108] In an optional manner, the server performs the following operations for each second conversion block in the text recognition model to obtain the second output difference:

[0109] The difference between the outputs of the second conversion block and the target conversion block in the feedforward neural network sublayer is used as the second output difference.

[0110] In one example, based on the feedforward neural network sublayer in the second conversion block, a first output vector of each character in the text sample is obtained; based on the feedforward neural network sublayer in the target conversion block, a second output vector of each character in the text sample is obtained; the first output vector of each character is dimensionally converted to obtain a target vector with the same dimension as the second output vector of the character; and based on the difference between the target vector and the second output vector of each character, a second output difference is obtained.

[0111] From the perspective of learning (or distillation), the first output vector output by the feedforward neural network sublayer in the text recognition model can also be called an observation vector; the second output vector output by the feedforward neural network sublayer in the reference model can also be called a reference vector.

[0112] The reason for the dimensionality conversion is that the reference model is larger than the text recognition model—that is, its dimensions are greater than those of the text recognition model. This results in the dimension of the first output vector for each character in the text sample obtained by the text recognition model being inconsistent with the dimension of the second output vector for each character in the text sample obtained by the reference model. This dimension is determined by the output layer of the feedforward neural network sublayer in the second conversion block. Therefore, dimensionality conversion is required to align the dimensions.

[0113] An optional dimensionality conversion method is to perform dimensionality conversion on the first output vector of each character based on a preset parameter matrix and parameter vector, to obtain a target vector with the same dimension as the second output vector. The parameter matrix and parameter vector are determined based on the dimension of the second output vector.

[0114] Specifically, the dimensions of the first output vector and the second output vector are aligned as follows: ′B =W proj V B +b1 (2)

[0115] Among them, V B is the first output vector, V ′B is the target vector with the same dimension as the second output vector, W proj is the parameter matrix and b is the parameter vector.

[0116] Afterwards, the sum of the squared differences between the target vector of each character and the corresponding second output vector may be used as the second output difference.

[0117] For example, the specific formula for the second output difference is as follows:

[0118] Where i represents the i-th character in the text sample, and x is the length of the token in the text sample, that is, the number of characters in the text. is the dth dimension in the second output vector, is the dth dimension in the target vector, and k is the dimension of the reference model. This distillation process also requires distillation of all the text in the text sample.

[0119] In the above embodiment, the text recognition model is trained using the output of the feedforward neural network sublayer of the reference model as supervision, so that the text recognition model can fit the feedforward neural network sublayer of the reference model as much as possible, thereby realizing the learning of the feedforward neural network and improving the accuracy of the text recognition model.

[0120] Following the assumptions in S2011, the text recognition model has 3 second conversion blocks and the reference model has 12 first conversion blocks. The conversion block mapping relationships are 1-4, 2-8, and 3-12. As shown in FIG6 , a logic diagram for obtaining output differences provided in an embodiment of the present application is provided. After the text sample 603: "[CLS] This bridge is located in the north of [cover][cover] and has [cover] great significance in the history of bridges [SEP]..." is input into the text recognition model 602 and the reference model 601, the attention sublayer in the second conversion block 1 of the text recognition model 602 outputs the first correlation degree of each two characters, and the attention sublayer in the first conversion block 4 of the reference model 601 outputs the second correlation degree of each two characters. The server calculates the sum of the square differences between each first correlation degree and the corresponding second correlation degree to obtain the first output difference.

[0121] The feedforward neural network sublayer in the second conversion block 1 of the text recognition model 602 outputs the first output vector for each character in the text sample, and the feedforward neural network sublayer in the first conversion block 4 of the reference model outputs the second output vector for each character in the text sample. The server transforms the dimension of the first output vector to obtain a target vector with the same dimension as the second output vector, and then calculates the sum of the square differences between each target vector and the corresponding second output vector to obtain the second output difference.

[0122] Based on the same method, the server can also obtain the first output difference between the attention sublayer in the 2nd first conversion block of the text recognition model and the attention sublayer in the 8th second conversion block of the reference model; the first output difference between the attention sublayer in the 3rd first conversion block of the text recognition model and the attention sublayer in the 12th second conversion block of the reference model; the second output difference between the feedforward neural network sublayer in the 2nd first conversion block of the text recognition model and the feedforward neural network sublayer in the 8th second conversion block of the reference model; and the second output difference between the feedforward neural network sublayer in the 3rd first conversion block of the text recognition model and the feedforward neural network sublayer in the 12th second conversion block of the reference model.

[0123] S2013: Obtain the prediction difference between the text recognition model and the reference model for the mask information contained in the text sample.

[0124] For the prediction difference, after the text sample is input into the text recognition model and the reference model, the text recognition model and the reference model will predict the various mask information in the text sample and output the prediction results in the output layer of the last conversion block. Specifically, the feedforward neural network sublayer in the last second conversion block of the text recognition model outputs the first prediction results of each mask information, and the feedforward neural network sublayer in the target conversion block corresponding to the reference model outputs the second prediction results of each mask information. After that, the prediction difference can be obtained based on the prediction results output by the text recognition model and the prediction results output by the reference model.

[0125] Optionally, based on the first prediction result of the text recognition model for each mask information, a first probability distribution corresponding to each first prediction result is obtained; based on the second prediction result of the reference model for each mask information, a second probability distribution corresponding to each second prediction result is obtained; finally, based on each first probability distribution and the corresponding second probability distribution, a prediction difference is obtained.

[0126] From the perspective of learning (or distillation), the first probability distribution can also be called the observation probability distribution; the second probability distribution can also be called the control probability distribution.

[0127] Specifically, for an output vector of mask information, that is, the prediction result V mask The server performs a linear transformation on it using the following formula to generate a vector logits: logits = WV mask +b2 (4)

[0128] Among them, W is also a parameter matrix, b2 is also a parameter vector, but W is different from W in formula (2) for dimension transformation. proj They are not the same parameter matrix, and b2 and b1 are not the same parameter vector.

[0129] The dimension of logits is the size of the preset word table, which is usually in the tens of thousands. The preset word table is constructed by relevant personnel before training. Taking Chinese as an example, the basic component of the word table is Chinese characters, or the word table contains tens of thousands of characters, as well as the identity document (ID) corresponding to each character. Since the machine cannot directly recognize the text represented by a string, it is necessary to first digitize and vectorize the characters in the text represented by the string. This process is based on the preset word table.

[0130] Similarly, if the language is English, the basic component unit of the word list is a word, and the word list contains multiple words and an ID corresponding to each word.

[0131] Afterwards, the server converts logits into a probability distribution through the softmax function: Probs=softmax(logits) (5)

[0132] Probs is the probability distribution corresponding to the predicted result of a mask. The probability distribution includes the probability that the model predicts that the mask information may be each basic component of the word list. If the word list is a Chinese word list, the probability distribution includes the probability that the model predicts that the mask information may be each Chinese character in the word list.

[0133] Based on the above formula, the first probability distribution corresponding to the first prediction result of each mask information output by the feedforward neural network sublayer in the last second conversion block of the text recognition model and the second probability distribution corresponding to the second prediction result of each mask information output by the feedforward neural network sublayer in the target conversion block corresponding to the reference model can be obtained.

[0134] Finally, the sum of the opposite numbers of the relative entropies of each first probability distribution and the corresponding second probability distribution can be used as the difference in the predictions of the mask information between the text recognition model and the reference model. The specific formula is as follows: KL(Probs B ||Probs A )=∑ y Probs B (y)log(Probs B (y) / Probs A (y)) (7)

[0135] Among them, KL is the relative entropy (Kullback–Leibler divergence), also known as KL divergence, g is the number of mask information in the text sample. s represents the sth mask information, y represents all Chinese characters (or words) in the word list, Probs B Contains the probability that the mask information predicted by the text recognition model may be each Chinese character (or word) in the word list. A Contains the probability that the mask information predicted by the reference model may be each Chinese character (or word) in the character table. As shown in formula (7), the input for calculating the KL divergence is the first probability distribution Probs of the text recognition model for each mask information B (y), and the second probability distribution Probs of the reference model for each mask information A (y).

[0136] As shown in Figure 7, a logical diagram of obtaining prediction differences is provided in an embodiment of the present application. The input text sample 703 is "[CLS] This bridge is located in the north of [cover][cover] and has [cover] great significance in the history of bridges [SEP]...", where each "[cover]" corresponds to mask information s1, s2, s3,..., sg. The text recognition model 702 predicts each mask information and outputs a first prediction result, and obtains a first probability distribution of each mask information according to the first prediction result; the reference model 701 predicts each mask information and outputs a second prediction result, and obtains a second probability distribution of each mask information according to the second prediction result; finally, based on the first probability distribution of each mask information and the corresponding second probability distribution, the prediction difference between the text recognition model 702 and the reference model 701 for the text sample 703 is obtained.

[0137] S2014: Adjusting parameters of the text recognition model based on the output differences and the prediction differences.

[0138] Referring to the first output difference shown in formula (1), the second output difference shown in formula (3), and the predicted difference shown in formula (6), an optional implementation is to perform a weighted summation process on the sum of each first output difference value, the sum of each second output difference value, and the predicted difference based on a preset coefficient to obtain a target loss function; and based on the target loss function, adjust the parameters of the text recognition model. The final loss function is calculated as follows:

[0139] Among them, h is the number of the second conversion block in the text recognition model, β, γ, is the preset coefficient.

[0140] In the above embodiment, the text recognition model is trained using the prediction result of the reference model on the mask information as supervision, with the aim of making the text recognition model fit the output of the last layer of the reference model, thereby improving the accuracy of the text recognition model.

[0141] In one embodiment, the parameter matrix and parameter vector may be adjusted based on the output differences and prediction differences. That is, the parameter matrix and parameter vector are adjusted together with other parameters in the model.

[0142] In another embodiment of the present application, in addition to the output difference and the prediction difference, the first probability distribution corresponding to each prediction result can be obtained based on the first prediction result of the text recognition model for each mask information; thereafter, the parameters of the text recognition model can be adjusted based on the sum of the reciprocal numbers of the logarithms of each first probability distribution, each output difference and the prediction difference.

[0143] That is, the text recognition model is first trained conventionally instead of distilled, and then only the first probability distribution of the text recognition model for each mask information is obtained, and the loss function Loss is constructed based on the first probability distribution. pred , the reference model does not participate in this process. The specific formula is as follows:

[0144] Where g is the number of mask information in the text sample, and s represents the sth mask information.

[0145] Afterwards, the server passes Loss pred , Loss att , Loss fnn , Loss mask Get the final loss function, the calculation formula is as follows:

[0146] Among them, h is the number of the second conversion block in the text recognition model, β, γ, is the preset coefficient.

[0147] S202: Input the text to be recognized into the trained text recognition model, recognize the named entities in the text to be recognized, and obtain the text content corresponding to the named entities.

[0148] Finally, the trained text recognition model obtained by the method in S201 can recognize named entities in a text.

[0149] Assuming that it is applied to the scenario of geographic location proper noun recognition, the text to be recognized is input into the trained text recognition model; and based on the trained text recognition model, the features of the text to be recognized are extracted to obtain the text features of the text to be recognized; finally, the geographic location named entities in the text to be recognized are recognized based on the text features to obtain the text content corresponding to the named entities.

[0150] On this basis, the text recognition method in the embodiment of the present application can be applied to search scenarios in browsers, instant messaging software, and content sharing platforms. For example, by identifying and matching the text entered by the object and the text in the content library, more accurate search results can be recommended to the object, further improving the click-through rate of the content.

[0151] In addition, the training method of the model proposed in this application can also be applied to other text processing models, such as text classification models, text translation models, etc. Assuming it is a text classification model, the trained text classification model will eventually be applied to the text classification scenario, then the server will input the text to be detected into the trained text classification model; and based on the trained text classification model, perform feature extraction on the text to be detected to obtain the text features of the text to be detected; finally, predict the text type of the text to be detected based on the text features to obtain the corresponding prediction results.

[0152] As an optional implementation, FIG8 is a flowchart of another text recognition method provided in an embodiment of the present application, which is performed by an electronic device, which may be the terminal device 110 or the server 120 shown in FIG1 , and includes the following steps:

[0153] S801: Input text samples selected from the text sample set into the reference model and the text recognition model respectively.

[0154] S802: For each second conversion block in the text recognition model, based on the attention sub-layer in the second conversion block, obtain a first correlation degree between every two characters in the text sample.

[0155] S803: For each second conversion block in the text recognition model, based on the conversion block mapping relationship, determine the first conversion block corresponding to the second conversion block in the reference model as the target conversion block, and based on the attention sublayer in the target conversion block, obtain the second degree of association between every two characters in the text sample.

[0156] S804: For each second conversion block in the text recognition model, obtain a first output difference based on the difference between the first association degree and the corresponding second association degree of each two characters.

[0157] In the above steps, each second conversion block in the text recognition model has a first output difference with the corresponding target conversion block in the reference model, that is, the number of first output differences is the same as the number of second conversion blocks in the text recognition model.

[0158] S805: For each second conversion block in the text recognition model, obtain a first output vector for each character in the text sample based on the feedforward neural network sublayer in the second conversion block.

[0159] S806: For each second conversion block in the text recognition model, based on the conversion block mapping relationship and based on the feedforward neural network sublayer in the corresponding target conversion block in the reference model, obtain a second output vector for each character in the text sample.

[0160] S807: For each second conversion block in the text recognition model, perform dimension transformation on each first output vector to obtain a corresponding target vector.

[0161] S808: For each second conversion block in the text recognition model, obtain a second output difference based on a difference between each target vector and a corresponding second output vector.

[0162] There is a second output difference between each second conversion block in the text recognition model and the corresponding target conversion block in the reference model, that is, the number of second output differences is the same as the number of second conversion blocks in the text recognition model.

[0163] S809: Based on the first prediction results of the text recognition model for each mask information, obtain a first probability distribution corresponding to each first prediction result; based on the second prediction results of the reference model for each mask information, obtain a second probability distribution corresponding to each second prediction result.

[0164] S810: Obtain prediction differences based on each first probability distribution and the corresponding second probability distribution.

[0165] S811: Adjusting parameters of the text recognition model based on the sum of the inverses of the logarithms of the first probability distributions, the output differences, and the prediction differences.

[0166] Each output difference includes the sum of all first output differences and the sum of all second output differences.

[0167] As shown in Figure 9, a logical interaction diagram of a terminal device and a server when applying a text recognition model provided in an embodiment of the present application is provided. Assuming that the application scenario of the text recognition model is that a book website supports readers to search for corresponding books based on the specific plot and book type described, a prompt message "Please describe the book you need to find" is displayed on the interface 903 of the book website. After the reader enters the text description on the terminal device 901, the server 902 inputs the text description into the text recognition model. The text recognition model extracts text features and identifies key descriptions of book types, character names, etc. in the text. The server 902 then compares these key descriptions with the original introductions of each book in the book library, matches the book that best matches the text description, that is, finds the book corresponding to the book introduction with the highest matching degree, outputs the book name, and transmits the book name back to the terminal device 901. The search result information is displayed on the interface 903 of the book website: "You may be looking for "XXXX"."

[0168] Based on the same inventive concept, the present invention also provides a text recognition device. As shown in FIG10 , it is a schematic diagram of the structure of the text recognition device, which may include:

[0169] A training unit 1001 is configured to perform at least one iterative training on a text recognition model to be trained based on a pre-built text sample set and a reference model to obtain a trained text recognition model;

[0170] The prediction unit 1002 is configured to input the text to be recognized into the trained text recognition model, recognize the named entities in the text to be recognized, and obtain the text content corresponding to the named entities;

[0171] The training unit 1001 includes an input subunit 10011, an acquisition subunit 10012, and an adjustment subunit 10013. Each iterative training executes the following process:

[0172] An input subunit 10011 is configured to input text samples selected from the text sample set into the reference model and the text recognition model, respectively, in each iterative training; the reference model includes at least one first conversion block for feature extraction, and the text recognition model includes at least one second conversion block for feature extraction, wherein the number of the first conversion blocks is greater than the number of the second conversion blocks;

[0173] An acquisition subunit 10012 is configured to obtain, in each iterative training, an output difference between each second conversion block and the corresponding first conversion block in the reference model based on the conversion block mapping relationship; and obtain a prediction difference between the text recognition model and the reference model for the mask information contained in the text sample;

[0174] The adjustment subunit 10013 is used to adjust the parameters of the text recognition model based on each output difference and the prediction difference in each iterative training.

[0175] Optionally, each conversion block includes an attention sublayer and a feedforward neural network sublayer, and the conversion block mapping relationship is a mapping relationship between each conversion block of the text recognition model and some conversion blocks in the reference model; the output difference includes a first output difference corresponding to the attention sublayer and a second output difference corresponding to the feedforward neural network sublayer; the acquisition subunit 10012 is specifically used to perform the following operations for each second conversion block in the text recognition model:

[0176] Based on the conversion block mapping relationship, determining a first conversion block corresponding to the second conversion block in the reference model as a target conversion block;

[0177] Taking the difference between the output of the second transformation block and the target transformation block at the attention sub-layer as the first output difference;

[0178] The difference between the outputs of the second conversion block and the target conversion block in the feedforward neural network sublayer is used as the second output difference.

[0179] Optionally, the acquisition subunit 10012 is specifically used for:

[0180] Based on the attention sublayer in the second conversion block, obtaining a first correlation degree between every two characters in the text sample;

[0181] Obtaining a second correlation degree between every two characters in the text sample based on the attention sublayer in the target conversion block;

[0182] The first output difference is obtained based on the difference between the first association degree and the second association degree of every two characters.

[0183] Optionally, the acquisition subunit 10012 is specifically used for:

[0184] The sum of square differences between each first association degree and the corresponding second association degree is used as the first output difference.

[0185] Optionally, the acquisition subunit 10012 is specifically used for:

[0186] Obtaining a first output vector for each character in the text sample based on the feedforward neural network sublayer in the second conversion block;

[0187] Obtaining a second output vector for each character in the text sample based on the feedforward neural network sublayer in the target conversion block;

[0188] Performing dimension conversion on the first output vector of each character to obtain a target vector having the same dimension as the second output vector of the character;

[0189] The second output difference is obtained based on the difference between the target vector and the second output vector of each character.

[0190] Optionally, the acquisition subunit 10012 is specifically used for:

[0191] Based on a preset parameter matrix and parameter vector, performing dimension conversion on the first output vector to obtain the target vector; the parameter matrix and the parameter vector are determined based on the dimension of the second output vector;

[0192] The adjustment subunit 10013 is further used for:

[0193] Parameter adjustment is performed on the parameter matrix and the parameter vector based on the respective output differences and the prediction differences.

[0194] Optionally, the acquisition subunit 10012 is specifically used for:

[0195] The sum of the squared differences between each target vector and the corresponding second output vector is used as the second output difference.

[0196] Optionally, the acquisition subunit 10012 is specifically used for:

[0197] Based on the first prediction results of the text recognition model for each mask information in the text sample, obtaining a first probability distribution corresponding to each first prediction result;

[0198] Based on the second prediction results of the reference model for each mask information in the text sample, obtaining a second probability distribution corresponding to each second prediction result;

[0199] The predicted differences are obtained based on each of the first probability distributions and the corresponding second probability distributions.

[0200] Optionally, the acquisition subunit 10012 is specifically used for:

[0201] The sum of the inverse numbers of the relative entropies of each of the first probability distributions and the corresponding second probability distribution is taken as the prediction difference.

[0202] Optionally, the adjustment subunit 10013 is specifically configured to:

[0203] Based on a preset coefficient, performing a weighted summation on the sum of each of the first output difference values, the sum of each of the second output difference values, and the predicted difference to obtain a target loss function;

[0204] Based on the target loss function, parameters of the text recognition model are adjusted.

[0205] Optionally, the acquisition subunit 10012 is further configured to:

[0206] Based on the first prediction results of the text recognition model for each of the mask information, obtaining a first probability distribution corresponding to each of the prediction results;

[0207] The adjustment subunit 10013 is specifically used for:

[0208] Parameters of the text recognition model are adjusted based on the sum of the reciprocals of the logarithms of the first probability distributions, the output differences, and the predicted differences.

[0209] Optionally, the prediction unit 1002 is specifically configured to:

[0210] Based on the trained text recognition model, feature extraction is performed on the text to be recognized to obtain text features of the text to be recognized;

[0211] Based on the text features, named entities in the to-be-recognized text are identified to obtain text content corresponding to the named entities.

[0212] For the convenience of description, the above parts are divided into modules (or units) according to their functions and described separately. Of course, when implementing this application, the functions of each module (or unit) can be implemented in the same or multiple software or hardware.

[0213] After introducing the method and apparatus for text recognition according to an exemplary embodiment of the present application, an electronic device according to another exemplary embodiment of the present application will be introduced next.

[0214] Those skilled in the art will appreciate that various aspects of the present application can be implemented as systems, methods, or program products. Therefore, various aspects of the present application can be specifically implemented in the following forms: a complete hardware implementation, a complete software implementation (including firmware, microcode, etc.), or an implementation that combines hardware and software aspects, which may be collectively referred to herein as a "circuit," "module," or "system."

[0215] Based on the same inventive concept as the above-described method embodiment, an electronic device is also provided in an embodiment of the present application. In one embodiment, the electronic device may be a server, such as server 120 shown in FIG. In this embodiment, the structure of the electronic device may be as shown in FIG. 11 , including a memory 1101, a communication module 1103, and one or more processors 1102.

[0216] Memory 1101 is used to store computer programs executed by processor 1102. Memory 1101 may primarily include a program storage area and a data storage area. The program storage area may store an operating system and programs required for running instant messaging functions, while the data storage area may store various instant messaging messages and operating instruction sets.

[0217] Memory 1101 may be a volatile memory, such as random-access memory (RAM); a non-volatile memory, such as read-only memory, flash memory, a hard disk drive (HDD), or a solid-state drive (SSD); or any other medium capable of carrying or storing a desired computer program in the form of instructions or data structures and accessible by a computer, but is not limited thereto. Memory 1101 may be a combination of the aforementioned memories.

[0218] The processor 1102 may include one or more central processing units (CPUs) or digital processing units, etc. The processor 1102 is configured to implement the above-mentioned text recognition method when calling the computer program stored in the memory 1101 .

[0219] The communication module 1103 is used to communicate with terminal devices and other servers.

[0220] The specific connection medium between the memory 1101, communication module 1103, and processor 1102 is not limited in the embodiments of the present application. In Figure 11, the embodiment of the present application shows that the memory 1101 and the processor 1102 are connected via a bus 1104. The bus 1104 is depicted in bold in Figure 11. The connection methods between other components are merely schematic and are not intended to be limiting. The bus 1104 can be divided into an address bus, a data bus, a control bus, etc. For ease of description, Figure 11 only uses a single bold line, but does not represent only one bus or one type of bus.

[0221] The memory 1101 stores a computer storage medium, which stores computer executable instructions for implementing the text recognition method of the embodiment of the present application. The processor 1102 is used to execute the above text recognition method, as shown in FIG2 .

[0222] In another embodiment, the electronic device may also be other electronic devices, such as the terminal device 110 shown in FIG1 . In this embodiment, the structure of the electronic device may be as shown in FIG12 , including: a communication component 1210, a memory 1220, a display unit 1230, a camera 1240, a sensor 1250, an audio circuit 1260, a Bluetooth module 1270, a processor 1280, and other components.

[0223] The communication component 1210 is used to communicate with the server. In some embodiments, it may include a wireless fidelity (WiFi) module. The WiFi module is a short-range wireless transmission technology. Electronic devices can help objects (such as users) send and receive information through the WiFi module.

[0224] The memory 1220 can be used to store software programs and data. The processor 1280 executes various functions and data processing of the terminal device 110 by running the software programs or data stored in the memory 1220. The memory 1220 may include high-speed random access memory and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device. The memory 1220 stores an operating system that enables the terminal device 110 to run. In the present application, the memory 1220 can store the operating system and various application programs, and may also store a computer program that executes the text recognition method of the embodiment of the present application.

[0225] The display unit 1230 can also be used to display information input by or provided to an object, as well as a graphical user interface (GUI) of various menus of the terminal device 110. Specifically, the display unit 1230 may include a display screen 1232 disposed on the front of the terminal device 110. The display screen 1232 may be configured in the form of a liquid crystal display, a light-emitting diode, etc. The display unit 1230 can be used to display the text recognition interface in the embodiments of the present application, etc.

[0226] The display unit 1230 can also be used to receive input digital or character information and generate signal input related to the object setting and function control of the terminal device 110. Specifically, the display unit 1230 may include a touch screen 1231 set on the front of the terminal device 110, which can collect touch operations of objects on or near it, such as clicking a button, dragging a scroll box, etc.

[0227] The touch screen 1231 can be covered on the display screen 1232, or the touch screen 1231 and the display screen 1232 can be integrated to realize the input and output functions of the terminal device 110. The integrated display screen can be simply called a touch screen. In this application, the display unit 1230 can display applications and corresponding operation steps.

[0228] The camera 1240 can be used to capture static images, and the subject can publish the images captured by the camera 1240 through an application. The camera 1240 can be one or more. The object generates an optical image through the lens and projects it onto the photosensitive element. The photosensitive element can be a charge coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor. The photosensitive element converts the optical signal into an electrical signal, which is then transmitted to the processor 1280 for conversion into a digital image signal.

[0229] The terminal device may further include at least one sensor 1250, such as an acceleration sensor 1251, a distance sensor 1252, a fingerprint sensor 1253, and a temperature sensor 1254. The terminal device may also be configured with other sensors such as a gyroscope, a barometer, a hygrometer, a thermometer, an infrared sensor, a light sensor, and a motion sensor.

[0230] The audio circuit 1260, speaker 1261, and microphone 1262 can provide an audio interface between the object and the terminal device 110. The audio circuit 1260 can transmit the electrical signal converted from the received audio data to the speaker 1261, which converts it into a sound signal for output. The terminal device 110 can also be equipped with a volume button for adjusting the volume of the sound signal. On the other hand, the microphone 1262 converts the collected sound signal into an electrical signal, which is received by the audio circuit 1260 and converted into audio data. The audio data is then output to the communication component 1210 for transmission to, for example, another terminal device 110, or the audio data is output to the memory 1220 for further processing.

[0231] The Bluetooth module 1270 is used to exchange information with other Bluetooth devices having a Bluetooth module through the Bluetooth protocol. For example, the terminal device can establish a Bluetooth connection with a wearable electronic device (such as a smart watch) that also has a Bluetooth module through the Bluetooth module 1270 to exchange data.

[0232] The processor 1280 is the control center of the terminal device. It uses various interfaces and lines to connect various parts of the entire terminal. By running or executing software programs stored in the memory 1220 and calling data stored in the memory 1220, it performs various functions of the terminal device and processes data. In some embodiments, the processor 1280 may include one or more processing units; the processor 1280 may also integrate an application processor and a baseband processor, wherein the application processor mainly processes the operating system, object interface, and application programs, and the baseband processor mainly processes wireless communications. It is understood that the above-mentioned baseband processor may not be integrated into the processor 1280. In the present application, the processor 1280 can run the operating system, application programs, object interface display and touch response, as well as the text recognition method of the embodiment of the present application. In addition, the processor 1280 is coupled to the display unit 1230.

[0233] In some possible implementations, various aspects of the text recognition method provided by the present application can also be implemented in the form of a program product, which includes a computer program. When the program product is run on an electronic device, the computer program is used to enable the electronic device to execute the steps of the text recognition method according to various exemplary embodiments of the present application described above in this specification. For example, the electronic device can execute the steps shown in Figure 2.

[0234] The program product may employ any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or component, or any combination thereof. More specific examples of readable storage media (a non-exhaustive list) include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof.

[0235] The program product of the embodiment of the present application may be a portable compact disc read-only memory (CD-ROM) and include a computer program, and can be run on an electronic device. However, the program product of the present application is not limited thereto. In this document, a readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with a command execution system, apparatus, or device.

[0236] A readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, which carries a readable computer program. Such a propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A readable signal medium may also be any readable medium other than a readable storage medium that can transmit, propagate, or transfer a program for use by or in conjunction with a command execution system, apparatus, or device.

[0237] The computer program embodied on the readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.

[0238] The computer program for performing the operations of the present application can be written in any combination of one or more programming languages, including object-oriented programming languages ​​such as Java, C++, etc., and conventional procedural programming languages ​​such as "C" or similar programming languages. The computer program can be executed entirely on the subject electronic device, partially on the subject electronic device, as a stand-alone software package, partially on the subject electronic device and partially on a remote electronic device, or entirely on a remote electronic device or server. In cases involving remote electronic devices, the remote electronic device can be connected to the subject electronic device through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external electronic device (for example, through the Internet using an Internet service provider).

[0239] It should be noted that although several units or subunits of the device are mentioned in the detailed description above, this division is merely exemplary and not mandatory. In fact, depending on the embodiment of the application, the features and functions of two or more units described above can be embodied in a single unit. Conversely, the features and functions of a single unit described above can be further divided and embodied by multiple units.

[0240] Furthermore, although the operations of the method of the present application are described in a particular order in the accompanying drawings, this does not require or imply that the operations must be performed in this particular order, or that all illustrated operations must be performed to achieve the desired results. Additionally or alternatively, some steps may be omitted, multiple steps may be combined into one step, and / or one step may be decomposed into multiple steps.

[0241] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Furthermore, the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) that contain a computer-usable computer program.

[0242] The present application is described with reference to the flow chart and / or block diagram of the method, device (system) and computer program product according to the embodiment of the present application. It should be understood that each flow process and / or box in the flow chart and / or block diagram and the combination of the flow process and / or box in the flow chart and / or block diagram can be realized by computer program commands. These computer program commands can be provided to the processor of a general-purpose computer, a special-purpose computer, an embedded processing machine or other programmable data processing device to produce a machine, so that the command executed by the processor of the computer or other programmable data processing device produces a device for realizing the function specified in one flow chart flow or multiple flows and / or one box or multiple boxes of the block diagram.

[0243] These computer program commands may also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to operate in a specific manner, so that the commands stored in the computer-readable memory produce a manufactured product including a command device that implements the functions specified in one or more processes in the flowchart and / or one or more boxes in the block diagram.

[0244] These computer program commands can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, so that the commands executed on the computer or other programmable device provide steps for implementing the functions specified in one or more processes in the flowchart and / or one or more boxes in the block diagram.

[0245] Although the preferred embodiments of the present application have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the present application.

[0246] Obviously, those skilled in the art may make various changes and modifications to this application without departing from the spirit and scope of this application. Thus, if these modifications and variations of this application fall within the scope of the claims of this application and their equivalents, this application is intended to include these modifications and variations.

Claims

1. A method for text recognition, performed by an electronic device, the method comprising: Based on the pre-built text sample set and the reference model, the text recognition model to be trained is iterated for at least one time to obtain a trained text recognition model; Inputting the text to be recognized into the trained text recognition model, recognizing the named entities in the text to be recognized, and obtaining the text content corresponding to the named entities; Each iteration of training performs the following process: Inputting text samples selected from the text sample set into the reference model and the text recognition model respectively; the reference model includes at least one first conversion block for feature extraction, and the text recognition model includes at least one second conversion block for feature extraction, and the number of the first conversion blocks is greater than the number of the second conversion blocks; Based on the conversion block mapping relationship, obtaining an output difference between each second conversion block and a corresponding first conversion block in the reference model; Obtaining a prediction difference between the text recognition model and the reference model for the mask information contained in the text sample; and, Based on the respective output differences and the predicted differences, parameters of the text recognition model are adjusted.

2. The method of claim 1, wherein: Each conversion block includes an attention sublayer and a feedforward neural network sublayer, and the conversion block mapping relationship is a mapping relationship between each second conversion block of the text recognition model and a part of the first conversion blocks in the reference model; the output difference includes a first output difference corresponding to the attention sublayer and a second output difference corresponding to the feedforward neural network sublayer; The obtaining, based on the conversion block mapping relationship, an output difference between each second conversion block and a corresponding first conversion block in the reference model comprises: For each second conversion block in the text recognition model, the following operations are performed respectively: Based on the conversion block mapping relationship, determining a first conversion block corresponding to the second conversion block in the reference model as a target conversion block; Using the difference between the outputs of the second transformation block and the target transformation block at the attention sublayer as the first output difference; The difference between the outputs of the second conversion block and the target conversion block in the feedforward neural network sublayer is used as the second output difference.

3. The method of claim 2, wherein: The taking the difference between the output of the second transformation block and the output of the target transformation block at the attention sublayer as the first output difference comprises: Based on the attention sublayer in the second conversion block, obtaining a first correlation degree between every two characters in the text sample; Based on the attention sublayer in the target conversion block, obtaining a second correlation degree between every two characters in the text sample; The first output difference is obtained based on the difference between the first association degree and the second association degree of every two characters.

4. The method of claim 3, wherein: The obtaining the first output difference based on the difference between the first association degree and the second association degree of every two characters includes: The sum of the square differences between each of the first association degrees and the corresponding second association degrees is taken as the first output difference.

5. The method of claim 2, wherein: The taking the difference between the outputs of the second conversion block and the target conversion block in the feedforward neural network sublayer as the second output difference comprises: Based on the feedforward neural network sublayer in the second conversion block, obtaining a first output vector for each character in the text sample; Based on the feedforward neural network sublayer in the target conversion block, obtain a second output vector for each word in the text sample; Performing dimension conversion on the first output vector of each character to obtain a target vector having the same dimension as the second output vector of the character; The second output difference is obtained based on the difference between the target vector and the second output vector of each character.

6. The method of claim 5, wherein: The step of converting the dimension of the first output vector of each character to obtain a target vector having the same dimension as the second output vector of the character includes: Based on a preset parameter matrix and parameter vector, the first output vector is dimensionally transformed to obtain the target vector; The parameter matrix and the parameter vector are determined based on the dimension of the second output vector; The method further comprises: Based on the respective output differences and the predicted differences, parameter adjustment is performed on the parameter matrix and the parameter vector.

7. The method of claim 5, wherein: The step of obtaining the second output difference based on the difference between the target vector and the second output vector of each character comprises: The sum of the square differences between each of the target vectors and the corresponding second output vector is taken as the second output difference.

8. The method according to any one of claims 1 to 7, wherein The obtaining of the prediction difference between the text recognition model and the reference model for the mask information contained in the text sample includes: Based on the first prediction results of the text recognition model for each mask information in the text sample, obtaining a first probability distribution corresponding to each first prediction result; Based on the second prediction results of the reference model for each mask information in the text sample, obtaining a second probability distribution corresponding to each second prediction result; The predicted differences are obtained based on each of the first probability distributions and the corresponding second probability distributions.

9. The method of claim 8, wherein: The obtaining the predicted difference based on the first probability distribution and the corresponding second probability distribution includes: The sum of the inverse numbers of the relative entropies of each of the first probability distributions and the corresponding second probability distribution is taken as the prediction difference.

10. The method of claim 2, wherein: The adjusting the parameters of the text recognition model based on each output difference and the prediction difference includes: Based on a preset coefficient, performing weighted summation on the sum of each of the first output difference values, the sum of each of the second output difference values, and the predicted difference to obtain a target loss function; Based on the target loss function, the parameters of the text recognition model are adjusted.

11. The method according to any one of claims 1 to 7 and 10, further comprising: Based on the first prediction results of the text recognition model for each of the mask information, obtaining a first probability distribution corresponding to each of the prediction results; The adjusting the parameters of the text recognition model based on each output difference and the prediction difference includes: The parameters of the text recognition model are adjusted based on the sum of the inverse numbers of the logarithms of the first probability distributions, the output differences and the predicted differences.

12. The method according to any one of claims 1 to 7 and 10, wherein: The step of inputting the text to be recognized into the trained text recognition model, recognizing the named entities in the text to be recognized, and obtaining the text content corresponding to the named entities includes: Based on the trained text recognition model, feature extraction is performed on the text to be recognized to obtain text features of the text to be recognized; Based on the text features, the named entities in the text to be recognized are recognized to obtain text content corresponding to the named entities.

13. A text recognition device, comprising: A training unit, used for performing at least one iterative training on the text recognition model to be trained based on a pre-built text sample set and a reference model to obtain a trained text recognition model; A prediction unit, used for inputting the text to be recognized into the trained text recognition model, recognizing the named entities in the text to be recognized, and obtaining the text content corresponding to the named entities; Wherein, the training unit comprises: An input subunit, used for inputting text samples selected from the text sample set into the reference model and the text recognition model respectively in each iterative training; the reference model includes at least one first conversion block for feature extraction, and the text recognition model includes at least one second conversion block for feature extraction, and the number of the first conversion blocks is greater than the number of the second conversion blocks; An acquisition subunit is used to obtain, in each iterative training, an output difference between each second conversion block and a corresponding first conversion block in the reference model based on the conversion block mapping relationship; and obtain a prediction difference between the text recognition model and the reference model for the mask information contained in the text sample; and, The adjustment subunit is used to adjust the parameters of the text recognition model based on each output difference and the prediction difference in each iterative training.

14. The device of claim 13, wherein: Each conversion block includes an attention sublayer and a feedforward neural network sublayer, and the conversion block mapping relationship is a mapping relationship between each second conversion block of the text recognition model and a part of the first conversion blocks in the reference model; the output difference includes a first output difference corresponding to the attention sublayer and a second output difference corresponding to the feedforward neural network sublayer; The acquisition subunit is used to perform the following operations for each second conversion block in the text recognition model: Based on the conversion block mapping relationship, determining a first conversion block corresponding to the second conversion block in the reference model as a target conversion block; Using the difference between the outputs of the second transformation block and the target transformation block at the attention sublayer as the first output difference; The difference between the outputs of the second conversion block and the target conversion block in the feedforward neural network sublayer is used as the second output difference.

15. The device of claim 14, wherein: The acquisition subunit is used to obtain a first correlation degree between every two characters in the text sample based on the attention sublayer in the second conversion block; Based on the attention sublayer in the target conversion block, a second degree of association between every two characters in the text sample is obtained; based on the difference between the first degree of association and the second degree of association between every two characters, the first output difference is obtained.

16. The device of claim 14, wherein: The acquisition subunit is used to obtain a first output vector for each character in the text sample based on the feedforward neural network sublayer in the second conversion block; Based on the feedforward neural network sublayer in the target conversion block, a second output vector of each character in the text sample is obtained; the first output vector of each character is dimensionally converted to obtain a target vector with the same dimension as the second output vector of the character; based on the difference between the target vector and the second output vector of each character, the second output difference is obtained.

17. The device according to any one of claims 13 to 16, wherein: The acquisition subunit is used to obtain, based on the first prediction results of the text recognition model for each mask information in the text sample, a first probability distribution corresponding to each first prediction result; based on the second prediction results of the reference model for each mask information in the text sample, obtain a second probability distribution corresponding to each second prediction result; and obtain the prediction difference based on each first probability distribution and the corresponding second probability distribution.

18. An electronic device comprising a processor and a memory, wherein: The memory stores a computer program, and when the computer program is executed by the processor, the processor is caused to perform the steps of the method according to any one of claims 1 to 12.

19. A computer-readable storage medium, comprising a computer program, wherein when the computer program is executed on an electronic device, the computer program is used to cause the electronic device to execute the steps of the method according to any one of claims 1 to 12.

20. A computer program product, comprising a computer program, wherein the computer program is stored in a computer-readable storage medium; when a processor of an electronic device reads the computer program from the computer-readable storage medium, the processor executes the computer program, so that the electronic device performs the steps of the method described in any one of claims 1 to 12.

Citation Information

Patent Citations

  • Semantic recognition method and device, computer equipment and storage medium

    CN112232086A

  • Student model training method and device and electronic equipment

    CN113435208A

  • Information identification method and device, computer system and readable storage medium

    CN113779240A

  • Entity recognition model training method and device and entity recognition method and device

    CN115496067A

  • Text recognition method and device, electronic equipment and storage medium

    CN116976346A

Cited By

  • Text detection method and device for publications based on large models

    CN119761351A